diff options
author | Luke Edwards <lukeed@github.com> | 2024-05-29 16:16:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-29 23:16:27 +0000 |
commit | 13723f267eb87f8c28ef0769cdf7e233b971326e (patch) | |
tree | fd97b4c13889aa657601440678f2e31316d8e47d /runtime/ops | |
parent | cf611fbf548ea0bbd38c82ab02249b7a2aa3b3c9 (diff) |
feat: Add `Deno.exitCode` API (#23609)
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 <biwanczuk@gmail.com>
Diffstat (limited to 'runtime/ops')
-rw-r--r-- | runtime/ops/os/mod.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index 7a71590ba..f6f55f68f 100644 --- a/runtime/ops/os/mod.rs +++ b/runtime/ops/os/mod.rs @@ -32,6 +32,7 @@ deno_core::extension!( op_os_uptime, op_set_env, op_set_exit_code, + op_get_exit_code, op_system_memory_info, op_uid, op_runtime_memory_usage, @@ -60,12 +61,13 @@ deno_core::extension!( op_os_uptime, op_set_env, op_set_exit_code, + op_get_exit_code, op_system_memory_info, op_uid, op_runtime_memory_usage, ], middleware = |op| match op.name { - "op_exit" | "op_set_exit_code" => + "op_exit" | "op_set_exit_code" | "op_get_exit_code" => op.with_implementation_from(&deno_core::op_void_sync()), _ => op, }, @@ -165,6 +167,12 @@ fn op_set_exit_code(state: &mut OpState, #[smi] code: i32) { } #[op2(fast)] +#[smi] +fn op_get_exit_code(state: &mut OpState) -> i32 { + state.borrow_mut::<ExitCode>().get() +} + +#[op2(fast)] fn op_exit(state: &mut OpState) { let code = state.borrow::<ExitCode>().get(); std::process::exit(code) |