Skip to content

Commit

Permalink
Update index.bs
Browse files Browse the repository at this point in the history
Small changes, responding to remarks by reviewer.
  • Loading branch information
fgmccabe authored Oct 30, 2024
1 parent 9aac0fc commit d89f2f7
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions document/js-api/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
1. Let |funcaddr| be the value of |v|'s \[[FunctionAddress]] internal slot.
1. Otherwise,
1. [=Create a host function=] from |v| and |functype|, and let |funcaddr| be the result.
1. Otherwise, if |v| has a \[[WrappedFunction]] internal slot
1. Otherwise, if |v| has a \[[WrappedFunction]] internal slot,
1. Let |func| be the value of |v|'s \[[WrappedFunction]] internal slot.
1. Assert: [$IsCallable$](|func|) is true.
1. [=Create a suspending function|create a suspending function=] from |func| and |functype|, and let |funcaddr| be the result.
Expand All @@ -431,10 +431,6 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1. Let (|store|, |globaladdr|) be [=global_alloc=](|store|, [=const=] |valtype|, |value|).
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
1. Otherwise, if |v| [=implements=] {{Global}},
1. Let |globaladdr| be |v|.\[[Global]].
1. Otherwise,
1. Throw a {{LinkError}} exception.
1. Let |externglobal| be [=external value|global=] |globaladdr|.
1. [=list/Append=] |externglobal| to |imports|.
1. If |externtype| is of the form [=external-type/mem=] <var ignore>memtype</var>,
Expand Down Expand Up @@ -1155,8 +1151,7 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
<div algorithm>
To <dfn>coerce JavaScript arguments</dfn> from a |functype| and a [=list=] of JavaScript arguments |argValues|, perform the following steps
1. Let [|parameters|][|results|] be |functype|.
1. If |parameters| or |results| contain [=v128=], throw a {{TypeError}}.

1. If |parameters| or |results| contain [=v128=] or [=exnref=], throw a {{TypeError}}.
Note: the above error is thrown each time the \[[Call]] method is invoked.
1. Let |args| be « ».
1. Let |i| be 0.
Expand All @@ -1172,7 +1167,7 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
To <dfn>call an Exported Function</dfn> with [=function address=] |funcaddr| and a [=list=] of JavaScript arguments |argValues|, perform the following steps:
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1. Let |functype| be [=func_type=](|store|, |funcaddr|).
1. Let |args| be the result of [=coerce JavaScript arguments|coercing arguments=] (|functype|,|argValues|)
1. Let |args| be the result of [=coerce JavaScript arguments|coercing arguments=] (|functype|,|argValues|).
1. Let (|store|, |ret|) be the result of [=func_invoke=](|store|, |funcaddr|, |args|).
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
1. If |ret| 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>.
Expand All @@ -1199,14 +1194,6 @@ Note: [=call an Exported Function|Calling an Exported Function=] executes in the

Note: Exported Functions do not have a \[[Construct]] method and thus it is not possible to call one with the `new` operator.

<div algorithm>
To <dfn>run a host function</dfn> from the JavaScript object |func|, type |functype|, and [=list=] of [=WebAssembly values=] |arguments|, perform the following steps:
1. Let [|parameters|][|resultTypes|] be |functype|.
1. Let |jsArguments| be the result of [=coerce WebAssembly arguments=](|parameters|,|arguments|)
1. Let |ret| be [=?=] [$Call$](|func|, undefined, |jsArguments|).
1. Return the result of performing [=coerce a JavaScript return=] on |resultTypes| and |ret|.
</div>

<div algorithm>
To <dfn>coerce WebAssembly arguments</dfn> from a [=list=] of |parameterTypes| and a [=list=] of JavaScript arguments |arguments|, perform the following steps
1. If |parameterTypes| contain [=v128=], throw a {{TypeError}}.
Expand Down Expand Up @@ -1240,7 +1227,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
1. Otherwise,
1. Let |type| be the [=JavaScript exception tag=].
1. Let |payload| be « ».
1. Let |opaqueData| be [=ToWebAssemblyValue=](|v|, [=externref=])
1. Let |opaqueData| be [=ToWebAssemblyValue=](|v|, [=externref=]).
1. Return the triple |type|, |payload| and |opaqueData|.
</div>

