summaryrefslogtreecommitdiff
path: root/runtime/worker.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-06-22 01:45:41 +0200
committerGitHub <noreply@github.com>2021-06-22 01:45:41 +0200
commit9105892ec8b454571c56883eace557eee25b3301 (patch)
tree965d90e3a885c2f870f58eef921d8811a9a491b9 /runtime/worker.rs
parenta5eb2dfc93afc2899ed6e1ad2b3e029157889f7c (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 'runtime/worker.rs')
-rw-r--r--runtime/worker.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/runtime/worker.rs b/runtime/worker.rs
index 58a2e8a9a..7bfb1506b 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -7,10 +7,10 @@ use crate::ops;
use crate::permissions::Permissions;
use deno_broadcast_channel::InMemoryBroadcastChannel;
use deno_core::error::AnyError;
-use deno_core::error::Context as ErrorContext;
use deno_core::futures::future::poll_fn;
use deno_core::futures::stream::StreamExt;
use deno_core::futures::Future;
+use deno_core::located_script_name;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::url::Url;
@@ -177,17 +177,17 @@ impl MainWorker {
serde_json::to_string_pretty(&runtime_options).unwrap()
);
self
- .execute(&script)
+ .execute_script(&located_script_name!(), &script)
.expect("Failed to execute bootstrap script");
}
- /// Same as execute2() but the filename defaults to "$CWD/__anonymous__".
- pub fn execute(&mut self, js_source: &str) -> Result<(), AnyError> {
- let path = env::current_dir()
- .context("Failed to get current working directory")?
- .join("__anonymous__");
- let url = Url::from_file_path(path).unwrap();
- self.js_runtime.execute(url.as_str(), js_source)
+ /// See [JsRuntime::execute_script](deno_core::JsRuntime::execute_script)
+ pub fn execute_script(
+ &mut self,
+ name: &str,
+ source_code: &str,
+ ) -> Result<(), AnyError> {
+ self.js_runtime.execute_script(name, source_code)
}
/// Loads and instantiates specified JavaScript module.