Debian Codegraph @

js/src/jit-test/tests/basic/destructuring-rest-identifiers.js

raw
1
2 load(libdir + 'asserts.js');
3 load(libdir + 'eqArrayHelper.js');
4
5 var reserved = [
6 'break',
7 'do',
8 'in',
9 'typeof',
10 'case',
11 'else',
12 'instanceof',
13 'var',
14 'catch',
15 'export',
16 'new',
17 'void',
18 'class',
19 'extends',
20 'return',
21 'while',
22 'const',
23 'finally',
24 'super',
25 'with',
26 'continue',
27 'for',
28 'switch',
29 'debugger',
30 'function',
31 'this',
32 'delete',
33 'import',
34 'try',
35 'enum',
36 'null',
37 'true',
38 'false'
39 ];
40 reserved.forEach(ident => {
41 assertThrowsInstanceOf(() => new Function('var [...' + ident + '] = []'), SyntaxError);
42 });
43
44 var strictIdentifiers = [
45 'yield',
46 'let',
47 'eval',
48 'arguments',
49 'implements',
50 'interface',
51 'package',
52 'private',
53 'protected',
54 'public',
55 'static'
56 ];
57
58 strictIdentifiers.forEach(ident =>
59 assertThrowsInstanceOf(() =>
60 new Function('"use strict"; [...' + ident + '] = []'), SyntaxError));
61
62 var globalEval = eval;
63 strictIdentifiers.forEach(ident => {
64 globalEval(ident + ' = null');
65 assertEqArray(new Function('input', '[, ...' + ident + '] = input;' +
66 'return ' + ident
67 )([1, 2, 3]), [2, 3]);
68 });
69