diff options
Diffstat (limited to 'runtime/worker.rs')
-rw-r--r-- | runtime/worker.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/runtime/worker.rs b/runtime/worker.rs index 48bf7b09f..ea1e5e046 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -11,6 +11,7 @@ use std::task::Poll; use deno_broadcast_channel::InMemoryBroadcastChannel; use deno_cache::CreateCache; use deno_cache::SqliteBackedCache; +use deno_core::ascii_str; use deno_core::error::AnyError; use deno_core::error::JsError; use deno_core::futures::Future; @@ -370,10 +371,10 @@ impl MainWorker { } /// See [JsRuntime::execute_script](deno_core::JsRuntime::execute_script) - pub fn execute_script<S: Into<ModuleCode>>( + pub fn execute_script( &mut self, script_name: &'static str, - source_code: S, + source_code: ModuleCode, ) -> Result<v8::Global<v8::Value>, AnyError> { self.js_runtime.execute_script(script_name, source_code) } @@ -510,12 +511,12 @@ impl MainWorker { &mut self, script_name: &'static str, ) -> Result<(), AnyError> { - self.execute_script( + self.js_runtime.execute_script( script_name, // NOTE(@bartlomieju): not using `globalThis` here, because user might delete // it. Instead we're using global `dispatchEvent` function which will // used a saved reference to global scope. - "dispatchEvent(new Event('load'))", + ascii_str!("dispatchEvent(new Event('load'))"), )?; Ok(()) } @@ -527,12 +528,12 @@ impl MainWorker { &mut self, script_name: &'static str, ) -> Result<(), AnyError> { - self.execute_script( + self.js_runtime.execute_script( script_name, // NOTE(@bartlomieju): not using `globalThis` here, because user might delete // it. Instead we're using global `dispatchEvent` function which will // used a saved reference to global scope. - "dispatchEvent(new Event('unload'))", + ascii_str!("dispatchEvent(new Event('unload'))"), )?; Ok(()) } @@ -549,7 +550,9 @@ impl MainWorker { // NOTE(@bartlomieju): not using `globalThis` here, because user might delete // it. Instead we're using global `dispatchEvent` function which will // used a saved reference to global scope. - "dispatchEvent(new Event('beforeunload', { cancelable: true }));", + ascii_str!( + "dispatchEvent(new Event('beforeunload', { cancelable: true }));" + ), )?; let local_value = value.open(&mut self.js_runtime.handle_scope()); Ok(local_value.is_false()) |