Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | //----------------------------------------------------------------------------- |
michael@0 | 7 | var BUGNUMBER = 497869; |
michael@0 | 8 | var summary = "Implement FutureReservedWords per-spec"; |
michael@0 | 9 | |
michael@0 | 10 | print(BUGNUMBER + ": " + summary); |
michael@0 | 11 | |
michael@0 | 12 | /************** |
michael@0 | 13 | * BEGIN TEST * |
michael@0 | 14 | **************/ |
michael@0 | 15 | |
michael@0 | 16 | var futureReservedWords = |
michael@0 | 17 | [ |
michael@0 | 18 | "class", |
michael@0 | 19 | // "const", // Mozilla extension enabled even for versionless code |
michael@0 | 20 | "enum", |
michael@0 | 21 | "export", |
michael@0 | 22 | "extends", |
michael@0 | 23 | "import", |
michael@0 | 24 | "super", |
michael@0 | 25 | ]; |
michael@0 | 26 | |
michael@0 | 27 | var strictFutureReservedWords = |
michael@0 | 28 | [ |
michael@0 | 29 | "implements", |
michael@0 | 30 | "interface", |
michael@0 | 31 | "let", // enabled: this file doesn't execute as JS1.7 |
michael@0 | 32 | "package", |
michael@0 | 33 | "private", |
michael@0 | 34 | "protected", |
michael@0 | 35 | "public", |
michael@0 | 36 | "static", |
michael@0 | 37 | "yield", // enabled: this file doesn't execute as JS1.7 |
michael@0 | 38 | ]; |
michael@0 | 39 | |
michael@0 | 40 | function testWord(word, expectNormal, expectStrict) |
michael@0 | 41 | { |
michael@0 | 42 | var actual, status; |
michael@0 | 43 | |
michael@0 | 44 | // USE AS LHS FOR ASSIGNMENT |
michael@0 | 45 | |
michael@0 | 46 | actual = ""; |
michael@0 | 47 | status = summary + ": " + word + ": normal assignment"; |
michael@0 | 48 | try |
michael@0 | 49 | { |
michael@0 | 50 | eval(word + " = 'foo';"); |
michael@0 | 51 | actual = "no error"; |
michael@0 | 52 | } |
michael@0 | 53 | catch(e) |
michael@0 | 54 | { |
michael@0 | 55 | actual = e.name; |
michael@0 | 56 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 57 | } |
michael@0 | 58 | reportCompare(expectNormal, actual, status); |
michael@0 | 59 | |
michael@0 | 60 | actual = ""; |
michael@0 | 61 | status = summary + ": " + word + ": strict assignment"; |
michael@0 | 62 | try |
michael@0 | 63 | { |
michael@0 | 64 | eval("'use strict'; " + word + " = 'foo';"); |
michael@0 | 65 | actual = "no error"; |
michael@0 | 66 | } |
michael@0 | 67 | catch(e) |
michael@0 | 68 | { |
michael@0 | 69 | actual = e.name; |
michael@0 | 70 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 71 | } |
michael@0 | 72 | reportCompare(expectStrict, actual, status); |
michael@0 | 73 | |
michael@0 | 74 | // USE IN VARIABLE DECLARATION |
michael@0 | 75 | |
michael@0 | 76 | actual = ""; |
michael@0 | 77 | status = summary + ": " + word + ": normal var"; |
michael@0 | 78 | try |
michael@0 | 79 | { |
michael@0 | 80 | eval("var " + word + ";"); |
michael@0 | 81 | actual = "no error"; |
michael@0 | 82 | } |
michael@0 | 83 | catch (e) |
michael@0 | 84 | { |
michael@0 | 85 | actual = e.name; |
michael@0 | 86 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 87 | } |
michael@0 | 88 | reportCompare(expectNormal, actual, status); |
michael@0 | 89 | |
michael@0 | 90 | actual = ""; |
michael@0 | 91 | status = summary + ": " + word + ": strict var"; |
michael@0 | 92 | try |
michael@0 | 93 | { |
michael@0 | 94 | eval("'use strict'; var " + word + ";"); |
michael@0 | 95 | actual = "no error"; |
michael@0 | 96 | } |
michael@0 | 97 | catch (e) |
michael@0 | 98 | { |
michael@0 | 99 | actual = e.name; |
michael@0 | 100 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 101 | } |
michael@0 | 102 | reportCompare(expectStrict, actual, status); |
michael@0 | 103 | |
michael@0 | 104 | // USE IN FOR-IN VARIABLE DECLARATION |
michael@0 | 105 | |
michael@0 | 106 | actual = ""; |
michael@0 | 107 | status = summary + ": " + word + ": normal for-in var"; |
michael@0 | 108 | try |
michael@0 | 109 | { |
michael@0 | 110 | eval("for (var " + word + " in {});"); |
michael@0 | 111 | actual = "no error"; |
michael@0 | 112 | } |
michael@0 | 113 | catch (e) |
michael@0 | 114 | { |
michael@0 | 115 | actual = e.name; |
michael@0 | 116 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 117 | } |
michael@0 | 118 | reportCompare(expectNormal, actual, status); |
michael@0 | 119 | |
michael@0 | 120 | actual = ""; |
michael@0 | 121 | status = summary + ": " + word + ": strict for-in var"; |
michael@0 | 122 | try |
michael@0 | 123 | { |
michael@0 | 124 | eval("'use strict'; for (var " + word + " in {});"); |
michael@0 | 125 | actual = "no error"; |
michael@0 | 126 | } |
michael@0 | 127 | catch (e) |
michael@0 | 128 | { |
michael@0 | 129 | actual = e.name; |
michael@0 | 130 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 131 | } |
michael@0 | 132 | reportCompare(expectStrict, actual, status); |
michael@0 | 133 | |
michael@0 | 134 | // USE AS CATCH IDENTIFIER |
michael@0 | 135 | |
michael@0 | 136 | actual = ""; |
michael@0 | 137 | status = summary + ": " + word + ": normal var"; |
michael@0 | 138 | try |
michael@0 | 139 | { |
michael@0 | 140 | eval("try { } catch (" + word + ") { }"); |
michael@0 | 141 | actual = "no error"; |
michael@0 | 142 | } |
michael@0 | 143 | catch (e) |
michael@0 | 144 | { |
michael@0 | 145 | actual = e.name; |
michael@0 | 146 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 147 | } |
michael@0 | 148 | reportCompare(expectNormal, actual, status); |
michael@0 | 149 | |
michael@0 | 150 | actual = ""; |
michael@0 | 151 | status = summary + ": " + word + ": strict var"; |
michael@0 | 152 | try |
michael@0 | 153 | { |
michael@0 | 154 | eval("'use strict'; try { } catch (" + word + ") { }"); |
michael@0 | 155 | actual = "no error"; |
michael@0 | 156 | } |
michael@0 | 157 | catch (e) |
michael@0 | 158 | { |
michael@0 | 159 | actual = e.name; |
michael@0 | 160 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 161 | } |
michael@0 | 162 | reportCompare(expectStrict, actual, status); |
michael@0 | 163 | |
michael@0 | 164 | // USE AS LABEL |
michael@0 | 165 | |
michael@0 | 166 | actual = ""; |
michael@0 | 167 | status = summary + ": " + word + ": normal label"; |
michael@0 | 168 | try |
michael@0 | 169 | { |
michael@0 | 170 | eval(word + ": while (false);"); |
michael@0 | 171 | actual = "no error"; |
michael@0 | 172 | } |
michael@0 | 173 | catch (e) |
michael@0 | 174 | { |
michael@0 | 175 | actual = e.name; |
michael@0 | 176 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 177 | } |
michael@0 | 178 | reportCompare(expectNormal, actual, status); |
michael@0 | 179 | |
michael@0 | 180 | actual = ""; |
michael@0 | 181 | status = summary + ": " + word + ": strict label"; |
michael@0 | 182 | try |
michael@0 | 183 | { |
michael@0 | 184 | eval("'use strict'; " + word + ": while (false);"); |
michael@0 | 185 | actual = "no error"; |
michael@0 | 186 | } |
michael@0 | 187 | catch (e) |
michael@0 | 188 | { |
michael@0 | 189 | actual = e.name; |
michael@0 | 190 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 191 | } |
michael@0 | 192 | reportCompare(expectStrict, actual, status); |
michael@0 | 193 | |
michael@0 | 194 | // USE AS ARGUMENT NAME IN FUNCTION DECLARATION |
michael@0 | 195 | |
michael@0 | 196 | actual = ""; |
michael@0 | 197 | status = summary + ": " + word + ": normal function argument"; |
michael@0 | 198 | try |
michael@0 | 199 | { |
michael@0 | 200 | eval("function foo(" + word + ") { }"); |
michael@0 | 201 | actual = "no error"; |
michael@0 | 202 | } |
michael@0 | 203 | catch (e) |
michael@0 | 204 | { |
michael@0 | 205 | actual = e.name; |
michael@0 | 206 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 207 | } |
michael@0 | 208 | reportCompare(expectNormal, actual, status); |
michael@0 | 209 | |
michael@0 | 210 | actual = ""; |
michael@0 | 211 | status = summary + ": " + word + ": strict function argument"; |
michael@0 | 212 | try |
michael@0 | 213 | { |
michael@0 | 214 | eval("'use strict'; function foo(" + word + ") { }"); |
michael@0 | 215 | actual = "no error"; |
michael@0 | 216 | } |
michael@0 | 217 | catch (e) |
michael@0 | 218 | { |
michael@0 | 219 | actual = e.name; |
michael@0 | 220 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 221 | } |
michael@0 | 222 | reportCompare(expectStrict, actual, status); |
michael@0 | 223 | |
michael@0 | 224 | actual = ""; |
michael@0 | 225 | status = summary + ": " + word + ": function argument retroactively strict"; |
michael@0 | 226 | try |
michael@0 | 227 | { |
michael@0 | 228 | eval("function foo(" + word + ") { 'use strict'; }"); |
michael@0 | 229 | actual = "no error"; |
michael@0 | 230 | } |
michael@0 | 231 | catch (e) |
michael@0 | 232 | { |
michael@0 | 233 | actual = e.name; |
michael@0 | 234 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 235 | } |
michael@0 | 236 | reportCompare(expectStrict, actual, status); |
michael@0 | 237 | |
michael@0 | 238 | // USE AS ARGUMENT NAME IN FUNCTION EXPRESSION |
michael@0 | 239 | |
michael@0 | 240 | actual = ""; |
michael@0 | 241 | status = summary + ": " + word + ": normal function expression argument"; |
michael@0 | 242 | try |
michael@0 | 243 | { |
michael@0 | 244 | eval("var s = (function foo(" + word + ") { });"); |
michael@0 | 245 | actual = "no error"; |
michael@0 | 246 | } |
michael@0 | 247 | catch (e) |
michael@0 | 248 | { |
michael@0 | 249 | actual = e.name; |
michael@0 | 250 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 251 | } |
michael@0 | 252 | reportCompare(expectNormal, actual, status); |
michael@0 | 253 | |
michael@0 | 254 | actual = ""; |
michael@0 | 255 | status = summary + ": " + word + ": strict function expression argument"; |
michael@0 | 256 | try |
michael@0 | 257 | { |
michael@0 | 258 | eval("'use strict'; var s = (function foo(" + word + ") { });"); |
michael@0 | 259 | actual = "no error"; |
michael@0 | 260 | } |
michael@0 | 261 | catch (e) |
michael@0 | 262 | { |
michael@0 | 263 | actual = e.name; |
michael@0 | 264 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 265 | } |
michael@0 | 266 | reportCompare(expectStrict, actual, status); |
michael@0 | 267 | |
michael@0 | 268 | actual = ""; |
michael@0 | 269 | status = summary + ": " + word + ": function expression argument retroactively strict"; |
michael@0 | 270 | try |
michael@0 | 271 | { |
michael@0 | 272 | eval("var s = (function foo(" + word + ") { 'use strict'; });"); |
michael@0 | 273 | actual = "no error"; |
michael@0 | 274 | } |
michael@0 | 275 | catch (e) |
michael@0 | 276 | { |
michael@0 | 277 | actual = e.name; |
michael@0 | 278 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 279 | } |
michael@0 | 280 | reportCompare(expectStrict, actual, status); |
michael@0 | 281 | |
michael@0 | 282 | // USE AS ARGUMENT NAME WITH FUNCTION CONSTRUCTOR |
michael@0 | 283 | |
michael@0 | 284 | actual = ""; |
michael@0 | 285 | status = summary + ": " + word + ": argument with normal Function"; |
michael@0 | 286 | try |
michael@0 | 287 | { |
michael@0 | 288 | Function(word, "return 17"); |
michael@0 | 289 | actual = "no error"; |
michael@0 | 290 | } |
michael@0 | 291 | catch (e) |
michael@0 | 292 | { |
michael@0 | 293 | actual = e.name; |
michael@0 | 294 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 295 | } |
michael@0 | 296 | reportCompare(expectNormal, actual, status); |
michael@0 | 297 | |
michael@0 | 298 | actual = ""; |
michael@0 | 299 | status = summary + ": " + word + ": argument with strict Function"; |
michael@0 | 300 | try |
michael@0 | 301 | { |
michael@0 | 302 | Function(word, "'use strict'; return 17"); |
michael@0 | 303 | actual = "no error"; |
michael@0 | 304 | } |
michael@0 | 305 | catch (e) |
michael@0 | 306 | { |
michael@0 | 307 | actual = e.name; |
michael@0 | 308 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 309 | } |
michael@0 | 310 | reportCompare(expectStrict, actual, status); |
michael@0 | 311 | |
michael@0 | 312 | // USE AS ARGUMENT NAME IN PROPERTY SETTER |
michael@0 | 313 | |
michael@0 | 314 | actual = ""; |
michael@0 | 315 | status = summary + ": " + word + ": normal property setter argument"; |
michael@0 | 316 | try |
michael@0 | 317 | { |
michael@0 | 318 | eval("var o = { set x(" + word + ") { } };"); |
michael@0 | 319 | actual = "no error"; |
michael@0 | 320 | } |
michael@0 | 321 | catch (e) |
michael@0 | 322 | { |
michael@0 | 323 | actual = e.name; |
michael@0 | 324 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 325 | } |
michael@0 | 326 | reportCompare(expectNormal, actual, status); |
michael@0 | 327 | |
michael@0 | 328 | actual = ""; |
michael@0 | 329 | status = summary + ": " + word + ": strict property setter argument"; |
michael@0 | 330 | try |
michael@0 | 331 | { |
michael@0 | 332 | eval("'use strict'; var o = { set x(" + word + ") { } };"); |
michael@0 | 333 | actual = "no error"; |
michael@0 | 334 | } |
michael@0 | 335 | catch (e) |
michael@0 | 336 | { |
michael@0 | 337 | actual = e.name; |
michael@0 | 338 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 339 | } |
michael@0 | 340 | reportCompare(expectStrict, actual, status); |
michael@0 | 341 | |
michael@0 | 342 | actual = ""; |
michael@0 | 343 | status = summary + ": " + word + ": property setter argument retroactively strict"; |
michael@0 | 344 | try |
michael@0 | 345 | { |
michael@0 | 346 | eval("var o = { set x(" + word + ") { 'use strict'; } };"); |
michael@0 | 347 | actual = "no error"; |
michael@0 | 348 | } |
michael@0 | 349 | catch (e) |
michael@0 | 350 | { |
michael@0 | 351 | actual = e.name; |
michael@0 | 352 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 353 | } |
michael@0 | 354 | reportCompare(expectStrict, actual, status); |
michael@0 | 355 | |
michael@0 | 356 | // USE AS FUNCTION NAME IN FUNCTION DECLARATION |
michael@0 | 357 | |
michael@0 | 358 | actual = ""; |
michael@0 | 359 | status = summary + ": " + word + ": normal function name"; |
michael@0 | 360 | try |
michael@0 | 361 | { |
michael@0 | 362 | eval("function " + word + "() { }"); |
michael@0 | 363 | actual = "no error"; |
michael@0 | 364 | } |
michael@0 | 365 | catch (e) |
michael@0 | 366 | { |
michael@0 | 367 | actual = e.name; |
michael@0 | 368 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 369 | } |
michael@0 | 370 | reportCompare(expectNormal, actual, status); |
michael@0 | 371 | |
michael@0 | 372 | actual = ""; |
michael@0 | 373 | status = summary + ": " + word + ": strict function name"; |
michael@0 | 374 | try |
michael@0 | 375 | { |
michael@0 | 376 | eval("'use strict'; function " + word + "() { }"); |
michael@0 | 377 | actual = "no error"; |
michael@0 | 378 | } |
michael@0 | 379 | catch (e) |
michael@0 | 380 | { |
michael@0 | 381 | actual = e.name; |
michael@0 | 382 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 383 | } |
michael@0 | 384 | reportCompare(expectStrict, actual, status); |
michael@0 | 385 | |
michael@0 | 386 | actual = ""; |
michael@0 | 387 | status = summary + ": " + word + ": function name retroactively strict"; |
michael@0 | 388 | try |
michael@0 | 389 | { |
michael@0 | 390 | eval("function " + word + "() { 'use strict'; }"); |
michael@0 | 391 | actual = "no error"; |
michael@0 | 392 | } |
michael@0 | 393 | catch (e) |
michael@0 | 394 | { |
michael@0 | 395 | actual = e.name; |
michael@0 | 396 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 397 | } |
michael@0 | 398 | reportCompare(expectStrict, actual, status); |
michael@0 | 399 | |
michael@0 | 400 | // USE AS FUNCTION NAME IN FUNCTION EXPRESSION |
michael@0 | 401 | |
michael@0 | 402 | actual = ""; |
michael@0 | 403 | status = summary + ": " + word + ": normal function expression name"; |
michael@0 | 404 | try |
michael@0 | 405 | { |
michael@0 | 406 | eval("var s = (function " + word + "() { });"); |
michael@0 | 407 | actual = "no error"; |
michael@0 | 408 | } |
michael@0 | 409 | catch (e) |
michael@0 | 410 | { |
michael@0 | 411 | actual = e.name; |
michael@0 | 412 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 413 | } |
michael@0 | 414 | reportCompare(expectNormal, actual, status); |
michael@0 | 415 | |
michael@0 | 416 | actual = ""; |
michael@0 | 417 | status = summary + ": " + word + ": strict function expression name"; |
michael@0 | 418 | try |
michael@0 | 419 | { |
michael@0 | 420 | eval("'use strict'; var s = (function " + word + "() { });"); |
michael@0 | 421 | actual = "no error"; |
michael@0 | 422 | } |
michael@0 | 423 | catch (e) |
michael@0 | 424 | { |
michael@0 | 425 | actual = e.name; |
michael@0 | 426 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 427 | } |
michael@0 | 428 | reportCompare(expectStrict, actual, status); |
michael@0 | 429 | |
michael@0 | 430 | actual = ""; |
michael@0 | 431 | status = summary + ": " + word + ": function expression name retroactively strict"; |
michael@0 | 432 | try |
michael@0 | 433 | { |
michael@0 | 434 | eval("var s = (function " + word + "() { 'use strict'; });"); |
michael@0 | 435 | actual = "no error"; |
michael@0 | 436 | } |
michael@0 | 437 | catch (e) |
michael@0 | 438 | { |
michael@0 | 439 | actual = e.name; |
michael@0 | 440 | status += ", " + e.name + ": " + e.message + " "; |
michael@0 | 441 | } |
michael@0 | 442 | reportCompare(expectStrict, actual, status); |
michael@0 | 443 | } |
michael@0 | 444 | |
michael@0 | 445 | function testFutureReservedWord(word) |
michael@0 | 446 | { |
michael@0 | 447 | testWord(word, "SyntaxError", "SyntaxError"); |
michael@0 | 448 | } |
michael@0 | 449 | |
michael@0 | 450 | function testStrictFutureReservedWord(word) |
michael@0 | 451 | { |
michael@0 | 452 | testWord(word, "no error", "SyntaxError"); |
michael@0 | 453 | } |
michael@0 | 454 | |
michael@0 | 455 | futureReservedWords.forEach(testFutureReservedWord); |
michael@0 | 456 | strictFutureReservedWords.forEach(testStrictFutureReservedWord); |
michael@0 | 457 | |
michael@0 | 458 | /******************************************************************************/ |
michael@0 | 459 | |
michael@0 | 460 | if (typeof reportCompare === "function") |
michael@0 | 461 | reportCompare(true, true); |
michael@0 | 462 | |
michael@0 | 463 | print("All tests passed!"); |