You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>This proposal adds a new field to the JobCallback Record as the following table:</p>
138
-
<emu-tableid="table-jobcallback-records"caption="JobCallback Record Fields">
139
-
<table>
140
-
<tr>
141
-
<th>
142
-
Field Name
143
-
</th>
144
-
<th>
145
-
Value
146
-
</th>
147
-
<th>
148
-
Meaning
149
-
</th>
150
-
</tr>
151
-
<tr>
152
-
<td>
153
-
[[Callback]]
154
-
</td>
155
-
<td>
156
-
a function object
157
-
</td>
158
-
<td>
159
-
The function to invoke when the Job is invoked.
160
-
</td>
161
-
</tr>
162
-
<tr>
163
-
<td>
164
-
<ins>[[AsyncContextSnapshot]]</ins>
165
-
</td>
166
-
<td>
167
-
<ins>a List of Async Context Mapping Records</ins>
168
-
</td>
169
-
<td>
170
-
<ins>A map from the AsyncContext.Variable instances to the saved ECMAScript language value. Every Record in the List contains a unique [[AsyncContextKey]].</ins>
<p>An implementation of HostMakeJobCallback must conform to the following requirements:</p>
197
-
<ul>
198
-
<li>It must return a JobCallback Record whose [[Callback]] field is _callback_,</li>
199
-
<li><ins>It must return a JobCallback Record whose [[AsyncContextSnapshot]] field is the result of performing AsyncContextSnapshot().</ins></li>
200
-
</ul>
201
-
<p>The default implementation of HostMakeJobCallback performs the following steps when called:</p>
202
-
<emu-alg>
203
-
1. <del>Return the JobCallback Record { [[Callback]]: _callback_, [[HostDefined]]: ~empty~ }.</del>
204
-
1. <ins>Let _snapshotMapping_ be AsyncContextSnapshot().</ins>
205
-
1. <ins>Return the JobCallback Record { [[Callback]]: _callback_, [[AsyncContextSnapshot]]: _snapshotMapping_, [[HostDefined]]: ~empty~ }.</ins>
206
-
</emu-alg>
207
-
<p>ECMAScript hosts that are not web browsers must use the default implementation of HostMakeJobCallback.</p>
208
-
<emu-note>
209
-
<p>HostMakeJobCallback snapshots the current AsyncContext global state. The snapshot is restored before calling HostCallJobCallback in NewPromiseReactionJob and NewPromiseResolveThenableJob.</p>
): either a normal completion containing ~unused~ or a throw completion
137
+
</h1>
138
+
<dlclass="header">
139
+
</dl>
140
+
<emu-alg>
141
+
1. <del>Assert: _finalizationRegistry_ has [[Cells]] and [[CleanupCallback]] internal slots.</del>
142
+
1. <ins>Assert: _finalizationRegistry_ has [[Cells]], [[CleanupCallback]], and [[FinalizationRegistryAsyncContextSnapshot]] internal slots.</ins>
143
+
1. Let _callback_ be _finalizationRegistry_.[[CleanupCallback]].
144
+
1. While _finalizationRegistry_.[[Cells]] contains a Record _cell_ such that _cell_.[[WeakRefTarget]] is ~empty~, an implementation may perform the following steps:
145
+
1. Choose any such _cell_.
146
+
1. Remove _cell_ from _finalizationRegistry_.[[Cells]].
<p>A <dfnvariants="PromiseReaction Records">PromiseReaction Record</dfn> is a Record value used to store information about how a promise should react when it becomes resolved or rejected with a given value. PromiseReaction Records are created by the PerformPromiseThen abstract operation, and are used by the Abstract Closure returned by NewPromiseReactionJob.</p>
221
+
<p>PromiseReaction Records have the fields listed in <emu-xrefhref="#table-promisereaction-record-fields"></emu-xref>.</p>
222
+
<emu-tableid="table-promisereaction-record-fields"caption="PromiseReaction Record Fields"oldids="table-58">
223
+
<table>
224
+
<tr>
225
+
<th>
226
+
Field Name
227
+
</th>
228
+
<th>
229
+
Value
230
+
</th>
231
+
<th>
232
+
Meaning
233
+
</th>
234
+
</tr>
235
+
<tr>
236
+
<td>
237
+
[[Capability]]
238
+
</td>
239
+
<td>
240
+
a PromiseCapability Record or *undefined*
241
+
</td>
242
+
<td>
243
+
The capabilities of the promise for which this record provides a reaction handler.
244
+
</td>
245
+
</tr>
246
+
<tr>
247
+
<td>
248
+
[[Type]]
249
+
</td>
250
+
<td>
251
+
~fulfill~ or ~reject~
252
+
</td>
253
+
<td>
254
+
The [[Type]] is used when [[Handler]] is ~empty~ to allow for behaviour specific to the settlement type.
255
+
</td>
256
+
</tr>
257
+
<tr>
258
+
<td>
259
+
[[Handler]]
260
+
</td>
261
+
<td>
262
+
a JobCallback Record or ~empty~
263
+
</td>
264
+
<td>
265
+
The function that should be applied to the incoming value, and whose return value will govern what happens to the derived promise. If [[Handler]] is ~empty~, a function that depends on the value of [[Type]] will be used instead.
266
+
</td>
267
+
</tr>
268
+
<tr>
269
+
<td>
270
+
<ins>[[PromiseAsyncContextSnapshot]]</ins>
271
+
</td>
272
+
<td>
273
+
<ins>a List of Async Context Mapping Records</ins>
274
+
</td>
275
+
<td>
276
+
<ins>A map from the AsyncContext.Variable instances to the saved ECMAScript language value. Every Record in the List contains a unique [[AsyncContextKey]].</ins>
1. Let _promiseCapability_ be _reaction_.[[Capability]].
322
329
1. Let _type_ be _reaction_.[[Type]].
323
330
1. Let _handler_ be _reaction_.[[Handler]].
324
-
1. <ins>Let _previousContextMapping_ be AsyncContextSwap(_handler_.[[AsyncContextSnapshot]]).</ins>
331
+
1. <ins>Let _previousContextMapping_ be AsyncContextSwap(_reaction_.[[PromiseAsyncContextSnapshot]]).</ins>
325
332
1. If _handler_ is ~empty~, then
326
333
1. If _type_ is ~fulfill~, then
327
334
1. let _handlerResult_ be NormalCompletion(_argument_).
@@ -364,9 +371,10 @@ <h1>
364
371
<dlclass="header">
365
372
</dl>
366
373
<emu-alg>
367
-
1. Let _job_ be a new Job Abstract Closure with no parameters that captures _promiseToResolve_, _thenable_, and _then_ and performs the following steps when called:
374
+
1. <ins>Let _snapshot_ be AsyncContextSnapshot().</ins>
375
+
1. Let _job_ be a new Job Abstract Closure with no parameters that captures _promiseToResolve_, _thenable_, _then_, <ins>and _snapshot_</ins> and performs the following steps when called:
368
376
1. Let _resolvingFunctions_ be CreateResolvingFunctions(_promiseToResolve_).
369
-
1. <ins>Let _previousContextMapping_ be AsyncContextSwap(_then_.[[AsyncContextSnapshot]]).</ins>
377
+
1. <ins>Let _previousContextMapping_ be AsyncContextSwap(_snapshot_).</ins>
370
378
1. Let _thenCallResult_ be Completion(HostCallJobCallback(_then_, _thenable_, « _resolvingFunctions_.[[Resolve]], _resolvingFunctions_.[[Reject]] »)).
371
379
1. If _thenCallResult_ is an abrupt completion, then
optional _resultCapability_: a PromiseCapability Record,
426
+
): an ECMAScript language value
427
+
</h1>
428
+
<dlclass="header">
429
+
<dt>description</dt>
430
+
<dd>It performs the “then” operation on _promise_ using _onFulfilled_ and _onRejected_ as its settlement actions. If _resultCapability_ is passed, the result is stored by updating _resultCapability_'s promise. If it is not passed, then PerformPromiseThen is being called by a specification-internal operation where the result does not matter.</dd>
431
+
</dl>
432
+
<emu-alg>
433
+
1.Assert: IsPromise(_promise_) is *true*.
434
+
1. If _resultCapability_ is not present, then
435
+
1. Set _resultCapability_ to *undefined*.
436
+
1. If IsCallable(_onFulfilled_) is *false*, then
437
+
1. Let _onFulfilledJobCallback_ be ~empty~.
438
+
1. Else,
439
+
1. Let _onFulfilledJobCallback_ be HostMakeJobCallback(_onFulfilled_).
440
+
1. If IsCallable(_onRejected_) is *false*, then
441
+
1. Let _onRejectedJobCallback_ be ~empty~.
442
+
1. Else,
443
+
1. Let _onRejectedJobCallback_ be HostMakeJobCallback(_onRejected_).
444
+
1. <ins>Let _snapshot_ be AsyncContextSnapshot().</ins>
445
+
1. Let _fulfillReaction_ be the PromiseReaction Record { [[Capability]]: _resultCapability_, [[Type]]: ~fulfill~, [[Handler]]: _onFulfilledJobCallback_, <ins>[[PromiseAsyncContextSnapshot]]: _snapshot_</ins> }.
446
+
1. Let _rejectReaction_ be the PromiseReaction Record { [[Capability]]: _resultCapability_, [[Type]]: ~reject~, [[Handler]]: _onRejectedJobCallback_, <ins>[[PromiseAsyncContextSnapshot]]: _snapshot_</ins>}.
447
+
1. If _promise_.[[PromiseState]] is ~pending~, then
448
+
1. Append _fulfillReaction_ to _promise_.[[PromiseFulfillReactions]].
449
+
1. Append _rejectReaction_ to _promise_.[[PromiseRejectReactions]].
450
+
1. Else if _promise_.[[PromiseState]] is ~fulfilled~, then
451
+
1. Let _value_ be _promise_.[[PromiseResult]].
452
+
1. Let _fulfillJob_ be NewPromiseReactionJob(_fulfillReaction_, _value_).
<p>A FinalizationRegistry is an object that manages registration and unregistration of cleanup operations that are performed when target objects and symbols are garbage collected.</p>
is the initial value of the *"FinalizationRegistry"* property of the global object.
1261
+
</li>
1262
+
<li>
1263
+
creates and initializes a new FinalizationRegistry when called as a constructor.
1264
+
</li>
1265
+
<li>
1266
+
is not intended to be called as a function and will throw an exception when called in that manner.
1267
+
</li>
1268
+
<li>
1269
+
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.
0 commit comments