1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -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:
Bartek Iwańczuk 2020-10-07 17:20:20 +02:00 committed by GitHub
parent 83f6def3c6
commit 9b70f2f345
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 52 deletions

View file

@ -10,12 +10,12 @@ use std::path::Path;
use std::path::PathBuf;
fn create_snapshot(
mut isolate: JsRuntime,
mut js_runtime: JsRuntime,
snapshot_path: &Path,
files: Vec<PathBuf>,
) {
deno_web::init(&mut isolate);
deno_fetch::init(&mut isolate);
deno_web::init(&mut js_runtime);
deno_fetch::init(&mut js_runtime);
// TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the
// workspace root.
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());
let display_path = file.strip_prefix(display_root).unwrap();
let display_path_str = display_path.display().to_string();
isolate
js_runtime
.execute(
&("deno:".to_string() + &display_path_str.replace('\\', "/")),
&std::fs::read_to_string(&file).unwrap(),
@ -31,7 +31,7 @@ fn create_snapshot(
.unwrap();
}
let snapshot = isolate.snapshot();
let snapshot = js_runtime.snapshot();
let snapshot_slice: &[u8] = &*snapshot;
println!("Snapshot size: {}", snapshot_slice.len());
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>) {
let isolate = JsRuntime::new(RuntimeOptions {
let js_runtime = JsRuntime::new(RuntimeOptions {
will_snapshot: true,
..Default::default()
});
create_snapshot(isolate, snapshot_path, files);
create_snapshot(js_runtime, snapshot_path, files);
}
fn create_compiler_snapshot(
@ -79,15 +79,15 @@ fn create_compiler_snapshot(
cwd.join("dts/lib.deno.unstable.d.ts"),
);
let mut isolate = JsRuntime::new(RuntimeOptions {
let mut js_runtime = JsRuntime::new(RuntimeOptions {
will_snapshot: true,
..Default::default()
});
isolate.register_op(
js_runtime.register_op(
"op_fetch_asset",
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 {

View file

@ -390,11 +390,11 @@ impl DenoInspector {
const CONTEXT_GROUP_ID: i32 = 1;
pub fn new(
isolate: &mut deno_core::JsRuntime,
js_runtime: &mut deno_core::JsRuntime,
server: Option<Arc<InspectorServer>>,
) -> Box<Self> {
let context = isolate.global_context();
let scope = &mut v8::HandleScope::new(isolate.v8_isolate());
let context = js_runtime.global_context();
let scope = &mut v8::HandleScope::new(js_runtime.v8_isolate());
let (new_websocket_tx, new_websocket_rx) =
mpsc::unbounded::<WebSocketProxy>();

View file

@ -30,11 +30,11 @@ pub fn compiler_isolate_init() -> Snapshot {
#[test]
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()),
..Default::default()
});
isolate
js_runtime
.execute(
"<anon>",
r#"
@ -49,11 +49,11 @@ fn cli_snapshot() {
#[test]
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()),
..Default::default()
});
isolate
js_runtime
.execute(
"<anon>",
r#"

View file

@ -62,7 +62,7 @@ fn create_web_worker(
);
if has_deno_namespace {
let state = worker.isolate.op_state();
let state = worker.js_runtime.op_state();
let mut state = state.borrow_mut();
let (stdin, stdout, stderr) = get_stdio();
if let Some(stream) = stdin {

View file

@ -96,7 +96,7 @@ fn create_channels() -> (WorkerChannelsInternal, WorkerHandle) {
/// - `WebWorker`
pub struct Worker {
pub name: String,
pub isolate: JsRuntime,
pub js_runtime: JsRuntime,
pub inspector: Option<Box<DenoInspector>>,
pub waker: AtomicWaker,
pub(crate) internal_channels: WorkerChannelsInternal,
@ -114,7 +114,7 @@ impl Worker {
) -> Self {
let global_state_ = global_state.clone();
let mut isolate = JsRuntime::new(RuntimeOptions {
let mut js_runtime = JsRuntime::new(RuntimeOptions {
module_loader: Some(module_loader),
startup_snapshot: Some(startup_snapshot),
js_error_create_fn: Some(Box::new(move |core_js_error| {
@ -123,7 +123,7 @@ impl Worker {
..Default::default()
});
{
let op_state = isolate.op_state();
let op_state = js_runtime.op_state();
let mut op_state = op_state.borrow_mut();
op_state.get_error_class_fn = &crate::errors::get_error_class_name;
}
@ -131,11 +131,11 @@ impl Worker {
let inspector =
if let Some(inspector_server) = &global_state.maybe_inspector_server {
Some(DenoInspector::new(
&mut isolate,
&mut js_runtime,
Some(inspector_server.clone()),
))
} else if global_state.flags.coverage || global_state.flags.repl {
Some(DenoInspector::new(&mut isolate, None))
Some(DenoInspector::new(&mut js_runtime, None))
} else {
None
};
@ -148,7 +148,7 @@ impl Worker {
Self {
name,
isolate,
js_runtime,
inspector,
waker: AtomicWaker::new(),
internal_channels,
@ -171,7 +171,7 @@ impl Worker {
js_filename: &str,
js_source: &str,
) -> Result<(), AnyError> {
self.isolate.execute(js_filename, js_source)
self.js_runtime.execute(js_filename, js_source)
}
/// Loads and instantiates specified JavaScript module.
@ -179,7 +179,7 @@ impl Worker {
&mut self,
module_specifier: &ModuleSpecifier,
) -> 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.
@ -189,7 +189,7 @@ impl Worker {
) -> Result<(), AnyError> {
let id = self.preload_module(module_specifier).await?;
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
@ -200,11 +200,11 @@ impl Worker {
code: String,
) -> Result<(), AnyError> {
let id = self
.isolate
.js_runtime
.load_module(module_specifier, Some(code))
.await?;
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.
@ -240,20 +240,20 @@ impl Future for Worker {
// We always poll the inspector if it exists.
let _ = inner.inspector.as_mut().map(|i| i.poll_unpin(cx));
inner.waker.register(cx.waker());
inner.isolate.poll_unpin(cx)
inner.js_runtime.poll_unpin(cx)
}
}
impl Deref for Worker {
type Target = JsRuntime;
fn deref(&self) -> &Self::Target {
&self.isolate
&self.js_runtime
}
}
impl DerefMut for Worker {
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 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 handle = WebWorkerHandle {

View file

@ -76,14 +76,14 @@ impl From<Record> for RecordBuf {
}
}
fn create_isolate() -> JsRuntime {
let mut isolate = JsRuntime::new(Default::default());
register_op_bin_sync(&mut isolate, "listen", op_listen);
register_op_bin_sync(&mut isolate, "close", op_close);
register_op_bin_async(&mut isolate, "accept", op_accept);
register_op_bin_async(&mut isolate, "read", op_read);
register_op_bin_async(&mut isolate, "write", op_write);
isolate
fn create_js_runtime() -> JsRuntime {
let mut js_runtime = JsRuntime::new(Default::default());
register_op_bin_sync(&mut js_runtime, "listen", op_listen);
register_op_bin_sync(&mut js_runtime, "close", op_close);
register_op_bin_async(&mut js_runtime, "accept", op_accept);
register_op_bin_async(&mut js_runtime, "read", op_read);
register_op_bin_async(&mut js_runtime, "write", op_write);
js_runtime
}
fn op_listen(
@ -172,7 +172,7 @@ fn op_write(
}
fn register_op_bin_sync<F>(
isolate: &mut JsRuntime,
js_runtime: &mut JsRuntime,
name: &'static str,
op_fn: F,
) where
@ -193,11 +193,11 @@ fn register_op_bin_sync<F>(
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>(
isolate: &mut JsRuntime,
js_runtime: &mut JsRuntime,
name: &'static str,
op_fn: F,
) where
@ -227,7 +227,7 @@ fn register_op_bin_async<F, R>(
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 {
@ -246,7 +246,7 @@ fn main() {
// NOTE: `--help` arg will display V8 help and exit
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()
.basic_scheduler()
.enable_all()
@ -254,13 +254,13 @@ fn main() {
.unwrap();
let future = async move {
isolate
js_runtime
.execute(
"http_bench_bin_ops.js",
include_str!("http_bench_bin_ops.js"),
)
.unwrap();
isolate.await
js_runtime.await
};
runtime.block_on(future).unwrap();
}

View file

@ -41,7 +41,7 @@ impl log::Log for Logger {
fn flush(&self) {}
}
fn create_isolate() -> JsRuntime {
fn create_js_runtime() -> JsRuntime {
let mut runtime = JsRuntime::new(Default::default());
runtime.register_op("listen", deno_core::json_op_sync(op_listen));
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
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()
.basic_scheduler()
.enable_all()
@ -187,13 +187,13 @@ fn main() {
.unwrap();
let future = async move {
isolate
js_runtime
.execute(
"http_bench_json_ops.js",
include_str!("http_bench_json_ops.js"),
)
.unwrap();
isolate.await
js_runtime.await
};
runtime.block_on(future).unwrap();
}