1'use strict'; 2require('../common'); 3 4if (process.argv[2] === 'wasi-child') { 5 const assert = require('assert'); 6 const fs = require('fs'); 7 const path = require('path'); 8 9 const { WASI } = require('wasi'); 10 const wasi = new WASI({ 11 args: ['foo', '-bar', '--baz=value'], 12 }); 13 const importObject = { wasi_snapshot_preview1: wasi.wasiImport }; 14 15 const modulePath = path.join(__dirname, 'wasm', 'main_args.wasm'); 16 const buffer = fs.readFileSync(modulePath); 17 18 assert.rejects(async () => { 19 const { instance } = await WebAssembly.instantiate(buffer, importObject); 20 instance.exports._start(); 21 }, { 22 name: 'Error', 23 code: 'ERR_WASI_NOT_STARTED', 24 message: 'wasi.start() has not been called', 25 }); 26} else { 27 const assert = require('assert'); 28 const cp = require('child_process'); 29 30 const child = cp.spawnSync(process.execPath, [ 31 __filename, 32 'wasi-child', 33 ], { 34 env: { ...process.env, NODE_DEBUG_NATIVE: 'wasi' }, 35 }); 36 assert.strictEqual(child.signal, null); 37 assert.strictEqual(child.status, 0); 38} 39