js/src/tests/js1_7/lexical/regress-336376-01.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial