mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00:00
refactor: ensure exit code reference is passed to all workers (#14814)
This commit is contained in:
parent
4911acb148
commit
ba13b8e2a9
5 changed files with 31 additions and 30 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue