js/src/jit-test/tests/parser/bug-889628.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:57738c6ed0ed
1 // Destructuring assignment to eval or arguments in destructuring is a SyntaxError
2
3 load(libdir + "asserts.js");
4
5 var patterns = [
6 "[_]",
7 "[a, b, _]",
8 "[[_]]",
9 "[[], [{}, [_]]]",
10 "{x:_}",
11 "{x:y, z:_}",
12 "{0:_}",
13 "{_}",
14 //"[..._]"
15 ];
16
17 // If the assertion below fails, congratulations! It means you have added
18 // spread operator support to destructuring assignment. Simply uncomment the
19 // "[..._]" case above. Then delete this comment and assertion.
20 assertThrowsInstanceOf(() => Function("[...x] = [1]"), ReferenceError);
21
22 for (var pattern of patterns) {
23 var stmt = pattern + " = obj";
24 if (stmt[0] == "{")
25 stmt = "(" + stmt + ")";
26 stmt += ";"
27
28 // stmt is a legal statement...
29 Function(stmt);
30
31 // ...but not if you replace _ with one of these two names.
32 for (var name of ["eval", "arguments"]) {
33 var s = stmt.replace("_", name);
34 assertThrowsInstanceOf(() => Function(s), SyntaxError);
35 assertThrowsInstanceOf(() => eval(s), SyntaxError);
36 assertThrowsInstanceOf(() => eval("'use strict'; " + s), SyntaxError);
37 }
38 }

mercurial