diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-06-22 01:45:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-22 01:45:41 +0200 |
commit | 9105892ec8b454571c56883eace557eee25b3301 (patch) | |
tree | 965d90e3a885c2f870f58eef921d8811a9a491b9 /cli/main.rs | |
parent | a5eb2dfc93afc2899ed6e1ad2b3e029157889f7c (diff) |
refactor: unify JavaScript script execution method (#11043)
This commit renames "JsRuntime::execute" to "JsRuntime::execute_script". Additionally
same renames were applied to methods on "deno_runtime::Worker" and
"deno_runtime::WebWorker".
A new macro was added to "deno_core" called "located_script_name" which
returns the name of Rust file alongside line no and col no of that call site.
This macro is useful in combination with "JsRuntime::execute_script"
and allows to provide accurate place where "one-off" JavaScript scripts
are executed for internal runtime functions.
Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/cli/main.rs b/cli/main.rs index 20f9131bf..2586e9b60 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -55,6 +55,7 @@ use deno_core::error::generic_error; use deno_core::error::AnyError; use deno_core::futures::future::FutureExt; use deno_core::futures::Future; +use deno_core::located_script_name; use deno_core::resolve_url_or_path; use deno_core::serde_json; use deno_core::serde_json::json; @@ -554,9 +555,15 @@ async fn eval_command( program_state.file_fetcher.insert_cached(file); debug!("main_module {}", &main_module); worker.execute_module(&main_module).await?; - worker.execute("window.dispatchEvent(new Event('load'))")?; + worker.execute_script( + &located_script_name!(), + "window.dispatchEvent(new Event('load'))", + )?; worker.run_event_loop(false).await?; - worker.execute("window.dispatchEvent(new Event('unload'))")?; + worker.execute_script( + &located_script_name!(), + "window.dispatchEvent(new Event('unload'))", + )?; Ok(()) } @@ -794,9 +801,15 @@ async fn run_from_stdin(flags: Flags) -> Result<(), AnyError> { debug!("main_module {}", main_module); worker.execute_module(&main_module).await?; - worker.execute("window.dispatchEvent(new Event('load'))")?; + worker.execute_script( + &located_script_name!(), + "window.dispatchEvent(new Event('load'))", + )?; worker.run_event_loop(false).await?; - worker.execute("window.dispatchEvent(new Event('unload'))")?; + worker.execute_script( + &located_script_name!(), + "window.dispatchEvent(new Event('unload'))", + )?; Ok(()) } @@ -866,9 +879,15 @@ async fn run_with_watch(flags: Flags, script: String) -> Result<(), AnyError> { ); debug!("main_module {}", main_module); worker.execute_module(&main_module).await?; - worker.execute("window.dispatchEvent(new Event('load'))")?; + worker.execute_script( + &located_script_name!(), + "window.dispatchEvent(new Event('load'))", + )?; worker.run_event_loop(false).await?; - worker.execute("window.dispatchEvent(new Event('unload'))")?; + worker.execute_script( + &located_script_name!(), + "window.dispatchEvent(new Event('unload'))", + )?; Ok(()) } }; @@ -909,11 +928,17 @@ async fn run_command(flags: Flags, script: String) -> Result<(), AnyError> { debug!("main_module {}", main_module); worker.execute_module(&main_module).await?; - worker.execute("window.dispatchEvent(new Event('load'))")?; + worker.execute_script( + &located_script_name!(), + "window.dispatchEvent(new Event('load'))", + )?; worker .run_event_loop(maybe_coverage_collector.is_none()) .await?; - worker.execute("window.dispatchEvent(new Event('unload'))")?; + worker.execute_script( + &located_script_name!(), + "window.dispatchEvent(new Event('unload'))", + )?; if let Some(coverage_collector) = maybe_coverage_collector.as_mut() { worker |