diff options
author | Andreu Botella <andreu@andreubotella.com> | 2022-03-29 14:44:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-29 14:44:33 +0200 |
commit | d983b577bc903f18028a99d0a40a17322ac80ffe (patch) | |
tree | 177395212614bc600cb8c073ecccec1469d9eec0 /cli/tests | |
parent | f7ce96ea6e7a720d578b6f7f719fba90c8afdded (diff) |
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.
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/testdata/wasm_streaming_panic_test.js.out | 2 | ||||
-rw-r--r-- | cli/tests/unit/wasm_test.ts | 8 |
2 files changed, 5 insertions, 5 deletions
diff --git a/cli/tests/testdata/wasm_streaming_panic_test.js.out b/cli/tests/testdata/wasm_streaming_panic_test.js.out index c21d709dd..3e93f643a 100644 --- a/cli/tests/testdata/wasm_streaming_panic_test.js.out +++ b/cli/tests/testdata/wasm_streaming_panic_test.js.out @@ -1,2 +1,2 @@ error: Uncaught (in promise) TypeError: Invalid WebAssembly content type. - at deno:ext/fetch/26_fetch.js:[WILDCARD] + at handleWasmStreaming (deno:ext/fetch/26_fetch.js:[WILDCARD]) diff --git a/cli/tests/unit/wasm_test.ts b/cli/tests/unit/wasm_test.ts index 3484b7f81..1b31249d4 100644 --- a/cli/tests/unit/wasm_test.ts +++ b/cli/tests/unit/wasm_test.ts @@ -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.", ); |