diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bindings.rs | 8 | ||||
-rw-r--r-- | core/error.rs | 6 | ||||
-rw-r--r-- | core/extensions.rs | 14 | ||||
-rw-r--r-- | core/lib.rs | 13 | ||||
-rw-r--r-- | core/modules.rs | 62 | ||||
-rw-r--r-- | core/runtime.rs | 16 | ||||
-rw-r--r-- | core/snapshot_util.rs | 4 |
7 files changed, 58 insertions, 65 deletions
diff --git a/core/bindings.rs b/core/bindings.rs index d8e9f50d8..b674ee6b6 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -281,11 +281,11 @@ pub fn host_import_module_dynamically_callback<'s>( .unwrap() .to_rust_string_lossy(scope); - let is_internal_module = specifier_str.starts_with("internal:"); + let is_ext_module = specifier_str.starts_with("ext:"); let resolver = v8::PromiseResolver::new(scope).unwrap(); let promise = resolver.get_promise(scope); - if !is_internal_module { + if !is_ext_module { let assertions = parse_import_assertions( scope, import_assertions, @@ -333,10 +333,10 @@ pub fn host_import_module_dynamically_callback<'s>( let promise = promise.catch(scope, map_err).unwrap(); - if is_internal_module { + if is_ext_module { let message = v8::String::new_external_onebyte_static( scope, - b"Cannot load internal module from external code", + b"Cannot load extension module from external code", ) .unwrap(); let exception = v8::Exception::type_error(scope, message); diff --git a/core/error.rs b/core/error.rs index 4b560fb5b..e0cae2673 100644 --- a/core/error.rs +++ b/core/error.rs @@ -272,7 +272,7 @@ impl JsError { if let (Some(file_name), Some(line_number)) = (&frame.file_name, frame.line_number) { - if !file_name.trim_start_matches('[').starts_with("internal:") { + if !file_name.trim_start_matches('[').starts_with("ext:") { source_line = get_source_line( file_name, line_number, @@ -424,7 +424,7 @@ impl JsError { if let (Some(file_name), Some(line_number)) = (&frame.file_name, frame.line_number) { - if !file_name.trim_start_matches('[').starts_with("internal:") { + if !file_name.trim_start_matches('[').starts_with("ext:") { source_line = get_source_line( file_name, line_number, @@ -438,7 +438,7 @@ impl JsError { } } else if let Some(frame) = frames.first() { if let Some(file_name) = &frame.file_name { - if !file_name.trim_start_matches('[').starts_with("internal:") { + if !file_name.trim_start_matches('[').starts_with("ext:") { source_line = msg .get_source_line(scope) .map(|v| v.to_rust_string_lossy(scope)); diff --git a/core/extensions.rs b/core/extensions.rs index beddce4c7..0ee6790ec 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -209,7 +209,7 @@ impl ExtensionBuilder { // use a different result struct that `ExtensionFileSource` as it's confusing // when (and why) the remapping happens. js_files.into_iter().map(|file_source| ExtensionFileSource { - specifier: format!("internal:{}/{}", self.name, file_source.specifier), + specifier: format!("ext:{}/{}", self.name, file_source.specifier), code: file_source.code, }); self.js.extend(js_files); @@ -223,7 +223,7 @@ impl ExtensionBuilder { // use a different result struct that `ExtensionFileSource` as it's confusing // when (and why) the remapping happens. .map(|file_source| ExtensionFileSource { - specifier: format!("internal:{}/{}", self.name, file_source.specifier), + specifier: format!("ext:{}/{}", self.name, file_source.specifier), code: file_source.code, }); self.esm.extend(esm_files); @@ -287,7 +287,7 @@ impl ExtensionBuilder { /// Helps embed JS files in an extension. Returns a vector of /// `ExtensionFileSource`, that represent the filename and source code. All -/// specified files are rewritten into "internal:<extension_name>/<file_name>". +/// specified files are rewritten into "ext:<extension_name>/<file_name>". /// /// An optional "dir" option can be specified to prefix all files with a /// directory name. @@ -299,8 +299,8 @@ impl ExtensionBuilder { /// "02_goodbye.js", /// ) /// // Produces following specifiers: -/// - "internal:my_extension/01_hello.js" -/// - "internal:my_extension/02_goodbye.js" +/// - "ext:my_extension/01_hello.js" +/// - "ext:my_extension/02_goodbye.js" /// /// /// Example with "dir" option (for "my_extension"): /// ```ignore @@ -310,8 +310,8 @@ impl ExtensionBuilder { /// "02_goodbye.js", /// ) /// // Produces following specifiers: -/// - "internal:my_extension/js/01_hello.js" -/// - "internal:my_extension/js/02_goodbye.js" +/// - "ext:my_extension/js/01_hello.js" +/// - "ext:my_extension/js/02_goodbye.js" /// ``` #[cfg(not(feature = "include_js_files_for_snapshotting"))] #[macro_export] diff --git a/core/lib.rs b/core/lib.rs index 1c60db694..08df6e44d 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -75,9 +75,9 @@ pub use crate::module_specifier::resolve_url_or_path; pub use crate::module_specifier::ModuleResolutionError; pub use crate::module_specifier::ModuleSpecifier; pub use crate::module_specifier::DUMMY_SPECIFIER; +pub use crate::modules::ExtModuleLoader; +pub use crate::modules::ExtModuleLoaderCb; pub use crate::modules::FsModuleLoader; -pub use crate::modules::InternalModuleLoader; -pub use crate::modules::InternalModuleLoaderCb; pub use crate::modules::ModuleId; pub use crate::modules::ModuleLoader; pub use crate::modules::ModuleSource; @@ -141,16 +141,11 @@ pub mod _ops { /// A helper macro that will return a call site in Rust code. Should be /// used when executing internal one-line scripts for JsRuntime lifecycle. /// -/// Returns a string in form of: "`[internal:<filename>:<line>:<column>]`" +/// Returns a string in form of: "`[ext:<filename>:<line>:<column>]`" #[macro_export] macro_rules! located_script_name { () => { - format!( - "[internal:{}:{}:{}]", - std::file!(), - std::line!(), - std::column!() - ); + format!("[ext:{}:{}:{}]", std::file!(), std::line!(), std::column!()); }; } diff --git a/core/modules.rs b/core/modules.rs index 3d335f8eb..3a3b1c370 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -301,7 +301,7 @@ impl ModuleLoader for NoopModuleLoader { } /// Helper function, that calls into `loader.resolve()`, but denies resolution -/// of `internal` scheme if we are running with a snapshot loaded and not +/// of `ext` scheme if we are running with a snapshot loaded and not /// creating a snapshot pub(crate) fn resolve_helper( snapshot_loaded_and_not_snapshotting: bool, @@ -310,29 +310,28 @@ pub(crate) fn resolve_helper( referrer: &str, kind: ResolutionKind, ) -> Result<ModuleSpecifier, Error> { - if snapshot_loaded_and_not_snapshotting && specifier.starts_with("internal:") - { + if snapshot_loaded_and_not_snapshotting && specifier.starts_with("ext:") { return Err(generic_error( - "Cannot load internal module from external code", + "Cannot load extension module from external code", )); } loader.resolve(specifier, referrer, kind) } -/// Function that can be passed to the `InternalModuleLoader` that allows to +/// Function that can be passed to the `ExtModuleLoader` that allows to /// transpile sources before passing to V8. -pub type InternalModuleLoaderCb = +pub type ExtModuleLoaderCb = Box<dyn Fn(&ExtensionFileSource) -> Result<String, Error>>; -pub struct InternalModuleLoader { +pub struct ExtModuleLoader { module_loader: Rc<dyn ModuleLoader>, esm_sources: Vec<ExtensionFileSource>, used_esm_sources: RefCell<HashMap<String, bool>>, - maybe_load_callback: Option<InternalModuleLoaderCb>, + maybe_load_callback: Option<ExtModuleLoaderCb>, } -impl Default for InternalModuleLoader { +impl Default for ExtModuleLoader { fn default() -> Self { Self { module_loader: Rc::new(NoopModuleLoader), @@ -343,18 +342,18 @@ impl Default for InternalModuleLoader { } } -impl InternalModuleLoader { +impl ExtModuleLoader { pub fn new( module_loader: Option<Rc<dyn ModuleLoader>>, esm_sources: Vec<ExtensionFileSource>, - maybe_load_callback: Option<InternalModuleLoaderCb>, + maybe_load_callback: Option<ExtModuleLoaderCb>, ) -> Self { let used_esm_sources: HashMap<String, bool> = esm_sources .iter() .map(|file_source| (file_source.specifier.to_string(), false)) .collect(); - InternalModuleLoader { + ExtModuleLoader { module_loader: module_loader.unwrap_or_else(|| Rc::new(NoopModuleLoader)), esm_sources, used_esm_sources: RefCell::new(used_esm_sources), @@ -363,7 +362,7 @@ impl InternalModuleLoader { } } -impl Drop for InternalModuleLoader { +impl Drop for ExtModuleLoader { fn drop(&mut self) { let used_esm_sources = self.used_esm_sources.get_mut(); let unused_modules: Vec<_> = used_esm_sources @@ -374,8 +373,8 @@ impl Drop for InternalModuleLoader { if !unused_modules.is_empty() { let mut msg = - "Following modules were passed to InternalModuleLoader but never used:\n" - .to_string(); + "Following modules were passed to ExtModuleLoader but never used:\n" + .to_string(); for m in unused_modules { msg.push_str(" - "); msg.push_str(m); @@ -386,7 +385,7 @@ impl Drop for InternalModuleLoader { } } -impl ModuleLoader for InternalModuleLoader { +impl ModuleLoader for ExtModuleLoader { fn resolve( &self, specifier: &str, @@ -394,14 +393,13 @@ impl ModuleLoader for InternalModuleLoader { kind: ResolutionKind, ) -> Result<ModuleSpecifier, Error> { if let Ok(url_specifier) = ModuleSpecifier::parse(specifier) { - if url_specifier.scheme() == "internal" { + if url_specifier.scheme() == "ext" { let referrer_specifier = ModuleSpecifier::parse(referrer).ok(); - if referrer == "." || referrer_specifier.unwrap().scheme() == "internal" - { + if referrer == "." || referrer_specifier.unwrap().scheme() == "ext" { return Ok(url_specifier); } else { return Err(generic_error( - "Cannot load internal module from external code", + "Cannot load extension module from external code", )); }; } @@ -416,7 +414,7 @@ impl ModuleLoader for InternalModuleLoader { maybe_referrer: Option<ModuleSpecifier>, is_dyn_import: bool, ) -> Pin<Box<ModuleSourceFuture>> { - if module_specifier.scheme() != "internal" { + if module_specifier.scheme() != "ext" { return self.module_loader.load( module_specifier, maybe_referrer, @@ -461,7 +459,7 @@ impl ModuleLoader for InternalModuleLoader { async move { Err(generic_error(format!( - "Cannot find internal module source for specifier {specifier}" + "Cannot find extension module source for specifier {specifier}" ))) } .boxed_local() @@ -474,7 +472,7 @@ impl ModuleLoader for InternalModuleLoader { maybe_referrer: Option<String>, is_dyn_import: bool, ) -> Pin<Box<dyn Future<Output = Result<(), Error>>>> { - if module_specifier.scheme() == "internal" { + if module_specifier.scheme() == "ext" { return async { Ok(()) }.boxed_local(); } @@ -2911,17 +2909,17 @@ if (import.meta.url != 'file:///main_with_code.js') throw Error(); } #[test] - fn internal_module_loader() { - let loader = InternalModuleLoader::default(); + fn ext_module_loader() { + let loader = ExtModuleLoader::default(); assert!(loader - .resolve("internal:foo", "internal:bar", ResolutionKind::Import) + .resolve("ext:foo", "ext:bar", ResolutionKind::Import) .is_ok()); assert_eq!( loader - .resolve("internal:foo", "file://bar", ResolutionKind::Import) + .resolve("ext:foo", "file://bar", ResolutionKind::Import) .err() .map(|e| e.to_string()), - Some("Cannot load internal module from external code".to_string()) + Some("Cannot load extension module from external code".to_string()) ); assert_eq!( loader @@ -2935,11 +2933,11 @@ if (import.meta.url != 'file:///main_with_code.js') throw Error(); ); assert_eq!( loader - .resolve("file://foo", "internal:bar", ResolutionKind::Import) + .resolve("file://foo", "ext:bar", ResolutionKind::Import) .err() .map(|e| e.to_string()), Some( - "Module loading is not supported; attempted to resolve: \"file://foo\" from \"internal:bar\"" + "Module loading is not supported; attempted to resolve: \"file://foo\" from \"ext:bar\"" .to_string() ) ); @@ -2947,13 +2945,13 @@ if (import.meta.url != 'file:///main_with_code.js') throw Error(); resolve_helper( true, Rc::new(loader), - "internal:core.js", + "ext:core.js", "file://bar", ResolutionKind::Import, ) .err() .map(|e| e.to_string()), - Some("Cannot load internal module from external code".to_string()) + Some("Cannot load extension module from external code".to_string()) ); } } diff --git a/core/runtime.rs b/core/runtime.rs index 92e23873a..f751138a9 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -8,7 +8,7 @@ use crate::extensions::OpDecl; use crate::extensions::OpEventLoopFn; use crate::inspector::JsRuntimeInspector; use crate::module_specifier::ModuleSpecifier; -use crate::modules::InternalModuleLoaderCb; +use crate::modules::ExtModuleLoaderCb; use crate::modules::ModuleError; use crate::modules::ModuleId; use crate::modules::ModuleLoadId; @@ -275,7 +275,7 @@ pub struct RuntimeOptions { /// An optional callback that will be called for each module that is loaded /// during snapshotting. This callback can be used to transpile source on the /// fly, during snapshotting, eg. to transpile TypeScript to JavaScript. - pub snapshot_module_load_cb: Option<InternalModuleLoaderCb>, + pub snapshot_module_load_cb: Option<ExtModuleLoaderCb>, /// Isolate creation parameters. pub create_params: Option<v8::CreateParams>, @@ -620,7 +620,7 @@ impl JsRuntime { } } - Rc::new(crate::modules::InternalModuleLoader::new( + Rc::new(crate::modules::ExtModuleLoader::new( options.module_loader, esm_sources, options.snapshot_module_load_cb, @@ -3984,8 +3984,8 @@ assertEquals(1, notify_return_value); ) .unwrap_err(); let error_string = error.to_string(); - // Test that the script specifier is a URL: `internal:<repo-relative path>`. - assert!(error_string.contains("internal:core/01_core.js")); + // Test that the script specifier is a URL: `ext:<repo-relative path>`. + assert!(error_string.contains("ext:core/01_core.js")); } #[test] @@ -5018,8 +5018,8 @@ Deno.core.opAsync("op_async_serialize_object_with_numbers_as_keys", { ) -> Pin<Box<ModuleSourceFuture>> { let source = r#" // This module doesn't really exist, just verifying that we'll get - // an error when specifier starts with "internal:". - import { core } from "internal:core.js"; + // an error when specifier starts with "ext:". + import { core } from "ext:core.js"; "#; async move { @@ -5055,7 +5055,7 @@ Deno.core.opAsync("op_async_serialize_object_with_numbers_as_keys", { .unwrap_err(); assert_eq!( err.to_string(), - "Cannot load internal module from external code" + "Cannot load extension module from external code" ); } } diff --git a/core/snapshot_util.rs b/core/snapshot_util.rs index 5b0ba92a0..8b4fa3fa4 100644 --- a/core/snapshot_util.rs +++ b/core/snapshot_util.rs @@ -4,8 +4,8 @@ use std::path::Path; use std::path::PathBuf; use std::time::Instant; +use crate::ExtModuleLoaderCb; use crate::Extension; -use crate::InternalModuleLoaderCb; use crate::JsRuntime; use crate::RuntimeOptions; use crate::Snapshot; @@ -19,7 +19,7 @@ pub struct CreateSnapshotOptions { pub extensions: Vec<Extension>, pub extensions_with_js: Vec<Extension>, pub compression_cb: Option<Box<CompressionCb>>, - pub snapshot_module_load_cb: Option<InternalModuleLoaderCb>, + pub snapshot_module_load_cb: Option<ExtModuleLoaderCb>, } pub fn create_snapshot(create_snapshot_options: CreateSnapshotOptions) { |