Skip to content

Commit 233339e

Browse files
authored
Modified AsyncBlockStart to accept Abstract Closure (#26)
1 parent 5f1344a commit 233339e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

spec.html

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,55 @@ <h1>Introduction</h1>
1919
explainer</a> for the proposal's background, motivation, and usage examples.</p>
2020
</emu-intro>
2121

22+
<emu-clause id="sec-control-abstraction-objects">
23+
<h1>Control Abstraction Objects</h1>
24+
<emu-clause id="sec-async-function-objects">
25+
<h1>AsyncFunction Objects</h1>
26+
<emu-clause id="sec-async-functions-abstract-operations">
27+
<h1>Async Functions Abstract Operations</h1>
28+
<emu-clause id="sec-asyncblockstart" type="abstract operation">
29+
<h1>
30+
AsyncBlockStart (
31+
_promiseCapability_: a PromiseCapability Record,
32+
_asyncBody_: a Parse Node <ins>or an Abstract Closure with no parameters</ins>,
33+
_asyncContext_: an execution context,
34+
)
35+
</h1>
36+
<dl class="header">
37+
</dl>
38+
<emu-alg>
39+
1. Assert: _promiseCapability_ is a PromiseCapability Record.
40+
1. Let _runningContext_ be the running execution context.
41+
1. [fence-effects="user-code"] Set the code evaluation state of _asyncContext_ such that when evaluation is resumed for that execution context the following steps will be performed:
42+
1. <ins> If _asyncBody_ is a Parse Node, then</ins>
43+
1. <ins> Let _result_ be the result of evaluating _asyncBody_.</ins>
44+
1. <ins> Else, </ins>
45+
1. <ins> Assert: _asyncBody_ is an Abstract Closure with no parameters.</ins>
46+
1. <ins> Let _result_ be _asyncBody_().</ins>
47+
1. <del>Let _result_ be the result of evaluating _asyncBody_. </del>
48+
1. Assert: If we return here, the async function either threw an exception or performed an implicit or explicit return; all awaiting is done.
49+
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.
50+
1. If _result_.[[Type]] is ~normal~, then
51+
1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, &laquo; *undefined* &raquo;).
52+
1. Else if _result_.[[Type]] is ~return~, then
53+
1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, &laquo; _result_.[[Value]] &raquo;).
54+
1. Else,
55+
1. Assert: _result_.[[Type]] is ~throw~.
56+
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, &laquo; _result_.[[Value]] &raquo;).
57+
1. [id="step-asyncblockstart-return-undefined"] Return.
58+
1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context.
59+
1. <emu-meta effects="user-code">Resume the suspended evaluation of _asyncContext_</emu-meta>. Let _result_ be the value returned by the resumed computation.
60+
1. Assert: When we return here, _asyncContext_ has already been removed from the execution context stack and _runningContext_ is the currently running execution context.
61+
1. Assert: _result_ is a normal completion with a value of *undefined*. The possible sources of completion values are Await or, if the async function doesn't await anything, step <emu-xref href="#step-asyncblockstart-return-undefined"></emu-xref> above.
62+
1. Return.
63+
</emu-alg>
64+
</emu-clause>
65+
</emu-clause>
66+
</emu-clause>
67+
68+
</emu-clause>
69+
70+
2271
<emu-clause id="sec-indexed-collections">
2372
<h1>Indexed Collections</h1>
2473

0 commit comments

Comments
 (0)