09.ObjectLiteral.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 write(v) { WScript.Echo(v + ""); }
  6. function exceptToString(ee) {
  7. if (ee instanceof TypeError) return "TypeError";
  8. if (ee instanceof ReferenceError) return "ReferenceError";
  9. if (ee instanceof EvalError) return "EvalError";
  10. if (ee instanceof SyntaxError) return "SyntaxError";
  11. return "Unknown Error";
  12. }
  13. (function Test1() {
  14. var str = "Property named eval";
  15. try {
  16. eval("var o = { set x(eval) { this.value = eval;}, get x() { return this.value;} };");
  17. o.x = 10;
  18. write("o.x : " + o.x);
  19. write("o.value : " + o.value);
  20. } catch (e) {
  21. write("Exception: " + str + " " + exceptToString(e));
  22. return;
  23. }
  24. write("Return: " + str);
  25. }) ();
  26. (function Test2() {
  27. var str = "Property named arguments";
  28. try {
  29. eval("var o = { set x(arguments) { this.value = arguments;}, get x() { return this.value;} };");
  30. o.x = 10;
  31. write("o.x : " + o.x);
  32. write("o.value : " + o.value);
  33. } catch (e) {
  34. write("Exception: " + str + " " + exceptToString(e));
  35. return;
  36. }
  37. write("Return: " + str);
  38. }) ();