Skip to content

Commit 75c1d1b

Browse files
mhdawsontargos
authored andcommitted
wasi: make returnOnExit true by default
Refs: #46923 Signed-off-by: Michael Dawson <[email protected]> PR-URL: #47390 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2664536 commit 75c1d1b

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

doc/api/wasi.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ changes:
121121
- version: v20.0.0
122122
pr-url: https://github.com/nodejs/node/pull/47391
123123
description: The version option is now required and has no default value.
124+
- version: REPLACEME
125+
pr-url: https://github.com/nodejs/node/pull/47390
126+
description: default value of returnOnExit changed to true.
124127
- version: v19.8.0
125128
pr-url: https://github.com/nodejs/node/pull/46469
126129
description: version field added to options.
@@ -136,10 +139,11 @@ changes:
136139
sandbox directory structure. The string keys of `preopens` are treated as
137140
directories within the sandbox. The corresponding values in `preopens` are
138141
the real paths to those directories on the host machine.
139-
* `returnOnExit` {boolean} By default, WASI applications terminate the Node.js
140-
process via the `__wasi_proc_exit()` function. Setting this option to `true`
141-
causes `wasi.start()` to return the exit code rather than terminate the
142-
process. **Default:** `false`.
142+
* `returnOnExit` {boolean} By default, when WASI applications call
143+
`__wasi_proc_exit()` `wasi.start()` will return with the exit code
144+
specified rather than terminatng the process. Setting this option to
145+
`false` will cause the Node.js process to exit with the specified
146+
exit code instead. **Default:** `true`.
143147
* `stdin` {integer} The file descriptor used as standard input in the
144148
WebAssembly application. **Default:** `0`.
145149
* `stdout` {integer} The file descriptor used as standard output in the

lib/wasi.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ class WASI {
102102
wrap[prop] = FunctionPrototypeBind(wrap[prop], wrap);
103103
}
104104

105+
let returnOnExit = true;
105106
if (options.returnOnExit !== undefined) {
106107
validateBoolean(options.returnOnExit, 'options.returnOnExit');
107-
if (options.returnOnExit)
108-
wrap.proc_exit = FunctionPrototypeBind(wasiReturnOnProcExit, this);
108+
returnOnExit = options.returnOnExit;
109109
}
110+
if (returnOnExit)
111+
wrap.proc_exit = FunctionPrototypeBind(wasiReturnOnProcExit, this);
110112

111113
this[kSetMemory] = wrap._setMemory;
112114
delete wrap._setMemory;

test/wasi/test-wasi.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
'use strict';
22
const common = require('../common');
33

4+
function returnOnExitEnvToValue(env) {
5+
const envValue = env.RETURN_ON_EXIT;
6+
if (envValue === undefined) {
7+
return undefined;
8+
}
9+
10+
return envValue === 'true';
11+
}
12+
413
if (process.argv[2] === 'wasi-child-preview1') {
514
// Test version set to preview1
615
const assert = require('assert');
@@ -23,6 +32,7 @@ if (process.argv[2] === 'wasi-child-preview1') {
2332
'/sandbox': fixtures.path('wasi'),
2433
'/tmp': tmpdir.path,
2534
},
35+
returnOnExit: returnOnExitEnvToValue(process.env),
2636
});
2737

2838
// Validate the getImportObject helper
@@ -56,6 +66,10 @@ if (process.argv[2] === 'wasi-child-preview1') {
5666
if (options.stdin !== undefined)
5767
opts.input = options.stdin;
5868

69+
if ('returnOnExit' in options) {
70+
opts.env.RETURN_ON_EXIT = options.returnOnExit;
71+
}
72+
5973
const child = cp.spawnSync(process.execPath, [
6074
...args,
6175
__filename,
@@ -79,7 +93,9 @@ if (process.argv[2] === 'wasi-child-preview1') {
7993
if (!common.isIBMi) {
8094
runWASI({ test: 'clock_getres' });
8195
}
82-
runWASI({ test: 'exitcode', exitCode: 120 });
96+
runWASI({ test: 'exitcode' });
97+
runWASI({ test: 'exitcode', returnOnExit: true });
98+
runWASI({ test: 'exitcode', exitCode: 120, returnOnExit: false });
8399
runWASI({ test: 'fd_prestat_get_refresh' });
84100
runWASI({ test: 'freopen', stdout: `hello from input2.txt${checkoutEOL}` });
85101
runWASI({ test: 'ftruncate' });

0 commit comments

Comments
 (0)