WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 4362b72

Browse files
committed
[web-api] Use the 'react' algorithm from WebIDL
Fixes #1834.
1 parent 85a7ccb commit 4362b72

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

document/web-api/index.bs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -110,30 +110,32 @@ Note: This algorithm accepts a {{Response}} object, or a
110110
{{CompileError}} or other relevant error type, depending on the cause of failure.
111111

112112

113-
1. Let |returnValue| be [=a new promise=]
114-
1. [=Upon fulfillment=] of |source| with value |unwrappedSource|:
115-
1. Let |response| be |unwrappedSource|'s [=Response/response=].
116-
1. Let |mimeType| be the result of [=header list/getting=] `` `Content-Type` `` from |response|'s [=response/header list=].
117-
1. If |mimeType| is null, reject |returnValue| with a {{TypeError}} and abort these substeps.
118-
1. Remove all [=HTTP tab or space byte=] from the start and end of |mimeType|.
119-
1. If |mimeType| is not a [=byte-case-insensitive=] match for `` `application/wasm` ``, reject |returnValue| with a {{TypeError}} and abort these substeps.
120-
121-
Note: extra parameters are not allowed, including the empty `` `application/wasm;` ``.
122-
123-
1. If |response| is not [=CORS-same-origin=], [=reject=] |returnValue| with a {{TypeError}} and abort these substeps.
124-
1. If |response|'s [=response/status=] is not an [=ok status=], [=reject=] |returnValue| with a {{TypeError}} and abort these substeps.
125-
1. [=Consume body|Consume=] |response|'s body as an {{ArrayBuffer}}, and let |bodyPromise| be the result.
126-
127-
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. -->
128-
129-
1. [=Upon fulfillment=] of |bodyPromise| with value |bodyArrayBuffer|:
130-
1. Let |stableBytes| be a [=get a copy of the buffer source|copy of the bytes held by the buffer=] |bodyArrayBuffer|.
131-
1. [=Asynchronously compile a WebAssembly module|Asynchronously compile the WebAssembly module=] |stableBytes| using the [=networking task source=] and [=resolve=] |returnValue| with the result.
132-
1. [=Upon rejection=] of |bodyPromise| with reason |reason|:
113+
1. Let |returnValue| be [=a new promise=].
114+
1. [=React=] to |source|:
115+
* If |source| was fulfilled with value |unwrappedSource|:
116+
1. Let |response| be |unwrappedSource|'s [=Response/response=].
117+
1. Let |mimeType| be the result of [=header list/getting=] `` `Content-Type` `` from |response|'s [=response/header list=].
118+
1. If |mimeType| is null, reject |returnValue| with a {{TypeError}} and abort these substeps.
119+
1. Remove all [=HTTP tab or space byte=] from the start and end of |mimeType|.
120+
1. If |mimeType| is not a [=byte-case-insensitive=] match for `` `application/wasm` ``, reject |returnValue| with a {{TypeError}} and abort these substeps.
121+
122+
Note: extra parameters are not allowed, including the empty `` `application/wasm;` ``.
123+
124+
1. If |response| is not [=CORS-same-origin=], [=reject=] |returnValue| with a {{TypeError}} and abort these substeps.
125+
1. If |response|'s [=response/status=] is not an [=ok status=], [=reject=] |returnValue| with a {{TypeError}} and abort these substeps.
126+
1. [=Consume body|Consume=] |response|'s body as an {{ArrayBuffer}}, and let |bodyPromise| be the result.
127+
128+
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. -->
129+
130+
1. [=React=] to |bodyPromise|:
131+
* If |bodyPromise| was fulfilled with value |bodyArrayBuffer|:
132+
1. Let |stableBytes| be a [=get a copy of the buffer source|copy of the bytes held by the buffer=] |bodyArrayBuffer|.
133+
1. [=Asynchronously compile a WebAssembly module|Asynchronously compile the WebAssembly module=] |stableBytes| using the [=networking task source=] and [=resolve=] |returnValue| with the result.
134+
* If |bodyPromise| was rejected with reason |reason|:
135+
1. [=Reject=] |returnValue| with |reason|.
136+
* If |source| was rejected with reason |reason|:
133137
1. [=Reject=] |returnValue| with |reason|.
134-
1. [=Upon rejection=] of |source| with reason |reason|:
135-
1. [=Reject=] |returnValue| with |reason|.
136-
1. Return |returnValue|.
138+
1. Return |returnValue|.
137139
</div>
138140

139141
<h2 id="serialization">Serialization</h2>

0 commit comments

Comments
 (0)