FixedFieldsInvalidation.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. WScript.Echo("Testing invalidation due to overwrite:");
  6. var proto1 = {
  7. // Make sure we branch to a unique type path to avoid false sharing
  8. unique1_1: 0,
  9. add: function () {
  10. return (this.x + this.y) + " (original)";
  11. },
  12. subtract: function () {
  13. return (this.x - this.y) + " (original)";
  14. }
  15. }
  16. var object1 = Object.create(proto1);
  17. object1.x = 0;
  18. object1.y = 1;
  19. var testOverwrite = function (object) {
  20. WScript.Echo("x + y = " + object.add());
  21. WScript.Echo("x - y = " + object.subtract());
  22. }
  23. testOverwrite(object1);
  24. testOverwrite(object1);
  25. proto1.subtract = function () {
  26. return (this.x - this.y) + " (overwritten)";
  27. }
  28. testOverwrite(object1);
  29. proto1.add = function () {
  30. return (this.x + this.y) + " (overwritten)";
  31. }
  32. testOverwrite(object1);
  33. var proto1 = {
  34. // Make sure we branch to a unique type path to avoid false sharing
  35. unique1_2: 0,
  36. add: function () {
  37. return (this.x + this.y) + " (original)";
  38. },
  39. subtract: function () {
  40. return (this.x - this.y) + " (original)";
  41. }
  42. }
  43. var object1 = Object.create(proto1);
  44. object1.x = 0;
  45. object1.y = 1;
  46. var overwrittenSubtract = function () {
  47. return (this.x - this.y) + " (overwritten)";
  48. }
  49. var testOverwrite = function (object, overwrite) {
  50. WScript.Echo("x + y = " + object.add());
  51. if (overwrite) {
  52. proto1.subtract = overwrittenSubtract;
  53. }
  54. WScript.Echo("x - y = " + object.subtract());
  55. }
  56. testOverwrite(object1, false);
  57. testOverwrite(object1, false);
  58. testOverwrite(object1, true);
  59. WScript.Echo();
  60. WScript.Echo("Testing invalidation due to delete:");
  61. var proto2 = {
  62. // Make sure we branch to a unique type path to avoid false sharing
  63. unique2: 0,
  64. add: function () {
  65. return (this.x + this.y) + " (from proto2)";
  66. },
  67. subtract: function () {
  68. return (this.x - this.y) + " (from proto2)";
  69. }
  70. }
  71. var proto1 = Object.create(proto2, {
  72. // Make sure we branch to a unique type path to avoid false sharing
  73. unique3: { value: 0 },
  74. add: {
  75. value: function () {
  76. return (this.x + this.y) + " (from proto1)";
  77. },
  78. writable: true, configurable: true
  79. },
  80. subtract: {
  81. value: function () {
  82. return (this.x - this.y) + " (from proto1)";
  83. },
  84. writable: true, configurable: true
  85. }
  86. });
  87. var object1 = Object.create(proto1);
  88. object1.x = 0;
  89. object1.y = 1;
  90. function testDelete(object) {
  91. WScript.Echo("x + y = " + object.add());
  92. WScript.Echo("x - y = " + object.subtract());
  93. }
  94. testDelete(object1);
  95. testDelete(object1);
  96. delete proto1.subtract;
  97. testDelete(object1);
  98. delete proto1.add;
  99. testDelete(object1);
  100. WScript.Echo();
  101. WScript.Echo("Testing invalidation due to shadowing:");
  102. var proto2 = {
  103. // Make sure we branch to a unique type path to avoid false sharing
  104. unique4: 0,
  105. add: function () {
  106. return (this.x + this.y) + " (from proto2)";
  107. },
  108. subtract: function () {
  109. return (this.x - this.y) + " (from proto2)";
  110. }
  111. }
  112. var proto1 = Object.create(proto2, {
  113. // Make sure we branch to a unique type path to avoid false sharing
  114. unique5: { value: 0 },
  115. });
  116. var object1 = Object.create(proto1);
  117. object1.x = 0;
  118. object1.y = 1;
  119. function testShadow(object) {
  120. WScript.Echo("x + y = " + object.add());
  121. WScript.Echo("x - y = " + object.subtract());
  122. }
  123. testShadow(object1);
  124. testShadow(object1);
  125. proto1.subtract = function () {
  126. return (this.x - this.y) + " (from proto1)";
  127. };
  128. testShadow(object1);
  129. proto1.add = function () {
  130. return (this.x + this.y) + " (from proto1)";
  131. };
  132. testShadow(object1);
  133. WScript.Echo();