Debian Codegraph @

js/src/tests/non262/arrow-functions/arrow-not-as-end-of-statement.js

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 // Grab-bag of ArrowFunctions with block bodies appearing in contexts where the
6 // subsequent token-examination must use the Operand modifier to avoid an
7 // assertion.
8
9 assertEq(`x ${a => {}} z`, "x a => {} z");
10
11 for (a => {}; ; )
12 break;
13
14 for (; a => {}; )
15 break;
16
17 for (; ; a => {})
18 break;
19
20 Function.prototype[Symbol.iterator] = function() { return { next() { return { done: true }; } }; };
21 for (let m of 0 ? 1 : a => {})
22 assertEq(true, false);
23 for (let [m] of 0 ? 1 : a => {})
24 assertEq(true, false);
25 delete Function.prototype[Symbol.iterator];
26
27 for (let w in 0 ? 1 : a => {})
28 break;
29 for (let [w] in 0 ? 1 : a => {})
30 break;
31
32 function* stargen()
33 {
34 yield a => {}
35 /Q/g;
36
37 var first = true;
38 Function.prototype[Symbol.iterator] = function() {
39 return {
40 next() {
41 var res = { done: true, value: 8675309 };
42 if (first)
43 {
44 res = { value: "fnord", done: false };
45 first = false;
46 }
47
48 return res;
49 }
50 };
51 };
52
53
54 yield* a => {}
55 /Q/g;
56
57 delete Function.prototype[Symbol.iterator];
58
59 yield 99;
60 }
61 var gen = stargen();
62 assertEq(typeof gen.next().value, "function");
63 var result = gen.next();
64 assertEq(result.value, "fnord");
65 assertEq(result.done, false);
66 assertEq(gen.next().value, 99);
67 assertEq(gen.next().done, true);
68
69 switch (1)
70 {
71 case a => {}:
72 break;
73 }
74
75 assertEq(0[a => {}], undefined);
76
77 class Y {};
78 class X extends Y { constructor() { super[a => {}](); } };
79
80 if (a => {})
81 assertEq(true, true);
82 else
83 assertEq(true, false);
84
85 switch (a => {})
86 {
87 }
88
89 with (a => {});
90
91 assertEq(typeof (a => {}), "function");
92 assertEq(typeof (a => b => {}), "function");
93
94 for (var x in y => {})
95 continue;
96
97 assertEq(eval("a => {}, 17, 42;"), 42);
98 assertEq(eval("42, a => {}, 17;"), 17);
99 assertEq(typeof eval("17, 42, a => {};"), "function");
100
101 assertEq(eval("1 ? 0 : a => {}, 17, 42;"), 42);
102 assertEq(eval("42, 1 ? 0 : a => {}, 17;"), 17);
103 assertEq(eval("17, 42, 1 ? 0 : a => {};"), 0);
104
105 var z = { x: 0 ? 1 : async a => {} };
106 assertEq(typeof z.x, "function");
107
108 var q = 0 ? 1 : async () => {};
109 assertEq(typeof q, "function");
110
111 var m = 0 ? 42 : m = foo => {} // ASI
112 /Q/g;
113 assertEq(typeof m, "function");
114
115 var { q: w = 0 ? 1 : a => {} } = {};
116 assertEq(typeof w, "function");
117
118 Function.prototype.c = 42;
119 var { c } = 0 ? 1 : a => {} // ASI
120 /Q/g;
121 assertEq(c, 42);
122
123 var c = 0 ? 1 : a => {}
124 /Q/g;
125 assertEq(typeof c, "function");
126 delete Function.prototype.c;
127
128 assertEq(typeof eval(0 ? 1 : a => {}), "function");
129
130 var zoom = 1 ? a => {} : 357;
131 assertEq(typeof zoom, "function");
132
133 var { b = 0 ? 1 : a => {} } = {};
134 assertEq(typeof b, "function");
135
136 var [k = 0 ? 1 : a => {}] = [];
137 assertEq(typeof k, "function");
138
139 assertEq(typeof [0 ? 1 : a => {}][0], "function");
140
141 Function.prototype[Symbol.iterator] = function() { return { next() { return { done: true }; } }; };
142 assertEq([...0 ? 1 : a => {}].length, 0);
143 delete Function.prototype[Symbol.iterator];
144
145 var props = Object.getOwnPropertyNames({ ...0 ? 1 : a => {} }).sort();
146 assertEq(props.length, 0);
147
148 function f1(x = 0 ? 1 : a => {}) { return x; }
149 assertEq(typeof f1(), "function");
150 assertEq(f1(5), 5);
151
152 var g1 = (x = 0 ? 1 : a => {}) => { return x; };
153 assertEq(typeof g1(), "function");
154 assertEq(g1(5), 5);
155
156 var h1 = async (x = 0 ? 1 : a => {}) => { return x; };
157 assertEq(typeof h1, "function");
158
159 function f2(m, x = 0 ? 1 : a => {}) { return x; }
160 assertEq(typeof f2(1), "function");
161 assertEq(f2(1, 5), 5);
162
163 var g2 = (m, x = 0 ? 1 : a => {}) => { return x; };
164 assertEq(typeof g2(1), "function");
165 assertEq(g2(1, 5), 5);
166
167 var h2 = async (m, x = 0 ? 1 : a => {}) => { return x; };
168 assertEq(typeof h2, "function");
169
170 function f3(x = 0 ? 1 : a => {}, q) { return x; }
171 assertEq(typeof f3(), "function");
172 assertEq(f3(5), 5);
173
174 var g3 = (x = 0 ? 1 : a => {}, q) => { return x; };
175 assertEq(typeof g3(), "function");
176 assertEq(g3(5), 5);
177
178 var h3 = async (x = 0 ? 1 : a => {}, q) => { return x; };
179 assertEq(typeof h3, "function");
180
181 var asyncf = async () => {};
182 assertEq(typeof asyncf, "function");
183
184 var { [0 ? 1 : a => {}]: h } = { "a => {}": "boo-urns!" };
185 assertEq(h, "boo-urns!");
186
187 if (typeof reportCompare === "function")
188 reportCompare(true, true);