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)
65 lines
1.5 KiB
JavaScript
65 lines
1.5 KiB
JavaScript
function assert(b) {
|
|
if (!b)
|
|
throw new Error("Bad");
|
|
}
|
|
|
|
function hasSyntaxError(f) {
|
|
let threw = false;
|
|
try {
|
|
f();
|
|
} catch(e) {
|
|
threw = e instanceof SyntaxError;
|
|
}
|
|
return threw;
|
|
}
|
|
|
|
let functions = [
|
|
Function,
|
|
(function*foo(){}).__proto__.constructor,
|
|
(async function foo(){}).__proto__.constructor,
|
|
];
|
|
|
|
function testError(...args) {
|
|
for (let f of functions) {
|
|
assert(hasSyntaxError(() => (f(...args))));
|
|
}
|
|
}
|
|
|
|
function testOK(...args) {
|
|
for (let f of functions) {
|
|
assert(!hasSyntaxError(() => (f(...args))));
|
|
}
|
|
}
|
|
|
|
testError("a", "b", "/*", "");
|
|
testError("/*", "*/){");
|
|
testError("a=super()", "body;");
|
|
testError("a=super.foo", "body;");
|
|
testError("super();");
|
|
testError("super.foo;");
|
|
testError("a", "b", "/*", "");
|
|
testError("a", "'use strict'; let a;");
|
|
testError("/*", "*/");
|
|
testError("/*", "*/");
|
|
testError("a=20", "'use strict';");
|
|
testError("{a}", "'use strict';");
|
|
testError("...args", "'use strict';");
|
|
testError("...args", "b", "");
|
|
testError("//", "b", "");
|
|
|
|
testOK("/*", "*/", "");
|
|
testOK("a", "/*b", "*/", "'use strict'; let b");
|
|
testOK("{a}", "return a;");
|
|
testOK("a", "...args", "");
|
|
testOK("");
|
|
testOK("let a");
|
|
testOK(undefined);
|
|
testOK("//");
|
|
|
|
let str = "";
|
|
testOK({toString() { str += "1"; return "a"}}, {toString() { str += "2"; return "b"}}, {toString() { str += "3"; return "body;"}});
|
|
let target = "";
|
|
for (let i = 0; i < functions.length; ++i)
|
|
target += "123";
|
|
assert(str === target);
|