mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 22:40:28 +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)
134 lines
2.7 KiB
JavaScript
134 lines
2.7 KiB
JavaScript
function assert(b, m) {
|
|
if (!b)
|
|
throw new Error(m);
|
|
}
|
|
|
|
function test(f, iters = 1000) {
|
|
noInline(f);
|
|
for (let i = 0; i < iters; i++)
|
|
f(i);
|
|
}
|
|
|
|
const globalConst = {};
|
|
class GlobalClass { }
|
|
let globalLet = {};
|
|
let f = new Function("", "return globalConst;");
|
|
test(function() {
|
|
assert(f() === globalConst);
|
|
});
|
|
|
|
f = new Function("", "return GlobalClass;");
|
|
test(function() {
|
|
let ctor = f();
|
|
assert(ctor === GlobalClass);
|
|
assert((new GlobalClass) instanceof GlobalClass);
|
|
});
|
|
|
|
|
|
f = new Function("", "return globalLet;");
|
|
test(function() {
|
|
assert(f() === globalLet);
|
|
});
|
|
|
|
f = new Function("prop", "x", "globalLet[prop] = x;");
|
|
test(function(i) {
|
|
f(i, i);
|
|
assert(globalLet[i] === i);
|
|
});
|
|
|
|
f = new Function("prop", "x", "globalConst[prop] = x;");
|
|
test(function(i) {
|
|
f(i, i);
|
|
assert(globalConst[i] === i);
|
|
});
|
|
|
|
f = new Function("", "globalConst = 25");
|
|
test(function() {
|
|
let threw = false;
|
|
try {
|
|
f();
|
|
} catch(e) {
|
|
threw = true;
|
|
assert(e.toString() === "TypeError: Attempted to assign to readonly property.")
|
|
}
|
|
assert(threw);
|
|
});
|
|
|
|
f = new Function("", "globalConst = 25");
|
|
test(function() {
|
|
let threw = false;
|
|
try {
|
|
f();
|
|
} catch(e) {
|
|
threw = true;
|
|
assert(e.toString() === "TypeError: Attempted to assign to readonly property.")
|
|
}
|
|
assert(threw);
|
|
});
|
|
|
|
f = new Function("", "constTDZ = 25");
|
|
test(function() {
|
|
let threw = false;
|
|
try {
|
|
f();
|
|
} catch(e) {
|
|
threw = true;
|
|
assert(e.toString() === "ReferenceError: Cannot access uninitialized variable.")
|
|
}
|
|
assert(threw);
|
|
});
|
|
|
|
f = new Function("", "constTDZ;");
|
|
test(function() {
|
|
let threw = false;
|
|
try {
|
|
f();
|
|
} catch(e) {
|
|
threw = true;
|
|
assert(e.toString() === "ReferenceError: Cannot access uninitialized variable.")
|
|
}
|
|
assert(threw);
|
|
});
|
|
|
|
f = new Function("", "letTDZ;");
|
|
test(function() {
|
|
let threw = false;
|
|
try {
|
|
f();
|
|
} catch(e) {
|
|
threw = true;
|
|
assert(e.toString() === "ReferenceError: Cannot access uninitialized variable.")
|
|
}
|
|
assert(threw);
|
|
});
|
|
|
|
f = new Function("", "letTDZ = 20;");
|
|
test(function() {
|
|
let threw = false;
|
|
try {
|
|
f();
|
|
} catch(e) {
|
|
threw = true;
|
|
assert(e.toString() === "ReferenceError: Cannot access uninitialized variable.")
|
|
}
|
|
assert(threw);
|
|
});
|
|
|
|
f = new Function("", "ClassTDZ");
|
|
test(function() {
|
|
let threw = false;
|
|
try {
|
|
f();
|
|
} catch(e) {
|
|
threw = true;
|
|
assert(e.toString() === "ReferenceError: Cannot access uninitialized variable.")
|
|
}
|
|
assert(threw);
|
|
});
|
|
|
|
|
|
const constTDZ = 25;
|
|
let letTDZ = 25;
|
|
class ClassTDZ { }
|
|
|