From 60448391a229947db7a0dbed69160e7c61fad212 Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Wed, 23 Jun 2021 22:21:13 -0700 Subject: [PATCH] Editorial: use abstract closures in Await (#2439) --- spec.html | 64 +++++++++++++++---------------------------------------- 1 file changed, 17 insertions(+), 47 deletions(-) diff --git a/spec.html b/spec.html index 211ae611267..feb8bec6b78 100644 --- a/spec.html +++ b/spec.html @@ -3548,7 +3548,7 @@

The Completion Record Specification Type

The term “abrupt completion” refers to any completion with a [[Type]] value other than ~normal~.

- +

Await

Algorithm steps that say

@@ -3562,14 +3562,22 @@

Await

1. Let _asyncContext_ be the running execution context. 1. Let _promise_ be ? PromiseResolve(%Promise%, _value_). - 1. Let _stepsFulfilled_ be the algorithm steps defined in . - 1. Let _lengthFulfilled_ be the number of non-optional parameters of the function definition in . - 1. Let _onFulfilled_ be ! CreateBuiltinFunction(_stepsFulfilled_, _lengthFulfilled_, *""*, « [[AsyncContext]] »). - 1. Set _onFulfilled_.[[AsyncContext]] to _asyncContext_. - 1. Let _stepsRejected_ be the algorithm steps defined in . - 1. Let _lengthRejected_ be the number of non-optional parameters of the function definition in . - 1. Let _onRejected_ be ! CreateBuiltinFunction(_stepsRejected_, _lengthRejected_, *""*, « [[AsyncContext]] »). - 1. Set _onRejected_.[[AsyncContext]] to _asyncContext_. + 1. Let _fulfilledClosure_ be a new Abstract Closure with parameters (_value_) that captures _asyncContext_ and performs the following steps when called: + 1. Let _prevContext_ be the running execution context. + 1. Suspend _prevContext_. + 1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context. + 1. Resume the suspended evaluation of _asyncContext_ using NormalCompletion(_value_) as the result of the operation that suspended it. + 1. Assert: When we reach this step, _asyncContext_ has already been removed from the execution context stack and _prevContext_ is the currently running execution context. + 1. Return *undefined*. + 1. Let _onFulfilled_ be ! CreateBuiltinFunction(_fulfilledClosure_, 1, *""*, « »). + 1. Let _rejectedClosure_ be a new Abstract Closure with parameters (_reason_) that captures _asyncContext_ and performs the following steps when called: + 1. Let _prevContext_ be the running execution context. + 1. Suspend _prevContext_. + 1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context. + 1. Resume the suspended evaluation of _asyncContext_ using ThrowCompletion(_reason_) as the result of the operation that suspended it. + 1. Assert: When we reach this step, _asyncContext_ has already been removed from the execution context stack and _prevContext_ is the currently running execution context. + 1. Return *undefined*. + 1. Let _onRejected_ be ! CreateBuiltinFunction(_rejectedClosure_, 1, *""*, « »). 1. Perform ! PerformPromiseThen(_promise_, _onFulfilled_, _onRejected_). 1. Remove _asyncContext_ from the execution context stack and restore the execution context that is at the top of the execution context stack as the running execution context. 1. Set the code evaluation state of _asyncContext_ such that when evaluation is resumed with a Completion _completion_, the following steps of the algorithm that invoked Await will be performed, with _completion_ available. @@ -3593,44 +3601,6 @@

Await

1. ReturnIfAbrupt(_result_).
- - -

Await Fulfilled Functions

-

An Await fulfilled function is an anonymous built-in function that is used as part of the Await specification device to deliver the promise fulfillment value to the caller as a normal completion. Each Await fulfilled function has an [[AsyncContext]] internal slot.

-

When an Await fulfilled function is called with argument _value_, the following steps are taken:

- - - 1. Let _F_ be the active function object. - 1. Let _asyncContext_ be _F_.[[AsyncContext]]. - 1. Let _prevContext_ be the running execution context. - 1. Suspend _prevContext_. - 1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context. - 1. Resume the suspended evaluation of _asyncContext_ using NormalCompletion(_value_) as the result of the operation that suspended it. - 1. Assert: When we reach this step, _asyncContext_ has already been removed from the execution context stack and _prevContext_ is the currently running execution context. - 1. Return *undefined*. - - -

The *"length"* property of an Await fulfilled function is *1*𝔽.

-
- - -

Await Rejected Functions

-

An Await rejected function is an anonymous built-in function that is used as part of the Await specification device to deliver the promise rejection reason to the caller as an abrupt throw completion. Each Await rejected function has an [[AsyncContext]] internal slot.

-

When an Await rejected function is called with argument _reason_, the following steps are taken:

- - - 1. Let _F_ be the active function object. - 1. Let _asyncContext_ be _F_.[[AsyncContext]]. - 1. Let _prevContext_ be the running execution context. - 1. Suspend _prevContext_. - 1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context. - 1. Resume the suspended evaluation of _asyncContext_ using ThrowCompletion(_reason_) as the result of the operation that suspended it. - 1. Assert: When we reach this step, _asyncContext_ has already been removed from the execution context stack and _prevContext_ is the currently running execution context. - 1. Return *undefined*. - - -

The *"length"* property of an Await rejected function is *1*𝔽.

-