scopedAccessors.js 1.8 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 top1() {
  6. var xx = new Object();
  7. Object.defineProperty(xx, "yy", { set: function(val) {telemetryLog("in nested setter1", true); this.val = 10;} });
  8. var z = function() {
  9. xx.yy = 20;
  10. telemetryLog(`val is ${xx.yy}`, true);
  11. }
  12. return z;
  13. }
  14. var foo1 = top1();
  15. function top2() {
  16. var xx = new Object();
  17. Object.defineProperty(xx, "yy", { get: function() { return this; },
  18. set: function(val) {telemetryLog("in nested setter2", true); this.val = 11;} });
  19. var z = function() {
  20. xx.yy = 20;
  21. telemetryLog(`val is ${xx.yy}`, true);
  22. telemetryLog(`val is ${xx.yy.val}`, true);
  23. }
  24. return z;
  25. }
  26. var foo2 = top2();
  27. function top3() {
  28. Object.defineProperty(this, "yy", { get: function() { return this; },
  29. set: function(val) {telemetryLog("in nested setter3"); this.val = 12;} });
  30. var z = function() {
  31. yy = 20;
  32. telemetryLog(`val is ${yy}`, true);
  33. telemetryLog(`val is ${yy.val}`, true);
  34. }
  35. return z;
  36. }
  37. var foo3 = top3();
  38. WScript.SetTimeout(testFunction, 50);
  39. /////////////////
  40. function testFunction()
  41. {
  42. telemetryLog("test1: nested setter without getter", true);
  43. foo1();
  44. telemetryLog("test2: nested setter and setter", true);
  45. foo2();
  46. telemetryLog("test3: nested setter and setter from this", true);
  47. foo3();
  48. emitTTDLog(ttdLogURI);
  49. }