Debian Codegraph @

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

raw
1 // Destructuring assignment to eval or arguments in destructuring is a SyntaxError
2 // in strict mode
3
4 load(libdir + "asserts.js");
5
6 var patterns = [
7 "[_]",
8 "[a, b, _]",
9 "[[_]]",
10 "[[], [{}, [_]]]",
11 "{x:_}",
12 "{x:y, z:_}",
13 "{0:_}",
14 "{_}",
15 "[..._]"
16 ];
17
18 for (var pattern of patterns) {
19 var stmt = pattern + " = obj";
20 if (stmt[0] == "{")
21 stmt = "(" + stmt + ")";
22 stmt += ";"
23
24 // stmt is a legal statement...
25 Function(stmt);
26
27 // ...but not if you replace _ with one of these two names.
28 for (var name of ["eval", "arguments"]) {
29 var s = stmt.replace("_", name);
30 Function(s);
31 assertThrowsInstanceOf(() => Function("'use strict'; " + s), SyntaxError);
32 }
33 }