11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cirequire('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { WASI } = require('wasi'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// If args is undefined, it should default to [] and should not throw. 81cb0ef41Sopenharmony_cinew WASI({}); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci// If args is not an Array and not undefined, it should throw. 111cb0ef41Sopenharmony_ciassert.throws(() => { new WASI({ args: 'fhqwhgads' }); }, 121cb0ef41Sopenharmony_ci { code: 'ERR_INVALID_ARG_TYPE', message: /\bargs\b/ }); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci// If env is not an Object and not undefined, it should throw. 151cb0ef41Sopenharmony_ciassert.throws(() => { new WASI({ env: 'fhqwhgads' }); }, 161cb0ef41Sopenharmony_ci { code: 'ERR_INVALID_ARG_TYPE', message: /\benv\b/ }); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci// If preopens is not an Object and not undefined, it should throw. 191cb0ef41Sopenharmony_ciassert.throws(() => { new WASI({ preopens: 'fhqwhgads' }); }, 201cb0ef41Sopenharmony_ci { code: 'ERR_INVALID_ARG_TYPE', message: /\bpreopens\b/ }); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci// If returnOnExit is not a boolean and not undefined, it should throw. 231cb0ef41Sopenharmony_ciassert.throws(() => { new WASI({ returnOnExit: 'fhqwhgads' }); }, 241cb0ef41Sopenharmony_ci { code: 'ERR_INVALID_ARG_TYPE', message: /\breturnOnExit\b/ }); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci// If stdin is not an int32 and not undefined, it should throw. 271cb0ef41Sopenharmony_ciassert.throws(() => { new WASI({ stdin: 'fhqwhgads' }); }, 281cb0ef41Sopenharmony_ci { code: 'ERR_INVALID_ARG_TYPE', message: /\bstdin\b/ }); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci// If stdout is not an int32 and not undefined, it should throw. 311cb0ef41Sopenharmony_ciassert.throws(() => { new WASI({ stdout: 'fhqwhgads' }); }, 321cb0ef41Sopenharmony_ci { code: 'ERR_INVALID_ARG_TYPE', message: /\bstdout\b/ }); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci// If stderr is not an int32 and not undefined, it should throw. 351cb0ef41Sopenharmony_ciassert.throws(() => { new WASI({ stderr: 'fhqwhgads' }); }, 361cb0ef41Sopenharmony_ci { code: 'ERR_INVALID_ARG_TYPE', message: /\bstderr\b/ }); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci// If options is provided, but not an object, the constructor should throw. 391cb0ef41Sopenharmony_ci[null, 'foo', '', 0, NaN, Symbol(), true, false, () => {}].forEach((value) => { 401cb0ef41Sopenharmony_ci assert.throws(() => { new WASI(value); }, 411cb0ef41Sopenharmony_ci { code: 'ERR_INVALID_ARG_TYPE' }); 421cb0ef41Sopenharmony_ci}); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci// Verify that exceptions thrown from the binding layer are handled. 451cb0ef41Sopenharmony_ciassert.throws(() => { 461cb0ef41Sopenharmony_ci new WASI({ preopens: { '/sandbox': '__/not/real/path' } }); 471cb0ef41Sopenharmony_ci}, { code: 'UVWASI_ENOENT', message: /uvwasi_init/ }); 48