26.2 FinalizationRegistry Objects
A
26.2.1 The FinalizationRegistry Constructor
The FinalizationRegistry
- is %FinalizationRegistry%.
-
is the initial value of the
"FinalizationRegistry" property of theglobal object . -
creates and initializes a new FinalizationRegistry object when called as a
constructor . - is not intended to be called as a function and will throw an exception when called in that manner.
-
is designed to be subclassable. It may be used as the value in an
extends
clause of a class definition. Subclass constructors that intend to inherit the specifiedFinalizationRegistry
behaviour must include asuper
call to theFinalizationRegistry
constructor to create and initialize the subclass instance with the internal state necessary to support theFinalizationRegistry.prototype
built-in methods.
26.2.1.1 FinalizationRegistry ( cleanupCallback )
When the FinalizationRegistry
function is called with argument cleanupCallback, the following steps are taken:
- If NewTarget is
undefined , throw aTypeError exception. - If
IsCallable (cleanupCallback) isfalse , throw aTypeError exception. - Let finalizationRegistry be ?
OrdinaryCreateFromConstructor (NewTarget,"%FinalizationRegistry.prototype%" , « [[Realm]], [[CleanupCallback]], [[Cells]] »). - Let fn be the
active function object . - Set finalizationRegistry.[[Realm]] to fn.[[Realm]].
- Set finalizationRegistry.[[CleanupCallback]] to cleanupCallback.
- Set finalizationRegistry.[[Cells]] to a new empty
List . - Return finalizationRegistry.
26.2.2 Properties of the FinalizationRegistry Constructor
The
-
has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
26.2.2.1 FinalizationRegistry.prototype
The initial value of FinalizationRegistry.prototype
is the
This property has the attributes { [[Writable]]:
26.2.3 Properties of the FinalizationRegistry Prototype Object
The FinalizationRegistry prototype object:
- is %FinalizationRegistry.prototype%.
-
has a [[Prototype]] internal slot whose value is
%Object.prototype% . - is an
ordinary object . - does not have [[Cells]] and [[CleanupCallback]] internal slots.
26.2.3.1 FinalizationRegistry.prototype.constructor
The initial value of FinalizationRegistry.prototype.constructor
is
26.2.3.2 FinalizationRegistry.prototype.register ( target, heldValue [ , unregisterToken ] )
The following steps are taken:
- Let finalizationRegistry be the
this value. - Perform ?
RequireInternalSlot (finalizationRegistry, [[Cells]]). - If
Type (target) is not Object, throw aTypeError exception. - If
SameValue (target, heldValue) istrue , throw aTypeError exception. - If
Type (unregisterToken) is not Object, then- If unregisterToken is not
undefined , throw aTypeError exception. - Set unregisterToken to
empty .
- If unregisterToken is not
- Let cell be the
Record { [[WeakRefTarget]]: target, [[HeldValue]]: heldValue, [[UnregisterToken]]: unregisterToken }. - Append cell to finalizationRegistry.[[Cells]].
- Return
undefined .
Based on the algorithms and definitions in this specification, cell.[[HeldValue]] is
26.2.3.3 FinalizationRegistry.prototype.unregister ( unregisterToken )
The following steps are taken:
- Let finalizationRegistry be the
this value. - Perform ?
RequireInternalSlot (finalizationRegistry, [[Cells]]). - If
Type (unregisterToken) is not Object, throw aTypeError exception. - Let removed be
false . - For each
Record { [[WeakRefTarget]], [[HeldValue]], [[UnregisterToken]] } cell of finalizationRegistry.[[Cells]], do- If cell.[[UnregisterToken]] is not
empty andSameValue (cell.[[UnregisterToken]], unregisterToken) istrue , then- Remove cell from finalizationRegistry.[[Cells]].
- Set removed to
true .
- If cell.[[UnregisterToken]] is not
- Return removed.
26.2.3.4 FinalizationRegistry.prototype [ @@toStringTag ]
The initial value of the
This property has the attributes { [[Writable]]: