mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
wasi: make returnOnExit true by default
Refs: https://github.com/nodejs/node/issues/46923 Signed-off-by: Michael Dawson <mdawson@devrus.com> PR-URL: https://github.com/nodejs/node/pull/47390 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
4bcb42c16c
commit
56ccd599fe
@ -121,6 +121,9 @@ changes:
|
|||||||
- version: REPLACEME
|
- version: REPLACEME
|
||||||
pr-url: https://github.com/nodejs/node/pull/47391
|
pr-url: https://github.com/nodejs/node/pull/47391
|
||||||
description: The version option is now required and has no default value.
|
description: The version option is now required and has no default value.
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/47390
|
||||||
|
description: default value of returnOnExit changed to true.
|
||||||
- version: v19.8.0
|
- version: v19.8.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/46469
|
pr-url: https://github.com/nodejs/node/pull/46469
|
||||||
description: version field added to options.
|
description: version field added to options.
|
||||||
@ -136,10 +139,11 @@ changes:
|
|||||||
sandbox directory structure. The string keys of `preopens` are treated as
|
sandbox directory structure. The string keys of `preopens` are treated as
|
||||||
directories within the sandbox. The corresponding values in `preopens` are
|
directories within the sandbox. The corresponding values in `preopens` are
|
||||||
the real paths to those directories on the host machine.
|
the real paths to those directories on the host machine.
|
||||||
* `returnOnExit` {boolean} By default, WASI applications terminate the Node.js
|
* `returnOnExit` {boolean} By default, when WASI applications call
|
||||||
process via the `__wasi_proc_exit()` function. Setting this option to `true`
|
`__wasi_proc_exit()` `wasi.start()` will return with the exit code
|
||||||
causes `wasi.start()` to return the exit code rather than terminate the
|
specified rather than terminatng the process. Setting this option to
|
||||||
process. **Default:** `false`.
|
`false` will cause the Node.js process to exit with the specified
|
||||||
|
exit code instead. **Default:** `true`.
|
||||||
* `stdin` {integer} The file descriptor used as standard input in the
|
* `stdin` {integer} The file descriptor used as standard input in the
|
||||||
WebAssembly application. **Default:** `0`.
|
WebAssembly application. **Default:** `0`.
|
||||||
* `stdout` {integer} The file descriptor used as standard output in the
|
* `stdout` {integer} The file descriptor used as standard output in the
|
||||||
|
@ -102,11 +102,13 @@ class WASI {
|
|||||||
wrap[prop] = FunctionPrototypeBind(wrap[prop], wrap);
|
wrap[prop] = FunctionPrototypeBind(wrap[prop], wrap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let returnOnExit = true;
|
||||||
if (options.returnOnExit !== undefined) {
|
if (options.returnOnExit !== undefined) {
|
||||||
validateBoolean(options.returnOnExit, 'options.returnOnExit');
|
validateBoolean(options.returnOnExit, 'options.returnOnExit');
|
||||||
if (options.returnOnExit)
|
returnOnExit = options.returnOnExit;
|
||||||
wrap.proc_exit = FunctionPrototypeBind(wasiReturnOnProcExit, this);
|
|
||||||
}
|
}
|
||||||
|
if (returnOnExit)
|
||||||
|
wrap.proc_exit = FunctionPrototypeBind(wasiReturnOnProcExit, this);
|
||||||
|
|
||||||
this[kSetMemory] = wrap._setMemory;
|
this[kSetMemory] = wrap._setMemory;
|
||||||
delete wrap._setMemory;
|
delete wrap._setMemory;
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
|
function returnOnExitEnvToValue(env) {
|
||||||
|
const envValue = env.RETURN_ON_EXIT;
|
||||||
|
if (envValue === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return envValue === 'true';
|
||||||
|
}
|
||||||
|
|
||||||
if (process.argv[2] === 'wasi-child-preview1') {
|
if (process.argv[2] === 'wasi-child-preview1') {
|
||||||
// Test version set to preview1
|
// Test version set to preview1
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
@ -23,6 +32,7 @@ if (process.argv[2] === 'wasi-child-preview1') {
|
|||||||
'/sandbox': fixtures.path('wasi'),
|
'/sandbox': fixtures.path('wasi'),
|
||||||
'/tmp': tmpdir.path,
|
'/tmp': tmpdir.path,
|
||||||
},
|
},
|
||||||
|
returnOnExit: returnOnExitEnvToValue(process.env),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Validate the getImportObject helper
|
// Validate the getImportObject helper
|
||||||
@ -56,6 +66,10 @@ if (process.argv[2] === 'wasi-child-preview1') {
|
|||||||
if (options.stdin !== undefined)
|
if (options.stdin !== undefined)
|
||||||
opts.input = options.stdin;
|
opts.input = options.stdin;
|
||||||
|
|
||||||
|
if ('returnOnExit' in options) {
|
||||||
|
opts.env.RETURN_ON_EXIT = options.returnOnExit;
|
||||||
|
}
|
||||||
|
|
||||||
const child = cp.spawnSync(process.execPath, [
|
const child = cp.spawnSync(process.execPath, [
|
||||||
...args,
|
...args,
|
||||||
__filename,
|
__filename,
|
||||||
@ -79,7 +93,9 @@ if (process.argv[2] === 'wasi-child-preview1') {
|
|||||||
if (!common.isIBMi) {
|
if (!common.isIBMi) {
|
||||||
runWASI({ test: 'clock_getres' });
|
runWASI({ test: 'clock_getres' });
|
||||||
}
|
}
|
||||||
runWASI({ test: 'exitcode', exitCode: 120 });
|
runWASI({ test: 'exitcode' });
|
||||||
|
runWASI({ test: 'exitcode', returnOnExit: true });
|
||||||
|
runWASI({ test: 'exitcode', exitCode: 120, returnOnExit: false });
|
||||||
runWASI({ test: 'fd_prestat_get_refresh' });
|
runWASI({ test: 'fd_prestat_get_refresh' });
|
||||||
runWASI({ test: 'freopen', stdout: `hello from input2.txt${checkoutEOL}` });
|
runWASI({ test: 'freopen', stdout: `hello from input2.txt${checkoutEOL}` });
|
||||||
runWASI({ test: 'ftruncate' });
|
runWASI({ test: 'ftruncate' });
|
||||||
|
Loading…
Reference in New Issue
Block a user