From 907cef563ec83fb5e8b95aeddbb54b5ebbf38746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 21 Dec 2021 15:49:27 +0100 Subject: refactor: cleanup cli/main.rs (#13160) --- runtime/worker.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'runtime') diff --git a/runtime/worker.rs b/runtime/worker.rs index 3e245d331..9029ab967 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -184,10 +184,10 @@ impl MainWorker { /// See [JsRuntime::execute_script](deno_core::JsRuntime::execute_script) pub fn execute_script( &mut self, - name: &str, + script_name: &str, source_code: &str, ) -> Result<(), AnyError> { - self.js_runtime.execute_script(name, source_code)?; + self.js_runtime.execute_script(script_name, source_code)?; Ok(()) } @@ -305,6 +305,27 @@ impl MainWorker { let exit_code = op_state.borrow::>().load(Relaxed); exit_code } + + /// Dispatches "load" event to the JavaScript runtime. + /// + /// Does not poll event loop, and thus not await any of the "load" event handlers. + pub fn dispatch_load_event( + &mut self, + script_name: &str, + ) -> Result<(), AnyError> { + self.execute_script(script_name, "window.dispatchEvent(new Event('load'))") + } + + /// Dispatches "unload" event to the JavaScript runtime. + /// + /// Does not poll event loop, and thus not await any of the "unload" event handlers. + pub fn dispatch_unload_event( + &mut self, + script_name: &str, + ) -> Result<(), AnyError> { + self + .execute_script(script_name, "window.dispatchEvent(new Event('unload'))") + } } #[cfg(test)] -- cgit v1.2.3