| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3e9012a commit 09ca76b
1 file 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 | + }, /^Error: test error$/); | ||
| 31 | + })().then(common.mustCall()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments