Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / mozilla / strict / script-tests / 13.1.js
blobe7e1b0928426d97a1e7ec650df6f1340377d9771
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 /*
4 * Any copyright is dedicated to the Public Domain.
5 * http://creativecommons.org/licenses/publicdomain/
6 */
8 /*
9 * In strict mode, it is a syntax error for an identifier to appear
10 * more than once in a function's argument list.
14 * The parameters of ordinary function definitions should not contain
15 * duplicate identifiers.
17 assertEq(testLenientAndStrict('function f(x,y) {}',
18 parsesSuccessfully,
19 parsesSuccessfully),
20 true);
21 assertEq(testLenientAndStrict('function f(x,x) {}',
22 parsesSuccessfully,
23 parseRaisesException(SyntaxError)),
24 true);
25 assertEq(testLenientAndStrict('function f(x,y,z,y) {}',
26 parsesSuccessfully,
27 parseRaisesException(SyntaxError)),
28 true);
30 /* Exercise the hashed local name map case. */
31 assertEq(testLenientAndStrict('function f(a,b,c,d,e,f,g,h,d) {}',
32 parsesSuccessfully,
33 parseRaisesException(SyntaxError)),
34 true);
37 * SpiderMonkey has always treated duplicates in destructuring
38 * patterns as an error. Strict mode should not affect this.
40 // Destructuring is not valid ES5 syntax.
41 assertEq(testLenientAndStrict('function f([x,y]) {}',
42 parseRaisesException(SyntaxError),
43 parseRaisesException(SyntaxError)),
44 true);
45 assertEq(testLenientAndStrict('function f([x,x]){}',
46 parseRaisesException(SyntaxError),
47 parseRaisesException(SyntaxError)),
48 true);
49 assertEq(testLenientAndStrict('function f(x,[x]){}',
50 parseRaisesException(SyntaxError),
51 parseRaisesException(SyntaxError)),
52 true);
55 * Strict rules apply to the parameters if the function's body is
56 * strict.
58 assertEq(testLenientAndStrict('function f(x,x) { "use strict" };',
59 parseRaisesException(SyntaxError),
60 parseRaisesException(SyntaxError)),
61 true);
64 * Calls to the function constructor should not be affected by the
65 * strictness of the calling code, but should be affected by the
66 * strictness of the function body.
68 assertEq(testLenientAndStrict('Function("x","x","")',
69 completesNormally,
70 completesNormally),
71 true);
72 assertEq(testLenientAndStrict('Function("x","y","")',
73 completesNormally,
74 completesNormally),
75 true);
76 assertEq(testLenientAndStrict('Function("x","x","\'use strict\'")',
77 raisesException(SyntaxError),
78 raisesException(SyntaxError)),
79 true);
80 assertEq(testLenientAndStrict('Function("x","y","\'use strict\'")',
81 completesNormally,
82 completesNormally),
83 true);
87 * The parameter lists of function expressions should not contain
88 * duplicate identifiers.
90 // This is not valid ES5 syntax.
91 assertEq(testLenientAndStrict('(function (x,x) 2)',
92 parseRaisesException(SyntaxError),
93 parseRaisesException(SyntaxError)),
94 true);
95 // This is not valid ES5 syntax.
96 assertEq(testLenientAndStrict('(function (x,y) 2)',
97 parseRaisesException(SyntaxError),
98 parseRaisesException(SyntaxError)),
99 true);
102 * All permutations of:
103 * - For the two magic identifiers 'arguments' or 'eval'
104 * - For function definitions, function expressions, expression closures,
105 * and getter and setter property definitions,
106 * - For forms that inherit their context's strictness, and forms that
107 * include their own strictness directives,
108 * - For ordinary parameters, array destructuring parameters, and
109 * object destructuring parameters,
110 * - the magic identifiers may be used to name such parameters
111 * in lenient code, but not in strict code
112 * - the magic identifiers may be used as function names in lenient code,
113 * but not in strict code
115 assertEq(testLenientAndStrict('function f(eval){}',
116 parsesSuccessfully,
117 parseRaisesException(SyntaxError)),
118 true);
119 // Destructuring is not valid ES5 syntax.
120 assertEq(testLenientAndStrict('function f([eval]){}',
121 parseRaisesException(SyntaxError),
122 parseRaisesException(SyntaxError)),
123 true);
124 // Destructuring is not valid ES5 syntax.
125 assertEq(testLenientAndStrict('function f({x:eval}){}',
126 parseRaisesException(SyntaxError),
127 parseRaisesException(SyntaxError)),
128 true);
129 assertEq(testLenientAndStrict('function eval(){}',
130 parsesSuccessfully,
131 parseRaisesException(SyntaxError)),
132 true);
133 assertEq(testLenientAndStrict('function f(eval){"use strict";}',
134 parseRaisesException(SyntaxError),
135 parseRaisesException(SyntaxError)),
136 true);
137 // Destructuring is not valid ES5 syntax.
138 assertEq(testLenientAndStrict('function f([eval]){"use strict";}',
139 parseRaisesException(SyntaxError),
140 parseRaisesException(SyntaxError)),
141 true);
142 // Destructuring is not valid ES5 syntax.
143 assertEq(testLenientAndStrict('function f({x:eval}){"use strict";}',
144 parseRaisesException(SyntaxError),
145 parseRaisesException(SyntaxError)),
146 true);
147 assertEq(testLenientAndStrict('function eval(){"use strict";}',
148 parseRaisesException(SyntaxError),
149 parseRaisesException(SyntaxError)),
150 true);
151 assertEq(testLenientAndStrict('(function f(eval){})',
152 parsesSuccessfully,
153 parseRaisesException(SyntaxError)),
154 true);
155 // Destructuring is not valid ES5 syntax.
156 assertEq(testLenientAndStrict('(function f([eval]){})',
157 parseRaisesException(SyntaxError),
158 parseRaisesException(SyntaxError)),
159 true);
160 // Destructuring is not valid ES5 syntax.
161 assertEq(testLenientAndStrict('(function f({x:eval}){})',
162 parseRaisesException(SyntaxError),
163 parseRaisesException(SyntaxError)),
164 true);
165 assertEq(testLenientAndStrict('(function eval(){})',
166 parsesSuccessfully,
167 parseRaisesException(SyntaxError)),
168 true);
169 assertEq(testLenientAndStrict('(function f(eval){"use strict";})',
170 parseRaisesException(SyntaxError),
171 parseRaisesException(SyntaxError)),
172 true);
173 assertEq(testLenientAndStrict('(function f([eval]){"use strict";})',
174 parseRaisesException(SyntaxError),
175 parseRaisesException(SyntaxError)),
176 true);
177 assertEq(testLenientAndStrict('(function f({x:eval}){"use strict";})',
178 parseRaisesException(SyntaxError),
179 parseRaisesException(SyntaxError)),
180 true);
181 assertEq(testLenientAndStrict('(function eval(){"use strict";})',
182 parseRaisesException(SyntaxError),
183 parseRaisesException(SyntaxError)),
184 true);
185 // This is not valid ES5 syntax.
186 assertEq(testLenientAndStrict('(function f(eval) 2)',
187 parseRaisesException(SyntaxError),
188 parseRaisesException(SyntaxError)),
189 true);
190 // Destructuring is not valid ES5 syntax.
191 assertEq(testLenientAndStrict('(function f([eval]) 2)',
192 parseRaisesException(SyntaxError),
193 parseRaisesException(SyntaxError)),
194 true);
195 // This is not valid ES5 syntax.
196 assertEq(testLenientAndStrict('(function f({x:eval}) 2)',
197 parseRaisesException(SyntaxError),
198 parseRaisesException(SyntaxError)),
199 true);
200 // This is not valid ES5 syntax.
201 assertEq(testLenientAndStrict('(function eval() 2)',
202 parseRaisesException(SyntaxError),
203 parseRaisesException(SyntaxError)),
204 true);
205 assertEq(testLenientAndStrict('({set x(eval){}})',
206 parsesSuccessfully,
207 parseRaisesException(SyntaxError)),
208 true);
209 // Destructuring is not valid ES5 syntax.
210 assertEq(testLenientAndStrict('({set x([eval]){}})',
211 parseRaisesException(SyntaxError),
212 parseRaisesException(SyntaxError)),
213 true);
214 // Destructuring is not valid ES5 syntax.
215 assertEq(testLenientAndStrict('({set x({x:eval}){}})',
216 parseRaisesException(SyntaxError),
217 parseRaisesException(SyntaxError)),
218 true);
219 assertEq(testLenientAndStrict('({set x(eval){"use strict";}})',
220 parseRaisesException(SyntaxError),
221 parseRaisesException(SyntaxError)),
222 true);
223 assertEq(testLenientAndStrict('({set x([eval]){"use strict";}})',
224 parseRaisesException(SyntaxError),
225 parseRaisesException(SyntaxError)),
226 true);
227 assertEq(testLenientAndStrict('({set x({x:eval}){"use strict";}})',
228 parseRaisesException(SyntaxError),
229 parseRaisesException(SyntaxError)),
230 true);
231 assertEq(testLenientAndStrict('function f(arguments){}',
232 parsesSuccessfully,
233 parseRaisesException(SyntaxError)),
234 true);
235 // Destructuring is not valid ES5 syntax.
236 assertEq(testLenientAndStrict('function f([arguments]){}',
237 parseRaisesException(SyntaxError),
238 parseRaisesException(SyntaxError)),
239 true);
240 // Destructuring is not valid ES5 syntax.
241 assertEq(testLenientAndStrict('function f({x:arguments}){}',
242 parseRaisesException(SyntaxError),
243 parseRaisesException(SyntaxError)),
244 true);
245 assertEq(testLenientAndStrict('function arguments(){}',
246 parsesSuccessfully,
247 parseRaisesException(SyntaxError)),
248 true);
249 assertEq(testLenientAndStrict('function f(arguments){"use strict";}',
250 parseRaisesException(SyntaxError),
251 parseRaisesException(SyntaxError)),
252 true);
253 // Destructuring is not valid ES5 syntax.
254 assertEq(testLenientAndStrict('function f([arguments]){"use strict";}',
255 parseRaisesException(SyntaxError),
256 parseRaisesException(SyntaxError)),
257 true);
258 assertEq(testLenientAndStrict('function f({x:arguments}){"use strict";}',
259 parseRaisesException(SyntaxError),
260 parseRaisesException(SyntaxError)),
261 true);
262 assertEq(testLenientAndStrict('function arguments(){"use strict";}',
263 parseRaisesException(SyntaxError),
264 parseRaisesException(SyntaxError)),
265 true);
266 assertEq(testLenientAndStrict('(function f(arguments){})',
267 parsesSuccessfully,
268 parseRaisesException(SyntaxError)),
269 true);
270 // Destructuring is not valid ES5 syntax.
271 assertEq(testLenientAndStrict('(function f([arguments]){})',
272 parseRaisesException(SyntaxError),
273 parseRaisesException(SyntaxError)),
274 true);
275 // Destructuring is not valid ES5 syntax.
276 assertEq(testLenientAndStrict('(function f({x:arguments}){})',
277 parseRaisesException(SyntaxError),
278 parseRaisesException(SyntaxError)),
279 true);
280 assertEq(testLenientAndStrict('(function arguments(){})',
281 parsesSuccessfully,
282 parseRaisesException(SyntaxError)),
283 true);
284 assertEq(testLenientAndStrict('(function f(arguments){"use strict";})',
285 parseRaisesException(SyntaxError),
286 parseRaisesException(SyntaxError)),
287 true);
288 assertEq(testLenientAndStrict('(function f([arguments]){"use strict";})',
289 parseRaisesException(SyntaxError),
290 parseRaisesException(SyntaxError)),
291 true);
292 assertEq(testLenientAndStrict('(function f({x:arguments}){"use strict";})',
293 parseRaisesException(SyntaxError),
294 parseRaisesException(SyntaxError)),
295 true);
296 assertEq(testLenientAndStrict('(function arguments(){"use strict";})',
297 parseRaisesException(SyntaxError),
298 parseRaisesException(SyntaxError)),
299 true);
300 // This is not valid ES5 syntax.
301 assertEq(testLenientAndStrict('(function f(arguments) 2)',
302 parseRaisesException(SyntaxError),
303 parseRaisesException(SyntaxError)),
304 true);
305 // Destructuring is not valid ES5 syntax.
306 assertEq(testLenientAndStrict('(function f([arguments]) 2)',
307 parseRaisesException(SyntaxError),
308 parseRaisesException(SyntaxError)),
309 true);
310 // Destructuring is not valid ES5 syntax.
311 assertEq(testLenientAndStrict('(function f({x:arguments}) 2)',
312 parseRaisesException(SyntaxError),
313 parseRaisesException(SyntaxError)),
314 true);
315 // This is not valid ES5 syntax.
316 assertEq(testLenientAndStrict('(function arguments() 2)',
317 parseRaisesException(SyntaxError),
318 parseRaisesException(SyntaxError)),
319 true);
320 assertEq(testLenientAndStrict('({set x(arguments){}})',
321 parsesSuccessfully,
322 parseRaisesException(SyntaxError)),
323 true);
324 // Destructuring is not valid ES5 syntax.
325 assertEq(testLenientAndStrict('({set x([arguments]){}})',
326 parseRaisesException(SyntaxError),
327 parseRaisesException(SyntaxError)),
328 true);
329 // Destructuring is not valid ES5 syntax.
330 assertEq(testLenientAndStrict('({set x({x:arguments}){}})',
331 parseRaisesException(SyntaxError),
332 parseRaisesException(SyntaxError)),
333 true);
334 assertEq(testLenientAndStrict('({set x(arguments){"use strict";}})',
335 parseRaisesException(SyntaxError),
336 parseRaisesException(SyntaxError)),
337 true);
338 assertEq(testLenientAndStrict('({set x([arguments]){"use strict";}})',
339 parseRaisesException(SyntaxError),
340 parseRaisesException(SyntaxError)),
341 true);
342 assertEq(testLenientAndStrict('({set x({x:arguments}){"use strict";}})',
343 parseRaisesException(SyntaxError),
344 parseRaisesException(SyntaxError)),
345 true);
348 * Functions produced using the Function constructor may not use
349 * 'eval' or 'arguments' as a parameter name if their body is strict
350 * mode code. The strictness of the calling code does not affect the
351 * constraints applied to the parameters.
353 assertEq(testLenientAndStrict('Function("eval","")',
354 completesNormally,
355 completesNormally),
356 true);
357 assertEq(testLenientAndStrict('Function("eval","\'use strict\';")',
358 raisesException(SyntaxError),
359 raisesException(SyntaxError)),
360 true);
361 assertEq(testLenientAndStrict('Function("arguments","")',
362 completesNormally,
363 completesNormally),
364 true);
365 assertEq(testLenientAndStrict('Function("arguments","\'use strict\';")',
366 raisesException(SyntaxError),
367 raisesException(SyntaxError)),
368 true);
371 reportCompare(true, true);
373 var successfullyParsed = true;