diff options
Diffstat (limited to 'runtime/worker.rs')
-rw-r--r-- | runtime/worker.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/runtime/worker.rs b/runtime/worker.rs index 4c38d232f..94c05cd82 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -35,6 +35,18 @@ use std::task::Poll; pub type FormatJsErrorFn = dyn Fn(&JsError) -> String + Sync + Send; +#[derive(Clone)] +pub struct ExitCode(Arc<AtomicI32>); + +impl ExitCode { + pub fn get(&self) -> i32 { + self.0.load(Relaxed) + } + + pub fn set(&mut self, code: i32) { + self.0.store(code, Relaxed); + } +} /// This worker is created and used by almost all /// subcommands in Deno executable. /// @@ -45,6 +57,7 @@ pub type FormatJsErrorFn = dyn Fn(&JsError) -> String + Sync + Send; pub struct MainWorker { pub js_runtime: JsRuntime, should_break_on_first_statement: bool, + exit_code: ExitCode, } pub struct WorkerOptions { @@ -98,6 +111,7 @@ impl MainWorker { Ok(()) }) .build(); + let exit_code = ExitCode(Arc::new(AtomicI32::new(0))); // Internal modules let mut extensions: Vec<Extension> = vec![ @@ -147,7 +161,7 @@ impl MainWorker { unstable, options.unsafely_ignore_certificate_errors.clone(), ), - ops::os::init(None), + ops::os::init(exit_code.clone()), ops::permissions::init(), ops::process::init(), ops::signal::init(), @@ -181,6 +195,7 @@ impl MainWorker { Self { js_runtime, should_break_on_first_statement: options.should_break_on_first_statement, + exit_code, } } @@ -314,11 +329,8 @@ impl MainWorker { /// Return exit code set by the executed code (either in main worker /// or one of child web workers). - pub fn get_exit_code(&mut self) -> i32 { - let op_state_rc = self.js_runtime.op_state(); - let op_state = op_state_rc.borrow(); - let exit_code = op_state.borrow::<Arc<AtomicI32>>().load(Relaxed); - exit_code + pub fn get_exit_code(&self) -> i32 { + self.exit_code.get() } /// Dispatches "load" event to the JavaScript runtime. |