Debian Codegraph @

rhino/testsrc/tests/js1_7/lexical/regress-336376-01.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 var gTestfile = 'regress-336376-01.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = "336376";
9 var summary = "Tests reserved words in contexts in which they are not reserved";
10 var actual, expect;
11
12 printBugNumber(BUGNUMBER);
13 printStatus(summary);
14
15 /**************
16 * TEST SETUP *
17 **************/
18
19 //
20 // New tests go in Tester.prototype._tests. A test is called with a single
21 // argument, the keyword to test in the syntax tested by that test. Tests
22 // should not return anything, and they should signal failure by throwing an
23 // explanatory exception and success by not throwing one.
24 //
25 // If you define a new test, make sure to name it using an informative string
26 // for ease of use if any keywords ever manually define the array of tests they
27 // should pass, and add it as a string to ALL_TESTS.
28 //
29
30 // all tests
31 const ALL_TESTS =
32 [
33 "CONTEXT_OBJECT_LITERAL_PROPERTY",
34 "CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE",
35 "CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE_IS_FUNCTION",
36 "CONTEXT_OBJECT_PROPERTY_DOT_GET",
37 "CONTEXT_OBJECT_PROPERTY_DOT_SET",
38 "CONTEXT_XML_DESCENDANTS",
39 "CONTEXT_XML_NAMESPACE_QUALIFIED_ELEMENT",
40 "CONTEXT_XML_NAMESPACE_QUALIFIED_ATTR",
41 "CONTEXT_XML_ATTRIBUTE_SELECTOR",
42 ];
43
44 function r(keyword, tests)
45 {
46 /**
47 * @param keyword
48 * the keyword as a string
49 * @param tests
50 * array of test numbers against it, or leave undefined to run all tests
51 * against it
52 */
53 function Reserved(keyword, tests)
54 {
55 this.keyword = keyword;
56 if (tests)
57 this.tests = tests;
58 else
59 this.tests = ALL_TESTS;
60 }
61 Reserved.prototype =
62 {
63 toString:
64 function()
65 {
66 return "'" + this.keyword + "' being run against tests " +
67 this.tests;
68 }
69 };
70 return new Reserved(keyword, tests);
71 }
72
73 // ECMA-262, 3rd. ed. keywords -- see 7.5.2
74 const ECMA_262_3_KEYWORD =
75 [
76 r("break"),
77 r("case"),
78 r("catch"),
79 r("continue"),
80 r("default"),
81 r("delete"),
82 r("do"),
83 r("else"),
84 r("finally"),
85 r("for"),
86 r("function"),
87 r("if"),
88 r("in"),
89 r("instanceof"),
90 r("new"),
91 r("return"),
92 r("switch"),
93 r("this"),
94 r("throw"),
95 r("try"),
96 r("typeof"),
97 r("var"),
98 r("void"),
99 r("while"),
100 r("with"),
101 ];
102
103 // ECMA-262, 3rd. ed. future reserved keywords -- see 7.5.3
104 const ECMA_262_3_FUTURERESERVEDKEYWORD =
105 [
106 r("abstract"),
107 r("boolean"),
108 r("byte"),
109 r("char"),
110 r("class"),
111 r("const"),
112 r("debugger"),
113 r("double"),
114 r("enum"),
115 r("export"),
116 r("extends"),
117 r("final"),
118 r("float"),
119 r("goto"),
120 r("implements"),
121 r("import"),
122 r("int"),
123 r("interface"),
124 r("long"),
125 r("native"),
126 r("package"),
127 r("private"),
128 r("protected"),
129 r("public"),
130 r("short"),
131 r("static"),
132 r("super"),
133 r("synchronized"),
134 r("throws"),
135 r("transient"),
136 r("volatile"),
137 ];
138
139 // like reserved words, but not quite reserved words
140 const PSEUDO_RESERVED =
141 [
142 r("true"),
143 r("false"),
144 r("null"),
145 r("each"), // |for each|
146 ];
147
148 // new-in-ES4 reserved words -- fill this as each is implemented
149 const ECMA_262_4_RESERVED_WORDS =
150 [
151 r("let")
152 ];
153
154
155
156 /**
157 * @param keyword
158 * string containing the tested keyword
159 * @param test
160 * the number of the failing test
161 * @param error
162 * the exception thrown when running the test
163 */
164 function Failure(keyword, test, error)
165 {
166 this.keyword = keyword;
167 this.test = test;
168 this.error = error;
169 }
170 Failure.prototype =
171 {
172 toString:
173 function()
174 {
175 return "*** FAILURE on '" + this.keyword + "'!\n" +
176 "* test: " + this.test + "\n" +
177 "* error: " + this.error + "\n";
178 }
179 };
180
181 function Tester()
182 {
183 this._failedTests = [];
184 }
185 Tester.prototype =
186 {
187 testReservedWords:
188 function(reservedArray)
189 {
190 var rv;
191 for (var i = 0, sz = reservedArray.length; i < sz; i++)
192 {
193 var res = reservedArray[i];
194 if (!res)
195 continue;
196
197 var tests = res.tests;
198 for (var j = 0, sz2 = tests.length; j < sz2; j++)
199 {
200 var test = tests[j];
201 if (!test)
202 continue;
203
204 try
205 {
206 this._tests[test](res.keyword);
207 }
208 catch (e)
209 {
210 this._failedTests.push(new Failure(res.keyword, test, e));
211 }
212 }
213 }
214 },
215 flushErrors:
216 function ()
217 {
218 if (this._failedTests.length > 0) {
219 var except = "*************************\n" +
220 "* FAILURES ENCOUNTERED! *\n" +
221 "*************************\n";
222 for (var i = 0, sz = this._failedTests.length; i < sz; i++)
223 except += this._failedTests[i];
224 throw except;
225 }
226 },
227 _tests:
228 {
229 CONTEXT_OBJECT_LITERAL_PROPERTY:
230 function(keyword)
231 {
232 try
233 {
234 eval("var o = { " + keyword + ": 17 };\n" +
235 "if (o['" + keyword + "'] != 17)\n" +
236 "throw \"o['" + keyword + "'] == 17\";");
237 }
238 catch (e)
239 {
240 throw e;
241 }
242 },
243 CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE:
244 function(keyword)
245 {
246 try
247 {
248 eval("var o = { \"" + keyword + "\": 17, baz: null };\n" +
249 "if (o." + keyword + " != 17)\n" +
250 "throw \"o." + keyword + " == 17\";");
251 }
252 catch (e)
253 {
254 throw e;
255 }
256 },
257 CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE_IS_FUNCTION:
258 function(keyword)
259 {
260 try
261 {
262 eval("var o = { '" + keyword + "': function() { return 17; }, baz: null };\n" +
263 "if (o." + keyword + "() != 17)\n" +
264 "throw \"o." + keyword + " == 17\";");
265 }
266 catch (e)
267 {
268 throw e;
269 }
270 },
271 CONTEXT_OBJECT_PROPERTY_DOT_GET:
272 function(keyword)
273 {
274 try
275 {
276 var o = {};
277 eval("o['" + keyword + "'] = 17;\n" +
278 "if (o." + keyword + " != 17)\n" +
279 "throw \"'o." + keyword + " != 17' failed!\";");
280 }
281 catch (e)
282 {
283 throw e;
284 }
285 },
286 CONTEXT_OBJECT_PROPERTY_DOT_SET:
287 function(keyword)
288 {
289 try
290 {
291 var o = {};
292 eval("o." + keyword + " = 17;\n" +
293 "if (o['" + keyword + "'] != 17)\n" +
294 "throw \"'o." + keyword + " = 17' failed!\";");
295 }
296 catch (e)
297 {
298 throw e;
299 }
300 },
301 CONTEXT_XML_DESCENDANTS:
302 function(keyword)
303 {
304 try
305 {
306 eval("var x = <foo><biz><" + keyword + " id='1'/></biz><" + keyword + " f='g'/></foo>;\n" +
307 "if (x.." + keyword + ".length() != 2 ||\n" +
308 " x.." + keyword + " != \n" +
309 " <><" + keyword + " id='1'/><" + keyword + " f='g'/></>)\n" +
310 "throw \"'x.." + keyword + ".length()' failed!\";");
311 }
312 catch (e)
313 {
314 throw e;
315 }
316 },
317 CONTEXT_XML_NAMESPACE_QUALIFIED_ELEMENT:
318 function(keyword)
319 {
320 try
321 {
322 var bar = new Namespace("http://localhost/");
323 eval("var x = <foo xmlns:bar='http://localhost/'>\n\
324 <bar>\n\
325 <baz/>\n\
326 </bar>\n\
327 <bar:" + keyword + " id='17'/>\n\
328 <quiz>\n\
329 <bar:" + keyword + ">\n\
330 <bunk/>\n\
331 </bar:" + keyword + ">\n\
332 </quiz>\n\
333 </foo>;\n\
334 if (x.quiz.bar::" + keyword + " != \n\
335 <bar:" + keyword + " xmlns:bar='http://localhost/'>\n\
336 <bunk/>\n\
337 </bar:" + keyword + "> ||\n\
338 x..bar::" + keyword + " != \n\
339 <><bar:" + keyword + "\n\
340 xmlns:bar='http://localhost/' id='17'/>\n\
341 <bar:" + keyword + " xmlns:bar='http://localhost/'>\n\
342 <bunk/>\n\
343 </bar:" + keyword + "></>)\n\
344 throw 'reserved names in XML namespace-qualified stuff are broken!';");
345 }
346 catch (e)
347 {
348 throw e;
349 }
350 },
351 CONTEXT_XML_NAMESPACE_QUALIFIED_ATTR:
352 function(keyword)
353 {
354 try
355 {
356 var bar = new Namespace("http://localhost/");
357 eval("var x = <foo xmlns:bar='http://localhost/'>\
358 <fin bar:" + keyword + "='5'/>\
359 </foo>;\n\
360 if (x.fin.@bar::" + keyword + " != 5)\n\
361 throw 'namespaced attributes which are keywords are broken!';");
362 }
363 catch (e)
364 {
365 throw e;
366 }
367 },
368 CONTEXT_XML_ATTRIBUTE_SELECTOR:
369 function(keyword)
370 {
371 try
372 {
373 eval("var x = <foo " + keyword + "='idref'/>;\n\
374 if (x.@" + keyword + " != 'idref')\n\
375 throw 'keywords on the right of the @ E4X selector are broken!';");
376 }
377 catch (e)
378 {
379 throw e;
380 }
381 }
382 }
383 };
384
385
386 /***************
387 * BEGIN TESTS *
388 ***************/
389
390 var failed = false;
391
392 try
393 {
394 var tester = new Tester();
395 tester.testReservedWords(ECMA_262_3_KEYWORD);
396 tester.testReservedWords(ECMA_262_3_FUTURERESERVEDKEYWORD);
397 tester.testReservedWords(PSEUDO_RESERVED);
398 tester.testReservedWords(ECMA_262_4_RESERVED_WORDS);
399 tester.flushErrors();
400 }
401 catch (e)
402 {
403 failed = e;
404 }
405
406 expect = false;
407 actual = failed;
408
409 reportCompare(expect, actual, summary);