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