IdsWithEscapes.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function Execute(str)
  6. {
  7. try {
  8. eval(str);
  9. }
  10. catch (e) {
  11. WScript.Echo(e);
  12. }
  13. }
  14. // Keywords that are reserved cannot be used as identifiers. Examples: var, with, false
  15. // Other keywords are not reserved, and can be used as identifiers. Examples: double, byte
  16. // regular identifier, referenced later with unicode variant
  17. Execute("var hello=10; WScript.Echo(hello); WScript.Echo(h\\u0065llo);");
  18. // identifier with unicode variant. Used with and without unicode
  19. Execute("var h\u0065llo=20; WScript.Echo(hello); WScript.Echo(h\\u0065llo);");
  20. // undefined identifier with unicode. Should throw a reference error
  21. Execute("WScript.Echo(h\\u0065llo2);");
  22. // Valid use of some reserved keywords in expressions, like FALSE
  23. // Invalid as of ES6 Draft 22
  24. Execute("WScript.Echo(fals\\u0065);");
  25. Execute("var a = fals\\u0065; WScript.Echo(a);");
  26. Execute("var b = tru\\u0065; WScript.Echo(b);");
  27. // Invalid use of a reserved keyword in an expression. Should throw a syntax error
  28. Execute("var c = var;");
  29. Execute("var c = v\\u0061r;");
  30. Execute("var c = else;");
  31. Execute("var c = els\\u0065;");
  32. // Reserved keyword declared as a var. Should throw an error indicating use of keyword as an identifier
  33. Execute("var false=30; WScript.Echo(false); WScript.Echo(fals\\u0065);");
  34. Execute("var var=30; WScript.Echo(var); WScript.Echo(v\\u0061r);");
  35. Execute("var fals\\u0065=40; WScript.Echo(false); WScript.Echo(fals\\u0065);");
  36. Execute("var v\\u0061r=30; WScript.Echo(var); WScript.Echo(v\\u0061r);");
  37. // Use a reserved keyword as a property, legal
  38. Execute("var x1={};x1.else = 10;WScript.Echo(x1.else);");
  39. Execute("var x2={};x2.els\\u0065 = 10;WScript.Echo(x2.els\\u0065);");
  40. // Use an unreserved keyword as a property, legal
  41. Execute("var x1={};x1.double = 10;WScript.Echo(x1.double);");
  42. Execute("var x2={};x2.doubl\\u0065 = 10;WScript.Echo(x2.doubl\\u0065);");
  43. // Use a reserved keyword as a function name, not legal
  44. Execute("function else() {};");
  45. Execute("function els\\u0065() {};");
  46. // Use an unreserved keyword as a function name, legal
  47. Execute("function double() {};");
  48. Execute("function doubl\\u0065() {};");