1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

chore(core): Deduplicate event_loop_pending_state (#17039)

This commit is contained in:
Andreu Botella 2022-12-13 23:28:38 +01:00 committed by GitHub
parent 3551955b63
commit 929847c722
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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(),
)
}
}
@ -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