Expand All @@ -1254,11 +1241,15 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
1. Let |relevant settings| be |realm|'s [=realm/settings object=].
1. [=Prepare to run script=] with |relevant settings|.
1. [=Prepare to run a callback=] with |stored settings|.
1. Let |result| be the result of [=run a host function|running a host function=] from |func|, |functype|, and |arguments|.
1. Let [|parameters|][|resultTypes|] be |functype|.
1. Let |jsArguments| be the result of [=coerce WebAssembly arguments=](|parameters|,|arguments|)
1. Let |result| be the result of Completion([$Call$](|func|, undefined, |jsArguments|)).
1. [=Clean up after running a callback=] with |stored settings|.
1. [=Clean up after running script=] with |relevant settings|.
1. Assert: |result|.\[[Type]] is <emu-const>throw</emu-const> or <emu-const>normal</emu-const>.
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1. If |result|.\[[Type]] is <emu-const>normal</emu-const>, then:
1. Return the result of performing [=coerce a JavaScript return=] on |resultTypes| and |ret|.
1. If |result|.\[[Type]] is <emu-const>throw</emu-const>, then:
1. Let |v| be |result|.\[[Value]].
1. If |v| [=implements=] {{Exception}},
Expand All @@ -1269,7 +1260,6 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
1. Let (|store|, |address|) be [=exn_alloc=](|store|, |type|, « |payload| »).
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
1. Execute the WebAssembly instructions ([=ref.exn=] |address|) ([=throw_ref=]).
1. Otherwise, return |result|.\[[Value]].
1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|).
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
1. Return |funcaddr|.
Expand Down Expand Up @@ -1425,9 +1415,10 @@ interface Suspending {
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:
1. Let |promise| be a new [=PromiseCapabilityRecord=].
1. Let |funcaddr| be the value of |wasmFunc|'s \[[FunctionAddress]] internal slot.
1. Let |runner| be a new [=AbstractClosure=] with no parameters that captures |promise|, |funcaddr|, and |arguments| and performs [=evaluate a Promising function=](|promise|,|funcaddr|,|arguments|) when called.
1. Perform [=?=][$AsyncFunctionStart$](|promise|,|runner|)
1. Returns |promise|
1. Let |runner| be a new [=AbstractClosure=] with no parameters that captures |promise|, |funcaddr|, and |arguments| and performs the following steps when called:
1. Perform [=evaluate a Promising function=](|promise|,|funcaddr|,|arguments|).
1. Perform [=?=][$AsyncFunctionStart$](|promise|,|runner|).
1. Return |promise|.
</div>

<div algorithm>
Expand All @@ -1443,10 +1434,9 @@ interface Suspending {
1. Assert: If control reaches here, we have done waiting for suspended imports.
1. If the entry for |ec| in |map| is not [=active=] then trap. Otherwise, remove the entry for |ec| from [=map=].
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
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>.
1. If |result| is [=error=], throw an exception. This exception must be a WebAssembly {{RuntimeError}} exception, unless otherwise indicated by <a href="#errors">the WebAssembly error mapping</a>.
1. Otherwise, if |result| is of the form [=throw=] exnaddr,
1. Perform [$Call$] (|promise|.\[[Reject]],|result|.,false).
1. Note: The result of the above call is ignored.
1. [=Reject=] |promise| with |result|.
1. Otherwise,
1. Assert: |result| is a [=list=] of WebAssembly values
1. Let |outArity| be the [=list/size=] of |result|.
Expand All @@ -1457,18 +1447,16 @@ interface Suspending {
1. [=list/iterate|For each=] |r| of |result|,
1. [=list/Append=] [=ToJSValue=](|r|) to |values|.
1. Let |jsReturnValue| be [$CreateArrayFromList$](|values|).
1. Perform [$Call$] (|promise|.\[[Resolve]],|jsReturnValue|,false)
1. [=Resolve=] |promise| with |jsReturnValue|.
1. Return UNUSED.
</div>

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.

<div algorithm>
The <dfn constructor for="Suspending">Suspending(|jsFun|)</dfn> constructor, when invoked, performs the following steps:
1. If [$IsCallable$](|jsFun|) is false, throw a {{TypeError}}.
1. Let |suspendingProto| be \[[%WebAssembly.Suspending.prototype%]].
1. Let |susp| be the result of [$OrdinaryObjectCreate$](|suspendingProto|,«\[[WrappedFunction]]»).
1. Assign the \[[WrappedFunction]] internal slot of |susp| to |jsFun|.
1. Set |susp|.\[[WrappedFunction]] to |jsFun|.
1. Return |susp|.
</div>

Expand Down Expand Up @@ -1498,7 +1486,7 @@ To <dfn>create a suspending function</dfn> from a JavaScript function |func|, wi
1. Let |promise| be |ret|.\[[Value]][0].
1. Set the entry for |async_context| in |map| to [=paused=].
1. Let |awaitResult| be the result of performing [$Completion$]([$Await$](|promise|)).
1. Note: That we only invoke [$Await$] if the call to |func| has returned a Promise object.
1. Note: We only invoke [$Await$] if the call to |func| has returned a Promise object.
1. Note: This will suspend both this algorithm, and the WebAssembly function being invoked by the [=evaluate a Promising function=] algorithm. On return, |ret| will be either a normal completion or a throw completion.
1. If the entry for |async_context| in |map| is not [=paused=] then trap, otherwise, set the entry to [=active=].
1. If |awaitResult|.\[[Type]] is <emu-const>throw</emu-const>, then:
Expand Down

0 comments on commit d89f2f7

Please sign in to comment.