diff --git a/Cargo.lock b/Cargo.lock index 09cb1295df..414f57cb4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1258,6 +1258,7 @@ dependencies = [ "async-trait", "base64-simd", "deno_bench_util", + "deno_console", "deno_core", "deno_url", "deno_webidl", diff --git a/bench_util/benches/op_baseline.rs b/bench_util/benches/op_baseline.rs index 14d04f60d0..9c3ac16c4b 100644 --- a/bench_util/benches/op_baseline.rs +++ b/bench_util/benches/op_baseline.rs @@ -6,7 +6,7 @@ use deno_core::op; use deno_core::Extension; fn setup() -> Vec { - vec![Extension::builder() + vec![Extension::builder("bench_setup") .ops(vec![ op_pi_json::decl(), op_pi_async::decl(), diff --git a/bench_util/benches/utf8.rs b/bench_util/benches/utf8.rs index 499571e5e6..363300d5e1 100644 --- a/bench_util/benches/utf8.rs +++ b/bench_util/benches/utf8.rs @@ -6,7 +6,7 @@ use deno_bench_util::BenchOptions; use deno_core::Extension; fn setup() -> Vec { - vec![Extension::builder() + vec![Extension::builder("bench_setup") .js(vec![( "setup.js", r#" diff --git a/cli/build.rs b/cli/build.rs index b4acc0d1d5..24898a7a1b 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -238,7 +238,7 @@ mod ts { cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"), snapshot_path, startup_snapshot: None, - extensions: vec![Extension::builder() + extensions: vec![Extension::builder("deno_tsc") .ops(vec![ op_build_info::decl(), op_cwd::decl(), diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 9f2ac2ba0f..fabe30ac73 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -2805,7 +2805,7 @@ fn js_runtime(performance: Arc) -> JsRuntime { } fn init_extension(performance: Arc) -> Extension { - Extension::builder() + Extension::builder("deno_tsc") .ops(vec![ op_exists::decl(), op_is_cancelled::decl(), diff --git a/cli/ops/bench.rs b/cli/ops/bench.rs index 3b27ffa7ec..9b70cfa79c 100644 --- a/cli/ops/bench.rs +++ b/cli/ops/bench.rs @@ -22,7 +22,7 @@ pub fn init( sender: UnboundedSender, filter: TestFilter, ) -> Extension { - Extension::builder() + Extension::builder("deno_bench") .ops(vec![ op_pledge_test_permissions::decl(), op_restore_test_permissions::decl(), diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs index 96599a663d..c31a305316 100644 --- a/cli/ops/mod.rs +++ b/cli/ops/mod.rs @@ -14,7 +14,7 @@ pub fn cli_exts(ps: ProcState) -> Vec { } fn init_proc_state(ps: ProcState) -> Extension { - Extension::builder() + Extension::builder("deno_cli") .ops(vec![op_npm_process_state::decl()]) .state(move |state| { state.put(ps.clone()); diff --git a/cli/ops/testing.rs b/cli/ops/testing.rs index e5c0a2b99c..e9d0acf41e 100644 --- a/cli/ops/testing.rs +++ b/cli/ops/testing.rs @@ -30,7 +30,7 @@ pub fn init( fail_fast_tracker: FailFastTracker, filter: TestFilter, ) -> Extension { - Extension::builder() + Extension::builder("deno_test") .ops(vec![ op_pledge_test_permissions::decl(), op_restore_test_permissions::decl(), diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index 497105cb51..c08b4e1aeb 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -770,7 +770,7 @@ pub fn exec(request: Request) -> Result { .collect(); let mut runtime = JsRuntime::new(RuntimeOptions { startup_snapshot: Some(compiler_snapshot()), - extensions: vec![Extension::builder() + extensions: vec![Extension::builder("deno_cli_tsc") .ops(vec![ op_cwd::decl(), op_create_hash::decl(), diff --git a/core/examples/disable_ops.rs b/core/examples/disable_ops.rs index a99568589f..b9a5e7fca4 100644 --- a/core/examples/disable_ops.rs +++ b/core/examples/disable_ops.rs @@ -7,7 +7,7 @@ use deno_core::JsRuntime; use deno_core::RuntimeOptions; fn main() { - let my_ext = Extension::builder() + let my_ext = Extension::builder("my_ext") .middleware(|op| match op.name { "op_print" => op.disable(), _ => op, diff --git a/core/examples/hello_world.rs b/core/examples/hello_world.rs index a1edbead0a..50cbe4e2c7 100644 --- a/core/examples/hello_world.rs +++ b/core/examples/hello_world.rs @@ -22,7 +22,7 @@ fn op_sum(nums: Vec) -> Result { fn main() { // Build a deno_core::Extension providing custom ops - let ext = Extension::builder() + let ext = Extension::builder("my_ext") .ops(vec![ // An op for summing an array of numbers // The op-layer automatically deserializes inputs diff --git a/core/examples/http_bench_json_ops.rs b/core/examples/http_bench_json_ops.rs index 23945c6325..9a55a0823d 100644 --- a/core/examples/http_bench_json_ops.rs +++ b/core/examples/http_bench_json_ops.rs @@ -117,7 +117,7 @@ impl From for TcpStream { } fn create_js_runtime() -> JsRuntime { - let ext = deno_core::Extension::builder() + let ext = deno_core::Extension::builder("my_ext") .ops(vec![op_listen::decl(), op_accept::decl()]) .build(); diff --git a/core/examples/panik.rs b/core/examples/panik.rs index 76be108ec2..1d2286a881 100644 --- a/core/examples/panik.rs +++ b/core/examples/panik.rs @@ -24,8 +24,9 @@ fn main() { panic!("panik !!!") } - let extensions = - vec![Extension::builder().ops(vec![op_panik::decl()]).build()]; + let extensions = vec![Extension::builder("my_ext") + .ops(vec![op_panik::decl()]) + .build()]; let mut rt = JsRuntime::new(RuntimeOptions { extensions, ..Default::default() diff --git a/core/examples/schedule_task.rs b/core/examples/schedule_task.rs index ba0f3ef0fc..6a61619d87 100644 --- a/core/examples/schedule_task.rs +++ b/core/examples/schedule_task.rs @@ -18,7 +18,7 @@ use deno_core::*; type Task = Box; fn main() { - let my_ext = Extension::builder() + let my_ext = Extension::builder("my_ext") .ops(vec![op_schedule_task::decl()]) .event_loop_middleware(|state_rc, cx| { let mut state = state_rc.borrow_mut(); diff --git a/core/examples/wasm.rs b/core/examples/wasm.rs index c4bb8b9adb..7c2d98bc91 100644 --- a/core/examples/wasm.rs +++ b/core/examples/wasm.rs @@ -51,7 +51,7 @@ fn op_set_wasm_mem( fn main() { // Build a deno_core::Extension providing custom ops - let ext = Extension::builder() + let ext = Extension::builder("my_ext") .ops(vec![op_wasm::decl(), op_set_wasm_mem::decl()]) .build(); diff --git a/core/extensions.rs b/core/extensions.rs index 6fca570df1..437621c0e5 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -42,13 +42,39 @@ pub struct Extension { event_loop_middleware: Option>, initialized: bool, enabled: bool, + name: &'static str, + deps: Option>, } // Note: this used to be a trait, but we "downgraded" it to a single concrete type // for the initial iteration, it will likely become a trait in the future impl Extension { - pub fn builder() -> ExtensionBuilder { - Default::default() + pub fn builder(name: &'static str) -> ExtensionBuilder { + ExtensionBuilder { + name, + ..Default::default() + } + } + + /// Check if dependencies have been loaded, and errors if either: + /// - The extension is depending on itself or an extension with the same name. + /// - A dependency hasn't been loaded yet. + pub fn check_dependencies(&self, previous_exts: &[&mut Extension]) { + if let Some(deps) = &self.deps { + 'dep_loop: for dep in deps { + if dep == &self.name { + panic!("Extension '{}' is either depending on itself or there is another extension with the same name", self.name); + } + + for ext in previous_exts { + if dep == &ext.name { + continue 'dep_loop; + } + } + + panic!("Extension '{}' is missing dependency '{dep}'", self.name); + } + } } /// returns JS source code to be loaded into the isolate (either at snapshotting, @@ -121,9 +147,16 @@ pub struct ExtensionBuilder { state: Option>, middleware: Option>, event_loop_middleware: Option>, + name: &'static str, + deps: Vec<&'static str>, } impl ExtensionBuilder { + pub fn dependencies(&mut self, dependencies: Vec<&'static str>) -> &mut Self { + self.deps.extend(dependencies); + self + } + pub fn js(&mut self, js_files: Vec) -> &mut Self { self.js.extend(js_files); self @@ -161,6 +194,7 @@ impl ExtensionBuilder { pub fn build(&mut self) -> Extension { let js_files = Some(std::mem::take(&mut self.js)); let ops = Some(std::mem::take(&mut self.ops)); + let deps = Some(std::mem::take(&mut self.deps)); Extension { js_files, ops, @@ -169,6 +203,8 @@ impl ExtensionBuilder { event_loop_middleware: self.event_loop_middleware.take(), initialized: false, enabled: true, + name: self.name, + deps, } } } diff --git a/core/modules.rs b/core/modules.rs index ff253db618..8abced2009 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -1479,7 +1479,9 @@ import "/a.js"; 43 } - let ext = Extension::builder().ops(vec![op_test::decl()]).build(); + let ext = Extension::builder("test_ext") + .ops(vec![op_test::decl()]) + .build(); let mut runtime = JsRuntime::new(RuntimeOptions { extensions: vec![ext], diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs index 6889c5dbc2..9054960257 100644 --- a/core/ops_builtin.rs +++ b/core/ops_builtin.rs @@ -17,7 +17,7 @@ use std::io::{stderr, stdout, Write}; use std::rc::Rc; pub(crate) fn init_builtins() -> Extension { - Extension::builder() + Extension::builder("deno_builtins") .js(include_js_files!( prefix "deno:core", "00_primordials.js", diff --git a/core/runtime.rs b/core/runtime.rs index 4a1302b3f0..baa7de1a14 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -728,10 +728,9 @@ impl JsRuntime { /// Initializes JS of provided Extensions in the given realm fn init_extension_js(&mut self, realm: &JsRealm) -> Result<(), Error> { // Take extensions to avoid double-borrow - let mut extensions: Vec = - std::mem::take(&mut self.extensions_with_js); - for m in extensions.iter_mut() { - let js_files = m.init_js(); + let extensions = std::mem::take(&mut self.extensions_with_js); + for ext in &extensions { + let js_files = ext.init_js(); for (filename, source) in js_files { // TODO(@AaronO): use JsRuntime::execute_static() here to move src off heap realm.execute_script(self.v8_isolate(), filename, source)?; @@ -752,6 +751,12 @@ impl JsRuntime { exts.extend(extensions); exts.extend(extensions_with_js); + for (ext, previous_exts) in + exts.iter().enumerate().map(|(i, ext)| (ext, &exts[..i])) + { + ext.check_dependencies(previous_exts); + } + // Middleware let middleware: Vec> = exts .iter_mut() @@ -2554,7 +2559,7 @@ pub mod tests { fn setup(mode: Mode) -> (JsRuntime, Arc) { let dispatch_count = Arc::new(AtomicUsize::new(0)); let dispatch_count2 = dispatch_count.clone(); - let ext = Extension::builder() + let ext = Extension::builder("test_ext") .ops(vec![op_test::decl()]) .state(move |state| { state.put(TestState { @@ -2976,7 +2981,9 @@ pub mod tests { } run_in_task(|cx| { - let ext = Extension::builder().ops(vec![op_err::decl()]).build(); + let ext = Extension::builder("test_ext") + .ops(vec![op_err::decl()]) + .build(); let mut runtime = JsRuntime::new(RuntimeOptions { extensions: vec![ext], get_error_class_fn: Some(&get_error_class_name), @@ -3428,7 +3435,7 @@ main(); } run_in_task(|cx| { - let ext = Extension::builder() + let ext = Extension::builder("test_ext") .ops(vec![op_err_sync::decl(), op_err_async::decl()]) .build(); let mut runtime = JsRuntime::new(RuntimeOptions { @@ -3596,7 +3603,7 @@ assertEquals(1, notify_return_value); Ok(()) } - let extension = Extension::builder() + let extension = Extension::builder("test_ext") .ops(vec![op_async_borrow::decl()]) .state(|state| { state.put(InnerState(42)); @@ -3631,7 +3638,7 @@ assertEquals(1, notify_return_value); Ok(()) } - let extension = Extension::builder() + let extension = Extension::builder("test_ext") .ops(vec![op_sync_serialize_object_with_numbers_as_keys::decl()]) .build(); @@ -3673,7 +3680,7 @@ Deno.core.ops.op_sync_serialize_object_with_numbers_as_keys({ Ok(()) } - let extension = Extension::builder() + let extension = Extension::builder("test_ext") .ops(vec![op_async_serialize_object_with_numbers_as_keys::decl()]) .build(); @@ -3712,7 +3719,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({ Ok(()) } - let extension = Extension::builder() + let extension = Extension::builder("test_ext") .ops(vec![op_async_sleep::decl()]) .build(); @@ -3792,7 +3799,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({ Ok(()) } - let extension = Extension::builder() + let extension = Extension::builder("test_ext") .ops(vec![op_macrotask::decl(), op_next_tick::decl()]) .build(); @@ -3922,7 +3929,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({ Ok(()) } - let extension = Extension::builder() + let extension = Extension::builder("test_ext") .ops(vec![op_promise_reject::decl()]) .build(); @@ -3982,7 +3989,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({ Ok(()) } - let extension = Extension::builder() + let extension = Extension::builder("test_ext") .ops(vec![op_promise_reject::decl()]) .build(); @@ -4051,7 +4058,9 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({ Ok([(1, 2), (3, 4)].into_iter().collect()) // Maps can't have non-string keys in serde_v8 } - let ext = Extension::builder().ops(vec![op_err::decl()]).build(); + let ext = Extension::builder("test_ext") + .ops(vec![op_err::decl()]) + .build(); let mut runtime = JsRuntime::new(RuntimeOptions { extensions: vec![ext], ..Default::default() @@ -4076,7 +4085,9 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({ Ok(x1 + x2 + x3 + x4) } - let ext = Extension::builder().ops(vec![op_add_4::decl()]).build(); + let ext = Extension::builder("test_ext") + .ops(vec![op_add_4::decl()]) + .build(); let mut runtime = JsRuntime::new(RuntimeOptions { extensions: vec![ext], ..Default::default() @@ -4095,7 +4106,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({ Ok(42) } - let ext = Extension::builder() + let ext = Extension::builder("test_ext") .ops(vec![op_foo::decl().disable()]) .build(); let mut runtime = JsRuntime::new(RuntimeOptions { @@ -4125,7 +4136,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({ Ok(b) } - let ext = Extension::builder() + let ext = Extension::builder("test_ext") .ops(vec![op_sum_take::decl(), op_boomerang::decl()]) .build(); @@ -4193,7 +4204,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({ Ok(42) } - let ext = Extension::builder() + let ext = Extension::builder("test_ext") .ops(vec![op_foo::decl(), op_bar::decl()]) .middleware(|op| if op.is_unstable { op.disable() } else { op }) .build(); @@ -4245,7 +4256,9 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({ } let mut runtime = JsRuntime::new(RuntimeOptions { - extensions: vec![Extension::builder().ops(vec![op_test::decl()]).build()], + extensions: vec![Extension::builder("test_ext") + .ops(vec![op_test::decl()]) + .build()], ..Default::default() }); let realm = runtime.create_realm().unwrap(); @@ -4275,7 +4288,9 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({ let mut runtime = JsRuntime::new(RuntimeOptions { startup_snapshot: Some(Snapshot::Boxed(snapshot)), - extensions: vec![Extension::builder().ops(vec![op_test::decl()]).build()], + extensions: vec![Extension::builder("test_ext") + .ops(vec![op_test::decl()]) + .build()], ..Default::default() }); let realm = runtime.create_realm().unwrap(); @@ -4304,7 +4319,9 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({ } let mut runtime = JsRuntime::new(RuntimeOptions { - extensions: vec![Extension::builder().ops(vec![op_test::decl()]).build()], + extensions: vec![Extension::builder("test_ext") + .ops(vec![op_test::decl()]) + .build()], get_error_class_fn: Some(&|error| { crate::error::get_custom_error_class(error).unwrap() }), diff --git a/ext/broadcast_channel/lib.rs b/ext/broadcast_channel/lib.rs index 00f8ec9ce0..0bf359e6bf 100644 --- a/ext/broadcast_channel/lib.rs +++ b/ext/broadcast_channel/lib.rs @@ -109,7 +109,8 @@ pub fn init( bc: BC, unstable: bool, ) -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) + .dependencies(vec!["deno_webidl", "deno_web"]) .js(include_js_files!( prefix "deno:ext/broadcast_channel", "01_broadcast_channel.js", diff --git a/ext/cache/lib.rs b/ext/cache/lib.rs index 50a07b255a..c48b7cda41 100644 --- a/ext/cache/lib.rs +++ b/ext/cache/lib.rs @@ -26,7 +26,8 @@ pub struct CreateCache(pub Arc C>); pub fn init( maybe_create_cache: Option>, ) -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) + .dependencies(vec!["deno_webidl", "deno_web", "deno_url", "deno_fetch"]) .js(include_js_files!( prefix "deno:ext/cache", "01_cache.js", diff --git a/ext/console/lib.rs b/ext/console/lib.rs index 3d98fc57f5..d8fdb38f35 100644 --- a/ext/console/lib.rs +++ b/ext/console/lib.rs @@ -5,7 +5,7 @@ use deno_core::Extension; use std::path::PathBuf; pub fn init() -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) .js(include_js_files!( prefix "deno:ext/console", "01_colors.js", diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs index d5a83b5ec6..cbcb816d9e 100644 --- a/ext/crypto/lib.rs +++ b/ext/crypto/lib.rs @@ -73,7 +73,8 @@ use crate::key::HkdfOutput; use crate::shared::RawKeyData; pub fn init(maybe_seed: Option) -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) + .dependencies(vec!["deno_webidl", "deno_web"]) .js(include_js_files!( prefix "deno:ext/crypto", "00_crypto.js", diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index 07af9fa158..b4c12fcbc3 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -94,7 +94,8 @@ pub fn init(options: Options) -> Extension where FP: FetchPermissions + 'static, { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) + .dependencies(vec!["deno_webidl", "deno_web", "deno_url", "deno_console"]) .js(include_js_files!( prefix "deno:ext/fetch", "01_fetch_util.js", diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs index 0ae01dcd68..64d7314914 100644 --- a/ext/ffi/lib.rs +++ b/ext/ffi/lib.rs @@ -84,7 +84,7 @@ pub(crate) struct FfiState { } pub fn init(unstable: bool) -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) .js(include_js_files!( prefix "deno:ext/ffi", "00_ffi.js", diff --git a/ext/flash/lib.rs b/ext/flash/lib.rs index 6eaf39944f..2e2417892a 100644 --- a/ext/flash/lib.rs +++ b/ext/flash/lib.rs @@ -1505,7 +1505,14 @@ pub trait FlashPermissions { } pub fn init(unstable: bool) -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) + .dependencies(vec![ + "deno_web", + "deno_net", + "deno_fetch", + "deno_websocket", + "deno_http", + ]) .js(deno_core::include_js_files!( prefix "deno:ext/flash", "01_http.js", diff --git a/ext/http/lib.rs b/ext/http/lib.rs index 8719f9de6f..f1371ffece 100644 --- a/ext/http/lib.rs +++ b/ext/http/lib.rs @@ -78,7 +78,8 @@ pub mod compressible; mod reader_stream; pub fn init() -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) + .dependencies(vec!["deno_web", "deno_net", "deno_fetch", "deno_websocket"]) .js(include_js_files!( prefix "deno:ext/http", "01_http.js", diff --git a/ext/napi/lib.rs b/ext/napi/lib.rs index b281fb9f2f..e76a08ed96 100644 --- a/ext/napi/lib.rs +++ b/ext/napi/lib.rs @@ -410,7 +410,7 @@ impl Env { } pub fn init(unstable: bool) -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) .ops(vec![op_napi_open::decl::

()]) .event_loop_middleware(|op_state_rc, cx| { // `work` can call back into the runtime. It can also schedule an async task diff --git a/ext/net/lib.rs b/ext/net/lib.rs index 63016ae6c7..64e28fd00b 100644 --- a/ext/net/lib.rs +++ b/ext/net/lib.rs @@ -85,7 +85,8 @@ pub fn init( ) -> Extension { let mut ops = ops::init::

(); ops.extend(ops_tls::init::

()); - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) + .dependencies(vec!["deno_web"]) .js(include_js_files!( prefix "deno:ext/net", "01_net.js", diff --git a/ext/net/ops.rs b/ext/net/ops.rs index 583ce6b455..5f832a4b9e 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -865,7 +865,7 @@ mod tests { let listener = TcpListener::bind(addr).await.unwrap(); let _ = listener.accept().await; }); - let my_ext = Extension::builder() + let my_ext = Extension::builder("test_ext") .state(move |state| { state.put(TestPermission {}); state.put(UnstableChecker { unstable: true }); diff --git a/ext/node/lib.rs b/ext/node/lib.rs index d6fdd76799..a670586d17 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -80,7 +80,7 @@ pub static NODE_ENV_VAR_ALLOWLIST: Lazy> = Lazy::new(|| { pub fn init( maybe_npm_resolver: Option>, ) -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) .js(include_js_files!( prefix "deno:ext/node", "01_node.js", diff --git a/ext/tls/lib.rs b/ext/tls/lib.rs index 2b4a0600d1..b762ac90ad 100644 --- a/ext/tls/lib.rs +++ b/ext/tls/lib.rs @@ -37,7 +37,7 @@ use std::time::SystemTime; /// This extension has no runtime apis, it only exports some shared native functions. pub fn init() -> Extension { - Extension::builder().build() + Extension::builder(env!("CARGO_PKG_NAME")).build() } struct DefaultSignatureVerification; diff --git a/ext/url/benches/url_ops.rs b/ext/url/benches/url_ops.rs index 315ea72606..63810733dd 100644 --- a/ext/url/benches/url_ops.rs +++ b/ext/url/benches/url_ops.rs @@ -8,7 +8,7 @@ fn setup() -> Vec { vec![ deno_webidl::init(), deno_url::init(), - Extension::builder() + Extension::builder("bench_setup") .js(vec![( "setup", "const { URL } = globalThis.__bootstrap.url;", diff --git a/ext/url/lib.rs b/ext/url/lib.rs index ba1167d541..6990017f56 100644 --- a/ext/url/lib.rs +++ b/ext/url/lib.rs @@ -18,7 +18,8 @@ use crate::urlpattern::op_urlpattern_parse; use crate::urlpattern::op_urlpattern_process_match_input; pub fn init() -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) + .dependencies(vec!["deno_webidl"]) .js(include_js_files!( prefix "deno:ext/url", "00_url.js", diff --git a/ext/web/Cargo.toml b/ext/web/Cargo.toml index bf30684baa..69a17963c2 100644 --- a/ext/web/Cargo.toml +++ b/ext/web/Cargo.toml @@ -25,6 +25,7 @@ uuid = { workspace = true, features = ["serde"] } [dev-dependencies] deno_bench_util.workspace = true +deno_console.workspace = true deno_url.workspace = true deno_webidl.workspace = true diff --git a/ext/web/benches/encoding.rs b/ext/web/benches/encoding.rs index 61c8533289..8c9eaeb6c0 100644 --- a/ext/web/benches/encoding.rs +++ b/ext/web/benches/encoding.rs @@ -24,8 +24,9 @@ fn setup() -> Vec { vec![ deno_webidl::init(), deno_url::init(), + deno_console::init(), deno_web::init::(BlobStore::default(), None), - Extension::builder() + Extension::builder("bench_setup") .js(vec![( "setup", r#" diff --git a/ext/web/benches/timers_ops.rs b/ext/web/benches/timers_ops.rs index 10b4340156..2ba93c5e13 100644 --- a/ext/web/benches/timers_ops.rs +++ b/ext/web/benches/timers_ops.rs @@ -23,8 +23,9 @@ fn setup() -> Vec { vec![ deno_webidl::init(), deno_url::init(), + deno_console::init(), deno_web::init::(BlobStore::default(), None), - Extension::builder() + Extension::builder("bench_setup") .js(vec![ ("setup", r#" const { setTimeout, handleTimerMacrotask } = globalThis.__bootstrap.timers; diff --git a/ext/web/lib.rs b/ext/web/lib.rs index a270882a97..de89842329 100644 --- a/ext/web/lib.rs +++ b/ext/web/lib.rs @@ -62,7 +62,8 @@ pub fn init( blob_store: BlobStore, maybe_location: Option, ) -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) + .dependencies(vec!["deno_webidl", "deno_console", "deno_url"]) .js(include_js_files!( prefix "deno:ext/web", "00_infra.js", diff --git a/ext/webgpu/src/lib.rs b/ext/webgpu/src/lib.rs index 8e67da6b85..9ee220dd03 100644 --- a/ext/webgpu/src/lib.rs +++ b/ext/webgpu/src/lib.rs @@ -104,7 +104,8 @@ impl Resource for WebGpuQuerySet { } pub fn init(unstable: bool) -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) + .dependencies(vec!["deno_webidl", "deno_web"]) .js(include_js_files!( prefix "deno:ext/webgpu", "01_webgpu.js", diff --git a/ext/webidl/lib.rs b/ext/webidl/lib.rs index 583717d97e..7962165c67 100644 --- a/ext/webidl/lib.rs +++ b/ext/webidl/lib.rs @@ -5,7 +5,7 @@ use deno_core::Extension; /// Load and execute the javascript code. pub fn init() -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) .js(include_js_files!( prefix "deno:ext/webidl", "00_webidl.js", diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index a58701e7ac..bc4b3876d7 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -602,7 +602,8 @@ pub fn init( root_cert_store: Option, unsafely_ignore_certificate_errors: Option>, ) -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) + .dependencies(vec!["deno_url", "deno_webidl"]) .js(include_js_files!( prefix "deno:ext/websocket", "01_websocket.js", diff --git a/ext/webstorage/lib.rs b/ext/webstorage/lib.rs index 5425edc04b..53175f1966 100644 --- a/ext/webstorage/lib.rs +++ b/ext/webstorage/lib.rs @@ -22,7 +22,8 @@ struct OriginStorageDir(PathBuf); const MAX_STORAGE_BYTES: u32 = 10 * 1024 * 1024; pub fn init(origin_storage_dir: Option) -> Extension { - Extension::builder() + Extension::builder(env!("CARGO_PKG_NAME")) + .dependencies(vec!["deno_webidl"]) .js(include_js_files!( prefix "deno:ext/webstorage", "01_webstorage.js", diff --git a/runtime/ops/fs.rs b/runtime/ops/fs.rs index 87bb090c30..fe263d9443 100644 --- a/runtime/ops/fs.rs +++ b/runtime/ops/fs.rs @@ -42,7 +42,7 @@ use deno_core::error::generic_error; use deno_core::error::not_supported; pub fn init() -> Extension { - Extension::builder() + Extension::builder("deno_fs") .ops(vec![ op_open_sync::decl(), op_open_async::decl(), diff --git a/runtime/ops/fs_events.rs b/runtime/ops/fs_events.rs index 6cda48ef35..e550d204c3 100644 --- a/runtime/ops/fs_events.rs +++ b/runtime/ops/fs_events.rs @@ -30,7 +30,7 @@ use std::rc::Rc; use tokio::sync::mpsc; pub fn init() -> Extension { - Extension::builder() + Extension::builder("deno_fs_events") .ops(vec![op_fs_events_open::decl(), op_fs_events_poll::decl()]) .build() } diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs index e751adae80..a531deb842 100644 --- a/runtime/ops/http.rs +++ b/runtime/ops/http.rs @@ -27,7 +27,7 @@ use deno_net::io::UnixStreamResource; use tokio::net::UnixStream; pub fn init() -> Extension { - Extension::builder() + Extension::builder("deno_http_runtime") .ops(vec![ op_http_start::decl(), op_http_upgrade::decl(), diff --git a/runtime/ops/io.rs b/runtime/ops/io.rs index 3bee7db606..43016395eb 100644 --- a/runtime/ops/io.rs +++ b/runtime/ops/io.rs @@ -76,7 +76,7 @@ pub static STDERR_HANDLE: Lazy = Lazy::new(|| { }); pub fn init() -> Extension { - Extension::builder() + Extension::builder("deno_io") .ops(vec![op_read_sync::decl(), op_write_sync::decl()]) .build() } @@ -114,7 +114,7 @@ pub fn init_stdio(stdio: Stdio) -> Extension { // todo(dsheret): don't do this? Taking out the writers was necessary to prevent invalid handle panics let stdio = Rc::new(RefCell::new(Some(stdio))); - Extension::builder() + Extension::builder("deno_stdio") .middleware(|op| match op.name { "op_print" => op_print::decl(), _ => op, diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index 537bb33f90..fec7629f53 100644 --- a/runtime/ops/os/mod.rs +++ b/runtime/ops/os/mod.rs @@ -40,7 +40,7 @@ fn init_ops(builder: &mut ExtensionBuilder) -> &mut ExtensionBuilder { } pub fn init(exit_code: ExitCode) -> Extension { - let mut builder = Extension::builder(); + let mut builder = Extension::builder("deno_os"); init_ops(&mut builder) .state(move |state| { state.put::(exit_code.clone()); @@ -50,7 +50,7 @@ pub fn init(exit_code: ExitCode) -> Extension { } pub fn init_for_worker() -> Extension { - let mut builder = Extension::builder(); + let mut builder = Extension::builder("deno_os_worker"); init_ops(&mut builder) .middleware(|op| match op.name { "op_exit" => noop_op::decl(), diff --git a/runtime/ops/permissions.rs b/runtime/ops/permissions.rs index d0b0cdd8b4..2b01da0a9e 100644 --- a/runtime/ops/permissions.rs +++ b/runtime/ops/permissions.rs @@ -13,7 +13,7 @@ use serde::Deserialize; use std::path::Path; pub fn init() -> Extension { - Extension::builder() + Extension::builder("deno_permissions") .ops(vec![ op_query_permission::decl(), op_revoke_permission::decl(), diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index 86ad292b88..75d9cfdc98 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -27,7 +27,7 @@ use tokio::process::Command; use std::os::unix::process::ExitStatusExt; pub fn init() -> Extension { - Extension::builder() + Extension::builder("deno_process") .ops(vec![op_run::decl(), op_run_status::decl(), op_kill::decl()]) .build() } diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index 52dc3f7457..b97741acce 100644 --- a/runtime/ops/runtime.rs +++ b/runtime/ops/runtime.rs @@ -9,7 +9,7 @@ use deno_core::ModuleSpecifier; use deno_core::OpState; pub fn init(main_module: ModuleSpecifier) -> Extension { - Extension::builder() + Extension::builder("deno_runtime") .ops(vec![op_main_module::decl()]) .state(move |state| { state.put::(main_module.clone()); diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index 14a9215edc..0af9a5c445 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -21,7 +21,7 @@ use tokio::signal::unix::{signal, Signal, SignalKind}; use tokio::signal::windows::{ctrl_break, ctrl_c, CtrlBreak, CtrlC}; pub fn init() -> Extension { - Extension::builder() + Extension::builder("deno_signal") .ops(vec![ op_signal_bind::decl(), op_signal_unbind::decl(), diff --git a/runtime/ops/spawn.rs b/runtime/ops/spawn.rs index 4bbf1ef489..f552e96907 100644 --- a/runtime/ops/spawn.rs +++ b/runtime/ops/spawn.rs @@ -28,7 +28,7 @@ use std::os::unix::prelude::ExitStatusExt; use std::os::unix::process::CommandExt; pub fn init() -> Extension { - Extension::builder() + Extension::builder("deno_spawn") .ops(vec![ op_spawn_child::decl(), op_node_unstable_spawn_child::decl(), diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs index fd87f0e394..d022a43dc3 100644 --- a/runtime/ops/tty.rs +++ b/runtime/ops/tty.rs @@ -34,7 +34,7 @@ fn get_windows_handle( } pub fn init() -> Extension { - Extension::builder() + Extension::builder("deno_tty") .ops(vec![ op_stdin_set_raw::decl(), op_isatty::decl(), diff --git a/runtime/ops/web_worker.rs b/runtime/ops/web_worker.rs index 11aeac8525..6176154247 100644 --- a/runtime/ops/web_worker.rs +++ b/runtime/ops/web_worker.rs @@ -17,7 +17,7 @@ use std::rc::Rc; use self::sync_fetch::op_worker_sync_fetch; pub fn init() -> Extension { - Extension::builder() + Extension::builder("deno_web_worker") .ops(vec![ op_worker_post_message::decl(), op_worker_recv_message::decl(), diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index 041d3ee6f6..8945ff1cc6 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -94,7 +94,7 @@ pub fn init( pre_execute_module_cb: Arc, format_js_error_fn: Option>, ) -> Extension { - Extension::builder() + Extension::builder("deno_worker_host") .state(move |state| { state.put::(WorkersTable::default()); state.put::(WorkerId::default()); diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 97ccbc870d..5424860db1 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -370,7 +370,7 @@ impl WebWorker { // Permissions: many ops depend on this let unstable = options.bootstrap.unstable; let enable_testing_features = options.bootstrap.enable_testing_features; - let perm_ext = Extension::builder() + let perm_ext = Extension::builder("deno_permissions_web_worker") .state(move |state| { state.put::(permissions.clone()); state.put(ops::UnstableChecker { unstable }); diff --git a/runtime/worker.rs b/runtime/worker.rs index 64b8b2c066..5c076a2a57 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -202,7 +202,7 @@ impl MainWorker { // Permissions: many ops depend on this let unstable = options.bootstrap.unstable; let enable_testing_features = options.bootstrap.enable_testing_features; - let perm_ext = Extension::builder() + let perm_ext = Extension::builder("deno_permissions_worker") .state(move |state| { state.put::(permissions.clone()); state.put(ops::UnstableChecker { unstable });