objlitgetset2.js 1.6 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 __getProperties(obj) {
  6. let properties = [];
  7. for (let name of Object.getOwnPropertyNames(obj)) {
  8. properties.push(name);
  9. }
  10. return properties;
  11. }
  12. function __getRandomObject() {
  13. }
  14. function __getRandomProperty(obj, seed) {
  15. let properties = __getProperties(obj);
  16. return properties[seed % properties.length];
  17. }
  18. (function __f_2672() {
  19. __v_13851 = {
  20. get p() {
  21. }
  22. }
  23. __v_13862 = {
  24. get p() {
  25. },
  26. p: 2,
  27. set p(__v_13863) { WScript.Echo('pass'); this.q = __v_13863},
  28. p:9,
  29. q:3,
  30. set p(__v_13863) { WScript.Echo('pass'); this.q = __v_13863},
  31. };
  32. __v_13862.p = 0;
  33. if (__v_13862.q !== 0) WScript.Echo(__v_13862.q);
  34. })();
  35. __v_13851[__getRandomProperty(__v_13851, 483779)] = __getRandomObject();
  36. let o = {get a(){},x:0};
  37. if (o.x !== 0) WScript.Echo('fail x0');
  38. Object.defineProperty(o, 'x', {configurable:true,enumerable:true,get:function(){return 'x1'}});
  39. if (o.x !== 'x1') WScript.Echo('fail x1');
  40. let p = {get a(){},x:0};
  41. p.y = 'y';
  42. Object.defineProperty(p, 'x', {configurable:true,enumerable:true,get:function(){return 'x2'}});
  43. if (p.x !== 'x2') WScript.Echo('fail x2');
  44. if (p.y !== 'y') WScript.Echo('fail y');