Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 09ca76b

Browse filesBrowse files
cjihrigMylesBorins
authored andcommitted
test: verify that WASI errors are rethrown
This commit adds a test to verify that exceptions thrown from a WASI application are properly caught and rethrown. This also gets the code coverage in lib/wasi.js back to 100%. PR-URL: #32157 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 3e9012a commit 09ca76b
Copy full SHA for 09ca76b

File tree

Expand file treeCollapse file tree

1 file changed

+15
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-2
lines changed
Open diff view settings
Collapse file

‎test/wasi/test-return-on-exit.js‎

Copy file name to clipboardExpand all lines: test/wasi/test-return-on-exit.js
+15-2Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,27 @@ const assert = require('assert');
55
const fs = require('fs');
66
const path = require('path');
77
const { WASI } = require('wasi');
8-
const wasi = new WASI({ returnOnExit: true });
9-
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
108
const wasmDir = path.join(__dirname, 'wasm');
119
const modulePath = path.join(wasmDir, 'exitcode.wasm');
1210
const buffer = fs.readFileSync(modulePath);
1311

1412
(async () => {
13+
const wasi = new WASI({ returnOnExit: true });
14+
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
1515
const { instance } = await WebAssembly.instantiate(buffer, importObject);
1616

1717
assert.strictEqual(wasi.start(instance), 120);
1818
})().then(common.mustCall());
19+
20+
(async () => {
21+
// Verify that if a WASI application throws an exception, Node rethrows it
22+
// properly.
23+
const wasi = new WASI({ returnOnExit: true });
24+
wasi.wasiImport.proc_exit = () => { throw new Error('test error'); };
25+
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
26+
const { instance } = await WebAssembly.instantiate(buffer, importObject);
27+
28+
assert.throws(() => {
29+
wasi.start(instance);
30+
}, /^Error: test error$/);
31+
})().then(common.mustCall());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.