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)
69 lines
2.2 KiB
JavaScript
69 lines
2.2 KiB
JavaScript
function testTypeError(script, message) {
|
|
var error = null;
|
|
try {
|
|
eval(script);
|
|
} catch (e) {
|
|
error = e;
|
|
}
|
|
if (!error)
|
|
throw new Error("Expected type error not thrown by `" + script + "`");
|
|
|
|
if (String(error) !== message)
|
|
throw new Error("Bad error: " + String(error));
|
|
}
|
|
|
|
function testOK(script) {
|
|
var error = null;
|
|
try {
|
|
eval(script);
|
|
} catch (e) {
|
|
error = e;
|
|
}
|
|
if (error)
|
|
throw new Error("Bad error: " + String(error));
|
|
}
|
|
|
|
testTypeError(`({ } = null)`, "TypeError: Right side of assignment cannot be destructured");
|
|
testTypeError(`({ a } = null)`, "TypeError: Right side of assignment cannot be destructured");
|
|
testTypeError(`({ a: { b } = null } = { })`, "TypeError: Right side of assignment cannot be destructured");
|
|
testTypeError(`({ a: { b } } = { a: null })`, "TypeError: Right side of assignment cannot be destructured");
|
|
testTypeError(`({ } = undefined)`, "TypeError: Right side of assignment cannot be destructured");
|
|
testTypeError(`({ a } = undefined)`, "TypeError: Right side of assignment cannot be destructured");
|
|
testTypeError(`({ a: { b } = undefined } = { })`, "TypeError: Right side of assignment cannot be destructured");
|
|
testTypeError(`({ a: { b } } = { a: undefined })`, "TypeError: Right side of assignment cannot be destructured");
|
|
|
|
testOK(`({ } = 123)`);
|
|
testOK(`({ a } = 123)`);
|
|
testOK(`({ a: { b } = 123 } = { })`);
|
|
testOK(`({ a: { b } } = { a: 123 })`);
|
|
|
|
testOK(`({ } = 0.5)`);
|
|
testOK(`({ a } = 0.5)`);
|
|
testOK(`({ a: { b } = 0.5 } = { })`);
|
|
testOK(`({ a: { b } } = { a: 0.5 })`);
|
|
|
|
testOK(`({ } = NaN)`);
|
|
testOK(`({ a } = NaN)`);
|
|
testOK(`({ a: { b } = NaN } = { })`);
|
|
testOK(`({ a: { b } } = { a: NaN })`);
|
|
|
|
testOK(`({ } = true)`);
|
|
testOK(`({ a } = true)`);
|
|
testOK(`({ a: { b } = true } = { })`);
|
|
testOK(`({ a: { b } } = { a: true })`);
|
|
|
|
testOK(`({ } = {})`);
|
|
testOK(`({ a } = {})`);
|
|
testOK(`({ a: { b } = {} } = { })`);
|
|
testOK(`({ a: { b } } = { a: {} })`);
|
|
|
|
testOK(`({ } = [])`);
|
|
testOK(`({ a } = [])`);
|
|
testOK(`({ a: { b } = [] } = { })`);
|
|
testOK(`({ a: { b } } = { a: [] })`);
|
|
|
|
testOK(`({ } = /1/)`);
|
|
testOK(`({ a } = /1/)`);
|
|
testOK(`({ a: { b } = /1/ } = { })`);
|
|
testOK(`({ a: { b } } = { a: /1/ })`);
|