| 1 |
|
| 2 |
load(libdir + 'asserts.js'); |
| 3 |
|
| 4 |
// globals: |
| 5 |
a = b = get = set = eval = arguments = 10; |
| 6 |
|
| 7 |
assertEq({arguments}.arguments, 10); |
| 8 |
|
| 9 |
var o = {a, b: b, get, set: set}; |
| 10 |
assertEq(o.a, 10); |
| 11 |
assertEq(o.b, 10); |
| 12 |
assertEq(o.get, 10); |
| 13 |
assertEq(o.set, 10); |
| 14 |
|
| 15 |
var names = ['a', 'get', 'set', 'eval']; |
| 16 |
// global |
| 17 |
names.forEach(ident => |
| 18 |
assertEq(new Function('return {' + ident + '}.' + ident + ';')(), 10)); |
| 19 |
// local |
| 20 |
names.forEach(ident => |
| 21 |
assertEq(new Function('var ' + ident + ' = 20; return {' + ident + '}.' + ident + ';')(), 20)); |
| 22 |
// scope |
| 23 |
names.forEach(ident => |
| 24 |
assertEq(new Function('var ' + ident + ' = 30; return (function () {return {' + ident + '}.' + ident + ';})();')(), 30)); |
| 25 |
|
| 26 |
var reserved = [ |
| 27 |
'break', |
| 28 |
'do', |
| 29 |
'in', |
| 30 |
'typeof', |
| 31 |
'case', |
| 32 |
'else', |
| 33 |
'instanceof', |
| 34 |
'var', |
| 35 |
'catch', |
| 36 |
'export', |
| 37 |
'new', |
| 38 |
'void', |
| 39 |
'class', |
| 40 |
'extends', |
| 41 |
'return', |
| 42 |
'while', |
| 43 |
'const', |
| 44 |
'finally', |
| 45 |
'super', |
| 46 |
'with', |
| 47 |
'continue', |
| 48 |
'for', |
| 49 |
'switch', |
| 50 |
'debugger', |
| 51 |
'function', |
| 52 |
'this', |
| 53 |
'delete', |
| 54 |
'import', |
| 55 |
'try', |
| 56 |
'enum', |
| 57 |
'null', |
| 58 |
'true', |
| 59 |
'false' |
| 60 |
]; |
| 61 |
|
| 62 |
// non-identifiers should also throw |
| 63 |
var nonidents = [ |
| 64 |
'"str"', |
| 65 |
'0' |
| 66 |
]; |
| 67 |
|
| 68 |
reserved.concat(nonidents).forEach(ident => |
| 69 |
assertThrowsInstanceOf(() => new Function('return {' + ident + '}'), SyntaxError)); |
| 70 |
|
| 71 |
var reservedStrict = [ |
| 72 |
'implements', |
| 73 |
'interface', |
| 74 |
'package', |
| 75 |
'private', |
| 76 |
'protected', |
| 77 |
'public', |
| 78 |
'static', |
| 79 |
// XXX: according to 12.1.1, these should only be errors in strict code: |
| 80 |
// see https://bugzilla.mozilla.org/show_bug.cgi?id=1032150 |
| 81 |
//'let', |
| 82 |
//'yield' |
| 83 |
]; |
| 84 |
|
| 85 |
reservedStrict.forEach(ident => |
| 86 |
assertEq(new Function('var ' + ident + ' = 10; return {' + ident + '}.' + ident + ';')(), 10)); |
| 87 |
|
| 88 |
reservedStrict.concat(['let', 'yield']).forEach(ident => |
| 89 |
assertThrowsInstanceOf(() => new Function('"use strict"; return {' + ident + '}'), SyntaxError)); |
| 90 |
|