mirror of https://github.com/tc39/test262.git
Rename FinalizationGroup to FinalizationRegistry
Corresponds to https://github.com/tc39/proposal-weakrefs/pull/183 (Note, this is untested)
This commit is contained in:
parent
723205bd54
commit
c6dd620ad3
|
@ -131,7 +131,7 @@ import.meta
|
|||
# WeakRef
|
||||
# https://github.com/tc39/proposal-weakref
|
||||
WeakRef
|
||||
FinalizationGroup
|
||||
FinalizationRegistry
|
||||
|
||||
# Optional Chaining
|
||||
# https://github.com/tc39/proposal-optional-chaining
|
||||
|
|
|
@ -5,16 +5,16 @@ description: >
|
|||
Collection of functions used to capture references cleanup from garbage collectors
|
||||
features: [Symbol, async-functions]
|
||||
flags: [non-deterministic]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
defines: [asyncGC, asyncGCDeref, resolveAsyncGC]
|
||||
---*/
|
||||
|
||||
function asyncGC(...targets) {
|
||||
var fg = new FinalizationGroup(() => {});
|
||||
var finalizationRegistry = new FinalizationRegistry(() => {});
|
||||
var length = targets.length;
|
||||
|
||||
for (let target of targets) {
|
||||
fg.register(target, 'target');
|
||||
finalizationRegistry.register(target, 'target');
|
||||
target = null;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ function asyncGC(...targets) {
|
|||
var names;
|
||||
|
||||
// consume iterator to capture names
|
||||
fg.cleanupSome(iter => { names = [...iter]; });
|
||||
finalizationRegistry.cleanupSome(iter => { names = [...iter]; });
|
||||
|
||||
if (!names || names.length != length) {
|
||||
throw asyncGC.notCollected;
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
description: >
|
||||
FinalizationGroupCleanupIteratorPrototype @@toStringTag
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup).
|
||||
...
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
%FinalizationGroupCleanupIteratorPrototype% [ @@toStringTag ]
|
||||
|
||||
The initial value of the @@toStringTag property is the String value "FinalizationGroup Cleanup Iterator".
|
||||
|
||||
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
||||
features: [FinalizationGroup, host-gc-required, Symbol, Symbol.toStringTag]
|
||||
includes: [async-gc.js, propertyHelper.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var FinalizationGroupCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
FinalizationGroupCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
fg.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
|
||||
verifyProperty(FinalizationGroupCleanupIteratorPrototype, Symbol.toStringTag, {
|
||||
value: 'FinalizationGroup Cleanup Iterator',
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -1,69 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
description: >
|
||||
Throws a TypeError if [[IsFinalizationGroupCleanupJobActive]] is false
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup).
|
||||
...
|
||||
5. Set finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] to true.
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
7. Set finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] to false.
|
||||
...
|
||||
|
||||
%FinalizationGroupCleanupIteratorPrototype%.next ( )
|
||||
|
||||
1. Let iterator be the this value.
|
||||
2. If Type(iterator) is not Object, throw a TypeError exception.
|
||||
3. If iterator does not have a [[FinalizationGroup]] internal slot, throw a TypeError exception.
|
||||
features: [FinalizationGroup, WeakRef, host-gc-required, Symbol]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var iter;
|
||||
var FinalizationGroupCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
iter = iterator;
|
||||
FinalizationGroupCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target, 'target');
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
fg.cleanupSome(callback);
|
||||
|
||||
// Make sure everything is set
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
assert.sameValue(typeof iter, 'object');
|
||||
assert.sameValue(Object.getPrototypeOf(iter), FinalizationGroupCleanupIteratorPrototype);
|
||||
|
||||
// To the actual assertion
|
||||
assert.throws(TypeError, function() {
|
||||
iter.next();
|
||||
}, 'Iter should fail if not called during the cleanupSome call');
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -1,90 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
description: >
|
||||
If iterator does not have a [[FinalizationGroup]] internal slot, throw a TypeError exception.
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup).
|
||||
...
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
%FinalizationGroupCleanupIteratorPrototype%.next ( )
|
||||
|
||||
1. Let iterator be the this value.
|
||||
2. If Type(iterator) is not Object, throw a TypeError exception.
|
||||
3. If iterator does not have a [[FinalizationGroup]] internal slot, throw a TypeError exception.
|
||||
features: [FinalizationGroup, WeakRef, host-gc-required, Symbol]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var FinalizationGroupCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var endOfCall = 0;
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
// Only the iterator itself will have a [[FinalizationGroup]] internal
|
||||
FinalizationGroupCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
|
||||
// It's sensitive the assertions remain inside this function in order to secure
|
||||
// [[IsFinalizationGroupCleanupJobActive]] is true
|
||||
assert.sameValue(typeof FinalizationGroupCleanupIteratorPrototype.next, 'function');
|
||||
|
||||
var next = FinalizationGroupCleanupIteratorPrototype.next;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
next.call({});
|
||||
}, '{}');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
next.call(FinalizationGroup);
|
||||
}, 'FinalizationGroup');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
next.call(FinalizationGroupCleanupIteratorPrototype);
|
||||
}, 'FinalizationGroupCleanupIteratorPrototype');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
next.call(fg);
|
||||
}, 'FinalizationGroup instance');
|
||||
|
||||
var wr = new WeakRef({});
|
||||
assert.throws(TypeError, function() {
|
||||
next.call(wr);
|
||||
}, 'WeakRef instance');
|
||||
|
||||
// Abrupt completions are not directly returned.
|
||||
endOfCall += 1;
|
||||
}
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
fg.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
assert.sameValue(endOfCall, 1, 'Abrupt completions are not directly returned.');
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -1,67 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
description: >
|
||||
Prop descriptor for FinalizationGroupCleanupIteratorPrototype.next
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup).
|
||||
...
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
|
||||
Every other data property described in clauses 18 through 26 and in Annex B.2
|
||||
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js, async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
features: [FinalizationGroup, host-gc-required, Symbol]
|
||||
---*/
|
||||
|
||||
var FinalizationGroupCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
FinalizationGroupCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
fg.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
|
||||
assert.sameValue(typeof FinalizationGroupCleanupIteratorPrototype.next, 'function');
|
||||
|
||||
var next = FinalizationGroupCleanupIteratorPrototype.next;
|
||||
|
||||
verifyProperty(FinalizationGroupCleanupIteratorPrototype, 'next', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -1,91 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
description: >
|
||||
FinalizationGroupCleanupIterator has a [[Prototype]] internal slot whose value is the intrinsic
|
||||
object %IteratorPrototype%.
|
||||
info: |
|
||||
The %FinalizationGroupCleanupIteratorPrototype% Object
|
||||
|
||||
- has properties that are inherited by all FinalizationGroup Cleanup Iterator Objects.
|
||||
- is an ordinary object.
|
||||
- has a [[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%.
|
||||
...
|
||||
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
6. Return undefined.
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
|
||||
...
|
||||
2. If CheckForEmptyCells(finalizationGroup) is false, return.
|
||||
3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup).
|
||||
4. If callback is undefined, set callback to finalizationGroup.[[CleanupCallback]].
|
||||
5. Set finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] to true.
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
CheckForEmptyCells ( finalizationGroup )
|
||||
|
||||
...
|
||||
2. For each cell in finalizationGroup.[[Cells]], do
|
||||
a. If cell.[[Target]] is empty, then
|
||||
i. Return true.
|
||||
3. Return false.
|
||||
|
||||
CreateFinalizationGroupCleanupIterator ( finalizationGroup )
|
||||
|
||||
...
|
||||
4. Let prototype be finalizationGroup.[[Realm]].[[Intrinsics]].[[%FinalizationGroupCleanupIteratorPrototype%]].
|
||||
5. Let iterator be ObjectCreate(prototype, « [[FinalizationGroup]] »).
|
||||
6. Set iterator.[[FinalizationGroup]] to finalizationGroup.
|
||||
7. Return iterator.
|
||||
features: [FinalizationGroup, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
|
||||
var FinalizationGroupCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var cleanupCallbackCalled = 0;
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
|
||||
FinalizationGroupCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
fg.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
|
||||
var proto = Object.getPrototypeOf(FinalizationGroupCleanupIteratorPrototype);
|
||||
assert.sameValue(
|
||||
proto, IteratorPrototype,
|
||||
'[[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%'
|
||||
);
|
||||
|
||||
assert.sameValue(cleanupCallbackCalled, 0, 'if a callback is given, do not call cleanupCallback');
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -1,15 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-constructor
|
||||
description: >
|
||||
The FinalizationGroup constructor is the %FinalizationGroup% intrinsic object and the initial
|
||||
value of the FinalizationGroup property of the global object.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof FinalizationGroup, 'function',
|
||||
'typeof FinalizationGroup is function'
|
||||
);
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
description: Instances of FinalizationGroup are extensible
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationGroup.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
ObjectCreate ( proto [ , internalSlotsList ] )
|
||||
|
||||
4. Set obj.[[Prototype]] to proto.
|
||||
5. Set obj.[[Extensible]] to true.
|
||||
6. Return obj.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
assert.sameValue(Object.isExtensible(fg), true);
|
|
@ -1,58 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
description: >
|
||||
[[Prototype]] defaults to %FinalizationGroupPrototype% if NewTarget.prototype is not an object.
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationGroup.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
|
||||
3. Let proto be ? Get(constructor, 'prototype').
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
|
||||
5. Return proto.
|
||||
features: [FinalizationGroup, Reflect.construct, Symbol]
|
||||
---*/
|
||||
|
||||
var fg;
|
||||
function newTarget() {}
|
||||
function fn() {}
|
||||
|
||||
newTarget.prototype = undefined;
|
||||
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is undefined');
|
||||
|
||||
newTarget.prototype = null;
|
||||
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is null');
|
||||
|
||||
newTarget.prototype = true;
|
||||
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is a Boolean');
|
||||
|
||||
newTarget.prototype = '';
|
||||
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is a String');
|
||||
|
||||
newTarget.prototype = Symbol();
|
||||
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is a Symbol');
|
||||
|
||||
newTarget.prototype = 1;
|
||||
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype, 'newTarget.prototype is a Number');
|
|
@ -1,59 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
description: Default [[Prototype]] value derived from realm of the newTarget
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationGroup.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
|
||||
3. Let proto be ? Get(constructor, 'prototype').
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
|
||||
5. Return proto.
|
||||
features: [FinalizationGroup, cross-realm, Reflect, Symbol]
|
||||
---*/
|
||||
|
||||
var other = $262.createRealm().global;
|
||||
var newTarget = new other.Function();
|
||||
function fn() {}
|
||||
var fg;
|
||||
|
||||
newTarget.prototype = undefined;
|
||||
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is undefined');
|
||||
|
||||
newTarget.prototype = null;
|
||||
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is null');
|
||||
|
||||
newTarget.prototype = true;
|
||||
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is a Boolean');
|
||||
|
||||
newTarget.prototype = '';
|
||||
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is a String');
|
||||
|
||||
newTarget.prototype = Symbol();
|
||||
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is a Symbol');
|
||||
|
||||
newTarget.prototype = 1;
|
||||
fg = Reflect.construct(FinalizationGroup, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), other.FinalizationGroup.prototype, 'newTarget.prototype is a Number');
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
description: >
|
||||
The prototype of FinalizationGroup is Object.prototype
|
||||
info: |
|
||||
The value of the [[Prototype]] internal slot of the FinalizationGroup object is the
|
||||
intrinsic object %FunctionPrototype%.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(FinalizationGroup),
|
||||
Function.prototype,
|
||||
'Object.getPrototypeOf(FinalizationGroup) returns the value of `Function.prototype`'
|
||||
);
|
|
@ -1,98 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
description: >
|
||||
The callback function is called with a FinalizationGroupCleanupIterator
|
||||
info: |
|
||||
The %FinalizationGroupCleanupIteratorPrototype% Object
|
||||
|
||||
- has properties that are inherited by all FinalizationGroup Cleanup Iterator Objects.
|
||||
- is an ordinary object.
|
||||
- has a [[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%.
|
||||
...
|
||||
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
6. Return undefined.
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
|
||||
...
|
||||
2. If CheckForEmptyCells(finalizationGroup) is false, return.
|
||||
3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup).
|
||||
4. If callback is undefined, set callback to finalizationGroup.[[CleanupCallback]].
|
||||
5. Set finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] to true.
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
CheckForEmptyCells ( finalizationGroup )
|
||||
|
||||
...
|
||||
2. For each cell in finalizationGroup.[[Cells]], do
|
||||
a. If cell.[[Target]] is empty, then
|
||||
i. Return true.
|
||||
3. Return false.
|
||||
|
||||
CreateFinalizationGroupCleanupIterator ( finalizationGroup )
|
||||
|
||||
...
|
||||
4. Let prototype be finalizationGroup.[[Realm]].[[Intrinsics]].[[%FinalizationGroupCleanupIteratorPrototype%]].
|
||||
5. Let iterator be ObjectCreate(prototype, « [[FinalizationGroup]] »).
|
||||
6. Set iterator.[[FinalizationGroup]] to finalizationGroup.
|
||||
7. Return iterator.
|
||||
features: [FinalizationGroup, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
|
||||
var FinalizationGroupCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var cleanupCallbackCalled = 0;
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
|
||||
FinalizationGroupCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
var fg = new FinalizationGroup(function() {
|
||||
cleanupCallbackCalled += 1;
|
||||
});
|
||||
|
||||
async function register() {
|
||||
var target = {};
|
||||
fg.register(target);
|
||||
var prom = asyncGC(target);
|
||||
|
||||
target = null;
|
||||
assert.sameValue(called, 0); // never called in sync execution
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
register()
|
||||
.then(function() {
|
||||
// We can't observe if the cleanupCallback was called, but we can make sure cleanupSome won't call it.
|
||||
cleanupCallbackCalled = 0;
|
||||
|
||||
fg.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1);
|
||||
|
||||
var proto = Object.getPrototypeOf(FinalizationGroupCleanupIteratorPrototype);
|
||||
assert.sameValue(
|
||||
proto, IteratorPrototype,
|
||||
'[[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%'
|
||||
);
|
||||
|
||||
assert.sameValue(cleanupCallbackCalled, 0, 'if a callback is given, do not call cleanupCallback');
|
||||
})
|
||||
.then($DONE, resolveAsyncGC);
|
|
@ -1,53 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.cleanupSome
|
||||
description: Throws a TypeError if callback is not callable
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
...
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.cleanupSome, 'function');
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.cleanupSome(null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.cleanupSome(true);
|
||||
}, 'true');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.cleanupSome(false);
|
||||
}, 'false');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.cleanupSome(1);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.cleanupSome('object');
|
||||
}, 'string');
|
||||
|
||||
var s = Symbol();
|
||||
assert.throws(TypeError, function() {
|
||||
fg.cleanupSome(s);
|
||||
}, 'symbol');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.cleanupSome({});
|
||||
}, 'object');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.cleanupSome(FinalizationGroup.prototype);
|
||||
}, 'FinalizationGroup.prototype');
|
|
@ -1,86 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
description: >
|
||||
The cleanup callback function is called with a FinalizationGroupCleanupIterator
|
||||
info: |
|
||||
The %FinalizationGroupCleanupIteratorPrototype% Object
|
||||
|
||||
- has properties that are inherited by all FinalizationGroup Cleanup Iterator Objects.
|
||||
- is an ordinary object.
|
||||
- has a [[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%.
|
||||
...
|
||||
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
6. Return undefined.
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
|
||||
...
|
||||
2. If CheckForEmptyCells(finalizationGroup) is false, return.
|
||||
3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup).
|
||||
4. If callback is undefined, set callback to finalizationGroup.[[CleanupCallback]].
|
||||
5. Set finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] to true.
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
CheckForEmptyCells ( finalizationGroup )
|
||||
|
||||
...
|
||||
2. For each cell in finalizationGroup.[[Cells]], do
|
||||
a. If cell.[[Target]] is empty, then
|
||||
i. Return true.
|
||||
3. Return false.
|
||||
|
||||
CreateFinalizationGroupCleanupIterator ( finalizationGroup )
|
||||
|
||||
...
|
||||
4. Let prototype be finalizationGroup.[[Realm]].[[Intrinsics]].[[%FinalizationGroupCleanupIteratorPrototype%]].
|
||||
5. Let iterator be ObjectCreate(prototype, « [[FinalizationGroup]] »).
|
||||
6. Set iterator.[[FinalizationGroup]] to finalizationGroup.
|
||||
7. Return iterator.
|
||||
features: [FinalizationGroup, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
|
||||
var FinalizationGroupCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
|
||||
FinalizationGroupCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
fg.cleanupSome(callback);
|
||||
assert.sameValue(called, 1);
|
||||
|
||||
var proto = Object.getPrototypeOf(FinalizationGroupCleanupIteratorPrototype);
|
||||
assert.sameValue(
|
||||
proto, IteratorPrototype,
|
||||
'[[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%'
|
||||
);
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.cleanupSome
|
||||
description: Return values applying custom this
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
6. Return undefined.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var cleanupSome = FinalizationGroup.prototype.cleanupSome;
|
||||
var fg = new FinalizationGroup(fn);
|
||||
|
||||
var cb = function() {};
|
||||
|
||||
assert.sameValue(cleanupSome.call(fg, cb), undefined);
|
||||
assert.sameValue(cleanupSome.call(fg, fn), undefined), 'reuse the same cleanup callback fn';
|
|
@ -1,62 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.cleanupSome
|
||||
description: Return abrupt completion from CleanupFinalizationGroup
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ? CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
6. Return undefined.
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
|
||||
4. If callback is undefined, set callback to finalizationGroup.[[CleanupCallback]].
|
||||
5. Set finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] to true.
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
7. Set finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] to false.
|
||||
8. If result is an abrupt completion, return result.
|
||||
features: [FinalizationGroup, arrow-function, async-functions, async-iteration, class, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var called = 0;
|
||||
var iterator = false;
|
||||
|
||||
function poisoned(iter) {
|
||||
called += 1;
|
||||
iterator = iter;
|
||||
iter.next(); // Won't throw
|
||||
throw new Test262Error();
|
||||
}
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
assert.throws(Test262Error, function() {
|
||||
fg.cleanupSome(poisoned);
|
||||
});
|
||||
|
||||
assert.sameValue(called, 1);
|
||||
|
||||
assert.sameValue(typeof iterator, 'object');
|
||||
assert.sameValue(typeof iterator.next, 'function');
|
||||
assert.throws(TypeError, function() {
|
||||
iterator.next();
|
||||
}, 'iterator.next throws a TypeError if IsFinalizationGroupCleanupJobActive is false');
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -1,84 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.cleanupSome
|
||||
description: Return undefined regardless the result of CleanupFinalizationGroup
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ? CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
6. Return undefined.
|
||||
features: [FinalizationGroup, arrow-function, async-functions, async-iteration, class, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var called;
|
||||
var fn = function() {
|
||||
called += 1;
|
||||
return 39;
|
||||
};
|
||||
var cb = function() {
|
||||
called += 1;
|
||||
return 42;
|
||||
};
|
||||
var fg = new FinalizationGroup(fn);
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
var tests = [];
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
called = 0;
|
||||
assert.sameValue(fg.cleanupSome(cb), undefined, 'regular callback');
|
||||
assert.sameValue(called, 1);
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
called = 0;
|
||||
assert.sameValue(fg.cleanupSome(fn), undefined, 'regular callback, same FG cleanup function');
|
||||
assert.sameValue(called, 1);
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
called = 0;
|
||||
assert.sameValue(fg.cleanupSome(), undefined, 'undefined (implicit) callback, defer to FB callback');
|
||||
assert.sameValue(called, 1);
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
called = 0;
|
||||
assert.sameValue(fg.cleanupSome(undefined), undefined, 'undefined (explicit) callback, defer to FB callback');
|
||||
assert.sameValue(called, 1);
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
assert.sameValue(fg.cleanupSome(() => 1), undefined, 'arrow function');
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
assert.sameValue(fg.cleanupSome(async function() {}), undefined, 'async function');
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
assert.sameValue(fg.cleanupSome(function *() {}), undefined, 'generator');
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
assert.sameValue(fg.cleanupSome(async function *() {}), undefined, 'async generator');
|
||||
}));
|
||||
|
||||
Promise.all(tests).then(() => { $DONE(); }, resolveAsyncGC);
|
|
@ -1,41 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.cleanupSome
|
||||
description: Return undefined regardless the result of CleanupFinalizationGroup
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ? CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
6. Return undefined.
|
||||
features: [FinalizationGroup, arrow-function, async-functions, async-iteration, class]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var cb = function() {};
|
||||
var poisoned = function() { throw new Test262Error(); };
|
||||
var fg = new FinalizationGroup(fn);
|
||||
|
||||
assert.sameValue(fg.cleanupSome(cb), undefined, 'regular callback');
|
||||
assert.sameValue(fg.cleanupSome(fn), undefined, 'regular callback, same FG cleanup function');
|
||||
|
||||
assert.sameValue(fg.cleanupSome(() => {}), undefined, 'arrow function');
|
||||
assert.sameValue(fg.cleanupSome(fg.cleanupSome), undefined, 'cleanupSome itself');
|
||||
assert.sameValue(fg.cleanupSome(poisoned), undefined, 'poisoned');
|
||||
assert.sameValue(fg.cleanupSome(class {}), undefined, 'class expression');
|
||||
assert.sameValue(fg.cleanupSome(async function() {}), undefined, 'async function');
|
||||
assert.sameValue(fg.cleanupSome(function *() {}), undefined, 'generator');
|
||||
assert.sameValue(fg.cleanupSome(async function *() {}), undefined, 'async generator');
|
||||
|
||||
assert.sameValue(fg.cleanupSome(), undefined, 'undefined, implicit');
|
||||
assert.sameValue(fg.cleanupSome(undefined), undefined, 'undefined, explicit');
|
||||
|
||||
var poisonedFg = new FinalizationGroup(poisoned);
|
||||
|
||||
assert.sameValue(poisonedFg.cleanupSome(cb), undefined, 'regular callback on poisoned FG cleanup callback');
|
||||
assert.sameValue(poisonedFg.cleanupSome(poisoned), undefined, 'poisoned callback on poisoned FG cleanup callback');
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.constructor
|
||||
description: FinalizationGroup.prototype.constructor property descriptor
|
||||
info: |
|
||||
FinalizationGroup.prototype.constructor
|
||||
|
||||
The initial value of FinalizationGroup.prototype.constructor is the intrinsic
|
||||
object %FinalizationGroup%.
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype, 'constructor', {
|
||||
value: FinalizationGroup,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
description: Return undefined (applying custom this)
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
7. Append cell to finalizationGroup.[[Cells]].
|
||||
8. Return undefined.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var register = FinalizationGroup.prototype.register;
|
||||
var fg = new FinalizationGroup(fn);
|
||||
|
||||
var target = {};
|
||||
assert.sameValue(register.call(fg, target), undefined);
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
description: No restriction for the value or type of holdings
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
7. Append cell to finalizationGroup.[[Cells]].
|
||||
8. Return undefined.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var fg = new FinalizationGroup(fn);
|
||||
|
||||
var target = {};
|
||||
assert.sameValue(fg.register(target, undefined), undefined, 'undefined');
|
||||
assert.sameValue(fg.register(target, null), undefined, 'null');
|
||||
assert.sameValue(fg.register(target, false), undefined, 'false');
|
||||
assert.sameValue(fg.register(target, true), undefined, 'true');
|
||||
assert.sameValue(fg.register(target, Symbol()), undefined, 'symbol');
|
||||
assert.sameValue(fg.register(target, {}), undefined, 'object');
|
||||
assert.sameValue(fg.register(target, fg), undefined, 'same as fg instance');
|
||||
assert.sameValue(fg.register(target, 1), undefined, 'number');
|
||||
assert.sameValue(fg.register(target, 'holdings'), undefined, 'string');
|
|
@ -1,21 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
description: holdings may be the same as target
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(target) is not Object, throw a TypeError exception.
|
||||
5. If SameValue(target, holdings), throw a TypeError exception.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
var target = {};
|
||||
assert.throws(TypeError, () => fg.register(target, target));
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
description: Return undefined after registering itself
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(target) is not Object, throw a TypeError exception.
|
||||
5. If SameValue(target, holdings), throw a TypeError exception.
|
||||
6. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
7. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
8. Append cell to finalizationGroup.[[Cells]].
|
||||
9. Return undefined.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var fg = new FinalizationGroup(fn);
|
||||
var holdings = {};
|
||||
|
||||
assert.sameValue(fg.register(fg), undefined, 'Register itself');
|
||||
assert.sameValue(fg.register(fg, holdings), undefined, 'Register itself with holdings');
|
||||
assert.sameValue(fg.register(fg, holdings, fg), undefined, 'Register itself with holdings and unregisterToken');
|
|
@ -1,42 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
description: Return undefined after registering
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
7. Append cell to finalizationGroup.[[Cells]].
|
||||
8. Return undefined.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var fg = new FinalizationGroup(fn);
|
||||
|
||||
var target = {};
|
||||
assert.sameValue(fg.register(target), undefined, 'Register a targer');
|
||||
assert.sameValue(fg.register(target), undefined, 'Register the same target again');
|
||||
assert.sameValue(fg.register(target), undefined, 'Register the same target again and again');
|
||||
|
||||
assert.sameValue(fg.register({}), undefined, 'Register other targets');
|
||||
|
||||
assert.sameValue(fg.register(target, undefined, {}), undefined, 'Register target with unregisterToken');
|
||||
assert.sameValue(
|
||||
fg.register(target, undefined, target),
|
||||
undefined,
|
||||
'Register target with unregisterToken being the registered target'
|
||||
);
|
||||
|
||||
assert.sameValue(fg.register(target, undefined, undefined), undefined, 'Register target with explicit undefined unregisterToken');
|
||||
|
||||
assert.sameValue(fg.register(fn), undefined, 'register the cleanup callback fn');
|
|
@ -1,48 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
description: Throws a TypeError if unregisterToken is not an Object or undefined
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
...
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.register, 'function');
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
var target = {};
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register(target, undefined, null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register(target, undefined, true);
|
||||
}, 'true');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register(target, undefined, false);
|
||||
}, 'false');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register(target, undefined, 1);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register(target, undefined, 'object');
|
||||
}, 'string');
|
||||
|
||||
var s = Symbol();
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register(target, undefined, s);
|
||||
}, 'symbol');
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
description: unregisterToken may be the same as holdings
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
7. Append cell to finalizationGroup.[[Cells]].
|
||||
8. Return undefined.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
var target = {};
|
||||
var holdings = {};
|
||||
assert.sameValue(fg.register(target, holdings, holdings), undefined);
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
description: unregisterToken may be the same as target
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
7. Append cell to finalizationGroup.[[Cells]].
|
||||
8. Return undefined.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
var target = {};
|
||||
assert.sameValue(fg.register(target, '1', target), undefined);
|
|
@ -1,47 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.unregister
|
||||
description: Return values applying custom this
|
||||
info: |
|
||||
FinalizationGroup.prototype.unregister ( unregisterToken )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(unregisterToken) is not Object, throw a TypeError exception.
|
||||
5. Let removed be false.
|
||||
6. For each Record { [[Target]], [[Holdings]], [[UnregisterToken]] } cell that is an element of finalizationGroup.[[Cells]], do
|
||||
a. If SameValue(cell.[[UnregisterToken]], unregisterToken) is true, then
|
||||
i. Remove cell from finalizationGroup.[[Cells]].
|
||||
ii. Set removed to true.
|
||||
7. Return removed.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var unregister = FinalizationGroup.prototype.unregister;
|
||||
var fg = new FinalizationGroup(fn);
|
||||
|
||||
var target1 = {};
|
||||
var target2 = {};
|
||||
var target3 = {};
|
||||
var token1 = {};
|
||||
var token2 = {};
|
||||
|
||||
assert.sameValue(unregister.call(fg, token1), false, 'unregistering token1 from empty fg');
|
||||
assert.sameValue(unregister.call(fg, token2), false, 'unregistering token2 from empty fg');
|
||||
|
||||
fg.register(target1, undefined, token1);
|
||||
fg.register(target2, undefined, token2);
|
||||
fg.register(target3, undefined, token2);
|
||||
|
||||
assert.sameValue(unregister.call(fg, target1), false, 'own target does not work on unregister, #1');
|
||||
assert.sameValue(unregister.call(fg, target2), false, 'own target does not work on unregister, #2');
|
||||
assert.sameValue(unregister.call(fg, target3), false, 'own target does not work on unregister, #3');
|
||||
|
||||
assert.sameValue(unregister.call(fg, token1), true, 'unregistering token1 from fg');
|
||||
assert.sameValue(unregister.call(fg, token1), false, 'unregistering token1 again from fg');
|
||||
assert.sameValue(unregister.call(fg, token2), true, 'unregistering token2 to remove target2 and target3');
|
||||
assert.sameValue(unregister.call(fg, token2), false, 'unregistering token2 from empty fg');
|
|
@ -1,56 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.unregister
|
||||
description: Return boolean values indicating unregistering of values from given token
|
||||
info: |
|
||||
FinalizationGroup.prototype.unregister ( unregisterToken )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(unregisterToken) is not Object, throw a TypeError exception.
|
||||
5. Let removed be false.
|
||||
6. For each Record { [[Target]], [[Holdings]], [[UnregisterToken]] } cell that is an element of finalizationGroup.[[Cells]], do
|
||||
a. If SameValue(cell.[[UnregisterToken]], unregisterToken) is true, then
|
||||
i. Remove cell from finalizationGroup.[[Cells]].
|
||||
ii. Set removed to true.
|
||||
7. Return removed.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var fg = new FinalizationGroup(fn);
|
||||
|
||||
var target1 = {};
|
||||
var target2 = {};
|
||||
var target3 = {};
|
||||
var token1 = {};
|
||||
var token2 = {};
|
||||
|
||||
assert.sameValue(fg.unregister(token1), false, 'unregistering token1 from empty fg');
|
||||
assert.sameValue(fg.unregister(token2), false, 'unregistering token2 from empty fg');
|
||||
|
||||
fg.register(target1, undefined, token1);
|
||||
fg.register(target1, undefined, token1); // Repeat registering un purpose
|
||||
fg.register(target2, undefined, token2);
|
||||
fg.register(target3, undefined, token2);
|
||||
|
||||
assert.sameValue(fg.unregister(target1), false, 'own target does not work on unregister, #1');
|
||||
assert.sameValue(fg.unregister(target2), false, 'own target does not work on unregister, #2');
|
||||
assert.sameValue(fg.unregister(target3), false, 'own target does not work on unregister, #3');
|
||||
|
||||
assert.sameValue(fg.unregister(token1), true, 'unregistering token1 from fg');
|
||||
assert.sameValue(fg.unregister(token1), false, 'unregistering token1 again from fg');
|
||||
assert.sameValue(fg.unregister(token2), true, 'unregistering token2 to remove target2 and target3');
|
||||
assert.sameValue(fg.unregister(token2), false, 'unregistering token2 from empty fg');
|
||||
|
||||
// Notice these assertions take advantage of adding targets previously added with a token,
|
||||
// but now they got no token so it won't be used to remove them.
|
||||
fg.register(target1, token1); // holdings, not unregisterToken
|
||||
fg.register(target2, token2); // holdings, not unregisterToken
|
||||
fg.register(target3);
|
||||
|
||||
assert.sameValue(fg.unregister(token1), false, 'nothing to remove without a set unregisterToken #1');
|
||||
assert.sameValue(fg.unregister(token2), false, 'nothing to remove without a set unregisterToken #2');
|
|
@ -1,49 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.unregister
|
||||
description: Throws a TypeError if unregisterToken is not an Object
|
||||
info: |
|
||||
FinalizationGroup.prototype.unregister ( unregisterToken )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(unregisterToken) is not Object, throw a TypeError exception.
|
||||
...
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.unregister, 'function');
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.unregister(undefined);
|
||||
}, 'undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.unregister(null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.unregister(true);
|
||||
}, 'true');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.unregister(false);
|
||||
}, 'false');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.unregister(1);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.unregister('object');
|
||||
}, 'string');
|
||||
|
||||
var s = Symbol();
|
||||
assert.throws(TypeError, function() {
|
||||
fg.unregister(s);
|
||||
}, 'symbol');
|
|
@ -1,39 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
description: >
|
||||
Returns a new ordinary object from the FinalizationGroup constructor
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationGroup.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
features: [FinalizationGroup, for-of]
|
||||
---*/
|
||||
|
||||
var cleanupCallback = function() {};
|
||||
var fg = new FinalizationGroup(cleanupCallback);
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype);
|
||||
assert.notSameValue(fg, cleanupCallback, 'does not return the same function');
|
||||
assert.sameValue(fg instanceof FinalizationGroup, true, 'instanceof');
|
||||
|
||||
for (let key of Object.getOwnPropertyNames(fg)) {
|
||||
assert(false, `should not set any own named properties: ${key}`);
|
||||
}
|
||||
|
||||
for (let key of Object.getOwnPropertySymbols(fg)) {
|
||||
assert(false, `should not set any own symbol properties: ${String(key)}`);
|
||||
}
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype);
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
description: >
|
||||
Normal completion even if the cleanupCallback fn is poisoned
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationGroup.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var cleanupCallback = function() { throw new Test262Error('should not throw yet'); };
|
||||
var fg = new FinalizationGroup(cleanupCallback);
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype);
|
||||
assert.notSameValue(fg, cleanupCallback, 'does not return the same function');
|
||||
assert.sameValue(fg instanceof FinalizationGroup, true, 'instanceof');
|
||||
|
||||
for (let key of Object.getOwnPropertyNames(fg)) {
|
||||
assert(false, `should not set any own named properties: ${key}`);
|
||||
}
|
||||
|
||||
for (let key of Object.getOwnPropertySymbols(fg)) {
|
||||
assert(false, `should not set any own symbol properties: ${String(key)}`);
|
||||
}
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype);
|
|
@ -0,0 +1,64 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
FinalizationRegistryCleanupIteratorPrototype @@toStringTag
|
||||
info: |
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationRegistryCleanupIterator(finalizationRegistry).
|
||||
...
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
%FinalizationRegistryCleanupIteratorPrototype% [ @@toStringTag ]
|
||||
|
||||
The initial value of the @@toStringTag property is the String value "FinalizationRegistry Cleanup Iterator".
|
||||
|
||||
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
||||
features: [FinalizationRegistry, host-gc-required, Symbol, Symbol.toStringTag]
|
||||
includes: [async-gc.js, propertyHelper.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var FinalizationRegistryCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
FinalizationRegistryCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
finalizationRegistry.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
finalizationRegistry.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
|
||||
verifyProperty(FinalizationRegistryCleanupIteratorPrototype, Symbol.toStringTag, {
|
||||
value: 'FinalizationRegistry Cleanup Iterator',
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -0,0 +1,69 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
Throws a TypeError if [[IsFinalizationRegistryCleanupJobActive]] is false
|
||||
info: |
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationRegistryCleanupIterator(finalizationRegistry).
|
||||
...
|
||||
5. Set finalizationRegistry.[[IsFinalizationRegistryCleanupJobActive]] to true.
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
7. Set finalizationRegistry.[[IsFinalizationRegistryCleanupJobActive]] to false.
|
||||
...
|
||||
|
||||
%FinalizationRegistryCleanupIteratorPrototype%.next ( )
|
||||
|
||||
1. Let iterator be the this value.
|
||||
2. If Type(iterator) is not Object, throw a TypeError exception.
|
||||
3. If iterator does not have a [[FinalizationRegistry]] internal slot, throw a TypeError exception.
|
||||
features: [FinalizationRegistry, WeakRef, host-gc-required, Symbol]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var iter;
|
||||
var FinalizationRegistryCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
iter = iterator;
|
||||
FinalizationRegistryCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
finalizationRegistry.register(target, 'target');
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
finalizationRegistry.cleanupSome(callback);
|
||||
|
||||
// Make sure everything is set
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
assert.sameValue(typeof iter, 'object');
|
||||
assert.sameValue(Object.getPrototypeOf(iter), FinalizationRegistryCleanupIteratorPrototype);
|
||||
|
||||
// To the actual assertion
|
||||
assert.throws(TypeError, function() {
|
||||
iter.next();
|
||||
}, 'Iter should fail if not called during the cleanupSome call');
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -2,21 +2,21 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
FinalizationGroupCleanupIteratorPrototype.next.length property descriptor
|
||||
FinalizationRegistryCleanupIteratorPrototype.next.length property descriptor
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup).
|
||||
3. Let iterator be ! CreateFinalizationRegistryCleanupIterator(finalizationRegistry).
|
||||
...
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
@ -36,21 +36,21 @@ info: |
|
|||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [async-gc.js, propertyHelper.js]
|
||||
flags: [async, non-deterministic]
|
||||
features: [FinalizationGroup, host-gc-required, Symbol]
|
||||
features: [FinalizationRegistry, host-gc-required, Symbol]
|
||||
---*/
|
||||
|
||||
var FinalizationGroupCleanupIteratorPrototype;
|
||||
var FinalizationRegistryCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
FinalizationGroupCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
FinalizationRegistryCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target);
|
||||
finalizationRegistry.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
@ -59,13 +59,13 @@ function emptyCells() {
|
|||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
fg.cleanupSome(callback);
|
||||
finalizationRegistry.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
|
||||
assert.sameValue(typeof FinalizationGroupCleanupIteratorPrototype.next, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistryCleanupIteratorPrototype.next, 'function');
|
||||
|
||||
verifyProperty(FinalizationGroupCleanupIteratorPrototype.next, 'length', {
|
||||
verifyProperty(FinalizationRegistryCleanupIteratorPrototype.next, 'length', {
|
||||
value: 0,
|
||||
enumerable: false,
|
||||
writable: false,
|
|
@ -0,0 +1,90 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
If iterator does not have a [[FinalizationRegistry]] internal slot, throw a TypeError exception.
|
||||
info: |
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationRegistryCleanupIterator(finalizationRegistry).
|
||||
...
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
%FinalizationRegistryCleanupIteratorPrototype%.next ( )
|
||||
|
||||
1. Let iterator be the this value.
|
||||
2. If Type(iterator) is not Object, throw a TypeError exception.
|
||||
3. If iterator does not have a [[FinalizationRegistry]] internal slot, throw a TypeError exception.
|
||||
features: [FinalizationRegistry, WeakRef, host-gc-required, Symbol]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var FinalizationRegistryCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var endOfCall = 0;
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
// Only the iterator itself will have a [[FinalizationRegistry]] internal
|
||||
FinalizationRegistryCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
|
||||
// It's sensitive the assertions remain inside this function in order to secure
|
||||
// [[IsFinalizationRegistryCleanupJobActive]] is true
|
||||
assert.sameValue(typeof FinalizationRegistryCleanupIteratorPrototype.next, 'function');
|
||||
|
||||
var next = FinalizationRegistryCleanupIteratorPrototype.next;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
next.call({});
|
||||
}, '{}');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
next.call(FinalizationRegistry);
|
||||
}, 'FinalizationRegistry');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
next.call(FinalizationRegistryCleanupIteratorPrototype);
|
||||
}, 'FinalizationRegistryCleanupIteratorPrototype');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
next.call(finalizationRegistry);
|
||||
}, 'FinalizationRegistry instance');
|
||||
|
||||
var wr = new WeakRef({});
|
||||
assert.throws(TypeError, function() {
|
||||
next.call(wr);
|
||||
}, 'WeakRef instance');
|
||||
|
||||
// Abrupt completions are not directly returned.
|
||||
endOfCall += 1;
|
||||
}
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
finalizationRegistry.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
finalizationRegistry.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
assert.sameValue(endOfCall, 1, 'Abrupt completions are not directly returned.');
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -2,21 +2,21 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
FinalizationGroupCleanupIteratorPrototype.next.name property descriptor
|
||||
FinalizationRegistryCleanupIteratorPrototype.next.name property descriptor
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup).
|
||||
3. Let iterator be ! CreateFinalizationRegistryCleanupIterator(finalizationRegistry).
|
||||
...
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
@ -35,21 +35,21 @@ info: |
|
|||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [async-gc.js, propertyHelper.js]
|
||||
flags: [async, non-deterministic]
|
||||
features: [FinalizationGroup, host-gc-required, Symbol]
|
||||
features: [FinalizationRegistry, host-gc-required, Symbol]
|
||||
---*/
|
||||
|
||||
var FinalizationGroupCleanupIteratorPrototype;
|
||||
var FinalizationRegistryCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
FinalizationGroupCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
FinalizationRegistryCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target);
|
||||
finalizationRegistry.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
@ -58,13 +58,13 @@ function emptyCells() {
|
|||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
fg.cleanupSome(callback);
|
||||
finalizationRegistry.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
|
||||
assert.sameValue(typeof FinalizationGroupCleanupIteratorPrototype.next, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistryCleanupIteratorPrototype.next, 'function');
|
||||
|
||||
var next = FinalizationGroupCleanupIteratorPrototype.next;
|
||||
var next = FinalizationRegistryCleanupIteratorPrototype.next;
|
||||
|
||||
verifyProperty(next, 'name', {
|
||||
value: 'next',
|
|
@ -2,46 +2,46 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
FinalizationGroupCleanupIteratorPrototype.next() throws if this is not Object
|
||||
FinalizationRegistryCleanupIteratorPrototype.next() throws if this is not Object
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup).
|
||||
3. Let iterator be ! CreateFinalizationRegistryCleanupIterator(finalizationRegistry).
|
||||
...
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
%FinalizationGroupCleanupIteratorPrototype%.next ( )
|
||||
%FinalizationRegistryCleanupIteratorPrototype%.next ( )
|
||||
|
||||
1. Let iterator be the this value.
|
||||
2. If Type(iterator) is not Object, throw a TypeError exception.
|
||||
features: [FinalizationGroup, host-gc-required, Symbol]
|
||||
features: [FinalizationRegistry, host-gc-required, Symbol]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var FinalizationGroupCleanupIteratorPrototype;
|
||||
var FinalizationRegistryCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
FinalizationGroupCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
FinalizationRegistryCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target);
|
||||
finalizationRegistry.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
@ -50,13 +50,13 @@ function emptyCells() {
|
|||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
fg.cleanupSome(callback);
|
||||
finalizationRegistry.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
|
||||
assert.sameValue(typeof FinalizationGroupCleanupIteratorPrototype.next, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistryCleanupIteratorPrototype.next, 'function');
|
||||
|
||||
var next = FinalizationGroupCleanupIteratorPrototype.next;
|
||||
var next = FinalizationRegistryCleanupIteratorPrototype.next;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
next.call(undefined);
|
|
@ -0,0 +1,67 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
Prop descriptor for FinalizationRegistryCleanupIteratorPrototype.next
|
||||
info: |
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationRegistryCleanupIterator(finalizationRegistry).
|
||||
...
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
|
||||
Every other data property described in clauses 18 through 26 and in Annex B.2
|
||||
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js, async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
features: [FinalizationRegistry, host-gc-required, Symbol]
|
||||
---*/
|
||||
|
||||
var FinalizationRegistryCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
FinalizationRegistryCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
finalizationRegistry.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
finalizationRegistry.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
|
||||
assert.sameValue(typeof FinalizationRegistryCleanupIteratorPrototype.next, 'function');
|
||||
|
||||
var next = FinalizationRegistryCleanupIteratorPrototype.next;
|
||||
|
||||
verifyProperty(FinalizationRegistryCleanupIteratorPrototype, 'next', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -0,0 +1,91 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
FinalizationRegistryCleanupIterator has a [[Prototype]] internal slot whose value is the intrinsic
|
||||
object %IteratorPrototype%.
|
||||
info: |
|
||||
The %FinalizationRegistryCleanupIteratorPrototype% Object
|
||||
|
||||
- has properties that are inherited by all FinalizationRegistry Cleanup Iterator Objects.
|
||||
- is an ordinary object.
|
||||
- has a [[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%.
|
||||
...
|
||||
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
6. Return undefined.
|
||||
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
...
|
||||
2. If CheckForEmptyCells(finalizationRegistry) is false, return.
|
||||
3. Let iterator be ! CreateFinalizationRegistryCleanupIterator(finalizationRegistry).
|
||||
4. If callback is undefined, set callback to finalizationRegistry.[[CleanupCallback]].
|
||||
5. Set finalizationRegistry.[[IsFinalizationRegistryCleanupJobActive]] to true.
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
CheckForEmptyCells ( finalizationRegistry )
|
||||
|
||||
...
|
||||
2. For each cell in finalizationRegistry.[[Cells]], do
|
||||
a. If cell.[[Target]] is empty, then
|
||||
i. Return true.
|
||||
3. Return false.
|
||||
|
||||
CreateFinalizationRegistryCleanupIterator ( finalizationRegistry )
|
||||
|
||||
...
|
||||
4. Let prototype be finalizationRegistry.[[Realm]].[[Intrinsics]].[[%FinalizationRegistryCleanupIteratorPrototype%]].
|
||||
5. Let iterator be ObjectCreate(prototype, « [[FinalizationRegistry]] »).
|
||||
6. Set iterator.[[FinalizationRegistry]] to finalizationRegistry.
|
||||
7. Return iterator.
|
||||
features: [FinalizationRegistry, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
|
||||
var FinalizationRegistryCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var cleanupCallbackCalled = 0;
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
|
||||
FinalizationRegistryCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
finalizationRegistry.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
finalizationRegistry.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1, 'cleanup successful');
|
||||
|
||||
var proto = Object.getPrototypeOf(FinalizationRegistryCleanupIteratorPrototype);
|
||||
assert.sameValue(
|
||||
proto, IteratorPrototype,
|
||||
'[[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%'
|
||||
);
|
||||
|
||||
assert.sameValue(cleanupCallbackCalled, 0, 'if a callback is given, do not call cleanupCallback');
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry-constructor
|
||||
description: >
|
||||
The FinalizationRegistry constructor is the %FinalizationRegistry% intrinsic object and the initial
|
||||
value of the FinalizationRegistry property of the global object.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof FinalizationRegistry, 'function',
|
||||
'typeof FinalizationRegistry is function'
|
||||
);
|
|
@ -2,18 +2,18 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
esid: sec-finalization-registry-target
|
||||
description: >
|
||||
cleanupCallback has only one optional chance to be called for a GC that cleans up
|
||||
a registered target.
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
FinalizationRegistry ( cleanupCallback )
|
||||
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
...
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ? CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
5. Perform ? CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
6. Return undefined.
|
||||
|
||||
Execution
|
||||
|
@ -22,10 +22,10 @@ info: |
|
|||
|
||||
1. For each WeakRef ref such that ref.[[Target]] is obj,
|
||||
a. Set ref.[[Target]] to empty.
|
||||
2. For each FinalizationGroup fg such that fg.[[Cells]] contains cell, such that cell.[[Target]] is obj,
|
||||
2. For each FinalizationRegistry finalizationRegistry such that finalizationRegistry.[[Cells]] contains cell, such that cell.[[Target]] is obj,
|
||||
a. Set cell.[[Target]] to empty.
|
||||
b. Optionally, perform ! HostCleanupFinalizationGroup(fg).
|
||||
features: [FinalizationGroup, async-functions, host-gc-required]
|
||||
b. Optionally, perform ! HostCleanupFinalizationRegistry(finalizationRegistry).
|
||||
features: [FinalizationRegistry, async-functions, host-gc-required]
|
||||
flags: [async, non-deterministic]
|
||||
includes: [async-gc.js]
|
||||
---*/
|
||||
|
@ -33,20 +33,20 @@ includes: [async-gc.js]
|
|||
var cleanupCallback = 0;
|
||||
var called = 0;
|
||||
|
||||
// both this cb and the fg callback are not exhausting the iterator to prevent
|
||||
// the target cell from being removed from the finalizationGroup.[[Cells]].
|
||||
// More info at %FinalizationGroupCleanupIteratorPrototype%.next ( )
|
||||
// both this cb and the finalizationRegistry callback are not exhausting the iterator to prevent
|
||||
// the target cell from being removed from the finalizationRegistry.[[Cells]].
|
||||
// More info at %FinalizationRegistryCleanupIteratorPrototype%.next ( )
|
||||
function cb() {
|
||||
called += 1;
|
||||
}
|
||||
|
||||
var fg = new FinalizationGroup(function() {
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {
|
||||
cleanupCallback += 1;
|
||||
});
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target, 'a');
|
||||
finalizationRegistry.register(target, 'a');
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
@ -59,7 +59,7 @@ function emptyCells() {
|
|||
async function fn() {
|
||||
await Promise.resolve(1);
|
||||
|
||||
fg.cleanupSome(cb);
|
||||
finalizationRegistry.cleanupSome(cb);
|
||||
// This asserts the registered object was emptied in the previous GC.
|
||||
assert.sameValue(called, 1, 'cleanupSome callback for the first time');
|
||||
|
||||
|
@ -71,16 +71,16 @@ async function fn() {
|
|||
assert(cleanupCallback >= 0, 'cleanupCallback might be 0');
|
||||
assert(cleanupCallback <= 1, 'cleanupCallback might be 1');
|
||||
|
||||
// Restoring the cleanupCallback variable to 0 will help us asserting the fg
|
||||
// Restoring the cleanupCallback variable to 0 will help us asserting the finalizationRegistry
|
||||
// callback is not called again.
|
||||
cleanupCallback = 0;
|
||||
|
||||
await $262.gc();
|
||||
await Promise.resolve(2); // tick
|
||||
|
||||
fg.cleanupSome(cb);
|
||||
finalizationRegistry.cleanupSome(cb);
|
||||
|
||||
// This cb is called again because fg still holds an emptied cell, but it's
|
||||
// This cb is called again because finalizationRegistry still holds an emptied cell, but it's
|
||||
// not yet removed from the
|
||||
assert.sameValue(called, 2, 'cleanupSome callback for the second time');
|
||||
assert.sameValue(cleanupCallback, 0, 'cleanupCallback is not called again #1');
|
||||
|
@ -88,7 +88,7 @@ async function fn() {
|
|||
await $262.gc();
|
||||
await Promise.resolve(3); // tick
|
||||
|
||||
fg.cleanupSome(cb);
|
||||
finalizationRegistry.cleanupSome(cb);
|
||||
|
||||
assert.sameValue(called, 3, 'cleanupSome callback for the third time');
|
||||
assert.sameValue(cleanupCallback, 0, 'cleanupCallback is not called again #2');
|
||||
|
@ -103,7 +103,7 @@ emptyCells()
|
|||
|
||||
assert.sameValue(cleanupCallback, 0, 'cleanupCallback is not called again #3');
|
||||
|
||||
fg.cleanupSome(cb);
|
||||
finalizationRegistry.cleanupSome(cb);
|
||||
|
||||
assert.sameValue(called, 4, 'cleanupSome callback for the fourth time');
|
||||
assert.sameValue(cleanupCallback, 0, 'cleanupCallback is not called again #4');
|
||||
|
@ -111,7 +111,7 @@ emptyCells()
|
|||
await $262.gc();
|
||||
|
||||
// Now we are exhausting the iterator, so cleanupSome callback will also not be called.
|
||||
fg.cleanupSome(iterator => {
|
||||
finalizationRegistry.cleanupSome(iterator => {
|
||||
var exhausted = [...iterator];
|
||||
assert.sameValue(exhausted.length, 1);
|
||||
assert.sameValue(exhausted[0], 'a');
|
||||
|
@ -127,7 +127,7 @@ emptyCells()
|
|||
await await Promise.resolve(6); // more ticks
|
||||
await await await Promise.resolve(7); // even more ticks
|
||||
|
||||
fg.cleanupSome(cb);
|
||||
finalizationRegistry.cleanupSome(cb);
|
||||
|
||||
assert.sameValue(called, 5, 'cleanupSome callback is not called anymore, no empty cells');
|
||||
assert.sameValue(cleanupCallback, 0, 'cleanupCallback is not called again #5');
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry-target
|
||||
description: Instances of FinalizationRegistry are extensible
|
||||
info: |
|
||||
FinalizationRegistry ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationRegistry be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationRegistryPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationRegistryCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationRegistry.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
ObjectCreate ( proto [ , internalSlotsList ] )
|
||||
|
||||
4. Set obj.[[Prototype]] to proto.
|
||||
5. Set obj.[[Extensible]] to true.
|
||||
6. Return obj.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
assert.sameValue(Object.isExtensible(finalizationRegistry), true);
|
|
@ -2,10 +2,10 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
description: FinalizationGroup.length property descriptor
|
||||
esid: sec-finalization-registry-target
|
||||
description: FinalizationRegistry.length property descriptor
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
FinalizationRegistry ( cleanupCallback )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
|
@ -21,10 +21,10 @@ info: |
|
|||
function object has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup, 'length', {
|
||||
verifyProperty(FinalizationRegistry, 'length', {
|
||||
value: 1,
|
||||
writable: false,
|
||||
enumerable: false,
|
|
@ -2,10 +2,10 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
description: FinalizationGroup.name property descriptor
|
||||
esid: sec-finalization-registry-target
|
||||
description: FinalizationRegistry.name property descriptor
|
||||
info: |
|
||||
FinalizationGroup ( value )
|
||||
FinalizationRegistry ( value )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
|
@ -20,11 +20,11 @@ info: |
|
|||
object, if it exists, has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup, 'name', {
|
||||
value: 'FinalizationGroup',
|
||||
verifyProperty(FinalizationRegistry, 'name', {
|
||||
value: 'FinalizationRegistry',
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true
|
|
@ -0,0 +1,58 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry-target
|
||||
description: >
|
||||
[[Prototype]] defaults to %FinalizationRegistryPrototype% if NewTarget.prototype is not an object.
|
||||
info: |
|
||||
FinalizationRegistry ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationRegistry be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationRegistryPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationRegistryCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationRegistry.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
|
||||
3. Let proto be ? Get(constructor, 'prototype').
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
|
||||
5. Return proto.
|
||||
features: [FinalizationRegistry, Reflect.construct, Symbol]
|
||||
---*/
|
||||
|
||||
var finalizationRegistry;
|
||||
function newTarget() {}
|
||||
function fn() {}
|
||||
|
||||
newTarget.prototype = undefined;
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), FinalizationRegistry.prototype, 'newTarget.prototype is undefined');
|
||||
|
||||
newTarget.prototype = null;
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), FinalizationRegistry.prototype, 'newTarget.prototype is null');
|
||||
|
||||
newTarget.prototype = true;
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), FinalizationRegistry.prototype, 'newTarget.prototype is a Boolean');
|
||||
|
||||
newTarget.prototype = '';
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), FinalizationRegistry.prototype, 'newTarget.prototype is a String');
|
||||
|
||||
newTarget.prototype = Symbol();
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), FinalizationRegistry.prototype, 'newTarget.prototype is a Symbol');
|
||||
|
||||
newTarget.prototype = 1;
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), FinalizationRegistry.prototype, 'newTarget.prototype is a Number');
|
|
@ -2,9 +2,9 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-constructor
|
||||
esid: sec-finalization-registry-constructor
|
||||
description: >
|
||||
Property descriptor of FinalizationGroup
|
||||
Property descriptor of FinalizationRegistry
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
|
||||
|
@ -12,10 +12,10 @@ info: |
|
|||
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
verifyProperty(this, 'FinalizationGroup', {
|
||||
verifyProperty(this, 'FinalizationRegistry', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
|
@ -0,0 +1,59 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry-target
|
||||
description: Default [[Prototype]] value derived from realm of the newTarget
|
||||
info: |
|
||||
FinalizationRegistry ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationRegistry be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationRegistryPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationRegistryCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationRegistry.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
|
||||
3. Let proto be ? Get(constructor, 'prototype').
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
|
||||
5. Return proto.
|
||||
features: [FinalizationRegistry, cross-realm, Reflect, Symbol]
|
||||
---*/
|
||||
|
||||
var other = $262.createRealm().global;
|
||||
var newTarget = new other.Function();
|
||||
function fn() {}
|
||||
var finalizationRegistry;
|
||||
|
||||
newTarget.prototype = undefined;
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is undefined');
|
||||
|
||||
newTarget.prototype = null;
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is null');
|
||||
|
||||
newTarget.prototype = true;
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is a Boolean');
|
||||
|
||||
newTarget.prototype = '';
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is a String');
|
||||
|
||||
newTarget.prototype = Symbol();
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is a Symbol');
|
||||
|
||||
newTarget.prototype = 1;
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is a Number');
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
The prototype of FinalizationRegistry is Object.prototype
|
||||
info: |
|
||||
The value of the [[Prototype]] internal slot of the FinalizationRegistry object is the
|
||||
intrinsic object %FunctionPrototype%.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(FinalizationRegistry),
|
||||
Function.prototype,
|
||||
'Object.getPrototypeOf(FinalizationRegistry) returns the value of `Function.prototype`'
|
||||
);
|
|
@ -2,16 +2,16 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
esid: sec-finalization-registry-target
|
||||
description: >
|
||||
Return abrupt from getting the NewTarget prototype
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
FinalizationRegistry ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
|
||||
3. Let finalizationRegistry be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationRegistryPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationRegistryCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationGroup.
|
||||
9. Return finalizationRegistry.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
|
@ -22,7 +22,7 @@ info: |
|
|||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
|
||||
3. Let proto be ? Get(constructor, 'prototype').
|
||||
features: [FinalizationGroup, Reflect.construct]
|
||||
features: [FinalizationRegistry, Reflect.construct]
|
||||
---*/
|
||||
|
||||
var calls = 0;
|
||||
|
@ -35,7 +35,7 @@ Object.defineProperty(newTarget, 'prototype', {
|
|||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Reflect.construct(FinalizationGroup, [function() {}], newTarget);
|
||||
Reflect.construct(FinalizationRegistry, [function() {}], newTarget);
|
||||
});
|
||||
|
||||
assert.sameValue(calls, 1);
|
|
@ -2,16 +2,16 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
esid: sec-finalization-registry-target
|
||||
description: >
|
||||
The [[Prototype]] internal slot is computed from NewTarget.
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
FinalizationRegistry ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
|
||||
3. Let finalizationRegistry be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationRegistryPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationRegistryCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationGroup.
|
||||
9. Return finalizationRegistry.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
|
@ -26,13 +26,13 @@ info: |
|
|||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
|
||||
5. Return proto.
|
||||
features: [FinalizationGroup, Reflect.construct]
|
||||
features: [FinalizationRegistry, Reflect.construct]
|
||||
---*/
|
||||
|
||||
var fg;
|
||||
var finalizationRegistry;
|
||||
|
||||
fg = Reflect.construct(FinalizationGroup, [function() {}], Object);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), Object.prototype, 'NewTarget is built-in Object constructor');
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [function() {}], Object);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), Object.prototype, 'NewTarget is built-in Object constructor');
|
||||
|
||||
var newTarget = function() {}.bind(null);
|
||||
Object.defineProperty(newTarget, 'prototype', {
|
||||
|
@ -40,5 +40,5 @@ Object.defineProperty(newTarget, 'prototype', {
|
|||
return Array.prototype;
|
||||
}
|
||||
});
|
||||
fg = Reflect.construct(FinalizationGroup, [function() {}], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(fg), Array.prototype, 'NewTarget is BoundFunction with accessor');
|
||||
finalizationRegistry = Reflect.construct(FinalizationRegistry, [function() {}], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), Array.prototype, 'NewTarget is BoundFunction with accessor');
|
|
@ -2,16 +2,16 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
esid: sec-finalization-registry-target
|
||||
description: >
|
||||
The [[Prototype]] internal slot is computed from NewTarget.
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
FinalizationRegistry ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
|
||||
3. Let finalizationRegistry be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationRegistryPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationRegistryCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationGroup.
|
||||
9. Return finalizationRegistry.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
|
@ -26,8 +26,8 @@ info: |
|
|||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
|
||||
5. Return proto.
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype);
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), FinalizationRegistry.prototype);
|
|
@ -2,21 +2,21 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-@@tostringtag
|
||||
esid: sec-finalization-registry-@@tostringtag
|
||||
description: >
|
||||
`Symbol.toStringTag` property descriptor
|
||||
info: |
|
||||
The initial value of the @@toStringTag property is the String value
|
||||
'FinalizationGroup'.
|
||||
'FinalizationRegistry'.
|
||||
|
||||
This property has the attributes { [[Writable]]: false, [[Enumerable]]:
|
||||
false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup, Symbol, Symbol.toStringTag]
|
||||
features: [FinalizationRegistry, Symbol, Symbol.toStringTag]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype, Symbol.toStringTag, {
|
||||
value: 'FinalizationGroup',
|
||||
verifyProperty(FinalizationRegistry.prototype, Symbol.toStringTag, {
|
||||
value: 'FinalizationRegistry',
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true
|
98
test/built-ins/FinalizationRegistry/prototype/cleanupSome/callback-iterator-proto.js
vendored
Normal file
98
test/built-ins/FinalizationRegistry/prototype/cleanupSome/callback-iterator-proto.js
vendored
Normal file
|
@ -0,0 +1,98 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
The callback function is called with a FinalizationRegistryCleanupIterator
|
||||
info: |
|
||||
The %FinalizationRegistryCleanupIteratorPrototype% Object
|
||||
|
||||
- has properties that are inherited by all FinalizationRegistry Cleanup Iterator Objects.
|
||||
- is an ordinary object.
|
||||
- has a [[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%.
|
||||
...
|
||||
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
6. Return undefined.
|
||||
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
...
|
||||
2. If CheckForEmptyCells(finalizationRegistry) is false, return.
|
||||
3. Let iterator be ! CreateFinalizationRegistryCleanupIterator(finalizationRegistry).
|
||||
4. If callback is undefined, set callback to finalizationRegistry.[[CleanupCallback]].
|
||||
5. Set finalizationRegistry.[[IsFinalizationRegistryCleanupJobActive]] to true.
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
CheckForEmptyCells ( finalizationRegistry )
|
||||
|
||||
...
|
||||
2. For each cell in finalizationRegistry.[[Cells]], do
|
||||
a. If cell.[[Target]] is empty, then
|
||||
i. Return true.
|
||||
3. Return false.
|
||||
|
||||
CreateFinalizationRegistryCleanupIterator ( finalizationRegistry )
|
||||
|
||||
...
|
||||
4. Let prototype be finalizationRegistry.[[Realm]].[[Intrinsics]].[[%FinalizationRegistryCleanupIteratorPrototype%]].
|
||||
5. Let iterator be ObjectCreate(prototype, « [[FinalizationRegistry]] »).
|
||||
6. Set iterator.[[FinalizationRegistry]] to finalizationRegistry.
|
||||
7. Return iterator.
|
||||
features: [FinalizationRegistry, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
|
||||
var FinalizationRegistryCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
var cleanupCallbackCalled = 0;
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
|
||||
FinalizationRegistryCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {
|
||||
cleanupCallbackCalled += 1;
|
||||
});
|
||||
|
||||
async function register() {
|
||||
var target = {};
|
||||
finalizationRegistry.register(target);
|
||||
var prom = asyncGC(target);
|
||||
|
||||
target = null;
|
||||
assert.sameValue(called, 0); // never called in sync execution
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
register()
|
||||
.then(function() {
|
||||
// We can't observe if the cleanupCallback was called, but we can make sure cleanupSome won't call it.
|
||||
cleanupCallbackCalled = 0;
|
||||
|
||||
finalizationRegistry.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1);
|
||||
|
||||
var proto = Object.getPrototypeOf(FinalizationRegistryCleanupIteratorPrototype);
|
||||
assert.sameValue(
|
||||
proto, IteratorPrototype,
|
||||
'[[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%'
|
||||
);
|
||||
|
||||
assert.sameValue(cleanupCallbackCalled, 0, 'if a callback is given, do not call cleanupCallback');
|
||||
})
|
||||
.then($DONE, resolveAsyncGC);
|
53
test/built-ins/FinalizationRegistry/prototype/cleanupSome/callback-not-callable-throws.js
vendored
Normal file
53
test/built-ins/FinalizationRegistry/prototype/cleanupSome/callback-not-callable-throws.js
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.cleanupSome
|
||||
description: Throws a TypeError if callback is not callable
|
||||
info: |
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
...
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.cleanupSome, 'function');
|
||||
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.cleanupSome(null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.cleanupSome(true);
|
||||
}, 'true');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.cleanupSome(false);
|
||||
}, 'false');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.cleanupSome(1);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.cleanupSome('object');
|
||||
}, 'string');
|
||||
|
||||
var s = Symbol();
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.cleanupSome(s);
|
||||
}, 'symbol');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.cleanupSome({});
|
||||
}, 'object');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.cleanupSome(FinalizationRegistry.prototype);
|
||||
}, 'FinalizationRegistry.prototype');
|
|
@ -2,18 +2,18 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.cleanupSome
|
||||
esid: sec-finalization-registry.prototype.cleanupSome
|
||||
description: Cleanup might be prevented with a reference usage;
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ? CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
5. Perform ? CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
6. Return undefined.
|
||||
features: [FinalizationGroup, host-gc-required]
|
||||
features: [FinalizationRegistry, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
@ -22,14 +22,14 @@ var holdingsList;
|
|||
function cb(iterator) {
|
||||
holdingsList = [...iterator];
|
||||
};
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
var referenced = {};
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target, 'target!');
|
||||
fg.register(referenced, 'referenced');
|
||||
finalizationRegistry.register(target, 'target!');
|
||||
finalizationRegistry.register(referenced, 'referenced');
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
@ -38,7 +38,7 @@ function emptyCells() {
|
|||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
fg.cleanupSome(cb);
|
||||
finalizationRegistry.cleanupSome(cb);
|
||||
|
||||
assert.sameValue(holdingsList.length, 1);
|
||||
assert.sameValue(holdingsList[0], 'target!');
|
|
@ -2,37 +2,37 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.cleanupSome
|
||||
esid: sec-finalization-registry.prototype.cleanupSome
|
||||
description: Cleanup might be prevented with an unregister usage
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ? CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
5. Perform ? CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
6. Return undefined.
|
||||
|
||||
FinalizationGroup.prototype.unregister ( unregisterToken )
|
||||
FinalizationRegistry.prototype.unregister ( unregisterToken )
|
||||
|
||||
1. Let removed be false.
|
||||
2. For each Record { [[Target]], [[Holdings]], [[UnregisterToken]] } cell that is an element of finalizationGroup.[[Cells]], do
|
||||
2. For each Record { [[Target]], [[Holdings]], [[UnregisterToken]] } cell that is an element of finalizationRegistry.[[Cells]], do
|
||||
a. If SameValue(cell.[[UnregisterToken]], unregisterToken) is true, then
|
||||
i. Remove cell from finalizationGroup.[[Cells]].
|
||||
i. Remove cell from finalizationRegistry.[[Cells]].
|
||||
ii. Set removed to true.
|
||||
3. Return removed.
|
||||
features: [FinalizationGroup, host-gc-required]
|
||||
features: [FinalizationRegistry, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var token = {};
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target, 'target!', token);
|
||||
finalizationRegistry.register(target, 'target!', token);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
@ -43,10 +43,10 @@ function emptyCells() {
|
|||
emptyCells().then(function() {
|
||||
var called = 0;
|
||||
|
||||
var res = fg.unregister(token);
|
||||
var res = finalizationRegistry.unregister(token);
|
||||
assert.sameValue(res, true, 'unregister target before iterating over it in cleanup');
|
||||
|
||||
fg.cleanupSome(function cb(iterator) {
|
||||
finalizationRegistry.cleanupSome(function cb(iterator) {
|
||||
called += 1;
|
||||
});
|
||||
|
|
@ -2,25 +2,25 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
The cleanupSome() method throws if cleanup is currently in progress.
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
...
|
||||
4. If finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] is true,
|
||||
4. If finalizationRegistry.[[IsFinalizationRegistryCleanupJobActive]] is true,
|
||||
throw a TypeError exception.
|
||||
|
||||
features: [FinalizationGroup, host-gc-required]
|
||||
features: [FinalizationRegistry, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var called = 0;
|
||||
var endOfCall = 0;
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
|
@ -29,7 +29,7 @@ function callback(iterator) {
|
|||
// Atempt to re-enter the callback.
|
||||
var nestedCallbackRan = false;
|
||||
assert.throws(TypeError, () => {
|
||||
fg.cleanupSome(() => { nestedCallbackRan = true });
|
||||
finalizationRegistry.cleanupSome(() => { nestedCallbackRan = true });
|
||||
});
|
||||
assert.sameValue(nestedCallbackRan, false);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ function callback(iterator) {
|
|||
|
||||
function emptyCells() {
|
||||
var o1 = {};
|
||||
fg.register(o1, 'holdings 1');
|
||||
finalizationRegistry.register(o1, 'holdings 1');
|
||||
|
||||
var prom = asyncGC(o1);
|
||||
o1 = null;
|
||||
|
@ -48,7 +48,7 @@ function emptyCells() {
|
|||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
fg.cleanupSome(callback);
|
||||
finalizationRegistry.cleanupSome(callback);
|
||||
|
||||
assert.sameValue(called, 1, 'callback was called');
|
||||
assert.sameValue(endOfCall, 1, 'callback finished');
|
86
test/built-ins/FinalizationRegistry/prototype/cleanupSome/cleanupcallback-iterator-proto.js
vendored
Normal file
86
test/built-ins/FinalizationRegistry/prototype/cleanupSome/cleanupcallback-iterator-proto.js
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
The cleanup callback function is called with a FinalizationRegistryCleanupIterator
|
||||
info: |
|
||||
The %FinalizationRegistryCleanupIteratorPrototype% Object
|
||||
|
||||
- has properties that are inherited by all FinalizationRegistry Cleanup Iterator Objects.
|
||||
- is an ordinary object.
|
||||
- has a [[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%.
|
||||
...
|
||||
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
6. Return undefined.
|
||||
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
...
|
||||
2. If CheckForEmptyCells(finalizationRegistry) is false, return.
|
||||
3. Let iterator be ! CreateFinalizationRegistryCleanupIterator(finalizationRegistry).
|
||||
4. If callback is undefined, set callback to finalizationRegistry.[[CleanupCallback]].
|
||||
5. Set finalizationRegistry.[[IsFinalizationRegistryCleanupJobActive]] to true.
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
CheckForEmptyCells ( finalizationRegistry )
|
||||
|
||||
...
|
||||
2. For each cell in finalizationRegistry.[[Cells]], do
|
||||
a. If cell.[[Target]] is empty, then
|
||||
i. Return true.
|
||||
3. Return false.
|
||||
|
||||
CreateFinalizationRegistryCleanupIterator ( finalizationRegistry )
|
||||
|
||||
...
|
||||
4. Let prototype be finalizationRegistry.[[Realm]].[[Intrinsics]].[[%FinalizationRegistryCleanupIteratorPrototype%]].
|
||||
5. Let iterator be ObjectCreate(prototype, « [[FinalizationRegistry]] »).
|
||||
6. Set iterator.[[FinalizationRegistry]] to finalizationRegistry.
|
||||
7. Return iterator.
|
||||
features: [FinalizationRegistry, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
|
||||
var FinalizationRegistryCleanupIteratorPrototype;
|
||||
var called = 0;
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
|
||||
FinalizationRegistryCleanupIteratorPrototype = Object.getPrototypeOf(iterator);
|
||||
}
|
||||
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
finalizationRegistry.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
finalizationRegistry.cleanupSome(callback);
|
||||
assert.sameValue(called, 1);
|
||||
|
||||
var proto = Object.getPrototypeOf(FinalizationRegistryCleanupIteratorPrototype);
|
||||
assert.sameValue(
|
||||
proto, IteratorPrototype,
|
||||
'[[Prototype]] internal slot whose value is the intrinsic object %IteratorPrototype%'
|
||||
);
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.cleanupSome
|
||||
description: Return values applying custom this
|
||||
info: |
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
6. Return undefined.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var cleanupSome = FinalizationRegistry.prototype.cleanupSome;
|
||||
var finalizationRegistry = new FinalizationRegistry(fn);
|
||||
|
||||
var cb = function() {};
|
||||
|
||||
assert.sameValue(cleanupSome.call(finalizationRegistry, cb), undefined);
|
||||
assert.sameValue(cleanupSome.call(finalizationRegistry, fn), undefined), 'reuse the same cleanup callback fn';
|
|
@ -2,33 +2,33 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-finalization-group-constructor
|
||||
esid: sec-properties-of-the-finalization-registry-constructor
|
||||
description: >
|
||||
Iterates over different type values in holdings
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup).
|
||||
3. Let iterator be ! CreateFinalizationRegistryCleanupIterator(finalizationRegistry).
|
||||
...
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
%FinalizationGroupCleanupIteratorPrototype%.next ( )
|
||||
%FinalizationRegistryCleanupIteratorPrototype%.next ( )
|
||||
|
||||
8. If finalizationGroup.[[Cells]] contains a Record cell such that cell.[[Target]] is empty,
|
||||
8. If finalizationRegistry.[[Cells]] contains a Record cell such that cell.[[Target]] is empty,
|
||||
a. Choose any such cell.
|
||||
b. Remove cell from finalizationGroup.[[Cells]].
|
||||
b. Remove cell from finalizationRegistry.[[Cells]].
|
||||
c. Return CreateIterResultObject(cell.[[Holdings]], false).
|
||||
9. Otherwise, return CreateIterResultObject(undefined, true).
|
||||
features: [FinalizationGroup, Symbol, host-gc-required]
|
||||
features: [FinalizationRegistry, Symbol, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
@ -36,7 +36,7 @@ flags: [async, non-deterministic]
|
|||
function check(value, expectedName) {
|
||||
var holdings;
|
||||
var called = 0;
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function callback(iterator) {
|
||||
called += 1;
|
||||
|
@ -46,7 +46,7 @@ function check(value, expectedName) {
|
|||
// This is internal to avoid conflicts
|
||||
function emptyCells(value) {
|
||||
var target = {};
|
||||
fg.register(target, value);
|
||||
finalizationRegistry.register(target, value);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
@ -55,7 +55,7 @@ function check(value, expectedName) {
|
|||
}
|
||||
|
||||
return emptyCells(value).then(function() {
|
||||
fg.cleanupSome(callback);
|
||||
finalizationRegistry.cleanupSome(callback);
|
||||
assert.sameValue(called, 1, expectedName);
|
||||
assert.sameValue(holdings.length, 1, expectedName);
|
||||
assert.sameValue(holdings[0], value, expectedName);
|
|
@ -2,10 +2,10 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.cleanupSome
|
||||
description: FinalizationGroup.prototype.cleanupSome.length property descriptor
|
||||
esid: sec-finalization-registry.prototype.cleanupSome
|
||||
description: FinalizationRegistry.prototype.cleanupSome.length property descriptor
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
|
@ -21,10 +21,10 @@ info: |
|
|||
function object has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype.cleanupSome, 'length', {
|
||||
verifyProperty(FinalizationRegistry.prototype.cleanupSome, 'length', {
|
||||
value: 0,
|
||||
writable: false,
|
||||
enumerable: false,
|
|
@ -2,10 +2,10 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
description: FinalizationGroup.prototype.register.name property descriptor
|
||||
esid: sec-finalization-registry.prototype.cleanupSome
|
||||
description: FinalizationRegistry.prototype.cleanupSome.name property descriptor
|
||||
info: |
|
||||
FinalizationGroup.prototype.register.name value and property descriptor
|
||||
FinalizationRegistry.prototype.cleanupSome.name value and property descriptor
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
|
@ -20,12 +20,12 @@ info: |
|
|||
object, if it exists, has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype.register, 'name', {
|
||||
value: 'register',
|
||||
enumerable: false,
|
||||
verifyProperty(FinalizationRegistry.prototype.cleanupSome, 'name', {
|
||||
value: 'cleanupSome',
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
62
test/built-ins/FinalizationRegistry/prototype/cleanupSome/poisoned-callback-throws.js
vendored
Normal file
62
test/built-ins/FinalizationRegistry/prototype/cleanupSome/poisoned-callback-throws.js
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.cleanupSome
|
||||
description: Return abrupt completion from CleanupFinalizationRegistry
|
||||
info: |
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ? CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
6. Return undefined.
|
||||
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
4. If callback is undefined, set callback to finalizationRegistry.[[CleanupCallback]].
|
||||
5. Set finalizationRegistry.[[IsFinalizationRegistryCleanupJobActive]] to true.
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
7. Set finalizationRegistry.[[IsFinalizationRegistryCleanupJobActive]] to false.
|
||||
8. If result is an abrupt completion, return result.
|
||||
features: [FinalizationRegistry, arrow-function, async-functions, async-iteration, class, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var called = 0;
|
||||
var iterator = false;
|
||||
|
||||
function poisoned(iter) {
|
||||
called += 1;
|
||||
iterator = iter;
|
||||
iter.next(); // Won't throw
|
||||
throw new Test262Error();
|
||||
}
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
finalizationRegistry.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells().then(function() {
|
||||
assert.throws(Test262Error, function() {
|
||||
finalizationRegistry.cleanupSome(poisoned);
|
||||
});
|
||||
|
||||
assert.sameValue(called, 1);
|
||||
|
||||
assert.sameValue(typeof iterator, 'object');
|
||||
assert.sameValue(typeof iterator.next, 'function');
|
||||
assert.throws(TypeError, function() {
|
||||
iterator.next();
|
||||
}, 'iterator.next throws a TypeError if IsFinalizationRegistryCleanupJobActive is false');
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -2,9 +2,9 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.unregister
|
||||
esid: sec-finalization-registry.prototype.cleanupSome
|
||||
description: >
|
||||
Property descriptor of FinalizationGroup.prototype.unregister
|
||||
Property descriptor of FinalizationRegistry.prototype.cleanupSome
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
|
||||
|
@ -12,12 +12,12 @@ info: |
|
|||
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.unregister, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.cleanupSome, 'function');
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype, 'unregister', {
|
||||
verifyProperty(FinalizationRegistry.prototype, 'cleanupSome', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
84
test/built-ins/FinalizationRegistry/prototype/cleanupSome/return-undefined-with-gc.js
vendored
Normal file
84
test/built-ins/FinalizationRegistry/prototype/cleanupSome/return-undefined-with-gc.js
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.cleanupSome
|
||||
description: Return undefined regardless the result of CleanupFinalizationRegistry
|
||||
info: |
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ? CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
6. Return undefined.
|
||||
features: [FinalizationRegistry, arrow-function, async-functions, async-iteration, class, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var called;
|
||||
var fn = function() {
|
||||
called += 1;
|
||||
return 39;
|
||||
};
|
||||
var cb = function() {
|
||||
called += 1;
|
||||
return 42;
|
||||
};
|
||||
var finalizationRegistry = new FinalizationRegistry(fn);
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
finalizationRegistry.register(target);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
var tests = [];
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
called = 0;
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(cb), undefined, 'regular callback');
|
||||
assert.sameValue(called, 1);
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
called = 0;
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(fn), undefined, 'regular callback, same FG cleanup function');
|
||||
assert.sameValue(called, 1);
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
called = 0;
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(), undefined, 'undefined (implicit) callback, defer to FB callback');
|
||||
assert.sameValue(called, 1);
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
called = 0;
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(undefined), undefined, 'undefined (explicit) callback, defer to FB callback');
|
||||
assert.sameValue(called, 1);
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(() => 1), undefined, 'arrow function');
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(async function() {}), undefined, 'async function');
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(function *() {}), undefined, 'generator');
|
||||
}));
|
||||
|
||||
tests.push(emptyCells().then(function() {
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(async function *() {}), undefined, 'async generator');
|
||||
}));
|
||||
|
||||
Promise.all(tests).then(() => { $DONE(); }, resolveAsyncGC);
|
41
test/built-ins/FinalizationRegistry/prototype/cleanupSome/return-undefined.js
vendored
Normal file
41
test/built-ins/FinalizationRegistry/prototype/cleanupSome/return-undefined.js
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.cleanupSome
|
||||
description: Return undefined regardless the result of CleanupFinalizationRegistry
|
||||
info: |
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
5. Perform ? CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
6. Return undefined.
|
||||
features: [FinalizationRegistry, arrow-function, async-functions, async-iteration, class]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var cb = function() {};
|
||||
var poisoned = function() { throw new Test262Error(); };
|
||||
var finalizationRegistry = new FinalizationRegistry(fn);
|
||||
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(cb), undefined, 'regular callback');
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(fn), undefined, 'regular callback, same FG cleanup function');
|
||||
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(() => {}), undefined, 'arrow function');
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(finalizationRegistry.cleanupSome), undefined, 'cleanupSome itself');
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(poisoned), undefined, 'poisoned');
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(class {}), undefined, 'class expression');
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(async function() {}), undefined, 'async function');
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(function *() {}), undefined, 'generator');
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(async function *() {}), undefined, 'async generator');
|
||||
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(), undefined, 'undefined, implicit');
|
||||
assert.sameValue(finalizationRegistry.cleanupSome(undefined), undefined, 'undefined, explicit');
|
||||
|
||||
var poisonedFg = new FinalizationRegistry(poisoned);
|
||||
|
||||
assert.sameValue(poisonedFg.cleanupSome(cb), undefined, 'regular callback on poisoned FG cleanup callback');
|
||||
assert.sameValue(poisonedFg.cleanupSome(poisoned), undefined, 'poisoned callback on poisoned FG cleanup callback');
|
|
@ -2,22 +2,22 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.cleanupSome
|
||||
esid: sec-finalization-registry.prototype.cleanupSome
|
||||
description: Throws a TypeError if this does not have a [[Cells]] internal slot
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
...
|
||||
features: [WeakSet, WeakMap, FinalizationGroup, WeakRef]
|
||||
features: [WeakSet, WeakMap, FinalizationRegistry, WeakRef]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.cleanupSome, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.cleanupSome, 'function');
|
||||
|
||||
var cleanupSome = FinalizationGroup.prototype.cleanupSome;
|
||||
var cleanupSome = FinalizationRegistry.prototype.cleanupSome;
|
||||
var cb = function() {};
|
||||
|
||||
assert.throws(TypeError, function() {
|
|
@ -2,22 +2,22 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.cleanupSome
|
||||
esid: sec-finalization-registry.prototype.cleanupSome
|
||||
description: Throws a TypeError if this is not an Object
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
|
||||
...
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.cleanupSome, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.cleanupSome, 'function');
|
||||
|
||||
var cleanupSome = FinalizationGroup.prototype.cleanupSome;
|
||||
var cleanupSome = FinalizationRegistry.prototype.cleanupSome;
|
||||
var cb = function() {};
|
||||
|
||||
assert.throws(TypeError, function() {
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.constructor
|
||||
description: FinalizationRegistry.prototype.constructor property descriptor
|
||||
info: |
|
||||
FinalizationRegistry.prototype.constructor
|
||||
|
||||
The initial value of FinalizationRegistry.prototype.constructor is the intrinsic
|
||||
object %FinalizationRegistry%.
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationRegistry.prototype, 'constructor', {
|
||||
value: FinalizationRegistry,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
|
@ -2,16 +2,16 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: The property descriptor FinalizationGroup.prototype
|
||||
esid: sec-finalization-group.prototype
|
||||
description: The property descriptor FinalizationRegistry.prototype
|
||||
esid: sec-finalization-registry.prototype
|
||||
info: |
|
||||
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||
[[Configurable]]: false }.
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup, 'prototype', {
|
||||
verifyProperty(FinalizationRegistry, 'prototype', {
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: false
|
|
@ -2,13 +2,13 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: The prototype of FinalizationGroup.prototype is Object.prototype
|
||||
esid: sec-properties-of-the-finalization-group-prototype-object
|
||||
description: The prototype of FinalizationRegistry.prototype is Object.prototype
|
||||
esid: sec-properties-of-the-finalization-registry-prototype-object
|
||||
info: |
|
||||
The value of the [[Prototype]] internal slot of the FinalizationGroup prototype object
|
||||
The value of the [[Prototype]] internal slot of the FinalizationRegistry prototype object
|
||||
is the intrinsic object %ObjectPrototype%.
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var proto = Object.getPrototypeOf(FinalizationGroup.prototype);
|
||||
var proto = Object.getPrototypeOf(FinalizationRegistry.prototype);
|
||||
assert.sameValue(proto, Object.prototype);
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: Return undefined (applying custom this)
|
||||
info: |
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
7. Append cell to finalizationRegistry.[[Cells]].
|
||||
8. Return undefined.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var register = FinalizationRegistry.prototype.register;
|
||||
var finalizationRegistry = new FinalizationRegistry(fn);
|
||||
|
||||
var target = {};
|
||||
assert.sameValue(register.call(finalizationRegistry, target), undefined);
|
35
test/built-ins/FinalizationRegistry/prototype/register/holdings-any-value-type.js
vendored
Normal file
35
test/built-ins/FinalizationRegistry/prototype/register/holdings-any-value-type.js
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: No restriction for the value or type of holdings
|
||||
info: |
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
7. Append cell to finalizationRegistry.[[Cells]].
|
||||
8. Return undefined.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var finalizationRegistry = new FinalizationRegistry(fn);
|
||||
|
||||
var target = {};
|
||||
assert.sameValue(finalizationRegistry.register(target, undefined), undefined, 'undefined');
|
||||
assert.sameValue(finalizationRegistry.register(target, null), undefined, 'null');
|
||||
assert.sameValue(finalizationRegistry.register(target, false), undefined, 'false');
|
||||
assert.sameValue(finalizationRegistry.register(target, true), undefined, 'true');
|
||||
assert.sameValue(finalizationRegistry.register(target, Symbol()), undefined, 'symbol');
|
||||
assert.sameValue(finalizationRegistry.register(target, {}), undefined, 'object');
|
||||
assert.sameValue(finalizationRegistry.register(target, finalizationRegistry), undefined, 'same as finalizationRegistry instance');
|
||||
assert.sameValue(finalizationRegistry.register(target, 1), undefined, 'number');
|
||||
assert.sameValue(finalizationRegistry.register(target, 'holdings'), undefined, 'string');
|
21
test/built-ins/FinalizationRegistry/prototype/register/holdings-same-as-target.js
vendored
Normal file
21
test/built-ins/FinalizationRegistry/prototype/register/holdings-same-as-target.js
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: holdings may be the same as target
|
||||
info: |
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(target) is not Object, throw a TypeError exception.
|
||||
5. If SameValue(target, holdings), throw a TypeError exception.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
var target = {};
|
||||
assert.throws(TypeError, () => finalizationRegistry.register(target, target));
|
|
@ -2,10 +2,10 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
description: FinalizationGroup.prototype.register.length property descriptor
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: FinalizationRegistry.prototype.register.length property descriptor
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
|
@ -21,10 +21,10 @@ info: |
|
|||
function object has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype.register, 'length', {
|
||||
verifyProperty(FinalizationRegistry.prototype.register, 'length', {
|
||||
value: 2,
|
||||
enumerable: false,
|
||||
writable: false,
|
|
@ -2,10 +2,10 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.cleanupSome
|
||||
description: FinalizationGroup.prototype.cleanupSome.name property descriptor
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: FinalizationRegistry.prototype.register.name property descriptor
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome.name value and property descriptor
|
||||
FinalizationRegistry.prototype.register.name value and property descriptor
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
|
@ -20,12 +20,12 @@ info: |
|
|||
object, if it exists, has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype.cleanupSome, 'name', {
|
||||
value: 'cleanupSome',
|
||||
writable: false,
|
||||
verifyProperty(FinalizationRegistry.prototype.register, 'name', {
|
||||
value: 'register',
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
configurable: true
|
||||
});
|
|
@ -2,9 +2,9 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.cleanupSome
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: >
|
||||
Property descriptor of FinalizationGroup.prototype.cleanupSome
|
||||
Property descriptor of FinalizationRegistry.prototype.register
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
|
||||
|
@ -12,12 +12,12 @@ info: |
|
|||
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.cleanupSome, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.register, 'function');
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype, 'cleanupSome', {
|
||||
verifyProperty(FinalizationRegistry.prototype, 'register', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
30
test/built-ins/FinalizationRegistry/prototype/register/return-undefined-register-itself.js
vendored
Normal file
30
test/built-ins/FinalizationRegistry/prototype/register/return-undefined-register-itself.js
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: Return undefined after registering itself
|
||||
info: |
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(target) is not Object, throw a TypeError exception.
|
||||
5. If SameValue(target, holdings), throw a TypeError exception.
|
||||
6. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
7. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
8. Append cell to finalizationRegistry.[[Cells]].
|
||||
9. Return undefined.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var finalizationRegistry = new FinalizationRegistry(fn);
|
||||
var holdings = {};
|
||||
|
||||
assert.sameValue(finalizationRegistry.register(finalizationRegistry), undefined, 'Register itself');
|
||||
assert.sameValue(finalizationRegistry.register(finalizationRegistry, holdings), undefined, 'Register itself with holdings');
|
||||
assert.sameValue(finalizationRegistry.register(finalizationRegistry, holdings, finalizationRegistry), undefined, 'Register itself with holdings and unregisterToken');
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: Return undefined after registering
|
||||
info: |
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
7. Append cell to finalizationRegistry.[[Cells]].
|
||||
8. Return undefined.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var finalizationRegistry = new FinalizationRegistry(fn);
|
||||
|
||||
var target = {};
|
||||
assert.sameValue(finalizationRegistry.register(target), undefined, 'Register a targer');
|
||||
assert.sameValue(finalizationRegistry.register(target), undefined, 'Register the same target again');
|
||||
assert.sameValue(finalizationRegistry.register(target), undefined, 'Register the same target again and again');
|
||||
|
||||
assert.sameValue(finalizationRegistry.register({}), undefined, 'Register other targets');
|
||||
|
||||
assert.sameValue(finalizationRegistry.register(target, undefined, {}), undefined, 'Register target with unregisterToken');
|
||||
assert.sameValue(
|
||||
finalizationRegistry.register(target, undefined, target),
|
||||
undefined,
|
||||
'Register target with unregisterToken being the registered target'
|
||||
);
|
||||
|
||||
assert.sameValue(finalizationRegistry.register(target, undefined, undefined), undefined, 'Register target with explicit undefined unregisterToken');
|
||||
|
||||
assert.sameValue(finalizationRegistry.register(fn), undefined, 'register the cleanup callback fn');
|
|
@ -2,51 +2,51 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: Throws a TypeError if target is not an Object
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
...
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.register, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.register, 'function');
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register(undefined);
|
||||
finalizationRegistry.register(undefined);
|
||||
}, 'undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register(null);
|
||||
finalizationRegistry.register(null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register(true);
|
||||
finalizationRegistry.register(true);
|
||||
}, 'true');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register(false);
|
||||
finalizationRegistry.register(false);
|
||||
}, 'false');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register(1);
|
||||
finalizationRegistry.register(1);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register('object');
|
||||
finalizationRegistry.register('object');
|
||||
}, 'string');
|
||||
|
||||
var s = Symbol();
|
||||
assert.throws(TypeError, function() {
|
||||
fg.register(s);
|
||||
finalizationRegistry.register(s);
|
||||
}, 'symbol');
|
|
@ -2,22 +2,22 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: Throws a TypeError if this does not have a [[Cells]] internal slot
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
...
|
||||
features: [WeakSet, WeakMap, FinalizationGroup, WeakRef]
|
||||
features: [WeakSet, WeakMap, FinalizationRegistry, WeakRef]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.register, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.register, 'function');
|
||||
|
||||
var register = FinalizationGroup.prototype.register;
|
||||
var register = FinalizationRegistry.prototype.register;
|
||||
var target = {};
|
||||
|
||||
assert.throws(TypeError, function() {
|
|
@ -2,24 +2,24 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: Throws a TypeError if this is not an Object
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
...
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.register, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.register, 'function');
|
||||
|
||||
var register = FinalizationGroup.prototype.register;
|
||||
var register = FinalizationRegistry.prototype.register;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
register.call(undefined, {});
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: Throws a TypeError if unregisterToken is not an Object or undefined
|
||||
info: |
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
...
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.register, 'function');
|
||||
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
var target = {};
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.register(target, undefined, null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.register(target, undefined, true);
|
||||
}, 'true');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.register(target, undefined, false);
|
||||
}, 'false');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.register(target, undefined, 1);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.register(target, undefined, 'object');
|
||||
}, 'string');
|
||||
|
||||
var s = Symbol();
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.register(target, undefined, s);
|
||||
}, 'symbol');
|
|
@ -2,26 +2,26 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: unregisterToken may be the same as holdings and target
|
||||
info: |
|
||||
FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(target) is not Object, throw a TypeError exception.
|
||||
5. If SameValue(target, holdings), throw a TypeError exception.
|
||||
6. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
7. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
8. Append cell to finalizationGroup.[[Cells]].
|
||||
8. Append cell to finalizationRegistry.[[Cells]].
|
||||
9. Return undefined.
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
var target = {};
|
||||
assert.throws(TypeError, () => fg.register(target, target, target));
|
||||
assert.throws(TypeError, () => finalizationRegistry.register(target, target, target));
|
27
test/built-ins/FinalizationRegistry/prototype/register/unregisterToken-same-as-holdings.js
vendored
Normal file
27
test/built-ins/FinalizationRegistry/prototype/register/unregisterToken-same-as-holdings.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: unregisterToken may be the same as holdings
|
||||
info: |
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
7. Append cell to finalizationRegistry.[[Cells]].
|
||||
8. Return undefined.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
var target = {};
|
||||
var holdings = {};
|
||||
assert.sameValue(finalizationRegistry.register(target, holdings, holdings), undefined);
|
26
test/built-ins/FinalizationRegistry/prototype/register/unregisterToken-same-as-target.js
vendored
Normal file
26
test/built-ins/FinalizationRegistry/prototype/register/unregisterToken-same-as-target.js
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.register
|
||||
description: unregisterToken may be the same as target
|
||||
info: |
|
||||
FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If Type(target) is not Object, throw a TypeError exception.
|
||||
4. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
5. If Type(unregisterToken) is not Object,
|
||||
a. If unregisterToken is not undefined, throw a TypeError exception.
|
||||
b. Set unregisterToken to empty.
|
||||
6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }.
|
||||
7. Append cell to finalizationRegistry.[[Cells]].
|
||||
8. Return undefined.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
var target = {};
|
||||
assert.sameValue(finalizationRegistry.register(target, '1', target), undefined);
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.unregister
|
||||
description: Return values applying custom this
|
||||
info: |
|
||||
FinalizationRegistry.prototype.unregister ( unregisterToken )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(unregisterToken) is not Object, throw a TypeError exception.
|
||||
5. Let removed be false.
|
||||
6. For each Record { [[Target]], [[Holdings]], [[UnregisterToken]] } cell that is an element of finalizationRegistry.[[Cells]], do
|
||||
a. If SameValue(cell.[[UnregisterToken]], unregisterToken) is true, then
|
||||
i. Remove cell from finalizationRegistry.[[Cells]].
|
||||
ii. Set removed to true.
|
||||
7. Return removed.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var unregister = FinalizationRegistry.prototype.unregister;
|
||||
var finalizationRegistry = new FinalizationRegistry(fn);
|
||||
|
||||
var target1 = {};
|
||||
var target2 = {};
|
||||
var target3 = {};
|
||||
var token1 = {};
|
||||
var token2 = {};
|
||||
|
||||
assert.sameValue(unregister.call(finalizationRegistry, token1), false, 'unregistering token1 from empty finalizationRegistry');
|
||||
assert.sameValue(unregister.call(finalizationRegistry, token2), false, 'unregistering token2 from empty finalizationRegistry');
|
||||
|
||||
finalizationRegistry.register(target1, undefined, token1);
|
||||
finalizationRegistry.register(target2, undefined, token2);
|
||||
finalizationRegistry.register(target3, undefined, token2);
|
||||
|
||||
assert.sameValue(unregister.call(finalizationRegistry, target1), false, 'own target does not work on unregister, #1');
|
||||
assert.sameValue(unregister.call(finalizationRegistry, target2), false, 'own target does not work on unregister, #2');
|
||||
assert.sameValue(unregister.call(finalizationRegistry, target3), false, 'own target does not work on unregister, #3');
|
||||
|
||||
assert.sameValue(unregister.call(finalizationRegistry, token1), true, 'unregistering token1 from finalizationRegistry');
|
||||
assert.sameValue(unregister.call(finalizationRegistry, token1), false, 'unregistering token1 again from finalizationRegistry');
|
||||
assert.sameValue(unregister.call(finalizationRegistry, token2), true, 'unregistering token2 to remove target2 and target3');
|
||||
assert.sameValue(unregister.call(finalizationRegistry, token2), false, 'unregistering token2 from empty finalizationRegistry');
|
|
@ -2,10 +2,10 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.unregister
|
||||
description: FinalizationGroup.prototype.unregister.length property descriptor
|
||||
esid: sec-finalization-registry.prototype.unregister
|
||||
description: FinalizationRegistry.prototype.unregister.length property descriptor
|
||||
info: |
|
||||
FinalizationGroup.prototype.unregister ( unregisterToken )
|
||||
FinalizationRegistry.prototype.unregister ( unregisterToken )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
|
@ -21,10 +21,10 @@ info: |
|
|||
function object has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype.unregister, 'length', {
|
||||
verifyProperty(FinalizationRegistry.prototype.unregister, 'length', {
|
||||
value: 1,
|
||||
writable: false,
|
||||
enumerable: false,
|
|
@ -2,10 +2,10 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.unregister
|
||||
description: FinalizationGroup.prototype.unregister.name property descriptor
|
||||
esid: sec-finalization-registry.prototype.unregister
|
||||
description: FinalizationRegistry.prototype.unregister.name property descriptor
|
||||
info: |
|
||||
FinalizationGroup.prototype.unregister.name value and property descriptor
|
||||
FinalizationRegistry.prototype.unregister.name value and property descriptor
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
|
@ -20,10 +20,10 @@ info: |
|
|||
object, if it exists, has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype.unregister, 'name', {
|
||||
verifyProperty(FinalizationRegistry.prototype.unregister, 'name', {
|
||||
value: 'unregister',
|
||||
writable: false,
|
||||
enumerable: false,
|
|
@ -2,9 +2,9 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.register
|
||||
esid: sec-finalization-registry.prototype.unregister
|
||||
description: >
|
||||
Property descriptor of FinalizationGroup.prototype.register
|
||||
Property descriptor of FinalizationRegistry.prototype.unregister
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
|
||||
|
@ -12,12 +12,12 @@ info: |
|
|||
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.register, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.unregister, 'function');
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype, 'register', {
|
||||
verifyProperty(FinalizationRegistry.prototype, 'unregister', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
|
@ -2,22 +2,22 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.unregister
|
||||
esid: sec-finalization-registry.prototype.unregister
|
||||
description: Throws a TypeError if this does not have a [[Cells]] internal slot
|
||||
info: |
|
||||
FinalizationGroup.prototype.unregister ( unregisterToken )
|
||||
FinalizationRegistry.prototype.unregister ( unregisterToken )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(unregisterToken) is not Object, throw a TypeError exception.
|
||||
...
|
||||
features: [WeakSet, WeakMap, FinalizationGroup, WeakRef]
|
||||
features: [WeakSet, WeakMap, FinalizationRegistry, WeakRef]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.unregister, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.unregister, 'function');
|
||||
|
||||
var unregister = FinalizationGroup.prototype.unregister;
|
||||
var unregister = FinalizationRegistry.prototype.unregister;
|
||||
var token = {};
|
||||
|
||||
assert.throws(TypeError, function() {
|
|
@ -2,22 +2,22 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.unregister
|
||||
esid: sec-finalization-registry.prototype.unregister
|
||||
description: Throws a TypeError if this is not an Object
|
||||
info: |
|
||||
FinalizationGroup.prototype.unregister ( unregisterToken )
|
||||
FinalizationRegistry.prototype.unregister ( unregisterToken )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
||||
3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(unregisterToken) is not Object, throw a TypeError exception.
|
||||
...
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.unregister, 'function');
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.unregister, 'function');
|
||||
|
||||
var unregister = FinalizationGroup.prototype.unregister;
|
||||
var unregister = FinalizationRegistry.prototype.unregister;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
unregister.call(undefined, {});
|
|
@ -2,52 +2,52 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group.prototype.unregister
|
||||
esid: sec-finalization-registry.prototype.unregister
|
||||
description: Cannot unregister a cell that has been cleaned up
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
1. Let finalizationGroup be the this value.
|
||||
1. Let finalizationRegistry be the this value.
|
||||
...
|
||||
5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback).
|
||||
5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback).
|
||||
...
|
||||
|
||||
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
|
||||
CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] )
|
||||
|
||||
...
|
||||
3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup).
|
||||
3. Let iterator be ! CreateFinalizationRegistryCleanupIterator(finalizationRegistry).
|
||||
...
|
||||
6. Let result be Call(callback, undefined, « iterator »).
|
||||
...
|
||||
|
||||
%FinalizationGroupCleanupIteratorPrototype%.next ( )
|
||||
%FinalizationRegistryCleanupIteratorPrototype%.next ( )
|
||||
|
||||
8. If finalizationGroup.[[Cells]] contains a Record cell such that cell.[[Target]] is empty,
|
||||
8. If finalizationRegistry.[[Cells]] contains a Record cell such that cell.[[Target]] is empty,
|
||||
a. Choose any such cell.
|
||||
b. Remove cell from finalizationGroup.[[Cells]].
|
||||
b. Remove cell from finalizationRegistry.[[Cells]].
|
||||
c. Return CreateIterResultObject(cell.[[Holdings]], false).
|
||||
9. Otherwise, return CreateIterResultObject(undefined, true).
|
||||
|
||||
FinalizationGroup.prototype.unregister ( unregisterToken )
|
||||
FinalizationRegistry.prototype.unregister ( unregisterToken )
|
||||
|
||||
1. Let removed be false.
|
||||
2. For each Record { [[Target]], [[Holdings]], [[UnregisterToken]] } cell that is an element of finalizationGroup.[[Cells]], do
|
||||
2. For each Record { [[Target]], [[Holdings]], [[UnregisterToken]] } cell that is an element of finalizationRegistry.[[Cells]], do
|
||||
a. If SameValue(cell.[[UnregisterToken]], unregisterToken) is true, then
|
||||
i. Remove cell from finalizationGroup.[[Cells]].
|
||||
i. Remove cell from finalizationRegistry.[[Cells]].
|
||||
ii. Set removed to true.
|
||||
3. Return removed.
|
||||
features: [FinalizationGroup, host-gc-required]
|
||||
features: [FinalizationRegistry, host-gc-required]
|
||||
includes: [async-gc.js]
|
||||
flags: [async, non-deterministic]
|
||||
---*/
|
||||
|
||||
var value = 'target!';
|
||||
var token = {};
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
fg.register(target, value, token);
|
||||
finalizationRegistry.register(target, value, token);
|
||||
|
||||
var prom = asyncGC(target);
|
||||
target = null;
|
||||
|
@ -58,7 +58,7 @@ function emptyCells() {
|
|||
emptyCells().then(function() {
|
||||
var called = 0;
|
||||
var holdings;
|
||||
fg.cleanupSome(function cb(iterator) {
|
||||
finalizationRegistry.cleanupSome(function cb(iterator) {
|
||||
called += 1;
|
||||
holdings = [...iterator];
|
||||
});
|
||||
|
@ -67,6 +67,6 @@ emptyCells().then(function() {
|
|||
assert.sameValue(holdings.length, 1);
|
||||
assert.sameValue(holdings[0], value);
|
||||
|
||||
var res = fg.unregister(token);
|
||||
var res = finalizationRegistry.unregister(token);
|
||||
assert.sameValue(res, false, 'unregister after iterating over it in cleanup');
|
||||
}).then($DONE, resolveAsyncGC);
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.unregister
|
||||
description: Return boolean values indicating unregistering of values from given token
|
||||
info: |
|
||||
FinalizationRegistry.prototype.unregister ( unregisterToken )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(unregisterToken) is not Object, throw a TypeError exception.
|
||||
5. Let removed be false.
|
||||
6. For each Record { [[Target]], [[Holdings]], [[UnregisterToken]] } cell that is an element of finalizationRegistry.[[Cells]], do
|
||||
a. If SameValue(cell.[[UnregisterToken]], unregisterToken) is true, then
|
||||
i. Remove cell from finalizationRegistry.[[Cells]].
|
||||
ii. Set removed to true.
|
||||
7. Return removed.
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var finalizationRegistry = new FinalizationRegistry(fn);
|
||||
|
||||
var target1 = {};
|
||||
var target2 = {};
|
||||
var target3 = {};
|
||||
var token1 = {};
|
||||
var token2 = {};
|
||||
|
||||
assert.sameValue(finalizationRegistry.unregister(token1), false, 'unregistering token1 from empty finalizationRegistry');
|
||||
assert.sameValue(finalizationRegistry.unregister(token2), false, 'unregistering token2 from empty finalizationRegistry');
|
||||
|
||||
finalizationRegistry.register(target1, undefined, token1);
|
||||
finalizationRegistry.register(target1, undefined, token1); // Repeat registering un purpose
|
||||
finalizationRegistry.register(target2, undefined, token2);
|
||||
finalizationRegistry.register(target3, undefined, token2);
|
||||
|
||||
assert.sameValue(finalizationRegistry.unregister(target1), false, 'own target does not work on unregister, #1');
|
||||
assert.sameValue(finalizationRegistry.unregister(target2), false, 'own target does not work on unregister, #2');
|
||||
assert.sameValue(finalizationRegistry.unregister(target3), false, 'own target does not work on unregister, #3');
|
||||
|
||||
assert.sameValue(finalizationRegistry.unregister(token1), true, 'unregistering token1 from finalizationRegistry');
|
||||
assert.sameValue(finalizationRegistry.unregister(token1), false, 'unregistering token1 again from finalizationRegistry');
|
||||
assert.sameValue(finalizationRegistry.unregister(token2), true, 'unregistering token2 to remove target2 and target3');
|
||||
assert.sameValue(finalizationRegistry.unregister(token2), false, 'unregistering token2 from empty finalizationRegistry');
|
||||
|
||||
// Notice these assertions take advantage of adding targets previously added with a token,
|
||||
// but now they got no token so it won't be used to remove them.
|
||||
finalizationRegistry.register(target1, token1); // holdings, not unregisterToken
|
||||
finalizationRegistry.register(target2, token2); // holdings, not unregisterToken
|
||||
finalizationRegistry.register(target3);
|
||||
|
||||
assert.sameValue(finalizationRegistry.unregister(token1), false, 'nothing to remove without a set unregisterToken #1');
|
||||
assert.sameValue(finalizationRegistry.unregister(token2), false, 'nothing to remove without a set unregisterToken #2');
|
49
test/built-ins/FinalizationRegistry/prototype/unregister/unregisterToken-not-object-throws.js
vendored
Normal file
49
test/built-ins/FinalizationRegistry/prototype/unregister/unregisterToken-not-object-throws.js
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry.prototype.unregister
|
||||
description: Throws a TypeError if unregisterToken is not an Object
|
||||
info: |
|
||||
FinalizationRegistry.prototype.unregister ( unregisterToken )
|
||||
|
||||
1. Let finalizationRegistry be the this value.
|
||||
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
|
||||
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
|
||||
4. If Type(unregisterToken) is not Object, throw a TypeError exception.
|
||||
...
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationRegistry.prototype.unregister, 'function');
|
||||
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.unregister(undefined);
|
||||
}, 'undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.unregister(null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.unregister(true);
|
||||
}, 'true');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.unregister(false);
|
||||
}, 'false');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.unregister(1);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.unregister('object');
|
||||
}, 'string');
|
||||
|
||||
var s = Symbol();
|
||||
assert.throws(TypeError, function() {
|
||||
finalizationRegistry.unregister(s);
|
||||
}, 'symbol');
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-registry-target
|
||||
description: >
|
||||
Returns a new ordinary object from the FinalizationRegistry constructor
|
||||
info: |
|
||||
FinalizationRegistry ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationRegistry be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationRegistryPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationRegistryCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationRegistry.
|
||||
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
features: [FinalizationRegistry, for-of]
|
||||
---*/
|
||||
|
||||
var cleanupCallback = function() {};
|
||||
var finalizationRegistry = new FinalizationRegistry(cleanupCallback);
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), FinalizationRegistry.prototype);
|
||||
assert.notSameValue(finalizationRegistry, cleanupCallback, 'does not return the same function');
|
||||
assert.sameValue(finalizationRegistry instanceof FinalizationRegistry, true, 'instanceof');
|
||||
|
||||
for (let key of Object.getOwnPropertyNames(finalizationRegistry)) {
|
||||
assert(false, `should not set any own named properties: ${key}`);
|
||||
}
|
||||
|
||||
for (let key of Object.getOwnPropertySymbols(finalizationRegistry)) {
|
||||
assert(false, `should not set any own symbol properties: ${String(key)}`);
|
||||
}
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), FinalizationRegistry.prototype);
|
|
@ -2,68 +2,68 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
esid: sec-finalization-registry-target
|
||||
description: >
|
||||
Throws a TypeError if target is not callable
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
FinalizationRegistry ( cleanupCallback )
|
||||
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
2. If IsCallable(cleanupCallback) is false, throw a TypeError exception.
|
||||
...
|
||||
features: [FinalizationGroup, WeakRef]
|
||||
features: [FinalizationRegistry, WeakRef]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof FinalizationGroup, 'function',
|
||||
'typeof FinalizationGroup is function'
|
||||
typeof FinalizationRegistry, 'function',
|
||||
'typeof FinalizationRegistry is function'
|
||||
);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new FinalizationGroup({});
|
||||
new FinalizationRegistry({});
|
||||
}, 'ordinary object');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new FinalizationGroup(WeakRef.prototype);
|
||||
new FinalizationRegistry(WeakRef.prototype);
|
||||
}, 'WeakRef.prototype');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new FinalizationGroup(FinalizationGroup.prototype);
|
||||
}, 'FinalizationGroup.prototype');
|
||||
new FinalizationRegistry(FinalizationRegistry.prototype);
|
||||
}, 'FinalizationRegistry.prototype');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new FinalizationGroup([]);
|
||||
new FinalizationRegistry([]);
|
||||
}, 'Array');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new FinalizationGroup();
|
||||
new FinalizationRegistry();
|
||||
}, 'implicit undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new FinalizationGroup(undefined);
|
||||
new FinalizationRegistry(undefined);
|
||||
}, 'explicit undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new FinalizationGroup(null);
|
||||
new FinalizationRegistry(null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new FinalizationGroup(1);
|
||||
new FinalizationRegistry(1);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new FinalizationGroup('Object');
|
||||
new FinalizationRegistry('Object');
|
||||
}, 'string');
|
||||
|
||||
var s = Symbol();
|
||||
assert.throws(TypeError, function() {
|
||||
new FinalizationGroup(s);
|
||||
new FinalizationRegistry(s);
|
||||
}, 'symbol');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new FinalizationGroup(true);
|
||||
new FinalizationRegistry(true);
|
||||
}, 'Boolean, true');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new FinalizationGroup(false);
|
||||
new FinalizationRegistry(false);
|
||||
}, 'Boolean, false');
|
|
@ -2,27 +2,27 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-finalization-group-target
|
||||
esid: sec-finalization-registry-target
|
||||
description: >
|
||||
Throws a TypeError if NewTarget is undefined.
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
FinalizationRegistry ( cleanupCallback )
|
||||
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
2. If IsCallable(cleanupCallback) is false, throw a TypeError exception.
|
||||
...
|
||||
features: [FinalizationGroup]
|
||||
features: [FinalizationRegistry]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof FinalizationGroup, 'function',
|
||||
'typeof FinalizationGroup is function'
|
||||
typeof FinalizationRegistry, 'function',
|
||||
'typeof FinalizationRegistry is function'
|
||||
);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
FinalizationGroup();
|
||||
FinalizationRegistry();
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
FinalizationGroup(function() {});
|
||||
FinalizationRegistry(function() {});
|
||||
});
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue