summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/arrow-functions/arrow-not-as-end-of-statement.js
blob: 53926d65da460f1dc01de1062bee4cdf0634cdc3 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// Grab-bag of ArrowFunctions with block bodies appearing in contexts where the
// subsequent token-examination must use the Operand modifier to avoid an
// assertion.

assertEq(`x ${a => {}} z`, "x a => {} z");

for (a => {}; ; )
  break;

for (; a => {}; )
  break;

for (; ; a => {})
  break;

Function.prototype[Symbol.iterator] = function() { return { next() { return { done: true }; } }; };
for (let m of 0 ? 1 : a => {})
  assertEq(true, false);
for (let [m] of 0 ? 1 : a => {})
  assertEq(true, false);
delete Function.prototype[Symbol.iterator];

for (let w in 0 ? 1 : a => {})
  break;
for (let [w] in 0 ? 1 : a => {})
  break;

function* stargen()
{
  yield a => {}
  /Q/g;

  var first = true;
  Function.prototype[Symbol.iterator] = function() {
    return {
      next() {
        var res = { done: true, value: 8675309 };
        if (first)
        {
          res = { value: "fnord", done: false };
          first = false;
        }

        return res;
      }
    };
  };


  yield* a => {}
  /Q/g;

  delete Function.prototype[Symbol.iterator];

  yield 99;
}
var gen = stargen();
assertEq(typeof gen.next().value, "function");
var result = gen.next();
assertEq(result.value, "fnord");
assertEq(result.done, false);
assertEq(gen.next().value, 99);
assertEq(gen.next().done, true);

switch (1)
{
  case a => {}:
   break;
}

assertEq(0[a => {}], undefined);

class Y {};
class X extends Y { constructor() { super[a => {}](); } };

if (a => {})
  assertEq(true, true);
else
  assertEq(true, false);

switch (a => {})
{
}

with (a => {});

assertEq(typeof (a => {}), "function");
assertEq(typeof (a => b => {}), "function");

for (var x in y => {})
  continue;

assertEq(eval("a => {}, 17, 42;"), 42);
assertEq(eval("42, a => {}, 17;"), 17);
assertEq(typeof eval("17, 42, a => {};"), "function");

assertEq(eval("1 ? 0 : a => {}, 17, 42;"), 42);
assertEq(eval("42, 1 ? 0 : a => {}, 17;"), 17);
assertEq(eval("17, 42, 1 ? 0 : a => {};"), 0);

var z = { x: 0 ? 1 : async a => {} };
assertEq(typeof z.x, "function");

var q = 0 ? 1 : async () => {};
assertEq(typeof q, "function");

var m = 0 ? 42 : m = foo => {} // ASI
/Q/g;
assertEq(typeof m, "function");

var { q: w = 0 ? 1 : a => {} } = {};
assertEq(typeof w, "function");

Function.prototype.c = 42;
var { c } = 0 ? 1 : a => {} // ASI
/Q/g;
assertEq(c, 42);

var c = 0 ? 1 : a => {}
/Q/g;
assertEq(typeof c, "function");
delete Function.prototype.c;

assertEq(typeof eval(0 ? 1 : a => {}), "function");

var zoom = 1 ? a => {} : 357;
assertEq(typeof zoom, "function");

var { b = 0 ? 1 : a => {} } = {};
assertEq(typeof b, "function");

var [k = 0 ? 1 : a => {}] = [];
assertEq(typeof k, "function");

assertEq(typeof [0 ? 1 : a => {}][0], "function");

Function.prototype[Symbol.iterator] = function() { return { next() { return { done: true }; } }; };
assertEq([...0 ? 1 : a => {}].length, 0);
delete Function.prototype[Symbol.iterator];

var props = Object.getOwnPropertyNames({ ...0 ? 1 : a => {} }).sort();
assertEq(props.length, 0);

function f1(x = 0 ? 1 : a => {}) { return x; }
assertEq(typeof f1(), "function");
assertEq(f1(5), 5);

var g1 = (x = 0 ? 1 : a => {}) => { return x; };
assertEq(typeof g1(), "function");
assertEq(g1(5), 5);

var h1 = async (x = 0 ? 1 : a => {}) => { return x; };
assertEq(typeof h1, "function");

function f2(m, x = 0 ? 1 : a => {}) { return x; }
assertEq(typeof f2(1), "function");
assertEq(f2(1, 5), 5);

var g2 = (m, x = 0 ? 1 : a => {}) => { return x; };
assertEq(typeof g2(1), "function");
assertEq(g2(1, 5), 5);

var h2 = async (m, x = 0 ? 1 : a => {}) => { return x; };
assertEq(typeof h2, "function");

function f3(x = 0 ? 1 : a => {}, q) { return x; }
assertEq(typeof f3(), "function");
assertEq(f3(5), 5);

var g3 = (x = 0 ? 1 : a => {}, q) => { return x; };
assertEq(typeof g3(), "function");
assertEq(g3(5), 5);

var h3 = async (x = 0 ? 1 : a => {}, q) => { return x; };
assertEq(typeof h3, "function");

var asyncf = async () => {};
assertEq(typeof asyncf, "function");

var { [0 ? 1 : a => {}]: h } = { "a => {}": "boo-urns!" };
assertEq(h, "boo-urns!");

if (typeof reportCompare === "function")
  reportCompare(true, true);