chore(wasm): Don't await on the argument to handleWasmStreaming (#14000)

`handleWasmStreaming` is the function that provides the binding with
the `fetch` API needed for `WebAssembly.instantiateStreaming()` and
`WebAssembly.compileStreaming()`. When I implemented it in #11200, I
thought V8 was calling these functions with the argument of the
`WebAssembly` streaming functions, without doing any resolving, and so
`handleWasmStreaming` awaits for the parameter to resolve. However,
as discovered in
https://github.com/denoland/deno/issues/13917#issuecomment-1065805565,
V8 does in fact resolve the parameter if it's a promise (and handles
rejections arising from that).

This change removes the `async` IIFE inside `handleWasmStreaming`,
letting initial errors be handled synchronously (which will however
not throw synchronously from the `WebAssembly` namespace functions).
Awaiting is still necessary for reading the bytes of the response,
though, and so there is an `async` IIFE for that.
This commit is contained in:
Andreu Botella 2022-03-29 14:44:33 +02:00 committed by GitHub
parent f7ce96ea6e
commit d983b577bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 46 deletions

View file

@ -45,11 +45,11 @@ Deno.test(
Deno.test(
async function wasmInstantiateStreamingNoContentType() {
const response = new Response(simpleWasm);
// Rejects, not throws.
const wasmPromise = WebAssembly.instantiateStreaming(response);
await assertRejects(
async () => {
const response = Promise.resolve(new Response(simpleWasm));
await WebAssembly.instantiateStreaming(response);
},
() => wasmPromise,
TypeError,
"Invalid WebAssembly content type.",
);