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)
50 lines
2.6 KiB
JavaScript
50 lines
2.6 KiB
JavaScript
// Check that const variables can't be assigned to from for-in/for-of.
|
|
// https://bugs.webkit.org/show_bug.cgi?id=156673
|
|
|
|
expect_nothrow = function(why, f) {
|
|
f();
|
|
}
|
|
|
|
expect_throw = function(why, f) {
|
|
threw = false;
|
|
try {
|
|
f();
|
|
} catch (e) {
|
|
if (e.toString() != "TypeError: Attempted to assign to readonly property.")
|
|
throw Error("expected a TypeError, got " + e.toString());
|
|
threw = true;
|
|
}
|
|
if (!threw)
|
|
throw Error("expected to throw");
|
|
}
|
|
|
|
// for-in
|
|
|
|
expect_nothrow("regular for-in", function() { for (x in [1,2,3]) x; });
|
|
expect_nothrow("var for-in", function() { for (var x in [1,2,3]) x; });
|
|
expect_nothrow("let for-in", function() { for (let x in [1,2,3]) x; });
|
|
expect_nothrow("for-in with const variable", function() { for (const x in [1,2,3]) x; });
|
|
expect_nothrow("for-in which never iterates", function() { const x = 20; for (x in []) x; });
|
|
|
|
expect_throw("for-in on const from func's scope", function() { const x = 20; for (x in [1,2,3]) x; });
|
|
expect_throw("same, with intervening capture", function() { const x = 20; capture = function() { x; }; for (x in [1,2,3]) x; });
|
|
expect_throw("same, iterating in capture", function() { const x = 20; capture = function() { for (x in [1,2,3]) x; }; capture(); });
|
|
|
|
// for-of
|
|
|
|
expect_nothrow("regular for-of", function() { for (x of [1,2,3]) x; });
|
|
expect_nothrow("var for-of", function() { for (var x of [1,2,3]) x; });
|
|
expect_nothrow("let for-of", function() { for (let x of [1,2,3]) x; });
|
|
expect_nothrow("for-of with const variable", function() { for (const x of [1,2,3]) x; });
|
|
expect_nothrow("for-of which never iterates", function() { const x = 20; for (x of []) x; });
|
|
|
|
expect_throw("for-of on const from func's scope", function() { const x = 20; for (x of [1,2,3]) x; });
|
|
expect_throw("same, with intervening capture", function() { const x = 20; capture = function() { x; }; for (x of [1,2,3]) x; });
|
|
expect_throw("same, iterating in capture", function() { const x = 20; capture = function() { for (x of [1,2,3]) x; }; capture(); });
|
|
|
|
expect_throw("bad destructuring", function() { let arr = [{x:20}]; const x = 50; for ({x} of arr) x; });
|
|
expect_nothrow("good destructuring", function() { let arr = [{x:20}]; const x = 50; for ({x : foo} of arr) x; });
|
|
expect_nothrow("const good destructuring", function() { let arr = [{x:20}]; const x = 50; for (const {x} of arr) x; });
|
|
expect_nothrow("let good destructuring", function() { let arr = [{x:20}]; const x = 50; for (let {x} of arr) x; });
|
|
// Note: `var {x}` would shadow `const x` and therefore fail.
|