13.delete.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. var scenarios = [
  14. "obj.foo", // obj is configurable false
  15. "'hello'[0]",
  16. "'hello'.length",
  17. "reg.source",
  18. "reg.global",
  19. "reg.lastIndex"
  20. ];
  21. (function Test1(x) {
  22. var str = "delete configurable false property";
  23. var obj = new Object();
  24. Object.defineProperty(obj, "foo", { configurable: false, value: 20 });
  25. var reg = /foo/;
  26. for (var i = 0; i < scenarios.length; ++i) {
  27. try {
  28. var r = eval("delete " + scenarios[i]);
  29. write("Return: " + scenarios[i] + " " + r);
  30. } catch (e) {
  31. write("Exception: " + scenarios[i] + " " + exceptToString(e));
  32. }
  33. }
  34. })();