callsideeffects.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 write(v) { WScript.Echo("" + v); }
  6. var x = ['x'];
  7. x.call1 = function() { write('In x.call1: this = ' + this) };
  8. var y = ['y'];
  9. y.call1 = function() { write('In y.call1: this = ' + this) };
  10. function call1()
  11. {
  12. write('In call1: this = ' + this);
  13. }
  14. function call2()
  15. {
  16. write('In call2: this = ' + this);
  17. }
  18. var savecall1 = call1;
  19. call1(call1 = call2);
  20. call1 = savecall1;
  21. savecall1 = x.call1;
  22. x.call1(x.call1 = call1);
  23. x.call1 = savecall1;
  24. var savex = x;
  25. x.call1(x.call1 = y.call1);
  26. x = savex;
  27. x.call1 = savecall1;
  28. var s = 'call1';
  29. x[x = s]();
  30. x = savex;
  31. x[s](s = 'call2');
  32. s = 'call1';
  33. x[s](x[s] = y.call1);
  34. x[s] = x.call1;
  35. (function() {
  36. // Now try the same set of stuff when call target components are local.
  37. var x = ['x'];
  38. x.call1 = function() { write('In x.call1: this = ' + this) };
  39. var y = ['y'];
  40. y.call1 = function() { write('In y.call1: this = ' + this) };
  41. function call1()
  42. {
  43. write('In call1: this = ' + this);
  44. }
  45. function call2()
  46. {
  47. write('In call2: this = ' + this);
  48. }
  49. var savecall1 = call1;
  50. call1(call1 = call2);
  51. call1 = savecall1;
  52. savecall1 = x.call1;
  53. x.call1(x.call1 = call1);
  54. x.call1 = savecall1;
  55. var savex = x;
  56. x.call1(x.call1 = y.call1);
  57. x = savex;
  58. x.call1 = savecall1;
  59. var s = 'call1';
  60. x[x = s]();
  61. x = savex;
  62. x[s](s = 'call2');
  63. s = 'call1';
  64. x[s](x[s] = y.call1);
  65. x[s] = x.call1;
  66. })();
  67. (function() {
  68. var evalExpr = '' +
  69. 'var x = ["x"];' +
  70. 'x.call1 = function() { write("In x.call1: this = " + this) };' +
  71. 'var y = ["y"];' +
  72. 'y.call1 = function() { write("In y.call1: this = " + this) };' +
  73. 'function call1()' +
  74. '{' +
  75. 'write("In call1: this = " + this);' +
  76. '}' +
  77. 'function call2()' +
  78. '{' +
  79. 'write("In call2: this = " + this);' +
  80. '}' +
  81. 'var savecall1 = call1;' +
  82. 'call1(call1 = call2);' +
  83. 'call1 = savecall1;' +
  84. 'savecall1 = x.call1;' +
  85. 'x.call1(x.call1 = call1);' +
  86. 'x.call1 = savecall1;' +
  87. 'var savex = x;' +
  88. 'x.call1(x.call1 = y.call1);' +
  89. 'x = savex;' +
  90. 'x.call1 = savecall1;' +
  91. 'var s = "call1";' +
  92. 'x[x = s]();' +
  93. 'x = savex;' +
  94. 'x[s](s = "call2");' +
  95. 's = "call1";' +
  96. 'x[s](x[s] = y.call1);' +
  97. 'x[s] = x.call1;';
  98. eval(evalExpr);
  99. })();
  100. // Verify that we assign regs properly in a compound assignment to function call result.
  101. // Note: this will cease to be a valid test when early reference errors are thrown by default.
  102. function test5921858() {
  103. function eval([]){}
  104. function shapeyConstructor(fujzty){
  105. Object.defineProperty(this, "a",
  106. ({value: ((eval("true", window)) ^= z), writable: true, configurable: false}));
  107. }
  108. }