From 993a1dd41ae5f96bdb24b09757e24c2ac24126d0 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 28 Nov 2021 00:45:38 +0100 Subject: feat(runtime): add op_set_exit_code (#12911) Set the exit code to use if none is provided to Deno.exit(), or when Deno exits naturally. Needed for process.exitCode Node compat. Paves the way for #12888. --- runtime/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'runtime/lib.rs') diff --git a/runtime/lib.rs b/runtime/lib.rs index fb6159dd9..ca250ce20 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -1,5 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +use std::sync::atomic::AtomicI32; + pub use deno_broadcast_channel; pub use deno_console; pub use deno_crypto; @@ -29,3 +31,12 @@ pub mod worker; mod worker_bootstrap; pub use worker_bootstrap::BootstrapOptions; + +// The global may not be very elegant but: +// +// 1. op_exit() calls std::process::exit() so there is not much point storing +// the exit code in runtime state +// +// 2. storing it in runtime state makes retrieving it again in cli/main.rs +// unduly complicated +pub static EXIT_CODE: AtomicI32 = AtomicI32::new(0); -- cgit v1.2.3