js/src/tests/ecma_5/misc/future-reserved-words.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_5/misc/future-reserved-words.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,463 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/licenses/publicdomain/
     1.7 + */
     1.8 +
     1.9 +//-----------------------------------------------------------------------------
    1.10 +var BUGNUMBER = 497869;
    1.11 +var summary = "Implement FutureReservedWords per-spec";
    1.12 +
    1.13 +print(BUGNUMBER + ": " + summary);
    1.14 +
    1.15 +/**************
    1.16 + * BEGIN TEST *
    1.17 + **************/
    1.18 +
    1.19 +var futureReservedWords =
    1.20 +  [
    1.21 +   "class",
    1.22 +   // "const", // Mozilla extension enabled even for versionless code
    1.23 +   "enum",
    1.24 +   "export",
    1.25 +   "extends",
    1.26 +   "import",
    1.27 +   "super",
    1.28 +  ];
    1.29 +
    1.30 +var strictFutureReservedWords =
    1.31 +  [
    1.32 +   "implements",
    1.33 +   "interface",
    1.34 +   "let", // enabled: this file doesn't execute as JS1.7
    1.35 +   "package",
    1.36 +   "private",
    1.37 +   "protected",
    1.38 +   "public",
    1.39 +   "static",
    1.40 +   "yield", // enabled: this file doesn't execute as JS1.7
    1.41 +  ];
    1.42 +
    1.43 +function testWord(word, expectNormal, expectStrict)
    1.44 +{
    1.45 +  var actual, status;
    1.46 +
    1.47 +  // USE AS LHS FOR ASSIGNMENT
    1.48 +
    1.49 +  actual = "";
    1.50 +  status = summary + ": " + word + ": normal assignment";
    1.51 +  try
    1.52 +  {
    1.53 +    eval(word + " = 'foo';");
    1.54 +    actual = "no error";
    1.55 +  }
    1.56 +  catch(e)
    1.57 +  {
    1.58 +    actual = e.name;
    1.59 +    status +=  ", " + e.name + ": " + e.message + " ";
    1.60 +  }
    1.61 +  reportCompare(expectNormal, actual, status);
    1.62 +
    1.63 +  actual = "";
    1.64 +  status = summary + ": " + word + ": strict assignment";
    1.65 +  try
    1.66 +  {
    1.67 +    eval("'use strict'; " + word + " = 'foo';");
    1.68 +    actual = "no error";
    1.69 +  }
    1.70 +  catch(e)
    1.71 +  {
    1.72 +    actual = e.name;
    1.73 +    status +=  ", " + e.name + ": " + e.message + " ";
    1.74 +  }
    1.75 +  reportCompare(expectStrict, actual, status);
    1.76 +
    1.77 +  // USE IN VARIABLE DECLARATION
    1.78 +
    1.79 +  actual = "";
    1.80 +  status = summary + ": " + word + ": normal var";
    1.81 +  try
    1.82 +  {
    1.83 +    eval("var " + word + ";");
    1.84 +    actual = "no error";
    1.85 +  }
    1.86 +  catch (e)
    1.87 +  {
    1.88 +    actual = e.name;
    1.89 +    status +=  ", " + e.name + ": " + e.message + " ";
    1.90 +  }
    1.91 +  reportCompare(expectNormal, actual, status);
    1.92 +
    1.93 +  actual = "";
    1.94 +  status = summary + ": " + word + ": strict var";
    1.95 +  try
    1.96 +  {
    1.97 +    eval("'use strict'; var " + word + ";");
    1.98 +    actual = "no error";
    1.99 +  }
   1.100 +  catch (e)
   1.101 +  {
   1.102 +    actual = e.name;
   1.103 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.104 +  }
   1.105 +  reportCompare(expectStrict, actual, status);
   1.106 +
   1.107 +  // USE IN FOR-IN VARIABLE DECLARATION
   1.108 +
   1.109 +  actual = "";
   1.110 +  status = summary + ": " + word + ": normal for-in var";
   1.111 +  try
   1.112 +  {
   1.113 +    eval("for (var " + word + " in {});");
   1.114 +    actual = "no error";
   1.115 +  }
   1.116 +  catch (e)
   1.117 +  {
   1.118 +    actual = e.name;
   1.119 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.120 +  }
   1.121 +  reportCompare(expectNormal, actual, status);
   1.122 +
   1.123 +  actual = "";
   1.124 +  status = summary + ": " + word + ": strict for-in var";
   1.125 +  try
   1.126 +  {
   1.127 +    eval("'use strict'; for (var " + word + " in {});");
   1.128 +    actual = "no error";
   1.129 +  }
   1.130 +  catch (e)
   1.131 +  {
   1.132 +    actual = e.name;
   1.133 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.134 +  }
   1.135 +  reportCompare(expectStrict, actual, status);
   1.136 +
   1.137 +  // USE AS CATCH IDENTIFIER
   1.138 +
   1.139 +  actual = "";
   1.140 +  status = summary + ": " + word + ": normal var";
   1.141 +  try
   1.142 +  {
   1.143 +    eval("try { } catch (" + word + ") { }");
   1.144 +    actual = "no error";
   1.145 +  }
   1.146 +  catch (e)
   1.147 +  {
   1.148 +    actual = e.name;
   1.149 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.150 +  }
   1.151 +  reportCompare(expectNormal, actual, status);
   1.152 +
   1.153 +  actual = "";
   1.154 +  status = summary + ": " + word + ": strict var";
   1.155 +  try
   1.156 +  {
   1.157 +    eval("'use strict'; try { } catch (" + word + ") { }");
   1.158 +    actual = "no error";
   1.159 +  }
   1.160 +  catch (e)
   1.161 +  {
   1.162 +    actual = e.name;
   1.163 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.164 +  }
   1.165 +  reportCompare(expectStrict, actual, status);
   1.166 +
   1.167 +  // USE AS LABEL
   1.168 +
   1.169 +  actual = "";
   1.170 +  status = summary + ": " + word + ": normal label";
   1.171 +  try
   1.172 +  {
   1.173 +    eval(word + ": while (false);");
   1.174 +    actual = "no error";
   1.175 +  }
   1.176 +  catch (e)
   1.177 +  {
   1.178 +    actual = e.name;
   1.179 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.180 +  }
   1.181 +  reportCompare(expectNormal, actual, status);
   1.182 +
   1.183 +  actual = "";
   1.184 +  status = summary + ": " + word + ": strict label";
   1.185 +  try
   1.186 +  {
   1.187 +    eval("'use strict'; " + word + ": while (false);");
   1.188 +    actual = "no error";
   1.189 +  }
   1.190 +  catch (e)
   1.191 +  {
   1.192 +    actual = e.name;
   1.193 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.194 +  }
   1.195 +  reportCompare(expectStrict, actual, status);
   1.196 +
   1.197 +  // USE AS ARGUMENT NAME IN FUNCTION DECLARATION
   1.198 +
   1.199 +  actual = "";
   1.200 +  status = summary + ": " + word + ": normal function argument";
   1.201 +  try
   1.202 +  {
   1.203 +    eval("function foo(" + word + ") { }");
   1.204 +    actual = "no error";
   1.205 +  }
   1.206 +  catch (e)
   1.207 +  {
   1.208 +    actual = e.name;
   1.209 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.210 +  }
   1.211 +  reportCompare(expectNormal, actual, status);
   1.212 +
   1.213 +  actual = "";
   1.214 +  status = summary + ": " + word + ": strict function argument";
   1.215 +  try
   1.216 +  {
   1.217 +    eval("'use strict'; function foo(" + word + ") { }");
   1.218 +    actual = "no error";
   1.219 +  }
   1.220 +  catch (e)
   1.221 +  {
   1.222 +    actual = e.name;
   1.223 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.224 +  }
   1.225 +  reportCompare(expectStrict, actual, status);
   1.226 +
   1.227 +  actual = "";
   1.228 +  status = summary + ": " + word + ": function argument retroactively strict";
   1.229 +  try
   1.230 +  {
   1.231 +    eval("function foo(" + word + ") { 'use strict'; }");
   1.232 +    actual = "no error";
   1.233 +  }
   1.234 +  catch (e)
   1.235 +  {
   1.236 +    actual = e.name;
   1.237 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.238 +  }
   1.239 +  reportCompare(expectStrict, actual, status);
   1.240 +
   1.241 +  // USE AS ARGUMENT NAME IN FUNCTION EXPRESSION
   1.242 +
   1.243 +  actual = "";
   1.244 +  status = summary + ": " + word + ": normal function expression argument";
   1.245 +  try
   1.246 +  {
   1.247 +    eval("var s = (function foo(" + word + ") { });");
   1.248 +    actual = "no error";
   1.249 +  }
   1.250 +  catch (e)
   1.251 +  {
   1.252 +    actual = e.name;
   1.253 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.254 +  }
   1.255 +  reportCompare(expectNormal, actual, status);
   1.256 +
   1.257 +  actual = "";
   1.258 +  status = summary + ": " + word + ": strict function expression argument";
   1.259 +  try
   1.260 +  {
   1.261 +    eval("'use strict'; var s = (function foo(" + word + ") { });");
   1.262 +    actual = "no error";
   1.263 +  }
   1.264 +  catch (e)
   1.265 +  {
   1.266 +    actual = e.name;
   1.267 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.268 +  }
   1.269 +  reportCompare(expectStrict, actual, status);
   1.270 +
   1.271 +  actual = "";
   1.272 +  status = summary + ": " + word + ": function expression argument retroactively strict";
   1.273 +  try
   1.274 +  {
   1.275 +    eval("var s = (function foo(" + word + ") { 'use strict'; });");
   1.276 +    actual = "no error";
   1.277 +  }
   1.278 +  catch (e)
   1.279 +  {
   1.280 +    actual = e.name;
   1.281 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.282 +  }
   1.283 +  reportCompare(expectStrict, actual, status);
   1.284 +
   1.285 +  // USE AS ARGUMENT NAME WITH FUNCTION CONSTRUCTOR
   1.286 +
   1.287 +  actual = "";
   1.288 +  status = summary + ": " + word + ": argument with normal Function";
   1.289 +  try
   1.290 +  {
   1.291 +    Function(word, "return 17");
   1.292 +    actual = "no error";
   1.293 +  }
   1.294 +  catch (e)
   1.295 +  {
   1.296 +    actual = e.name;
   1.297 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.298 +  }
   1.299 +  reportCompare(expectNormal, actual, status);
   1.300 +
   1.301 +  actual = "";
   1.302 +  status = summary + ": " + word + ": argument with strict Function";
   1.303 +  try
   1.304 +  {
   1.305 +    Function(word, "'use strict'; return 17");
   1.306 +    actual = "no error";
   1.307 +  }
   1.308 +  catch (e)
   1.309 +  {
   1.310 +    actual = e.name;
   1.311 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.312 +  }
   1.313 +  reportCompare(expectStrict, actual, status);
   1.314 +
   1.315 +  // USE AS ARGUMENT NAME IN PROPERTY SETTER
   1.316 +
   1.317 +  actual = "";
   1.318 +  status = summary + ": " + word + ": normal property setter argument";
   1.319 +  try
   1.320 +  {
   1.321 +    eval("var o = { set x(" + word + ") { } };");
   1.322 +    actual = "no error";
   1.323 +  }
   1.324 +  catch (e)
   1.325 +  {
   1.326 +    actual = e.name;
   1.327 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.328 +  }
   1.329 +  reportCompare(expectNormal, actual, status);
   1.330 +
   1.331 +  actual = "";
   1.332 +  status = summary + ": " + word + ": strict property setter argument";
   1.333 +  try
   1.334 +  {
   1.335 +    eval("'use strict'; var o = { set x(" + word + ") { } };");
   1.336 +    actual = "no error";
   1.337 +  }
   1.338 +  catch (e)
   1.339 +  {
   1.340 +    actual = e.name;
   1.341 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.342 +  }
   1.343 +  reportCompare(expectStrict, actual, status);
   1.344 +
   1.345 +  actual = "";
   1.346 +  status = summary + ": " + word + ": property setter argument retroactively strict";
   1.347 +  try
   1.348 +  {
   1.349 +    eval("var o = { set x(" + word + ") { 'use strict'; } };");
   1.350 +    actual = "no error";
   1.351 +  }
   1.352 +  catch (e)
   1.353 +  {
   1.354 +    actual = e.name;
   1.355 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.356 +  }
   1.357 +  reportCompare(expectStrict, actual, status);
   1.358 +
   1.359 +  // USE AS FUNCTION NAME IN FUNCTION DECLARATION
   1.360 +
   1.361 +  actual = "";
   1.362 +  status = summary + ": " + word + ": normal function name";
   1.363 +  try
   1.364 +  {
   1.365 +    eval("function " + word + "() { }");
   1.366 +    actual = "no error";
   1.367 +  }
   1.368 +  catch (e)
   1.369 +  {
   1.370 +    actual = e.name;
   1.371 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.372 +  }
   1.373 +  reportCompare(expectNormal, actual, status);
   1.374 +
   1.375 +  actual = "";
   1.376 +  status = summary + ": " + word + ": strict function name";
   1.377 +  try
   1.378 +  {
   1.379 +    eval("'use strict'; function " + word + "() { }");
   1.380 +    actual = "no error";
   1.381 +  }
   1.382 +  catch (e)
   1.383 +  {
   1.384 +    actual = e.name;
   1.385 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.386 +  }
   1.387 +  reportCompare(expectStrict, actual, status);
   1.388 +
   1.389 +  actual = "";
   1.390 +  status = summary + ": " + word + ": function name retroactively strict";
   1.391 +  try
   1.392 +  {
   1.393 +    eval("function " + word + "() { 'use strict'; }");
   1.394 +    actual = "no error";
   1.395 +  }
   1.396 +  catch (e)
   1.397 +  {
   1.398 +    actual = e.name;
   1.399 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.400 +  }
   1.401 +  reportCompare(expectStrict, actual, status);
   1.402 +
   1.403 +  // USE AS FUNCTION NAME IN FUNCTION EXPRESSION
   1.404 +
   1.405 +  actual = "";
   1.406 +  status = summary + ": " + word + ": normal function expression name";
   1.407 +  try
   1.408 +  {
   1.409 +    eval("var s = (function " + word + "() { });");
   1.410 +    actual = "no error";
   1.411 +  }
   1.412 +  catch (e)
   1.413 +  {
   1.414 +    actual = e.name;
   1.415 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.416 +  }
   1.417 +  reportCompare(expectNormal, actual, status);
   1.418 +
   1.419 +  actual = "";
   1.420 +  status = summary + ": " + word + ": strict function expression name";
   1.421 +  try
   1.422 +  {
   1.423 +    eval("'use strict'; var s = (function " + word + "() { });");
   1.424 +    actual = "no error";
   1.425 +  }
   1.426 +  catch (e)
   1.427 +  {
   1.428 +    actual = e.name;
   1.429 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.430 +  }
   1.431 +  reportCompare(expectStrict, actual, status);
   1.432 +
   1.433 +  actual = "";
   1.434 +  status = summary + ": " + word + ": function expression name retroactively strict";
   1.435 +  try
   1.436 +  {
   1.437 +    eval("var s = (function " + word + "() { 'use strict'; });");
   1.438 +    actual = "no error";
   1.439 +  }
   1.440 +  catch (e)
   1.441 +  {
   1.442 +    actual = e.name;
   1.443 +    status +=  ", " + e.name + ": " + e.message + " ";
   1.444 +  }
   1.445 +  reportCompare(expectStrict, actual, status);
   1.446 +}
   1.447 +
   1.448 +function testFutureReservedWord(word)
   1.449 +{
   1.450 +  testWord(word, "SyntaxError", "SyntaxError");
   1.451 +}
   1.452 +
   1.453 +function testStrictFutureReservedWord(word)
   1.454 +{
   1.455 +  testWord(word, "no error", "SyntaxError");
   1.456 +}
   1.457 +
   1.458 +futureReservedWords.forEach(testFutureReservedWord);
   1.459 +strictFutureReservedWords.forEach(testStrictFutureReservedWord);
   1.460 +
   1.461 +/******************************************************************************/
   1.462 +
   1.463 +if (typeof reportCompare === "function")
   1.464 +  reportCompare(true, true);
   1.465 +
   1.466 +print("All tests passed!");

mercurial