From 4362b7218db8f8ab8eb7e12502421fcb47db86d5 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 24 Oct 2024 17:10:16 +0200 Subject: [PATCH 1/2] [web-api] Use the 'react' algorithm from WebIDL Fixes #1834. --- document/web-api/index.bs | 48 ++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/document/web-api/index.bs b/document/web-api/index.bs index c086c43208..22a2710d5c 100644 --- a/document/web-api/index.bs +++ b/document/web-api/index.bs @@ -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. - - 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. + + 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|.

Serialization

From d8ef842c491bd5a6584dc1c7f734d80929ff82ff Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 28 Oct 2024 15:45:18 +0100 Subject: [PATCH 2/2] [js-api] Use the 'react' algorithm from WebIDL --- document/js-api/index.bs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 8013e7456d..858952bae0 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -469,15 +469,17 @@ The verification of WebAssembly type requirements is deferred to the To instantiate a promise of a module |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|.