From 13723f267eb87f8c28ef0769cdf7e233b971326e Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Wed, 29 May 2024 16:16:27 -0700 Subject: feat: Add `Deno.exitCode` API (#23609) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commits adds the ability to set a would-be exit code for the Deno process without forcing an immediate exit, through the new `Deno.exitCode` API. - **Implements `Deno.exitCode` getter and setter**: Adds support for setting and retrieving a would-be exit code via `Deno.exitCode`. This allows for asynchronous cleanup before process termination without immediately exiting. - **Ensures type safety**: The setter for `Deno.exitCode` validates that the provided value is a number, throwing a TypeError if not, to ensure that only valid exit codes are set. Closes to #23605 --------- Co-authored-by: Bartek IwaƄczuk --- tests/specs/run/exit_code/__test__.jsonc | 5 +++++ tests/specs/run/exit_code/main.js | 7 +++++++ tests/specs/run/exit_code/main.out | 1 + 3 files changed, 13 insertions(+) create mode 100644 tests/specs/run/exit_code/__test__.jsonc create mode 100644 tests/specs/run/exit_code/main.js create mode 100644 tests/specs/run/exit_code/main.out (limited to 'tests/specs/run/exit_code') diff --git a/tests/specs/run/exit_code/__test__.jsonc b/tests/specs/run/exit_code/__test__.jsonc new file mode 100644 index 000000000..977f8b0e3 --- /dev/null +++ b/tests/specs/run/exit_code/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run main.js", + "exitCode": 42, + "output": "main.out" +} diff --git a/tests/specs/run/exit_code/main.js b/tests/specs/run/exit_code/main.js new file mode 100644 index 000000000..1ba1f06c4 --- /dev/null +++ b/tests/specs/run/exit_code/main.js @@ -0,0 +1,7 @@ +if (Deno.exitCode != 0) { + throw new Error("boom!"); +} + +Deno.exitCode = 42; + +console.log("Deno.exitCode", Deno.exitCode); diff --git a/tests/specs/run/exit_code/main.out b/tests/specs/run/exit_code/main.out new file mode 100644 index 000000000..25f2de2d5 --- /dev/null +++ b/tests/specs/run/exit_code/main.out @@ -0,0 +1 @@ +Deno.exitCode 42 -- cgit v1.2.3