summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/watchtower
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/watchtower
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/watchtower')
-rw-r--r--js/src/jit-test/tests/watchtower/basic.js87
-rw-r--r--js/src/jit-test/tests/watchtower/bug-1871949.js19
-rw-r--r--js/src/jit-test/tests/watchtower/megamorphic-has-prop.js33
-rw-r--r--js/src/jit-test/tests/watchtower/megamorphic-invalidate.js81
-rw-r--r--js/src/jit-test/tests/watchtower/megamorphic-long-proto-chain.js28
-rw-r--r--js/src/jit-test/tests/watchtower/property-modification.js36
6 files changed, 284 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/watchtower/basic.js b/js/src/jit-test/tests/watchtower/basic.js
new file mode 100644
index 0000000000..dd3bbb45ff
--- /dev/null
+++ b/js/src/jit-test/tests/watchtower/basic.js
@@ -0,0 +1,87 @@
+function getLogString(obj) {
+ let log = getWatchtowerLog();
+ return log.map(item => {
+ assertEq(item.object, obj);
+ if (typeof item.extra === "symbol") {
+ item.extra = "<symbol>";
+ }
+ return item.kind + (item.extra ? ": " + item.extra : "");
+ }).join("\n");
+}
+
+function testBasic() {
+ let o = {};
+ addWatchtowerTarget(o);
+
+ o.x = 1;
+ o.y = 2;
+ o[Symbol()] = 3;
+ Object.defineProperty(o, "foo", {enumerable: false, configurable: false, value: 1});
+ Object.defineProperty(o, "getter", {get() { return 123; }});
+ o.__proto__ = {};
+ o.__proto__ = null;
+ o[12345] = 1; // Sparse elements are included for now.
+ delete o.x;
+ Object.defineProperty(o, "y", {writable: false});
+ Object.defineProperty(o, "x", {value: 0});
+ Object.seal(o);
+ Object.freeze(o);
+
+ let log = getLogString(o);
+ assertEq(log,
+`add-prop: x
+add-prop: y
+add-prop: <symbol>
+add-prop: foo
+add-prop: getter
+proto-change
+proto-change
+add-prop: 12345
+remove-prop: x
+change-prop: y
+add-prop: x
+freeze-or-seal
+freeze-or-seal`);
+}
+for (var i = 0; i < 20; i++) {
+ testBasic();
+}
+
+// Object.assign edge case.
+function testAssign() {
+ let o = {};
+ o.x = 1;
+ delete o.x;
+ let from = {x: 1, y: 2, z: 3, a: 4};
+ addWatchtowerTarget(o);
+ addWatchtowerTarget(from);
+ Object.assign(o, from);
+ let log = getLogString(o);
+ assertEq(log, "add-prop: x\nadd-prop: y\nadd-prop: z\nadd-prop: a");
+}
+testAssign();
+
+function testJit() {
+ for (var i = 0; i < 20; i++) {
+ let o = {};
+ addWatchtowerTarget(o);
+ o.x = 1;
+ o.y = 2;
+ let log = getLogString(o);
+ assertEq(log, "add-prop: x\nadd-prop: y");
+ }
+}
+testJit();
+
+// array.length is a custom data property.
+function testCustomDataProp() {
+ let o = [];
+ addWatchtowerTarget(o);
+
+ Object.defineProperty(o, "length", {writable: false});
+ let log = getLogString(o);
+ assertEq(log, "change-prop: length");
+}
+for (var i = 0; i < 20; i++) {
+ testCustomDataProp();
+}
diff --git a/js/src/jit-test/tests/watchtower/bug-1871949.js b/js/src/jit-test/tests/watchtower/bug-1871949.js
new file mode 100644
index 0000000000..9b8b277b36
--- /dev/null
+++ b/js/src/jit-test/tests/watchtower/bug-1871949.js
@@ -0,0 +1,19 @@
+function getLogString(obj) {
+ let log = getWatchtowerLog();
+ return log.map(item => {
+ assertEq(item.object, obj);
+ if (typeof item.extra === "symbol") {
+ item.extra = "<symbol>";
+ }
+ return item.kind + (item.extra ? ": " + item.extra : "");
+ }).join("\n");
+}
+
+const entry = cacheEntry("");
+addWatchtowerTarget(entry);
+evaluate(entry, { "saveIncrementalBytecode": true });
+let log = getLogString(entry);
+
+// Nothing is logged for the manipulation of reserved slots, as we
+// lack infrastructure to track them thus far.
+assertEq(log.length, 0);
diff --git a/js/src/jit-test/tests/watchtower/megamorphic-has-prop.js b/js/src/jit-test/tests/watchtower/megamorphic-has-prop.js
new file mode 100644
index 0000000000..98481c636e
--- /dev/null
+++ b/js/src/jit-test/tests/watchtower/megamorphic-has-prop.js
@@ -0,0 +1,33 @@
+function hasOwnProp(o, p) {
+ return Object.prototype.hasOwnProperty.call(o, p);
+}
+function testHasProp() {
+ var C = Object.create(null);
+ C.protox = 0;
+ var B = Object.create(C);
+ var objs = [];
+ for (var i = 0; i < 50; i++) {
+ var A = Object.create(B);
+ A["x" + i] = 0;
+ A.ownx = 3;
+ objs.push(A);
+ }
+ for (var i = 0; i < 10; i++) {
+ for (var j = 0; j < objs.length; j++) {
+ var obj = objs[j];
+ assertEq(hasOwnProp(obj, "protox"), false);
+ assertEq("protox" in obj, true);
+ assertEq(obj.protox, 0);
+
+ assertEq(hasOwnProp(obj, "ownx"), true);
+ assertEq("ownx" in obj, true);
+ assertEq(obj.ownx, 3);
+
+ assertEq("missing" in obj, false);
+ assertEq(hasOwnProp(obj, "missing"), false);
+ assertEq(obj.missing, undefined);
+ }
+ }
+}
+testHasProp();
+
diff --git a/js/src/jit-test/tests/watchtower/megamorphic-invalidate.js b/js/src/jit-test/tests/watchtower/megamorphic-invalidate.js
new file mode 100644
index 0000000000..b4c78359fa
--- /dev/null
+++ b/js/src/jit-test/tests/watchtower/megamorphic-invalidate.js
@@ -0,0 +1,81 @@
+setJitCompilerOption("ic.force-megamorphic", 1);
+
+function testAddToIntermediate() {
+ var C = Object.create(null);
+ var B = Object.create(C);
+ var A = Object.create(B);
+ C.x = 1;
+ for (var i = 0; i < 50; i++) {
+ assertEq(A.x, i <= 45 ? 1 : 0);
+ if (i === 45) {
+ B.x = 0;
+ }
+ }
+}
+for (var i = 0; i < 5; i++) {
+ testAddToIntermediate();
+}
+
+function testAddToReceiver() {
+ var C = Object.create(null);
+ var B = Object.create(C);
+ var A = Object.create(B);
+ C.x = 1;
+ for (var i = 0; i < 50; i++) {
+ assertEq(A.x, i <= 45 ? 1 : 0);
+ if (i === 45) {
+ A.x = 0;
+ }
+ }
+}
+for (var i = 0; i < 5; i++) {
+ testAddToReceiver();
+}
+
+function testDelete() {
+ var C = Object.create(null);
+ var B = Object.create(C);
+ var A = Object.create(B);
+ C.x = 1;
+ for (var i = 0; i < 50; i++) {
+ assertEq(A.x, i <= 45 ? 1 : undefined);
+ if (i === 45) {
+ delete C.x;
+ }
+ }
+}
+for (var i = 0; i < 5; i++) {
+ testDelete();
+}
+
+function testDataToAccessor() {
+ var C = Object.create(null);
+ var B = Object.create(C);
+ var A = Object.create(B);
+ C.x = 1;
+ for (var i = 0; i < 50; i++) {
+ assertEq(A.x, i <= 45 ? 1 : 7);
+ if (i === 45) {
+ Object.defineProperty(C, "x", {get: () => 7});
+ }
+ }
+}
+for (var i = 0; i < 5; i++) {
+ testDataToAccessor();
+}
+
+function testProtoChange() {
+ var C = Object.create(null);
+ var B = Object.create(C);
+ var A = Object.create(B);
+ C.x = 1;
+ for (var i = 0; i < 50; i++) {
+ assertEq(A.x, i <= 45 ? 1 : 8);
+ if (i === 45) {
+ Object.setPrototypeOf(B, {a: 0, b: 1, x: 8});
+ }
+ }
+}
+for (var i = 0; i < 5; i++) {
+ testProtoChange();
+}
diff --git a/js/src/jit-test/tests/watchtower/megamorphic-long-proto-chain.js b/js/src/jit-test/tests/watchtower/megamorphic-long-proto-chain.js
new file mode 100644
index 0000000000..675f29333f
--- /dev/null
+++ b/js/src/jit-test/tests/watchtower/megamorphic-long-proto-chain.js
@@ -0,0 +1,28 @@
+setJitCompilerOption("ic.force-megamorphic", 1);
+
+function objectWithHops(hops) {
+ var o = Object.create(null);
+ o.hops = hops;
+ for (var i = 0; i < hops; i++) {
+ o = Object.create(o);
+ }
+ return o;
+}
+function test() {
+ var objs = [];
+ for (var i = 0; i < 32; i++) {
+ objs.push(objectWithHops(230 + i));
+ }
+ for (var i = 0; i < 130; i++) {
+ var o = objs[i % objs.length];
+ assertEq(o.hops, 230 + (i % objs.length));
+ assertEq("hops" in o, true);
+ assertEq(Object.hasOwnProperty.call(o, "hops"), false);
+ assertEq(o.missing, undefined);
+ assertEq("missing" in o, false);
+ assertEq(Object.hasOwnProperty.call(o, "missing"), false);
+ }
+}
+for (var i = 0; i < 10; i++) {
+ test();
+}
diff --git a/js/src/jit-test/tests/watchtower/property-modification.js b/js/src/jit-test/tests/watchtower/property-modification.js
new file mode 100644
index 0000000000..993cb5bdf8
--- /dev/null
+++ b/js/src/jit-test/tests/watchtower/property-modification.js
@@ -0,0 +1,36 @@
+function getLogString(obj) {
+ let log = getWatchtowerLog();
+ return log.map(item => {
+ assertEq(item.object, obj);
+ if (typeof item.extra === "symbol") {
+ item.extra = "<symbol>";
+ }
+ return item.kind + (item.extra ? ": " + item.extra : "");
+ }).join("\n");
+}
+
+function testBasic() {
+ let o = { a: 10 };
+ addWatchtowerTarget(o);
+
+ // modify-prop: a
+ o.a = 12;
+ let p = { a: 15 };
+
+ // modify-prop: a
+ Object.assign(o, p);
+
+ // change-prop: a
+ Object.defineProperty(o, "a", { value: 19 });
+ let log = getLogString(o);
+
+ assertEq(log,
+ `modify-prop: a
+modify-prop: a
+change-prop: a`);
+}
+
+for (var i = 0; i < 20; i++) {
+ console.log(`Iteration ${i}`);
+ testBasic();
+}