1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

feat(core): allow specifying name and dependencies of an Extension (#17301)

This commit is contained in:
Leo Kettmeir 2023-01-08 23:48:46 +01:00 committed by GitHub
parent 2be1282be4
commit c41d4ff90e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
57 changed files with 158 additions and 80 deletions

1
Cargo.lock generated
View file

@ -1258,6 +1258,7 @@ dependencies = [
"async-trait", "async-trait",
"base64-simd", "base64-simd",
"deno_bench_util", "deno_bench_util",
"deno_console",
"deno_core", "deno_core",
"deno_url", "deno_url",
"deno_webidl", "deno_webidl",

View file

@ -6,7 +6,7 @@ use deno_core::op;
use deno_core::Extension; use deno_core::Extension;
fn setup() -> Vec<Extension> { fn setup() -> Vec<Extension> {
vec![Extension::builder() vec![Extension::builder("bench_setup")
.ops(vec![ .ops(vec![
op_pi_json::decl(), op_pi_json::decl(),
op_pi_async::decl(), op_pi_async::decl(),

View file

@ -6,7 +6,7 @@ use deno_bench_util::BenchOptions;
use deno_core::Extension; use deno_core::Extension;
fn setup() -> Vec<Extension> { fn setup() -> Vec<Extension> {
vec![Extension::builder() vec![Extension::builder("bench_setup")
.js(vec![( .js(vec![(
"setup.js", "setup.js",
r#" r#"

View file

@ -238,7 +238,7 @@ mod ts {
cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"), cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"),
snapshot_path, snapshot_path,
startup_snapshot: None, startup_snapshot: None,
extensions: vec![Extension::builder() extensions: vec![Extension::builder("deno_tsc")
.ops(vec![ .ops(vec![
op_build_info::decl(), op_build_info::decl(),
op_cwd::decl(), op_cwd::decl(),

View file

@ -2805,7 +2805,7 @@ fn js_runtime(performance: Arc<Performance>) -> JsRuntime {
} }
fn init_extension(performance: Arc<Performance>) -> Extension { fn init_extension(performance: Arc<Performance>) -> Extension {
Extension::builder() Extension::builder("deno_tsc")
.ops(vec![ .ops(vec![
op_exists::decl(), op_exists::decl(),
op_is_cancelled::decl(), op_is_cancelled::decl(),

View file

@ -22,7 +22,7 @@ pub fn init(
sender: UnboundedSender<BenchEvent>, sender: UnboundedSender<BenchEvent>,
filter: TestFilter, filter: TestFilter,
) -> Extension { ) -> Extension {
Extension::builder() Extension::builder("deno_bench")
.ops(vec![ .ops(vec![
op_pledge_test_permissions::decl(), op_pledge_test_permissions::decl(),
op_restore_test_permissions::decl(), op_restore_test_permissions::decl(),

View file

@ -14,7 +14,7 @@ pub fn cli_exts(ps: ProcState) -> Vec<Extension> {
} }
fn init_proc_state(ps: ProcState) -> Extension { fn init_proc_state(ps: ProcState) -> Extension {
Extension::builder() Extension::builder("deno_cli")
.ops(vec![op_npm_process_state::decl()]) .ops(vec![op_npm_process_state::decl()])
.state(move |state| { .state(move |state| {
state.put(ps.clone()); state.put(ps.clone());

View file

@ -30,7 +30,7 @@ pub fn init(
fail_fast_tracker: FailFastTracker, fail_fast_tracker: FailFastTracker,
filter: TestFilter, filter: TestFilter,
) -> Extension { ) -> Extension {
Extension::builder() Extension::builder("deno_test")
.ops(vec![ .ops(vec![
op_pledge_test_permissions::decl(), op_pledge_test_permissions::decl(),
op_restore_test_permissions::decl(), op_restore_test_permissions::decl(),

View file

@ -770,7 +770,7 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
.collect(); .collect();
let mut runtime = JsRuntime::new(RuntimeOptions { let mut runtime = JsRuntime::new(RuntimeOptions {
startup_snapshot: Some(compiler_snapshot()), startup_snapshot: Some(compiler_snapshot()),
extensions: vec![Extension::builder() extensions: vec![Extension::builder("deno_cli_tsc")
.ops(vec![ .ops(vec![
op_cwd::decl(), op_cwd::decl(),
op_create_hash::decl(), op_create_hash::decl(),

View file

@ -7,7 +7,7 @@ use deno_core::JsRuntime;
use deno_core::RuntimeOptions; use deno_core::RuntimeOptions;
fn main() { fn main() {
let my_ext = Extension::builder() let my_ext = Extension::builder("my_ext")
.middleware(|op| match op.name { .middleware(|op| match op.name {
"op_print" => op.disable(), "op_print" => op.disable(),
_ => op, _ => op,

View file

@ -22,7 +22,7 @@ fn op_sum(nums: Vec<f64>) -> Result<f64, deno_core::error::AnyError> {
fn main() { fn main() {
// Build a deno_core::Extension providing custom ops // Build a deno_core::Extension providing custom ops
let ext = Extension::builder() let ext = Extension::builder("my_ext")
.ops(vec![ .ops(vec![
// An op for summing an array of numbers // An op for summing an array of numbers
// The op-layer automatically deserializes inputs // The op-layer automatically deserializes inputs

View file

@ -117,7 +117,7 @@ impl From<tokio::net::TcpStream> for TcpStream {
} }
fn create_js_runtime() -> JsRuntime { 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()]) .ops(vec![op_listen::decl(), op_accept::decl()])
.build(); .build();

View file

@ -24,8 +24,9 @@ fn main() {
panic!("panik !!!") panic!("panik !!!")
} }
let extensions = let extensions = vec![Extension::builder("my_ext")
vec![Extension::builder().ops(vec![op_panik::decl()]).build()]; .ops(vec![op_panik::decl()])
.build()];
let mut rt = JsRuntime::new(RuntimeOptions { let mut rt = JsRuntime::new(RuntimeOptions {
extensions, extensions,
..Default::default() ..Default::default()

View file

@ -18,7 +18,7 @@ use deno_core::*;
type Task = Box<dyn FnOnce()>; type Task = Box<dyn FnOnce()>;
fn main() { fn main() {
let my_ext = Extension::builder() let my_ext = Extension::builder("my_ext")
.ops(vec![op_schedule_task::decl()]) .ops(vec![op_schedule_task::decl()])
.event_loop_middleware(|state_rc, cx| { .event_loop_middleware(|state_rc, cx| {
let mut state = state_rc.borrow_mut(); let mut state = state_rc.borrow_mut();

View file

@ -51,7 +51,7 @@ fn op_set_wasm_mem(
fn main() { fn main() {
// Build a deno_core::Extension providing custom ops // 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()]) .ops(vec![op_wasm::decl(), op_set_wasm_mem::decl()])
.build(); .build();

View file

@ -42,13 +42,39 @@ pub struct Extension {
event_loop_middleware: Option<Box<OpEventLoopFn>>, event_loop_middleware: Option<Box<OpEventLoopFn>>,
initialized: bool, initialized: bool,
enabled: bool, enabled: bool,
name: &'static str,
deps: Option<Vec<&'static str>>,
} }
// Note: this used to be a trait, but we "downgraded" it to a single concrete type // 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 // for the initial iteration, it will likely become a trait in the future
impl Extension { impl Extension {
pub fn builder() -> ExtensionBuilder { pub fn builder(name: &'static str) -> ExtensionBuilder {
Default::default() 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, /// returns JS source code to be loaded into the isolate (either at snapshotting,
@ -121,9 +147,16 @@ pub struct ExtensionBuilder {
state: Option<Box<OpStateFn>>, state: Option<Box<OpStateFn>>,
middleware: Option<Box<OpMiddlewareFn>>, middleware: Option<Box<OpMiddlewareFn>>,
event_loop_middleware: Option<Box<OpEventLoopFn>>, event_loop_middleware: Option<Box<OpEventLoopFn>>,
name: &'static str,
deps: Vec<&'static str>,
} }
impl ExtensionBuilder { 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<SourcePair>) -> &mut Self { pub fn js(&mut self, js_files: Vec<SourcePair>) -> &mut Self {
self.js.extend(js_files); self.js.extend(js_files);
self self
@ -161,6 +194,7 @@ impl ExtensionBuilder {
pub fn build(&mut self) -> Extension { pub fn build(&mut self) -> Extension {
let js_files = Some(std::mem::take(&mut self.js)); let js_files = Some(std::mem::take(&mut self.js));
let ops = Some(std::mem::take(&mut self.ops)); let ops = Some(std::mem::take(&mut self.ops));
let deps = Some(std::mem::take(&mut self.deps));
Extension { Extension {
js_files, js_files,
ops, ops,
@ -169,6 +203,8 @@ impl ExtensionBuilder {
event_loop_middleware: self.event_loop_middleware.take(), event_loop_middleware: self.event_loop_middleware.take(),
initialized: false, initialized: false,
enabled: true, enabled: true,
name: self.name,
deps,
} }
} }
} }

View file

@ -1479,7 +1479,9 @@ import "/a.js";
43 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 { let mut runtime = JsRuntime::new(RuntimeOptions {
extensions: vec![ext], extensions: vec![ext],

View file

@ -17,7 +17,7 @@ use std::io::{stderr, stdout, Write};
use std::rc::Rc; use std::rc::Rc;
pub(crate) fn init_builtins() -> Extension { pub(crate) fn init_builtins() -> Extension {
Extension::builder() Extension::builder("deno_builtins")
.js(include_js_files!( .js(include_js_files!(
prefix "deno:core", prefix "deno:core",
"00_primordials.js", "00_primordials.js",

View file

@ -728,10 +728,9 @@ impl JsRuntime {
/// Initializes JS of provided Extensions in the given realm /// Initializes JS of provided Extensions in the given realm
fn init_extension_js(&mut self, realm: &JsRealm) -> Result<(), Error> { fn init_extension_js(&mut self, realm: &JsRealm) -> Result<(), Error> {
// Take extensions to avoid double-borrow // Take extensions to avoid double-borrow
let mut extensions: Vec<Extension> = let extensions = std::mem::take(&mut self.extensions_with_js);
std::mem::take(&mut self.extensions_with_js); for ext in &extensions {
for m in extensions.iter_mut() { let js_files = ext.init_js();
let js_files = m.init_js();
for (filename, source) in js_files { for (filename, source) in js_files {
// TODO(@AaronO): use JsRuntime::execute_static() here to move src off heap // TODO(@AaronO): use JsRuntime::execute_static() here to move src off heap
realm.execute_script(self.v8_isolate(), filename, source)?; realm.execute_script(self.v8_isolate(), filename, source)?;
@ -752,6 +751,12 @@ impl JsRuntime {
exts.extend(extensions); exts.extend(extensions);
exts.extend(extensions_with_js); 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 // Middleware
let middleware: Vec<Box<OpMiddlewareFn>> = exts let middleware: Vec<Box<OpMiddlewareFn>> = exts
.iter_mut() .iter_mut()
@ -2554,7 +2559,7 @@ pub mod tests {
fn setup(mode: Mode) -> (JsRuntime, Arc<AtomicUsize>) { fn setup(mode: Mode) -> (JsRuntime, Arc<AtomicUsize>) {
let dispatch_count = Arc::new(AtomicUsize::new(0)); let dispatch_count = Arc::new(AtomicUsize::new(0));
let dispatch_count2 = dispatch_count.clone(); let dispatch_count2 = dispatch_count.clone();
let ext = Extension::builder() let ext = Extension::builder("test_ext")
.ops(vec![op_test::decl()]) .ops(vec![op_test::decl()])
.state(move |state| { .state(move |state| {
state.put(TestState { state.put(TestState {
@ -2976,7 +2981,9 @@ pub mod tests {
} }
run_in_task(|cx| { 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 { let mut runtime = JsRuntime::new(RuntimeOptions {
extensions: vec![ext], extensions: vec![ext],
get_error_class_fn: Some(&get_error_class_name), get_error_class_fn: Some(&get_error_class_name),
@ -3428,7 +3435,7 @@ main();
} }
run_in_task(|cx| { run_in_task(|cx| {
let ext = Extension::builder() let ext = Extension::builder("test_ext")
.ops(vec![op_err_sync::decl(), op_err_async::decl()]) .ops(vec![op_err_sync::decl(), op_err_async::decl()])
.build(); .build();
let mut runtime = JsRuntime::new(RuntimeOptions { let mut runtime = JsRuntime::new(RuntimeOptions {
@ -3596,7 +3603,7 @@ assertEquals(1, notify_return_value);
Ok(()) Ok(())
} }
let extension = Extension::builder() let extension = Extension::builder("test_ext")
.ops(vec![op_async_borrow::decl()]) .ops(vec![op_async_borrow::decl()])
.state(|state| { .state(|state| {
state.put(InnerState(42)); state.put(InnerState(42));
@ -3631,7 +3638,7 @@ assertEquals(1, notify_return_value);
Ok(()) Ok(())
} }
let extension = Extension::builder() let extension = Extension::builder("test_ext")
.ops(vec![op_sync_serialize_object_with_numbers_as_keys::decl()]) .ops(vec![op_sync_serialize_object_with_numbers_as_keys::decl()])
.build(); .build();
@ -3673,7 +3680,7 @@ Deno.core.ops.op_sync_serialize_object_with_numbers_as_keys({
Ok(()) Ok(())
} }
let extension = Extension::builder() let extension = Extension::builder("test_ext")
.ops(vec![op_async_serialize_object_with_numbers_as_keys::decl()]) .ops(vec![op_async_serialize_object_with_numbers_as_keys::decl()])
.build(); .build();
@ -3712,7 +3719,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
Ok(()) Ok(())
} }
let extension = Extension::builder() let extension = Extension::builder("test_ext")
.ops(vec![op_async_sleep::decl()]) .ops(vec![op_async_sleep::decl()])
.build(); .build();
@ -3792,7 +3799,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
Ok(()) Ok(())
} }
let extension = Extension::builder() let extension = Extension::builder("test_ext")
.ops(vec![op_macrotask::decl(), op_next_tick::decl()]) .ops(vec![op_macrotask::decl(), op_next_tick::decl()])
.build(); .build();
@ -3922,7 +3929,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
Ok(()) Ok(())
} }
let extension = Extension::builder() let extension = Extension::builder("test_ext")
.ops(vec![op_promise_reject::decl()]) .ops(vec![op_promise_reject::decl()])
.build(); .build();
@ -3982,7 +3989,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
Ok(()) Ok(())
} }
let extension = Extension::builder() let extension = Extension::builder("test_ext")
.ops(vec![op_promise_reject::decl()]) .ops(vec![op_promise_reject::decl()])
.build(); .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 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 { let mut runtime = JsRuntime::new(RuntimeOptions {
extensions: vec![ext], extensions: vec![ext],
..Default::default() ..Default::default()
@ -4076,7 +4085,9 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
Ok(x1 + x2 + x3 + x4) 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 { let mut runtime = JsRuntime::new(RuntimeOptions {
extensions: vec![ext], extensions: vec![ext],
..Default::default() ..Default::default()
@ -4095,7 +4106,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
Ok(42) Ok(42)
} }
let ext = Extension::builder() let ext = Extension::builder("test_ext")
.ops(vec![op_foo::decl().disable()]) .ops(vec![op_foo::decl().disable()])
.build(); .build();
let mut runtime = JsRuntime::new(RuntimeOptions { let mut runtime = JsRuntime::new(RuntimeOptions {
@ -4125,7 +4136,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
Ok(b) Ok(b)
} }
let ext = Extension::builder() let ext = Extension::builder("test_ext")
.ops(vec![op_sum_take::decl(), op_boomerang::decl()]) .ops(vec![op_sum_take::decl(), op_boomerang::decl()])
.build(); .build();
@ -4193,7 +4204,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
Ok(42) Ok(42)
} }
let ext = Extension::builder() let ext = Extension::builder("test_ext")
.ops(vec![op_foo::decl(), op_bar::decl()]) .ops(vec![op_foo::decl(), op_bar::decl()])
.middleware(|op| if op.is_unstable { op.disable() } else { op }) .middleware(|op| if op.is_unstable { op.disable() } else { op })
.build(); .build();
@ -4245,7 +4256,9 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
} }
let mut runtime = JsRuntime::new(RuntimeOptions { 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() ..Default::default()
}); });
let realm = runtime.create_realm().unwrap(); 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 { let mut runtime = JsRuntime::new(RuntimeOptions {
startup_snapshot: Some(Snapshot::Boxed(snapshot)), 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() ..Default::default()
}); });
let realm = runtime.create_realm().unwrap(); 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 { 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| { get_error_class_fn: Some(&|error| {
crate::error::get_custom_error_class(error).unwrap() crate::error::get_custom_error_class(error).unwrap()
}), }),

View file

@ -109,7 +109,8 @@ pub fn init<BC: BroadcastChannel + 'static>(
bc: BC, bc: BC,
unstable: bool, unstable: bool,
) -> Extension { ) -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.dependencies(vec!["deno_webidl", "deno_web"])
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/broadcast_channel", prefix "deno:ext/broadcast_channel",
"01_broadcast_channel.js", "01_broadcast_channel.js",

3
ext/cache/lib.rs vendored
View file

@ -26,7 +26,8 @@ pub struct CreateCache<C: Cache + 'static>(pub Arc<dyn Fn() -> C>);
pub fn init<CA: Cache + 'static>( pub fn init<CA: Cache + 'static>(
maybe_create_cache: Option<CreateCache<CA>>, maybe_create_cache: Option<CreateCache<CA>>,
) -> Extension { ) -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.dependencies(vec!["deno_webidl", "deno_web", "deno_url", "deno_fetch"])
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/cache", prefix "deno:ext/cache",
"01_cache.js", "01_cache.js",

View file

@ -5,7 +5,7 @@ use deno_core::Extension;
use std::path::PathBuf; use std::path::PathBuf;
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/console", prefix "deno:ext/console",
"01_colors.js", "01_colors.js",

View file

@ -73,7 +73,8 @@ use crate::key::HkdfOutput;
use crate::shared::RawKeyData; use crate::shared::RawKeyData;
pub fn init(maybe_seed: Option<u64>) -> Extension { pub fn init(maybe_seed: Option<u64>) -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.dependencies(vec!["deno_webidl", "deno_web"])
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/crypto", prefix "deno:ext/crypto",
"00_crypto.js", "00_crypto.js",

View file

@ -94,7 +94,8 @@ pub fn init<FP>(options: Options) -> Extension
where where
FP: FetchPermissions + 'static, 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!( .js(include_js_files!(
prefix "deno:ext/fetch", prefix "deno:ext/fetch",
"01_fetch_util.js", "01_fetch_util.js",

View file

@ -84,7 +84,7 @@ pub(crate) struct FfiState {
} }
pub fn init<P: FfiPermissions + 'static>(unstable: bool) -> Extension { pub fn init<P: FfiPermissions + 'static>(unstable: bool) -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/ffi", prefix "deno:ext/ffi",
"00_ffi.js", "00_ffi.js",

View file

@ -1505,7 +1505,14 @@ pub trait FlashPermissions {
} }
pub fn init<P: FlashPermissions + 'static>(unstable: bool) -> Extension { pub fn init<P: FlashPermissions + 'static>(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!( .js(deno_core::include_js_files!(
prefix "deno:ext/flash", prefix "deno:ext/flash",
"01_http.js", "01_http.js",

View file

@ -78,7 +78,8 @@ pub mod compressible;
mod reader_stream; mod reader_stream;
pub fn init() -> Extension { 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!( .js(include_js_files!(
prefix "deno:ext/http", prefix "deno:ext/http",
"01_http.js", "01_http.js",

View file

@ -410,7 +410,7 @@ impl Env {
} }
pub fn init<P: NapiPermissions + 'static>(unstable: bool) -> Extension { pub fn init<P: NapiPermissions + 'static>(unstable: bool) -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.ops(vec![op_napi_open::decl::<P>()]) .ops(vec![op_napi_open::decl::<P>()])
.event_loop_middleware(|op_state_rc, cx| { .event_loop_middleware(|op_state_rc, cx| {
// `work` can call back into the runtime. It can also schedule an async task // `work` can call back into the runtime. It can also schedule an async task

View file

@ -85,7 +85,8 @@ pub fn init<P: NetPermissions + 'static>(
) -> Extension { ) -> Extension {
let mut ops = ops::init::<P>(); let mut ops = ops::init::<P>();
ops.extend(ops_tls::init::<P>()); ops.extend(ops_tls::init::<P>());
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.dependencies(vec!["deno_web"])
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/net", prefix "deno:ext/net",
"01_net.js", "01_net.js",

View file

@ -865,7 +865,7 @@ mod tests {
let listener = TcpListener::bind(addr).await.unwrap(); let listener = TcpListener::bind(addr).await.unwrap();
let _ = listener.accept().await; let _ = listener.accept().await;
}); });
let my_ext = Extension::builder() let my_ext = Extension::builder("test_ext")
.state(move |state| { .state(move |state| {
state.put(TestPermission {}); state.put(TestPermission {});
state.put(UnstableChecker { unstable: true }); state.put(UnstableChecker { unstable: true });

View file

@ -80,7 +80,7 @@ pub static NODE_ENV_VAR_ALLOWLIST: Lazy<HashSet<String>> = Lazy::new(|| {
pub fn init<P: NodePermissions + 'static>( pub fn init<P: NodePermissions + 'static>(
maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>, maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>,
) -> Extension { ) -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/node", prefix "deno:ext/node",
"01_node.js", "01_node.js",

View file

@ -37,7 +37,7 @@ use std::time::SystemTime;
/// This extension has no runtime apis, it only exports some shared native functions. /// This extension has no runtime apis, it only exports some shared native functions.
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder().build() Extension::builder(env!("CARGO_PKG_NAME")).build()
} }
struct DefaultSignatureVerification; struct DefaultSignatureVerification;

View file

@ -8,7 +8,7 @@ fn setup() -> Vec<Extension> {
vec![ vec![
deno_webidl::init(), deno_webidl::init(),
deno_url::init(), deno_url::init(),
Extension::builder() Extension::builder("bench_setup")
.js(vec![( .js(vec![(
"setup", "setup",
"const { URL } = globalThis.__bootstrap.url;", "const { URL } = globalThis.__bootstrap.url;",

View file

@ -18,7 +18,8 @@ use crate::urlpattern::op_urlpattern_parse;
use crate::urlpattern::op_urlpattern_process_match_input; use crate::urlpattern::op_urlpattern_process_match_input;
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.dependencies(vec!["deno_webidl"])
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/url", prefix "deno:ext/url",
"00_url.js", "00_url.js",

View file

@ -25,6 +25,7 @@ uuid = { workspace = true, features = ["serde"] }
[dev-dependencies] [dev-dependencies]
deno_bench_util.workspace = true deno_bench_util.workspace = true
deno_console.workspace = true
deno_url.workspace = true deno_url.workspace = true
deno_webidl.workspace = true deno_webidl.workspace = true

View file

@ -24,8 +24,9 @@ fn setup() -> Vec<Extension> {
vec![ vec![
deno_webidl::init(), deno_webidl::init(),
deno_url::init(), deno_url::init(),
deno_console::init(),
deno_web::init::<Permissions>(BlobStore::default(), None), deno_web::init::<Permissions>(BlobStore::default(), None),
Extension::builder() Extension::builder("bench_setup")
.js(vec![( .js(vec![(
"setup", "setup",
r#" r#"

View file

@ -23,8 +23,9 @@ fn setup() -> Vec<Extension> {
vec![ vec![
deno_webidl::init(), deno_webidl::init(),
deno_url::init(), deno_url::init(),
deno_console::init(),
deno_web::init::<Permissions>(BlobStore::default(), None), deno_web::init::<Permissions>(BlobStore::default(), None),
Extension::builder() Extension::builder("bench_setup")
.js(vec![ .js(vec![
("setup", r#" ("setup", r#"
const { setTimeout, handleTimerMacrotask } = globalThis.__bootstrap.timers; const { setTimeout, handleTimerMacrotask } = globalThis.__bootstrap.timers;

View file

@ -62,7 +62,8 @@ pub fn init<P: TimersPermission + 'static>(
blob_store: BlobStore, blob_store: BlobStore,
maybe_location: Option<Url>, maybe_location: Option<Url>,
) -> Extension { ) -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.dependencies(vec!["deno_webidl", "deno_console", "deno_url"])
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/web", prefix "deno:ext/web",
"00_infra.js", "00_infra.js",

View file

@ -104,7 +104,8 @@ impl Resource for WebGpuQuerySet {
} }
pub fn init(unstable: bool) -> Extension { pub fn init(unstable: bool) -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.dependencies(vec!["deno_webidl", "deno_web"])
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/webgpu", prefix "deno:ext/webgpu",
"01_webgpu.js", "01_webgpu.js",

View file

@ -5,7 +5,7 @@ use deno_core::Extension;
/// Load and execute the javascript code. /// Load and execute the javascript code.
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/webidl", prefix "deno:ext/webidl",
"00_webidl.js", "00_webidl.js",

View file

@ -602,7 +602,8 @@ pub fn init<P: WebSocketPermissions + 'static>(
root_cert_store: Option<RootCertStore>, root_cert_store: Option<RootCertStore>,
unsafely_ignore_certificate_errors: Option<Vec<String>>, unsafely_ignore_certificate_errors: Option<Vec<String>>,
) -> Extension { ) -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.dependencies(vec!["deno_url", "deno_webidl"])
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/websocket", prefix "deno:ext/websocket",
"01_websocket.js", "01_websocket.js",

View file

@ -22,7 +22,8 @@ struct OriginStorageDir(PathBuf);
const MAX_STORAGE_BYTES: u32 = 10 * 1024 * 1024; const MAX_STORAGE_BYTES: u32 = 10 * 1024 * 1024;
pub fn init(origin_storage_dir: Option<PathBuf>) -> Extension { pub fn init(origin_storage_dir: Option<PathBuf>) -> Extension {
Extension::builder() Extension::builder(env!("CARGO_PKG_NAME"))
.dependencies(vec!["deno_webidl"])
.js(include_js_files!( .js(include_js_files!(
prefix "deno:ext/webstorage", prefix "deno:ext/webstorage",
"01_webstorage.js", "01_webstorage.js",

View file

@ -42,7 +42,7 @@ use deno_core::error::generic_error;
use deno_core::error::not_supported; use deno_core::error::not_supported;
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder("deno_fs")
.ops(vec![ .ops(vec![
op_open_sync::decl(), op_open_sync::decl(),
op_open_async::decl(), op_open_async::decl(),

View file

@ -30,7 +30,7 @@ use std::rc::Rc;
use tokio::sync::mpsc; use tokio::sync::mpsc;
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder("deno_fs_events")
.ops(vec![op_fs_events_open::decl(), op_fs_events_poll::decl()]) .ops(vec![op_fs_events_open::decl(), op_fs_events_poll::decl()])
.build() .build()
} }

View file

@ -27,7 +27,7 @@ use deno_net::io::UnixStreamResource;
use tokio::net::UnixStream; use tokio::net::UnixStream;
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder("deno_http_runtime")
.ops(vec![ .ops(vec![
op_http_start::decl(), op_http_start::decl(),
op_http_upgrade::decl(), op_http_upgrade::decl(),

View file

@ -76,7 +76,7 @@ pub static STDERR_HANDLE: Lazy<StdFile> = Lazy::new(|| {
}); });
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder("deno_io")
.ops(vec![op_read_sync::decl(), op_write_sync::decl()]) .ops(vec![op_read_sync::decl(), op_write_sync::decl()])
.build() .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 // 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))); let stdio = Rc::new(RefCell::new(Some(stdio)));
Extension::builder() Extension::builder("deno_stdio")
.middleware(|op| match op.name { .middleware(|op| match op.name {
"op_print" => op_print::decl(), "op_print" => op_print::decl(),
_ => op, _ => op,

View file

@ -40,7 +40,7 @@ fn init_ops(builder: &mut ExtensionBuilder) -> &mut ExtensionBuilder {
} }
pub fn init(exit_code: ExitCode) -> Extension { pub fn init(exit_code: ExitCode) -> Extension {
let mut builder = Extension::builder(); let mut builder = Extension::builder("deno_os");
init_ops(&mut builder) init_ops(&mut builder)
.state(move |state| { .state(move |state| {
state.put::<ExitCode>(exit_code.clone()); state.put::<ExitCode>(exit_code.clone());
@ -50,7 +50,7 @@ pub fn init(exit_code: ExitCode) -> Extension {
} }
pub fn init_for_worker() -> Extension { pub fn init_for_worker() -> Extension {
let mut builder = Extension::builder(); let mut builder = Extension::builder("deno_os_worker");
init_ops(&mut builder) init_ops(&mut builder)
.middleware(|op| match op.name { .middleware(|op| match op.name {
"op_exit" => noop_op::decl(), "op_exit" => noop_op::decl(),

View file

@ -13,7 +13,7 @@ use serde::Deserialize;
use std::path::Path; use std::path::Path;
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder("deno_permissions")
.ops(vec![ .ops(vec![
op_query_permission::decl(), op_query_permission::decl(),
op_revoke_permission::decl(), op_revoke_permission::decl(),

View file

@ -27,7 +27,7 @@ use tokio::process::Command;
use std::os::unix::process::ExitStatusExt; use std::os::unix::process::ExitStatusExt;
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder("deno_process")
.ops(vec![op_run::decl(), op_run_status::decl(), op_kill::decl()]) .ops(vec![op_run::decl(), op_run_status::decl(), op_kill::decl()])
.build() .build()
} }

View file

@ -9,7 +9,7 @@ use deno_core::ModuleSpecifier;
use deno_core::OpState; use deno_core::OpState;
pub fn init(main_module: ModuleSpecifier) -> Extension { pub fn init(main_module: ModuleSpecifier) -> Extension {
Extension::builder() Extension::builder("deno_runtime")
.ops(vec![op_main_module::decl()]) .ops(vec![op_main_module::decl()])
.state(move |state| { .state(move |state| {
state.put::<ModuleSpecifier>(main_module.clone()); state.put::<ModuleSpecifier>(main_module.clone());

View file

@ -21,7 +21,7 @@ use tokio::signal::unix::{signal, Signal, SignalKind};
use tokio::signal::windows::{ctrl_break, ctrl_c, CtrlBreak, CtrlC}; use tokio::signal::windows::{ctrl_break, ctrl_c, CtrlBreak, CtrlC};
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder("deno_signal")
.ops(vec![ .ops(vec![
op_signal_bind::decl(), op_signal_bind::decl(),
op_signal_unbind::decl(), op_signal_unbind::decl(),

View file

@ -28,7 +28,7 @@ use std::os::unix::prelude::ExitStatusExt;
use std::os::unix::process::CommandExt; use std::os::unix::process::CommandExt;
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder("deno_spawn")
.ops(vec![ .ops(vec![
op_spawn_child::decl(), op_spawn_child::decl(),
op_node_unstable_spawn_child::decl(), op_node_unstable_spawn_child::decl(),

View file

@ -34,7 +34,7 @@ fn get_windows_handle(
} }
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder("deno_tty")
.ops(vec![ .ops(vec![
op_stdin_set_raw::decl(), op_stdin_set_raw::decl(),
op_isatty::decl(), op_isatty::decl(),

View file

@ -17,7 +17,7 @@ use std::rc::Rc;
use self::sync_fetch::op_worker_sync_fetch; use self::sync_fetch::op_worker_sync_fetch;
pub fn init() -> Extension { pub fn init() -> Extension {
Extension::builder() Extension::builder("deno_web_worker")
.ops(vec![ .ops(vec![
op_worker_post_message::decl(), op_worker_post_message::decl(),
op_worker_recv_message::decl(), op_worker_recv_message::decl(),

View file

@ -94,7 +94,7 @@ pub fn init(
pre_execute_module_cb: Arc<WorkerEventCb>, pre_execute_module_cb: Arc<WorkerEventCb>,
format_js_error_fn: Option<Arc<FormatJsErrorFn>>, format_js_error_fn: Option<Arc<FormatJsErrorFn>>,
) -> Extension { ) -> Extension {
Extension::builder() Extension::builder("deno_worker_host")
.state(move |state| { .state(move |state| {
state.put::<WorkersTable>(WorkersTable::default()); state.put::<WorkersTable>(WorkersTable::default());
state.put::<WorkerId>(WorkerId::default()); state.put::<WorkerId>(WorkerId::default());

View file

@ -370,7 +370,7 @@ impl WebWorker {
// Permissions: many ops depend on this // Permissions: many ops depend on this
let unstable = options.bootstrap.unstable; let unstable = options.bootstrap.unstable;
let enable_testing_features = options.bootstrap.enable_testing_features; 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(move |state| {
state.put::<PermissionsContainer>(permissions.clone()); state.put::<PermissionsContainer>(permissions.clone());
state.put(ops::UnstableChecker { unstable }); state.put(ops::UnstableChecker { unstable });

View file

@ -202,7 +202,7 @@ impl MainWorker {
// Permissions: many ops depend on this // Permissions: many ops depend on this
let unstable = options.bootstrap.unstable; let unstable = options.bootstrap.unstable;
let enable_testing_features = options.bootstrap.enable_testing_features; 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(move |state| {
state.put::<PermissionsContainer>(permissions.clone()); state.put::<PermissionsContainer>(permissions.clone());
state.put(ops::UnstableChecker { unstable }); state.put(ops::UnstableChecker { unstable });