summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit/wasm_test.ts14
-rw-r--r--ext/fetch/26_fetch.js17
2 files changed, 25 insertions, 6 deletions
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
@@ -77,6 +77,20 @@ Deno.test(async function wasmInstantiateStreaming() {
});
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() {
// deno-dom's WASM file is a real-world non-trivial case that gave us
diff --git a/ext/fetch/26_fetch.js b/ext/fetch/26_fetch.js
index 47d8b2e85..a66146bee 100644
--- a/ext/fetch/26_fetch.js
+++ b/ext/fetch/26_fetch.js
@@ -37,6 +37,7 @@
PromisePrototypeThen,
PromisePrototypeCatch,
String,
+ StringPrototypeStartsWith,
StringPrototypeToLowerCase,
TypedArrayPrototypeSubarray,
TypeError,
@@ -498,12 +499,16 @@
// The spec is ambiguous here, see
// https://github.com/WebAssembly/spec/issues/1138. The WPT tests
// expect the raw value of the Content-Type attribute lowercased.
- const contentType = res.headers.get("Content-Type");
- if (
- typeof contentType !== "string" ||
- StringPrototypeToLowerCase(contentType) !== "application/wasm"
- ) {
- throw new TypeError("Invalid WebAssembly content type.");
+ // We ignore this for file:// because file fetches don't have a
+ // Content-Type.
+ if (!StringPrototypeStartsWith(res.url, "file://")) {
+ const contentType = res.headers.get("Content-Type");
+ if (
+ typeof contentType !== "string" ||
+ StringPrototypeToLowerCase(contentType) !== "application/wasm"
+ ) {
+ throw new TypeError("Invalid WebAssembly content type.");
+ }
}
// 2.5.