Skip to content

Commit

Permalink
doc: make returnOnExit true by default
Browse files Browse the repository at this point in the history
Refs: nodejs#46923

Signed-off-by: Michael Dawson <mdawson@devrus.com>
  • Loading branch information
mhdawson committed Apr 3, 2023
1 parent 6473f5e commit fc2acf6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/wasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ class WASI {
wrap[prop] = FunctionPrototypeBind(wrap[prop], wrap);
}

let returnOnExit = true;
if (options.returnOnExit !== undefined) {
validateBoolean(options.returnOnExit, 'options.returnOnExit');
if (options.returnOnExit)
wrap.proc_exit = FunctionPrototypeBind(wasiReturnOnProcExit, this);
returnOnExit = options.returnOnExit;
validateBoolean(returnOnExit, 'options.returnOnExit');
}
if (returnOnExit === true)
wrap.proc_exit = FunctionPrototypeBind(wasiReturnOnProcExit, this);

this[kSetMemory] = wrap._setMemory;
delete wrap._setMemory;
Expand Down
17 changes: 16 additions & 1 deletion test/wasi/test-wasi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
'use strict';
const common = require('../common');

function returnOnExitEnvToValue(env) {
const envValue = env.RETURN_ON_EXIT;
if (envValue !== undefined)
return envValue === 'true';

return undefined;
}

if (process.argv[2] === 'wasi-child-default') {
// test default case
const fixtures = require('../common/fixtures');
Expand All @@ -21,6 +29,7 @@ if (process.argv[2] === 'wasi-child-default') {
'/sandbox': fixtures.path('wasi'),
'/tmp': tmpdir.path,
},
returnOnExit: returnOnExitEnvToValue(process.env),
});
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
const modulePath = path.join(wasmDir, `${process.argv[3]}.wasm`);
Expand Down Expand Up @@ -53,6 +62,7 @@ if (process.argv[2] === 'wasi-child-default') {
'/sandbox': fixtures.path('wasi'),
'/tmp': tmpdir.path,
},
returnOnExit: returnOnExitEnvToValue(process.env),
});

// Validate the getImportObject helper
Expand Down Expand Up @@ -86,6 +96,9 @@ if (process.argv[2] === 'wasi-child-default') {
if (options.stdin !== undefined)
opts.input = options.stdin;

if (options.returnOnExit === false)
opts.env.RETURN_ON_EXIT = 'false';

const child = cp.spawnSync(process.execPath, [
...args,
__filename,
Expand All @@ -110,7 +123,9 @@ if (process.argv[2] === 'wasi-child-default') {
if (!common.isIBMi) {
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: 'freopen', stdout: `hello from input2.txt${checkoutEOL}` });
runWASI({ test: 'ftruncate' });
Expand Down

0 comments on commit fc2acf6

Please sign in to comment.