From 6ac2a03334f3d4b1dc1ebac64b78cad1eb1fbda7 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 3 Oct 2018 13:29:01 +0200 Subject: [PATCH] Add some tests for instantiateStreaming(). --- .../instantiateStreaming-bad-imports.any.js | 14 +++++++++++++ wasm/webapi/instantiateStreaming.any.js | 20 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 wasm/webapi/instantiateStreaming-bad-imports.any.js create mode 100644 wasm/webapi/instantiateStreaming.any.js diff --git a/wasm/webapi/instantiateStreaming-bad-imports.any.js b/wasm/webapi/instantiateStreaming-bad-imports.any.js new file mode 100644 index 00000000000000..b1efba31e91926 --- /dev/null +++ b/wasm/webapi/instantiateStreaming-bad-imports.any.js @@ -0,0 +1,14 @@ +// META: global=window,worker +// META: script=/wasm/jsapi/wasm-constants.js +// META: script=/wasm/jsapi/wasm-module-builder.js +// META: script=/wasm/jsapi/bad-imports.js + +test_bad_imports((name, error, build, ...args) => { + promise_test(t => { + const builder = new WasmModuleBuilder(); + build(builder); + const buffer = builder.toBuffer(); + const response = new Response(buffer, { "headers": { "Content-Type": "application/wasm" } }); + return promise_rejects(t, error, WebAssembly.instantiateStreaming(response, ...args)); + }, name); +}); diff --git a/wasm/webapi/instantiateStreaming.any.js b/wasm/webapi/instantiateStreaming.any.js new file mode 100644 index 00000000000000..224b0a3d0b78af --- /dev/null +++ b/wasm/webapi/instantiateStreaming.any.js @@ -0,0 +1,20 @@ +// META: global=window,worker +// META: script=/wasm/jsapi/wasm-constants.js +// META: script=/wasm/jsapi/wasm-module-builder.js +// META: script=/wasm/jsapi/assertions.js +// META: script=/wasm/jsapi/instanceTestFactory.js + +let emptyModuleBinary; +setup(() => { + emptyModuleBinary = new WasmModuleBuilder().toBuffer(); +}); + +for (const [name, fn] of instanceTestFactory) { + promise_test(async () => { + const { buffer, args, exports, verify } = fn(); + const response = new Response(buffer, { "headers": { "Content-Type": "application/wasm" } }); + const result = await WebAssembly.instantiateStreaming(response, ...args); + assert_WebAssemblyInstantiatedSource(result, exports); + verify(result.instance); + }, name); +}