diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-12-21 15:49:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-21 15:49:27 +0100 |
| commit | 907cef563ec83fb5e8b95aeddbb54b5ebbf38746 (patch) | |
| tree | 7695484aa68ee73071229122fa4219321e29a0c1 /runtime | |
| parent | 9825c876b466cf69a8ddd1646ba7fedecd54ba51 (diff) | |
refactor: cleanup cli/main.rs (#13160)
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/worker.rs | 25 |
1 files changed, 23 insertions, 2 deletions
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::<Arc<AtomicI32>>().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)] |
