diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/examples/hello_runtime.rs | 3 | ||||
-rw-r--r-- | runtime/ops/runtime.rs | 4 | ||||
-rw-r--r-- | runtime/ops/worker_host.rs | 2 | ||||
-rw-r--r-- | runtime/permissions.rs | 43 | ||||
-rw-r--r-- | runtime/web_worker.rs | 3 | ||||
-rw-r--r-- | runtime/worker.rs | 16 |
6 files changed, 25 insertions, 46 deletions
diff --git a/runtime/examples/hello_runtime.rs b/runtime/examples/hello_runtime.rs index 9b8e17a4c..e8bf9841e 100644 --- a/runtime/examples/hello_runtime.rs +++ b/runtime/examples/hello_runtime.rs @@ -2,7 +2,6 @@ use deno_core::error::AnyError; use deno_core::FsModuleLoader; -use deno_core::ModuleSpecifier; use deno_runtime::permissions::Permissions; use deno_runtime::worker::MainWorker; use deno_runtime::worker::WorkerOptions; @@ -44,7 +43,7 @@ async fn main() -> Result<(), AnyError> { let js_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/hello_runtime.js"); - let main_module = ModuleSpecifier::resolve_path(&js_path.to_string_lossy())?; + let main_module = deno_core::resolve_path(&js_path.to_string_lossy())?; let permissions = Permissions::allow_all(); let mut worker = diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index 4b81c579f..77abc45b7 100644 --- a/runtime/ops/runtime.rs +++ b/runtime/ops/runtime.rs @@ -26,8 +26,8 @@ fn op_main_module( _zero_copy: &mut [ZeroCopyBuf], ) -> Result<Value, AnyError> { let main = state.borrow::<ModuleSpecifier>().to_string(); - let main_url = ModuleSpecifier::resolve_url_or_path(&main)?; - if main_url.as_url().scheme() == "file" { + let main_url = deno_core::resolve_url_or_path(&main)?; + if main_url.scheme() == "file" { let main_path = std::env::current_dir().unwrap().join(main_url.to_string()); state .borrow::<Permissions>() diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index d68fa02e8..6b375605f 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -482,7 +482,7 @@ fn op_create_worker( state.put::<CreateWebWorkerCbHolder>(create_module_loader.clone()); state.put::<WorkerId>(worker_id + 1); - let module_specifier = ModuleSpecifier::resolve_url(&specifier)?; + let module_specifier = deno_core::resolve_url(&specifier)?; let worker_name = args_name.unwrap_or_else(|| "".to_string()); let (handle_sender, handle_receiver) = diff --git a/runtime/permissions.rs b/runtime/permissions.rs index b568c0a4f..e89a8747d 100644 --- a/runtime/permissions.rs +++ b/runtime/permissions.rs @@ -580,9 +580,8 @@ impl Permissions { &self, specifier: &ModuleSpecifier, ) -> Result<(), AnyError> { - let url = specifier.as_url(); - match url.scheme() { - "file" => match url.to_file_path() { + match specifier.scheme() { + "file" => match specifier.to_file_path() { Ok(path) => self.check_read(&path), Err(_) => Err(uri_error(format!( "Invalid file path.\n Specifier: {}", @@ -590,7 +589,7 @@ impl Permissions { ))), }, "data" => Ok(()), - _ => self.check_net_url(url), + _ => self.check_net_url(specifier), } } @@ -749,6 +748,7 @@ fn format_host<T: AsRef<str>>(host: &(T, Option<u16>)) -> String { #[cfg(test)] mod tests { use super::*; + use deno_core::resolve_url_or_path; // Creates vector of strings, Vec<String> macro_rules! svec { @@ -1000,42 +1000,27 @@ mod tests { let mut fixtures = vec![ ( - ModuleSpecifier::resolve_url_or_path("http://localhost:4545/mod.ts") - .unwrap(), + resolve_url_or_path("http://localhost:4545/mod.ts").unwrap(), true, ), ( - ModuleSpecifier::resolve_url_or_path("http://deno.land/x/mod.ts") - .unwrap(), + resolve_url_or_path("http://deno.land/x/mod.ts").unwrap(), false, ), ( - ModuleSpecifier::resolve_url_or_path( - "data:text/plain,Hello%2C%20Deno!", - ) - .unwrap(), + resolve_url_or_path("data:text/plain,Hello%2C%20Deno!").unwrap(), true, ), ]; if cfg!(target_os = "windows") { - fixtures.push(( - ModuleSpecifier::resolve_url_or_path("file:///C:/a/mod.ts").unwrap(), - true, - )); - fixtures.push(( - ModuleSpecifier::resolve_url_or_path("file:///C:/b/mod.ts").unwrap(), - false, - )); + fixtures + .push((resolve_url_or_path("file:///C:/a/mod.ts").unwrap(), true)); + fixtures + .push((resolve_url_or_path("file:///C:/b/mod.ts").unwrap(), false)); } else { - fixtures.push(( - ModuleSpecifier::resolve_url_or_path("file:///a/mod.ts").unwrap(), - true, - )); - fixtures.push(( - ModuleSpecifier::resolve_url_or_path("file:///b/mod.ts").unwrap(), - false, - )); + fixtures.push((resolve_url_or_path("file:///a/mod.ts").unwrap(), true)); + fixtures.push((resolve_url_or_path("file:///b/mod.ts").unwrap(), false)); } for (specifier, expected) in fixtures { @@ -1058,7 +1043,7 @@ mod tests { for url in test_cases { assert!(perms - .check_specifier(&ModuleSpecifier::resolve_url_or_path(url).unwrap()) + .check_specifier(&resolve_url_or_path(url).unwrap()) .is_err()); } } diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 0efb547f4..0847059ac 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -476,8 +476,7 @@ mod tests { use deno_core::serde_json::json; fn create_test_web_worker() -> WebWorker { - let main_module = - ModuleSpecifier::resolve_url_or_path("./hello.js").unwrap(); + let main_module = deno_core::resolve_url_or_path("./hello.js").unwrap(); let module_loader = Rc::new(deno_core::NoopModuleLoader); let create_web_worker_cb = Arc::new(|_| unreachable!()); diff --git a/runtime/worker.rs b/runtime/worker.rs index a619ecc4c..dca01932d 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -260,10 +260,10 @@ impl Drop for MainWorker { #[cfg(test)] mod tests { use super::*; + use deno_core::resolve_url_or_path; fn create_test_worker() -> MainWorker { - let main_module = - ModuleSpecifier::resolve_url_or_path("./hello.js").unwrap(); + let main_module = resolve_url_or_path("./hello.js").unwrap(); let permissions = Permissions::default(); let options = WorkerOptions { @@ -296,8 +296,7 @@ mod tests { .parent() .unwrap() .join("cli/tests/esm_imports_a.js"); - let module_specifier = - ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap(); + let module_specifier = resolve_url_or_path(&p.to_string_lossy()).unwrap(); let mut worker = create_test_worker(); let result = worker.execute_module(&module_specifier).await; if let Err(err) = result { @@ -314,8 +313,7 @@ mod tests { .parent() .unwrap() .join("tests/circular1.js"); - let module_specifier = - ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap(); + let module_specifier = resolve_url_or_path(&p.to_string_lossy()).unwrap(); let mut worker = create_test_worker(); let result = worker.execute_module(&module_specifier).await; if let Err(err) = result { @@ -330,8 +328,7 @@ mod tests { async fn execute_mod_resolve_error() { // "foo" is not a valid module specifier so this should return an error. let mut worker = create_test_worker(); - let module_specifier = - ModuleSpecifier::resolve_url_or_path("does-not-exist").unwrap(); + let module_specifier = resolve_url_or_path("does-not-exist").unwrap(); let result = worker.execute_module(&module_specifier).await; assert!(result.is_err()); } @@ -345,8 +342,7 @@ mod tests { .parent() .unwrap() .join("cli/tests/001_hello.js"); - let module_specifier = - ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap(); + let module_specifier = resolve_url_or_path(&p.to_string_lossy()).unwrap(); let result = worker.execute_module(&module_specifier).await; assert!(result.is_ok()); } |