From 6aff62fcb326bd3d51dbbcf91e63f6d2150488b3 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 3a72442d77f223..27dceaa014f7e8 100644 --- a/doc/api/wasi.md +++ b/doc/api/wasi.md @@ -58,6 +58,10 @@ added: v13.3.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)`