1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

fix(ext/fetch): better error if no content-type

The streaming WASM support code inspects the Response object's
Content-Type header but if that was missing, it failed with a fairly
inscrutable "String.prototype.toLowerCase called on null or undefined"
exception. Now it raises a more legible "Invalid WebAssembly content
type" exception.
This commit is contained in:
Ben Noordhuis 2021-08-16 12:53:30 +02:00 committed by Luca Casonato
parent 6ddabb7427
commit 6ced7b0383
2 changed files with 16 additions and 2 deletions

View file

@ -48,6 +48,19 @@ unitTest(
}, },
); );
unitTest(
async function wasmInstantiateStreamingNoContentType() {
await assertThrowsAsync(
async () => {
const response = Promise.resolve(new Response(simpleWasm));
await WebAssembly.instantiateStreaming(response);
},
TypeError,
"Invalid WebAssembly content type.",
);
},
);
unitTest(async function wasmInstantiateStreaming() { unitTest(async function wasmInstantiateStreaming() {
let isomorphic = ""; let isomorphic = "";
for (const byte of simpleWasm) { for (const byte of simpleWasm) {

View file

@ -503,9 +503,10 @@
// The spec is ambiguous here, see // The spec is ambiguous here, see
// https://github.com/WebAssembly/spec/issues/1138. The WPT tests // https://github.com/WebAssembly/spec/issues/1138. The WPT tests
// expect the raw value of the Content-Type attribute lowercased. // expect the raw value of the Content-Type attribute lowercased.
const contentType = res.headers.get("Content-Type");
if ( if (
StringPrototypeToLowerCase(res.headers.get("Content-Type")) !== typeof contentType !== "string" ||
"application/wasm" StringPrototypeToLowerCase(contentType) !== "application/wasm"
) { ) {
throw new TypeError("Invalid WebAssembly content type."); throw new TypeError("Invalid WebAssembly content type.");
} }