diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/build.rs | 7 | ||||
-rw-r--r-- | runtime/web_worker.rs | 15 | ||||
-rw-r--r-- | runtime/worker.rs | 13 |
3 files changed, 19 insertions, 16 deletions
diff --git a/runtime/build.rs b/runtime/build.rs index 016ece810..ec7c9642c 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -17,11 +17,12 @@ mod startup_snapshot { use deno_core::snapshot_util::*; use deno_core::Extension; use deno_core::ExtensionFileSource; + use deno_core::ModuleCode; use std::path::Path; fn transpile_ts_for_snapshotting( file_source: &ExtensionFileSource, - ) -> Result<String, AnyError> { + ) -> Result<ModuleCode, AnyError> { let media_type = MediaType::from_path(Path::new(&file_source.specifier)); let should_transpile = match media_type { @@ -41,7 +42,7 @@ mod startup_snapshot { let parsed = deno_ast::parse_module(ParseParams { specifier: file_source.specifier.to_string(), - text_info: SourceTextInfo::from_string(code), + text_info: SourceTextInfo::from_string(code.take_as_string()), media_type, capture_tokens: false, scope_analysis: false, @@ -53,7 +54,7 @@ mod startup_snapshot { ..Default::default() })?; - Ok(transpiled_source.text) + Ok(transpiled_source.text.into()) } #[derive(Clone)] diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index c6fbb8370..0aa142da8 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -25,6 +25,7 @@ use deno_core::CompiledWasmModuleStore; use deno_core::Extension; use deno_core::GetErrorClassFn; use deno_core::JsRuntime; +use deno_core::ModuleCode; use deno_core::ModuleId; use deno_core::ModuleLoader; use deno_core::ModuleSpecifier; @@ -575,16 +576,16 @@ impl WebWorker { "#; let poll_for_messages_fn = self .js_runtime - .execute_script(&located_script_name!(), script) + .execute_script(located_script_name!(), script) .expect("Failed to execute worker bootstrap script"); self.poll_for_messages_fn = Some(poll_for_messages_fn); } /// See [JsRuntime::execute_script](deno_core::JsRuntime::execute_script) - pub fn execute_script( + pub fn execute_script<S: Into<ModuleCode>>( &mut self, - name: &str, - source_code: &str, + name: &'static str, + source_code: S, ) -> Result<(), AnyError> { self.js_runtime.execute_script(name, source_code)?; Ok(()) @@ -744,7 +745,7 @@ fn print_worker_error( pub fn run_web_worker( worker: WebWorker, specifier: ModuleSpecifier, - maybe_source_code: Option<String>, + mut maybe_source_code: Option<String>, preload_module_cb: Arc<ops::worker_host::WorkerEventCb>, pre_execute_module_cb: Arc<ops::worker_host::WorkerEventCb>, format_js_error_fn: Option<Arc<FormatJsErrorFn>>, @@ -772,8 +773,8 @@ pub fn run_web_worker( }; // Execute provided source code immediately - let result = if let Some(source_code) = maybe_source_code { - let r = worker.execute_script(&located_script_name!(), &source_code); + let result = if let Some(source_code) = maybe_source_code.take() { + let r = worker.execute_script(located_script_name!(), source_code); worker.start_polling_for_messages(); r } else { diff --git a/runtime/worker.rs b/runtime/worker.rs index a995861c5..a24a22c96 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -21,6 +21,7 @@ use deno_core::FsModuleLoader; use deno_core::GetErrorClassFn; use deno_core::JsRuntime; use deno_core::LocalInspectorSession; +use deno_core::ModuleCode; use deno_core::ModuleId; use deno_core::ModuleLoader; use deno_core::ModuleSpecifier; @@ -364,10 +365,10 @@ impl MainWorker { } /// See [JsRuntime::execute_script](deno_core::JsRuntime::execute_script) - pub fn execute_script( + pub fn execute_script<S: Into<ModuleCode>>( &mut self, - script_name: &str, - source_code: &str, + script_name: &'static str, + source_code: S, ) -> Result<v8::Global<v8::Value>, AnyError> { self.js_runtime.execute_script(script_name, source_code) } @@ -502,7 +503,7 @@ impl MainWorker { /// 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, + script_name: &'static str, ) -> Result<(), AnyError> { self.execute_script( script_name, @@ -519,7 +520,7 @@ impl MainWorker { /// 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, + script_name: &'static str, ) -> Result<(), AnyError> { self.execute_script( script_name, @@ -536,7 +537,7 @@ impl MainWorker { /// running. pub fn dispatch_beforeunload_event( &mut self, - script_name: &str, + script_name: &'static str, ) -> Result<bool, AnyError> { let value = self.js_runtime.execute_script( script_name, |