accessor.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. var x = { foo: 3, bar: null };
  6. Object.defineProperty(x, "b", {
  7. get: function () { return this.foo + 1; },
  8. set: function (x) { this.foo = x / 2; }
  9. });
  10. Object.defineProperty(x, "onlyone", {
  11. get: function () { return this.bar; }
  12. });
  13. var y = {};
  14. Object.defineProperty(y, "pdata", { value : 24 });
  15. Object.defineProperty(y, "pwrite", {value : 12, writable: true});
  16. Object.defineProperty(y, "pdel", {get : function() {return "pdel";}, configurable: true});
  17. Object.defineProperty(y, "pconfig", {get : function() {return "pconfig";}, configurable: true});
  18. Object.defineProperty(y, "penum", {get : function() {return "penum";}, enumerable: true});
  19. var oWritable = {};
  20. Object.defineProperty(oWritable, "p", { writable: true });
  21. var oNotWritable = {};
  22. Object.defineProperty(oNotWritable, "p", { writable: false });
  23. WScript.SetTimeout(testFunction, 50);
  24. /////////////////
  25. function testFunction()
  26. {
  27. telemetryLog(`typeof (x): ${typeof (x)}`, true); //object
  28. telemetryLog(`x.foo: ${x.foo}`, true); //3
  29. telemetryLog(`x.b: ${x.b}`, true); //4
  30. telemetryLog(`x.onlyone: ${x.onlyone}`, true); //null
  31. ////
  32. x.b = 12;
  33. ////
  34. telemetryLog(`x.foo: ${x.foo}`, true); //6
  35. telemetryLog(`x.b: ${x.b}`, true); //7
  36. telemetryLog(`Object.getOwnPropertyDescriptor(y.pdata): ${JSON.stringify(Object.getOwnPropertyDescriptor(y, "pdata"))}`, true); //asdf
  37. telemetryLog(`Object.getOwnPropertyDescriptor(y.pwrite): ${JSON.stringify(Object.getOwnPropertyDescriptor(y, "pwrite"))}`, true); //asdf
  38. telemetryLog(`Object.getOwnPropertyDescriptor(y.pdel): ${JSON.stringify(Object.getOwnPropertyDescriptor(y, "pdel"))}`, true); //asdf
  39. telemetryLog(`Object.getOwnPropertyDescriptor(y.pconfig): ${JSON.stringify(Object.getOwnPropertyDescriptor(y, "pconfig"))}`, true); //asdf
  40. telemetryLog(`Object.getOwnPropertyDescriptor(y.penum): ${JSON.stringify(Object.getOwnPropertyDescriptor(y, "penum"))}`, true); //asdf
  41. telemetryLog(`y.pdel: ${y.pdel}`, true); //pdel
  42. delete y.pdel; //no exception here
  43. telemetryLog(`y.pdel: ${y.pdel}`, true); //undef
  44. telemetryLog(`Object.getOwnPropertyDescriptor(y.pdel): ${JSON.stringify(Object.getOwnPropertyDescriptor(y, "pdel"))}`, true); //asdf
  45. oWritable.p = 10;
  46. oNotWritable.p = 10;
  47. telemetryLog(`oWritable.p: ${oWritable.p}`, true); //10
  48. telemetryLog(`oNotWritable.p: ${oNotWritable.p}`, true); //undef
  49. }