stackobject_escape.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 leak;
  6. var c = 0;
  7. function Ctor()
  8. {
  9. this.b = 2;
  10. this.a = c + c;
  11. }
  12. function test1()
  13. {
  14. var a = new Ctor();
  15. return a + a;
  16. }
  17. WScript.Echo(test1());
  18. WScript.Echo(test1());
  19. Ctor.prototype.valueOf = function() { leak = this; return 40; }
  20. WScript.Echo(test1());
  21. WScript.Echo(leak.a);
  22. WScript.Echo(leak.b);
  23. function test2()
  24. {
  25. var a = new Ctor();
  26. var f = a.a;
  27. var g = a.b;
  28. return f + g + a.a;
  29. }
  30. WScript.Echo(test2());
  31. WScript.Echo(test2());
  32. Object.defineProperty(Ctor.prototype, "b", { get: function() { WScript.Echo("get"); return 3; }, set: function() { leak = this; WScript.Echo("set");} });
  33. WScript.Echo(test2());
  34. WScript.Echo(leak.a);
  35. WScript.Echo(leak.b);
  36. function test3()
  37. {
  38. var a = [ 1 ];
  39. a[1] = 2;
  40. return a[0] + a[1];
  41. }
  42. WScript.Echo(test3());
  43. WScript.Echo(test3());
  44. Object.defineProperty(Array.prototype, "1" , { get: function() { WScript.Echo("get"); return 4; }, set: function() { leak = this; WScript.Echo("set"); }});
  45. WScript.Echo(test3());
  46. WScript.Echo(leak[0]);
  47. WScript.Echo(leak[1]);