Skip to content

Commit a021d92

Browse files
authored
Merge pull request #61 from nodejs/master
test: verify that WASI errors are rethrown
2 parents 0bb292d + ec204d8 commit a021d92

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

Lines 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)