From 5c81b8d814dd8beca67511c0bf94e5aca5fbc49a Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 4 Mar 2020 20:46:02 -0500 Subject: [PATCH] wasi: add returnOnExit option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a WASI option allowing the __wasi_proc_exit() function to return an exit code instead of forcefully terminating the process. PR-URL: https://github.com/nodejs/node/pull/32101 Fixes: https://github.com/nodejs/node/issues/32093 Reviewed-By: James M Snell Reviewed-By: Gus Caplan Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: Tobias Nießen --- doc/api/wasi.md | 4 +++ lib/wasi.js | 39 ++++++++++++++++++++--- test/wasi/test-return-on-exit.js | 18 +++++++++++ test/wasi/test-wasi-options-validation.js | 4 +++ 4 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 test/wasi/test-return-on-exit.js diff --git a/doc/api/wasi.md b/doc/api/wasi.md index c29a83c889a517..622de02ff85c23 100644 --- a/doc/api/wasi.md +++ b/doc/api/wasi.md @@ -58,6 +58,10 @@ added: v12.16.0 sandbox directory structure. The string keys of `preopens` are treated as directories within the sandbox. The corresponding values in `preopens` are the real paths to those directories on the host machine. + * `returnOnExit` {boolean} By default, WASI applications terminate the Node.js + process via the `__wasi_proc_exit()` function. Setting this option to `true` + causes `wasi.start()` to return the exit code rather than terminate the + process. **Default:** `false`. ### `wasi.start(instance)`