11cb0ef41Sopenharmony_ci// META: global=window,worker
21cb0ef41Sopenharmony_ci// META: script=/wasm/jsapi/wasm-module-builder.js
31cb0ef41Sopenharmony_ci// META: script=/wasm/jsapi/assertions.js
41cb0ef41Sopenharmony_ci// META: script=/wasm/jsapi/instanceTestFactory.js
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_cilet emptyModuleBinary;
71cb0ef41Sopenharmony_cisetup(() => {
81cb0ef41Sopenharmony_ci  emptyModuleBinary = new WasmModuleBuilder().toBuffer();
91cb0ef41Sopenharmony_ci});
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cifor (const [name, fn] of instanceTestFactory) {
121cb0ef41Sopenharmony_ci  promise_test(async () => {
131cb0ef41Sopenharmony_ci    const { buffer, args, exports, verify } = fn();
141cb0ef41Sopenharmony_ci    const response = new Response(buffer, { "headers": { "Content-Type": "application/wasm" } });
151cb0ef41Sopenharmony_ci    const result = await WebAssembly.instantiateStreaming(response, ...args);
161cb0ef41Sopenharmony_ci    assert_WebAssemblyInstantiatedSource(result, exports);
171cb0ef41Sopenharmony_ci    verify(result.instance);
181cb0ef41Sopenharmony_ci  }, name);
191cb0ef41Sopenharmony_ci}
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cipromise_test(async () => {
221cb0ef41Sopenharmony_ci  const builder = new WasmModuleBuilder();
231cb0ef41Sopenharmony_ci  builder.addImportedGlobal("module", "global", kWasmI32);
241cb0ef41Sopenharmony_ci  const buffer = builder.toBuffer();
251cb0ef41Sopenharmony_ci  const response = new Response(buffer, { "headers": { "Content-Type": "application/wasm" } });
261cb0ef41Sopenharmony_ci  const order = [];
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci  const imports = {
291cb0ef41Sopenharmony_ci    get module() {
301cb0ef41Sopenharmony_ci      order.push("module getter");
311cb0ef41Sopenharmony_ci      return {
321cb0ef41Sopenharmony_ci        get global() {
331cb0ef41Sopenharmony_ci          order.push("global getter");
341cb0ef41Sopenharmony_ci          return 0;
351cb0ef41Sopenharmony_ci        },
361cb0ef41Sopenharmony_ci      }
371cb0ef41Sopenharmony_ci    },
381cb0ef41Sopenharmony_ci  };
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  const expected = [
411cb0ef41Sopenharmony_ci    "module getter",
421cb0ef41Sopenharmony_ci    "global getter",
431cb0ef41Sopenharmony_ci  ];
441cb0ef41Sopenharmony_ci  const p = WebAssembly.instantiateStreaming(response, imports);
451cb0ef41Sopenharmony_ci  assert_array_equals(order, []);
461cb0ef41Sopenharmony_ci  const result = await p;
471cb0ef41Sopenharmony_ci  assert_WebAssemblyInstantiatedSource(result, {});
481cb0ef41Sopenharmony_ci  assert_array_equals(order, expected);
491cb0ef41Sopenharmony_ci}, "Synchronous options handling");
50