summaryrefslogtreecommitdiff
path: root/runtime/worker.rs
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/worker.rs')
-rw-r--r--runtime/worker.rs25
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)]