Skip to content

Commit 48430f5

Browse files
committed
Slight refactor of the suspend operation
Make it clear that a 'long jump' in the meta-interpreter is being affected.
1 parent 8de2a62 commit 48430f5

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

‎document/js-api/index.bs

+32-26
Original file line numberDiff line numberDiff line change
@@ -1425,36 +1425,41 @@ interface Suspending {
14251425
The algorithm to <dfn>run a Promising function</dfn> from the JavaScript object |wasmFunc| and a [=list=] of [=WebAssembly values=] |arguments| consists of the following steps:
14261426
1. Let |promise| be a new [=PromiseCapabilityRecord=].
14271427
1. Let |funcaddr| be the value of |wasmFunc|'s \[[FunctionAddress]] internal slot.
1428-
1. Let |runner| be a new [=AbstractClosure=] with no arguments that captures |promise|, |funcaddr|, and |arguments| that performs the following steps when called:
1429-
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1430-
1. Let |functype| be [=func_type=](|store|, |funcaddr|).
1431-
1. Let |args| be the result of [=coerce JavaScript arguments|coercing arguments=] (|functype|,|arguments|)
1432-
1. Let |map| be the [=surrounding agent=]'s associated [=Execution Context Status map=].
1433-
1. Let |ec| be the currently executing [=execution context=], i.e., the [=execution context=] that is at the top of the [=surrounding agent=]'s current [=execution context stack=].
1434-
1. Assert: |map| does not contain any entry for |ec|.
1435-
1. Add an entry mapping |ec| to [=active=] in |map|.
1436-
1. Let (|store|, |result|) be the result of [=func_invoke=](|store|, |funcaddr|, |args|).
1437-
1. Assert: if control reaches here, we have done waiting for suspended imports
1438-
1. If the entry for |ec| in |map| is not [=active=] then trap. Otherwise, remove the entry for |ec| from [=map=].
1439-
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
1440-
1. If |result| is [=error=], throw an exception. This exception should be a WebAssembly {{RuntimeError}} exception, unless otherwise indicated by <a href="#errors">the WebAssembly error mapping</a>.
1441-
1. Otherwise, if |result| is of the form [=throw=] exnaddr,
1442-
1. Perform [=EvaluateCall=] (|promise|.\[[Reject]],|result|.,false).
1443-
1. Otherwise, assert |result| is a [=list=] of WebAssembly values
1444-
1. Let |outArity| be the [=list/size=] of |result|.
1445-
1. If |outArity| is 0, return undefined.
1446-
1. Otherwise, if |outArity| is 1, let |jsReturnValue| be [=ToJSValue=](|result|[0]).
1447-
1. Otherwise,
1448-
1. Let |values| be « ».
1449-
1. [=list/iterate|For each=] |r| of |result|,
1450-
1. [=list/Append=] [=ToJSValue=](|r|) to |values|.
1451-
1. let |jsReturnValue| be [$CreateArrayFromList$](|values|).
1452-
1. Perform [=EvaluateCall=] (|promise|.\[[Resolve]],|jsReturnValue|,false)
1428+
1. Let |runner| be a new [=AbstractClosure=] with no arguments that captures |promise|, |funcaddr|, and |arguments| that performs [=evaluate a Promising function=](|promise|,|funcaddr|,|arguments|)
14531429
1. Let |con| be [=CreateBuiltinFunction=](|runner|,0,"",<<>>)
14541430
1. Perform [$Call$](|con|, undefined, <<>>)
14551431
1. Returns |promise|
14561432
</div>
14571433

1434+
<div algorithm>
1435+
The algorithm to <dfn>evaluate a Promising function</dfn>(|promise|, |funcaddr|, |arguments|) consists of the following steps:
1436+
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1437+
1. Let |functype| be [=func_type=](|store|, |funcaddr|).
1438+
1. Let |args| be the result of [=coerce JavaScript arguments|coercing arguments=] (|functype|,|arguments|)
1439+
1. Let |map| be the [=surrounding agent=]'s associated [=Execution Context Status map=].
1440+
1. Let |ec| be the currently executing [=execution context=], i.e., the [=execution context=] that is at the top of the [=surrounding agent=]'s current [=execution context stack=].
1441+
1. Assert: |map| does not contain any entry for |ec|.
1442+
1. Add an entry mapping |ec| to [=active=] in |map|.
1443+
1. Let (|store|, |result|) be the result of [=func_invoke=](|store|, |funcaddr|, |args|).
1444+
1. Assert: if control reaches here, we have done waiting for suspended imports
1445+
1. If the entry for |ec| in |map| is not [=active=] then trap. Otherwise, remove the entry for |ec| from [=map=].
1446+
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
1447+
1. If |result| is [=error=], throw an exception. This exception should be a WebAssembly {{RuntimeError}} exception, unless otherwise indicated by <a href="#errors">the WebAssembly error mapping</a>.
1448+
1. Otherwise, if |result| is of the form [=throw=] exnaddr,
1449+
1. Perform [=EvaluateCall=] (|promise|.\[[Reject]],|result|.,false).
1450+
1. Otherwise, assert |result| is a [=list=] of WebAssembly values
1451+
1. Let |outArity| be the [=list/size=] of |result|.
1452+
1. If |outArity| is 0, return undefined.
1453+
1. Otherwise, if |outArity| is 1, let |jsReturnValue| be [=ToJSValue=](|result|[0]).
1454+
1. Otherwise,
1455+
1. Let |values| be « ».
1456+
1. [=list/iterate|For each=] |r| of |result|,
1457+
1. [=list/Append=] [=ToJSValue=](|r|) to |values|.
1458+
1. let |jsReturnValue| be [$CreateArrayFromList$](|values|).
1459+
1. Perform [=EvaluateCall=] (|promise|.\[[Resolve]],|jsReturnValue|,false)
1460+
1. Return undefined.
1461+
</div>
1462+
14581463
Note: The extra |$Call$| in the above algorithm ensures that the creation of the Promise is separated from the fullfilling of that Promise. In effect, this allows suspension of the fullfillment to occur whilst allowing the creation of the Promise itself to continue.
14591464

14601465
<div algorithm>
@@ -1499,7 +1504,8 @@ To <dfn>create a suspending function</dfn> from a JavaScript function |func|, wi
14991504
1. Let |rejected| be an [=AbstractClosure=] with parameters (|e|) that captures |async_context| and performs the following steps when called:
15001505
1. Perform the [=Reject=] procedure, passing it the captured continuation |k| the exception value |e| and |async_context|.
15011506
1. Let |onRejected| be [=CreateBuiltinFunction=](|rejected|,1,"",[])
1502-
1. Perform [$PerformPromiseThen$](|promise|, |onResolved|, |onRejected|).
1507+
1. Perform [$PerformPromiseThen$](|promise|, |onResolved|, |onRejected|).
1508+
1. Note: this terminates the innermost call to [=evaluate a Promising function=] algorithm. Control will return to the caller of that algorithm.
15031509
1. Return the result of performing [=coerce a JavaScript return=] on |results| and |ret|.
15041510
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
15051511
1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|).

0 commit comments

Comments
 (0)