mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
7efae9341f
- remove default for version - updates tests to specify version - add test for when version is not specified Signed-off-by: Michael Dawson <mdawson@devrus.com> PR-URL: https://github.com/nodejs/node/pull/47391 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { WASI } = require('wasi');
|
|
const wasmDir = path.join(__dirname, 'wasm');
|
|
const modulePath = path.join(wasmDir, 'exitcode.wasm');
|
|
const buffer = fs.readFileSync(modulePath);
|
|
|
|
(async () => {
|
|
const wasi = new WASI({ version: 'preview1', returnOnExit: true });
|
|
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
|
|
const { instance } = await WebAssembly.instantiate(buffer, importObject);
|
|
|
|
assert.strictEqual(wasi.start(instance), 120);
|
|
})().then(common.mustCall());
|
|
|
|
(async () => {
|
|
// Verify that if a WASI application throws an exception, Node rethrows it
|
|
// properly.
|
|
const wasi = new WASI({ version: 'preview1', returnOnExit: true });
|
|
const patchedExit = () => { throw new Error('test error'); };
|
|
wasi.wasiImport.proc_exit = patchedExit.bind(wasi.wasiImport);
|
|
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
|
|
const { instance } = await WebAssembly.instantiate(buffer, importObject);
|
|
|
|
assert.throws(() => {
|
|
wasi.start(instance);
|
|
}, /^Error: test error$/);
|
|
})().then(common.mustCall());
|