1'use strict'; 2 3require('../common'); 4const assert = require('assert'); 5const { WASI } = require('wasi'); 6 7// If args is undefined, it should default to [] and should not throw. 8new WASI({}); 9 10// If args is not an Array and not undefined, it should throw. 11assert.throws(() => { new WASI({ args: 'fhqwhgads' }); }, 12 { code: 'ERR_INVALID_ARG_TYPE', message: /\bargs\b/ }); 13 14// If env is not an Object and not undefined, it should throw. 15assert.throws(() => { new WASI({ env: 'fhqwhgads' }); }, 16 { code: 'ERR_INVALID_ARG_TYPE', message: /\benv\b/ }); 17 18// If preopens is not an Object and not undefined, it should throw. 19assert.throws(() => { new WASI({ preopens: 'fhqwhgads' }); }, 20 { code: 'ERR_INVALID_ARG_TYPE', message: /\bpreopens\b/ }); 21 22// If returnOnExit is not a boolean and not undefined, it should throw. 23assert.throws(() => { new WASI({ returnOnExit: 'fhqwhgads' }); }, 24 { code: 'ERR_INVALID_ARG_TYPE', message: /\breturnOnExit\b/ }); 25 26// If stdin is not an int32 and not undefined, it should throw. 27assert.throws(() => { new WASI({ stdin: 'fhqwhgads' }); }, 28 { code: 'ERR_INVALID_ARG_TYPE', message: /\bstdin\b/ }); 29 30// If stdout is not an int32 and not undefined, it should throw. 31assert.throws(() => { new WASI({ stdout: 'fhqwhgads' }); }, 32 { code: 'ERR_INVALID_ARG_TYPE', message: /\bstdout\b/ }); 33 34// If stderr is not an int32 and not undefined, it should throw. 35assert.throws(() => { new WASI({ stderr: 'fhqwhgads' }); }, 36 { code: 'ERR_INVALID_ARG_TYPE', message: /\bstderr\b/ }); 37 38// If options is provided, but not an object, the constructor should throw. 39[null, 'foo', '', 0, NaN, Symbol(), true, false, () => {}].forEach((value) => { 40 assert.throws(() => { new WASI(value); }, 41 { code: 'ERR_INVALID_ARG_TYPE' }); 42}); 43 44// Verify that exceptions thrown from the binding layer are handled. 45assert.throws(() => { 46 new WASI({ preopens: { '/sandbox': '__/not/real/path' } }); 47}, { code: 'UVWASI_ENOENT', message: /uvwasi_init/ }); 48