diff options
author | Colin Ihrig <cjihrig@gmail.com> | 2022-06-28 10:49:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-28 10:49:30 -0400 |
commit | 0f6a5c5fc24e8dc9125c5c536c8547a86ca87b15 (patch) | |
tree | 41538ee1df06dc80d60e49ed50177f99ba8dc297 /core/runtime.rs | |
parent | ab11b45d1d2678cfea2217ac72fc24317eef777d (diff) |
feat(web): add beforeunload event (#14830)
This commit adds the 'beforeunload' event.
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'core/runtime.rs')
-rw-r--r-- | core/runtime.rs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/core/runtime.rs b/core/runtime.rs index 23fe73013..8b150e4e9 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -90,14 +90,14 @@ pub struct JsRuntime { event_loop_middlewares: Vec<Box<OpEventLoopFn>>, } -struct DynImportModEvaluate { +pub(crate) struct DynImportModEvaluate { load_id: ModuleLoadId, module_id: ModuleId, promise: v8::Global<v8::Promise>, module: v8::Global<v8::Module>, } -struct ModEvaluate { +pub(crate) struct ModEvaluate { promise: v8::Global<v8::Promise>, sender: oneshot::Sender<Result<(), Error>>, } @@ -158,8 +158,8 @@ pub(crate) struct JsRuntimeState { pub(crate) js_wasm_streaming_cb: Option<v8::Global<v8::Function>>, pub(crate) pending_promise_exceptions: HashMap<v8::Global<v8::Promise>, v8::Global<v8::Value>>, - pending_dyn_mod_evaluate: Vec<DynImportModEvaluate>, - pending_mod_evaluate: Option<ModEvaluate>, + pub(crate) pending_dyn_mod_evaluate: Vec<DynImportModEvaluate>, + pub(crate) pending_mod_evaluate: Option<ModEvaluate>, /// A counter used to delay our dynamic import deadlock detection by one spin /// of the event loop. dyn_module_evaluate_idle_counter: u32, @@ -1021,6 +1021,30 @@ Pending dynamic modules:\n".to_string(); Poll::Pending } + + pub fn event_loop_has_work(&mut self) -> bool { + let state_rc = Self::state(self.v8_isolate()); + let module_map_rc = Self::module_map(self.v8_isolate()); + let state = state_rc.borrow_mut(); + let module_map = module_map_rc.borrow(); + + let has_pending_refed_ops = + state.pending_ops.len() > state.unrefed_ops.len(); + let has_pending_dyn_imports = module_map.has_pending_dynamic_imports(); + let has_pending_dyn_module_evaluation = + !state.pending_dyn_mod_evaluate.is_empty(); + let has_pending_module_evaluation = state.pending_mod_evaluate.is_some(); + let has_pending_background_tasks = + self.v8_isolate().has_pending_background_tasks(); + let has_tick_scheduled = state.has_tick_scheduled; + + has_pending_refed_ops + || has_pending_dyn_imports + || has_pending_dyn_module_evaluation + || has_pending_module_evaluation + || has_pending_background_tasks + || has_tick_scheduled + } } extern "C" fn near_heap_limit_callback<F>( |