From 283fff0ef513dacd401d28dcac9767333edc8438 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Tue, 5 Mar 2024 21:10:25 -0500 Subject: [PATCH] Use creation-time context --- spec.html | 68 ++++++++++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 43 deletions(-) diff --git a/spec.html b/spec.html index 95d055d..e6f0d09 100644 --- a/spec.html +++ b/spec.html @@ -144,7 +144,7 @@

1. Choose any such _cell_. 1. Remove _cell_ from _finalizationRegistry_.[[Cells]]. 1. Perform ? HostCallJobCallback(_callback_, *undefined*, « _cell_.[[HeldValue]] »). - 1. Let _previousContextMapping_ be AsyncContextSwap(_cell_.[[AsyncContextSnapshot]]). + 1. Let _previousContextMapping_ be AsyncContextSwap(_finalizationRegistry_.[[FinalizationRegistryAsyncContextSnapshot]]). 1. Let _result_ be Completion(HostCallJobCallback(_callback_, *undefined*, « _cell_.[[HeldValue]] »)). 1. AsyncContextSwap(_previousContextMapping_). 1. Perform ? _result_. @@ -1208,56 +1208,38 @@

Managing Memory

FinalizationRegistry Objects

A FinalizationRegistry is an object that manages registration and unregistration of cleanup operations that are performed when target objects and symbols are garbage collected.

- -

Properties of the FinalizationRegistry Prototype Object

-

The FinalizationRegistry prototype object:

+ +

The FinalizationRegistry Constructor

+

The FinalizationRegistry constructor:

    -
  • is %FinalizationRegistry.prototype%.
  • +
  • is %FinalizationRegistry%.
  • - has a [[Prototype]] internal slot whose value is %Object.prototype%. + is the initial value of the *"FinalizationRegistry"* property of the global 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.
  • -
  • is an ordinary object.
  • - does not have [[Cells]] and [[CleanupCallback]] internal slots. + may be used as the value in an `extends` clause of a class definition. Subclass constructors that intend to inherit the specified `FinalizationRegistry` behaviour must include a `super` call to the `FinalizationRegistry` constructor to create and initialize the subclass instance with the internal state necessary to support the `FinalizationRegistry.prototype` built-in methods.
- -

FinalizationRegistry.prototype.register ( _target_, _heldValue_ [ , _unregisterToken_ ] )

-

This method performs the following steps when called:

- - 1. Let _finalizationRegistry_ be the *this* value. - 1. Perform ? RequireInternalSlot(_finalizationRegistry_, [[Cells]]). - 1. If CanBeHeldWeakly(_target_) is *false*, throw a *TypeError* exception. - 1. If SameValue(_target_, _heldValue_) is *true*, throw a *TypeError* exception. - 1. If CanBeHeldWeakly(_unregisterToken_) is *false*, then - 1. If _unregisterToken_ is not *undefined*, throw a *TypeError* exception. - 1. Set _unregisterToken_ to ~empty~. - 1. Let _cell_ be the Record { [[WeakRefTarget]]: _target_, [[HeldValue]]: _heldValue_, [[UnregisterToken]]: _unregisterToken_ }. - 1. Let _snapshot_ be AsyncContextSnapshot(). - 1. Let _cell_ be the Record { [[WeakRefTarget]]: _target_, [[HeldValue]]: _heldValue_, [[UnregisterToken]]: _unregisterToken_, [[AsyncContextSnapshot]]: _snapshot_ }. - 1. Append _cell_ to _finalizationRegistry_.[[Cells]]. - 1. Return *undefined*. - - - -

Based on the algorithms and definitions in this specification, _cell_.[[HeldValue]] is live when _finalizationRegistry_.[[Cells]] contains _cell_; however, this does not necessarily mean that _cell_.[[UnregisterToken]] or _cell_.[[Target]] are live. For example, registering an object with itself as its unregister token would not keep the object alive forever.

-
-
- - -

FinalizationRegistry.prototype.unregister ( _unregisterToken_ )

-

This method performs the following steps when called:

+ +

FinalizationRegistry ( _cleanupCallback_ )

+

This function performs the following steps when called:

- 1. Let _finalizationRegistry_ be the *this* value. - 1. Perform ? RequireInternalSlot(_finalizationRegistry_, [[Cells]]). - 1. If CanBeHeldWeakly(_unregisterToken_) is *false*, throw a *TypeError* exception. - 1. Let _removed_ be *false*. - 1. For each Record { [[WeakRefTarget]], [[HeldValue]], [[UnregisterToken]], [[AsyncContextSnapshot]] } _cell_ of _finalizationRegistry_.[[Cells]], do - 1. If _cell_.[[UnregisterToken]] is not ~empty~ and SameValue(_cell_.[[UnregisterToken]], _unregisterToken_) is *true*, then - 1. Remove _cell_ from _finalizationRegistry_.[[Cells]]. - 1. Set _removed_ to *true*. - 1. Return _removed_. + 1. If NewTarget is *undefined*, throw a *TypeError* exception. + 1. If IsCallable(_cleanupCallback_) is *false*, throw a *TypeError* exception. + 1. Let _finalizationRegistry_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%FinalizationRegistry.prototype%"*, « [[Realm]], [[CleanupCallback]], [[Cells]], [[FinalizationRegistryAsyncContextSnapshot]] »). + 1. Let _fn_ be the active function object. + 1. Set _finalizationRegistry_.[[Realm]] to _fn_.[[Realm]]. + 1. Set _finalizationRegistry_.[[CleanupCallback]] to HostMakeJobCallback(_cleanupCallback_). + 1. Set _finalizationRegistry_.[[Cells]] to a new empty List. + 1. Set _finalizationRegistry_.[[FinalizationRegistryAsyncContextSnapshot]] to AsyncContextSnapshot(). + 1. Return _finalizationRegistry_.