A WeakRef is an object that is used to refer to a target object without preserving it from garbage collection. WeakRefs can dereference to allow access to the target object, if the target object hasn't been reclaimed by garbage collection.
The WeakRef constructor:
WeakRef
property of the extends
clause of a class definition. Subclass
constructors that intend to inherit the specified WeakRef
behaviour must include a super
call to the WeakRef
constructor
to create and initialize the subclass instance with the internal
state necessary to support the WeakRef.prototype
built-in
methods.
When the WeakRef
function is called with argument target,
the following steps are taken:
"%WeakRefPrototype%"
, « [[Target]] »).The WeakRef constructor:
The initial value of WeakRef.prototype
is the intrinsic
This property has the attributes { [[Writable]]:
WeakRef[@@species]
is an accessor property whose set
accessor function is
The value of the name
property of this function is "get [Symbol.species]"
.
Methods that create derived collection objects should call @@species to determine the constructor to use to create the derived objects. Subclass constructor may over-ride @@species to change the default constructor assignment.
The WeakRef prototype object:
The following steps are taken:
target = { foo: function() {} }; let weakRef = new WeakRef(target); ... later ... if (weakRef.deref()) { weakRef.deref().foo(); }In the above example, if the first deref evaluates to true then the second deref can not fail.
WeakRef instances are ordinary objects that inherit properties from the WeakRef prototype. WeakRef instances also have a [[Target]] internal slot.
A FinalizationGroup is an object that manages registeration and unregisteration of cleanup operations that are performed when target objects are garbage collected.
The FinalizationGroup constructor:
FinalizationGroup
property of
the extends
clause of a class definition. Subclass
constructors that intend to inherit the specified
FinalizationGroup
behaviour must include a super
call to
the FinalizationGroup
constructor to create and initialize
the subclass instance with the internal state necessary to
support the FinalizationGroup.prototype
built-in methods.
When the FinalizationGroup
function is called with argument cleanupCallback,
the following steps are taken:
"%FinalizationGroupPrototype%"
, « [[CleanupCallback]], [[Cells]] »).The FinalizationGroup constructor:
The initial value of FinalizationGroup.prototype
is the
intrinsic
This property has the attributes { [[Writable]]:
FinalizationGroup[@@species]
is an accessor property whose
set accessor function is
The value of the name
property of this function is "get [Symbol.species]"
.
Methods that create derived collection objects should call @@species to determine the constructor to use to create the derived objects. Subclass constructor may over-ride @@species to change the default constructor assignment.
The FinalizationGroup prototype object:
The initial value of
FinalizationGroup.prototype.constructor
is the intrinsic
object
The following steps are taken:
The following steps are taken:
The following steps are taken:
FinalizationGroup instances are ordinary objects that inherit properties from the FinalizationGroup prototype. FinalizationGroup instances also have [[Cells]] and [[CleanupCallback]] internal slot.
A FinalizationGroup Cleanup Iterator is an ordinary object, with the structure defined below, that represents a specific iteration over some specific FinalizationGroup instance object. There is not a named constructor for FinalizationGroup Cleanup Iterator objects. Instead, these iterator objects are created when the cleanupCallback of the FinalizationGroup is called.
The following steps are taken:
The %FinalizationGroupCleanupIteratorPrototyp% object:
The initial value of the @@toStringTag property is the String value "FinalizationGroup Cleanup Iterator"
.
This property has the attributes { [[Writable]]:
FinalizationGroup Cleanup Iterator instances are ordinary objects that inherit properties from the %FinalizationGroupCleanupIteratorPrototype% intrinsic object. FinalizationGroup Cleanup Iteratorinstances are initially created with a [[FinalizationGroup]] internal slot.
Field Name | Value | Meaning |
---|---|---|
[[LittleEndian]] | Boolean | The default value computed for the isLittleEndian parameter when it is needed by the algorithms |
[[CanBlock]] | Boolean | Determines whether the agent can block or not. |
[[Signifier]] | Any globally-unique value | Uniquely identifies the agent within its agent cluster. |
[[IsLockFree1]] | Boolean | |
[[IsLockFree2]] | Boolean | |
[[CandidateExecution]] | A candidate execution |
See the memory model. |
[[KeptAlive]] | Initially a new empty |
|
[[FinalizationGroups]] | Initially a new empty |
At any given time, if all references to a ECMAScript object are from a
[[Target]] field or internal slot, and
The following steps are performed:
"FinalizationJob"
, In HTML, DoAgentFinalization is called between Step 2 and 3 of the perform a microtask checkpoint algorithm.
In the ECMAScript specification, DoAgentFinalization is called as the last step of
A particular host environment will, in practice, only invoke DoAgentFinalization from one of these callsites. See tc39/ecma262#735 for more information.
The following steps are performed:
The following steps are performed: