From d763633781be484bb19b458208dd7c11efb83228 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Fri, 26 Nov 2021 09:52:41 +0100 Subject: feat(etc/fetch): Support `WebAssembly.instantiateStreaming` for file fetches (#12901) Fetching of local files, added in #12545, returns a response with no headers, including the `Content-Type` header. This currently makes it not work with the WebAssembly streaming APIs, which require the response to have a content type of `application/wasm`. Since the only way to obtain a `Response` object with a non-empty `url` field is via `fetch()`, this change changes the content type requirement to only apply to responses whose url has the `file:` scheme. --- cli/tests/unit/wasm_test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'cli') diff --git a/cli/tests/unit/wasm_test.ts b/cli/tests/unit/wasm_test.ts index e1659b090..3484b7f81 100644 --- a/cli/tests/unit/wasm_test.ts +++ b/cli/tests/unit/wasm_test.ts @@ -76,6 +76,20 @@ Deno.test(async function wasmInstantiateStreaming() { assertEquals(add(1, 3), 4); }); +Deno.test( + { permissions: { read: true } }, + async function wasmFileStreaming() { + const url = new URL("../testdata/unreachable.wasm", import.meta.url); + assert(url.href.startsWith("file://")); + + const { module } = await WebAssembly.instantiateStreaming(fetch(url)); + assertEquals(WebAssembly.Module.exports(module), [{ + name: "unreachable", + kind: "function", + }]); + }, +); + Deno.test( { permissions: { net: true } }, async function wasmStreamingNonTrivial() { -- cgit v1.2.3