Bug 1593329 - Split up FinalizationGroup tests r=sfink
authorJon Coppeard <jcoppeard@mozilla.com>
Fri, 08 Nov 2019 13:40:34 +0000
changeset 501304 aa8e5bc16edd8ec3597de2d36044834218fba0cb
parent 501303 1de3fc411adadda1b2bb87f392d754039942b3fc
child 501305 39bc5b23a7a9047fa3770d80787a0d93c9491ee9
push id100114
push userjcoppeard@mozilla.com
push dateFri, 08 Nov 2019 14:08:13 +0000
treeherderautoland@aa8e5bc16edd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1593329
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1593329 - Split up FinalizationGroup tests r=sfink Differential Revision: https://phabricator.services.mozilla.com/D52196
js/src/jit-test/tests/gc/finalizationGroup-ccw.js
js/src/jit-test/tests/gc/finalizationGroup-oom1.js
js/src/jit-test/tests/gc/finalizationGroup-oom2.js
js/src/jit-test/tests/gc/finalizationGroup-oom3.js
js/src/jit-test/tests/gc/finalizationGroup.js
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/gc/finalizationGroup-ccw.js
@@ -0,0 +1,52 @@
+// |jit-test| --enable-weak-refs
+
+// Test combinations of arguments in different compartments.
+
+gczeal(0);
+
+let holdings = [];
+let group = new FinalizationGroup(iterator => {
+    for (const holding of iterator) {
+        holdings.push(holding);
+    }
+});
+
+function ccwToObject() {
+    return evalcx('({})', newGlobal({newCompartment: true}));
+}
+
+function ccwToGroup() {
+    let global = newGlobal({newCompartment: true});
+    global.holdings = holdings;
+    return global.eval(
+        `new FinalizationGroup(iterator => holdings.push(...iterator))`);
+}
+
+function incrementalGC() {
+    startgc(1);
+    while (gcstate() !== "NotActive") {
+        gcslice(1000);
+    }
+}
+
+for (let w of [false, true]) {
+    for (let x of [false, true]) {
+        for (let y of [false, true]) {
+            for (let z of [false, true]) {
+                let g = w ? ccwToGroup(w) : group;
+                let target = x ? ccwToObject() : {};
+                let holding = y ? ccwToObject() : {};
+                let token = z ? ccwToObject() : {};
+                g.register(target, holding, token);
+                g.unregister(token);
+                g.register(target, holding, token);
+                target = undefined;
+                incrementalGC();
+                holdings.length = 0; // Clear, don't replace.
+                g.cleanupSome();
+                assertEq(holdings.length, 1);
+                assertEq(holdings[0], holding);
+            }
+        }
+    }
+}
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/gc/finalizationGroup-oom1.js
@@ -0,0 +1,8 @@
+// |jit-test| --enable-weak-refs; skip-if: !('oomTest' in this)
+
+// Don't test prototype initialization etc.
+new FinalizationGroup(x => 0);
+
+oomTest(() => {
+    new FinalizationGroup(x => 0);
+});
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/gc/finalizationGroup-oom2.js
@@ -0,0 +1,4 @@
+// |jit-test| --enable-weak-refs; skip-if: !('oomTest' in this)
+let group = new FinalizationGroup(x => 0);
+let token = {};
+oomTest(() => group.register({}, 1, token));
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/gc/finalizationGroup-oom3.js
@@ -0,0 +1,4 @@
+// |jit-test| --enable-weak-refs; skip-if: !('oomTest' in this)
+let group = new FinalizationGroup(x => 0);
+group.register({}, 1, {});
+oomTest(() => group.unregister(token));
--- a/js/src/jit-test/tests/gc/finalizationGroup.js
+++ b/js/src/jit-test/tests/gc/finalizationGroup.js
@@ -154,25 +154,16 @@ group.register({}, 4, token2);
 group.unregister(token);
 gc();
 drainJobQueue();
 assertEq(holdings.length, 2);
 holdings = holdings.sort((a, b) => a - b);
 assertEq(holdings[0], 2);
 assertEq(holdings[1], 4);
 
-// OOM test.
-if ('oomTest' in this) {
-    oomTest(() => new FinalizationGroup(x => 0));
-
-    let token = {};
-    oomTest(() => group.register({}, 1, token));
-    oomTest(() => group.unregister(token));
-}
-
 // Watch object in another global.
 let other = newGlobal({newCompartment: true});
 holdings = [];
 group.register(evalcx('({})', other), 1);
 gc();
 drainJobQueue();
 assertEq(holdings.length, 1);
 assertEq(holdings[0], 1);
@@ -252,50 +243,8 @@ assertEq(holdings[2], 3);
 
 // Test trying to call cleanupSome in callback.
 let g6 = new FinalizationGroup(x => {
     assertThrowsTypeError(() => g6.cleanupSome());
 });
 g6.register({}, 1);
 gc();
 drainJobQueue();
-
-// Test combinations of arguments in different compartments.
-function ccwToObject() {
-    return evalcx('({})', newGlobal({newCompartment: true}));
-}
-function ccwToGroup() {
-    let global = newGlobal({newCompartment: true});
-    global.holdings = holdings;
-    return global.eval(`
-      new FinalizationGroup(iterator => {
-        for (const holding of iterator) {
-          holdings.push(holding);
-        }
-      })`);
-}
-function incrementalGC() {
-    startgc(1);
-    while (gcstate() !== "NotActive") {
-        gcslice(1000);
-    }
-}
-for (let w of [false, true]) {
-    for (let x of [false, true]) {
-        for (let y of [false, true]) {
-            for (let z of [false, true]) {
-                let g = w ? ccwToGroup(w) : group;
-                let target = x ? ccwToObject() : {};
-                let holding = y ? ccwToObject() : {};
-                let token = z ? ccwToObject() : {};
-                g.register(target, holding, token);
-                g.unregister(token);
-                g.register(target, holding, token);
-                target = undefined;
-                incrementalGC();
-                holdings.length = 0; // Clear, don't replace.
-                g.cleanupSome();
-                assertEq(holdings.length, 1);
-                assertEq(holdings[0], holding);
-            }
-        }
-    }
-}