1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
18 * Jeff Walden <jwalden+code@mit.edu>.
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 var gTestfile = 'regress-336376-01.js';
39 //-----------------------------------------------------------------------------
40 var BUGNUMBER = "336376";
41 var summary = "Tests reserved words in contexts in which they are not reserved";
44 printBugNumber(BUGNUMBER);
52 // New tests go in Tester.prototype._tests. A test is called with a single
53 // argument, the keyword to test in the syntax tested by that test. Tests
54 // should not return anything, and they should signal failure by throwing an
55 // explanatory exception and success by not throwing one.
57 // If you define a new test, make sure to name it using an informative string
58 // for ease of use if any keywords ever manually define the array of tests they
59 // should pass, and add it as a string to ALL_TESTS.
65 "CONTEXT_OBJECT_LITERAL_PROPERTY",
66 "CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE",
67 "CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE_IS_FUNCTION",
68 "CONTEXT_OBJECT_PROPERTY_DOT_GET",
69 "CONTEXT_OBJECT_PROPERTY_DOT_SET",
70 "CONTEXT_XML_DESCENDANTS",
71 "CONTEXT_XML_NAMESPACE_QUALIFIED_ELEMENT",
72 "CONTEXT_XML_NAMESPACE_QUALIFIED_ATTR",
73 "CONTEXT_XML_ATTRIBUTE_SELECTOR",
76 function r(keyword, tests)
80 * the keyword as a string
82 * array of test numbers against it, or leave undefined to run all tests
85 function Reserved(keyword, tests)
87 this.keyword = keyword;
91 this.tests = ALL_TESTS;
98 return "'" + this.keyword + "' being run against tests " +
102 return new Reserved(keyword, tests);
105 // ECMA-262, 3rd. ed. keywords -- see 7.5.2
106 const ECMA_262_3_KEYWORD =
135 // ECMA-262, 3rd. ed. future reserved keywords -- see 7.5.3
136 const ECMA_262_3_FUTURERESERVEDKEYWORD =
171 // like reserved words, but not quite reserved words
172 const PSEUDO_RESERVED =
177 r("each"), // |for each|
180 // new-in-ES4 reserved words -- fill this as each is implemented
181 const ECMA_262_4_RESERVED_WORDS =
190 * string containing the tested keyword
192 * the number of the failing test
194 * the exception thrown when running the test
196 function Failure(keyword, test, error)
198 this.keyword = keyword;
207 return "*** FAILURE on '" + this.keyword + "'!\n" +
208 "* test: " + this.test + "\n" +
209 "* error: " + this.error + "\n";
215 this._failedTests = [];
220 function(reservedArray)
223 for (var i = 0, sz = reservedArray.length; i < sz; i++)
225 var res = reservedArray[i];
229 var tests = res.tests;
230 for (var j = 0, sz2 = tests.length; j < sz2; j++)
238 this._tests[test](res.keyword);
242 this._failedTests.push(new Failure(res.keyword, test, e));
250 if (this._failedTests.length > 0) {
251 var except = "*************************\n" +
252 "* FAILURES ENCOUNTERED! *\n" +
253 "*************************\n";
254 for (var i = 0, sz = this._failedTests.length; i < sz; i++)
255 except += this._failedTests[i];
261 CONTEXT_OBJECT_LITERAL_PROPERTY:
266 eval("var o = { " + keyword + ": 17 };\n" +
267 "if (o['" + keyword + "'] != 17)\n" +
268 "throw \"o['" + keyword + "'] == 17\";");
275 CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE:
280 eval("var o = { \"" + keyword + "\": 17, baz: null };\n" +
281 "if (o." + keyword + " != 17)\n" +
282 "throw \"o." + keyword + " == 17\";");
289 CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE_IS_FUNCTION:
294 eval("var o = { '" + keyword + "': function() { return 17; }, baz: null };\n" +
295 "if (o." + keyword + "() != 17)\n" +
296 "throw \"o." + keyword + " == 17\";");
303 CONTEXT_OBJECT_PROPERTY_DOT_GET:
309 eval("o['" + keyword + "'] = 17;\n" +
310 "if (o." + keyword + " != 17)\n" +
311 "throw \"'o." + keyword + " != 17' failed!\";");
318 CONTEXT_OBJECT_PROPERTY_DOT_SET:
324 eval("o." + keyword + " = 17;\n" +
325 "if (o['" + keyword + "'] != 17)\n" +
326 "throw \"'o." + keyword + " = 17' failed!\";");
333 CONTEXT_XML_DESCENDANTS:
338 eval("var x = <foo><biz><" + keyword + " id='1'/></biz><" + keyword + " f='g'/></foo>;\n" +
339 "if (x.." + keyword + ".length() != 2 ||\n" +
340 " x.." + keyword + " != \n" +
341 " <><" + keyword + " id='1'/><" + keyword + " f='g'/></>)\n" +
342 "throw \"'x.." + keyword + ".length()' failed!\";");
349 CONTEXT_XML_NAMESPACE_QUALIFIED_ELEMENT:
354 var bar = new Namespace("http://localhost/");
355 eval("var x = <foo xmlns:bar='http://localhost/'>\n\
359 <bar:" + keyword + " id='17'/>\n\
361 <bar:" + keyword + ">\n\
363 </bar:" + keyword + ">\n\
366 if (x.quiz.bar::" + keyword + " != \n\
367 <bar:" + keyword + " xmlns:bar='http://localhost/'>\n\
369 </bar:" + keyword + "> ||\n\
370 x..bar::" + keyword + " != \n\
371 <><bar:" + keyword + "\n\
372 xmlns:bar='http://localhost/' id='17'/>\n\
373 <bar:" + keyword + " xmlns:bar='http://localhost/'>\n\
375 </bar:" + keyword + "></>)\n\
376 throw 'reserved names in XML namespace-qualified stuff are broken!';");
383 CONTEXT_XML_NAMESPACE_QUALIFIED_ATTR:
388 var bar = new Namespace("http://localhost/");
389 eval("var x = <foo xmlns:bar='http://localhost/'>\
390 <fin bar:" + keyword + "='5'/>\
392 if (x.fin.@bar::" + keyword + " != 5)\n\
393 throw 'namespaced attributes which are keywords are broken!';");
400 CONTEXT_XML_ATTRIBUTE_SELECTOR:
405 eval("var x = <foo " + keyword + "='idref'/>;\n\
406 if (x.@" + keyword + " != 'idref')\n\
407 throw 'keywords on the right of the @ E4X selector are broken!';");
426 var tester = new Tester();
427 tester.testReservedWords(ECMA_262_3_KEYWORD);
428 tester.testReservedWords(ECMA_262_3_FUTURERESERVEDKEYWORD);
429 tester.testReservedWords(PSEUDO_RESERVED);
430 tester.testReservedWords(ECMA_262_4_RESERVED_WORDS);
431 tester.flushErrors();
441 reportCompare(expect, actual, summary);