diff --git a/cli/ops/plugins.rs b/cli/ops/plugins.rs index ecaa66b539..aa810e0ea9 100644 --- a/cli/ops/plugins.rs +++ b/cli/ops/plugins.rs @@ -7,9 +7,9 @@ use dlopen::symbor::Library; use std::collections::HashMap; use std::ffi::OsStr; use std::path::Path; -use std::sync::Arc; +use std::rc::Rc; -pub fn init(i: &mut Isolate, s: &State, r: Arc) { +pub fn init(i: &mut Isolate, s: &State, r: Rc) { let r_ = r; i.register_op( "open_plugin", @@ -51,7 +51,7 @@ struct OpenPluginArgs { } pub fn op_open_plugin( - registry: &Arc, + registry: &Rc, state: &State, args: Value, _zero_copy: Option, diff --git a/cli/worker.rs b/cli/worker.rs index c975a588a1..fa04d5a8f3 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -18,6 +18,7 @@ use std::future::Future; use std::ops::Deref; use std::ops::DerefMut; use std::pin::Pin; +use std::rc::Rc; use std::sync::Arc; use std::task::Context; use std::task::Poll; @@ -99,8 +100,8 @@ pub struct Worker { impl Worker { pub fn new(name: String, startup_data: StartupData, state: State) -> Self { - let mut isolate = - deno_core::EsIsolate::new(Box::new(state.clone()), startup_data, false); + let loader = Rc::new(state.clone()); + let mut isolate = deno_core::EsIsolate::new(loader, startup_data, false); let global_state_ = state.borrow().global_state.clone(); isolate.set_js_error_create(move |v8_exception| { diff --git a/core/es_isolate.rs b/core/es_isolate.rs index aeb6e318a0..197c548d74 100644 --- a/core/es_isolate.rs +++ b/core/es_isolate.rs @@ -21,7 +21,7 @@ use std::collections::HashMap; use std::ops::{Deref, DerefMut}; use std::option::Option; use std::pin::Pin; -use std::sync::Arc; +use std::rc::Rc; use std::task::Context; use std::task::Poll; @@ -56,7 +56,7 @@ pub struct SourceCodeInfo { /// loading of modules can be customized by the implementor. pub struct EsIsolate { core_isolate: Box, - loader: Arc>, + loader: Rc, pub modules: Modules, pub(crate) next_dyn_import_id: DynImportId, pub(crate) dyn_import_map: @@ -101,7 +101,7 @@ impl Drop for EsIsolate { impl EsIsolate { pub fn new( - loader: Box, + loader: Rc, startup_data: StartupData, will_snapshot: bool, ) -> Box { @@ -118,7 +118,7 @@ impl EsIsolate { let es_isolate = Self { modules: Modules::new(), - loader: Arc::new(loader), + loader, core_isolate, next_dyn_import_id: 0, dyn_import_map: HashMap::new(), @@ -606,6 +606,7 @@ pub mod tests { use crate::ops::*; use std::io; use std::sync::atomic::{AtomicUsize, Ordering}; + use std::sync::Arc; #[test] fn test_mods() { @@ -638,7 +639,7 @@ pub mod tests { } } - let loader = Box::new(ModsLoader::default()); + let loader = Rc::new(ModsLoader::default()); let resolve_count = loader.count.clone(); let dispatch_count = Arc::new(AtomicUsize::new(0)); let dispatch_count_ = dispatch_count.clone(); @@ -740,7 +741,7 @@ pub mod tests { // Test an erroneous dynamic import where the specified module isn't found. run_in_task(|cx| { - let loader = Box::new(DynImportErrLoader::default()); + let loader = Rc::new(DynImportErrLoader::default()); let count = loader.count.clone(); let mut isolate = EsIsolate::new(loader, StartupData::None, false); @@ -894,7 +895,7 @@ pub mod tests { } run_in_task(|cx| { - let loader = Box::new(DynImportOkLoader::default()); + let loader = Rc::new(DynImportOkLoader::default()); let resolve_count = loader.resolve_count.clone(); let load_count = loader.load_count.clone(); let mut isolate = EsIsolate::new(loader, StartupData::None, false); diff --git a/core/isolate.rs b/core/isolate.rs index 3892d6d75b..d67ed93312 100644 --- a/core/isolate.rs +++ b/core/isolate.rs @@ -29,6 +29,7 @@ use std::fmt; use std::ops::{Deref, DerefMut}; use std::option::Option; use std::pin::Pin; +use std::rc::Rc; use std::sync::{Arc, Mutex, Once}; use std::task::Context; use std::task::Poll; @@ -175,7 +176,7 @@ pub struct Isolate { pending_unref_ops: FuturesUnordered, have_unpolled_ops: bool, startup_script: Option, - pub op_registry: Arc, + pub op_registry: Rc, waker: AtomicWaker, error_handler: Option>, } @@ -335,7 +336,7 @@ impl Isolate { pending_unref_ops: FuturesUnordered::new(), have_unpolled_ops: false, startup_script, - op_registry: Arc::new(OpRegistry::new()), + op_registry: Rc::new(OpRegistry::new()), waker: AtomicWaker::new(), error_handler: None, }; diff --git a/core/modules.rs b/core/modules.rs index ee91c183a7..29f6067cd0 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -16,7 +16,7 @@ use std::collections::HashSet; use std::fmt; use std::future::Future; use std::pin::Pin; -use std::sync::Arc; +use std::rc::Rc; use std::task::Context; use std::task::Poll; @@ -74,7 +74,7 @@ pub struct RecursiveModuleLoad { // Kind::Main pub dyn_import_id: Option, pub state: LoadState, - pub loader: Arc>, + pub loader: Rc, pub pending: FuturesUnordered>>, pub is_pending: HashSet, } @@ -84,7 +84,7 @@ impl RecursiveModuleLoad { pub fn main( specifier: &str, code: Option, - loader: Arc>, + loader: Rc, ) -> Self { let kind = Kind::Main; let state = LoadState::ResolveMain(specifier.to_owned(), code); @@ -95,7 +95,7 @@ impl RecursiveModuleLoad { id: DynImportId, specifier: &str, referrer: &str, - loader: Arc>, + loader: Rc, ) -> Self { let kind = Kind::DynamicImport; let state = @@ -110,7 +110,7 @@ impl RecursiveModuleLoad { fn new( kind: Kind, state: LoadState, - loader: Arc>, + loader: Rc, dyn_import_id: Option, ) -> Self { Self { @@ -478,6 +478,7 @@ mod tests { use std::error::Error; use std::fmt; use std::future::Future; + use std::sync::Arc; use std::sync::Mutex; struct MockLoader { @@ -651,8 +652,7 @@ mod tests { fn test_recursive_load() { let loader = MockLoader::new(); let loads = loader.loads.clone(); - let mut isolate = - EsIsolate::new(Box::new(loader), StartupData::None, false); + let mut isolate = EsIsolate::new(Rc::new(loader), StartupData::None, false); let a_id_fut = isolate.load_module("/a.js", None); let a_id = futures::executor::block_on(a_id_fut).expect("Failed to load"); @@ -711,8 +711,7 @@ mod tests { fn test_circular_load() { let loader = MockLoader::new(); let loads = loader.loads.clone(); - let mut isolate = - EsIsolate::new(Box::new(loader), StartupData::None, false); + let mut isolate = EsIsolate::new(Rc::new(loader), StartupData::None, false); let fut = async move { let result = isolate.load_module("/circular1.js", None).await; @@ -782,8 +781,7 @@ mod tests { fn test_redirect_load() { let loader = MockLoader::new(); let loads = loader.loads.clone(); - let mut isolate = - EsIsolate::new(Box::new(loader), StartupData::None, false); + let mut isolate = EsIsolate::new(Rc::new(loader), StartupData::None, false); let fut = async move { let result = isolate.load_module("/redirect1.js", None).await; @@ -845,7 +843,7 @@ mod tests { let loader = MockLoader::new(); let loads = loader.loads.clone(); let mut isolate = - EsIsolate::new(Box::new(loader), StartupData::None, false); + EsIsolate::new(Rc::new(loader), StartupData::None, false); let mut recursive_load = isolate.load_module("/main.js", None).boxed_local(); @@ -891,7 +889,7 @@ mod tests { run_in_task(|mut cx| { let loader = MockLoader::new(); let mut isolate = - EsIsolate::new(Box::new(loader), StartupData::None, false); + EsIsolate::new(Rc::new(loader), StartupData::None, false); let mut load_fut = isolate.load_module("/bad_import.js", None).boxed_local(); let result = load_fut.poll_unpin(&mut cx); @@ -919,8 +917,7 @@ mod tests { fn recursive_load_main_with_code() { let loader = MockLoader::new(); let loads = loader.loads.clone(); - let mut isolate = - EsIsolate::new(Box::new(loader), StartupData::None, false); + let mut isolate = EsIsolate::new(Rc::new(loader), StartupData::None, false); // In default resolution code should be empty. // Instead we explicitly pass in our own code. // The behavior should be very similar to /a.js. diff --git a/core/ops.rs b/core/ops.rs index 266a36648c..98407f1570 100644 --- a/core/ops.rs +++ b/core/ops.rs @@ -3,7 +3,7 @@ use crate::ZeroCopyBuf; use futures::Future; use std::collections::HashMap; use std::pin::Pin; -use std::sync::Arc; +use std::rc::Rc; use std::sync::RwLock; pub type OpId = u32; @@ -34,7 +34,7 @@ pub type OpDispatcher = dyn Fn(&[u8], Option) -> CoreOp + 'static; #[derive(Default)] pub struct OpRegistry { - dispatchers: RwLock>>>, + dispatchers: RwLock>>, name_to_id: RwLock>, } @@ -63,7 +63,7 @@ impl OpRegistry { format!("Op already registered: {}", name) ); - lock.push(Arc::new(Box::new(op))); + lock.push(Rc::new(op)); drop(name_lock); drop(lock); op_id @@ -90,7 +90,7 @@ impl OpRegistry { } let lock = self.dispatchers.read().unwrap(); if let Some(op) = lock.get(op_id as usize) { - let op_ = Arc::clone(&op); + let op_ = Rc::clone(&op); // This should allow for changes to the dispatcher list during a call. drop(lock); Some(op_(control, zero_copy_buf))