Skip to content

Commit

Permalink
refactor: rename InternalModuleLoader to ExtModuleLoader, use ext: sc…
Browse files Browse the repository at this point in the history
…heme for snapshotted modules (#18041)

This commit renames "deno_core::InternalModuleLoader" to
"ExtModuleLoader" and changes the specifiers used by the 
modules loaded from this loader to "ext:".

"internal:" scheme was really ambiguous and it's more characters than
"ext:", which should result in slightly smaller snapshot size.

Closes #18020
  • Loading branch information
bartlomieju authored Mar 8, 2023
1 parent d24c6ea commit 72fe9bb
Show file tree
Hide file tree
Showing 293 changed files with 1,510 additions and 1,633 deletions.
6 changes: 3 additions & 3 deletions bench_util/js_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use crate::profiling::is_profiling;
pub fn create_js_runtime(setup: impl FnOnce() -> Vec<Extension>) -> JsRuntime {
JsRuntime::new(RuntimeOptions {
extensions_with_js: setup(),
module_loader: Some(std::rc::Rc::new(
deno_core::InternalModuleLoader::default(),
)),
module_loader: Some(
std::rc::Rc::new(deno_core::ExtModuleLoader::default()),
),
..Default::default()
})
}
Expand Down
10 changes: 5 additions & 5 deletions cli/js/40_testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const core = globalThis.Deno.core;
const ops = core.ops;
const internals = globalThis.__bootstrap.internals;
import { setExitHandler } from "internal:runtime/30_os.js";
import { Console } from "internal:deno_console/02_console.js";
import { serializePermissions } from "internal:runtime/10_permissions.js";
import { assert } from "internal:deno_web/00_infra.js";
import { setExitHandler } from "ext:runtime/30_os.js";
import { Console } from "ext:deno_console/02_console.js";
import { serializePermissions } from "ext:runtime/10_permissions.js";
import { assert } from "ext:deno_web/00_infra.js";
const primordials = globalThis.__bootstrap.primordials;
const {
ArrayFrom,
Expand Down Expand Up @@ -1424,6 +1424,6 @@ internals.testing = {
enableBench,
};

import { denoNs } from "internal:runtime/90_deno_ns.js";
import { denoNs } from "ext:runtime/90_deno_ns.js";
denoNs.bench = bench;
denoNs.test = test;
12 changes: 6 additions & 6 deletions cli/tests/integration/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4048,14 +4048,14 @@ itest!(node_prefix_missing {
exit_code: 1,
});

itest!(internal_import {
args: "run run/internal_import.ts",
output: "run/internal_import.ts.out",
itest!(extension_import {
args: "run run/extension_import.ts",
output: "run/extension_import.ts.out",
exit_code: 1,
});

itest!(internal_dynamic_import {
args: "run run/internal_dynamic_import.ts",
output: "run/internal_dynamic_import.ts.out",
itest!(extension_dynamic_import {
args: "run run/extension_dynamic_import.ts",
output: "run/extension_dynamic_import.ts.out",
exit_code: 1,
});
2 changes: 1 addition & 1 deletion cli/tests/testdata/run/error_009_extensions_error.js.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
new Event();
^
at [WILDCARD]
at new Event (internal:deno_web/[WILDCARD])
at new Event (ext:deno_web/[WILDCARD])
at [WILDCARD]
1 change: 1 addition & 0 deletions cli/tests/testdata/run/extension_dynamic_import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
await import("ext:runtime/01_errors.js");
4 changes: 4 additions & 0 deletions cli/tests/testdata/run/extension_dynamic_import.ts.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: Uncaught TypeError: Cannot load extension module from external code
await import("ext:runtime/01_errors.js");
^
at [WILDCARD]/extension_dynamic_import.ts:1:1
1 change: 1 addition & 0 deletions cli/tests/testdata/run/extension_import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "ext:runtime/01_errors.js";
8 changes: 8 additions & 0 deletions cli/tests/testdata/run/extension_import.ts.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: Unsupported scheme "ext" for module "ext:runtime/01_errors.js". Supported schemes: [
"data",
"blob",
"file",
"http",
"https",
]
at [WILDCARD]
2 changes: 1 addition & 1 deletion cli/tests/testdata/run/fetch_async_error_stack.ts.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: Uncaught (in promise) TypeError: error sending request for url[WILDCARD]
await fetch("https://nonexistent.deno.land/");
^[WILDCARD]
at async fetch (internal:[WILDCARD])
at async fetch (ext:[WILDCARD])
at async file:///[WILDCARD]/fetch_async_error_stack.ts:1:1
1 change: 0 additions & 1 deletion cli/tests/testdata/run/internal_dynamic_import.ts

This file was deleted.

4 changes: 0 additions & 4 deletions cli/tests/testdata/run/internal_dynamic_import.ts.out

This file was deleted.

1 change: 0 additions & 1 deletion cli/tests/testdata/run/internal_import.ts

This file was deleted.

8 changes: 0 additions & 8 deletions cli/tests/testdata/run/internal_import.ts.out

This file was deleted.

2 changes: 1 addition & 1 deletion cli/tests/testdata/run/queue_microtask_error.ts.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ error: Uncaught Error: foo
throw new Error("foo");
^
at [WILDCARD]/queue_microtask_error.ts:2:9
at internal:core/[WILDCARD]
at ext:core/[WILDCARD]
4 changes: 2 additions & 2 deletions cli/tests/testdata/run/queue_microtask_error_handled.ts.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
colno: 9,
error: Error: foo
at [WILDCARD]/queue_microtask_error_handled.ts:18:9
at internal:core/[WILDCARD]
at ext:core/[WILDCARD]
}
onerror() called Error: foo
at [WILDCARD]/queue_microtask_error_handled.ts:18:9
at internal:core/[WILDCARD]
at ext:core/[WILDCARD]
2
2 changes: 1 addition & 1 deletion cli/tests/testdata/run/wasm_streaming_panic_test.js.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: Uncaught (in promise) TypeError: Invalid WebAssembly content type.
at handleWasmStreaming (internal:deno_fetch/26_fetch.js:[WILDCARD])
at handleWasmStreaming (ext:deno_fetch/26_fetch.js:[WILDCARD])
6 changes: 3 additions & 3 deletions cli/tests/testdata/run/worker_drop_handle_race.js.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: Uncaught (in worker "") Error
throw new Error();
^
at [WILDCARD]/workers/drop_handle_race.js:2:9
at Object.action (internal:deno_web/02_timers.js:[WILDCARD])
at handleTimerMacrotask (internal:deno_web/02_timers.js:[WILDCARD])
at Object.action (ext:deno_web/02_timers.js:[WILDCARD])
at handleTimerMacrotask (ext:deno_web/02_timers.js:[WILDCARD])
error: Uncaught (in promise) Error: Unhandled error in child worker.
at Worker.#pollControl (internal:runtime/11_workers.js:[WILDCARD])
at Worker.#pollControl (ext:runtime/11_workers.js:[WILDCARD])
8 changes: 4 additions & 4 deletions cli/tests/testdata/test/steps/failing_steps.out
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ failing step in failing test ... FAILED ([WILDCARD])

nested failure => ./test/steps/failing_steps.ts:[WILDCARD]
error: Error: 1 test step failed.
at runTest (internal:cli/40_testing.js:[WILDCARD])
at async runTests (internal:cli/40_testing.js:[WILDCARD])
at runTest (ext:cli/40_testing.js:[WILDCARD])
at async runTests (ext:cli/40_testing.js:[WILDCARD])

multiple test step failures => ./test/steps/failing_steps.ts:[WILDCARD]
error: Error: 2 test steps failed.
at runTest (internal:cli/40_testing.js:[WILDCARD])
at async runTests (internal:cli/40_testing.js:[WILDCARD])
at runTest (ext:cli/40_testing.js:[WILDCARD])
at async runTests (ext:cli/40_testing.js:[WILDCARD])

failing step in failing test => ./test/steps/failing_steps.ts:[WILDCARD]
error: Error: Fail test.
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/unit/opcall_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Deno.test(async function sendAsyncStackTrace() {
assertStringIncludes(s, "opcall_test.ts");
assertStringIncludes(s, "read");
assert(
!s.includes("internal:core"),
"opcall stack traces should NOT include internal:core internals such as unwrapOpResult",
!s.includes("ext:core"),
"opcall stack traces should NOT include ext:core internals such as unwrapOpResult",
);
}
});
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ fn filter_coverages(
coverages
.into_iter()
.filter(|e| {
let is_internal = e.url.starts_with("internal:")
let is_internal = e.url.starts_with("ext:")
|| e.url.ends_with("__anonymous__")
|| e.url.ends_with("$deno$test.js")
|| e.url.ends_with(".snap");
Expand Down
6 changes: 2 additions & 4 deletions cli/tools/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,7 @@ fn abbreviate_test_error(js_error: &JsError) -> JsError {
// check if there are any stack frames coming from user code
let should_filter = frames.iter().any(|f| {
if let Some(file_name) = &f.file_name {
!(file_name.starts_with("[internal:")
|| file_name.starts_with("internal:"))
!(file_name.starts_with("[ext:") || file_name.starts_with("ext:"))
} else {
true
}
Expand All @@ -668,8 +667,7 @@ fn abbreviate_test_error(js_error: &JsError) -> JsError {
.rev()
.skip_while(|f| {
if let Some(file_name) = &f.file_name {
file_name.starts_with("[internal:")
|| file_name.starts_with("internal:")
file_name.starts_with("[ext:") || file_name.starts_with("ext:")
} else {
false
}
Expand Down
8 changes: 4 additions & 4 deletions core/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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));
Expand Down
14 changes: 7 additions & 7 deletions core/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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]
Expand Down
13 changes: 4 additions & 9 deletions core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!());
};
}

Expand Down
Loading

0 comments on commit 72fe9bb

Please sign in to comment.