mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 14:30:27 +02:00
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
47 lines
2.8 KiB
JavaScript
47 lines
2.8 KiB
JavaScript
function shouldBe(func, expected) {
|
|
let result = func();
|
|
if (result !== expected)
|
|
throw new Error("bad value");
|
|
}
|
|
|
|
function shouldThrow(func, errorType, message) {
|
|
let errorThrown = false;
|
|
let error = null;
|
|
try {
|
|
func();
|
|
} catch (e) {
|
|
errorThrown = true;
|
|
error = e;
|
|
}
|
|
if (!errorThrown)
|
|
throw new Error("not thrown");
|
|
if (!(error instanceof errorType))
|
|
throw new Error("wrong error type thrown: " + error);
|
|
if (error.message !== message)
|
|
throw new Error("wrong message thrown: " + error.message);
|
|
}
|
|
|
|
shouldBe(() => isNaN({}), true);
|
|
shouldBe(() => isNaN({[Symbol.toPrimitive]: undefined}), true);
|
|
shouldBe(() => isNaN({[Symbol.toPrimitive]: null}), true);
|
|
shouldBe(() => isNaN({[Symbol.toPrimitive]() { /* empty */ } }), true);
|
|
shouldBe(() => isNaN({[Symbol.toPrimitive]() { return NaN } }), true);
|
|
shouldBe(() => isNaN({[Symbol.toPrimitive]() { return 1 } }), false);
|
|
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]: 1 }) }, TypeError, "Symbol.toPrimitive is not a function, undefined, or null");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]: NaN }) }, TypeError, "Symbol.toPrimitive is not a function, undefined, or null");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]: true }) }, TypeError, "Symbol.toPrimitive is not a function, undefined, or null");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]: "string" }) }, TypeError, "Symbol.toPrimitive is not a function, undefined, or null");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]: Symbol() }) }, TypeError, "Symbol.toPrimitive is not a function, undefined, or null");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]: {} }) }, TypeError, "Symbol.toPrimitive is not a function, undefined, or null");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]: [] }) }, TypeError, "Symbol.toPrimitive is not a function, undefined, or null");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]: /regex/ }) }, TypeError, "Symbol.toPrimitive is not a function, undefined, or null");
|
|
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]() { return this } }) }, TypeError, "Symbol.toPrimitive returned an object");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]() { return {} } }) }, TypeError, "Symbol.toPrimitive returned an object");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]() { return [] } }) }, TypeError, "Symbol.toPrimitive returned an object");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]() { return /regex/ } }) }, TypeError, "Symbol.toPrimitive returned an object");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]() { return function(){} } }) }, TypeError, "Symbol.toPrimitive returned an object");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]() { return Symbol() } }) }, TypeError, "Cannot convert a symbol to a number");
|
|
shouldThrow(() => { isNaN({[Symbol.toPrimitive]() { throw new Error("Inner Error") } }) }, Error, "Inner Error");
|