summaryrefslogtreecommitdiff
path: root/cli/worker.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-04-15 19:08:33 +0100
committerGitHub <noreply@github.com>2024-04-15 20:08:33 +0200
commita080acc1b46ce9915760ce5c818763c64be8dca1 (patch)
treecbc44ea39628283b4ba73b6941bc2f9528b5b528 /cli/worker.rs
parentf36a8951a420e34d8189cda5792f5eeaa5ce85b7 (diff)
refactor: move lifecycle events dispatch to Rust (#23358)
This commit moves logic of dispatching lifecycle events ( "load", "beforeunload", "unload") to be triggered from Rust. Before that we were executing scripts from Rust, but now we are storing references to functions from "99_main.js" and calling them directly. Prerequisite for https://github.com/denoland/deno/issues/23342
Diffstat (limited to 'cli/worker.rs')
-rw-r--r--cli/worker.rs31
1 files changed, 7 insertions, 24 deletions
diff --git a/cli/worker.rs b/cli/worker.rs
index ed82f4872..74ae1ef8f 100644
--- a/cli/worker.rs
+++ b/cli/worker.rs
@@ -10,7 +10,6 @@ use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_core::futures::FutureExt;
-use deno_core::located_script_name;
use deno_core::parking_lot::Mutex;
use deno_core::url::Url;
use deno_core::v8;
@@ -182,7 +181,7 @@ impl CliMainWorker {
self.execute_main_module_possibly_with_npm().await?;
}
- self.worker.dispatch_load_event(located_script_name!())?;
+ self.worker.dispatch_load_event()?;
loop {
if let Some(hmr_runner) = maybe_hmr_runner.as_mut() {
@@ -213,15 +212,12 @@ impl CliMainWorker {
.await?;
}
- if !self
- .worker
- .dispatch_beforeunload_event(located_script_name!())?
- {
+ if !self.worker.dispatch_beforeunload_event()? {
break;
}
}
- self.worker.dispatch_unload_event(located_script_name!())?;
+ self.worker.dispatch_unload_event()?;
if let Some(coverage_collector) = maybe_coverage_collector.as_mut() {
self
@@ -268,10 +264,7 @@ impl CliMainWorker {
/// respectively.
pub async fn execute(&mut self) -> Result<(), AnyError> {
self.inner.execute_main_module_possibly_with_npm().await?;
- self
- .inner
- .worker
- .dispatch_load_event(located_script_name!())?;
+ self.inner.worker.dispatch_load_event()?;
self.pending_unload = true;
let result = loop {
@@ -279,11 +272,7 @@ impl CliMainWorker {
Ok(()) => {}
Err(error) => break Err(error),
}
- match self
- .inner
- .worker
- .dispatch_beforeunload_event(located_script_name!())
- {
+ match self.inner.worker.dispatch_beforeunload_event() {
Ok(default_prevented) if default_prevented => {} // continue loop
Ok(_) => break Ok(()),
Err(error) => break Err(error),
@@ -293,10 +282,7 @@ impl CliMainWorker {
result?;
- self
- .inner
- .worker
- .dispatch_unload_event(located_script_name!())?;
+ self.inner.worker.dispatch_unload_event()?;
Ok(())
}
@@ -305,10 +291,7 @@ impl CliMainWorker {
impl Drop for FileWatcherModuleExecutor {
fn drop(&mut self) {
if self.pending_unload {
- let _ = self
- .inner
- .worker
- .dispatch_unload_event(located_script_name!());
+ let _ = self.inner.worker.dispatch_unload_event();
}
}
}