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

refactor: replace Arc<Box<..>> with Rc<..> (#3996)

This commit is contained in:
Bartek Iwańczuk 2020-02-15 01:18:36 +01:00 committed by GitHub
parent 87c329c45a
commit a0f015b1a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 33 deletions

View file

@ -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<deno_core::OpRegistry>) {
pub fn init(i: &mut Isolate, s: &State, r: Rc<deno_core::OpRegistry>) {
let r_ = r;
i.register_op(
"open_plugin",
@ -51,7 +51,7 @@ struct OpenPluginArgs {
}
pub fn op_open_plugin(
registry: &Arc<deno_core::OpRegistry>,
registry: &Rc<deno_core::OpRegistry>,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,

View file

@ -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| {

View file

@ -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<Isolate>,
loader: Arc<Box<dyn Loader + Unpin>>,
loader: Rc<dyn Loader + Unpin>,
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<dyn Loader + Unpin>,
loader: Rc<dyn Loader + Unpin>,
startup_data: StartupData,
will_snapshot: bool,
) -> Box<Self> {
@ -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);

View file

@ -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<PendingOpFuture>,
have_unpolled_ops: bool,
startup_script: Option<OwnedScript>,
pub op_registry: Arc<OpRegistry>,
pub op_registry: Rc<OpRegistry>,
waker: AtomicWaker,
error_handler: Option<Box<IsolateErrorHandleFn>>,
}
@ -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,
};

View file

@ -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<DynImportId>,
pub state: LoadState,
pub loader: Arc<Box<dyn Loader + Unpin>>,
pub loader: Rc<dyn Loader + Unpin>,
pub pending: FuturesUnordered<Pin<Box<SourceCodeInfoFuture>>>,
pub is_pending: HashSet<ModuleSpecifier>,
}
@ -84,7 +84,7 @@ impl RecursiveModuleLoad {
pub fn main(
specifier: &str,
code: Option<String>,
loader: Arc<Box<dyn Loader + Unpin>>,
loader: Rc<dyn Loader + Unpin>,
) -> 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<Box<dyn Loader + Unpin>>,
loader: Rc<dyn Loader + Unpin>,
) -> Self {
let kind = Kind::DynamicImport;
let state =
@ -110,7 +110,7 @@ impl RecursiveModuleLoad {
fn new(
kind: Kind,
state: LoadState,
loader: Arc<Box<dyn Loader + Unpin>>,
loader: Rc<dyn Loader + Unpin>,
dyn_import_id: Option<DynImportId>,
) -> 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.

View file

@ -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<ZeroCopyBuf>) -> CoreOp + 'static;
#[derive(Default)]
pub struct OpRegistry {
dispatchers: RwLock<Vec<Arc<Box<OpDispatcher>>>>,
dispatchers: RwLock<Vec<Rc<OpDispatcher>>>,
name_to_id: RwLock<HashMap<String, OpId>>,
}
@ -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))