| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- WScript.Echo("Testing invalidation due to overwrite:");
- var proto1 = {
- // Make sure we branch to a unique type path to avoid false sharing
- unique1_1: 0,
- add: function () {
- return (this.x + this.y) + " (original)";
- },
- subtract: function () {
- return (this.x - this.y) + " (original)";
- }
- }
- var object1 = Object.create(proto1);
- object1.x = 0;
- object1.y = 1;
- var testOverwrite = function (object) {
- WScript.Echo("x + y = " + object.add());
- WScript.Echo("x - y = " + object.subtract());
- }
- testOverwrite(object1);
- testOverwrite(object1);
- proto1.subtract = function () {
- return (this.x - this.y) + " (overwritten)";
- }
- testOverwrite(object1);
- proto1.add = function () {
- return (this.x + this.y) + " (overwritten)";
- }
- testOverwrite(object1);
- var proto1 = {
- // Make sure we branch to a unique type path to avoid false sharing
- unique1_2: 0,
- add: function () {
- return (this.x + this.y) + " (original)";
- },
- subtract: function () {
- return (this.x - this.y) + " (original)";
- }
- }
- var object1 = Object.create(proto1);
- object1.x = 0;
- object1.y = 1;
- var overwrittenSubtract = function () {
- return (this.x - this.y) + " (overwritten)";
- }
- var testOverwrite = function (object, overwrite) {
- WScript.Echo("x + y = " + object.add());
- if (overwrite) {
- proto1.subtract = overwrittenSubtract;
- }
- WScript.Echo("x - y = " + object.subtract());
- }
- testOverwrite(object1, false);
- testOverwrite(object1, false);
- testOverwrite(object1, true);
- WScript.Echo();
- WScript.Echo("Testing invalidation due to delete:");
- var proto2 = {
- // Make sure we branch to a unique type path to avoid false sharing
- unique2: 0,
- add: function () {
- return (this.x + this.y) + " (from proto2)";
- },
- subtract: function () {
- return (this.x - this.y) + " (from proto2)";
- }
- }
- var proto1 = Object.create(proto2, {
- // Make sure we branch to a unique type path to avoid false sharing
- unique3: { value: 0 },
- add: {
- value: function () {
- return (this.x + this.y) + " (from proto1)";
- },
- writable: true, configurable: true
- },
- subtract: {
- value: function () {
- return (this.x - this.y) + " (from proto1)";
- },
- writable: true, configurable: true
- }
- });
- var object1 = Object.create(proto1);
- object1.x = 0;
- object1.y = 1;
- function testDelete(object) {
- WScript.Echo("x + y = " + object.add());
- WScript.Echo("x - y = " + object.subtract());
- }
- testDelete(object1);
- testDelete(object1);
- delete proto1.subtract;
- testDelete(object1);
- delete proto1.add;
- testDelete(object1);
- WScript.Echo();
- WScript.Echo("Testing invalidation due to shadowing:");
- var proto2 = {
- // Make sure we branch to a unique type path to avoid false sharing
- unique4: 0,
- add: function () {
- return (this.x + this.y) + " (from proto2)";
- },
- subtract: function () {
- return (this.x - this.y) + " (from proto2)";
- }
- }
- var proto1 = Object.create(proto2, {
- // Make sure we branch to a unique type path to avoid false sharing
- unique5: { value: 0 },
- });
- var object1 = Object.create(proto1);
- object1.x = 0;
- object1.y = 1;
- function testShadow(object) {
- WScript.Echo("x + y = " + object.add());
- WScript.Echo("x - y = " + object.subtract());
- }
- testShadow(object1);
- testShadow(object1);
- proto1.subtract = function () {
- return (this.x - this.y) + " (from proto1)";
- };
- testShadow(object1);
- proto1.add = function () {
- return (this.x + this.y) + " (from proto1)";
- };
- testShadow(object1);
- WScript.Echo();
|