1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
4 * Any copyright is dedicated to the Public Domain.
5 * http://creativecommons.org/licenses/publicdomain/
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) {}',
21 assertEq(testLenientAndStrict('function f(x,x) {}',
23 parseRaisesException(SyntaxError
)),
25 assertEq(testLenientAndStrict('function f(x,y,z,y) {}',
27 parseRaisesException(SyntaxError
)),
30 /* Exercise the hashed local name map case. */
31 assertEq(testLenientAndStrict('function f(a,b,c,d,e,f,g,h,d) {}',
33 parseRaisesException(SyntaxError
)),
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
)),
45 assertEq(testLenientAndStrict('function f([x,x]){}',
46 parseRaisesException(SyntaxError
),
47 parseRaisesException(SyntaxError
)),
49 assertEq(testLenientAndStrict('function f(x,[x]){}',
50 parseRaisesException(SyntaxError
),
51 parseRaisesException(SyntaxError
)),
55 * Strict rules apply to the parameters if the function's body is
58 assertEq(testLenientAndStrict('function f(x,x) { "use strict" };',
59 parseRaisesException(SyntaxError
),
60 parseRaisesException(SyntaxError
)),
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","")',
72 assertEq(testLenientAndStrict('Function("x","y","")',
76 assertEq(testLenientAndStrict('Function("x","x","\'use strict\'")',
77 raisesException(SyntaxError
),
78 raisesException(SyntaxError
)),
80 assertEq(testLenientAndStrict('Function("x","y","\'use strict\'")',
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
)),
95 // This is not valid ES5 syntax.
96 assertEq(testLenientAndStrict('(function (x,y) 2)',
97 parseRaisesException(SyntaxError
),
98 parseRaisesException(SyntaxError
)),
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){}',
117 parseRaisesException(SyntaxError
)),
119 // Destructuring is not valid ES5 syntax.
120 assertEq(testLenientAndStrict('function f([eval]){}',
121 parseRaisesException(SyntaxError
),
122 parseRaisesException(SyntaxError
)),
124 // Destructuring is not valid ES5 syntax.
125 assertEq(testLenientAndStrict('function f({x:eval}){}',
126 parseRaisesException(SyntaxError
),
127 parseRaisesException(SyntaxError
)),
129 assertEq(testLenientAndStrict('function eval(){}',
131 parseRaisesException(SyntaxError
)),
133 assertEq(testLenientAndStrict('function f(eval){"use strict";}',
134 parseRaisesException(SyntaxError
),
135 parseRaisesException(SyntaxError
)),
137 // Destructuring is not valid ES5 syntax.
138 assertEq(testLenientAndStrict('function f([eval]){"use strict";}',
139 parseRaisesException(SyntaxError
),
140 parseRaisesException(SyntaxError
)),
142 // Destructuring is not valid ES5 syntax.
143 assertEq(testLenientAndStrict('function f({x:eval}){"use strict";}',
144 parseRaisesException(SyntaxError
),
145 parseRaisesException(SyntaxError
)),
147 assertEq(testLenientAndStrict('function eval(){"use strict";}',
148 parseRaisesException(SyntaxError
),
149 parseRaisesException(SyntaxError
)),
151 assertEq(testLenientAndStrict('(function f(eval){})',
153 parseRaisesException(SyntaxError
)),
155 // Destructuring is not valid ES5 syntax.
156 assertEq(testLenientAndStrict('(function f([eval]){})',
157 parseRaisesException(SyntaxError
),
158 parseRaisesException(SyntaxError
)),
160 // Destructuring is not valid ES5 syntax.
161 assertEq(testLenientAndStrict('(function f({x:eval}){})',
162 parseRaisesException(SyntaxError
),
163 parseRaisesException(SyntaxError
)),
165 assertEq(testLenientAndStrict('(function eval(){})',
167 parseRaisesException(SyntaxError
)),
169 assertEq(testLenientAndStrict('(function f(eval){"use strict";})',
170 parseRaisesException(SyntaxError
),
171 parseRaisesException(SyntaxError
)),
173 assertEq(testLenientAndStrict('(function f([eval]){"use strict";})',
174 parseRaisesException(SyntaxError
),
175 parseRaisesException(SyntaxError
)),
177 assertEq(testLenientAndStrict('(function f({x:eval}){"use strict";})',
178 parseRaisesException(SyntaxError
),
179 parseRaisesException(SyntaxError
)),
181 assertEq(testLenientAndStrict('(function eval(){"use strict";})',
182 parseRaisesException(SyntaxError
),
183 parseRaisesException(SyntaxError
)),
185 // This is not valid ES5 syntax.
186 assertEq(testLenientAndStrict('(function f(eval) 2)',
187 parseRaisesException(SyntaxError
),
188 parseRaisesException(SyntaxError
)),
190 // Destructuring is not valid ES5 syntax.
191 assertEq(testLenientAndStrict('(function f([eval]) 2)',
192 parseRaisesException(SyntaxError
),
193 parseRaisesException(SyntaxError
)),
195 // This is not valid ES5 syntax.
196 assertEq(testLenientAndStrict('(function f({x:eval}) 2)',
197 parseRaisesException(SyntaxError
),
198 parseRaisesException(SyntaxError
)),
200 // This is not valid ES5 syntax.
201 assertEq(testLenientAndStrict('(function eval() 2)',
202 parseRaisesException(SyntaxError
),
203 parseRaisesException(SyntaxError
)),
205 assertEq(testLenientAndStrict('({set x(eval){}})',
207 parseRaisesException(SyntaxError
)),
209 // Destructuring is not valid ES5 syntax.
210 assertEq(testLenientAndStrict('({set x([eval]){}})',
211 parseRaisesException(SyntaxError
),
212 parseRaisesException(SyntaxError
)),
214 // Destructuring is not valid ES5 syntax.
215 assertEq(testLenientAndStrict('({set x({x:eval}){}})',
216 parseRaisesException(SyntaxError
),
217 parseRaisesException(SyntaxError
)),
219 assertEq(testLenientAndStrict('({set x(eval){"use strict";}})',
220 parseRaisesException(SyntaxError
),
221 parseRaisesException(SyntaxError
)),
223 assertEq(testLenientAndStrict('({set x([eval]){"use strict";}})',
224 parseRaisesException(SyntaxError
),
225 parseRaisesException(SyntaxError
)),
227 assertEq(testLenientAndStrict('({set x({x:eval}){"use strict";}})',
228 parseRaisesException(SyntaxError
),
229 parseRaisesException(SyntaxError
)),
231 assertEq(testLenientAndStrict('function f(arguments){}',
233 parseRaisesException(SyntaxError
)),
235 // Destructuring is not valid ES5 syntax.
236 assertEq(testLenientAndStrict('function f([arguments]){}',
237 parseRaisesException(SyntaxError
),
238 parseRaisesException(SyntaxError
)),
240 // Destructuring is not valid ES5 syntax.
241 assertEq(testLenientAndStrict('function f({x:arguments}){}',
242 parseRaisesException(SyntaxError
),
243 parseRaisesException(SyntaxError
)),
245 assertEq(testLenientAndStrict('function arguments(){}',
247 parseRaisesException(SyntaxError
)),
249 assertEq(testLenientAndStrict('function f(arguments){"use strict";}',
250 parseRaisesException(SyntaxError
),
251 parseRaisesException(SyntaxError
)),
253 // Destructuring is not valid ES5 syntax.
254 assertEq(testLenientAndStrict('function f([arguments]){"use strict";}',
255 parseRaisesException(SyntaxError
),
256 parseRaisesException(SyntaxError
)),
258 assertEq(testLenientAndStrict('function f({x:arguments}){"use strict";}',
259 parseRaisesException(SyntaxError
),
260 parseRaisesException(SyntaxError
)),
262 assertEq(testLenientAndStrict('function arguments(){"use strict";}',
263 parseRaisesException(SyntaxError
),
264 parseRaisesException(SyntaxError
)),
266 assertEq(testLenientAndStrict('(function f(arguments){})',
268 parseRaisesException(SyntaxError
)),
270 // Destructuring is not valid ES5 syntax.
271 assertEq(testLenientAndStrict('(function f([arguments]){})',
272 parseRaisesException(SyntaxError
),
273 parseRaisesException(SyntaxError
)),
275 // Destructuring is not valid ES5 syntax.
276 assertEq(testLenientAndStrict('(function f({x:arguments}){})',
277 parseRaisesException(SyntaxError
),
278 parseRaisesException(SyntaxError
)),
280 assertEq(testLenientAndStrict('(function arguments(){})',
282 parseRaisesException(SyntaxError
)),
284 assertEq(testLenientAndStrict('(function f(arguments){"use strict";})',
285 parseRaisesException(SyntaxError
),
286 parseRaisesException(SyntaxError
)),
288 assertEq(testLenientAndStrict('(function f([arguments]){"use strict";})',
289 parseRaisesException(SyntaxError
),
290 parseRaisesException(SyntaxError
)),
292 assertEq(testLenientAndStrict('(function f({x:arguments}){"use strict";})',
293 parseRaisesException(SyntaxError
),
294 parseRaisesException(SyntaxError
)),
296 assertEq(testLenientAndStrict('(function arguments(){"use strict";})',
297 parseRaisesException(SyntaxError
),
298 parseRaisesException(SyntaxError
)),
300 // This is not valid ES5 syntax.
301 assertEq(testLenientAndStrict('(function f(arguments) 2)',
302 parseRaisesException(SyntaxError
),
303 parseRaisesException(SyntaxError
)),
305 // Destructuring is not valid ES5 syntax.
306 assertEq(testLenientAndStrict('(function f([arguments]) 2)',
307 parseRaisesException(SyntaxError
),
308 parseRaisesException(SyntaxError
)),
310 // Destructuring is not valid ES5 syntax.
311 assertEq(testLenientAndStrict('(function f({x:arguments}) 2)',
312 parseRaisesException(SyntaxError
),
313 parseRaisesException(SyntaxError
)),
315 // This is not valid ES5 syntax.
316 assertEq(testLenientAndStrict('(function arguments() 2)',
317 parseRaisesException(SyntaxError
),
318 parseRaisesException(SyntaxError
)),
320 assertEq(testLenientAndStrict('({set x(arguments){}})',
322 parseRaisesException(SyntaxError
)),
324 // Destructuring is not valid ES5 syntax.
325 assertEq(testLenientAndStrict('({set x([arguments]){}})',
326 parseRaisesException(SyntaxError
),
327 parseRaisesException(SyntaxError
)),
329 // Destructuring is not valid ES5 syntax.
330 assertEq(testLenientAndStrict('({set x({x:arguments}){}})',
331 parseRaisesException(SyntaxError
),
332 parseRaisesException(SyntaxError
)),
334 assertEq(testLenientAndStrict('({set x(arguments){"use strict";}})',
335 parseRaisesException(SyntaxError
),
336 parseRaisesException(SyntaxError
)),
338 assertEq(testLenientAndStrict('({set x([arguments]){"use strict";}})',
339 parseRaisesException(SyntaxError
),
340 parseRaisesException(SyntaxError
)),
342 assertEq(testLenientAndStrict('({set x({x:arguments}){"use strict";}})',
343 parseRaisesException(SyntaxError
),
344 parseRaisesException(SyntaxError
)),
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","")',
357 assertEq(testLenientAndStrict('Function("eval","\'use strict\';")',
358 raisesException(SyntaxError
),
359 raisesException(SyntaxError
)),
361 assertEq(testLenientAndStrict('Function("arguments","")',
365 assertEq(testLenientAndStrict('Function("arguments","\'use strict\';")',
366 raisesException(SyntaxError
),
367 raisesException(SyntaxError
)),
371 reportCompare(true, true);
373 var successfullyParsed
= true;