Skip to content

Commit

Permalink
chore(core): Deduplicate event_loop_pending_state (denoland#17039)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreubotella committed Dec 13, 2022
1 parent 3551955 commit 929847c
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions core/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,40 +1242,21 @@ impl JsRuntime {
}

fn event_loop_pending_state(&mut self) -> EventLoopPendingState {
let isolate = self.v8_isolate.as_mut().unwrap();
let state = self.state.borrow_mut();
let module_map = self.module_map.as_mut().unwrap().borrow();

EventLoopPendingState {
has_pending_refed_ops: state.pending_ops.len() > state.unrefed_ops.len(),
has_pending_dyn_imports: module_map.has_pending_dynamic_imports(),
has_pending_dyn_module_evaluation: !state
.pending_dyn_mod_evaluate
.is_empty(),
has_pending_module_evaluation: state.pending_mod_evaluate.is_some(),
has_pending_background_tasks: isolate.has_pending_background_tasks(),
has_tick_scheduled: state.has_tick_scheduled,
}
EventLoopPendingState::new(
self.v8_isolate.as_mut().unwrap(),
&mut self.state.borrow_mut(),
&self.module_map.as_ref().unwrap().borrow(),
)
}

pub(crate) fn event_loop_pending_state_from_isolate(
isolate: &mut v8::Isolate,
) -> EventLoopPendingState {
let state_rc = Self::state(isolate);
let module_map_rc = Self::module_map(isolate);
let state = state_rc.borrow_mut();
let module_map = module_map_rc.borrow();

EventLoopPendingState {
has_pending_refed_ops: state.pending_ops.len() > state.unrefed_ops.len(),
has_pending_dyn_imports: module_map.has_pending_dynamic_imports(),
has_pending_dyn_module_evaluation: !state
.pending_dyn_mod_evaluate
.is_empty(),
has_pending_module_evaluation: state.pending_mod_evaluate.is_some(),
has_pending_background_tasks: isolate.has_pending_background_tasks(),
has_tick_scheduled: state.has_tick_scheduled,
}
EventLoopPendingState::new(
isolate,
&mut Self::state(isolate).borrow_mut(),
&Self::module_map(isolate).borrow(),
)
}
}

Expand Down Expand Up @@ -1342,6 +1323,23 @@ pub(crate) struct EventLoopPendingState {
has_tick_scheduled: bool,
}
impl EventLoopPendingState {
pub fn new(
isolate: &mut v8::Isolate,
state: &mut JsRuntimeState,
module_map: &ModuleMap,
) -> EventLoopPendingState {
EventLoopPendingState {
has_pending_refed_ops: state.pending_ops.len() > state.unrefed_ops.len(),
has_pending_dyn_imports: module_map.has_pending_dynamic_imports(),
has_pending_dyn_module_evaluation: !state
.pending_dyn_mod_evaluate
.is_empty(),
has_pending_module_evaluation: state.pending_mod_evaluate.is_some(),
has_pending_background_tasks: isolate.has_pending_background_tasks(),
has_tick_scheduled: state.has_tick_scheduled,
}
}

pub fn is_pending(&self) -> bool {
self.has_pending_refed_ops
|| self.has_pending_dyn_imports
Expand Down

0 comments on commit 929847c

Please sign in to comment.