File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -5,14 +5,27 @@ const assert = require('assert');
5
5
const fs = require ( 'fs' ) ;
6
6
const path = require ( 'path' ) ;
7
7
const { WASI } = require ( 'wasi' ) ;
8
- const wasi = new WASI ( { returnOnExit : true } ) ;
9
- const importObject = { wasi_snapshot_preview1 : wasi . wasiImport } ;
10
8
const wasmDir = path . join ( __dirname , 'wasm' ) ;
11
9
const modulePath = path . join ( wasmDir , 'exitcode.wasm' ) ;
12
10
const buffer = fs . readFileSync ( modulePath ) ;
13
11
14
12
( async ( ) => {
13
+ const wasi = new WASI ( { returnOnExit : true } ) ;
14
+ const importObject = { wasi_snapshot_preview1 : wasi . wasiImport } ;
15
15
const { instance } = await WebAssembly . instantiate ( buffer , importObject ) ;
16
16
17
17
assert . strictEqual ( wasi . start ( instance ) , 120 ) ;
18
18
} ) ( ) . 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
+ } , / ^ E r r o r : t e s t e r r o r $ / ) ;
31
+ } ) ( ) . then ( common . mustCall ( ) ) ;
You can’t perform that action at this time.
0 commit comments