summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/object-shorthand.js
blob: 934f4668002e7c0eea99113f3c056f4ba7d2e6e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

load(libdir + 'asserts.js');

// globals:
a = b = get = set = eval = arguments = 10;

assertEq({arguments}.arguments, 10);

var o = {a, b: b, get, set: set};
assertEq(o.a, 10);
assertEq(o.b, 10);
assertEq(o.get, 10);
assertEq(o.set, 10);

var names = ['a', 'get', 'set', 'eval'];
// global
names.forEach(ident =>
  assertEq(new Function('return {' + ident + '}.' + ident + ';')(), 10));
// local
names.forEach(ident =>
  assertEq(new Function('var ' + ident + ' = 20; return {' + ident + '}.' + ident + ';')(), 20));
// scope
names.forEach(ident =>
  assertEq(new Function('var ' + ident + ' = 30; return (function () {return {' + ident + '}.' + ident + ';})();')(), 30));

var reserved = [
  'break',
  'do',
  'in',
  'typeof',
  'case',
  'else',
  'instanceof',
  'var',
  'catch',
  'export',
  'new',
  'void',
  'class',
  'extends',
  'return',
  'while',
  'const',
  'finally',
  'super',
  'with',
  'continue',
  'for',
  'switch',
  'debugger',
  'function',
  'this',
  'delete',
  'import',
  'try',
  'enum',
  'null',
  'true',
  'false'
];

// non-identifiers should also throw
var nonidents = [
  '"str"',
  '0'
];

reserved.concat(nonidents).forEach(ident =>
  assertThrowsInstanceOf(() => new Function('return {' + ident + '}'), SyntaxError));

var reservedStrict = [
  'implements',
  'interface',
  'package',
  'private',
  'protected',
  'public',
  'static',
  // XXX: according to 12.1.1, these should only be errors in strict code:
  // see https://bugzilla.mozilla.org/show_bug.cgi?id=1032150
  //'let',
  //'yield'
];

reservedStrict.forEach(ident =>
  assertEq(new Function('var ' + ident + ' = 10; return {' + ident + '}.' + ident + ';')(), 10));

reservedStrict.concat(['let', 'yield']).forEach(ident =>
  assertThrowsInstanceOf(() => new Function('"use strict"; return {' + ident + '}'), SyntaxError));