diff --git a/cli/build.rs b/cli/build.rs index e4df856f79..9068723d43 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::(), 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::(false), deno_flash::deno_flash::init_ops::(false), // No --unstable deno_node::deno_node_loading::init_ops::(None), // No --unstable. diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 910d136913..91eb6e24b5 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 }, - 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 7bd3f988a2..6fa9edee88 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, 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 562aa86492..c12409514d 100644 --- a/cli/ops/mod.rs +++ b/cli/ops/mod.rs @@ -15,11 +15,11 @@ pub fn cli_exts(ps: ProcState) -> Vec { 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 f32e961479..0849f1c7a0 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 387fd3aa16..45589780ff 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 { deno_core::extension!(deno_cli_tsc, ops_fn = deno_ops, - config = { - request: Rc, + options = { + request: Request, root_map: HashMap, remapped_specifiers: HashMap, }, - 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 { 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 71b9cdb4f5..53ce57be8b 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>, &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(self, state: &mut $crate::OpState, f: F) { - f(state, $( $( self. $config_id ),* )? ) + fn call_callback(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(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(&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 1ea9c01684..0531e861c3 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, }, - 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 3df11566f3..5b38e70f85 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, ], 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 eaf56c8b70..b5a29e9050 100644 --- a/ext/cache/lib.rs +++ b/ext/cache/lib.rs @@ -32,11 +32,11 @@ deno_core::extension!(deno_cache, op_cache_delete, ], esm = [ "01_cache.js" ], - config = { + options = { maybe_create_cache: Option>, }, - 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 48c5acf4a2..6056b02a45 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, }, - 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 4cd5d68c8f..9ed73161dd 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.clone()); + state.put::(options.options.clone()); state.put::({ 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 1fd01c9d25..c11f08dd8e 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::(); diff --git a/ext/flash/lib.rs b/ext/flash/lib.rs index 6f11e14afa..b6a586d1fe 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 48b0e34957..386d143d21 100644 --- a/ext/fs/lib.rs +++ b/ext/fs/lib.rs @@ -180,11 +180,11 @@ deno_core::extension!(deno_fs, op_readfile_text_async

, ], 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 bfbb1d94f0..5bb526d4aa 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>>, + options = { + stdio: Option, }, 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; + 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(), + 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"); + "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(), + 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"); + "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(), + 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 76ed02706a..00833b53c4 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

, ], esm = [ "01_net.js", "02_tls.js" ], - config = { + options = { root_cert_store: Option, unstable: bool, unsafely_ignore_certificate_errors: Option>, }, - 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 06138cf4cb..23a003bc83 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>, }, - 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 f3a22d6236..b0dc0d56d5 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, }, - 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 e480d7f4c6..24a290b4be 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, unsafely_ignore_certificate_errors: Option> }, - state = |state, user_agent, root_cert_store, unsafely_ignore_certificate_errors| { - state.put::(WsUserAgent(user_agent)); + state = |state, options| { + state.put::(WsUserAgent(options.user_agent)); state.put(UnsafelyIgnoreCertificateErrors( - unsafely_ignore_certificate_errors, + options.unsafely_ignore_certificate_errors, )); - state.put::(WsRootStore(root_cert_store)); + state.put::(WsRootStore(options.root_cert_store)); }, ); diff --git a/ext/webstorage/lib.rs b/ext/webstorage/lib.rs index 6cdc7bbff9..10be072e81 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 }, - 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 c1837de827..df5a0c2993 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::(), 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::(false), deno_flash::deno_flash::init_ops_and_esm::(false), // No --unstable runtime::init_ops_and_esm(), diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index 87181654b3..b346293954 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::(exit_code); + state = |state, options| { + state.put::(options.exit_code); }, ); diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index 564d2279bf..a77e888c82 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::(main_module); + options = { main_module: ModuleSpecifier }, + state = |state, options| { + state.put::(options.main_module); } ); diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index de7e02e186..26c99efab0 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, preload_module_cb: Arc, pre_execute_module_cb: Arc, format_js_error_fn: Option>, }, - state = |state, create_web_worker_cb, preload_module_cb, pre_execute_module_cb, format_js_error_fn| { + state = |state, options| { state.put::(WorkersTable::default()); state.put::(WorkerId::default()); let create_web_worker_cb_holder = - CreateWebWorkerCbHolder(create_web_worker_cb.clone()); + CreateWebWorkerCbHolder(options.create_web_worker_cb); state.put::(create_web_worker_cb_holder); let preload_module_cb_holder = - PreloadModuleCbHolder(preload_module_cb.clone()); + PreloadModuleCbHolder(options.preload_module_cb); state.put::(preload_module_cb_holder); let pre_execute_module_cb_holder = - PreExecuteModuleCbHolder(pre_execute_module_cb.clone()); + PreExecuteModuleCbHolder(options.pre_execute_module_cb); state.put::(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::(format_js_error_fn_holder); } ); diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index a78e7078b3..1a8d02a1dc 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::(permissions); - state.put(ops::UnstableChecker { unstable }); - state.put(ops::TestingFeaturesEnabled(enable_testing_features)); + state = |state, options| { + state.put::(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::(), 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::(unstable), deno_flash::deno_flash::init_ops::(unstable), deno_node::deno_node_loading::init_ops::( diff --git a/runtime/worker.rs b/runtime/worker.rs index 8a7f5711d1..ed3478ff01 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::(permissions); - state.put(ops::UnstableChecker { unstable }); - state.put(ops::TestingFeaturesEnabled(enable_testing_features)); + state = |state, options| { + state.put::(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::(), 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::(unstable), deno_flash::deno_flash::init_ops::(unstable), deno_node::deno_node_loading::init_ops::(