| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d56c0f7 commit 4b52727
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -118,6 +118,9 @@ added: | |||
| 118 | 118 | - v13.3.0 | |
| 119 | 119 | - v12.16.0 | |
| 120 | 120 | changes: | |
| 121 | + - version: REPLACEME | ||
| 122 | + pr-url: https://github.com/nodejs/node/pull/47391 | ||
| 123 | + description: The version option is now required and has no default value. | ||
| 121 | 124 | - version: v19.8.0 | |
| 122 | 125 | pr-url: https://github.com/nodejs/node/pull/46469 | |
| 123 | 126 | description: version field added to options. | |
@@ -144,7 +147,8 @@ changes: | |||
| 144 | 147 | * `stderr` {integer} The file descriptor used as standard error in the | |
| 145 | 148 | WebAssembly application. **Default:** `2`. | |
| 146 | 149 | * `version` {string} The version of WASI requested. Currently the only | |
| 147 | - supported versions are `unstable` and `preview1`. **Default:** `preview1`. | ||
| 150 | + supported versions are `unstable` and `preview1`. This option is | ||
| 151 | + mandatory. | ||
| 148 | 152 | ||
| 149 | 153 | ### `wasi.getImportObject()` | |
| 150 | 154 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,28 +48,21 @@ class WASI { | |||
| 48 | 48 | validateObject(options, 'options'); | |
| 49 | 49 | ||
| 50 | 50 | let _WASI; | |
| 51 | - if (options.version !== undefined) { | ||
| 52 | - validateString(options.version, 'options.version'); | ||
| 53 | - switch (options.version) { | ||
| 54 | - case 'unstable': | ||
| 55 | - ({ WASI: _WASI } = internalBinding('wasi')); | ||
| 56 | - this[kBindingName] = 'wasi_unstable'; | ||
| 57 | - break; | ||
| 58 | - // When adding support for additional wasi versions add case here | ||
| 59 | - case 'preview1': | ||
| 60 | - ({ WASI: _WASI } = internalBinding('wasi')); | ||
| 61 | - this[kBindingName] = 'wasi_snapshot_preview1'; | ||
| 62 | - break; | ||
| 63 | - // When adding support for additional wasi versions add case here | ||
| 64 | - default: | ||
| 65 | - throw new ERR_INVALID_ARG_VALUE('options.version', | ||
| 66 | - options.version, | ||
| 67 | - 'unsupported WASI version'); | ||
| 68 | - } | ||
| 69 | - } else { | ||
| 70 | - // TODO(mdawson): Remove this in a SemVer major PR before Node.js 20 | ||
| 71 | - ({ WASI: _WASI } = internalBinding('wasi')); | ||
| 72 | - this[kBindingName] = 'wasi_snapshot_preview1'; | ||
| 51 | + validateString(options.version, 'options.version'); | ||
| 52 | + switch (options.version) { | ||
| 53 | + case 'unstable': | ||
| 54 | + ({ WASI: _WASI } = internalBinding('wasi')); | ||
| 55 | + this[kBindingName] = 'wasi_unstable'; | ||
| 56 | + break; | ||
| 57 | + case 'preview1': | ||
| 58 | + ({ WASI: _WASI } = internalBinding('wasi')); | ||
| 59 | + this[kBindingName] = 'wasi_snapshot_preview1'; | ||
| 60 | + break; | ||
| 61 | + // When adding support for additional wasi versions add case here | ||
| 62 | + default: | ||
| 63 | + throw new ERR_INVALID_ARG_VALUE('options.version', | ||
| 64 | + options.version, | ||
| 65 | + 'unsupported WASI version'); | ||
| 73 | 66 | } | |
| 74 | 67 | ||
| 75 | 68 | if (options.args !== undefined) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ const modulePath = path.join(wasmDir, 'exitcode.wasm'); | |||
| 9 | 9 | const buffer = fs.readFileSync(modulePath); | |
| 10 | 10 | ||
| 11 | 11 | (async () => { | |
| 12 | - const wasi = new WASI({ returnOnExit: true }); | ||
| 12 | + const wasi = new WASI({ version: 'preview1', returnOnExit: true }); | ||
| 13 | 13 | const importObject = { wasi_snapshot_preview1: wasi.wasiImport }; | |
| 14 | 14 | const { instance } = await WebAssembly.instantiate(buffer, importObject); | |
| 15 | 15 | ||
@@ -19,7 +19,7 @@ const buffer = fs.readFileSync(modulePath); | |||
| 19 | 19 | (async () => { | |
| 20 | 20 | // Verify that if a WASI application throws an exception, Node rethrows it | |
| 21 | 21 | // properly. | |
| 22 | - const wasi = new WASI({ returnOnExit: true }); | ||
| 22 | + const wasi = new WASI({ version: 'preview1', returnOnExit: true }); | ||
| 23 | 23 | const patchedExit = () => { throw new Error('test error'); }; | |
| 24 | 24 | wasi.wasiImport.proc_exit = patchedExit.bind(wasi.wasiImport); | |
| 25 | 25 | const importObject = { wasi_snapshot_preview1: wasi.wasiImport }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 11 | 11 | (async () => { | |
| 12 | 12 | { | |
| 13 | 13 | // Verify that a WebAssembly.Instance is passed in. | |
| 14 | - const wasi = new WASI(); | ||
| 14 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 15 | 15 | ||
| 16 | 16 | assert.throws( | |
| 17 | 17 | () => { wasi.initialize(); }, | |
@@ -24,7 +24,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 24 | 24 | ||
| 25 | 25 | { | |
| 26 | 26 | // Verify that the passed instance has an exports objects. | |
| 27 | - const wasi = new WASI({}); | ||
| 27 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 28 | 28 | const wasm = await WebAssembly.compile(bufferSource); | |
| 29 | 29 | const instance = await WebAssembly.instantiate(wasm); | |
| 30 | 30 | ||
@@ -40,7 +40,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 40 | 40 | ||
| 41 | 41 | { | |
| 42 | 42 | // Verify that a _initialize() export was passed. | |
| 43 | - const wasi = new WASI({}); | ||
| 43 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 44 | 44 | const wasm = await WebAssembly.compile(bufferSource); | |
| 45 | 45 | const instance = await WebAssembly.instantiate(wasm); | |
| 46 | 46 | ||
@@ -63,7 +63,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 63 | 63 | ||
| 64 | 64 | { | |
| 65 | 65 | // Verify that a _start export was not passed. | |
| 66 | - const wasi = new WASI({}); | ||
| 66 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 67 | 67 | const wasm = await WebAssembly.compile(bufferSource); | |
| 68 | 68 | const instance = await WebAssembly.instantiate(wasm); | |
| 69 | 69 | ||
@@ -88,7 +88,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 88 | 88 | ||
| 89 | 89 | { | |
| 90 | 90 | // Verify that a memory export was passed. | |
| 91 | - const wasi = new WASI({}); | ||
| 91 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 92 | 92 | const wasm = await WebAssembly.compile(bufferSource); | |
| 93 | 93 | const instance = await WebAssembly.instantiate(wasm); | |
| 94 | 94 | ||
@@ -106,7 +106,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 106 | 106 | ||
| 107 | 107 | { | |
| 108 | 108 | // Verify that a WebAssembly.Instance from another VM context is accepted. | |
| 109 | - const wasi = new WASI({}); | ||
| 109 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 110 | 110 | const instance = await vm.runInNewContext(` | |
| 111 | 111 | (async () => { | |
| 112 | 112 | const wasm = await WebAssembly.compile(bufferSource); | |
@@ -130,7 +130,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 130 | 130 | ||
| 131 | 131 | { | |
| 132 | 132 | // Verify that initialize() can only be called once. | |
| 133 | - const wasi = new WASI({}); | ||
| 133 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 134 | 134 | const wasm = await WebAssembly.compile(bufferSource); | |
| 135 | 135 | const instance = await WebAssembly.instantiate(wasm); | |
| 136 | 136 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ if (process.argv[2] === 'wasi-child') { | |||
| 8 | 8 | ||
| 9 | 9 | const { WASI } = require('wasi'); | |
| 10 | 10 | const wasi = new WASI({ | |
| 11 | + version: 'preview1', | ||
| 11 | 12 | args: ['foo', '-bar', '--baz=value'], | |
| 12 | 13 | }); | |
| 13 | 14 | const importObject = { wasi_snapshot_preview1: wasi.wasiImport }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,34 +5,34 @@ const assert = require('assert'); | |||
| 5 | 5 | const { WASI } = require('wasi'); | |
| 6 | 6 | ||
| 7 | 7 | // If args is undefined, it should default to [] and should not throw. | |
| 8 | - new WASI({}); | ||
| 8 | + new WASI({ version: 'preview1' }); | ||
| 9 | 9 | ||
| 10 | 10 | // If args is not an Array and not undefined, it should throw. | |
| 11 | - assert.throws(() => { new WASI({ args: 'fhqwhgads' }); }, | ||
| 11 | + assert.throws(() => { new WASI({ version: 'preview1', args: 'fhqwhgads' }); }, | ||
| 12 | 12 | { code: 'ERR_INVALID_ARG_TYPE', message: /\bargs\b/ }); | |
| 13 | 13 | ||
| 14 | 14 | // If env is not an Object and not undefined, it should throw. | |
| 15 | - assert.throws(() => { new WASI({ env: 'fhqwhgads' }); }, | ||
| 15 | + assert.throws(() => { new WASI({ version: 'preview1', env: 'fhqwhgads' }); }, | ||
| 16 | 16 | { code: 'ERR_INVALID_ARG_TYPE', message: /\benv\b/ }); | |
| 17 | 17 | ||
| 18 | 18 | // If preopens is not an Object and not undefined, it should throw. | |
| 19 | - assert.throws(() => { new WASI({ preopens: 'fhqwhgads' }); }, | ||
| 19 | + assert.throws(() => { new WASI({ version: 'preview1', preopens: 'fhqwhgads' }); }, | ||
| 20 | 20 | { code: 'ERR_INVALID_ARG_TYPE', message: /\bpreopens\b/ }); | |
| 21 | 21 | ||
| 22 | 22 | // If returnOnExit is not a boolean and not undefined, it should throw. | |
| 23 | - assert.throws(() => { new WASI({ returnOnExit: 'fhqwhgads' }); }, | ||
| 23 | + assert.throws(() => { new WASI({ version: 'preview1', returnOnExit: 'fhqwhgads' }); }, | ||
| 24 | 24 | { code: 'ERR_INVALID_ARG_TYPE', message: /\breturnOnExit\b/ }); | |
| 25 | 25 | ||
| 26 | 26 | // If stdin is not an int32 and not undefined, it should throw. | |
| 27 | - assert.throws(() => { new WASI({ stdin: 'fhqwhgads' }); }, | ||
| 27 | + assert.throws(() => { new WASI({ version: 'preview1', stdin: 'fhqwhgads' }); }, | ||
| 28 | 28 | { code: 'ERR_INVALID_ARG_TYPE', message: /\bstdin\b/ }); | |
| 29 | 29 | ||
| 30 | 30 | // If stdout is not an int32 and not undefined, it should throw. | |
| 31 | - assert.throws(() => { new WASI({ stdout: 'fhqwhgads' }); }, | ||
| 31 | + assert.throws(() => { new WASI({ version: 'preview1', stdout: 'fhqwhgads' }); }, | ||
| 32 | 32 | { code: 'ERR_INVALID_ARG_TYPE', message: /\bstdout\b/ }); | |
| 33 | 33 | ||
| 34 | 34 | // If stderr is not an int32 and not undefined, it should throw. | |
| 35 | - assert.throws(() => { new WASI({ stderr: 'fhqwhgads' }); }, | ||
| 35 | + assert.throws(() => { new WASI({ version: 'preview1', stderr: 'fhqwhgads' }); }, | ||
| 36 | 36 | { code: 'ERR_INVALID_ARG_TYPE', message: /\bstderr\b/ }); | |
| 37 | 37 | ||
| 38 | 38 | // If options is provided, but not an object, the constructor should throw. | |
@@ -43,13 +43,16 @@ assert.throws(() => { new WASI({ stderr: 'fhqwhgads' }); }, | |||
| 43 | 43 | ||
| 44 | 44 | // Verify that exceptions thrown from the binding layer are handled. | |
| 45 | 45 | assert.throws(() => { | |
| 46 | - new WASI({ preopens: { '/sandbox': '__/not/real/path' } }); | ||
| 46 | + new WASI({ version: 'preview1', preopens: { '/sandbox': '__/not/real/path' } }); | ||
| 47 | 47 | }, { code: 'UVWASI_ENOENT', message: /uvwasi_init/ }); | |
| 48 | 48 | ||
| 49 | 49 | // If version is not a string, it should throw | |
| 50 | 50 | assert.throws(() => { new WASI({ version: { x: 'y' } }); }, | |
| 51 | 51 | { code: 'ERR_INVALID_ARG_TYPE', message: /\bversion\b/ }); | |
| 52 | 52 | ||
| 53 | + // If version is not specified, it should throw. | ||
| 54 | + assert.throws(() => { new WASI(); }, | ||
| 55 | + { code: 'ERR_INVALID_ARG_TYPE', message: /\bversion\b/ }); | ||
| 53 | 56 | ||
| 54 | 57 | // If version is an unsupported version, it should throw | |
| 55 | 58 | assert.throws(() => { new WASI({ version: 'not_a_version' }); }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 11 | 11 | (async () => { | |
| 12 | 12 | { | |
| 13 | 13 | // Verify that a WebAssembly.Instance is passed in. | |
| 14 | - const wasi = new WASI(); | ||
| 14 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 15 | 15 | ||
| 16 | 16 | assert.throws( | |
| 17 | 17 | () => { wasi.start(); }, | |
@@ -24,7 +24,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 24 | 24 | ||
| 25 | 25 | { | |
| 26 | 26 | // Verify that the passed instance has an exports objects. | |
| 27 | - const wasi = new WASI({}); | ||
| 27 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 28 | 28 | const wasm = await WebAssembly.compile(bufferSource); | |
| 29 | 29 | const instance = await WebAssembly.instantiate(wasm); | |
| 30 | 30 | ||
@@ -40,7 +40,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 40 | 40 | ||
| 41 | 41 | { | |
| 42 | 42 | // Verify that a _start() export was passed. | |
| 43 | - const wasi = new WASI({}); | ||
| 43 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 44 | 44 | const wasm = await WebAssembly.compile(bufferSource); | |
| 45 | 45 | const instance = await WebAssembly.instantiate(wasm); | |
| 46 | 46 | ||
@@ -60,7 +60,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 60 | 60 | ||
| 61 | 61 | { | |
| 62 | 62 | // Verify that an _initialize export was not passed. | |
| 63 | - const wasi = new WASI({}); | ||
| 63 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 64 | 64 | const wasm = await WebAssembly.compile(bufferSource); | |
| 65 | 65 | const instance = await WebAssembly.instantiate(wasm); | |
| 66 | 66 | ||
@@ -85,7 +85,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 85 | 85 | ||
| 86 | 86 | { | |
| 87 | 87 | // Verify that a memory export was passed. | |
| 88 | - const wasi = new WASI({}); | ||
| 88 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 89 | 89 | const wasm = await WebAssembly.compile(bufferSource); | |
| 90 | 90 | const instance = await WebAssembly.instantiate(wasm); | |
| 91 | 91 | ||
@@ -103,7 +103,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 103 | 103 | ||
| 104 | 104 | { | |
| 105 | 105 | // Verify that a WebAssembly.Instance from another VM context is accepted. | |
| 106 | - const wasi = new WASI({}); | ||
| 106 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 107 | 107 | const instance = await vm.runInNewContext(` | |
| 108 | 108 | (async () => { | |
| 109 | 109 | const wasm = await WebAssembly.compile(bufferSource); | |
@@ -127,7 +127,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); | |||
| 127 | 127 | ||
| 128 | 128 | { | |
| 129 | 129 | // Verify that start() can only be called once. | |
| 130 | - const wasi = new WASI({}); | ||
| 130 | + const wasi = new WASI({ version: 'preview1' }); | ||
| 131 | 131 | const wasm = await WebAssembly.compile(bufferSource); | |
| 132 | 132 | const instance = await WebAssembly.instantiate(wasm); | |
| 133 | 133 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ writeFileSync(stdinFile, 'x'.repeat(33)); | |||
| 18 | 18 | const stdin = openSync(stdinFile, 'r'); | |
| 19 | 19 | const stdout = openSync(stdoutFile, 'a'); | |
| 20 | 20 | const stderr = openSync(stderrFile, 'a'); | |
| 21 | - const wasi = new WASI({ stdin, stdout, stderr, returnOnExit: true }); | ||
| 21 | + const wasi = new WASI({ version: 'preview1', stdin, stdout, stderr, returnOnExit: true }); | ||
| 22 | 22 | const importObject = { wasi_snapshot_preview1: wasi.wasiImport }; | |
| 23 | 23 | ||
| 24 | 24 | (async () => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ if (process.argv[2] === 'wasi-child') { | |||
| 10 | 10 | const { WASI } = require('wasi'); | |
| 11 | 11 | const wasmDir = path.join(__dirname, 'wasm'); | |
| 12 | 12 | const wasi = new WASI({ | |
| 13 | + version: 'preview1', | ||
| 13 | 14 | args: [], | |
| 14 | 15 | env: process.env, | |
| 15 | 16 | preopens: { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,7 +34,7 @@ if (!process.env.HAS_STARTED_WORKER) { | |||
| 34 | 34 | } | |
| 35 | 35 | ||
| 36 | 36 | async function go() { | |
| 37 | - const wasi = new WASI({ returnOnExit: true }); | ||
| 37 | + const wasi = new WASI({ version: 'preview1', returnOnExit: true }); | ||
| 38 | 38 | const imports = { wasi_snapshot_preview1: wasi.wasiImport }; | |
| 39 | 39 | const module = await WebAssembly.compile(bytecode); | |
| 40 | 40 | const instance = await WebAssembly.instantiate(module, imports); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments