зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1618258 - Part 2: Rename FinalizationGroup to FinalizationRegistry in test files. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D66931 --HG-- rename : js/src/jit-test/tests/gc/finalizationGroup-ccw.js => js/src/jit-test/tests/gc/finalizationRegistry-ccw.js rename : js/src/jit-test/tests/gc/finalizationGroup-gray.js => js/src/jit-test/tests/gc/finalizationRegistry-gray.js rename : js/src/jit-test/tests/gc/finalizationGroup-oom1.js => js/src/jit-test/tests/gc/finalizationRegistry-oom1.js rename : js/src/jit-test/tests/gc/finalizationGroup-oom2.js => js/src/jit-test/tests/gc/finalizationRegistry-oom2.js rename : js/src/jit-test/tests/gc/finalizationGroup-oom3.js => js/src/jit-test/tests/gc/finalizationRegistry-oom3.js rename : js/src/jit-test/tests/gc/finalizationGroup-oom4.js => js/src/jit-test/tests/gc/finalizationRegistry-oom4.js rename : js/src/jit-test/tests/gc/finalizationGroup-records-not-initialized.js => js/src/jit-test/tests/gc/finalizationRegistry-records-not-initialized.js rename : js/src/jit-test/tests/gc/finalizationGroup.js => js/src/jit-test/tests/gc/finalizationRegistry.js rename : js/xpconnect/tests/mochitest/finalizationGroup_worker.js => js/xpconnect/tests/mochitest/finalizationRegistry_worker.js rename : js/xpconnect/tests/mochitest/test_finalizationGroup.html => js/xpconnect/tests/mochitest/test_finalizationRegistry.html rename : js/xpconnect/tests/mochitest/test_finalizationGroupInWorker.html => js/xpconnect/tests/mochitest/test_finalizationRegistryInWorker.html extra : moz-landing-system : lando
This commit is contained in:
Родитель
0105311d41
Коммит
6b3564cef8
|
@ -2,5 +2,5 @@
|
|||
enableShellAllocationMetadataBuilder();
|
||||
evaluate(`
|
||||
gczeal(9,3);
|
||||
new FinalizationGroup(function() {});
|
||||
new FinalizationRegistry(function() {});
|
||||
`);
|
||||
|
|
|
@ -8,7 +8,7 @@ function f() {
|
|||
newCompartment: true
|
||||
});
|
||||
try {
|
||||
return global.eval("new FinalizationGroup(function(){})");
|
||||
return global.eval("new FinalizationRegistry(function(){})");
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError && e.message.includes('dead')) {
|
||||
// Creating a new CCW to the global fails with
|
||||
|
@ -18,6 +18,6 @@ function f() {
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
g = f();
|
||||
g.register({}, {}, {});
|
||||
r = f();
|
||||
r.register({}, {}, {});
|
||||
startgc();
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
// |jit-test| --enable-weak-refs
|
||||
|
||||
// Test that drainJobQueue() drains all jobs, including those queued
|
||||
// by FinalizationGroup callbacks.
|
||||
// by FinalizationRegistry callbacks.
|
||||
|
||||
let finalizeRan = false;
|
||||
let promiseRan = false;
|
||||
|
||||
let fg = new FinalizationGroup(() => {
|
||||
let fr = new FinalizationRegistry(() => {
|
||||
finalizeRan = true;
|
||||
Promise.resolve().then(() => {
|
||||
promiseRan = true;
|
||||
});
|
||||
});
|
||||
|
||||
fg.register({}, {});
|
||||
fr.register({}, {});
|
||||
|
||||
gc();
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
gczeal(4);
|
||||
let heldValues = [];
|
||||
group = new FinalizationGroup(iterator => {
|
||||
registry = new FinalizationRegistry(iterator => {
|
||||
heldValues.push(...iterator);
|
||||
});
|
||||
group.register({}, 42);
|
||||
registry.register({}, 42);
|
||||
gc();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// |jit-test| --enable-weak-refs
|
||||
|
||||
var group = new FinalizationGroup(x => {
|
||||
var registry = new FinalizationRegistry(x => {
|
||||
if (target1 === null) {
|
||||
return;
|
||||
}
|
||||
|
@ -13,10 +13,10 @@ var group = new FinalizationGroup(x => {
|
|||
});
|
||||
|
||||
var target1 = {};
|
||||
group.register(target1, "target1");
|
||||
registry.register(target1, "target1");
|
||||
|
||||
var target2 = {};
|
||||
group.register(target2, "target2");
|
||||
registry.register(target2, "target2");
|
||||
|
||||
target2 = null;
|
||||
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
const token = {};
|
||||
let iterated;
|
||||
const finalizationGroup = new FinalizationGroup(items => {
|
||||
const finalizationRegistry = new FinalizationRegistry(items => {
|
||||
iterated = items.next().value;
|
||||
});
|
||||
{
|
||||
let object = {};
|
||||
finalizationGroup.register(object, token, token);
|
||||
finalizationRegistry.register(object, token, token);
|
||||
object = undefined;
|
||||
}
|
||||
gc();
|
||||
finalizationGroup.cleanupSome();
|
||||
finalizationRegistry.cleanupSome();
|
||||
assertEq(iterated, token);
|
||||
assertEq(finalizationGroup.unregister(token), false);
|
||||
assertEq(finalizationRegistry.unregister(token), false);
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
const token = {};
|
||||
let iterated;
|
||||
const finalizationGroup = new FinalizationGroup(items => {
|
||||
const finalizationRegistry = new FinalizationRegistry(items => {
|
||||
iterated = items.next().value;
|
||||
});
|
||||
{
|
||||
let object = {};
|
||||
finalizationGroup.register(object, token, token);
|
||||
finalizationRegistry.register(object, token, token);
|
||||
object = undefined;
|
||||
}
|
||||
gc();
|
||||
assertEq(finalizationGroup.unregister(token), true);
|
||||
finalizationGroup.cleanupSome();
|
||||
assertEq(finalizationRegistry.unregister(token), true);
|
||||
finalizationRegistry.cleanupSome();
|
||||
assertEq(iterated, undefined);
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
// |jit-test| --enable-weak-refs
|
||||
|
||||
// Test gray finalization group is correctly barrired.
|
||||
target = {};
|
||||
group = new FinalizationGroup(iterator => undefined);
|
||||
group.register(target, 1);
|
||||
grayRoot()[0] = group;
|
||||
group = undefined;
|
||||
gc(); // Group is now marked gray.
|
||||
target = undefined;
|
||||
gc(); // Target dies, group is queued.
|
||||
drainJobQueue();
|
|
@ -1,4 +0,0 @@
|
|||
// |jit-test| --enable-weak-refs; skip-if: !('oomTest' in this)
|
||||
let group = new FinalizationGroup(x => 0);
|
||||
let token = {};
|
||||
oomTest(() => group.register({}, 1, token));
|
|
@ -1,5 +0,0 @@
|
|||
// |jit-test| --enable-weak-refs; skip-if: !('oomTest' in this)
|
||||
let group = new FinalizationGroup(x => 0);
|
||||
group.register({}, 1, {});
|
||||
let token = {};
|
||||
oomTest(() => group.unregister(token));
|
|
@ -1,5 +0,0 @@
|
|||
// |jit-test| --enable-weak-refs; skip-if: !('oomTest' in this)
|
||||
let group = new FinalizationGroup(x => 0);
|
||||
let target = {};
|
||||
let token = {};
|
||||
oomTest(() => group.register(target, 1, token));
|
|
@ -10,17 +10,17 @@ function ccwToObject() {
|
|||
return evalcx('({})', newGlobal({newCompartment: true}));
|
||||
}
|
||||
|
||||
function newGroup() {
|
||||
return new FinalizationGroup(iterator => {
|
||||
function newRegistry() {
|
||||
return new FinalizationRegistry(iterator => {
|
||||
heldValues.push(...iterator);
|
||||
});
|
||||
}
|
||||
|
||||
function ccwToGroup() {
|
||||
function ccwToRegistry() {
|
||||
let global = newGlobal({newCompartment: true});
|
||||
global.heldValues = heldValues;
|
||||
return global.eval(
|
||||
`new FinalizationGroup(iterator => heldValues.push(...iterator))`);
|
||||
`new FinalizationRegistry(iterator => heldValues.push(...iterator))`);
|
||||
}
|
||||
|
||||
function incrementalGC() {
|
||||
|
@ -30,18 +30,18 @@ function incrementalGC() {
|
|||
}
|
||||
}
|
||||
|
||||
// Test the case when the group remains live.
|
||||
// Test the case when the registry remains live.
|
||||
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 group = w ? ccwToGroup(w) : newGroup();
|
||||
let registry = w ? ccwToRegistry(w) : newRegistry();
|
||||
let target = x ? ccwToObject() : {};
|
||||
let heldValue = y ? ccwToObject() : {};
|
||||
let token = z ? ccwToObject() : {};
|
||||
group.register(target, heldValue, token);
|
||||
group.unregister(token);
|
||||
group.register(target, heldValue, token);
|
||||
registry.register(target, heldValue, token);
|
||||
registry.unregister(token);
|
||||
registry.register(target, heldValue, token);
|
||||
target = undefined;
|
||||
token = undefined;
|
||||
heldValue = undefined;
|
||||
|
@ -54,22 +54,22 @@ for (let w of [false, true]) {
|
|||
}
|
||||
}
|
||||
|
||||
// Test the case when group has no more references.
|
||||
// Test the case when registry has no more references.
|
||||
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 group = w ? ccwToGroup(w) : newGroup();
|
||||
let registry = w ? ccwToRegistry(w) : newRegistry();
|
||||
let target = x ? ccwToObject() : {};
|
||||
let heldValue = y ? ccwToObject() : {};
|
||||
let token = z ? ccwToObject() : {};
|
||||
group.register(target, heldValue, token);
|
||||
group.unregister(token);
|
||||
group.register(target, heldValue, token);
|
||||
registry.register(target, heldValue, token);
|
||||
registry.unregister(token);
|
||||
registry.register(target, heldValue, token);
|
||||
target = undefined;
|
||||
token = undefined;
|
||||
heldValue = undefined;
|
||||
group = undefined; // Remove last reference to group.
|
||||
registry = undefined; // Remove last reference to registry.
|
||||
incrementalGC();
|
||||
heldValues.length = 0;
|
||||
drainJobQueue();
|
|
@ -0,0 +1,12 @@
|
|||
// |jit-test| --enable-weak-refs
|
||||
|
||||
// Test gray finalization registry is correctly barrired.
|
||||
target = {};
|
||||
registry = new FinalizationRegistry(iterator => undefined);
|
||||
registry.register(target, 1);
|
||||
grayRoot()[0] = registry;
|
||||
registry = undefined;
|
||||
gc(); // Registry is now marked gray.
|
||||
target = undefined;
|
||||
gc(); // Target dies, registry is queued.
|
||||
drainJobQueue();
|
|
@ -1,8 +1,8 @@
|
|||
// |jit-test| --enable-weak-refs; skip-if: !('oomTest' in this)
|
||||
|
||||
// Don't test prototype initialization etc.
|
||||
new FinalizationGroup(x => 0);
|
||||
new FinalizationRegistry(x => 0);
|
||||
|
||||
oomTest(() => {
|
||||
new FinalizationGroup(x => 0);
|
||||
new FinalizationRegistry(x => 0);
|
||||
});
|
|
@ -0,0 +1,4 @@
|
|||
// |jit-test| --enable-weak-refs; skip-if: !('oomTest' in this)
|
||||
let registry = new FinalizationRegistry(x => 0);
|
||||
let token = {};
|
||||
oomTest(() => registry.register({}, 1, token));
|
|
@ -0,0 +1,5 @@
|
|||
// |jit-test| --enable-weak-refs; skip-if: !('oomTest' in this)
|
||||
let registry = new FinalizationRegistry(x => 0);
|
||||
registry.register({}, 1, {});
|
||||
let token = {};
|
||||
oomTest(() => registry.unregister(token));
|
|
@ -0,0 +1,5 @@
|
|||
// |jit-test| --enable-weak-refs; skip-if: !('oomTest' in this)
|
||||
let registry = new FinalizationRegistry(x => 0);
|
||||
let target = {};
|
||||
let token = {};
|
||||
oomTest(() => registry.register(target, 1, token));
|
|
@ -1,7 +1,7 @@
|
|||
// |jit-test| --enable-weak-refs
|
||||
enableShellAllocationMetadataBuilder();
|
||||
evaluate(`
|
||||
var group = new FinalizationGroup(x => 0);
|
||||
var registry = new FinalizationRegistry(x => 0);
|
||||
gczeal(9,3);
|
||||
group.register({}, 1, {});
|
||||
registry.register({}, 1, {});
|
||||
`);
|
|
@ -19,83 +19,83 @@ function assertThrowsTypeError(thunk) {
|
|||
assertEq(error instanceof TypeError, true);
|
||||
}
|
||||
|
||||
// 3.1 The FinalizationGroup Constructor
|
||||
assertEq(typeof this.FinalizationGroup, "function");
|
||||
// 3.1 The FinalizationRegistry Constructor
|
||||
assertEq(typeof this.FinalizationRegistry, "function");
|
||||
|
||||
// 3.1.1 FinalizationGroup ( cleanupCallback )
|
||||
assertThrowsTypeError(() => new FinalizationGroup());
|
||||
assertThrowsTypeError(() => new FinalizationGroup(1));
|
||||
new FinalizationGroup(x => 0);
|
||||
// 3.1.1 FinalizationRegistry ( cleanupCallback )
|
||||
assertThrowsTypeError(() => new FinalizationRegistry());
|
||||
assertThrowsTypeError(() => new FinalizationRegistry(1));
|
||||
new FinalizationRegistry(x => 0);
|
||||
|
||||
// 3.2 Properties of the FinalizationGroup Constructor
|
||||
assertEq(Object.getPrototypeOf(FinalizationGroup), Function.prototype);
|
||||
// 3.2 Properties of the FinalizationRegistry Constructor
|
||||
assertEq(Object.getPrototypeOf(FinalizationRegistry), Function.prototype);
|
||||
|
||||
// 3.2.1 FinalizationGroup.prototype
|
||||
checkPropertyDescriptor(FinalizationGroup, 'prototype', false, false, false);
|
||||
// 3.2.1 FinalizationRegistry.prototype
|
||||
checkPropertyDescriptor(FinalizationRegistry, 'prototype', false, false, false);
|
||||
|
||||
// 3.3 Properties of the FinalizationGroup Prototype Object
|
||||
let proto = FinalizationGroup.prototype;
|
||||
// 3.3 Properties of the FinalizationRegistry Prototype Object
|
||||
let proto = FinalizationRegistry.prototype;
|
||||
assertEq(Object.getPrototypeOf(proto), Object.prototype);
|
||||
|
||||
// 3.3.1 FinalizationGroup.prototype.constructor
|
||||
assertEq(proto.constructor, FinalizationGroup);
|
||||
// 3.3.1 FinalizationRegistry.prototype.constructor
|
||||
assertEq(proto.constructor, FinalizationRegistry);
|
||||
|
||||
// 3.3.2 FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
// 3.3.2 FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
assertEq(proto.hasOwnProperty('register'), true);
|
||||
assertEq(typeof proto.register, 'function');
|
||||
|
||||
// 3.3.3 FinalizationGroup.prototype.unregister ( unregisterToken )
|
||||
// 3.3.3 FinalizationRegistry.prototype.unregister ( unregisterToken )
|
||||
assertEq(proto.hasOwnProperty('unregister'), true);
|
||||
assertEq(typeof proto.unregister, 'function');
|
||||
|
||||
// 3.3.4 FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
// 3.3.4 FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
assertEq(proto.hasOwnProperty('cleanupSome'), true);
|
||||
assertEq(typeof proto.cleanupSome, 'function');
|
||||
|
||||
// 3.3.5 FinalizationGroup.prototype [ @@toStringTag ]
|
||||
assertEq(proto[Symbol.toStringTag], "FinalizationGroup");
|
||||
// 3.3.5 FinalizationRegistry.prototype [ @@toStringTag ]
|
||||
assertEq(proto[Symbol.toStringTag], "FinalizationRegistry");
|
||||
checkPropertyDescriptor(proto, Symbol.toStringTag, false, false, true);
|
||||
|
||||
// 3.4 Properties of FinalizationGroup Instances
|
||||
let group = new FinalizationGroup(x => 0);
|
||||
assertEq(Object.getPrototypeOf(group), proto);
|
||||
assertEq(Object.getOwnPropertyNames(group).length, 0);
|
||||
// 3.4 Properties of FinalizationRegistry Instances
|
||||
let registry = new FinalizationRegistry(x => 0);
|
||||
assertEq(Object.getPrototypeOf(registry), proto);
|
||||
assertEq(Object.getOwnPropertyNames(registry).length, 0);
|
||||
|
||||
// Get a cleanup iterator.
|
||||
let iterator;
|
||||
group = new FinalizationGroup(it => iterator = it);
|
||||
group.register({}, 0);
|
||||
registry = new FinalizationRegistry(it => iterator = it);
|
||||
registry.register({}, 0);
|
||||
gc();
|
||||
drainJobQueue();
|
||||
assertEq(typeof group, 'object');
|
||||
assertEq(typeof registry, 'object');
|
||||
assertEq(typeof iterator, 'object');
|
||||
|
||||
// 3.5.2 The %FinalizationGroupCleanupIteratorPrototype% Object
|
||||
// 3.5.2 The %FinalizationRegistryCleanupIteratorPrototype% Object
|
||||
let arrayIterator = [][Symbol.iterator]();
|
||||
let iteratorProto = arrayIterator.__proto__.__proto__;
|
||||
proto = iterator.__proto__;
|
||||
assertEq(typeof proto, "object");
|
||||
assertEq(proto.__proto__, iteratorProto);
|
||||
|
||||
// 3.5.2.1 %FinalizationGroupCleanupIteratorPrototype%.next()
|
||||
// 3.5.2.1 %FinalizationRegistryCleanupIteratorPrototype%.next()
|
||||
assertEq(proto.hasOwnProperty("next"), true);
|
||||
assertEq(typeof proto.next, "function");
|
||||
|
||||
// 3.5.2.2 %FinalizationGroupCleanupIteratorPrototype% [ @@toStringTag ]
|
||||
assertEq(proto[Symbol.toStringTag], "FinalizationGroup Cleanup Iterator");
|
||||
// 3.5.2.2 %FinalizationRegistryCleanupIteratorPrototype% [ @@toStringTag ]
|
||||
assertEq(proto[Symbol.toStringTag], "FinalizationRegistry Cleanup Iterator");
|
||||
checkPropertyDescriptor(proto, Symbol.toStringTag, false, false, true);
|
||||
|
||||
// 3.5.3 Properties of FinalizationGroup Cleanup Iterator Instances
|
||||
// 3.5.3 Properties of FinalizationRegistry Cleanup Iterator Instances
|
||||
assertEq(Object.getOwnPropertyNames(iterator).length, 0);
|
||||
|
||||
let heldValues = [];
|
||||
group = new FinalizationGroup(iterator => {
|
||||
registry = new FinalizationRegistry(iterator => {
|
||||
heldValues.push(...iterator);
|
||||
});
|
||||
|
||||
// Test a single target.
|
||||
heldValues = [];
|
||||
group.register({}, 42);
|
||||
registry.register({}, 42);
|
||||
gc();
|
||||
drainJobQueue();
|
||||
assertEq(heldValues.length, 1);
|
||||
|
@ -104,7 +104,7 @@ assertEq(heldValues[0], 42);
|
|||
// Test multiple targets.
|
||||
heldValues = [];
|
||||
for (let i = 0; i < 100; i++) {
|
||||
group.register({}, i);
|
||||
registry.register({}, i);
|
||||
}
|
||||
gc();
|
||||
drainJobQueue();
|
||||
|
@ -114,16 +114,16 @@ for (let i = 0; i < 100; i++) {
|
|||
assertEq(heldValues[i], i);
|
||||
}
|
||||
|
||||
// Test a single object in multiple groups
|
||||
// Test a single object in multiple registries
|
||||
heldValues = [];
|
||||
let heldValues2 = [];
|
||||
let group2 = new FinalizationGroup(iterator => {
|
||||
let registry2 = new FinalizationRegistry(iterator => {
|
||||
heldValues2.push(...iterator);
|
||||
});
|
||||
{
|
||||
let object = {};
|
||||
group.register(object, 1);
|
||||
group2.register(object, 2);
|
||||
registry.register(object, 1);
|
||||
registry2.register(object, 2);
|
||||
object = null;
|
||||
}
|
||||
gc();
|
||||
|
@ -136,8 +136,8 @@ assertEq(heldValues2[0], 2);
|
|||
// Unregister a single target.
|
||||
heldValues = [];
|
||||
let token = {};
|
||||
group.register({}, 1, token);
|
||||
group.unregister(token);
|
||||
registry.register({}, 1, token);
|
||||
registry.unregister(token);
|
||||
gc();
|
||||
drainJobQueue();
|
||||
assertEq(heldValues.length, 0);
|
||||
|
@ -145,11 +145,11 @@ assertEq(heldValues.length, 0);
|
|||
// Unregister multiple targets.
|
||||
heldValues = [];
|
||||
let token2 = {};
|
||||
group.register({}, 1, token);
|
||||
group.register({}, 2, token2);
|
||||
group.register({}, 3, token);
|
||||
group.register({}, 4, token2);
|
||||
group.unregister(token);
|
||||
registry.register({}, 1, token);
|
||||
registry.register({}, 2, token2);
|
||||
registry.register({}, 3, token);
|
||||
registry.register({}, 4, token2);
|
||||
registry.unregister(token);
|
||||
gc();
|
||||
drainJobQueue();
|
||||
assertEq(heldValues.length, 2);
|
||||
|
@ -160,7 +160,7 @@ assertEq(heldValues[1], 4);
|
|||
// Watch object in another global.
|
||||
let other = newGlobal({newCompartment: true});
|
||||
heldValues = [];
|
||||
group.register(evalcx('({})', other), 1);
|
||||
registry.register(evalcx('({})', other), 1);
|
||||
gc();
|
||||
drainJobQueue();
|
||||
assertEq(heldValues.length, 1);
|
||||
|
@ -169,7 +169,7 @@ assertEq(heldValues[0], 1);
|
|||
// Pass heldValues from another global.
|
||||
let heldValue = evalcx('{}', other);
|
||||
heldValues = [];
|
||||
group.register({}, heldValue);
|
||||
registry.register({}, heldValue);
|
||||
gc();
|
||||
drainJobQueue();
|
||||
assertEq(heldValues.length, 1);
|
||||
|
@ -178,29 +178,29 @@ assertEq(heldValues[0], heldValue);
|
|||
// Pass unregister token from another global.
|
||||
token = evalcx('({})', other);
|
||||
heldValues = [];
|
||||
group.register({}, 1, token);
|
||||
registry.register({}, 1, token);
|
||||
gc();
|
||||
drainJobQueue();
|
||||
assertEq(heldValues.length, 1);
|
||||
assertEq(heldValues[0], 1);
|
||||
heldValues = [];
|
||||
group.register({}, 1, token);
|
||||
group.unregister(token);
|
||||
registry.register({}, 1, token);
|
||||
registry.unregister(token);
|
||||
gc();
|
||||
drainJobQueue();
|
||||
assertEq(heldValues.length, 0);
|
||||
|
||||
// FinalizationGroup is designed to be subclassable.
|
||||
class MyGroup extends FinalizationGroup {
|
||||
// FinalizationRegistry is designed to be subclassable.
|
||||
class MyRegistry extends FinalizationRegistry {
|
||||
constructor(callback) {
|
||||
super(callback);
|
||||
}
|
||||
}
|
||||
let g2 = new MyGroup(iterator => {
|
||||
let r2 = new MyRegistry(iterator => {
|
||||
heldValues.push(...iterator);
|
||||
});
|
||||
heldValues = [];
|
||||
g2.register({}, 42);
|
||||
r2.register({}, 42);
|
||||
gc();
|
||||
drainJobQueue();
|
||||
assertEq(heldValues.length, 1);
|
||||
|
@ -208,29 +208,29 @@ assertEq(heldValues[0], 42);
|
|||
|
||||
// Test trying to use iterator after the callback.
|
||||
iterator = undefined;
|
||||
let g3 = new FinalizationGroup(i => iterator = i);
|
||||
g3.register({}, 1);
|
||||
let r3 = new FinalizationRegistry(i => iterator = i);
|
||||
r3.register({}, 1);
|
||||
gc();
|
||||
drainJobQueue();
|
||||
assertEq(typeof iterator, 'object');
|
||||
assertThrowsTypeError(() => iterator.next());
|
||||
|
||||
// Test trying to use the wrong iterator inside the callback.
|
||||
let g4 = new FinalizationGroup(x => {
|
||||
let r4 = new FinalizationRegistry(x => {
|
||||
assertThrowsTypeError(() => iterator.next());
|
||||
});
|
||||
g4.register({}, 1);
|
||||
r4.register({}, 1);
|
||||
gc();
|
||||
drainJobQueue();
|
||||
|
||||
// Test cleanupSome.
|
||||
heldValues = [];
|
||||
let g5 = new FinalizationGroup(i => heldValues = [...i]);
|
||||
g5.register({}, 1);
|
||||
g5.register({}, 2);
|
||||
g5.register({}, 3);
|
||||
let r5 = new FinalizationRegistry(i => heldValues = [...i]);
|
||||
r5.register({}, 1);
|
||||
r5.register({}, 2);
|
||||
r5.register({}, 3);
|
||||
gc();
|
||||
g5.cleanupSome();
|
||||
r5.cleanupSome();
|
||||
assertEq(heldValues.length, 3);
|
||||
heldValues = heldValues.sort((a, b) => a - b);
|
||||
assertEq(heldValues[0], 1);
|
||||
|
@ -238,40 +238,40 @@ assertEq(heldValues[1], 2);
|
|||
assertEq(heldValues[2], 3);
|
||||
|
||||
// Test trying to call cleanupSome in callback.
|
||||
let g6 = new FinalizationGroup(x => {
|
||||
assertThrowsTypeError(() => g6.cleanupSome());
|
||||
let r6 = new FinalizationRegistry(x => {
|
||||
assertThrowsTypeError(() => r6.cleanupSome());
|
||||
});
|
||||
g6.register({}, 1);
|
||||
r6.register({}, 1);
|
||||
gc();
|
||||
drainJobQueue();
|
||||
|
||||
// Test that targets don't keep the finalization group alive.
|
||||
// Test that targets don't keep the finalization registry alive.
|
||||
let target = {};
|
||||
group = new FinalizationGroup(iterator => undefined);
|
||||
group.register(target, 1);
|
||||
let weakRef = new WeakRef(group);
|
||||
group = undefined;
|
||||
registry = new FinalizationRegistry(iterator => undefined);
|
||||
registry.register(target, 1);
|
||||
let weakRef = new WeakRef(registry);
|
||||
registry = undefined;
|
||||
assertEq(typeof weakRef.deref(), 'object');
|
||||
drainJobQueue();
|
||||
gc();
|
||||
assertEq(weakRef.deref(), undefined);
|
||||
assertEq(typeof target, 'object');
|
||||
|
||||
// Test that targets don't keep the finalization group alive when also
|
||||
// Test that targets don't keep the finalization registry alive when also
|
||||
// used as the unregister token.
|
||||
group = new FinalizationGroup(iterator => undefined);
|
||||
group.register(target, 1, target);
|
||||
weakRef = new WeakRef(group);
|
||||
group = undefined;
|
||||
registry = new FinalizationRegistry(iterator => undefined);
|
||||
registry.register(target, 1, target);
|
||||
weakRef = new WeakRef(registry);
|
||||
registry = undefined;
|
||||
assertEq(typeof weakRef.deref(), 'object');
|
||||
drainJobQueue();
|
||||
gc();
|
||||
assertEq(weakRef.deref(), undefined);
|
||||
assertEq(typeof target, 'object');
|
||||
|
||||
// Test that cleanup doesn't happen if the finalization group dies.
|
||||
// Test that cleanup doesn't happen if the finalization registry dies.
|
||||
heldValues = [];
|
||||
new FinalizationGroup(iterator => {
|
||||
new FinalizationRegistry(iterator => {
|
||||
heldValues.push(...iterator);
|
||||
}).register({}, 1);
|
||||
gc();
|
|
@ -1,3 +1,3 @@
|
|||
// Weak references are disabled by default.
|
||||
assertEq('WeakRef' in this, false);
|
||||
assertEq('FinalizationGroup' in this, false);
|
||||
assertEq('FinalizationRegistry' in this, false);
|
||||
|
|
|
@ -18,29 +18,29 @@ onmessage = (event) => {
|
|||
};
|
||||
|
||||
function startTest() {
|
||||
// Group with no registered objects.
|
||||
let group1 = new FinalizationGroup(i => holdings1 = [...i]);
|
||||
// Registry with no registered objects.
|
||||
let registry1 = new FinalizationRegistry(i => holdings1 = [...i]);
|
||||
|
||||
// Group with three registered objects.
|
||||
let group2 = new FinalizationGroup(i => holdings2 = [...i]);
|
||||
group2.register({}, 1);
|
||||
group2.register({}, 2);
|
||||
group2.register({}, 3);
|
||||
// Registry with three registered objects.
|
||||
let registry2 = new FinalizationRegistry(i => holdings2 = [...i]);
|
||||
registry2.register({}, 1);
|
||||
registry2.register({}, 2);
|
||||
registry2.register({}, 3);
|
||||
|
||||
// Group with registered object that is then unregistered.
|
||||
let group3 = new FinalizationGroup(i => holdings3 = [...i]);
|
||||
// Registry with registered object that is then unregistered.
|
||||
let registry3 = new FinalizationRegistry(i => holdings3 = [...i]);
|
||||
let token3 = {}
|
||||
group3.register({}, 1, token3);
|
||||
group3.unregister(token3);
|
||||
registry3.register({}, 1, token3);
|
||||
registry3.unregister(token3);
|
||||
|
||||
// Group with registered object that doesn't die.
|
||||
let group4 = new FinalizationGroup(i => holdings4 = [...i]);
|
||||
// Registry with registered object that doesn't die.
|
||||
let registry4 = new FinalizationRegistry(i => holdings4 = [...i]);
|
||||
let object4 = {};
|
||||
group4.register(object4, 1);
|
||||
registry4.register(object4, 1);
|
||||
|
||||
// Group observing cyclic JS data structure.
|
||||
let group5 = new FinalizationGroup(i => holdings5 = [...i]);
|
||||
group5.register(makeJSCycle(4), 5);
|
||||
// Registry observing cyclic JS data structure.
|
||||
let registry5 = new FinalizationRegistry(i => holdings5 = [...i]);
|
||||
registry5.register(makeJSCycle(4), 5);
|
||||
|
||||
const { gc } = getJSTestingFunctions();
|
||||
gc();
|
|
@ -36,7 +36,7 @@ support-files =
|
|||
inner.html
|
||||
test1_bug629331.html
|
||||
test2_bug629331.html
|
||||
finalizationGroup_worker.js
|
||||
finalizationRegistry_worker.js
|
||||
prefs =
|
||||
javascript.options.experimental.weakrefs=true
|
||||
|
||||
|
@ -113,9 +113,9 @@ skip-if = (debug == false)
|
|||
support-files =
|
||||
../../../../dom/tests/mochitest/fetch/test_fetch_basic.js
|
||||
[test_weakmaps.html]
|
||||
[test_finalizationGroup.html]
|
||||
[test_finalizationRegistry.html]
|
||||
skip-if = !nightly_build
|
||||
[test_finalizationGroupInWorker.html]
|
||||
[test_finalizationRegistryInWorker.html]
|
||||
skip-if = !nightly_build
|
||||
[test_weakRefs.html]
|
||||
skip-if = !nightly_build
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test FinalizationGroup works in the browser</title>
|
||||
<title>Test FinalizationRegistry works in the browser</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript">
|
||||
let object4 = {};
|
||||
|
@ -10,38 +10,38 @@
|
|||
function go() {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
// Group with no registered objects.
|
||||
// Registry with no registered objects.
|
||||
let holdings1 = [];
|
||||
let group1 = new FinalizationGroup(i => holdings1 = [...i]);
|
||||
let registry1 = new FinalizationRegistry(i => holdings1 = [...i]);
|
||||
|
||||
// Group with three registered objects.
|
||||
// Registry with three registered objects.
|
||||
let holdings2 = [];
|
||||
let group2 = new FinalizationGroup(i => holdings2 = [...i]);
|
||||
group2.register({}, 1);
|
||||
group2.register({}, 2);
|
||||
group2.register({}, 3);
|
||||
let registry2 = new FinalizationRegistry(i => holdings2 = [...i]);
|
||||
registry2.register({}, 1);
|
||||
registry2.register({}, 2);
|
||||
registry2.register({}, 3);
|
||||
|
||||
// Group with registered object that is then unregistered.
|
||||
// Registry with registered object that is then unregistered.
|
||||
let holdings3 = [];
|
||||
let group3 = new FinalizationGroup(i => holdings3 = [...i]);
|
||||
let registry3 = new FinalizationRegistry(i => holdings3 = [...i]);
|
||||
let token3 = {}
|
||||
group3.register({}, 1, token3);
|
||||
group3.unregister(token3);
|
||||
registry3.register({}, 1, token3);
|
||||
registry3.unregister(token3);
|
||||
|
||||
// Group with registered object that doesn't die.
|
||||
// Registry with registered object that doesn't die.
|
||||
let holdings4 = [];
|
||||
let group4 = new FinalizationGroup(i => holdings4 = [...i]);
|
||||
group4.register(object4, 1);
|
||||
let registry4 = new FinalizationRegistry(i => holdings4 = [...i]);
|
||||
registry4.register(object4, 1);
|
||||
|
||||
// Group observing cyclic JS data structure.
|
||||
// Registry observing cyclic JS data structure.
|
||||
let holdings5 = [];
|
||||
let group5 = new FinalizationGroup(i => holdings5 = [...i]);
|
||||
group5.register(makeJSCycle(4), 5);
|
||||
let registry5 = new FinalizationRegistry(i => holdings5 = [...i]);
|
||||
registry5.register(makeJSCycle(4), 5);
|
||||
|
||||
// Group observing cyclic DOM/JS data structure.
|
||||
// Registry observing cyclic DOM/JS data structure.
|
||||
let holdings6 = [];
|
||||
let group6 = new FinalizationGroup(i => holdings6 = [...i]);
|
||||
group6.register(makeDOMCycle(4), 6);
|
||||
let registry6 = new FinalizationRegistry(i => holdings6 = [...i]);
|
||||
registry6.register(makeDOMCycle(4), 6);
|
||||
|
||||
// Need to run full GC/CC/GC cycle to collect cyclic garbage through DOM
|
||||
// and JS heaps.
|
|
@ -2,13 +2,13 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test FinalizationGroup works in workers</title>
|
||||
<title>Test FinalizationRegistry works in workers</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript">
|
||||
function go() {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
let worker = new Worker('finalizationGroup_worker.js');
|
||||
let worker = new Worker('finalizationRegistry_worker.js');
|
||||
|
||||
worker.onevent = (event) => {
|
||||
console.log(event.message);
|
Загрузка…
Ссылка в новой задаче