diff options
author | Tobias Nießen <tniessen@tnie.de> | 2022-04-26 00:46:42 +0300 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2022-04-28 07:57:24 +0300 |
commit | ad8269450a1f9b04b5a502789a6097f4346aae03 (patch) | |
tree | adbeb1629acd43dc3e0c68d9217d1c3faf85976d /test | |
parent | 7b701442de42329ea2b244a18226d51bb14529b2 (diff) |
lib,src: use Response URL as WebAssembly location
As per Section 3 of the WebAssembly Web API spec.
PR-URL: https://github.com/nodejs/node/pull/42842
Refs: https://github.com/nodejs/node/pull/42701
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/crash.wasm | bin | 0 -> 36 bytes | |||
-rw-r--r-- | test/fixtures/crash.wat | 1 | ||||
-rw-r--r-- | test/parallel/test-wasm-web-api.js | 23 |
3 files changed, 23 insertions, 1 deletions
diff --git a/test/fixtures/crash.wasm b/test/fixtures/crash.wasm Binary files differnew file mode 100644 index 00000000000..fdcc992885e --- /dev/null +++ b/test/fixtures/crash.wasm diff --git a/test/fixtures/crash.wat b/test/fixtures/crash.wat new file mode 100644 index 00000000000..70450453869 --- /dev/null +++ b/test/fixtures/crash.wat @@ -0,0 +1 @@ +(module (func (export "crash") unreachable)) diff --git a/test/parallel/test-wasm-web-api.js b/test/parallel/test-wasm-web-api.js index 9576e13d669..d4a81794f80 100644 --- a/test/parallel/test-wasm-web-api.js +++ b/test/parallel/test-wasm-web-api.js @@ -19,7 +19,7 @@ async function testRequest(handler) { const server = createServer((_, res) => handler(res)).unref().listen(0); await events.once(server, 'listening'); const { port } = server.address(); - return fetch(`http://127.0.0.1:${port}/`); + return fetch(`http://127.0.0.1:${port}/foo.wasm`); } // Runs the given function both with the promise itself and as a continuation @@ -223,4 +223,25 @@ function testCompileStreamingRejectionUsingFetch(responseCallback, rejection) { name: 'TypeError', message: /terminated/ }); + + // Test "Developer-Facing Display Conventions" described in the WebAssembly + // Web API specification. + await testCompileStreaming(() => testRequest((res) => { + // Respond with a WebAssembly module that only exports a single function, + // which only contains an 'unreachable' instruction. + res.setHeader('Content-Type', 'application/wasm'); + res.end(fixtures.readSync('crash.wasm')); + }), async (modPromise) => { + // Call the WebAssembly function and check that the error stack contains the + // correct "WebAssembly location" as per the specification. + const mod = await modPromise; + const instance = new WebAssembly.Instance(mod); + assert.throws(() => instance.exports.crash(), (err) => { + const stack = err.stack.split(/\n/g); + assert.strictEqual(stack[0], 'RuntimeError: unreachable'); + assert.match(stack[1], + /^\s*at http:\/\/127\.0\.0\.1:\d+\/foo\.wasm:wasm-function\[0\]:0x22$/); + return true; + }); + }); })().then(common.mustCall()); |