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 when called as a
constructor . - is not intended to be called as a function and will throw an exception when called in that manner.
-
may be used as the value in an
extends
clause of a class definition. Subclassconstructors 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 )
This function performs the following steps when called:
- 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
HostMakeJobCallback (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 ] )
This method performs the following steps when called:
- Let finalizationRegistry be the
this value. - Perform ?
RequireInternalSlot (finalizationRegistry, [[Cells]]). - If
CanBeHeldWeakly (target) isfalse , throw aTypeError exception. - If
SameValue (target, heldValue) istrue , throw aTypeError exception. - If
CanBeHeldWeakly (unregisterToken) isfalse , 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 )
This method performs the following steps when called:
- Let finalizationRegistry be the
this value. - Perform ?
RequireInternalSlot (finalizationRegistry, [[Cells]]). - If
CanBeHeldWeakly (unregisterToken) isfalse , 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]]: