Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js-api][web-api] Use the 'react' algorithm from WebIDL #1835

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions document/js-api/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,17 @@ The verification of WebAssembly type requirements is deferred to the
To <dfn>instantiate a promise of a module</dfn> |promiseOfModule| with imports |importObject|, perform the following steps:

1. Let |promise| be [=a new promise=].
1. [=Upon fulfillment=] of |promiseOfModule| with value |module|:
1. [=asynchronously instantiate a WebAssembly module|Instantiate the WebAssembly module=] |module| importing |importObject|, and let |innerPromise| be the result.
1. [=Upon fulfillment=] of |innerPromise| with value |instance|.
1. Let |result| be the {{WebAssemblyInstantiatedSource}} value «[ "{{WebAssemblyInstantiatedSource/module}}" → |module|, "{{WebAssemblyInstantiatedSource/instance}}" → |instance| ]».
1. [=Resolve=] |promise| with |result|.
1. [=Upon rejection=] of |innerPromise| with reason |reason|:
1. [=React=] to |promiseOfModule|:
* If |promiseOfModule| was fulfilled with value |module|:
1. [=asynchronously instantiate a WebAssembly module|Instantiate the WebAssembly module=] |module| importing |importObject|, and let |innerPromise| be the result.
1. [=React=] to |innerPromise|:
* If |innerPromise| was fulfilled with value |instance|.
1. Let |result| be the {{WebAssemblyInstantiatedSource}} value «[ "{{WebAssemblyInstantiatedSource/module}}" → |module|, "{{WebAssemblyInstantiatedSource/instance}}" → |instance| ]».
1. [=Resolve=] |promise| with |result|.
* If |innerPromise| was rejected with reason |reason|:
1. [=Reject=] |promise| with |reason|.
* If |promiseOfModule| was rejected with reason |reason|:
1. [=Reject=] |promise| with |reason|.
1. [=Upon rejection=] of |promiseOfModule| with reason |reason|:
1. [=Reject=] |promise| with |reason|.
1. Return |promise|.
</div>

Expand Down
48 changes: 25 additions & 23 deletions document/web-api/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,32 @@ Note: This algorithm accepts a {{Response}} object, or a
{{CompileError}} or other relevant error type, depending on the cause of failure.


1. Let |returnValue| be [=a new promise=]
1. [=Upon fulfillment=] of |source| with value |unwrappedSource|:
1. Let |response| be |unwrappedSource|'s [=Response/response=].
1. Let |mimeType| be the result of [=header list/getting=] `` `Content-Type` `` from |response|'s [=response/header list=].
1. If |mimeType| is null, reject |returnValue| with a {{TypeError}} and abort these substeps.
1. Remove all [=HTTP tab or space byte=] from the start and end of |mimeType|.
1. If |mimeType| is not a [=byte-case-insensitive=] match for `` `application/wasm` ``, reject |returnValue| with a {{TypeError}} and abort these substeps.

Note: extra parameters are not allowed, including the empty `` `application/wasm;` ``.

1. If |response| is not [=CORS-same-origin=], [=reject=] |returnValue| with a {{TypeError}} and abort these substeps.
1. If |response|'s [=response/status=] is not an [=ok status=], [=reject=] |returnValue| with a {{TypeError}} and abort these substeps.
1. [=Consume body|Consume=] |response|'s body as an {{ArrayBuffer}}, and let |bodyPromise| be the result.

Note: Although it is specified here that the response is consumed entirely before compilation proceeds, that is purely for ease of specification; implementations are likely to instead perform processing in a streaming fashion. The difference is unobservable, and thus the simpler model is specified. <!-- Using consume is a bit silly as it creates an ArrayBuffer but then we just want the underlying bytes. This is because of how streams is specced in terms of promises and JS objects whereas we want to operate more directly on the underlying concept. We can revisit this if things change in the Streams/Fetch specs. -->

1. [=Upon fulfillment=] of |bodyPromise| with value |bodyArrayBuffer|:
1. Let |stableBytes| be a [=get a copy of the buffer source|copy of the bytes held by the buffer=] |bodyArrayBuffer|.
1. [=Asynchronously compile a WebAssembly module|Asynchronously compile the WebAssembly module=] |stableBytes| using the [=networking task source=] and [=resolve=] |returnValue| with the result.
1. [=Upon rejection=] of |bodyPromise| with reason |reason|:
1. Let |returnValue| be [=a new promise=].
1. [=React=] to |source|:
* If |source| was fulfilled with value |unwrappedSource|:
1. Let |response| be |unwrappedSource|'s [=Response/response=].
1. Let |mimeType| be the result of [=header list/getting=] `` `Content-Type` `` from |response|'s [=response/header list=].
1. If |mimeType| is null, reject |returnValue| with a {{TypeError}} and abort these substeps.
1. Remove all [=HTTP tab or space byte=] from the start and end of |mimeType|.
1. If |mimeType| is not a [=byte-case-insensitive=] match for `` `application/wasm` ``, reject |returnValue| with a {{TypeError}} and abort these substeps.

Note: extra parameters are not allowed, including the empty `` `application/wasm;` ``.

1. If |response| is not [=CORS-same-origin=], [=reject=] |returnValue| with a {{TypeError}} and abort these substeps.
1. If |response|'s [=response/status=] is not an [=ok status=], [=reject=] |returnValue| with a {{TypeError}} and abort these substeps.
1. [=Consume body|Consume=] |response|'s body as an {{ArrayBuffer}}, and let |bodyPromise| be the result.

Note: Although it is specified here that the response is consumed entirely before compilation proceeds, that is purely for ease of specification; implementations are likely to instead perform processing in a streaming fashion. The difference is unobservable, and thus the simpler model is specified. <!-- Using consume is a bit silly as it creates an ArrayBuffer but then we just want the underlying bytes. This is because of how streams is specced in terms of promises and JS objects whereas we want to operate more directly on the underlying concept. We can revisit this if things change in the Streams/Fetch specs. -->

1. [=React=] to |bodyPromise|:
* If |bodyPromise| was fulfilled with value |bodyArrayBuffer|:
1. Let |stableBytes| be a [=get a copy of the buffer source|copy of the bytes held by the buffer=] |bodyArrayBuffer|.
1. [=Asynchronously compile a WebAssembly module|Asynchronously compile the WebAssembly module=] |stableBytes| using the [=networking task source=] and [=resolve=] |returnValue| with the result.
* If |bodyPromise| was rejected with reason |reason|:
1. [=Reject=] |returnValue| with |reason|.
* If |source| was rejected with reason |reason|:
1. [=Reject=] |returnValue| with |reason|.
1. [=Upon rejection=] of |source| with reason |reason|:
1. [=Reject=] |returnValue| with |reason|.
1. Return |returnValue|.
1. Return |returnValue|.
</div>

<h2 id="serialization">Serialization</h2>
Expand Down
Loading