defineProperty.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 TestDefineProperty(desc, testName) {
  6. WScript.Echo(testName);
  7. CatchAndWriteExceptions(function () {
  8. Object.defineProperty(new Object(), "foo", desc);
  9. WScript.Echo("Success");
  10. });
  11. }
  12. function CatchAndWriteExceptions(func) {
  13. try {
  14. func();
  15. }
  16. catch (e) {
  17. WScript.Echo(e.name + ": " + e.number);
  18. }
  19. }
  20. var bools = [true, false];
  21. var boolsExtended = [true, false];
  22. boolsExtended[2] = undefined; // Work around WOOB 1099317 in compat mode
  23. var desc;
  24. for (var includeValue in bools) {
  25. for (var includeWritable in boolsExtended) {
  26. for (var includeGetter in bools) {
  27. for (var includeSetter in bools) {
  28. var s = "";
  29. var b;
  30. desc = {};
  31. b = bools[includeValue];
  32. if (b) { desc.value = "fooValue"; s += "value; "; }
  33. b = boolsExtended[includeWritable];
  34. if (b !== undefined) { desc.writable = b; s += "writable=" + b + "; "; }
  35. b = bools[includeGetter];
  36. if (b) { desc.get = function () { return "aValue"; }; s += "getter; "; }
  37. b = bools[includeSetter];
  38. if (b) { desc.set = function (v) { }; s += "setter; "; }
  39. TestDefineProperty(desc, s);
  40. }
  41. }
  42. }
  43. }