From d8711155ca20fb2907beed304557d0815ac56452 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 23 Apr 2020 05:51:07 -0400 Subject: [PATCH] Rename deno_core::Isolate to deno_core::CoreIsolate (#4851) --- cli/build.rs | 10 ++-- cli/inspector.rs | 4 +- cli/js.rs | 4 +- cli/ops/compiler.rs | 6 ++- cli/ops/dispatch_json.rs | 16 +++---- cli/ops/dispatch_minimal.rs | 7 +-- cli/ops/errors.rs | 5 +- cli/ops/fetch.rs | 7 +-- cli/ops/fs.rs | 8 ++-- cli/ops/fs_events.rs | 10 ++-- cli/ops/io.rs | 10 ++-- cli/ops/net.rs | 22 +++++---- cli/ops/net_unix.rs | 9 ++-- cli/ops/os.rs | 5 +- cli/ops/permissions.rs | 5 +- cli/ops/plugins.rs | 8 ++-- cli/ops/process.rs | 10 ++-- cli/ops/random.rs | 5 +- cli/ops/repl.rs | 9 ++-- cli/ops/resources.rs | 9 ++-- cli/ops/runtime.rs | 5 +- cli/ops/runtime_compiler.rs | 5 +- cli/ops/signal.rs | 17 +++---- cli/ops/timers.rs | 5 +- cli/ops/tls.rs | 13 +++--- cli/ops/tty.rs | 9 ++-- cli/ops/web_worker.rs | 21 +++------ cli/ops/worker_host.rs | 7 ++- cli/state.rs | 30 ++++++------ core/bindings.rs | 92 ++++++++++++++++++------------------- core/es_isolate.rs | 18 ++++---- core/examples/http_bench.rs | 12 +++-- core/isolate.rs | 38 +++++++-------- core/ops.rs | 10 ++-- deno_typescript/lib.rs | 22 ++++----- test_plugin/src/lib.rs | 7 +-- 36 files changed, 253 insertions(+), 227 deletions(-) diff --git a/cli/build.rs b/cli/build.rs index 98fc8dbc08..f49cde386c 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -1,6 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use deno_core::include_crate_modules; -use deno_core::Isolate; +use deno_core::CoreIsolate; use deno_core::StartupData; use std::collections::HashMap; use std::env; @@ -48,10 +48,10 @@ fn main() { .expect("Bundle compilation failed"); assert!(bundle_path.exists()); - let runtime_isolate = &mut Isolate::new(StartupData::None, true); + let mut runtime_isolate = CoreIsolate::new(StartupData::None, true); deno_typescript::mksnapshot_bundle( - runtime_isolate, + &mut runtime_isolate, &snapshot_path, &bundle_path, &main_module_name, @@ -71,7 +71,7 @@ fn main() { .expect("Bundle compilation failed"); assert!(bundle_path.exists()); - let runtime_isolate = &mut Isolate::new(StartupData::None, true); + let mut runtime_isolate = CoreIsolate::new(StartupData::None, true); let mut custom_libs: HashMap = HashMap::new(); custom_libs.insert( @@ -96,7 +96,7 @@ fn main() { ); deno_typescript::mksnapshot_bundle_ts( - runtime_isolate, + &mut runtime_isolate, &snapshot_path, &bundle_path, &main_module_name, diff --git a/cli/inspector.rs b/cli/inspector.rs index 6db080a342..a637e980ff 100644 --- a/cli/inspector.rs +++ b/cli/inspector.rs @@ -308,11 +308,11 @@ impl DenoInspector { const CONTEXT_GROUP_ID: i32 = 1; pub fn new( - isolate: &mut deno_core::Isolate, + isolate: &mut deno_core::CoreIsolate, host: SocketAddr, wait_for_debugger: bool, ) -> Box { - let deno_core::Isolate { + let deno_core::CoreIsolate { v8_isolate, global_context, .. diff --git a/cli/js.rs b/cli/js.rs index 8a5821998c..08392aa92a 100644 --- a/cli/js.rs +++ b/cli/js.rs @@ -23,7 +23,7 @@ pub static WINDOW_LIB: &str = include_str!("js/lib.deno.window.d.ts"); #[test] fn cli_snapshot() { - let mut isolate = deno_core::Isolate::new( + let mut isolate = deno_core::CoreIsolate::new( deno_core::StartupData::Snapshot(deno_core::Snapshot::Static(CLI_SNAPSHOT)), false, ); @@ -40,7 +40,7 @@ fn cli_snapshot() { #[test] fn compiler_snapshot() { - let mut isolate = deno_core::Isolate::new( + let mut isolate = deno_core::CoreIsolate::new( deno_core::StartupData::Snapshot(deno_core::Snapshot::Static( COMPILER_SNAPSHOT, )), diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs index f6f1dc34e2..32e6655f97 100644 --- a/cli/ops/compiler.rs +++ b/cli/ops/compiler.rs @@ -6,11 +6,13 @@ use crate::futures::future::try_join_all; use crate::msg; use crate::op_error::OpError; use crate::state::State; +use deno_core::CoreIsolate; use deno_core::ModuleLoader; -use deno_core::*; +use deno_core::ModuleSpecifier; +use deno_core::ZeroCopyBuf; use futures::future::FutureExt; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_cache", s.stateful_json_op(op_cache)); i.register_op("op_resolve_modules", s.stateful_json_op(op_resolve_modules)); i.register_op( diff --git a/cli/ops/dispatch_json.rs b/cli/ops/dispatch_json.rs index bfffd6d098..6125ea39bb 100644 --- a/cli/ops/dispatch_json.rs +++ b/cli/ops/dispatch_json.rs @@ -1,6 +1,9 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use crate::op_error::OpError; -use deno_core::*; +use deno_core::Buf; +use deno_core::CoreIsolate; +use deno_core::Op; +use deno_core::ZeroCopyBuf; use futures::future::FutureExt; pub use serde_derive::Deserialize; use serde_json::json; @@ -43,15 +46,12 @@ struct AsyncArgs { pub fn json_op( d: D, -) -> impl Fn(&mut deno_core::Isolate, &[u8], Option) -> Op +) -> impl Fn(&mut CoreIsolate, &[u8], Option) -> Op where - D: Fn( - &mut deno_core::Isolate, - Value, - Option, - ) -> Result, + D: + Fn(&mut CoreIsolate, Value, Option) -> Result, { - move |isolate: &mut deno_core::Isolate, + move |isolate: &mut CoreIsolate, control: &[u8], zero_copy: Option| { let async_args: AsyncArgs = match serde_json::from_slice(control) { diff --git a/cli/ops/dispatch_minimal.rs b/cli/ops/dispatch_minimal.rs index 4865714252..ac98ea5896 100644 --- a/cli/ops/dispatch_minimal.rs +++ b/cli/ops/dispatch_minimal.rs @@ -7,6 +7,7 @@ use crate::op_error::OpError; use byteorder::{LittleEndian, WriteBytesExt}; use deno_core::Buf; +use deno_core::CoreIsolate; use deno_core::Op; use deno_core::ZeroCopyBuf; use futures::future::FutureExt; @@ -115,11 +116,11 @@ fn test_parse_min_record() { pub fn minimal_op( d: D, -) -> impl Fn(&mut deno_core::Isolate, &[u8], Option) -> Op +) -> impl Fn(&mut CoreIsolate, &[u8], Option) -> Op where - D: Fn(&mut deno_core::Isolate, bool, i32, Option) -> MinimalOp, + D: Fn(&mut CoreIsolate, bool, i32, Option) -> MinimalOp, { - move |isolate: &mut deno_core::Isolate, + move |isolate: &mut CoreIsolate, control: &[u8], zero_copy: Option| { let mut record = match parse_min_record(control) { diff --git a/cli/ops/errors.rs b/cli/ops/errors.rs index 2eab3a9534..3e48fd0076 100644 --- a/cli/ops/errors.rs +++ b/cli/ops/errors.rs @@ -5,10 +5,11 @@ use crate::op_error::OpError; use crate::source_maps::get_orig_position; use crate::source_maps::CachedMaps; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; use std::collections::HashMap; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op( "op_apply_source_map", s.stateful_json_op(op_apply_source_map), diff --git a/cli/ops/fetch.rs b/cli/ops/fetch.rs index 4a7b45430f..596c9a2fd2 100644 --- a/cli/ops/fetch.rs +++ b/cli/ops/fetch.rs @@ -4,14 +4,15 @@ use super::io::{StreamResource, StreamResourceHolder}; use crate::http_util::{create_http_client, HttpBody}; use crate::op_error::OpError; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; use futures::future::FutureExt; use http::header::HeaderName; use http::header::HeaderValue; use http::Method; use std::convert::From; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_fetch", s.stateful_json_op2(op_fetch)); } @@ -23,7 +24,7 @@ struct FetchArgs { } pub fn op_fetch( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, data: Option, diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs index e1a431b00c..a7f7fbf087 100644 --- a/cli/ops/fs.rs +++ b/cli/ops/fs.rs @@ -7,7 +7,7 @@ use crate::fs::resolve_from_cwd; use crate::op_error::OpError; use crate::ops::dispatch_json::JsonResult; use crate::state::State; -use deno_core::Isolate; +use deno_core::CoreIsolate; use deno_core::ZeroCopyBuf; use futures::future::FutureExt; use std::convert::From; @@ -17,7 +17,7 @@ use std::time::UNIX_EPOCH; use rand::{thread_rng, Rng}; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_open", s.stateful_json_op2(op_open)); i.register_op("op_seek", s.stateful_json_op2(op_seek)); i.register_op("op_umask", s.stateful_json_op(op_umask)); @@ -68,7 +68,7 @@ struct OpenOptions { } fn op_open( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, _zero_copy: Option, @@ -205,7 +205,7 @@ struct SeekArgs { } fn op_seek( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, _zero_copy: Option, diff --git a/cli/ops/fs_events.rs b/cli/ops/fs_events.rs index 0a6fee8eae..56ed556f4f 100644 --- a/cli/ops/fs_events.rs +++ b/cli/ops/fs_events.rs @@ -2,7 +2,9 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::op_error::OpError; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ErrBox; +use deno_core::ZeroCopyBuf; use futures::future::poll_fn; use futures::future::FutureExt; use notify::event::Event as NotifyEvent; @@ -16,7 +18,7 @@ use std::convert::From; use std::path::PathBuf; use tokio::sync::mpsc; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_fs_events_open", s.stateful_json_op2(op_fs_events_open)); i.register_op("op_fs_events_poll", s.stateful_json_op2(op_fs_events_poll)); } @@ -60,7 +62,7 @@ impl From for FsEvent { } pub fn op_fs_events_open( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, _zero_copy: Option, @@ -98,7 +100,7 @@ pub fn op_fs_events_open( } pub fn op_fs_events_poll( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, _zero_copy: Option, diff --git a/cli/ops/io.rs b/cli/ops/io.rs index 45fd6ff959..705083e15c 100644 --- a/cli/ops/io.rs +++ b/cli/ops/io.rs @@ -2,7 +2,9 @@ use super::dispatch_minimal::MinimalOp; use crate::http_util::HttpBody; use crate::op_error::OpError; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ResourceTable; +use deno_core::ZeroCopyBuf; use futures::future::poll_fn; use futures::future::FutureExt; use futures::ready; @@ -58,7 +60,7 @@ lazy_static! { }; } -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_read", s.stateful_minimal_op2(op_read)); i.register_op("op_write", s.stateful_minimal_op2(op_write)); } @@ -204,7 +206,7 @@ impl DenoAsyncRead for StreamResource { } pub fn op_read( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, is_sync: bool, rid: i32, @@ -328,7 +330,7 @@ impl DenoAsyncWrite for StreamResource { } pub fn op_write( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, is_sync: bool, rid: i32, diff --git a/cli/ops/net.rs b/cli/ops/net.rs index 8a6afe756f..a9b1e0051b 100644 --- a/cli/ops/net.rs +++ b/cli/ops/net.rs @@ -4,7 +4,9 @@ use super::io::{StreamResource, StreamResourceHolder}; use crate::op_error::OpError; use crate::resolve_addr::resolve_addr; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ResourceTable; +use deno_core::ZeroCopyBuf; use futures::future::poll_fn; use futures::future::FutureExt; use std::convert::From; @@ -19,7 +21,7 @@ use tokio::net::UdpSocket; #[cfg(unix)] use super::net_unix; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_accept", s.stateful_json_op2(op_accept)); i.register_op("op_connect", s.stateful_json_op2(op_connect)); i.register_op("op_shutdown", s.stateful_json_op2(op_shutdown)); @@ -35,7 +37,7 @@ struct AcceptArgs { } fn accept_tcp( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, args: AcceptArgs, _zero_copy: Option, ) -> Result { @@ -95,7 +97,7 @@ fn accept_tcp( } fn op_accept( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, zero_copy: Option, @@ -119,7 +121,7 @@ struct ReceiveArgs { } fn receive_udp( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: ReceiveArgs, zero_copy: Option, @@ -156,7 +158,7 @@ fn receive_udp( } fn op_receive( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, zero_copy: Option, @@ -185,7 +187,7 @@ struct SendArgs { } fn op_send( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, zero_copy: Option, @@ -254,7 +256,7 @@ struct ConnectArgs { } fn op_connect( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, _zero_copy: Option, @@ -339,7 +341,7 @@ struct ShutdownArgs { } fn op_shutdown( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, _zero_copy: Option, @@ -479,7 +481,7 @@ fn listen_udp( } fn op_listen( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, _zero_copy: Option, diff --git a/cli/ops/net_unix.rs b/cli/ops/net_unix.rs index e3052e4105..28b895b2c0 100644 --- a/cli/ops/net_unix.rs +++ b/cli/ops/net_unix.rs @@ -1,9 +1,10 @@ use super::dispatch_json::{Deserialize, JsonOp}; use super::io::{StreamResource, StreamResourceHolder}; use crate::op_error::OpError; +use deno_core::CoreIsolate; +use deno_core::ResourceTable; +use deno_core::ZeroCopyBuf; use futures::future::FutureExt; - -use deno_core::*; use std::fs::remove_file; use std::os::unix; pub use std::path::Path; @@ -26,7 +27,7 @@ pub struct UnixListenArgs { } pub fn accept_unix( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, rid: u32, _zero_copy: Option, ) -> Result { @@ -77,7 +78,7 @@ pub fn accept_unix( } pub fn receive_unix_packet( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, rid: u32, zero_copy: Option, ) -> Result { diff --git a/cli/ops/os.rs b/cli/ops/os.rs index a58ed788be..eccb45f501 100644 --- a/cli/ops/os.rs +++ b/cli/ops/os.rs @@ -2,13 +2,14 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::op_error::OpError; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; use std::collections::HashMap; use std::env; use std::io::{Error, ErrorKind}; use url::Url; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_exit", s.stateful_json_op(op_exit)); i.register_op("op_env", s.stateful_json_op(op_env)); i.register_op("op_exec_path", s.stateful_json_op(op_exec_path)); diff --git a/cli/ops/permissions.rs b/cli/ops/permissions.rs index 55358b760c..3ccff40656 100644 --- a/cli/ops/permissions.rs +++ b/cli/ops/permissions.rs @@ -3,10 +3,11 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::fs as deno_fs; use crate::op_error::OpError; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; use std::path::Path; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op( "op_query_permission", s.stateful_json_op(op_query_permission), diff --git a/cli/ops/plugins.rs b/cli/ops/plugins.rs index f8c1b5bd23..17f366d39f 100644 --- a/cli/ops/plugins.rs +++ b/cli/ops/plugins.rs @@ -3,15 +3,15 @@ use crate::fs as deno_fs; use crate::op_error::OpError; use crate::ops::json_op; use crate::state::State; -use deno_core::Isolate; +use deno_core::CoreIsolate; use deno_core::ZeroCopyBuf; use dlopen::symbor::Library; use std::ffi::OsStr; use std::path::Path; -pub type PluginInitFn = fn(isolate: &mut deno_core::Isolate); +pub type PluginInitFn = fn(isolate: &mut CoreIsolate); -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op( "op_open_plugin", s.core_op(json_op(s.stateful_op2(op_open_plugin))), @@ -34,7 +34,7 @@ struct OpenPluginArgs { } pub fn op_open_plugin( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, _zero_copy: Option, diff --git a/cli/ops/process.rs b/cli/ops/process.rs index 72603f7a5c..0384f5b39d 100644 --- a/cli/ops/process.rs +++ b/cli/ops/process.rs @@ -4,7 +4,9 @@ use super::io::{std_file_resource, StreamResource, StreamResourceHolder}; use crate::op_error::OpError; use crate::signal::kill; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ResourceTable; +use deno_core::ZeroCopyBuf; use futures::future::poll_fn; use futures::future::FutureExt; use futures::TryFutureExt; @@ -14,7 +16,7 @@ use tokio::process::Command; #[cfg(unix)] use std::os::unix::process::ExitStatusExt; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_run", s.stateful_json_op2(op_run)); i.register_op("op_run_status", s.stateful_json_op2(op_run_status)); i.register_op("op_kill", s.stateful_json_op(op_kill)); @@ -58,7 +60,7 @@ struct ChildResource { } fn op_run( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, _zero_copy: Option, @@ -172,7 +174,7 @@ struct RunStatusArgs { } fn op_run_status( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, _zero_copy: Option, diff --git a/cli/ops/random.rs b/cli/ops/random.rs index 4430aa9c5d..874887cdb4 100644 --- a/cli/ops/random.rs +++ b/cli/ops/random.rs @@ -2,11 +2,12 @@ use super::dispatch_json::{JsonOp, Value}; use crate::op_error::OpError; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; use rand::thread_rng; use rand::Rng; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op( "op_get_random_values", s.stateful_json_op(op_get_random_values), diff --git a/cli/ops/repl.rs b/cli/ops/repl.rs index 5ad79c22ae..7dc0d0263d 100644 --- a/cli/ops/repl.rs +++ b/cli/ops/repl.rs @@ -4,11 +4,12 @@ use crate::op_error::OpError; use crate::repl; use crate::repl::Repl; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; use std::sync::Arc; use std::sync::Mutex; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_repl_start", s.stateful_json_op2(op_repl_start)); i.register_op("op_repl_readline", s.stateful_json_op2(op_repl_readline)); } @@ -22,7 +23,7 @@ struct ReplStartArgs { } fn op_repl_start( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, _zero_copy: Option, @@ -45,7 +46,7 @@ struct ReplReadlineArgs { } fn op_repl_readline( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, _zero_copy: Option, diff --git a/cli/ops/resources.rs b/cli/ops/resources.rs index f284306114..1fdee18501 100644 --- a/cli/ops/resources.rs +++ b/cli/ops/resources.rs @@ -2,15 +2,16 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::op_error::OpError; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_resources", s.stateful_json_op2(op_resources)); i.register_op("op_close", s.stateful_json_op2(op_close)); } fn op_resources( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, _args: Value, _zero_copy: Option, @@ -21,7 +22,7 @@ fn op_resources( /// op_close removes a resource from the resource table. fn op_close( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, _zero_copy: Option, diff --git a/cli/ops/runtime.rs b/cli/ops/runtime.rs index b1382ce360..72555344ce 100644 --- a/cli/ops/runtime.rs +++ b/cli/ops/runtime.rs @@ -5,7 +5,8 @@ use crate::op_error::OpError; use crate::state::State; use crate::version; use crate::DenoSubcommand; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; use std::env; /// BUILD_OS and BUILD_ARCH match the values in Deno.build. See js/build.ts. @@ -18,7 +19,7 @@ static BUILD_OS: &str = "win"; #[cfg(target_arch = "x86_64")] static BUILD_ARCH: &str = "x64"; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_start", s.stateful_json_op(op_start)); i.register_op("op_metrics", s.stateful_json_op(op_metrics)); } diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index 87702b7ad4..666e243dc2 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -4,10 +4,11 @@ use crate::compilers::runtime_compile; use crate::compilers::runtime_transpile; use crate::op_error::OpError; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; use std::collections::HashMap; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_compile", s.stateful_json_op(op_compile)); i.register_op("op_transpile", s.stateful_json_op(op_transpile)); } diff --git a/cli/ops/signal.rs b/cli/ops/signal.rs index 0d0660ce91..8cada6b995 100644 --- a/cli/ops/signal.rs +++ b/cli/ops/signal.rs @@ -2,7 +2,8 @@ use super::dispatch_json::{JsonOp, Value}; use crate::op_error::OpError; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; #[cfg(unix)] use super::dispatch_json::Deserialize; @@ -13,7 +14,7 @@ use std::task::Waker; #[cfg(unix)] use tokio::signal::unix::{signal, Signal, SignalKind}; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_signal_bind", s.stateful_json_op2(op_signal_bind)); i.register_op("op_signal_unbind", s.stateful_json_op2(op_signal_unbind)); i.register_op("op_signal_poll", s.stateful_json_op2(op_signal_poll)); @@ -38,7 +39,7 @@ struct SignalArgs { #[cfg(unix)] fn op_signal_bind( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, _zero_copy: Option, @@ -59,7 +60,7 @@ fn op_signal_bind( #[cfg(unix)] fn op_signal_poll( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, _zero_copy: Option, @@ -85,7 +86,7 @@ fn op_signal_poll( #[cfg(unix)] pub fn op_signal_unbind( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, _zero_copy: Option, @@ -109,7 +110,7 @@ pub fn op_signal_unbind( #[cfg(not(unix))] pub fn op_signal_bind( - _isolate: &mut deno_core::Isolate, + _isolate: &mut CoreIsolate, _state: &State, _args: Value, _zero_copy: Option, @@ -119,7 +120,7 @@ pub fn op_signal_bind( #[cfg(not(unix))] fn op_signal_unbind( - _isolate: &mut deno_core::Isolate, + _isolate: &mut CoreIsolate, _state: &State, _args: Value, _zero_copy: Option, @@ -129,7 +130,7 @@ fn op_signal_unbind( #[cfg(not(unix))] fn op_signal_poll( - _isolate: &mut deno_core::Isolate, + _isolate: &mut CoreIsolate, _state: &State, _args: Value, _zero_copy: Option, diff --git a/cli/ops/timers.rs b/cli/ops/timers.rs index 29d2514c9b..e5bc461d03 100644 --- a/cli/ops/timers.rs +++ b/cli/ops/timers.rs @@ -2,12 +2,13 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::op_error::OpError; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; use futures::future::FutureExt; use std::time::Duration; use std::time::Instant; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op( "op_global_timer_stop", s.stateful_json_op(op_global_timer_stop), diff --git a/cli/ops/tls.rs b/cli/ops/tls.rs index 27d7739edd..d422014fd5 100644 --- a/cli/ops/tls.rs +++ b/cli/ops/tls.rs @@ -4,7 +4,8 @@ use super::io::{StreamResource, StreamResourceHolder}; use crate::op_error::OpError; use crate::resolve_addr::resolve_addr; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; use futures::future::poll_fn; use futures::future::FutureExt; use std::convert::From; @@ -27,7 +28,7 @@ use tokio_rustls::{ }; use webpki::DNSNameRef; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_start_tls", s.stateful_json_op2(op_start_tls)); i.register_op("op_connect_tls", s.stateful_json_op2(op_connect_tls)); i.register_op("op_listen_tls", s.stateful_json_op2(op_listen_tls)); @@ -52,7 +53,7 @@ struct StartTLSArgs { } pub fn op_start_tls( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, _zero_copy: Option, @@ -125,7 +126,7 @@ pub fn op_start_tls( } pub fn op_connect_tls( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, _zero_copy: Option, @@ -301,7 +302,7 @@ struct ListenTlsArgs { } fn op_listen_tls( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, state: &State, args: Value, _zero_copy: Option, @@ -351,7 +352,7 @@ struct AcceptTlsArgs { } fn op_accept_tls( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, _zero_copy: Option, diff --git a/cli/ops/tty.rs b/cli/ops/tty.rs index 54b3eca5fa..53736ae919 100644 --- a/cli/ops/tty.rs +++ b/cli/ops/tty.rs @@ -3,7 +3,8 @@ use super::io::std_file_resource; use super::io::{StreamResource, StreamResourceHolder}; use crate::op_error::OpError; use crate::state::State; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; #[cfg(unix)] use nix::sys::termios; use serde_derive::Deserialize; @@ -33,7 +34,7 @@ fn get_windows_handle( Ok(handle) } -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_set_raw", s.stateful_json_op2(op_set_raw)); i.register_op("op_isatty", s.stateful_json_op2(op_isatty)); } @@ -45,7 +46,7 @@ struct SetRawArgs { } pub fn op_set_raw( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, _zero_copy: Option, @@ -213,7 +214,7 @@ struct IsattyArgs { } pub fn op_isatty( - isolate: &mut deno_core::Isolate, + isolate: &mut CoreIsolate, _state: &State, args: Value, _zero_copy: Option, diff --git a/cli/ops/web_worker.rs b/cli/ops/web_worker.rs index ee376719fd..e95eb8fe11 100644 --- a/cli/ops/web_worker.rs +++ b/cli/ops/web_worker.rs @@ -5,18 +5,15 @@ use crate::ops::json_op; use crate::state::State; use crate::web_worker::WebWorkerHandle; use crate::worker::WorkerEvent; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ZeroCopyBuf; use futures::channel::mpsc; use std::convert::From; pub fn web_worker_op( sender: mpsc::Sender, dispatcher: D, -) -> impl Fn( - &mut deno_core::Isolate, - Value, - Option, -) -> Result +) -> impl Fn(&mut CoreIsolate, Value, Option) -> Result where D: Fn( &mpsc::Sender, @@ -24,7 +21,7 @@ where Option, ) -> Result, { - move |_isolate: &mut deno_core::Isolate, + move |_isolate: &mut CoreIsolate, args: Value, zero_copy: Option| -> Result { dispatcher(&sender, args, zero_copy) } @@ -34,11 +31,7 @@ pub fn web_worker_op2( handle: WebWorkerHandle, sender: mpsc::Sender, dispatcher: D, -) -> impl Fn( - &mut deno_core::Isolate, - Value, - Option, -) -> Result +) -> impl Fn(&mut CoreIsolate, Value, Option) -> Result where D: Fn( WebWorkerHandle, @@ -47,7 +40,7 @@ where Option, ) -> Result, { - move |_isolate: &mut deno_core::Isolate, + move |_isolate: &mut CoreIsolate, args: Value, zero_copy: Option| -> Result { @@ -56,7 +49,7 @@ where } pub fn init( - i: &mut Isolate, + i: &mut CoreIsolate, s: &State, sender: &mpsc::Sender, handle: WebWorkerHandle, diff --git a/cli/ops/worker_host.rs b/cli/ops/worker_host.rs index 4704e99fe1..460596b818 100644 --- a/cli/ops/worker_host.rs +++ b/cli/ops/worker_host.rs @@ -11,12 +11,15 @@ use crate::tokio_util::create_basic_runtime; use crate::web_worker::WebWorker; use crate::web_worker::WebWorkerHandle; use crate::worker::WorkerEvent; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::ErrBox; +use deno_core::ModuleSpecifier; +use deno_core::ZeroCopyBuf; use futures::future::FutureExt; use std::convert::From; use std::thread::JoinHandle; -pub fn init(i: &mut Isolate, s: &State) { +pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_create_worker", s.stateful_json_op(op_create_worker)); i.register_op( "op_host_terminate_worker", diff --git a/cli/state.rs b/cli/state.rs index c59eb8eeb3..96be28f2f6 100644 --- a/cli/state.rs +++ b/cli/state.rs @@ -71,7 +71,7 @@ impl State { pub fn stateful_json_op( &self, dispatcher: D, - ) -> impl Fn(&mut deno_core::Isolate, &[u8], Option) -> Op + ) -> impl Fn(&mut deno_core::CoreIsolate, &[u8], Option) -> Op where D: Fn(&State, Value, Option) -> Result, { @@ -82,10 +82,10 @@ impl State { pub fn stateful_json_op2( &self, dispatcher: D, - ) -> impl Fn(&mut deno_core::Isolate, &[u8], Option) -> Op + ) -> impl Fn(&mut deno_core::CoreIsolate, &[u8], Option) -> Op where D: Fn( - &mut deno_core::Isolate, + &mut deno_core::CoreIsolate, &State, Value, Option, @@ -101,13 +101,13 @@ impl State { pub fn core_op( &self, dispatcher: D, - ) -> impl Fn(&mut deno_core::Isolate, &[u8], Option) -> Op + ) -> impl Fn(&mut deno_core::CoreIsolate, &[u8], Option) -> Op where - D: Fn(&mut deno_core::Isolate, &[u8], Option) -> Op, + D: Fn(&mut deno_core::CoreIsolate, &[u8], Option) -> Op, { let state = self.clone(); - move |isolate: &mut deno_core::Isolate, + move |isolate: &mut deno_core::CoreIsolate, control: &[u8], zero_copy: Option| -> Op { @@ -161,10 +161,10 @@ impl State { pub fn stateful_minimal_op2( &self, dispatcher: D, - ) -> impl Fn(&mut deno_core::Isolate, &[u8], Option) -> Op + ) -> impl Fn(&mut deno_core::CoreIsolate, &[u8], Option) -> Op where D: Fn( - &mut deno_core::Isolate, + &mut deno_core::CoreIsolate, &State, bool, i32, @@ -173,7 +173,7 @@ impl State { { let state = self.clone(); self.core_op(crate::ops::minimal_op( - move |isolate: &mut deno_core::Isolate, + move |isolate: &mut deno_core::CoreIsolate, is_sync: bool, rid: i32, zero_copy: Option| @@ -186,13 +186,13 @@ impl State { /// This is a special function that provides `state` argument to dispatcher. /// /// NOTE: This only works with JSON dispatcher. - /// This is a band-aid for transition to `Isolate.register_op` API as most of our + /// This is a band-aid for transition to `CoreIsolate.register_op` API as most of our /// ops require `state` argument. pub fn stateful_op( &self, dispatcher: D, ) -> impl Fn( - &mut deno_core::Isolate, + &mut deno_core::CoreIsolate, Value, Option, ) -> Result @@ -200,7 +200,7 @@ impl State { D: Fn(&State, Value, Option) -> Result, { let state = self.clone(); - move |_isolate: &mut deno_core::Isolate, + move |_isolate: &mut deno_core::CoreIsolate, args: Value, zero_copy: Option| -> Result { dispatcher(&state, args, zero_copy) } @@ -210,20 +210,20 @@ impl State { &self, dispatcher: D, ) -> impl Fn( - &mut deno_core::Isolate, + &mut deno_core::CoreIsolate, Value, Option, ) -> Result where D: Fn( - &mut deno_core::Isolate, + &mut deno_core::CoreIsolate, &State, Value, Option, ) -> Result, { let state = self.clone(); - move |isolate: &mut deno_core::Isolate, + move |isolate: &mut deno_core::CoreIsolate, args: Value, zero_copy: Option| -> Result { diff --git a/core/bindings.rs b/core/bindings.rs index d34dfe8341..25272af847 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -1,7 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use crate::es_isolate::EsIsolate; -use crate::isolate::Isolate; +use crate::isolate::CoreIsolate; use crate::isolate::ZeroCopyBuf; use crate::js_errors::JSError; @@ -251,7 +251,7 @@ pub extern "C" fn host_import_module_dynamically_callback( let mut hs = v8::EscapableHandleScope::new(cbs.enter()); let scope = hs.enter(); let isolate = scope.isolate(); - let deno_isolate: &mut EsIsolate = + let core_isolate: &mut EsIsolate = unsafe { &mut *(isolate.get_data(1) as *mut EsIsolate) }; // NOTE(bartlomieju): will crash for non-UTF-8 specifier @@ -277,13 +277,13 @@ pub extern "C" fn host_import_module_dynamically_callback( let mut resolver_handle = v8::Global::new(); resolver_handle.set(scope, resolver); - let import_id = deno_isolate.next_dyn_import_id; - deno_isolate.next_dyn_import_id += 1; - deno_isolate + let import_id = core_isolate.next_dyn_import_id; + core_isolate.next_dyn_import_id += 1; + core_isolate .dyn_import_map .insert(import_id, resolver_handle); - deno_isolate.dyn_import_cb(&specifier_str, &referrer_name_str, import_id); + core_isolate.dyn_import_cb(&specifier_str, &referrer_name_str, import_id); &mut *scope.escape(promise) } @@ -297,13 +297,13 @@ pub extern "C" fn host_initialize_import_meta_object_callback( let mut hs = v8::HandleScope::new(cbs.enter()); let scope = hs.enter(); let isolate = scope.isolate(); - let deno_isolate: &mut EsIsolate = + let core_isolate: &mut EsIsolate = unsafe { &mut *(isolate.get_data(1) as *mut EsIsolate) }; let id = module.get_identity_hash(); assert_ne!(id, 0); - let info = deno_isolate.modules.get_info(id).expect("Module not found"); + let info = core_isolate.modules.get_info(id).expect("Module not found"); meta.create_data_property( context, @@ -322,10 +322,10 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) { let mut hs = v8::HandleScope::new(cbs.enter()); let scope = hs.enter(); - let deno_isolate: &mut Isolate = - unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; + let core_isolate: &mut CoreIsolate = + unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) }; - let context = deno_isolate.global_context.get(scope).unwrap(); + let context = core_isolate.global_context.get(scope).unwrap(); let mut cs = v8::ContextScope::new(scope, context); let scope = cs.enter(); @@ -337,13 +337,13 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) { let error = message.get_value(); let mut error_global = v8::Global::::new(); error_global.set(scope, error); - deno_isolate + core_isolate .pending_promise_exceptions .insert(promise_id, error_global); } v8::PromiseRejectEvent::PromiseHandlerAddedAfterReject => { if let Some(mut handle) = - deno_isolate.pending_promise_exceptions.remove(&promise_id) + core_isolate.pending_promise_exceptions.remove(&promise_id) { handle.reset(scope); } @@ -417,17 +417,17 @@ fn recv( args: v8::FunctionCallbackArguments, _rv: v8::ReturnValue, ) { - let deno_isolate: &mut Isolate = - unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; + let core_isolate: &mut CoreIsolate = + unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) }; - if !deno_isolate.js_recv_cb.is_empty() { + if !core_isolate.js_recv_cb.is_empty() { let msg = v8::String::new(scope, "Deno.core.recv already called.").unwrap(); scope.isolate().throw_exception(msg.into()); return; } let recv_fn = v8::Local::::try_from(args.get(0)).unwrap(); - deno_isolate.js_recv_cb.set(scope, recv_fn); + core_isolate.js_recv_cb.set(scope, recv_fn); } fn send( @@ -435,9 +435,9 @@ fn send( args: v8::FunctionCallbackArguments, mut rv: v8::ReturnValue, ) { - let deno_isolate: &mut Isolate = - unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; - assert!(!deno_isolate.global_context.is_empty()); + let core_isolate: &mut CoreIsolate = + unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) }; + assert!(!core_isolate.global_context.is_empty()); let op_id = match v8::Local::::try_from(args.get(0)) { Ok(op_id) => op_id.value() as u32, @@ -469,7 +469,7 @@ fn send( // If response is empty then it's either async op or exception was thrown let maybe_response = - deno_isolate.dispatch_op(scope, op_id, control, zero_copy); + core_isolate.dispatch_op(scope, op_id, control, zero_copy); if let Some(response) = maybe_response { // Synchronous response. @@ -488,10 +488,10 @@ fn set_macrotask_callback( args: v8::FunctionCallbackArguments, _rv: v8::ReturnValue, ) { - let deno_isolate: &mut Isolate = - unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; + let core_isolate: &mut CoreIsolate = + unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) }; - if !deno_isolate.js_macrotask_cb.is_empty() { + if !core_isolate.js_macrotask_cb.is_empty() { let msg = v8::String::new(scope, "Deno.core.setMacrotaskCallback already called.") .unwrap(); @@ -501,7 +501,7 @@ fn set_macrotask_callback( let macrotask_cb_fn = v8::Local::::try_from(args.get(0)).unwrap(); - deno_isolate.js_macrotask_cb.set(scope, macrotask_cb_fn); + core_isolate.js_macrotask_cb.set(scope, macrotask_cb_fn); } fn eval_context( @@ -509,10 +509,10 @@ fn eval_context( args: v8::FunctionCallbackArguments, mut rv: v8::ReturnValue, ) { - let deno_isolate: &mut Isolate = - unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; - assert!(!deno_isolate.global_context.is_empty()); - let context = deno_isolate.global_context.get(scope).unwrap(); + let core_isolate: &mut CoreIsolate = + unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) }; + assert!(!core_isolate.global_context.is_empty()); + let context = core_isolate.global_context.get(scope).unwrap(); let source = match v8::Local::::try_from(args.get(0)) { Ok(s) => s, @@ -645,10 +645,10 @@ fn format_error( args: v8::FunctionCallbackArguments, mut rv: v8::ReturnValue, ) { - let deno_isolate: &mut Isolate = - unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; + let core_isolate: &mut CoreIsolate = + unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) }; let e = JSError::from_v8_exception(scope, args.get(0)); - let e = (deno_isolate.js_error_create_fn)(e); + let e = (core_isolate.js_error_create_fn)(e); let e = e.to_string(); let e = v8::String::new(scope, &e).unwrap(); rv.set(e.into()) @@ -736,19 +736,19 @@ fn shared_getter( _args: v8::PropertyCallbackArguments, mut rv: v8::ReturnValue, ) { - let deno_isolate: &mut Isolate = - unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; + let core_isolate: &mut CoreIsolate = + unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) }; // Lazily initialize the persistent external ArrayBuffer. - if deno_isolate.shared_ab.is_empty() { + if core_isolate.shared_ab.is_empty() { let ab = v8::SharedArrayBuffer::with_backing_store( scope, - deno_isolate.shared.get_backing_store(), + core_isolate.shared.get_backing_store(), ); - deno_isolate.shared_ab.set(scope, ab); + core_isolate.shared_ab.set(scope, ab); } - let shared_ab = deno_isolate.shared_ab.get(scope).unwrap(); + let shared_ab = core_isolate.shared_ab.get(scope).unwrap(); rv.set(shared_ab.into()); } @@ -761,11 +761,11 @@ pub fn module_resolve_callback<'s>( let mut scope = v8::EscapableHandleScope::new(scope.enter()); let scope = scope.enter(); - let deno_isolate: &mut EsIsolate = + let core_isolate: &mut EsIsolate = unsafe { &mut *(scope.isolate().get_data(1) as *mut EsIsolate) }; let referrer_id = referrer.get_identity_hash(); - let referrer_name = deno_isolate + let referrer_name = core_isolate .modules .get_info(referrer_id) .expect("ModuleInfo not found") @@ -780,8 +780,8 @@ pub fn module_resolve_callback<'s>( let req_str = req.to_rust_string_lossy(scope); if req_str == specifier_str { - let id = deno_isolate.module_resolve_cb(&req_str, referrer_id); - let maybe_info = deno_isolate.modules.get_info(id); + let id = core_isolate.module_resolve_cb(&req_str, referrer_id); + let maybe_info = core_isolate.modules.get_info(id); if maybe_info.is_none() { let msg = format!( @@ -812,10 +812,10 @@ fn get_promise_details( args: v8::FunctionCallbackArguments, mut rv: v8::ReturnValue, ) { - let deno_isolate: &mut Isolate = - unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; - assert!(!deno_isolate.global_context.is_empty()); - let context = deno_isolate.global_context.get(scope).unwrap(); + let core_isolate: &mut CoreIsolate = + unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) }; + assert!(!core_isolate.global_context.is_empty()); + let context = core_isolate.global_context.get(scope).unwrap(); let promise = match v8::Local::::try_from(args.get(0)) { Ok(val) => val, diff --git a/core/es_isolate.rs b/core/es_isolate.rs index b847005f9b..8b6f6fb301 100644 --- a/core/es_isolate.rs +++ b/core/es_isolate.rs @@ -1,6 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -// This module provides higher level implementation of Isolate that +// This module provides higher level implementation of CoreIsolate that // supports asynchronous loading and executution of ES Modules. // The isolate.rs should never depend on this module. @@ -27,7 +27,7 @@ use std::task::Poll; use crate::isolate::attach_handle_to_error; use crate::isolate::exception_to_err_result; -use crate::isolate::Isolate; +use crate::isolate::CoreIsolate; use crate::isolate::StartupData; use crate::module_specifier::ModuleSpecifier; use crate::modules::LoadState; @@ -39,14 +39,14 @@ use crate::modules::RecursiveModuleLoad; pub type ModuleId = i32; pub type DynImportId = i32; -/// More specialized version of `Isolate` that provides loading +/// More specialized version of `CoreIsolate` that provides loading /// and execution of ES Modules. /// /// Creating `EsIsolate` requires to pass `loader` argument /// that implements `ModuleLoader` trait - that way actual resolution and /// loading of modules can be customized by the implementor. pub struct EsIsolate { - core_isolate: Box, + core_isolate: Box, loader: Rc, pub modules: Modules, pub(crate) next_dyn_import_id: DynImportId, @@ -58,7 +58,7 @@ pub struct EsIsolate { } impl Deref for EsIsolate { - type Target = Isolate; + type Target = CoreIsolate; fn deref(&self) -> &Self::Target { &self.core_isolate @@ -77,7 +77,7 @@ impl EsIsolate { startup_data: StartupData, will_snapshot: bool, ) -> Box { - let mut core_isolate = Isolate::new(startup_data, will_snapshot); + let mut core_isolate = CoreIsolate::new(startup_data, will_snapshot); { let v8_isolate = core_isolate.v8_isolate.as_mut().unwrap(); v8_isolate.set_host_initialize_import_meta_object_callback( @@ -174,7 +174,7 @@ impl EsIsolate { /// /// ErrBox can be downcast to a type that exposes additional information about /// the V8 exception. By default this type is JSError, however it may be a - /// different type if Isolate::set_js_error_create_fn() has been used. + /// different type if CoreIsolate::set_js_error_create_fn() has been used. fn mod_instantiate(&mut self, id: ModuleId) -> Result<(), ErrBox> { let v8_isolate = self.core_isolate.v8_isolate.as_mut().unwrap(); let js_error_create_fn = &*self.core_isolate.js_error_create_fn; @@ -219,7 +219,7 @@ impl EsIsolate { /// /// ErrBox can be downcast to a type that exposes additional information about /// the V8 exception. By default this type is JSError, however it may be a - /// different type if Isolate::set_js_error_create_fn() has been used. + /// different type if CoreIsolate::set_js_error_create_fn() has been used. pub fn mod_evaluate(&mut self, id: ModuleId) -> Result<(), ErrBox> { let core_isolate = &mut self.core_isolate; let v8_isolate = core_isolate.v8_isolate.as_mut().unwrap(); @@ -580,7 +580,7 @@ pub mod tests { let mut isolate = EsIsolate::new(loader, StartupData::None, false); - let dispatcher = move |_isolate: &mut Isolate, + let dispatcher = move |_isolate: &mut CoreIsolate, control: &[u8], _zero_copy: Option| -> Op { diff --git a/core/examples/http_bench.rs b/core/examples/http_bench.rs index 9e58080438..f728b2a69d 100644 --- a/core/examples/http_bench.rs +++ b/core/examples/http_bench.rs @@ -3,8 +3,12 @@ extern crate derive_deref; #[macro_use] extern crate log; -use deno_core::Isolate as CoreIsolate; -use deno_core::*; +use deno_core::CoreIsolate; +use deno_core::Op; +use deno_core::ResourceTable; +use deno_core::Script; +use deno_core::StartupData; +use deno_core::ZeroCopyBuf; use futures::future::poll_fn; use futures::prelude::*; use futures::task::Context; @@ -111,7 +115,7 @@ impl Isolate { F: 'static + Fn(State, u32, Option) -> Result, { let state = self.state.clone(); - let core_handler = move |_isolate: &mut deno_core::Isolate, + let core_handler = move |_isolate: &mut CoreIsolate, control_buf: &[u8], zero_copy_buf: Option| -> Op { @@ -141,7 +145,7 @@ impl Isolate { >::Error: Debug, { let state = self.state.clone(); - let core_handler = move |_isolate: &mut deno_core::Isolate, + let core_handler = move |_isolate: &mut CoreIsolate, control_buf: &[u8], zero_copy_buf: Option| -> Op { diff --git a/core/isolate.rs b/core/isolate.rs index 6e0728564a..37a9de2ad8 100644 --- a/core/isolate.rs +++ b/core/isolate.rs @@ -140,15 +140,15 @@ type JSErrorCreateFn = dyn Fn(JSError) -> ErrBox; type IsolateErrorHandleFn = dyn FnMut(ErrBox) -> Result<(), ErrBox>; /// A single execution context of JavaScript. Corresponds roughly to the "Web -/// Worker" concept in the DOM. An Isolate is a Future that can be used with -/// Tokio. The Isolate future complete when there is an error or when all +/// Worker" concept in the DOM. An CoreIsolate is a Future that can be used with +/// Tokio. The CoreIsolate future complete when there is an error or when all /// pending ops have completed. /// /// Ops are created in JavaScript by calling Deno.core.dispatch(), and in Rust /// by implementing dispatcher function that takes control buffer and optional zero copy buffer /// as arguments. An async Op corresponds exactly to a Promise in JavaScript. #[allow(unused)] -pub struct Isolate { +pub struct CoreIsolate { pub v8_isolate: Option, snapshot_creator: Option, has_snapshotted: bool, @@ -171,7 +171,7 @@ pub struct Isolate { error_handler: Option>, } -impl Drop for Isolate { +impl Drop for CoreIsolate { fn drop(&mut self) { if let Some(creator) = self.snapshot_creator.take() { // TODO(ry): in rusty_v8, `SnapShotCreator::get_owned_isolate()` returns @@ -212,7 +212,7 @@ pub unsafe fn v8_init() { v8::V8::set_flags_from_command_line(argv); } -impl Isolate { +impl CoreIsolate { /// startup_data defines the snapshot or script used at startup to initialize /// the isolate. pub fn new(startup_data: StartupData, will_snapshot: bool) -> Box { @@ -233,7 +233,7 @@ impl Isolate { let mut creator = v8::SnapshotCreator::new(Some(&bindings::EXTERNAL_REFERENCES)); let isolate = unsafe { creator.get_owned_isolate() }; - let mut isolate = Isolate::setup_isolate(isolate); + let mut isolate = CoreIsolate::setup_isolate(isolate); let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); @@ -257,7 +257,7 @@ impl Isolate { }; let isolate = v8::Isolate::new(params); - let mut isolate = Isolate::setup_isolate(isolate); + let mut isolate = CoreIsolate::setup_isolate(isolate); let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); @@ -314,7 +314,7 @@ impl Isolate { boxed_isolate } - pub fn setup_isolate(mut isolate: v8::OwnedIsolate) -> v8::OwnedIsolate { + fn setup_isolate(mut isolate: v8::OwnedIsolate) -> v8::OwnedIsolate { isolate.set_capture_stack_trace_for_uncaught_exceptions(true, 10); isolate.set_promise_reject_callback(bindings::promise_reject_callback); isolate @@ -327,7 +327,7 @@ impl Isolate { /// Requires runtime to explicitly ask for op ids before using any of the ops. pub fn register_op(&mut self, name: &str, op: F) -> OpId where - F: Fn(&mut Isolate, &[u8], Option) -> Op + 'static, + F: Fn(&mut CoreIsolate, &[u8], Option) -> Op + 'static, { self.op_registry.register(name, op) } @@ -400,7 +400,7 @@ impl Isolate { /// /// ErrBox can be downcast to a type that exposes additional information about /// the V8 exception. By default this type is JSError, however it may be a - /// different type if Isolate::set_js_error_create_fn() has been used. + /// different type if CoreIsolate::set_js_error_create_fn() has been used. pub fn execute( &mut self, js_filename: &str, @@ -449,7 +449,7 @@ impl Isolate { /// /// ErrBox can be downcast to a type that exposes additional information about /// the V8 exception. By default this type is JSError, however it may be a - /// different type if Isolate::set_js_error_create_fn() has been used. + /// different type if CoreIsolate::set_js_error_create_fn() has been used. pub fn snapshot(&mut self) -> v8::StartupData { assert!(self.snapshot_creator.is_some()); @@ -473,7 +473,7 @@ impl Isolate { } } -impl Future for Isolate { +impl Future for CoreIsolate { type Output = Result<(), ErrBox>; fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll { @@ -727,7 +727,7 @@ pub mod tests { } } panic!( - "Isolate still not ready after polling {} times.", + "CoreIsolate still not ready after polling {} times.", max_poll_count ) } @@ -741,13 +741,13 @@ pub mod tests { OverflowResAsync, } - pub fn setup(mode: Mode) -> (Box, Arc) { + pub fn setup(mode: Mode) -> (Box, Arc) { let dispatch_count = Arc::new(AtomicUsize::new(0)); let dispatch_count_ = dispatch_count.clone(); - let mut isolate = Isolate::new(StartupData::None, false); + let mut isolate = CoreIsolate::new(StartupData::None, false); - let dispatcher = move |_isolate: &mut Isolate, + let dispatcher = move |_isolate: &mut CoreIsolate, control: &[u8], _zero_copy: Option| -> Op { @@ -1141,7 +1141,7 @@ pub mod tests { #[test] fn syntax_error() { - let mut isolate = Isolate::new(StartupData::None, false); + let mut isolate = CoreIsolate::new(StartupData::None, false); let src = "hocuspocus("; let r = isolate.execute("i.js", src); let e = r.unwrap_err(); @@ -1166,13 +1166,13 @@ pub mod tests { #[test] fn will_snapshot() { let snapshot = { - let mut isolate = Isolate::new(StartupData::None, true); + let mut isolate = CoreIsolate::new(StartupData::None, true); js_check(isolate.execute("a.js", "a = 1 + 2")); isolate.snapshot() }; let startup_data = StartupData::Snapshot(Snapshot::JustCreated(snapshot)); - let mut isolate2 = Isolate::new(startup_data, false); + let mut isolate2 = CoreIsolate::new(startup_data, false); js_check(isolate2.execute("check.js", "if (a != 3) throw Error('x')")); } } diff --git a/core/ops.rs b/core/ops.rs index ed9b27e469..0361f5ee9f 100644 --- a/core/ops.rs +++ b/core/ops.rs @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -use crate::Isolate; +use crate::CoreIsolate; use crate::ZeroCopyBuf; use futures::Future; use std::collections::HashMap; @@ -22,7 +22,7 @@ pub enum Op { /// Main type describing op pub type OpDispatcher = - dyn Fn(&mut Isolate, &[u8], Option) -> Op + 'static; + dyn Fn(&mut CoreIsolate, &[u8], Option) -> Op + 'static; #[derive(Default)] pub struct OpRegistry { @@ -43,7 +43,7 @@ impl OpRegistry { pub fn register(&mut self, name: &str, op: F) -> OpId where - F: Fn(&mut Isolate, &[u8], Option) -> Op + 'static, + F: Fn(&mut CoreIsolate, &[u8], Option) -> Op + 'static, { let op_id = self.dispatchers.len() as u32; @@ -86,7 +86,7 @@ fn test_op_registry() { expected.insert("test".to_string(), 1); assert_eq!(op_registry.name_to_id, expected); - let mut isolate = Isolate::new(crate::StartupData::None, false); + let mut isolate = CoreIsolate::new(crate::StartupData::None, false); let dispatch = op_registry.get(test_id).unwrap(); let res = dispatch(&mut isolate, &[], None); @@ -126,7 +126,7 @@ fn register_op_during_call() { }; assert!(test_id != 0); - let mut isolate = Isolate::new(crate::StartupData::None, false); + let mut isolate = CoreIsolate::new(crate::StartupData::None, false); let dispatcher1 = { let g = op_registry.lock().unwrap(); diff --git a/deno_typescript/lib.rs b/deno_typescript/lib.rs index 24ecd62877..d554022d8b 100644 --- a/deno_typescript/lib.rs +++ b/deno_typescript/lib.rs @@ -8,8 +8,8 @@ extern crate serde_json; mod ops; use deno_core::js_check; pub use deno_core::v8_set_flags; +use deno_core::CoreIsolate; use deno_core::ErrBox; -use deno_core::Isolate; use deno_core::ModuleSpecifier; use deno_core::Op; use deno_core::StartupData; @@ -49,11 +49,11 @@ pub struct TSState { fn compiler_op( ts_state: Arc>, dispatcher: D, -) -> impl Fn(&mut deno_core::Isolate, &[u8], Option) -> Op +) -> impl Fn(&mut CoreIsolate, &[u8], Option) -> Op where D: Fn(&mut TSState, &[u8]) -> Op, { - move |_isolate: &mut deno_core::Isolate, + move |_isolate: &mut CoreIsolate, control: &[u8], zero_copy_buf: Option| -> Op { @@ -64,7 +64,7 @@ where } pub struct TSIsolate { - isolate: Box, + isolate: Box, state: Arc>, } @@ -73,7 +73,7 @@ impl TSIsolate { bundle: bool, maybe_extern_crate_modules: Option, ) -> TSIsolate { - let mut isolate = Isolate::new(StartupData::None, false); + let mut isolate = CoreIsolate::new(StartupData::None, false); js_check(isolate.execute("assets/typescript.js", TYPESCRIPT_CODE)); js_check(isolate.execute("compiler_main.js", COMPILER_CODE)); @@ -196,7 +196,7 @@ fn print_source_code(code: &str) { /// Create a V8 snapshot. pub fn mksnapshot_bundle( - isolate: &mut Isolate, + isolate: &mut CoreIsolate, snapshot_filename: &Path, bundle_filename: &Path, main_module_name: &str, @@ -216,7 +216,7 @@ pub fn mksnapshot_bundle( /// Create a V8 snapshot. This differs from mksnapshot_bundle in that is also /// runs typescript.js pub fn mksnapshot_bundle_ts( - isolate: &mut Isolate, + isolate: &mut CoreIsolate, snapshot_filename: &Path, bundle_filename: &Path, main_module_name: &str, @@ -231,7 +231,7 @@ pub fn mksnapshot_bundle_ts( } fn write_snapshot( - runtime_isolate: &mut Isolate, + runtime_isolate: &mut CoreIsolate, snapshot_filename: &Path, ) -> Result<(), ErrBox> { println!("Creating snapshot..."); @@ -326,14 +326,14 @@ pub fn trace_serializer() { } /// Warning: Returns a non-JSON op dispatcher. Must be manually attached to -/// Isolate. +/// CoreIsolate. pub fn op_fetch_asset( custom_assets: HashMap, -) -> impl Fn(&mut deno_core::Isolate, &[u8], Option) -> Op { +) -> impl Fn(&mut CoreIsolate, &[u8], Option) -> Op { for (_, path) in custom_assets.iter() { println!("cargo:rerun-if-changed={}", path.display()); } - move |_isolate: &mut deno_core::Isolate, + move |_isolate: &mut CoreIsolate, control: &[u8], zero_copy_buf: Option| -> Op { diff --git a/test_plugin/src/lib.rs b/test_plugin/src/lib.rs index 0c8655c5dd..2304cd65b2 100644 --- a/test_plugin/src/lib.rs +++ b/test_plugin/src/lib.rs @@ -2,18 +2,19 @@ extern crate deno_core; extern crate futures; use deno_core::Buf; +use deno_core::CoreIsolate; use deno_core::Op; use deno_core::ZeroCopyBuf; use futures::future::FutureExt; #[no_mangle] -pub fn deno_plugin_init(isolate: &mut deno_core::Isolate) { +pub fn deno_plugin_init(isolate: &mut CoreIsolate) { isolate.register_op("testSync", op_test_sync); isolate.register_op("testAsync", op_test_async); } pub fn op_test_sync( - _isolate: &mut deno_core::Isolate, + _isolate: &mut CoreIsolate, data: &[u8], zero_copy: Option, ) -> Op { @@ -31,7 +32,7 @@ pub fn op_test_sync( } pub fn op_test_async( - _isolate: &mut deno_core::Isolate, + _isolate: &mut CoreIsolate, data: &[u8], zero_copy: Option, ) -> Op {