|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/licenses/publicdomain/ |
|
4 */ |
|
5 |
|
6 //----------------------------------------------------------------------------- |
|
7 var BUGNUMBER = 497869; |
|
8 var summary = "Implement FutureReservedWords per-spec"; |
|
9 |
|
10 print(BUGNUMBER + ": " + summary); |
|
11 |
|
12 /************** |
|
13 * BEGIN TEST * |
|
14 **************/ |
|
15 |
|
16 var futureReservedWords = |
|
17 [ |
|
18 "class", |
|
19 // "const", // Mozilla extension enabled even for versionless code |
|
20 "enum", |
|
21 "export", |
|
22 "extends", |
|
23 "import", |
|
24 "super", |
|
25 ]; |
|
26 |
|
27 var strictFutureReservedWords = |
|
28 [ |
|
29 "implements", |
|
30 "interface", |
|
31 "let", // enabled: this file doesn't execute as JS1.7 |
|
32 "package", |
|
33 "private", |
|
34 "protected", |
|
35 "public", |
|
36 "static", |
|
37 "yield", // enabled: this file doesn't execute as JS1.7 |
|
38 ]; |
|
39 |
|
40 function testWord(word, expectNormal, expectStrict) |
|
41 { |
|
42 var actual, status; |
|
43 |
|
44 // USE AS LHS FOR ASSIGNMENT |
|
45 |
|
46 actual = ""; |
|
47 status = summary + ": " + word + ": normal assignment"; |
|
48 try |
|
49 { |
|
50 eval(word + " = 'foo';"); |
|
51 actual = "no error"; |
|
52 } |
|
53 catch(e) |
|
54 { |
|
55 actual = e.name; |
|
56 status += ", " + e.name + ": " + e.message + " "; |
|
57 } |
|
58 reportCompare(expectNormal, actual, status); |
|
59 |
|
60 actual = ""; |
|
61 status = summary + ": " + word + ": strict assignment"; |
|
62 try |
|
63 { |
|
64 eval("'use strict'; " + word + " = 'foo';"); |
|
65 actual = "no error"; |
|
66 } |
|
67 catch(e) |
|
68 { |
|
69 actual = e.name; |
|
70 status += ", " + e.name + ": " + e.message + " "; |
|
71 } |
|
72 reportCompare(expectStrict, actual, status); |
|
73 |
|
74 // USE IN VARIABLE DECLARATION |
|
75 |
|
76 actual = ""; |
|
77 status = summary + ": " + word + ": normal var"; |
|
78 try |
|
79 { |
|
80 eval("var " + word + ";"); |
|
81 actual = "no error"; |
|
82 } |
|
83 catch (e) |
|
84 { |
|
85 actual = e.name; |
|
86 status += ", " + e.name + ": " + e.message + " "; |
|
87 } |
|
88 reportCompare(expectNormal, actual, status); |
|
89 |
|
90 actual = ""; |
|
91 status = summary + ": " + word + ": strict var"; |
|
92 try |
|
93 { |
|
94 eval("'use strict'; var " + word + ";"); |
|
95 actual = "no error"; |
|
96 } |
|
97 catch (e) |
|
98 { |
|
99 actual = e.name; |
|
100 status += ", " + e.name + ": " + e.message + " "; |
|
101 } |
|
102 reportCompare(expectStrict, actual, status); |
|
103 |
|
104 // USE IN FOR-IN VARIABLE DECLARATION |
|
105 |
|
106 actual = ""; |
|
107 status = summary + ": " + word + ": normal for-in var"; |
|
108 try |
|
109 { |
|
110 eval("for (var " + word + " in {});"); |
|
111 actual = "no error"; |
|
112 } |
|
113 catch (e) |
|
114 { |
|
115 actual = e.name; |
|
116 status += ", " + e.name + ": " + e.message + " "; |
|
117 } |
|
118 reportCompare(expectNormal, actual, status); |
|
119 |
|
120 actual = ""; |
|
121 status = summary + ": " + word + ": strict for-in var"; |
|
122 try |
|
123 { |
|
124 eval("'use strict'; for (var " + word + " in {});"); |
|
125 actual = "no error"; |
|
126 } |
|
127 catch (e) |
|
128 { |
|
129 actual = e.name; |
|
130 status += ", " + e.name + ": " + e.message + " "; |
|
131 } |
|
132 reportCompare(expectStrict, actual, status); |
|
133 |
|
134 // USE AS CATCH IDENTIFIER |
|
135 |
|
136 actual = ""; |
|
137 status = summary + ": " + word + ": normal var"; |
|
138 try |
|
139 { |
|
140 eval("try { } catch (" + word + ") { }"); |
|
141 actual = "no error"; |
|
142 } |
|
143 catch (e) |
|
144 { |
|
145 actual = e.name; |
|
146 status += ", " + e.name + ": " + e.message + " "; |
|
147 } |
|
148 reportCompare(expectNormal, actual, status); |
|
149 |
|
150 actual = ""; |
|
151 status = summary + ": " + word + ": strict var"; |
|
152 try |
|
153 { |
|
154 eval("'use strict'; try { } catch (" + word + ") { }"); |
|
155 actual = "no error"; |
|
156 } |
|
157 catch (e) |
|
158 { |
|
159 actual = e.name; |
|
160 status += ", " + e.name + ": " + e.message + " "; |
|
161 } |
|
162 reportCompare(expectStrict, actual, status); |
|
163 |
|
164 // USE AS LABEL |
|
165 |
|
166 actual = ""; |
|
167 status = summary + ": " + word + ": normal label"; |
|
168 try |
|
169 { |
|
170 eval(word + ": while (false);"); |
|
171 actual = "no error"; |
|
172 } |
|
173 catch (e) |
|
174 { |
|
175 actual = e.name; |
|
176 status += ", " + e.name + ": " + e.message + " "; |
|
177 } |
|
178 reportCompare(expectNormal, actual, status); |
|
179 |
|
180 actual = ""; |
|
181 status = summary + ": " + word + ": strict label"; |
|
182 try |
|
183 { |
|
184 eval("'use strict'; " + word + ": while (false);"); |
|
185 actual = "no error"; |
|
186 } |
|
187 catch (e) |
|
188 { |
|
189 actual = e.name; |
|
190 status += ", " + e.name + ": " + e.message + " "; |
|
191 } |
|
192 reportCompare(expectStrict, actual, status); |
|
193 |
|
194 // USE AS ARGUMENT NAME IN FUNCTION DECLARATION |
|
195 |
|
196 actual = ""; |
|
197 status = summary + ": " + word + ": normal function argument"; |
|
198 try |
|
199 { |
|
200 eval("function foo(" + word + ") { }"); |
|
201 actual = "no error"; |
|
202 } |
|
203 catch (e) |
|
204 { |
|
205 actual = e.name; |
|
206 status += ", " + e.name + ": " + e.message + " "; |
|
207 } |
|
208 reportCompare(expectNormal, actual, status); |
|
209 |
|
210 actual = ""; |
|
211 status = summary + ": " + word + ": strict function argument"; |
|
212 try |
|
213 { |
|
214 eval("'use strict'; function foo(" + word + ") { }"); |
|
215 actual = "no error"; |
|
216 } |
|
217 catch (e) |
|
218 { |
|
219 actual = e.name; |
|
220 status += ", " + e.name + ": " + e.message + " "; |
|
221 } |
|
222 reportCompare(expectStrict, actual, status); |
|
223 |
|
224 actual = ""; |
|
225 status = summary + ": " + word + ": function argument retroactively strict"; |
|
226 try |
|
227 { |
|
228 eval("function foo(" + word + ") { 'use strict'; }"); |
|
229 actual = "no error"; |
|
230 } |
|
231 catch (e) |
|
232 { |
|
233 actual = e.name; |
|
234 status += ", " + e.name + ": " + e.message + " "; |
|
235 } |
|
236 reportCompare(expectStrict, actual, status); |
|
237 |
|
238 // USE AS ARGUMENT NAME IN FUNCTION EXPRESSION |
|
239 |
|
240 actual = ""; |
|
241 status = summary + ": " + word + ": normal function expression argument"; |
|
242 try |
|
243 { |
|
244 eval("var s = (function foo(" + word + ") { });"); |
|
245 actual = "no error"; |
|
246 } |
|
247 catch (e) |
|
248 { |
|
249 actual = e.name; |
|
250 status += ", " + e.name + ": " + e.message + " "; |
|
251 } |
|
252 reportCompare(expectNormal, actual, status); |
|
253 |
|
254 actual = ""; |
|
255 status = summary + ": " + word + ": strict function expression argument"; |
|
256 try |
|
257 { |
|
258 eval("'use strict'; var s = (function foo(" + word + ") { });"); |
|
259 actual = "no error"; |
|
260 } |
|
261 catch (e) |
|
262 { |
|
263 actual = e.name; |
|
264 status += ", " + e.name + ": " + e.message + " "; |
|
265 } |
|
266 reportCompare(expectStrict, actual, status); |
|
267 |
|
268 actual = ""; |
|
269 status = summary + ": " + word + ": function expression argument retroactively strict"; |
|
270 try |
|
271 { |
|
272 eval("var s = (function foo(" + word + ") { 'use strict'; });"); |
|
273 actual = "no error"; |
|
274 } |
|
275 catch (e) |
|
276 { |
|
277 actual = e.name; |
|
278 status += ", " + e.name + ": " + e.message + " "; |
|
279 } |
|
280 reportCompare(expectStrict, actual, status); |
|
281 |
|
282 // USE AS ARGUMENT NAME WITH FUNCTION CONSTRUCTOR |
|
283 |
|
284 actual = ""; |
|
285 status = summary + ": " + word + ": argument with normal Function"; |
|
286 try |
|
287 { |
|
288 Function(word, "return 17"); |
|
289 actual = "no error"; |
|
290 } |
|
291 catch (e) |
|
292 { |
|
293 actual = e.name; |
|
294 status += ", " + e.name + ": " + e.message + " "; |
|
295 } |
|
296 reportCompare(expectNormal, actual, status); |
|
297 |
|
298 actual = ""; |
|
299 status = summary + ": " + word + ": argument with strict Function"; |
|
300 try |
|
301 { |
|
302 Function(word, "'use strict'; return 17"); |
|
303 actual = "no error"; |
|
304 } |
|
305 catch (e) |
|
306 { |
|
307 actual = e.name; |
|
308 status += ", " + e.name + ": " + e.message + " "; |
|
309 } |
|
310 reportCompare(expectStrict, actual, status); |
|
311 |
|
312 // USE AS ARGUMENT NAME IN PROPERTY SETTER |
|
313 |
|
314 actual = ""; |
|
315 status = summary + ": " + word + ": normal property setter argument"; |
|
316 try |
|
317 { |
|
318 eval("var o = { set x(" + word + ") { } };"); |
|
319 actual = "no error"; |
|
320 } |
|
321 catch (e) |
|
322 { |
|
323 actual = e.name; |
|
324 status += ", " + e.name + ": " + e.message + " "; |
|
325 } |
|
326 reportCompare(expectNormal, actual, status); |
|
327 |
|
328 actual = ""; |
|
329 status = summary + ": " + word + ": strict property setter argument"; |
|
330 try |
|
331 { |
|
332 eval("'use strict'; var o = { set x(" + word + ") { } };"); |
|
333 actual = "no error"; |
|
334 } |
|
335 catch (e) |
|
336 { |
|
337 actual = e.name; |
|
338 status += ", " + e.name + ": " + e.message + " "; |
|
339 } |
|
340 reportCompare(expectStrict, actual, status); |
|
341 |
|
342 actual = ""; |
|
343 status = summary + ": " + word + ": property setter argument retroactively strict"; |
|
344 try |
|
345 { |
|
346 eval("var o = { set x(" + word + ") { 'use strict'; } };"); |
|
347 actual = "no error"; |
|
348 } |
|
349 catch (e) |
|
350 { |
|
351 actual = e.name; |
|
352 status += ", " + e.name + ": " + e.message + " "; |
|
353 } |
|
354 reportCompare(expectStrict, actual, status); |
|
355 |
|
356 // USE AS FUNCTION NAME IN FUNCTION DECLARATION |
|
357 |
|
358 actual = ""; |
|
359 status = summary + ": " + word + ": normal function name"; |
|
360 try |
|
361 { |
|
362 eval("function " + word + "() { }"); |
|
363 actual = "no error"; |
|
364 } |
|
365 catch (e) |
|
366 { |
|
367 actual = e.name; |
|
368 status += ", " + e.name + ": " + e.message + " "; |
|
369 } |
|
370 reportCompare(expectNormal, actual, status); |
|
371 |
|
372 actual = ""; |
|
373 status = summary + ": " + word + ": strict function name"; |
|
374 try |
|
375 { |
|
376 eval("'use strict'; function " + word + "() { }"); |
|
377 actual = "no error"; |
|
378 } |
|
379 catch (e) |
|
380 { |
|
381 actual = e.name; |
|
382 status += ", " + e.name + ": " + e.message + " "; |
|
383 } |
|
384 reportCompare(expectStrict, actual, status); |
|
385 |
|
386 actual = ""; |
|
387 status = summary + ": " + word + ": function name retroactively strict"; |
|
388 try |
|
389 { |
|
390 eval("function " + word + "() { 'use strict'; }"); |
|
391 actual = "no error"; |
|
392 } |
|
393 catch (e) |
|
394 { |
|
395 actual = e.name; |
|
396 status += ", " + e.name + ": " + e.message + " "; |
|
397 } |
|
398 reportCompare(expectStrict, actual, status); |
|
399 |
|
400 // USE AS FUNCTION NAME IN FUNCTION EXPRESSION |
|
401 |
|
402 actual = ""; |
|
403 status = summary + ": " + word + ": normal function expression name"; |
|
404 try |
|
405 { |
|
406 eval("var s = (function " + word + "() { });"); |
|
407 actual = "no error"; |
|
408 } |
|
409 catch (e) |
|
410 { |
|
411 actual = e.name; |
|
412 status += ", " + e.name + ": " + e.message + " "; |
|
413 } |
|
414 reportCompare(expectNormal, actual, status); |
|
415 |
|
416 actual = ""; |
|
417 status = summary + ": " + word + ": strict function expression name"; |
|
418 try |
|
419 { |
|
420 eval("'use strict'; var s = (function " + word + "() { });"); |
|
421 actual = "no error"; |
|
422 } |
|
423 catch (e) |
|
424 { |
|
425 actual = e.name; |
|
426 status += ", " + e.name + ": " + e.message + " "; |
|
427 } |
|
428 reportCompare(expectStrict, actual, status); |
|
429 |
|
430 actual = ""; |
|
431 status = summary + ": " + word + ": function expression name retroactively strict"; |
|
432 try |
|
433 { |
|
434 eval("var s = (function " + word + "() { 'use strict'; });"); |
|
435 actual = "no error"; |
|
436 } |
|
437 catch (e) |
|
438 { |
|
439 actual = e.name; |
|
440 status += ", " + e.name + ": " + e.message + " "; |
|
441 } |
|
442 reportCompare(expectStrict, actual, status); |
|
443 } |
|
444 |
|
445 function testFutureReservedWord(word) |
|
446 { |
|
447 testWord(word, "SyntaxError", "SyntaxError"); |
|
448 } |
|
449 |
|
450 function testStrictFutureReservedWord(word) |
|
451 { |
|
452 testWord(word, "no error", "SyntaxError"); |
|
453 } |
|
454 |
|
455 futureReservedWords.forEach(testFutureReservedWord); |
|
456 strictFutureReservedWords.forEach(testStrictFutureReservedWord); |
|
457 |
|
458 /******************************************************************************/ |
|
459 |
|
460 if (typeof reportCompare === "function") |
|
461 reportCompare(true, true); |
|
462 |
|
463 print("All tests passed!"); |