• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// META: global=window,worker
2// META: script=/wasm/jsapi/wasm-module-builder.js
3// META: script=/wasm/jsapi/assertions.js
4// META: script=/wasm/jsapi/instanceTestFactory.js
5
6let emptyModuleBinary;
7setup(() => {
8  emptyModuleBinary = new WasmModuleBuilder().toBuffer();
9});
10
11for (const [name, fn] of instanceTestFactory) {
12  promise_test(async () => {
13    const { buffer, args, exports, verify } = fn();
14    const response = new Response(buffer, { "headers": { "Content-Type": "application/wasm" } });
15    const result = await WebAssembly.instantiateStreaming(response, ...args);
16    assert_WebAssemblyInstantiatedSource(result, exports);
17    verify(result.instance);
18  }, name);
19}
20
21promise_test(async () => {
22  const builder = new WasmModuleBuilder();
23  builder.addImportedGlobal("module", "global", kWasmI32);
24  const buffer = builder.toBuffer();
25  const response = new Response(buffer, { "headers": { "Content-Type": "application/wasm" } });
26  const order = [];
27
28  const imports = {
29    get module() {
30      order.push("module getter");
31      return {
32        get global() {
33          order.push("global getter");
34          return 0;
35        },
36      }
37    },
38  };
39
40  const expected = [
41    "module getter",
42    "global getter",
43  ];
44  const p = WebAssembly.instantiateStreaming(response, imports);
45  assert_array_equals(order, []);
46  const result = await p;
47  assert_WebAssemblyInstantiatedSource(result, {});
48  assert_array_equals(order, expected);
49}, "Synchronous options handling");
50