mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
refactor: rename isolate to js_runtime (#7858)
This commit renames occurrences of "isolate" variable name to "js_runtime". This was outstanding debt after renaming deno_core::CoreIsolate to JsRuntime.
This commit is contained in:
parent
83f6def3c6
commit
9b70f2f345
7 changed files with 52 additions and 52 deletions
20
cli/build.rs
20
cli/build.rs
|
@ -10,12 +10,12 @@ use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn create_snapshot(
|
fn create_snapshot(
|
||||||
mut isolate: JsRuntime,
|
mut js_runtime: JsRuntime,
|
||||||
snapshot_path: &Path,
|
snapshot_path: &Path,
|
||||||
files: Vec<PathBuf>,
|
files: Vec<PathBuf>,
|
||||||
) {
|
) {
|
||||||
deno_web::init(&mut isolate);
|
deno_web::init(&mut js_runtime);
|
||||||
deno_fetch::init(&mut isolate);
|
deno_fetch::init(&mut js_runtime);
|
||||||
// TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the
|
// TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the
|
||||||
// workspace root.
|
// workspace root.
|
||||||
let display_root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
|
let display_root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
|
||||||
|
@ -23,7 +23,7 @@ fn create_snapshot(
|
||||||
println!("cargo:rerun-if-changed={}", file.display());
|
println!("cargo:rerun-if-changed={}", file.display());
|
||||||
let display_path = file.strip_prefix(display_root).unwrap();
|
let display_path = file.strip_prefix(display_root).unwrap();
|
||||||
let display_path_str = display_path.display().to_string();
|
let display_path_str = display_path.display().to_string();
|
||||||
isolate
|
js_runtime
|
||||||
.execute(
|
.execute(
|
||||||
&("deno:".to_string() + &display_path_str.replace('\\', "/")),
|
&("deno:".to_string() + &display_path_str.replace('\\', "/")),
|
||||||
&std::fs::read_to_string(&file).unwrap(),
|
&std::fs::read_to_string(&file).unwrap(),
|
||||||
|
@ -31,7 +31,7 @@ fn create_snapshot(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let snapshot = isolate.snapshot();
|
let snapshot = js_runtime.snapshot();
|
||||||
let snapshot_slice: &[u8] = &*snapshot;
|
let snapshot_slice: &[u8] = &*snapshot;
|
||||||
println!("Snapshot size: {}", snapshot_slice.len());
|
println!("Snapshot size: {}", snapshot_slice.len());
|
||||||
std::fs::write(&snapshot_path, snapshot_slice).unwrap();
|
std::fs::write(&snapshot_path, snapshot_slice).unwrap();
|
||||||
|
@ -39,11 +39,11 @@ fn create_snapshot(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_runtime_snapshot(snapshot_path: &Path, files: Vec<PathBuf>) {
|
fn create_runtime_snapshot(snapshot_path: &Path, files: Vec<PathBuf>) {
|
||||||
let isolate = JsRuntime::new(RuntimeOptions {
|
let js_runtime = JsRuntime::new(RuntimeOptions {
|
||||||
will_snapshot: true,
|
will_snapshot: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
create_snapshot(isolate, snapshot_path, files);
|
create_snapshot(js_runtime, snapshot_path, files);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_compiler_snapshot(
|
fn create_compiler_snapshot(
|
||||||
|
@ -79,15 +79,15 @@ fn create_compiler_snapshot(
|
||||||
cwd.join("dts/lib.deno.unstable.d.ts"),
|
cwd.join("dts/lib.deno.unstable.d.ts"),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut isolate = JsRuntime::new(RuntimeOptions {
|
let mut js_runtime = JsRuntime::new(RuntimeOptions {
|
||||||
will_snapshot: true,
|
will_snapshot: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
isolate.register_op(
|
js_runtime.register_op(
|
||||||
"op_fetch_asset",
|
"op_fetch_asset",
|
||||||
op_fetch_asset::op_fetch_asset(custom_libs),
|
op_fetch_asset::op_fetch_asset(custom_libs),
|
||||||
);
|
);
|
||||||
create_snapshot(isolate, snapshot_path, files);
|
create_snapshot(js_runtime, snapshot_path, files);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ts_version() -> String {
|
fn ts_version() -> String {
|
||||||
|
|
|
@ -390,11 +390,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::JsRuntime,
|
js_runtime: &mut deno_core::JsRuntime,
|
||||||
server: Option<Arc<InspectorServer>>,
|
server: Option<Arc<InspectorServer>>,
|
||||||
) -> Box<Self> {
|
) -> Box<Self> {
|
||||||
let context = isolate.global_context();
|
let context = js_runtime.global_context();
|
||||||
let scope = &mut v8::HandleScope::new(isolate.v8_isolate());
|
let scope = &mut v8::HandleScope::new(js_runtime.v8_isolate());
|
||||||
|
|
||||||
let (new_websocket_tx, new_websocket_rx) =
|
let (new_websocket_tx, new_websocket_rx) =
|
||||||
mpsc::unbounded::<WebSocketProxy>();
|
mpsc::unbounded::<WebSocketProxy>();
|
||||||
|
|
|
@ -30,11 +30,11 @@ pub fn compiler_isolate_init() -> Snapshot {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cli_snapshot() {
|
fn cli_snapshot() {
|
||||||
let mut isolate = deno_core::JsRuntime::new(deno_core::RuntimeOptions {
|
let mut js_runtime = deno_core::JsRuntime::new(deno_core::RuntimeOptions {
|
||||||
startup_snapshot: Some(deno_isolate_init()),
|
startup_snapshot: Some(deno_isolate_init()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
isolate
|
js_runtime
|
||||||
.execute(
|
.execute(
|
||||||
"<anon>",
|
"<anon>",
|
||||||
r#"
|
r#"
|
||||||
|
@ -49,11 +49,11 @@ fn cli_snapshot() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compiler_snapshot() {
|
fn compiler_snapshot() {
|
||||||
let mut isolate = deno_core::JsRuntime::new(deno_core::RuntimeOptions {
|
let mut js_runtime = deno_core::JsRuntime::new(deno_core::RuntimeOptions {
|
||||||
startup_snapshot: Some(compiler_isolate_init()),
|
startup_snapshot: Some(compiler_isolate_init()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
isolate
|
js_runtime
|
||||||
.execute(
|
.execute(
|
||||||
"<anon>",
|
"<anon>",
|
||||||
r#"
|
r#"
|
||||||
|
|
|
@ -62,7 +62,7 @@ fn create_web_worker(
|
||||||
);
|
);
|
||||||
|
|
||||||
if has_deno_namespace {
|
if has_deno_namespace {
|
||||||
let state = worker.isolate.op_state();
|
let state = worker.js_runtime.op_state();
|
||||||
let mut state = state.borrow_mut();
|
let mut state = state.borrow_mut();
|
||||||
let (stdin, stdout, stderr) = get_stdio();
|
let (stdin, stdout, stderr) = get_stdio();
|
||||||
if let Some(stream) = stdin {
|
if let Some(stream) = stdin {
|
||||||
|
|
|
@ -96,7 +96,7 @@ fn create_channels() -> (WorkerChannelsInternal, WorkerHandle) {
|
||||||
/// - `WebWorker`
|
/// - `WebWorker`
|
||||||
pub struct Worker {
|
pub struct Worker {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub isolate: JsRuntime,
|
pub js_runtime: JsRuntime,
|
||||||
pub inspector: Option<Box<DenoInspector>>,
|
pub inspector: Option<Box<DenoInspector>>,
|
||||||
pub waker: AtomicWaker,
|
pub waker: AtomicWaker,
|
||||||
pub(crate) internal_channels: WorkerChannelsInternal,
|
pub(crate) internal_channels: WorkerChannelsInternal,
|
||||||
|
@ -114,7 +114,7 @@ impl Worker {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let global_state_ = global_state.clone();
|
let global_state_ = global_state.clone();
|
||||||
|
|
||||||
let mut isolate = JsRuntime::new(RuntimeOptions {
|
let mut js_runtime = JsRuntime::new(RuntimeOptions {
|
||||||
module_loader: Some(module_loader),
|
module_loader: Some(module_loader),
|
||||||
startup_snapshot: Some(startup_snapshot),
|
startup_snapshot: Some(startup_snapshot),
|
||||||
js_error_create_fn: Some(Box::new(move |core_js_error| {
|
js_error_create_fn: Some(Box::new(move |core_js_error| {
|
||||||
|
@ -123,7 +123,7 @@ impl Worker {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
{
|
{
|
||||||
let op_state = isolate.op_state();
|
let op_state = js_runtime.op_state();
|
||||||
let mut op_state = op_state.borrow_mut();
|
let mut op_state = op_state.borrow_mut();
|
||||||
op_state.get_error_class_fn = &crate::errors::get_error_class_name;
|
op_state.get_error_class_fn = &crate::errors::get_error_class_name;
|
||||||
}
|
}
|
||||||
|
@ -131,11 +131,11 @@ impl Worker {
|
||||||
let inspector =
|
let inspector =
|
||||||
if let Some(inspector_server) = &global_state.maybe_inspector_server {
|
if let Some(inspector_server) = &global_state.maybe_inspector_server {
|
||||||
Some(DenoInspector::new(
|
Some(DenoInspector::new(
|
||||||
&mut isolate,
|
&mut js_runtime,
|
||||||
Some(inspector_server.clone()),
|
Some(inspector_server.clone()),
|
||||||
))
|
))
|
||||||
} else if global_state.flags.coverage || global_state.flags.repl {
|
} else if global_state.flags.coverage || global_state.flags.repl {
|
||||||
Some(DenoInspector::new(&mut isolate, None))
|
Some(DenoInspector::new(&mut js_runtime, None))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
@ -148,7 +148,7 @@ impl Worker {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
name,
|
name,
|
||||||
isolate,
|
js_runtime,
|
||||||
inspector,
|
inspector,
|
||||||
waker: AtomicWaker::new(),
|
waker: AtomicWaker::new(),
|
||||||
internal_channels,
|
internal_channels,
|
||||||
|
@ -171,7 +171,7 @@ impl Worker {
|
||||||
js_filename: &str,
|
js_filename: &str,
|
||||||
js_source: &str,
|
js_source: &str,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
self.isolate.execute(js_filename, js_source)
|
self.js_runtime.execute(js_filename, js_source)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads and instantiates specified JavaScript module.
|
/// Loads and instantiates specified JavaScript module.
|
||||||
|
@ -179,7 +179,7 @@ impl Worker {
|
||||||
&mut self,
|
&mut self,
|
||||||
module_specifier: &ModuleSpecifier,
|
module_specifier: &ModuleSpecifier,
|
||||||
) -> Result<ModuleId, AnyError> {
|
) -> Result<ModuleId, AnyError> {
|
||||||
self.isolate.load_module(module_specifier, None).await
|
self.js_runtime.load_module(module_specifier, None).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads, instantiates and executes specified JavaScript module.
|
/// Loads, instantiates and executes specified JavaScript module.
|
||||||
|
@ -189,7 +189,7 @@ impl Worker {
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let id = self.preload_module(module_specifier).await?;
|
let id = self.preload_module(module_specifier).await?;
|
||||||
self.wait_for_inspector_session();
|
self.wait_for_inspector_session();
|
||||||
self.isolate.mod_evaluate(id).await
|
self.js_runtime.mod_evaluate(id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads, instantiates and executes provided source code
|
/// Loads, instantiates and executes provided source code
|
||||||
|
@ -200,11 +200,11 @@ impl Worker {
|
||||||
code: String,
|
code: String,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let id = self
|
let id = self
|
||||||
.isolate
|
.js_runtime
|
||||||
.load_module(module_specifier, Some(code))
|
.load_module(module_specifier, Some(code))
|
||||||
.await?;
|
.await?;
|
||||||
self.wait_for_inspector_session();
|
self.wait_for_inspector_session();
|
||||||
self.isolate.mod_evaluate(id).await
|
self.js_runtime.mod_evaluate(id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a way to communicate with the Worker from other threads.
|
/// Returns a way to communicate with the Worker from other threads.
|
||||||
|
@ -240,20 +240,20 @@ impl Future for Worker {
|
||||||
// We always poll the inspector if it exists.
|
// We always poll the inspector if it exists.
|
||||||
let _ = inner.inspector.as_mut().map(|i| i.poll_unpin(cx));
|
let _ = inner.inspector.as_mut().map(|i| i.poll_unpin(cx));
|
||||||
inner.waker.register(cx.waker());
|
inner.waker.register(cx.waker());
|
||||||
inner.isolate.poll_unpin(cx)
|
inner.js_runtime.poll_unpin(cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for Worker {
|
impl Deref for Worker {
|
||||||
type Target = JsRuntime;
|
type Target = JsRuntime;
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.isolate
|
&self.js_runtime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for Worker {
|
impl DerefMut for Worker {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
&mut self.isolate
|
&mut self.js_runtime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +428,7 @@ impl WebWorker {
|
||||||
);
|
);
|
||||||
|
|
||||||
let terminated = Arc::new(AtomicBool::new(false));
|
let terminated = Arc::new(AtomicBool::new(false));
|
||||||
let isolate_handle = worker.isolate.v8_isolate().thread_safe_handle();
|
let isolate_handle = worker.js_runtime.v8_isolate().thread_safe_handle();
|
||||||
let (terminate_tx, terminate_rx) = mpsc::channel::<()>(1);
|
let (terminate_tx, terminate_rx) = mpsc::channel::<()>(1);
|
||||||
|
|
||||||
let handle = WebWorkerHandle {
|
let handle = WebWorkerHandle {
|
||||||
|
|
|
@ -76,14 +76,14 @@ impl From<Record> for RecordBuf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_isolate() -> JsRuntime {
|
fn create_js_runtime() -> JsRuntime {
|
||||||
let mut isolate = JsRuntime::new(Default::default());
|
let mut js_runtime = JsRuntime::new(Default::default());
|
||||||
register_op_bin_sync(&mut isolate, "listen", op_listen);
|
register_op_bin_sync(&mut js_runtime, "listen", op_listen);
|
||||||
register_op_bin_sync(&mut isolate, "close", op_close);
|
register_op_bin_sync(&mut js_runtime, "close", op_close);
|
||||||
register_op_bin_async(&mut isolate, "accept", op_accept);
|
register_op_bin_async(&mut js_runtime, "accept", op_accept);
|
||||||
register_op_bin_async(&mut isolate, "read", op_read);
|
register_op_bin_async(&mut js_runtime, "read", op_read);
|
||||||
register_op_bin_async(&mut isolate, "write", op_write);
|
register_op_bin_async(&mut js_runtime, "write", op_write);
|
||||||
isolate
|
js_runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_listen(
|
fn op_listen(
|
||||||
|
@ -172,7 +172,7 @@ fn op_write(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_op_bin_sync<F>(
|
fn register_op_bin_sync<F>(
|
||||||
isolate: &mut JsRuntime,
|
js_runtime: &mut JsRuntime,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
op_fn: F,
|
op_fn: F,
|
||||||
) where
|
) where
|
||||||
|
@ -193,11 +193,11 @@ fn register_op_bin_sync<F>(
|
||||||
Op::Sync(buf)
|
Op::Sync(buf)
|
||||||
};
|
};
|
||||||
|
|
||||||
isolate.register_op(name, base_op_fn);
|
js_runtime.register_op(name, base_op_fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_op_bin_async<F, R>(
|
fn register_op_bin_async<F, R>(
|
||||||
isolate: &mut JsRuntime,
|
js_runtime: &mut JsRuntime,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
op_fn: F,
|
op_fn: F,
|
||||||
) where
|
) where
|
||||||
|
@ -227,7 +227,7 @@ fn register_op_bin_async<F, R>(
|
||||||
Op::Async(fut.boxed_local())
|
Op::Async(fut.boxed_local())
|
||||||
};
|
};
|
||||||
|
|
||||||
isolate.register_op(name, base_op_fn);
|
js_runtime.register_op(name, base_op_fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bad_resource_id() -> Error {
|
fn bad_resource_id() -> Error {
|
||||||
|
@ -246,7 +246,7 @@ fn main() {
|
||||||
// NOTE: `--help` arg will display V8 help and exit
|
// NOTE: `--help` arg will display V8 help and exit
|
||||||
deno_core::v8_set_flags(env::args().collect());
|
deno_core::v8_set_flags(env::args().collect());
|
||||||
|
|
||||||
let mut isolate = create_isolate();
|
let mut js_runtime = create_js_runtime();
|
||||||
let mut runtime = runtime::Builder::new()
|
let mut runtime = runtime::Builder::new()
|
||||||
.basic_scheduler()
|
.basic_scheduler()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
|
@ -254,13 +254,13 @@ fn main() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let future = async move {
|
let future = async move {
|
||||||
isolate
|
js_runtime
|
||||||
.execute(
|
.execute(
|
||||||
"http_bench_bin_ops.js",
|
"http_bench_bin_ops.js",
|
||||||
include_str!("http_bench_bin_ops.js"),
|
include_str!("http_bench_bin_ops.js"),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
isolate.await
|
js_runtime.await
|
||||||
};
|
};
|
||||||
runtime.block_on(future).unwrap();
|
runtime.block_on(future).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ impl log::Log for Logger {
|
||||||
fn flush(&self) {}
|
fn flush(&self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_isolate() -> JsRuntime {
|
fn create_js_runtime() -> JsRuntime {
|
||||||
let mut runtime = JsRuntime::new(Default::default());
|
let mut runtime = JsRuntime::new(Default::default());
|
||||||
runtime.register_op("listen", deno_core::json_op_sync(op_listen));
|
runtime.register_op("listen", deno_core::json_op_sync(op_listen));
|
||||||
runtime.register_op("close", deno_core::json_op_sync(op_close));
|
runtime.register_op("close", deno_core::json_op_sync(op_close));
|
||||||
|
@ -179,7 +179,7 @@ fn main() {
|
||||||
// NOTE: `--help` arg will display V8 help and exit
|
// NOTE: `--help` arg will display V8 help and exit
|
||||||
deno_core::v8_set_flags(env::args().collect());
|
deno_core::v8_set_flags(env::args().collect());
|
||||||
|
|
||||||
let mut isolate = create_isolate();
|
let mut js_runtime = create_js_runtime();
|
||||||
let mut runtime = runtime::Builder::new()
|
let mut runtime = runtime::Builder::new()
|
||||||
.basic_scheduler()
|
.basic_scheduler()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
|
@ -187,13 +187,13 @@ fn main() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let future = async move {
|
let future = async move {
|
||||||
isolate
|
js_runtime
|
||||||
.execute(
|
.execute(
|
||||||
"http_bench_json_ops.js",
|
"http_bench_json_ops.js",
|
||||||
include_str!("http_bench_json_ops.js"),
|
include_str!("http_bench_json_ops.js"),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
isolate.await
|
js_runtime.await
|
||||||
};
|
};
|
||||||
runtime.block_on(future).unwrap();
|
runtime.block_on(future).unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue