1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

Rename deno_core::Isolate to deno_core::CoreIsolate (#4851)

This commit is contained in:
Ryan Dahl 2020-04-23 05:51:07 -04:00 committed by GitHub
parent 10a174834e
commit d8711155ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 253 additions and 227 deletions

View file

@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use deno_core::include_crate_modules; use deno_core::include_crate_modules;
use deno_core::Isolate; use deno_core::CoreIsolate;
use deno_core::StartupData; use deno_core::StartupData;
use std::collections::HashMap; use std::collections::HashMap;
use std::env; use std::env;
@ -48,10 +48,10 @@ fn main() {
.expect("Bundle compilation failed"); .expect("Bundle compilation failed");
assert!(bundle_path.exists()); 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( deno_typescript::mksnapshot_bundle(
runtime_isolate, &mut runtime_isolate,
&snapshot_path, &snapshot_path,
&bundle_path, &bundle_path,
&main_module_name, &main_module_name,
@ -71,7 +71,7 @@ fn main() {
.expect("Bundle compilation failed"); .expect("Bundle compilation failed");
assert!(bundle_path.exists()); 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<String, PathBuf> = HashMap::new(); let mut custom_libs: HashMap<String, PathBuf> = HashMap::new();
custom_libs.insert( custom_libs.insert(
@ -96,7 +96,7 @@ fn main() {
); );
deno_typescript::mksnapshot_bundle_ts( deno_typescript::mksnapshot_bundle_ts(
runtime_isolate, &mut runtime_isolate,
&snapshot_path, &snapshot_path,
&bundle_path, &bundle_path,
&main_module_name, &main_module_name,

View file

@ -308,11 +308,11 @@ impl DenoInspector {
const CONTEXT_GROUP_ID: i32 = 1; const CONTEXT_GROUP_ID: i32 = 1;
pub fn new( pub fn new(
isolate: &mut deno_core::Isolate, isolate: &mut deno_core::CoreIsolate,
host: SocketAddr, host: SocketAddr,
wait_for_debugger: bool, wait_for_debugger: bool,
) -> Box<Self> { ) -> Box<Self> {
let deno_core::Isolate { let deno_core::CoreIsolate {
v8_isolate, v8_isolate,
global_context, global_context,
.. ..

View file

@ -23,7 +23,7 @@ pub static WINDOW_LIB: &str = include_str!("js/lib.deno.window.d.ts");
#[test] #[test]
fn cli_snapshot() { 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)), deno_core::StartupData::Snapshot(deno_core::Snapshot::Static(CLI_SNAPSHOT)),
false, false,
); );
@ -40,7 +40,7 @@ fn cli_snapshot() {
#[test] #[test]
fn compiler_snapshot() { 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( deno_core::StartupData::Snapshot(deno_core::Snapshot::Static(
COMPILER_SNAPSHOT, COMPILER_SNAPSHOT,
)), )),

View file

@ -6,11 +6,13 @@ use crate::futures::future::try_join_all;
use crate::msg; use crate::msg;
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::state::State; use crate::state::State;
use deno_core::CoreIsolate;
use deno_core::ModuleLoader; use deno_core::ModuleLoader;
use deno_core::*; use deno_core::ModuleSpecifier;
use deno_core::ZeroCopyBuf;
use futures::future::FutureExt; 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_cache", s.stateful_json_op(op_cache));
i.register_op("op_resolve_modules", s.stateful_json_op(op_resolve_modules)); i.register_op("op_resolve_modules", s.stateful_json_op(op_resolve_modules));
i.register_op( i.register_op(

View file

@ -1,6 +1,9 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use crate::op_error::OpError; 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; use futures::future::FutureExt;
pub use serde_derive::Deserialize; pub use serde_derive::Deserialize;
use serde_json::json; use serde_json::json;
@ -43,15 +46,12 @@ struct AsyncArgs {
pub fn json_op<D>( pub fn json_op<D>(
d: D, d: D,
) -> impl Fn(&mut deno_core::Isolate, &[u8], Option<ZeroCopyBuf>) -> Op ) -> impl Fn(&mut CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op
where where
D: Fn( D:
&mut deno_core::Isolate, Fn(&mut CoreIsolate, Value, Option<ZeroCopyBuf>) -> Result<JsonOp, OpError>,
Value,
Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError>,
{ {
move |isolate: &mut deno_core::Isolate, move |isolate: &mut CoreIsolate,
control: &[u8], control: &[u8],
zero_copy: Option<ZeroCopyBuf>| { zero_copy: Option<ZeroCopyBuf>| {
let async_args: AsyncArgs = match serde_json::from_slice(control) { let async_args: AsyncArgs = match serde_json::from_slice(control) {

View file

@ -7,6 +7,7 @@
use crate::op_error::OpError; use crate::op_error::OpError;
use byteorder::{LittleEndian, WriteBytesExt}; use byteorder::{LittleEndian, WriteBytesExt};
use deno_core::Buf; use deno_core::Buf;
use deno_core::CoreIsolate;
use deno_core::Op; use deno_core::Op;
use deno_core::ZeroCopyBuf; use deno_core::ZeroCopyBuf;
use futures::future::FutureExt; use futures::future::FutureExt;
@ -115,11 +116,11 @@ fn test_parse_min_record() {
pub fn minimal_op<D>( pub fn minimal_op<D>(
d: D, d: D,
) -> impl Fn(&mut deno_core::Isolate, &[u8], Option<ZeroCopyBuf>) -> Op ) -> impl Fn(&mut CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op
where where
D: Fn(&mut deno_core::Isolate, bool, i32, Option<ZeroCopyBuf>) -> MinimalOp, D: Fn(&mut CoreIsolate, bool, i32, Option<ZeroCopyBuf>) -> MinimalOp,
{ {
move |isolate: &mut deno_core::Isolate, move |isolate: &mut CoreIsolate,
control: &[u8], control: &[u8],
zero_copy: Option<ZeroCopyBuf>| { zero_copy: Option<ZeroCopyBuf>| {
let mut record = match parse_min_record(control) { let mut record = match parse_min_record(control) {

View file

@ -5,10 +5,11 @@ use crate::op_error::OpError;
use crate::source_maps::get_orig_position; use crate::source_maps::get_orig_position;
use crate::source_maps::CachedMaps; use crate::source_maps::CachedMaps;
use crate::state::State; use crate::state::State;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
use std::collections::HashMap; use std::collections::HashMap;
pub fn init(i: &mut Isolate, s: &State) { pub fn init(i: &mut CoreIsolate, s: &State) {
i.register_op( i.register_op(
"op_apply_source_map", "op_apply_source_map",
s.stateful_json_op(op_apply_source_map), s.stateful_json_op(op_apply_source_map),

View file

@ -4,14 +4,15 @@ use super::io::{StreamResource, StreamResourceHolder};
use crate::http_util::{create_http_client, HttpBody}; use crate::http_util::{create_http_client, HttpBody};
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::state::State; use crate::state::State;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
use futures::future::FutureExt; use futures::future::FutureExt;
use http::header::HeaderName; use http::header::HeaderName;
use http::header::HeaderValue; use http::header::HeaderValue;
use http::Method; use http::Method;
use std::convert::From; 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)); i.register_op("op_fetch", s.stateful_json_op2(op_fetch));
} }
@ -23,7 +24,7 @@ struct FetchArgs {
} }
pub fn op_fetch( pub fn op_fetch(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
data: Option<ZeroCopyBuf>, data: Option<ZeroCopyBuf>,

View file

@ -7,7 +7,7 @@ use crate::fs::resolve_from_cwd;
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::ops::dispatch_json::JsonResult; use crate::ops::dispatch_json::JsonResult;
use crate::state::State; use crate::state::State;
use deno_core::Isolate; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf; use deno_core::ZeroCopyBuf;
use futures::future::FutureExt; use futures::future::FutureExt;
use std::convert::From; use std::convert::From;
@ -17,7 +17,7 @@ use std::time::UNIX_EPOCH;
use rand::{thread_rng, Rng}; 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_open", s.stateful_json_op2(op_open));
i.register_op("op_seek", s.stateful_json_op2(op_seek)); i.register_op("op_seek", s.stateful_json_op2(op_seek));
i.register_op("op_umask", s.stateful_json_op(op_umask)); i.register_op("op_umask", s.stateful_json_op(op_umask));
@ -68,7 +68,7 @@ struct OpenOptions {
} }
fn op_open( fn op_open(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -205,7 +205,7 @@ struct SeekArgs {
} }
fn op_seek( fn op_seek(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,

View file

@ -2,7 +2,9 @@
use super::dispatch_json::{Deserialize, JsonOp, Value}; use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::state::State; 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::poll_fn;
use futures::future::FutureExt; use futures::future::FutureExt;
use notify::event::Event as NotifyEvent; use notify::event::Event as NotifyEvent;
@ -16,7 +18,7 @@ use std::convert::From;
use std::path::PathBuf; use std::path::PathBuf;
use tokio::sync::mpsc; 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_open", s.stateful_json_op2(op_fs_events_open));
i.register_op("op_fs_events_poll", s.stateful_json_op2(op_fs_events_poll)); i.register_op("op_fs_events_poll", s.stateful_json_op2(op_fs_events_poll));
} }
@ -60,7 +62,7 @@ impl From<NotifyEvent> for FsEvent {
} }
pub fn op_fs_events_open( pub fn op_fs_events_open(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -98,7 +100,7 @@ pub fn op_fs_events_open(
} }
pub fn op_fs_events_poll( pub fn op_fs_events_poll(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,

View file

@ -2,7 +2,9 @@ use super::dispatch_minimal::MinimalOp;
use crate::http_util::HttpBody; use crate::http_util::HttpBody;
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::state::State; 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::poll_fn;
use futures::future::FutureExt; use futures::future::FutureExt;
use futures::ready; 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_read", s.stateful_minimal_op2(op_read));
i.register_op("op_write", s.stateful_minimal_op2(op_write)); i.register_op("op_write", s.stateful_minimal_op2(op_write));
} }
@ -204,7 +206,7 @@ impl DenoAsyncRead for StreamResource {
} }
pub fn op_read( pub fn op_read(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
is_sync: bool, is_sync: bool,
rid: i32, rid: i32,
@ -328,7 +330,7 @@ impl DenoAsyncWrite for StreamResource {
} }
pub fn op_write( pub fn op_write(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
is_sync: bool, is_sync: bool,
rid: i32, rid: i32,

View file

@ -4,7 +4,9 @@ use super::io::{StreamResource, StreamResourceHolder};
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::resolve_addr::resolve_addr; use crate::resolve_addr::resolve_addr;
use crate::state::State; 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::poll_fn;
use futures::future::FutureExt; use futures::future::FutureExt;
use std::convert::From; use std::convert::From;
@ -19,7 +21,7 @@ use tokio::net::UdpSocket;
#[cfg(unix)] #[cfg(unix)]
use super::net_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_accept", s.stateful_json_op2(op_accept));
i.register_op("op_connect", s.stateful_json_op2(op_connect)); i.register_op("op_connect", s.stateful_json_op2(op_connect));
i.register_op("op_shutdown", s.stateful_json_op2(op_shutdown)); i.register_op("op_shutdown", s.stateful_json_op2(op_shutdown));
@ -35,7 +37,7 @@ struct AcceptArgs {
} }
fn accept_tcp( fn accept_tcp(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
args: AcceptArgs, args: AcceptArgs,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError> { ) -> Result<JsonOp, OpError> {
@ -95,7 +97,7 @@ fn accept_tcp(
} }
fn op_accept( fn op_accept(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
zero_copy: Option<ZeroCopyBuf>, zero_copy: Option<ZeroCopyBuf>,
@ -119,7 +121,7 @@ struct ReceiveArgs {
} }
fn receive_udp( fn receive_udp(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: ReceiveArgs, args: ReceiveArgs,
zero_copy: Option<ZeroCopyBuf>, zero_copy: Option<ZeroCopyBuf>,
@ -156,7 +158,7 @@ fn receive_udp(
} }
fn op_receive( fn op_receive(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
zero_copy: Option<ZeroCopyBuf>, zero_copy: Option<ZeroCopyBuf>,
@ -185,7 +187,7 @@ struct SendArgs {
} }
fn op_send( fn op_send(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
zero_copy: Option<ZeroCopyBuf>, zero_copy: Option<ZeroCopyBuf>,
@ -254,7 +256,7 @@ struct ConnectArgs {
} }
fn op_connect( fn op_connect(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -339,7 +341,7 @@ struct ShutdownArgs {
} }
fn op_shutdown( fn op_shutdown(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -479,7 +481,7 @@ fn listen_udp(
} }
fn op_listen( fn op_listen(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,

View file

@ -1,9 +1,10 @@
use super::dispatch_json::{Deserialize, JsonOp}; use super::dispatch_json::{Deserialize, JsonOp};
use super::io::{StreamResource, StreamResourceHolder}; use super::io::{StreamResource, StreamResourceHolder};
use crate::op_error::OpError; use crate::op_error::OpError;
use deno_core::CoreIsolate;
use deno_core::ResourceTable;
use deno_core::ZeroCopyBuf;
use futures::future::FutureExt; use futures::future::FutureExt;
use deno_core::*;
use std::fs::remove_file; use std::fs::remove_file;
use std::os::unix; use std::os::unix;
pub use std::path::Path; pub use std::path::Path;
@ -26,7 +27,7 @@ pub struct UnixListenArgs {
} }
pub fn accept_unix( pub fn accept_unix(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
rid: u32, rid: u32,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError> { ) -> Result<JsonOp, OpError> {
@ -77,7 +78,7 @@ pub fn accept_unix(
} }
pub fn receive_unix_packet( pub fn receive_unix_packet(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
rid: u32, rid: u32,
zero_copy: Option<ZeroCopyBuf>, zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError> { ) -> Result<JsonOp, OpError> {

View file

@ -2,13 +2,14 @@
use super::dispatch_json::{Deserialize, JsonOp, Value}; use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::state::State; use crate::state::State;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
use std::collections::HashMap; use std::collections::HashMap;
use std::env; use std::env;
use std::io::{Error, ErrorKind}; use std::io::{Error, ErrorKind};
use url::Url; 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_exit", s.stateful_json_op(op_exit));
i.register_op("op_env", s.stateful_json_op(op_env)); i.register_op("op_env", s.stateful_json_op(op_env));
i.register_op("op_exec_path", s.stateful_json_op(op_exec_path)); i.register_op("op_exec_path", s.stateful_json_op(op_exec_path));

View file

@ -3,10 +3,11 @@ use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::fs as deno_fs; use crate::fs as deno_fs;
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::state::State; use crate::state::State;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
use std::path::Path; use std::path::Path;
pub fn init(i: &mut Isolate, s: &State) { pub fn init(i: &mut CoreIsolate, s: &State) {
i.register_op( i.register_op(
"op_query_permission", "op_query_permission",
s.stateful_json_op(op_query_permission), s.stateful_json_op(op_query_permission),

View file

@ -3,15 +3,15 @@ use crate::fs as deno_fs;
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::ops::json_op; use crate::ops::json_op;
use crate::state::State; use crate::state::State;
use deno_core::Isolate; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf; use deno_core::ZeroCopyBuf;
use dlopen::symbor::Library; use dlopen::symbor::Library;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::path::Path; 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( i.register_op(
"op_open_plugin", "op_open_plugin",
s.core_op(json_op(s.stateful_op2(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( pub fn op_open_plugin(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,

View file

@ -4,7 +4,9 @@ use super::io::{std_file_resource, StreamResource, StreamResourceHolder};
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::signal::kill; use crate::signal::kill;
use crate::state::State; 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::poll_fn;
use futures::future::FutureExt; use futures::future::FutureExt;
use futures::TryFutureExt; use futures::TryFutureExt;
@ -14,7 +16,7 @@ use tokio::process::Command;
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::process::ExitStatusExt; 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", s.stateful_json_op2(op_run));
i.register_op("op_run_status", s.stateful_json_op2(op_run_status)); i.register_op("op_run_status", s.stateful_json_op2(op_run_status));
i.register_op("op_kill", s.stateful_json_op(op_kill)); i.register_op("op_kill", s.stateful_json_op(op_kill));
@ -58,7 +60,7 @@ struct ChildResource {
} }
fn op_run( fn op_run(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -172,7 +174,7 @@ struct RunStatusArgs {
} }
fn op_run_status( fn op_run_status(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,

View file

@ -2,11 +2,12 @@
use super::dispatch_json::{JsonOp, Value}; use super::dispatch_json::{JsonOp, Value};
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::state::State; use crate::state::State;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
use rand::thread_rng; use rand::thread_rng;
use rand::Rng; use rand::Rng;
pub fn init(i: &mut Isolate, s: &State) { pub fn init(i: &mut CoreIsolate, s: &State) {
i.register_op( i.register_op(
"op_get_random_values", "op_get_random_values",
s.stateful_json_op(op_get_random_values), s.stateful_json_op(op_get_random_values),

View file

@ -4,11 +4,12 @@ use crate::op_error::OpError;
use crate::repl; use crate::repl;
use crate::repl::Repl; use crate::repl::Repl;
use crate::state::State; use crate::state::State;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; 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_start", s.stateful_json_op2(op_repl_start));
i.register_op("op_repl_readline", s.stateful_json_op2(op_repl_readline)); i.register_op("op_repl_readline", s.stateful_json_op2(op_repl_readline));
} }
@ -22,7 +23,7 @@ struct ReplStartArgs {
} }
fn op_repl_start( fn op_repl_start(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -45,7 +46,7 @@ struct ReplReadlineArgs {
} }
fn op_repl_readline( fn op_repl_readline(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,

View file

@ -2,15 +2,16 @@
use super::dispatch_json::{Deserialize, JsonOp, Value}; use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::state::State; 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_resources", s.stateful_json_op2(op_resources));
i.register_op("op_close", s.stateful_json_op2(op_close)); i.register_op("op_close", s.stateful_json_op2(op_close));
} }
fn op_resources( fn op_resources(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
_args: Value, _args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -21,7 +22,7 @@ fn op_resources(
/// op_close removes a resource from the resource table. /// op_close removes a resource from the resource table.
fn op_close( fn op_close(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,

View file

@ -5,7 +5,8 @@ use crate::op_error::OpError;
use crate::state::State; use crate::state::State;
use crate::version; use crate::version;
use crate::DenoSubcommand; use crate::DenoSubcommand;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
use std::env; use std::env;
/// BUILD_OS and BUILD_ARCH match the values in Deno.build. See js/build.ts. /// 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")] #[cfg(target_arch = "x86_64")]
static BUILD_ARCH: &str = "x64"; 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_start", s.stateful_json_op(op_start));
i.register_op("op_metrics", s.stateful_json_op(op_metrics)); i.register_op("op_metrics", s.stateful_json_op(op_metrics));
} }

View file

@ -4,10 +4,11 @@ use crate::compilers::runtime_compile;
use crate::compilers::runtime_transpile; use crate::compilers::runtime_transpile;
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::state::State; use crate::state::State;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
use std::collections::HashMap; 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_compile", s.stateful_json_op(op_compile));
i.register_op("op_transpile", s.stateful_json_op(op_transpile)); i.register_op("op_transpile", s.stateful_json_op(op_transpile));
} }

View file

@ -2,7 +2,8 @@
use super::dispatch_json::{JsonOp, Value}; use super::dispatch_json::{JsonOp, Value};
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::state::State; use crate::state::State;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
#[cfg(unix)] #[cfg(unix)]
use super::dispatch_json::Deserialize; use super::dispatch_json::Deserialize;
@ -13,7 +14,7 @@ use std::task::Waker;
#[cfg(unix)] #[cfg(unix)]
use tokio::signal::unix::{signal, Signal, SignalKind}; 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_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_unbind", s.stateful_json_op2(op_signal_unbind));
i.register_op("op_signal_poll", s.stateful_json_op2(op_signal_poll)); i.register_op("op_signal_poll", s.stateful_json_op2(op_signal_poll));
@ -38,7 +39,7 @@ struct SignalArgs {
#[cfg(unix)] #[cfg(unix)]
fn op_signal_bind( fn op_signal_bind(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -59,7 +60,7 @@ fn op_signal_bind(
#[cfg(unix)] #[cfg(unix)]
fn op_signal_poll( fn op_signal_poll(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -85,7 +86,7 @@ fn op_signal_poll(
#[cfg(unix)] #[cfg(unix)]
pub fn op_signal_unbind( pub fn op_signal_unbind(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -109,7 +110,7 @@ pub fn op_signal_unbind(
#[cfg(not(unix))] #[cfg(not(unix))]
pub fn op_signal_bind( pub fn op_signal_bind(
_isolate: &mut deno_core::Isolate, _isolate: &mut CoreIsolate,
_state: &State, _state: &State,
_args: Value, _args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -119,7 +120,7 @@ pub fn op_signal_bind(
#[cfg(not(unix))] #[cfg(not(unix))]
fn op_signal_unbind( fn op_signal_unbind(
_isolate: &mut deno_core::Isolate, _isolate: &mut CoreIsolate,
_state: &State, _state: &State,
_args: Value, _args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -129,7 +130,7 @@ fn op_signal_unbind(
#[cfg(not(unix))] #[cfg(not(unix))]
fn op_signal_poll( fn op_signal_poll(
_isolate: &mut deno_core::Isolate, _isolate: &mut CoreIsolate,
_state: &State, _state: &State,
_args: Value, _args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,

View file

@ -2,12 +2,13 @@
use super::dispatch_json::{Deserialize, JsonOp, Value}; use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::state::State; use crate::state::State;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
use futures::future::FutureExt; use futures::future::FutureExt;
use std::time::Duration; use std::time::Duration;
use std::time::Instant; use std::time::Instant;
pub fn init(i: &mut Isolate, s: &State) { pub fn init(i: &mut CoreIsolate, s: &State) {
i.register_op( i.register_op(
"op_global_timer_stop", "op_global_timer_stop",
s.stateful_json_op(op_global_timer_stop), s.stateful_json_op(op_global_timer_stop),

View file

@ -4,7 +4,8 @@ use super::io::{StreamResource, StreamResourceHolder};
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::resolve_addr::resolve_addr; use crate::resolve_addr::resolve_addr;
use crate::state::State; use crate::state::State;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
use futures::future::poll_fn; use futures::future::poll_fn;
use futures::future::FutureExt; use futures::future::FutureExt;
use std::convert::From; use std::convert::From;
@ -27,7 +28,7 @@ use tokio_rustls::{
}; };
use webpki::DNSNameRef; 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_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_connect_tls", s.stateful_json_op2(op_connect_tls));
i.register_op("op_listen_tls", s.stateful_json_op2(op_listen_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( pub fn op_start_tls(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -125,7 +126,7 @@ pub fn op_start_tls(
} }
pub fn op_connect_tls( pub fn op_connect_tls(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -301,7 +302,7 @@ struct ListenTlsArgs {
} }
fn op_listen_tls( fn op_listen_tls(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
state: &State, state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -351,7 +352,7 @@ struct AcceptTlsArgs {
} }
fn op_accept_tls( fn op_accept_tls(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,

View file

@ -3,7 +3,8 @@ use super::io::std_file_resource;
use super::io::{StreamResource, StreamResourceHolder}; use super::io::{StreamResource, StreamResourceHolder};
use crate::op_error::OpError; use crate::op_error::OpError;
use crate::state::State; use crate::state::State;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
#[cfg(unix)] #[cfg(unix)]
use nix::sys::termios; use nix::sys::termios;
use serde_derive::Deserialize; use serde_derive::Deserialize;
@ -33,7 +34,7 @@ fn get_windows_handle(
Ok(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_set_raw", s.stateful_json_op2(op_set_raw));
i.register_op("op_isatty", s.stateful_json_op2(op_isatty)); i.register_op("op_isatty", s.stateful_json_op2(op_isatty));
} }
@ -45,7 +46,7 @@ struct SetRawArgs {
} }
pub fn op_set_raw( pub fn op_set_raw(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,
@ -213,7 +214,7 @@ struct IsattyArgs {
} }
pub fn op_isatty( pub fn op_isatty(
isolate: &mut deno_core::Isolate, isolate: &mut CoreIsolate,
_state: &State, _state: &State,
args: Value, args: Value,
_zero_copy: Option<ZeroCopyBuf>, _zero_copy: Option<ZeroCopyBuf>,

View file

@ -5,18 +5,15 @@ use crate::ops::json_op;
use crate::state::State; use crate::state::State;
use crate::web_worker::WebWorkerHandle; use crate::web_worker::WebWorkerHandle;
use crate::worker::WorkerEvent; use crate::worker::WorkerEvent;
use deno_core::*; use deno_core::CoreIsolate;
use deno_core::ZeroCopyBuf;
use futures::channel::mpsc; use futures::channel::mpsc;
use std::convert::From; use std::convert::From;
pub fn web_worker_op<D>( pub fn web_worker_op<D>(
sender: mpsc::Sender<WorkerEvent>, sender: mpsc::Sender<WorkerEvent>,
dispatcher: D, dispatcher: D,
) -> impl Fn( ) -> impl Fn(&mut CoreIsolate, Value, Option<ZeroCopyBuf>) -> Result<JsonOp, OpError>
&mut deno_core::Isolate,
Value,
Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError>
where where
D: Fn( D: Fn(
&mpsc::Sender<WorkerEvent>, &mpsc::Sender<WorkerEvent>,
@ -24,7 +21,7 @@ where
Option<ZeroCopyBuf>, Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError>, ) -> Result<JsonOp, OpError>,
{ {
move |_isolate: &mut deno_core::Isolate, move |_isolate: &mut CoreIsolate,
args: Value, args: Value,
zero_copy: Option<ZeroCopyBuf>| zero_copy: Option<ZeroCopyBuf>|
-> Result<JsonOp, OpError> { dispatcher(&sender, args, zero_copy) } -> Result<JsonOp, OpError> { dispatcher(&sender, args, zero_copy) }
@ -34,11 +31,7 @@ pub fn web_worker_op2<D>(
handle: WebWorkerHandle, handle: WebWorkerHandle,
sender: mpsc::Sender<WorkerEvent>, sender: mpsc::Sender<WorkerEvent>,
dispatcher: D, dispatcher: D,
) -> impl Fn( ) -> impl Fn(&mut CoreIsolate, Value, Option<ZeroCopyBuf>) -> Result<JsonOp, OpError>
&mut deno_core::Isolate,
Value,
Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError>
where where
D: Fn( D: Fn(
WebWorkerHandle, WebWorkerHandle,
@ -47,7 +40,7 @@ where
Option<ZeroCopyBuf>, Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError>, ) -> Result<JsonOp, OpError>,
{ {
move |_isolate: &mut deno_core::Isolate, move |_isolate: &mut CoreIsolate,
args: Value, args: Value,
zero_copy: Option<ZeroCopyBuf>| zero_copy: Option<ZeroCopyBuf>|
-> Result<JsonOp, OpError> { -> Result<JsonOp, OpError> {
@ -56,7 +49,7 @@ where
} }
pub fn init( pub fn init(
i: &mut Isolate, i: &mut CoreIsolate,
s: &State, s: &State,
sender: &mpsc::Sender<WorkerEvent>, sender: &mpsc::Sender<WorkerEvent>,
handle: WebWorkerHandle, handle: WebWorkerHandle,

View file

@ -11,12 +11,15 @@ use crate::tokio_util::create_basic_runtime;
use crate::web_worker::WebWorker; use crate::web_worker::WebWorker;
use crate::web_worker::WebWorkerHandle; use crate::web_worker::WebWorkerHandle;
use crate::worker::WorkerEvent; 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 futures::future::FutureExt;
use std::convert::From; use std::convert::From;
use std::thread::JoinHandle; 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_create_worker", s.stateful_json_op(op_create_worker));
i.register_op( i.register_op(
"op_host_terminate_worker", "op_host_terminate_worker",

View file

@ -71,7 +71,7 @@ impl State {
pub fn stateful_json_op<D>( pub fn stateful_json_op<D>(
&self, &self,
dispatcher: D, dispatcher: D,
) -> impl Fn(&mut deno_core::Isolate, &[u8], Option<ZeroCopyBuf>) -> Op ) -> impl Fn(&mut deno_core::CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op
where where
D: Fn(&State, Value, Option<ZeroCopyBuf>) -> Result<JsonOp, OpError>, D: Fn(&State, Value, Option<ZeroCopyBuf>) -> Result<JsonOp, OpError>,
{ {
@ -82,10 +82,10 @@ impl State {
pub fn stateful_json_op2<D>( pub fn stateful_json_op2<D>(
&self, &self,
dispatcher: D, dispatcher: D,
) -> impl Fn(&mut deno_core::Isolate, &[u8], Option<ZeroCopyBuf>) -> Op ) -> impl Fn(&mut deno_core::CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op
where where
D: Fn( D: Fn(
&mut deno_core::Isolate, &mut deno_core::CoreIsolate,
&State, &State,
Value, Value,
Option<ZeroCopyBuf>, Option<ZeroCopyBuf>,
@ -101,13 +101,13 @@ impl State {
pub fn core_op<D>( pub fn core_op<D>(
&self, &self,
dispatcher: D, dispatcher: D,
) -> impl Fn(&mut deno_core::Isolate, &[u8], Option<ZeroCopyBuf>) -> Op ) -> impl Fn(&mut deno_core::CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op
where where
D: Fn(&mut deno_core::Isolate, &[u8], Option<ZeroCopyBuf>) -> Op, D: Fn(&mut deno_core::CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op,
{ {
let state = self.clone(); let state = self.clone();
move |isolate: &mut deno_core::Isolate, move |isolate: &mut deno_core::CoreIsolate,
control: &[u8], control: &[u8],
zero_copy: Option<ZeroCopyBuf>| zero_copy: Option<ZeroCopyBuf>|
-> Op { -> Op {
@ -161,10 +161,10 @@ impl State {
pub fn stateful_minimal_op2<D>( pub fn stateful_minimal_op2<D>(
&self, &self,
dispatcher: D, dispatcher: D,
) -> impl Fn(&mut deno_core::Isolate, &[u8], Option<ZeroCopyBuf>) -> Op ) -> impl Fn(&mut deno_core::CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op
where where
D: Fn( D: Fn(
&mut deno_core::Isolate, &mut deno_core::CoreIsolate,
&State, &State,
bool, bool,
i32, i32,
@ -173,7 +173,7 @@ impl State {
{ {
let state = self.clone(); let state = self.clone();
self.core_op(crate::ops::minimal_op( self.core_op(crate::ops::minimal_op(
move |isolate: &mut deno_core::Isolate, move |isolate: &mut deno_core::CoreIsolate,
is_sync: bool, is_sync: bool,
rid: i32, rid: i32,
zero_copy: Option<ZeroCopyBuf>| zero_copy: Option<ZeroCopyBuf>|
@ -186,13 +186,13 @@ impl State {
/// This is a special function that provides `state` argument to dispatcher. /// This is a special function that provides `state` argument to dispatcher.
/// ///
/// NOTE: This only works with JSON 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. /// ops require `state` argument.
pub fn stateful_op<D>( pub fn stateful_op<D>(
&self, &self,
dispatcher: D, dispatcher: D,
) -> impl Fn( ) -> impl Fn(
&mut deno_core::Isolate, &mut deno_core::CoreIsolate,
Value, Value,
Option<ZeroCopyBuf>, Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError> ) -> Result<JsonOp, OpError>
@ -200,7 +200,7 @@ impl State {
D: Fn(&State, Value, Option<ZeroCopyBuf>) -> Result<JsonOp, OpError>, D: Fn(&State, Value, Option<ZeroCopyBuf>) -> Result<JsonOp, OpError>,
{ {
let state = self.clone(); let state = self.clone();
move |_isolate: &mut deno_core::Isolate, move |_isolate: &mut deno_core::CoreIsolate,
args: Value, args: Value,
zero_copy: Option<ZeroCopyBuf>| zero_copy: Option<ZeroCopyBuf>|
-> Result<JsonOp, OpError> { dispatcher(&state, args, zero_copy) } -> Result<JsonOp, OpError> { dispatcher(&state, args, zero_copy) }
@ -210,20 +210,20 @@ impl State {
&self, &self,
dispatcher: D, dispatcher: D,
) -> impl Fn( ) -> impl Fn(
&mut deno_core::Isolate, &mut deno_core::CoreIsolate,
Value, Value,
Option<ZeroCopyBuf>, Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError> ) -> Result<JsonOp, OpError>
where where
D: Fn( D: Fn(
&mut deno_core::Isolate, &mut deno_core::CoreIsolate,
&State, &State,
Value, Value,
Option<ZeroCopyBuf>, Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError>, ) -> Result<JsonOp, OpError>,
{ {
let state = self.clone(); let state = self.clone();
move |isolate: &mut deno_core::Isolate, move |isolate: &mut deno_core::CoreIsolate,
args: Value, args: Value,
zero_copy: Option<ZeroCopyBuf>| zero_copy: Option<ZeroCopyBuf>|
-> Result<JsonOp, OpError> { -> Result<JsonOp, OpError> {

View file

@ -1,7 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use crate::es_isolate::EsIsolate; use crate::es_isolate::EsIsolate;
use crate::isolate::Isolate; use crate::isolate::CoreIsolate;
use crate::isolate::ZeroCopyBuf; use crate::isolate::ZeroCopyBuf;
use crate::js_errors::JSError; 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 mut hs = v8::EscapableHandleScope::new(cbs.enter());
let scope = hs.enter(); let scope = hs.enter();
let isolate = scope.isolate(); let isolate = scope.isolate();
let deno_isolate: &mut EsIsolate = let core_isolate: &mut EsIsolate =
unsafe { &mut *(isolate.get_data(1) as *mut EsIsolate) }; unsafe { &mut *(isolate.get_data(1) as *mut EsIsolate) };
// NOTE(bartlomieju): will crash for non-UTF-8 specifier // 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(); let mut resolver_handle = v8::Global::new();
resolver_handle.set(scope, resolver); resolver_handle.set(scope, resolver);
let import_id = deno_isolate.next_dyn_import_id; let import_id = core_isolate.next_dyn_import_id;
deno_isolate.next_dyn_import_id += 1; core_isolate.next_dyn_import_id += 1;
deno_isolate core_isolate
.dyn_import_map .dyn_import_map
.insert(import_id, resolver_handle); .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) &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 mut hs = v8::HandleScope::new(cbs.enter());
let scope = hs.enter(); let scope = hs.enter();
let isolate = scope.isolate(); let isolate = scope.isolate();
let deno_isolate: &mut EsIsolate = let core_isolate: &mut EsIsolate =
unsafe { &mut *(isolate.get_data(1) as *mut EsIsolate) }; unsafe { &mut *(isolate.get_data(1) as *mut EsIsolate) };
let id = module.get_identity_hash(); let id = module.get_identity_hash();
assert_ne!(id, 0); 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( meta.create_data_property(
context, context,
@ -322,10 +322,10 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) {
let mut hs = v8::HandleScope::new(cbs.enter()); let mut hs = v8::HandleScope::new(cbs.enter());
let scope = hs.enter(); let scope = hs.enter();
let deno_isolate: &mut Isolate = let core_isolate: &mut CoreIsolate =
unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; 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 mut cs = v8::ContextScope::new(scope, context);
let scope = cs.enter(); let scope = cs.enter();
@ -337,13 +337,13 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) {
let error = message.get_value(); let error = message.get_value();
let mut error_global = v8::Global::<v8::Value>::new(); let mut error_global = v8::Global::<v8::Value>::new();
error_global.set(scope, error); error_global.set(scope, error);
deno_isolate core_isolate
.pending_promise_exceptions .pending_promise_exceptions
.insert(promise_id, error_global); .insert(promise_id, error_global);
} }
v8::PromiseRejectEvent::PromiseHandlerAddedAfterReject => { v8::PromiseRejectEvent::PromiseHandlerAddedAfterReject => {
if let Some(mut handle) = if let Some(mut handle) =
deno_isolate.pending_promise_exceptions.remove(&promise_id) core_isolate.pending_promise_exceptions.remove(&promise_id)
{ {
handle.reset(scope); handle.reset(scope);
} }
@ -417,17 +417,17 @@ fn recv(
args: v8::FunctionCallbackArguments, args: v8::FunctionCallbackArguments,
_rv: v8::ReturnValue, _rv: v8::ReturnValue,
) { ) {
let deno_isolate: &mut Isolate = let core_isolate: &mut CoreIsolate =
unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; 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(); let msg = v8::String::new(scope, "Deno.core.recv already called.").unwrap();
scope.isolate().throw_exception(msg.into()); scope.isolate().throw_exception(msg.into());
return; return;
} }
let recv_fn = v8::Local::<v8::Function>::try_from(args.get(0)).unwrap(); let recv_fn = v8::Local::<v8::Function>::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( fn send(
@ -435,9 +435,9 @@ fn send(
args: v8::FunctionCallbackArguments, args: v8::FunctionCallbackArguments,
mut rv: v8::ReturnValue, mut rv: v8::ReturnValue,
) { ) {
let deno_isolate: &mut Isolate = let core_isolate: &mut CoreIsolate =
unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) };
assert!(!deno_isolate.global_context.is_empty()); assert!(!core_isolate.global_context.is_empty());
let op_id = match v8::Local::<v8::Uint32>::try_from(args.get(0)) { let op_id = match v8::Local::<v8::Uint32>::try_from(args.get(0)) {
Ok(op_id) => op_id.value() as u32, 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 // If response is empty then it's either async op or exception was thrown
let maybe_response = 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 { if let Some(response) = maybe_response {
// Synchronous response. // Synchronous response.
@ -488,10 +488,10 @@ fn set_macrotask_callback(
args: v8::FunctionCallbackArguments, args: v8::FunctionCallbackArguments,
_rv: v8::ReturnValue, _rv: v8::ReturnValue,
) { ) {
let deno_isolate: &mut Isolate = let core_isolate: &mut CoreIsolate =
unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; 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 = let msg =
v8::String::new(scope, "Deno.core.setMacrotaskCallback already called.") v8::String::new(scope, "Deno.core.setMacrotaskCallback already called.")
.unwrap(); .unwrap();
@ -501,7 +501,7 @@ fn set_macrotask_callback(
let macrotask_cb_fn = let macrotask_cb_fn =
v8::Local::<v8::Function>::try_from(args.get(0)).unwrap(); v8::Local::<v8::Function>::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( fn eval_context(
@ -509,10 +509,10 @@ fn eval_context(
args: v8::FunctionCallbackArguments, args: v8::FunctionCallbackArguments,
mut rv: v8::ReturnValue, mut rv: v8::ReturnValue,
) { ) {
let deno_isolate: &mut Isolate = let core_isolate: &mut CoreIsolate =
unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) };
assert!(!deno_isolate.global_context.is_empty()); assert!(!core_isolate.global_context.is_empty());
let context = deno_isolate.global_context.get(scope).unwrap(); let context = core_isolate.global_context.get(scope).unwrap();
let source = match v8::Local::<v8::String>::try_from(args.get(0)) { let source = match v8::Local::<v8::String>::try_from(args.get(0)) {
Ok(s) => s, Ok(s) => s,
@ -645,10 +645,10 @@ fn format_error(
args: v8::FunctionCallbackArguments, args: v8::FunctionCallbackArguments,
mut rv: v8::ReturnValue, mut rv: v8::ReturnValue,
) { ) {
let deno_isolate: &mut Isolate = let core_isolate: &mut CoreIsolate =
unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) };
let e = JSError::from_v8_exception(scope, args.get(0)); 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 = e.to_string();
let e = v8::String::new(scope, &e).unwrap(); let e = v8::String::new(scope, &e).unwrap();
rv.set(e.into()) rv.set(e.into())
@ -736,19 +736,19 @@ fn shared_getter(
_args: v8::PropertyCallbackArguments, _args: v8::PropertyCallbackArguments,
mut rv: v8::ReturnValue, mut rv: v8::ReturnValue,
) { ) {
let deno_isolate: &mut Isolate = let core_isolate: &mut CoreIsolate =
unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) };
// Lazily initialize the persistent external ArrayBuffer. // 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( let ab = v8::SharedArrayBuffer::with_backing_store(
scope, 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()); rv.set(shared_ab.into());
} }
@ -761,11 +761,11 @@ pub fn module_resolve_callback<'s>(
let mut scope = v8::EscapableHandleScope::new(scope.enter()); let mut scope = v8::EscapableHandleScope::new(scope.enter());
let scope = 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) }; unsafe { &mut *(scope.isolate().get_data(1) as *mut EsIsolate) };
let referrer_id = referrer.get_identity_hash(); let referrer_id = referrer.get_identity_hash();
let referrer_name = deno_isolate let referrer_name = core_isolate
.modules .modules
.get_info(referrer_id) .get_info(referrer_id)
.expect("ModuleInfo not found") .expect("ModuleInfo not found")
@ -780,8 +780,8 @@ pub fn module_resolve_callback<'s>(
let req_str = req.to_rust_string_lossy(scope); let req_str = req.to_rust_string_lossy(scope);
if req_str == specifier_str { if req_str == specifier_str {
let id = deno_isolate.module_resolve_cb(&req_str, referrer_id); let id = core_isolate.module_resolve_cb(&req_str, referrer_id);
let maybe_info = deno_isolate.modules.get_info(id); let maybe_info = core_isolate.modules.get_info(id);
if maybe_info.is_none() { if maybe_info.is_none() {
let msg = format!( let msg = format!(
@ -812,10 +812,10 @@ fn get_promise_details(
args: v8::FunctionCallbackArguments, args: v8::FunctionCallbackArguments,
mut rv: v8::ReturnValue, mut rv: v8::ReturnValue,
) { ) {
let deno_isolate: &mut Isolate = let core_isolate: &mut CoreIsolate =
unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) }; unsafe { &mut *(scope.isolate().get_data(0) as *mut CoreIsolate) };
assert!(!deno_isolate.global_context.is_empty()); assert!(!core_isolate.global_context.is_empty());
let context = deno_isolate.global_context.get(scope).unwrap(); let context = core_isolate.global_context.get(scope).unwrap();
let promise = match v8::Local::<v8::Promise>::try_from(args.get(0)) { let promise = match v8::Local::<v8::Promise>::try_from(args.get(0)) {
Ok(val) => val, Ok(val) => val,

View file

@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // 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. // supports asynchronous loading and executution of ES Modules.
// The isolate.rs should never depend on this module. // 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::attach_handle_to_error;
use crate::isolate::exception_to_err_result; use crate::isolate::exception_to_err_result;
use crate::isolate::Isolate; use crate::isolate::CoreIsolate;
use crate::isolate::StartupData; use crate::isolate::StartupData;
use crate::module_specifier::ModuleSpecifier; use crate::module_specifier::ModuleSpecifier;
use crate::modules::LoadState; use crate::modules::LoadState;
@ -39,14 +39,14 @@ use crate::modules::RecursiveModuleLoad;
pub type ModuleId = i32; pub type ModuleId = i32;
pub type DynImportId = 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. /// and execution of ES Modules.
/// ///
/// Creating `EsIsolate` requires to pass `loader` argument /// Creating `EsIsolate` requires to pass `loader` argument
/// that implements `ModuleLoader` trait - that way actual resolution and /// that implements `ModuleLoader` trait - that way actual resolution and
/// loading of modules can be customized by the implementor. /// loading of modules can be customized by the implementor.
pub struct EsIsolate { pub struct EsIsolate {
core_isolate: Box<Isolate>, core_isolate: Box<CoreIsolate>,
loader: Rc<dyn ModuleLoader>, loader: Rc<dyn ModuleLoader>,
pub modules: Modules, pub modules: Modules,
pub(crate) next_dyn_import_id: DynImportId, pub(crate) next_dyn_import_id: DynImportId,
@ -58,7 +58,7 @@ pub struct EsIsolate {
} }
impl Deref for EsIsolate { impl Deref for EsIsolate {
type Target = Isolate; type Target = CoreIsolate;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.core_isolate &self.core_isolate
@ -77,7 +77,7 @@ impl EsIsolate {
startup_data: StartupData, startup_data: StartupData,
will_snapshot: bool, will_snapshot: bool,
) -> Box<Self> { ) -> Box<Self> {
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(); let v8_isolate = core_isolate.v8_isolate.as_mut().unwrap();
v8_isolate.set_host_initialize_import_meta_object_callback( 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 /// 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 /// 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> { fn mod_instantiate(&mut self, id: ModuleId) -> Result<(), ErrBox> {
let v8_isolate = self.core_isolate.v8_isolate.as_mut().unwrap(); let v8_isolate = self.core_isolate.v8_isolate.as_mut().unwrap();
let js_error_create_fn = &*self.core_isolate.js_error_create_fn; 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 /// 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 /// 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> { pub fn mod_evaluate(&mut self, id: ModuleId) -> Result<(), ErrBox> {
let core_isolate = &mut self.core_isolate; let core_isolate = &mut self.core_isolate;
let v8_isolate = core_isolate.v8_isolate.as_mut().unwrap(); 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 mut isolate = EsIsolate::new(loader, StartupData::None, false);
let dispatcher = move |_isolate: &mut Isolate, let dispatcher = move |_isolate: &mut CoreIsolate,
control: &[u8], control: &[u8],
_zero_copy: Option<ZeroCopyBuf>| _zero_copy: Option<ZeroCopyBuf>|
-> Op { -> Op {

View file

@ -3,8 +3,12 @@ extern crate derive_deref;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
use deno_core::Isolate as CoreIsolate; use deno_core::CoreIsolate;
use deno_core::*; 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::future::poll_fn;
use futures::prelude::*; use futures::prelude::*;
use futures::task::Context; use futures::task::Context;
@ -111,7 +115,7 @@ impl Isolate {
F: 'static + Fn(State, u32, Option<ZeroCopyBuf>) -> Result<u32, Error>, F: 'static + Fn(State, u32, Option<ZeroCopyBuf>) -> Result<u32, Error>,
{ {
let state = self.state.clone(); let state = self.state.clone();
let core_handler = move |_isolate: &mut deno_core::Isolate, let core_handler = move |_isolate: &mut CoreIsolate,
control_buf: &[u8], control_buf: &[u8],
zero_copy_buf: Option<ZeroCopyBuf>| zero_copy_buf: Option<ZeroCopyBuf>|
-> Op { -> Op {
@ -141,7 +145,7 @@ impl Isolate {
<F::Ok as TryInto<i32>>::Error: Debug, <F::Ok as TryInto<i32>>::Error: Debug,
{ {
let state = self.state.clone(); let state = self.state.clone();
let core_handler = move |_isolate: &mut deno_core::Isolate, let core_handler = move |_isolate: &mut CoreIsolate,
control_buf: &[u8], control_buf: &[u8],
zero_copy_buf: Option<ZeroCopyBuf>| zero_copy_buf: Option<ZeroCopyBuf>|
-> Op { -> Op {

View file

@ -140,15 +140,15 @@ type JSErrorCreateFn = dyn Fn(JSError) -> ErrBox;
type IsolateErrorHandleFn = dyn FnMut(ErrBox) -> Result<(), ErrBox>; type IsolateErrorHandleFn = dyn FnMut(ErrBox) -> Result<(), ErrBox>;
/// A single execution context of JavaScript. Corresponds roughly to the "Web /// 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 /// Worker" concept in the DOM. An CoreIsolate is a Future that can be used with
/// Tokio. The Isolate future complete when there is an error or when all /// Tokio. The CoreIsolate future complete when there is an error or when all
/// pending ops have completed. /// pending ops have completed.
/// ///
/// Ops are created in JavaScript by calling Deno.core.dispatch(), and in Rust /// 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 /// 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. /// as arguments. An async Op corresponds exactly to a Promise in JavaScript.
#[allow(unused)] #[allow(unused)]
pub struct Isolate { pub struct CoreIsolate {
pub v8_isolate: Option<v8::OwnedIsolate>, pub v8_isolate: Option<v8::OwnedIsolate>,
snapshot_creator: Option<v8::SnapshotCreator>, snapshot_creator: Option<v8::SnapshotCreator>,
has_snapshotted: bool, has_snapshotted: bool,
@ -171,7 +171,7 @@ pub struct Isolate {
error_handler: Option<Box<IsolateErrorHandleFn>>, error_handler: Option<Box<IsolateErrorHandleFn>>,
} }
impl Drop for Isolate { impl Drop for CoreIsolate {
fn drop(&mut self) { fn drop(&mut self) {
if let Some(creator) = self.snapshot_creator.take() { if let Some(creator) = self.snapshot_creator.take() {
// TODO(ry): in rusty_v8, `SnapShotCreator::get_owned_isolate()` returns // 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); v8::V8::set_flags_from_command_line(argv);
} }
impl Isolate { impl CoreIsolate {
/// startup_data defines the snapshot or script used at startup to initialize /// startup_data defines the snapshot or script used at startup to initialize
/// the isolate. /// the isolate.
pub fn new(startup_data: StartupData, will_snapshot: bool) -> Box<Self> { pub fn new(startup_data: StartupData, will_snapshot: bool) -> Box<Self> {
@ -233,7 +233,7 @@ impl Isolate {
let mut creator = let mut creator =
v8::SnapshotCreator::new(Some(&bindings::EXTERNAL_REFERENCES)); v8::SnapshotCreator::new(Some(&bindings::EXTERNAL_REFERENCES));
let isolate = unsafe { creator.get_owned_isolate() }; 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 mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
@ -257,7 +257,7 @@ impl Isolate {
}; };
let isolate = v8::Isolate::new(params); 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 mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
@ -314,7 +314,7 @@ impl Isolate {
boxed_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_capture_stack_trace_for_uncaught_exceptions(true, 10);
isolate.set_promise_reject_callback(bindings::promise_reject_callback); isolate.set_promise_reject_callback(bindings::promise_reject_callback);
isolate isolate
@ -327,7 +327,7 @@ impl Isolate {
/// Requires runtime to explicitly ask for op ids before using any of the ops. /// Requires runtime to explicitly ask for op ids before using any of the ops.
pub fn register_op<F>(&mut self, name: &str, op: F) -> OpId pub fn register_op<F>(&mut self, name: &str, op: F) -> OpId
where where
F: Fn(&mut Isolate, &[u8], Option<ZeroCopyBuf>) -> Op + 'static, F: Fn(&mut CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op + 'static,
{ {
self.op_registry.register(name, op) self.op_registry.register(name, op)
} }
@ -400,7 +400,7 @@ impl Isolate {
/// ///
/// ErrBox can be downcast to a type that exposes additional information about /// 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 /// 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( pub fn execute(
&mut self, &mut self,
js_filename: &str, js_filename: &str,
@ -449,7 +449,7 @@ impl Isolate {
/// ///
/// ErrBox can be downcast to a type that exposes additional information about /// 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 /// 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 { pub fn snapshot(&mut self) -> v8::StartupData {
assert!(self.snapshot_creator.is_some()); assert!(self.snapshot_creator.is_some());
@ -473,7 +473,7 @@ impl Isolate {
} }
} }
impl Future for Isolate { impl Future for CoreIsolate {
type Output = Result<(), ErrBox>; type Output = Result<(), ErrBox>;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
@ -727,7 +727,7 @@ pub mod tests {
} }
} }
panic!( panic!(
"Isolate still not ready after polling {} times.", "CoreIsolate still not ready after polling {} times.",
max_poll_count max_poll_count
) )
} }
@ -741,13 +741,13 @@ pub mod tests {
OverflowResAsync, OverflowResAsync,
} }
pub fn setup(mode: Mode) -> (Box<Isolate>, Arc<AtomicUsize>) { pub fn setup(mode: Mode) -> (Box<CoreIsolate>, Arc<AtomicUsize>) {
let dispatch_count = Arc::new(AtomicUsize::new(0)); let dispatch_count = Arc::new(AtomicUsize::new(0));
let dispatch_count_ = dispatch_count.clone(); 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], control: &[u8],
_zero_copy: Option<ZeroCopyBuf>| _zero_copy: Option<ZeroCopyBuf>|
-> Op { -> Op {
@ -1141,7 +1141,7 @@ pub mod tests {
#[test] #[test]
fn syntax_error() { fn syntax_error() {
let mut isolate = Isolate::new(StartupData::None, false); let mut isolate = CoreIsolate::new(StartupData::None, false);
let src = "hocuspocus("; let src = "hocuspocus(";
let r = isolate.execute("i.js", src); let r = isolate.execute("i.js", src);
let e = r.unwrap_err(); let e = r.unwrap_err();
@ -1166,13 +1166,13 @@ pub mod tests {
#[test] #[test]
fn will_snapshot() { fn will_snapshot() {
let 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")); js_check(isolate.execute("a.js", "a = 1 + 2"));
isolate.snapshot() isolate.snapshot()
}; };
let startup_data = StartupData::Snapshot(Snapshot::JustCreated(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')")); js_check(isolate2.execute("check.js", "if (a != 3) throw Error('x')"));
} }
} }

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use crate::Isolate; use crate::CoreIsolate;
use crate::ZeroCopyBuf; use crate::ZeroCopyBuf;
use futures::Future; use futures::Future;
use std::collections::HashMap; use std::collections::HashMap;
@ -22,7 +22,7 @@ pub enum Op {
/// Main type describing op /// Main type describing op
pub type OpDispatcher = pub type OpDispatcher =
dyn Fn(&mut Isolate, &[u8], Option<ZeroCopyBuf>) -> Op + 'static; dyn Fn(&mut CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op + 'static;
#[derive(Default)] #[derive(Default)]
pub struct OpRegistry { pub struct OpRegistry {
@ -43,7 +43,7 @@ impl OpRegistry {
pub fn register<F>(&mut self, name: &str, op: F) -> OpId pub fn register<F>(&mut self, name: &str, op: F) -> OpId
where where
F: Fn(&mut Isolate, &[u8], Option<ZeroCopyBuf>) -> Op + 'static, F: Fn(&mut CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op + 'static,
{ {
let op_id = self.dispatchers.len() as u32; let op_id = self.dispatchers.len() as u32;
@ -86,7 +86,7 @@ fn test_op_registry() {
expected.insert("test".to_string(), 1); expected.insert("test".to_string(), 1);
assert_eq!(op_registry.name_to_id, expected); 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 dispatch = op_registry.get(test_id).unwrap();
let res = dispatch(&mut isolate, &[], None); let res = dispatch(&mut isolate, &[], None);
@ -126,7 +126,7 @@ fn register_op_during_call() {
}; };
assert!(test_id != 0); 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 dispatcher1 = {
let g = op_registry.lock().unwrap(); let g = op_registry.lock().unwrap();

View file

@ -8,8 +8,8 @@ extern crate serde_json;
mod ops; mod ops;
use deno_core::js_check; use deno_core::js_check;
pub use deno_core::v8_set_flags; pub use deno_core::v8_set_flags;
use deno_core::CoreIsolate;
use deno_core::ErrBox; use deno_core::ErrBox;
use deno_core::Isolate;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_core::Op; use deno_core::Op;
use deno_core::StartupData; use deno_core::StartupData;
@ -49,11 +49,11 @@ pub struct TSState {
fn compiler_op<D>( fn compiler_op<D>(
ts_state: Arc<Mutex<TSState>>, ts_state: Arc<Mutex<TSState>>,
dispatcher: D, dispatcher: D,
) -> impl Fn(&mut deno_core::Isolate, &[u8], Option<ZeroCopyBuf>) -> Op ) -> impl Fn(&mut CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op
where where
D: Fn(&mut TSState, &[u8]) -> Op, D: Fn(&mut TSState, &[u8]) -> Op,
{ {
move |_isolate: &mut deno_core::Isolate, move |_isolate: &mut CoreIsolate,
control: &[u8], control: &[u8],
zero_copy_buf: Option<ZeroCopyBuf>| zero_copy_buf: Option<ZeroCopyBuf>|
-> Op { -> Op {
@ -64,7 +64,7 @@ where
} }
pub struct TSIsolate { pub struct TSIsolate {
isolate: Box<Isolate>, isolate: Box<CoreIsolate>,
state: Arc<Mutex<TSState>>, state: Arc<Mutex<TSState>>,
} }
@ -73,7 +73,7 @@ impl TSIsolate {
bundle: bool, bundle: bool,
maybe_extern_crate_modules: Option<ExternCrateModules>, maybe_extern_crate_modules: Option<ExternCrateModules>,
) -> TSIsolate { ) -> 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("assets/typescript.js", TYPESCRIPT_CODE));
js_check(isolate.execute("compiler_main.js", COMPILER_CODE)); js_check(isolate.execute("compiler_main.js", COMPILER_CODE));
@ -196,7 +196,7 @@ fn print_source_code(code: &str) {
/// Create a V8 snapshot. /// Create a V8 snapshot.
pub fn mksnapshot_bundle( pub fn mksnapshot_bundle(
isolate: &mut Isolate, isolate: &mut CoreIsolate,
snapshot_filename: &Path, snapshot_filename: &Path,
bundle_filename: &Path, bundle_filename: &Path,
main_module_name: &str, 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 /// Create a V8 snapshot. This differs from mksnapshot_bundle in that is also
/// runs typescript.js /// runs typescript.js
pub fn mksnapshot_bundle_ts( pub fn mksnapshot_bundle_ts(
isolate: &mut Isolate, isolate: &mut CoreIsolate,
snapshot_filename: &Path, snapshot_filename: &Path,
bundle_filename: &Path, bundle_filename: &Path,
main_module_name: &str, main_module_name: &str,
@ -231,7 +231,7 @@ pub fn mksnapshot_bundle_ts(
} }
fn write_snapshot( fn write_snapshot(
runtime_isolate: &mut Isolate, runtime_isolate: &mut CoreIsolate,
snapshot_filename: &Path, snapshot_filename: &Path,
) -> Result<(), ErrBox> { ) -> Result<(), ErrBox> {
println!("Creating snapshot..."); println!("Creating snapshot...");
@ -326,14 +326,14 @@ pub fn trace_serializer() {
} }
/// Warning: Returns a non-JSON op dispatcher. Must be manually attached to /// Warning: Returns a non-JSON op dispatcher. Must be manually attached to
/// Isolate. /// CoreIsolate.
pub fn op_fetch_asset<S: ::std::hash::BuildHasher>( pub fn op_fetch_asset<S: ::std::hash::BuildHasher>(
custom_assets: HashMap<String, PathBuf, S>, custom_assets: HashMap<String, PathBuf, S>,
) -> impl Fn(&mut deno_core::Isolate, &[u8], Option<ZeroCopyBuf>) -> Op { ) -> impl Fn(&mut CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op {
for (_, path) in custom_assets.iter() { for (_, path) in custom_assets.iter() {
println!("cargo:rerun-if-changed={}", path.display()); println!("cargo:rerun-if-changed={}", path.display());
} }
move |_isolate: &mut deno_core::Isolate, move |_isolate: &mut CoreIsolate,
control: &[u8], control: &[u8],
zero_copy_buf: Option<ZeroCopyBuf>| zero_copy_buf: Option<ZeroCopyBuf>|
-> Op { -> Op {

View file

@ -2,18 +2,19 @@ extern crate deno_core;
extern crate futures; extern crate futures;
use deno_core::Buf; use deno_core::Buf;
use deno_core::CoreIsolate;
use deno_core::Op; use deno_core::Op;
use deno_core::ZeroCopyBuf; use deno_core::ZeroCopyBuf;
use futures::future::FutureExt; use futures::future::FutureExt;
#[no_mangle] #[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("testSync", op_test_sync);
isolate.register_op("testAsync", op_test_async); isolate.register_op("testAsync", op_test_async);
} }
pub fn op_test_sync( pub fn op_test_sync(
_isolate: &mut deno_core::Isolate, _isolate: &mut CoreIsolate,
data: &[u8], data: &[u8],
zero_copy: Option<ZeroCopyBuf>, zero_copy: Option<ZeroCopyBuf>,
) -> Op { ) -> Op {
@ -31,7 +32,7 @@ pub fn op_test_sync(
} }
pub fn op_test_async( pub fn op_test_async(
_isolate: &mut deno_core::Isolate, _isolate: &mut CoreIsolate,
data: &[u8], data: &[u8],
zero_copy: Option<ZeroCopyBuf>, zero_copy: Option<ZeroCopyBuf>,
) -> Op { ) -> Op {