test262/implementation-contributed/javascriptcore/stress/variable-named-eval-under-tdz.js
test262-automation e9a5a7f918 [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) (#1620)
* [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)
2018-07-03 15:59:58 -04:00

88 lines
1.4 KiB
JavaScript

function shouldThrowTDZ(func) {
var hasThrown = false;
try {
func();
} catch(e) {
hasThrown = e instanceof ReferenceError;
}
if (!hasThrown)
throw new Error("Did not throw TDZ error");
}
function test(f, n = 1000) {
for (let i = 0; i < n; i++)
f();
}
test(function() {
function foo() {
eval("20");
let eval;
}
shouldThrowTDZ(foo);
});
test(function() {
function foo() {
eval("20");
let {eval} = {eval:450};
}
shouldThrowTDZ(foo);
});
test(function() {
function foo() {
eval("20");
const eval = 45;
}
shouldThrowTDZ(foo);
});
test(function() {
function foo() {
eval("20");
}
shouldThrowTDZ(foo);
let eval;
});
test(function() {
function foo() {
eval("20");
}
shouldThrowTDZ(foo);
let {eval} = {eval:450};
});
test(function() {
function foo() {
eval("20");
}
shouldThrowTDZ(foo);
const eval = 45;
});
{
let threw = false;
try {
eval(20);
let eval;
} catch(e) {
threw = e instanceof ReferenceError;
}
if (!threw)
throw new Error("Bad")
}
{
let threw = false;
try {
eval(20);
const eval = 25;
} catch(e) {
threw = e instanceof ReferenceError;
}
if (!threw)
throw new Error("Bad")
}