• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// META: global=window,worker
2// META: script=/wasm/jsapi/assertions.js
3
4promise_test(t => {
5  const response = fetch("/wasm/incrementer.wasm").then(res => new Response(res.body));
6  return promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(response));
7}, "Response with no Content-Type: compileStreaming");
8
9promise_test(t => {
10  const response = fetch("/wasm/incrementer.wasm").then(res => new Response(res.body));
11  return promise_rejects_js(t, TypeError, WebAssembly.instantiateStreaming(response));
12}, "Response with no Content-Type: instantiateStreaming");
13
14const invalidContentTypes = [
15  "",
16  "application/javascript",
17  "application/octet-stream",
18  "text/wasm",
19  "application/wasm;",
20  "application/wasm;x",
21  "application/wasm;charset=UTF-8",
22];
23
24for (const contenttype of invalidContentTypes) {
25  promise_test(t => {
26    const response = fetch(`/wasm/incrementer.wasm?pipe=header(Content-Type,${encodeURIComponent(contenttype)})`);
27    return promise_rejects_js(t, TypeError, WebAssembly.compileStreaming(response));
28  }, `Response with Content-Type ${format_value(contenttype)}: compileStreaming`);
29
30  promise_test(t => {
31    const response = fetch(`/wasm/incrementer.wasm?pipe=header(Content-Type,${encodeURIComponent(contenttype)})`);
32    return promise_rejects_js(t, TypeError, WebAssembly.instantiateStreaming(response));
33  }, `Response with Content-Type ${format_value(contenttype)}: instantiateStreaming`);
34}
35
36const validContentTypes = [
37  "application/wasm",
38  "APPLICATION/wasm",
39  "APPLICATION/WASM",
40];
41
42for (const contenttype of validContentTypes) {
43  promise_test(async t => {
44    const response = fetch(`/wasm/incrementer.wasm?pipe=header(Content-Type,${encodeURIComponent(contenttype)})`);
45    const module = await WebAssembly.compileStreaming(response);
46    assert_equals(Object.getPrototypeOf(module), WebAssembly.Module.prototype,
47                  "prototype");
48  }, `Response with Content-Type ${format_value(contenttype)}: compileStreaming`);
49
50  promise_test(async t => {
51    const response = fetch(`/wasm/incrementer.wasm?pipe=header(Content-Type,${encodeURIComponent(contenttype)})`);
52    const result = await WebAssembly.instantiateStreaming(response);
53    assert_WebAssemblyInstantiatedSource(
54        result,
55        {
56          "increment": {
57            "kind": "function",
58            "name": "0",
59            "length": 1
60          }
61        }
62      );
63  }, `Response with Content-Type ${format_value(contenttype)}: instantiateStreaming`);
64}
65