From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../tests/test_webassembly_compile_worker.js | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 dom/promise/tests/test_webassembly_compile_worker.js (limited to 'dom/promise/tests/test_webassembly_compile_worker.js') diff --git a/dom/promise/tests/test_webassembly_compile_worker.js b/dom/promise/tests/test_webassembly_compile_worker.js new file mode 100644 index 0000000000..90c3551137 --- /dev/null +++ b/dom/promise/tests/test_webassembly_compile_worker.js @@ -0,0 +1,55 @@ +const sampleURL = "test_webassembly_compile_sample.wasm"; +const sampleExportName = "run"; +const sampleResult = 1275; + +/* eslint-disable no-throw-literal */ + +function checkSampleModule(m) { + if (!(m instanceof WebAssembly.Module)) { + throw "not a module"; + } + var i = new WebAssembly.Instance(m); + if (!(i instanceof WebAssembly.Instance)) { + throw "not an instance"; + } + if (i.exports[sampleExportName]() !== sampleResult) { + throw "wrong result"; + } +} + +function checkSampleInstance(i) { + if (!(i instanceof WebAssembly.Instance)) { + throw "not an instance"; + } + if (i.exports[sampleExportName]() !== sampleResult) { + throw "wrong result"; + } +} + +const initObj = { headers: { "Content-Type": "application/wasm" } }; + +onmessage = e => { + WebAssembly.compile(e.data) + .then(m => checkSampleModule(m)) + .then(() => WebAssembly.instantiate(e.data)) + .then(({ module, instance }) => { + checkSampleModule(module); + checkSampleInstance(instance); + }) + .then(() => WebAssembly.compileStreaming(new Response(e.data, initObj))) + .then(m => checkSampleModule(m)) + .then(() => WebAssembly.instantiateStreaming(new Response(e.data, initObj))) + .then(({ module, instance }) => { + checkSampleModule(module); + checkSampleInstance(instance); + }) + .then(() => WebAssembly.compileStreaming(fetch(sampleURL))) + .then(m => checkSampleModule(m)) + .then(() => WebAssembly.instantiateStreaming(fetch(sampleURL))) + .then(({ module, instance }) => { + checkSampleModule(module); + checkSampleInstance(instance); + }) + .then(() => postMessage("ok")) + .catch(err => postMessage("fail: " + err)); +}; -- cgit v1.2.3