diff options
-rw-r--r-- | cli/build.rs | 14 | ||||
-rw-r--r-- | cli/lsp/tsc.rs | 6 | ||||
-rw-r--r-- | cli/ops/bench.rs | 8 | ||||
-rw-r--r-- | cli/ops/mod.rs | 6 | ||||
-rw-r--r-- | cli/ops/testing.rs | 10 | ||||
-rw-r--r-- | cli/tsc/mod.rs | 21 | ||||
-rw-r--r-- | core/extensions.rs | 86 | ||||
-rw-r--r-- | core/runtime.rs | 8 | ||||
-rw-r--r-- | ext/broadcast_channel/lib.rs | 8 | ||||
-rw-r--r-- | ext/cache/lib.rs | 6 | ||||
-rw-r--r-- | ext/crypto/lib.rs | 6 | ||||
-rw-r--r-- | ext/fetch/lib.rs | 14 | ||||
-rw-r--r-- | ext/ffi/lib.rs | 6 | ||||
-rw-r--r-- | ext/flash/lib.rs | 6 | ||||
-rw-r--r-- | ext/fs/lib.rs | 6 | ||||
-rw-r--r-- | ext/io/lib.rs | 80 | ||||
-rw-r--r-- | ext/net/lib.rs | 10 | ||||
-rw-r--r-- | ext/node/lib.rs | 6 | ||||
-rw-r--r-- | ext/web/lib.rs | 8 | ||||
-rw-r--r-- | ext/websocket/lib.rs | 10 | ||||
-rw-r--r-- | ext/webstorage/lib.rs | 6 | ||||
-rw-r--r-- | runtime/build.rs | 6 | ||||
-rw-r--r-- | runtime/ops/os/mod.rs | 6 | ||||
-rw-r--r-- | runtime/ops/runtime.rs | 6 | ||||
-rw-r--r-- | runtime/ops/worker_host.rs | 12 | ||||
-rw-r--r-- | runtime/web_worker.rs | 12 | ||||
-rw-r--r-- | runtime/worker.rs | 13 |
27 files changed, 209 insertions, 177 deletions
diff --git a/cli/build.rs b/cli/build.rs index e4df856f7..9068723d4 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -1,9 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -use std::cell::RefCell; use std::env; use std::path::PathBuf; -use std::rc::Rc; use deno_core::snapshot_util::*; use deno_core::Extension; @@ -122,15 +120,15 @@ mod ts { "00_typescript.js", "99_main_compiler.js", ], - config = { + options = { op_crate_libs: HashMap<&'static str, PathBuf>, build_libs: Vec<&'static str>, path_dts: PathBuf, }, - state = |state, op_crate_libs, build_libs, path_dts| { - state.put(op_crate_libs); - state.put(build_libs); - state.put(path_dts); + state = |state, options| { + state.put(options.op_crate_libs); + state.put(options.build_libs); + state.put(options.path_dts); }, ); @@ -362,7 +360,7 @@ fn create_cli_snapshot(snapshot_path: PathBuf) { deno_tls::deno_tls::init_ops(), deno_napi::deno_napi::init_ops::<PermissionsContainer>(), deno_http::deno_http::init_ops(), - deno_io::deno_io::init_ops(Rc::new(RefCell::new(Some(Default::default())))), + deno_io::deno_io::init_ops(Default::default()), deno_fs::deno_fs::init_ops::<PermissionsContainer>(false), deno_flash::deno_flash::init_ops::<PermissionsContainer>(false), // No --unstable deno_node::deno_node_loading::init_ops::<PermissionsContainer>(None), // No --unstable. diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 910d13691..91eb6e24b 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -2834,13 +2834,13 @@ deno_core::extension!(deno_tsc, op_script_names, op_script_version, ], - config = { + options = { performance: Arc<Performance> }, - state = |state, performance| { + state = |state, options| { state.put(State::new( Arc::new(StateSnapshot::default()), - performance, + options.performance, )); }, ); diff --git a/cli/ops/bench.rs b/cli/ops/bench.rs index 7bd3f988a..6fa9edee8 100644 --- a/cli/ops/bench.rs +++ b/cli/ops/bench.rs @@ -30,13 +30,13 @@ deno_core::extension!(deno_bench, op_dispatch_bench_event, op_bench_now, ], - config = { + options = { sender: UnboundedSender<BenchEvent>, filter: TestFilter, }, - state = |state, sender, filter| { - state.put(sender); - state.put(filter); + state = |state, options| { + state.put(options.sender); + state.put(options.filter); }, ); diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs index 562aa8649..c12409514 100644 --- a/cli/ops/mod.rs +++ b/cli/ops/mod.rs @@ -15,11 +15,11 @@ pub fn cli_exts(ps: ProcState) -> Vec<Extension> { deno_core::extension!(deno_cli, ops = [op_npm_process_state], - config = { + options = { ps: ProcState, }, - state = |state, ps| { - state.put(ps); + state = |state, options| { + state.put(options.ps); }, ); diff --git a/cli/ops/testing.rs b/cli/ops/testing.rs index f32e96147..0849f1c7a 100644 --- a/cli/ops/testing.rs +++ b/cli/ops/testing.rs @@ -34,15 +34,15 @@ deno_core::extension!(deno_test, op_dispatch_test_event, op_tests_should_stop, ], - config = { + options = { sender: TestEventSender, fail_fast_tracker: FailFastTracker, filter: TestFilter, }, - state = |state, sender, fail_fast_tracker, filter| { - state.put(sender); - state.put(fail_fast_tracker); - state.put(filter); + state = |state, options| { + state.put(options.sender); + state.put(options.fail_fast_tracker); + state.put(options.filter); }, ); diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index 387fd3aa1..45589780f 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -41,7 +41,6 @@ use std::collections::HashMap; use std::fmt; use std::path::Path; use std::path::PathBuf; -use std::rc::Rc; use std::sync::Arc; mod diagnostics; @@ -829,19 +828,19 @@ pub fn exec(request: Request) -> Result<Response, AnyError> { deno_core::extension!(deno_cli_tsc, ops_fn = deno_ops, - config = { - request: Rc<Request>, + options = { + request: Request, root_map: HashMap<String, Url>, remapped_specifiers: HashMap<String, Url>, }, - state = |state, request, root_map, remapped_specifiers| { + state = |state, options| { state.put(State::new( - request.graph.clone(), - request.hash_data.clone(), - request.maybe_npm_resolver.clone(), - request.maybe_tsbuildinfo.clone(), - root_map, - remapped_specifiers, + options.request.graph, + options.request.hash_data, + options.request.maybe_npm_resolver, + options.request.maybe_tsbuildinfo, + options.root_map, + options.remapped_specifiers, std::env::current_dir() .context("Unable to get CWD") .unwrap(), @@ -861,7 +860,7 @@ pub fn exec(request: Request) -> Result<Response, AnyError> { let mut runtime = JsRuntime::new(RuntimeOptions { startup_snapshot: Some(compiler_snapshot()), extensions: vec![deno_cli_tsc::init_ops( - Rc::new(request), + request, root_map, remapped_specifiers, )], diff --git a/core/extensions.rs b/core/extensions.rs index 71b9cdb4f..53ce57be8 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -42,7 +42,7 @@ pub struct ExtensionFileSource { } pub type OpFnRef = v8::FunctionCallback; pub type OpMiddlewareFn = dyn Fn(OpDecl) -> OpDecl; -pub type OpStateFn = dyn Fn(&mut OpState); +pub type OpStateFn = dyn FnOnce(&mut OpState); pub type OpEventLoopFn = dyn Fn(Rc<RefCell<OpState>>, &mut Context) -> bool; pub struct OpDecl { @@ -164,7 +164,7 @@ macro_rules! extension { $(, esm = [ $( dir $dir_esm:literal , )? $( $esm:literal ),* $(,)? ] )? $(, esm_setup_script = $esm_setup_script:expr )? $(, js = [ $( dir $dir_js:literal , )? $( $js:literal ),* $(,)? ] )? - $(, config = { $( $config_id:ident : $config_type:ty ),* $(,)? } )? + $(, options = { $( $options_id:ident : $options_type:ty ),* $(,)? } )? $(, middleware = $middleware_fn:expr )? $(, state = $state_fn:expr )? $(, event_loop_middleware = $event_loop_middleware_fn:ident )? @@ -227,13 +227,13 @@ macro_rules! extension { // Includes the state and middleware functions, if defined. #[inline(always)] #[allow(unused_variables)] - fn with_state_and_middleware$( < $( $param : $type + Clone + 'static ),+ > )?(ext: &mut $crate::ExtensionBuilder, $( $( $config_id : $config_type ),* )? ) { + fn with_state_and_middleware$( < $( $param : $type + Clone + 'static ),+ > )?(ext: &mut $crate::ExtensionBuilder, $( $( $options_id : $options_type ),* )? ) { #[allow(unused_variables)] - let config = $crate::extension!(! __config__ $( parameters = [ $( $param : $type ),* ] )? $( config = { $( $config_id : $config_type ),* } )? ); + let config = $crate::extension!(! __config__ $( parameters = [ $( $param : $type ),* ] )? $( config = { $( $options_id : $options_type ),* } )? ); $( ext.state(move |state: &mut $crate::OpState| { - config.clone().call_callback(state, $state_fn) + config.call_callback(state, $state_fn) }); )? @@ -259,57 +259,78 @@ macro_rules! extension { Self::with_js(&mut ext); Self::with_ops $( ::<($( $param ),+)> )?(&mut ext); Self::with_customizer(&mut ext); - ext.build() + ext.take() } #[allow(dead_code)] - pub fn init_ops_and_esm $( < $( $param : $type + Clone + 'static ),+ > )? ( $( $( $config_id : $config_type ),* )? ) -> $crate::Extension { + pub fn init_ops_and_esm $( < $( $param : $type + Clone + 'static ),+ > )? ( $( $( $options_id : $options_type ),* )? ) -> $crate::Extension { let mut ext = Self::ext(); // If esm or JS was specified, add JS files Self::with_js(&mut ext); Self::with_ops $( ::<($( $param ),+)> )?(&mut ext); - Self::with_state_and_middleware $( ::<($( $param ),+)> )?(&mut ext, $( $( $config_id , )* )? ); + Self::with_state_and_middleware $( ::<($( $param ),+)> )?(&mut ext, $( $( $options_id , )* )? ); Self::with_customizer(&mut ext); - ext.build() + ext.take() } #[allow(dead_code)] - pub fn init_ops $( < $( $param : $type + Clone + 'static ),+ > )? ( $( $( $config_id : $config_type ),* )? ) -> $crate::Extension { + pub fn init_ops $( < $( $param : $type + Clone + 'static ),+ > )? ( $( $( $options_id : $options_type ),* )? ) -> $crate::Extension { let mut ext = Self::ext(); Self::with_ops $( ::<($( $param ),+)> )?(&mut ext); - Self::with_state_and_middleware $( ::<($( $param ),+)> )?(&mut ext, $( $( $config_id , )* )? ); + Self::with_state_and_middleware $( ::<($( $param ),+)> )?(&mut ext, $( $( $options_id , )* )? ); Self::with_customizer(&mut ext); - ext.build() + ext.take() } } }; - (! __config__ $( parameters = [ $( $param:ident : $type:ident ),+ ] )? $( config = { $( $config_id:ident : $config_type:ty ),* } )? ) => { + // This branch of the macro generates a config object that calls the state function with itself. + (! __config__ $( parameters = [ $( $param:ident : $type:ident ),+ ] )? config = { $( $options_id:ident : $options_type:ty ),* } ) => { { #[doc(hidden)] - #[derive(Clone)] struct Config $( < $( $param : $type + Clone + 'static ),+ > )? { - $( $( pub $config_id : $config_type , )* )? + $( pub $options_id : $options_type , )* $( __phantom_data: ::std::marker::PhantomData<($( $param ),+)>, )? } impl $( < $( $param : $type + Clone + 'static ),+ > )? Config $( < $( $param ),+ > )? { - /// Call a function of |state, ...| using the fields of this configuration structure. + /// Call a function of |state, cfg| using this configuration structure. #[allow(dead_code)] #[doc(hidden)] #[inline(always)] - fn call_callback<F: Fn(&mut $crate::OpState, $( $( $config_type ),* )?)>(self, state: &mut $crate::OpState, f: F) { - f(state, $( $( self. $config_id ),* )? ) + fn call_callback<F: Fn(&mut $crate::OpState, Self)>(self, state: &mut $crate::OpState, f: F) { + f(state, self) } } Config { - $( $( $config_id , )* )? + $( $options_id , )* $( __phantom_data: ::std::marker::PhantomData::<($( $param ),+)>::default() )? } } }; + // This branch of the macro generates an empty config object that doesn't actually make any callbacks on the state function. + (! __config__ $( parameters = [ $( $param:ident : $type:ident ),+ ] )? ) => { + { + #[doc(hidden)] + struct Config { + } + + impl Config { + /// Call a function of |state| using the fields of this configuration structure. + #[allow(dead_code)] + #[doc(hidden)] + #[inline(always)] + fn call_callback<F: Fn(&mut $crate::OpState)>(self, state: &mut $crate::OpState, f: F) { + f(state) + } + } + + Config {} + } + }; + (! __ops__ $ext:ident __eot__) => { }; @@ -409,8 +430,8 @@ impl Extension { } /// Allows setting up the initial op-state of an isolate at startup. - pub fn init_state(&self, state: &mut OpState) { - if let Some(op_fn) = &self.opstate_fn { + pub fn init_state(&mut self, state: &mut OpState) { + if let Some(op_fn) = self.opstate_fn.take() { op_fn(state); } } @@ -499,7 +520,7 @@ impl ExtensionBuilder { pub fn state<F>(&mut self, opstate_fn: F) -> &mut Self where - F: Fn(&mut OpState) + 'static, + F: FnOnce(&mut OpState) + 'static, { self.state = Some(Box::new(opstate_fn)); self @@ -521,6 +542,27 @@ impl ExtensionBuilder { self } + /// Consume the [`ExtensionBuilder`] and return an [`Extension`]. + pub fn take(self) -> Extension { + let js_files = Some(self.js); + let esm_files = Some(self.esm); + let ops = Some(self.ops); + let deps = Some(self.deps); + Extension { + js_files, + esm_files, + esm_entry_point: self.esm_entry_point, + ops, + opstate_fn: self.state, + middleware_fn: self.middleware, + event_loop_middleware: self.event_loop_middleware, + initialized: false, + enabled: true, + name: self.name, + deps, + } + } + pub fn build(&mut self) -> Extension { let js_files = Some(std::mem::take(&mut self.js)); let esm_files = Some(std::mem::take(&mut self.esm)); diff --git a/core/runtime.rs b/core/runtime.rs index 1ea9c0168..0531e861c 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -2731,14 +2731,14 @@ pub mod tests { deno_core::extension!( test_ext, ops = [op_test], - config = { + options = { mode: Mode, dispatch_count: Arc<AtomicUsize>, }, - state = |state, mode, dispatch_count| { + state = |state, options| { state.put(TestState { - mode, - dispatch_count + mode: options.mode, + dispatch_count: options.dispatch_count }) } ); diff --git a/ext/broadcast_channel/lib.rs b/ext/broadcast_channel/lib.rs index 3df11566f..5b38e70f8 100644 --- a/ext/broadcast_channel/lib.rs +++ b/ext/broadcast_channel/lib.rs @@ -114,13 +114,13 @@ deno_core::extension!(deno_broadcast_channel, op_broadcast_recv<BC>, ], esm = [ "01_broadcast_channel.js" ], - config = { + options = { bc: BC, unstable: bool, }, - state = |state, bc, unstable| { - state.put(bc); - state.put(Unstable(unstable)); + state = |state, options| { + state.put(options.bc); + state.put(Unstable(options.unstable)); }, ); diff --git a/ext/cache/lib.rs b/ext/cache/lib.rs index eaf56c8b7..b5a29e905 100644 --- a/ext/cache/lib.rs +++ b/ext/cache/lib.rs @@ -32,11 +32,11 @@ deno_core::extension!(deno_cache, op_cache_delete<CA>, ], esm = [ "01_cache.js" ], - config = { + options = { maybe_create_cache: Option<CreateCache<CA>>, }, - state = |state, maybe_create_cache| { - if let Some(create_cache) = maybe_create_cache { + state = |state, options| { + if let Some(create_cache) = options.maybe_create_cache { state.put(create_cache); } }, diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs index 48c5acf4a..6056b02a4 100644 --- a/ext/crypto/lib.rs +++ b/ext/crypto/lib.rs @@ -104,11 +104,11 @@ deno_core::extension!(deno_crypto, x25519::op_export_pkcs8_x25519, ], esm = [ "00_crypto.js", "01_webidl.js" ], - config = { + options = { maybe_seed: Option<u64>, }, - state = |state, maybe_seed| { - if let Some(seed) = maybe_seed { + state = |state, options| { + if let Some(seed) = options.maybe_seed { state.put(StdRng::seed_from_u64(seed)); } }, diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index 4cd5d68c8..9ed73161d 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -107,19 +107,19 @@ deno_core::extension!(deno_fetch, "23_response.js", "26_fetch.js" ], - config = { + options = { options: Options, }, state = |state, options| { - state.put::<Options>(options.clone()); + state.put::<Options>(options.options.clone()); state.put::<reqwest::Client>({ create_http_client( - options.user_agent, - options.root_cert_store, + options.options.user_agent, + options.options.root_cert_store, vec![], - options.proxy, - options.unsafely_ignore_certificate_errors, - options.client_cert_chain_and_key + options.options.proxy, + options.options.unsafely_ignore_certificate_errors, + options.options.client_cert_chain_and_key ) .unwrap() }); diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs index 1fd01c9d2..c11f08dd8 100644 --- a/ext/ffi/lib.rs +++ b/ext/ffi/lib.rs @@ -112,12 +112,12 @@ deno_core::extension!(deno_ffi, op_ffi_unsafe_callback_ref, ], esm = [ "00_ffi.js" ], - config = { + options = { unstable: bool, }, - state = |state, unstable| { + state = |state, options| { // Stolen from deno_webgpu, is there a better option? - state.put(Unstable(unstable)); + state.put(Unstable(options.unstable)); let (async_work_sender, async_work_receiver) = mpsc::unbounded::<PendingFfiAsyncWork>(); diff --git a/ext/flash/lib.rs b/ext/flash/lib.rs index 6f11e14af..b6a586d1f 100644 --- a/ext/flash/lib.rs +++ b/ext/flash/lib.rs @@ -1559,11 +1559,11 @@ deno_core::extension!(deno_flash, op_try_flash_respond_chunked, ], esm = [ "01_http.js" ], - config = { + options = { unstable: bool, }, - state = |state, unstable| { - state.put(Unstable(unstable)); + state = |state, options| { + state.put(Unstable(options.unstable)); state.put(FlashContext { next_server_id: 0, join_handles: HashMap::default(), diff --git a/ext/fs/lib.rs b/ext/fs/lib.rs index 48b0e3495..386d143d2 100644 --- a/ext/fs/lib.rs +++ b/ext/fs/lib.rs @@ -180,11 +180,11 @@ deno_core::extension!(deno_fs, op_readfile_text_async<P>, ], esm = [ "30_fs.js" ], - config = { + options = { unstable: bool }, - state = |state, unstable| { - state.put(UnstableChecker { unstable }); + state = |state, options| { + state.put(UnstableChecker { unstable: options.unstable }); }, ); diff --git a/ext/io/lib.rs b/ext/io/lib.rs index bfbb1d94f..5bb526d4a 100644 --- a/ext/io/lib.rs +++ b/ext/io/lib.rs @@ -80,55 +80,53 @@ deno_core::extension!(deno_io, deps = [ deno_web ], ops = [op_read_sync, op_write_sync], esm = [ "12_io.js" ], - config = { - stdio: Rc<RefCell<Option<Stdio>>>, + options = { + stdio: Option<Stdio>, }, middleware = |op| match op.name { "op_print" => op_print::decl(), _ => op, }, - state = |state, stdio| { - let stdio = stdio - .borrow_mut() - .take() - .expect("Extension only supports being used once."); - let t = &mut state.resource_table; - - let rid = t.add(StdFileResource::stdio( - match stdio.stdin { - StdioPipe::Inherit => StdFileResourceInner { - kind: StdFileResourceKind::Stdin, - file: STDIN_HANDLE.try_clone().unwrap(), + state = |state, options| { + if let Some(stdio) = options.stdio { + let t = &mut state.resource_table; + + let rid = t.add(StdFileResource::stdio( + match stdio.stdin { + StdioPipe::Inherit => StdFileResourceInner { + kind: StdFileResourceKind::Stdin, + file: STDIN_HANDLE.try_clone().unwrap(), + }, + StdioPipe::File(pipe) => StdFileResourceInner::file(pipe), }, - StdioPipe::File(pipe) => StdFileResourceInner::file(pipe), - }, - "stdin", - )); - assert_eq!(rid, 0, "stdin must have ResourceId 0"); - - let rid = t.add(StdFileResource::stdio( - match stdio.stdout { - StdioPipe::Inherit => StdFileResourceInner { - kind: StdFileResourceKind::Stdout, - file: STDOUT_HANDLE.try_clone().unwrap(), + "stdin", + )); + assert_eq!(rid, 0, "stdin must have ResourceId 0"); + + let rid = t.add(StdFileResource::stdio( + match stdio.stdout { + StdioPipe::Inherit => StdFileResourceInner { + kind: StdFileResourceKind::Stdout, + file: STDOUT_HANDLE.try_clone().unwrap(), + }, + StdioPipe::File(pipe) => StdFileResourceInner::file(pipe), }, - StdioPipe::File(pipe) => StdFileResourceInner::file(pipe), - }, - "stdout", - )); - assert_eq!(rid, 1, "stdout must have ResourceId 1"); - - let rid = t.add(StdFileResource::stdio( - match stdio.stderr { - StdioPipe::Inherit => StdFileResourceInner { - kind: StdFileResourceKind::Stderr, - file: STDERR_HANDLE.try_clone().unwrap(), + "stdout", + )); + assert_eq!(rid, 1, "stdout must have ResourceId 1"); + + let rid = t.add(StdFileResource::stdio( + match stdio.stderr { + StdioPipe::Inherit => StdFileResourceInner { + kind: StdFileResourceKind::Stderr, + file: STDERR_HANDLE.try_clone().unwrap(), + }, + StdioPipe::File(pipe) => StdFileResourceInner::file(pipe), }, - StdioPipe::File(pipe) => StdFileResourceInner::file(pipe), - }, - "stderr", - )); - assert_eq!(rid, 2, "stderr must have ResourceId 2"); + "stderr", + )); + assert_eq!(rid, 2, "stderr must have ResourceId 2"); + } }, ); diff --git a/ext/net/lib.rs b/ext/net/lib.rs index 76ed02706..00833b53c 100644 --- a/ext/net/lib.rs +++ b/ext/net/lib.rs @@ -105,18 +105,18 @@ deno_core::extension!(deno_net, #[cfg(unix)] ops_unix::op_net_send_unixpacket<P>, ], esm = [ "01_net.js", "02_tls.js" ], - config = { + options = { root_cert_store: Option<RootCertStore>, unstable: bool, unsafely_ignore_certificate_errors: Option<Vec<String>>, }, - state = |state, root_cert_store, unstable, unsafely_ignore_certificate_errors| { + state = |state, options| { state.put(DefaultTlsOptions { - root_cert_store, + root_cert_store: options.root_cert_store, }); - state.put(UnstableChecker { unstable }); + state.put(UnstableChecker { unstable: options.unstable }); state.put(UnsafelyIgnoreCertificateErrors( - unsafely_ignore_certificate_errors, + options.unsafely_ignore_certificate_errors, )); }, ); diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 06138cf4c..23a003bc8 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -370,11 +370,11 @@ deno_core::extension!(deno_node_loading, ops::op_require_break_on_next_statement, ], esm = ["01_node.js", "02_require.js", "module_es_shim.js"], - config = { + options = { maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>, }, - state = |state, maybe_npm_resolver| { - if let Some(npm_resolver) = maybe_npm_resolver.clone() { + state = |state, options| { + if let Some(npm_resolver) = options.maybe_npm_resolver { state.put(npm_resolver); } }, diff --git a/ext/web/lib.rs b/ext/web/lib.rs index f3a22d623..b0dc0d56d 100644 --- a/ext/web/lib.rs +++ b/ext/web/lib.rs @@ -109,13 +109,13 @@ deno_core::extension!(deno_web, "14_compression.js", "15_performance.js", ], - config = { + options = { blob_store: BlobStore, maybe_location: Option<Url>, }, - state = |state, blob_store, maybe_location| { - state.put(blob_store); - if let Some(location) = maybe_location { + state = |state, options| { + state.put(options.blob_store); + if let Some(location) = options.maybe_location { state.put(Location(location)); } state.put(StartTime::now()); diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index e480d7f4c..24a290b4b 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -506,17 +506,17 @@ deno_core::extension!(deno_websocket, op_ws_next_event, ], esm = [ "01_websocket.js", "02_websocketstream.js" ], - config = { + options = { user_agent: String, root_cert_store: Option<RootCertStore>, unsafely_ignore_certificate_errors: Option<Vec<String>> }, - state = |state, user_agent, root_cert_store, unsafely_ignore_certificate_errors| { - state.put::<WsUserAgent>(WsUserAgent(user_agent)); + state = |state, options| { + state.put::<WsUserAgent>(WsUserAgent(options.user_agent)); state.put(UnsafelyIgnoreCertificateErrors( - unsafely_ignore_certificate_errors, + options.unsafely_ignore_certificate_errors, )); - state.put::<WsRootStore>(WsRootStore(root_cert_store)); + state.put::<WsRootStore>(WsRootStore(options.root_cert_store)); }, ); diff --git a/ext/webstorage/lib.rs b/ext/webstorage/lib.rs index 6cdc7bbff..10be072e8 100644 --- a/ext/webstorage/lib.rs +++ b/ext/webstorage/lib.rs @@ -31,11 +31,11 @@ deno_core::extension!(deno_webstorage, op_webstorage_iterate_keys, ], esm = [ "01_webstorage.js" ], - config = { + options = { origin_storage_dir: Option<PathBuf> }, - state = |state, origin_storage_dir| { - if let Some(origin_storage_dir) = origin_storage_dir { + state = |state, options| { + if let Some(origin_storage_dir) = options.origin_storage_dir { state.put(OriginStorageDir(origin_storage_dir)); } }, diff --git a/runtime/build.rs b/runtime/build.rs index c1837de82..df5a0c299 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -17,9 +17,7 @@ mod startup_snapshot { use deno_core::snapshot_util::*; use deno_core::Extension; use deno_core::ExtensionFileSource; - use std::cell::RefCell; use std::path::Path; - use std::rc::Rc; fn transpile_ts_for_snapshotting( file_source: &ExtensionFileSource, @@ -292,9 +290,7 @@ mod startup_snapshot { deno_tls::deno_tls::init_ops_and_esm(), deno_napi::deno_napi::init_ops_and_esm::<Permissions>(), deno_http::deno_http::init_ops_and_esm(), - deno_io::deno_io::init_ops_and_esm(Rc::new(RefCell::new(Some( - Default::default(), - )))), + deno_io::deno_io::init_ops_and_esm(Default::default()), deno_fs::deno_fs::init_ops_and_esm::<Permissions>(false), deno_flash::deno_flash::init_ops_and_esm::<Permissions>(false), // No --unstable runtime::init_ops_and_esm(), diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index 87181654b..b34629395 100644 --- a/runtime/ops/os/mod.rs +++ b/runtime/ops/os/mod.rs @@ -42,11 +42,11 @@ deno_core::ops!( deno_core::extension!( deno_os, ops_fn = deno_ops, - config = { + options = { exit_code: ExitCode, }, - state = |state, exit_code| { - state.put::<ExitCode>(exit_code); + state = |state, options| { + state.put::<ExitCode>(options.exit_code); }, ); diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index 564d2279b..a77e888c8 100644 --- a/runtime/ops/runtime.rs +++ b/runtime/ops/runtime.rs @@ -9,9 +9,9 @@ use deno_core::OpState; deno_core::extension!( deno_runtime, ops = [op_main_module], - config = { main_module: ModuleSpecifier }, - state = |state, main_module| { - state.put::<ModuleSpecifier>(main_module); + options = { main_module: ModuleSpecifier }, + state = |state, options| { + state.put::<ModuleSpecifier>(options.main_module); } ); diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index de7e02e18..26c99efab 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -96,27 +96,27 @@ deno_core::extension!( op_host_recv_ctrl, op_host_recv_message, ], - config = { + options = { create_web_worker_cb: Arc<CreateWebWorkerCb>, preload_module_cb: Arc<WorkerEventCb>, pre_execute_module_cb: Arc<WorkerEventCb>, format_js_error_fn: Option<Arc<FormatJsErrorFn>>, }, - state = |state, create_web_worker_cb, preload_module_cb, pre_execute_module_cb, format_js_error_fn| { + state = |state, options| { state.put::<WorkersTable>(WorkersTable::default()); state.put::<WorkerId>(WorkerId::default()); let create_web_worker_cb_holder = - CreateWebWorkerCbHolder(create_web_worker_cb.clone()); + CreateWebWorkerCbHolder(options.create_web_worker_cb); state.put::<CreateWebWorkerCbHolder>(create_web_worker_cb_holder); let preload_module_cb_holder = - PreloadModuleCbHolder(preload_module_cb.clone()); + PreloadModuleCbHolder(options.preload_module_cb); state.put::<PreloadModuleCbHolder>(preload_module_cb_holder); let pre_execute_module_cb_holder = - PreExecuteModuleCbHolder(pre_execute_module_cb.clone()); + PreExecuteModuleCbHolder(options.pre_execute_module_cb); state.put::<PreExecuteModuleCbHolder>(pre_execute_module_cb_holder); let format_js_error_fn_holder = - FormatJsErrorFnHolder(format_js_error_fn.clone()); + FormatJsErrorFnHolder(options.format_js_error_fn); state.put::<FormatJsErrorFnHolder>(format_js_error_fn_holder); } ); diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index a78e7078b..1a8d02a1d 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -369,15 +369,15 @@ impl WebWorker { mut options: WebWorkerOptions, ) -> (Self, SendableWebWorkerHandle) { deno_core::extension!(deno_permissions_web_worker, - config = { + options = { permissions: PermissionsContainer, unstable: bool, enable_testing_features: bool, }, - state = |state, permissions, unstable, enable_testing_features| { - state.put::<PermissionsContainer>(permissions); - state.put(ops::UnstableChecker { unstable }); - state.put(ops::TestingFeaturesEnabled(enable_testing_features)); + state = |state, options| { + state.put::<PermissionsContainer>(options.permissions); + state.put(ops::UnstableChecker { unstable: options.unstable }); + state.put(ops::TestingFeaturesEnabled(options.enable_testing_features)); }, ); @@ -432,7 +432,7 @@ impl WebWorker { deno_tls::deno_tls::init_ops(), deno_napi::deno_napi::init_ops::<PermissionsContainer>(), deno_http::deno_http::init_ops(), - deno_io::deno_io::init_ops(Rc::new(RefCell::new(Some(options.stdio)))), + deno_io::deno_io::init_ops(Some(options.stdio)), deno_fs::deno_fs::init_ops::<PermissionsContainer>(unstable), deno_flash::deno_flash::init_ops::<PermissionsContainer>(unstable), deno_node::deno_node_loading::init_ops::<PermissionsContainer>( diff --git a/runtime/worker.rs b/runtime/worker.rs index 8a7f5711d..ed3478ff0 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -1,6 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -use std::cell::RefCell; use std::pin::Pin; use std::rc::Rc; use std::sync::atomic::AtomicI32; @@ -189,15 +188,15 @@ impl MainWorker { mut options: WorkerOptions, ) -> Self { deno_core::extension!(deno_permissions_worker, - config = { + options = { permissions: PermissionsContainer, unstable: bool, enable_testing_features: bool, }, - state = |state, permissions, unstable, enable_testing_features| { - state.put::<PermissionsContainer>(permissions); - state.put(ops::UnstableChecker { unstable }); - state.put(ops::TestingFeaturesEnabled(enable_testing_features)); + state = |state, options| { + state.put::<PermissionsContainer>(options.permissions); + state.put(ops::UnstableChecker { unstable: options.unstable }); + state.put(ops::TestingFeaturesEnabled(options.enable_testing_features)); }, ); @@ -255,7 +254,7 @@ impl MainWorker { deno_tls::deno_tls::init_ops(), deno_napi::deno_napi::init_ops::<PermissionsContainer>(), deno_http::deno_http::init_ops(), - deno_io::deno_io::init_ops(Rc::new(RefCell::new(Some(options.stdio)))), + deno_io::deno_io::init_ops(Some(options.stdio)), deno_fs::deno_fs::init_ops::<PermissionsContainer>(unstable), deno_flash::deno_flash::init_ops::<PermissionsContainer>(unstable), deno_node::deno_node_loading::init_ops::<PermissionsContainer>( |