mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00:00
refactor: cleanup cli/main.rs (#13160)
This commit is contained in:
parent
9825c876b4
commit
907cef563e
6 changed files with 207 additions and 206 deletions
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue