summaryrefslogtreecommitdiff
path: root/cli/ops
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ops')
-rw-r--r--cli/ops/mod.rs1
-rw-r--r--cli/ops/os.rs41
-rw-r--r--cli/ops/runtime.rs50
-rw-r--r--cli/ops/worker_host.rs15
4 files changed, 62 insertions, 45 deletions
diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs
index 4306e25e2..aa702c9c8 100644
--- a/cli/ops/mod.rs
+++ b/cli/ops/mod.rs
@@ -21,6 +21,7 @@ pub mod process;
pub mod random;
pub mod repl;
pub mod resources;
+pub mod runtime;
pub mod runtime_compiler;
pub mod signal;
pub mod timers;
diff --git a/cli/ops/os.rs b/cli/ops/os.rs
index ffc453bc6..ce2320d92 100644
--- a/cli/ops/os.rs
+++ b/cli/ops/os.rs
@@ -1,10 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{Deserialize, JsonOp, Value};
-use crate::colors;
-use crate::fs as deno_fs;
use crate::ops::json_op;
use crate::state::ThreadSafeState;
-use crate::version;
use atty;
use deno_core::*;
use std::collections::HashMap;
@@ -13,16 +10,6 @@ use std::io::{Error, ErrorKind};
use sys_info;
use url::Url;
-/// BUILD_OS and BUILD_ARCH match the values in Deno.build. See js/build.ts.
-#[cfg(target_os = "macos")]
-static BUILD_OS: &str = "mac";
-#[cfg(target_os = "linux")]
-static BUILD_OS: &str = "linux";
-#[cfg(target_os = "windows")]
-static BUILD_OS: &str = "win";
-#[cfg(target_arch = "x86_64")]
-static BUILD_ARCH: &str = "x64";
-
pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
i.register_op("exit", s.core_op(json_op(s.stateful_op(op_exit))));
i.register_op("is_tty", s.core_op(json_op(s.stateful_op(op_is_tty))));
@@ -32,34 +19,6 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
i.register_op("get_env", s.core_op(json_op(s.stateful_op(op_get_env))));
i.register_op("get_dir", s.core_op(json_op(s.stateful_op(op_get_dir))));
i.register_op("hostname", s.core_op(json_op(s.stateful_op(op_hostname))));
- i.register_op("start", s.core_op(json_op(s.stateful_op(op_start))));
-}
-
-fn op_start(
- state: &ThreadSafeState,
- _args: Value,
- _zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
- let gs = &state.global_state;
- let script_args = if gs.flags.argv.len() >= 2 {
- gs.flags.argv.clone().split_off(2)
- } else {
- vec![]
- };
- Ok(JsonOp::Sync(json!({
- "cwd": deno_fs::normalize_path(&env::current_dir().unwrap()),
- "pid": std::process::id(),
- "argv": script_args,
- "mainModule": gs.main_module.as_ref().map(|x| x.to_string()),
- "debugFlag": gs.flags.log_level.map_or(false, |l| l == log::Level::Debug),
- "versionFlag": gs.flags.version,
- "v8Version": version::v8(),
- "denoVersion": version::DENO,
- "tsVersion": version::TYPESCRIPT,
- "noColor": !colors::use_color(),
- "os": BUILD_OS,
- "arch": BUILD_ARCH,
- })))
}
#[derive(Deserialize)]
diff --git a/cli/ops/runtime.rs b/cli/ops/runtime.rs
new file mode 100644
index 000000000..886326146
--- /dev/null
+++ b/cli/ops/runtime.rs
@@ -0,0 +1,50 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+use super::dispatch_json::{JsonOp, Value};
+use crate::colors;
+use crate::fs as deno_fs;
+use crate::ops::json_op;
+use crate::state::ThreadSafeState;
+use crate::version;
+use deno_core::*;
+use std::env;
+
+/// BUILD_OS and BUILD_ARCH match the values in Deno.build. See js/build.ts.
+#[cfg(target_os = "macos")]
+static BUILD_OS: &str = "mac";
+#[cfg(target_os = "linux")]
+static BUILD_OS: &str = "linux";
+#[cfg(target_os = "windows")]
+static BUILD_OS: &str = "win";
+#[cfg(target_arch = "x86_64")]
+static BUILD_ARCH: &str = "x64";
+
+pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
+ i.register_op("start", s.core_op(json_op(s.stateful_op(op_start))));
+}
+
+fn op_start(
+ state: &ThreadSafeState,
+ _args: Value,
+ _zero_copy: Option<ZeroCopyBuf>,
+) -> Result<JsonOp, ErrBox> {
+ let gs = &state.global_state;
+ let script_args = if gs.flags.argv.len() >= 2 {
+ gs.flags.argv.clone().split_off(2)
+ } else {
+ vec![]
+ };
+ Ok(JsonOp::Sync(json!({
+ "cwd": deno_fs::normalize_path(&env::current_dir().unwrap()),
+ "pid": std::process::id(),
+ "argv": script_args,
+ "mainModule": gs.main_module.as_ref().map(|x| x.to_string()),
+ "debugFlag": gs.flags.log_level.map_or(false, |l| l == log::Level::Debug),
+ "versionFlag": gs.flags.version,
+ "v8Version": version::v8(),
+ "denoVersion": version::DENO,
+ "tsVersion": version::TYPESCRIPT,
+ "noColor": !colors::use_color(),
+ "os": BUILD_OS,
+ "arch": BUILD_ARCH,
+ })))
+}
diff --git a/cli/ops/worker_host.rs b/cli/ops/worker_host.rs
index 58457c2e7..976c32219 100644
--- a/cli/ops/worker_host.rs
+++ b/cli/ops/worker_host.rs
@@ -97,10 +97,17 @@ fn op_create_worker(
)?;
// TODO: add a new option to make child worker not sharing permissions
// with parent (aka .clone(), requests from child won't reflect in parent)
+ // TODO(bartlomieju): get it from "name" argument when creating worker
let name = format!("USER-WORKER-{}", specifier);
- let mut worker =
- WebWorker::new(name, startup_data::deno_isolate_init(), child_state, ext);
- js_check(worker.execute("bootstrapWorkerRuntime()"));
+ let mut worker = WebWorker::new(
+ name.to_string(),
+ startup_data::deno_isolate_init(),
+ child_state,
+ ext,
+ );
+ let script = format!("bootstrapWorkerRuntime(\"{}\")", name);
+ js_check(worker.execute(&script));
+ js_check(worker.execute("runWorkerMessageLoop()"));
let worker_id = parent_state.add_child_worker(worker.clone());
@@ -249,7 +256,7 @@ fn op_host_resume_worker(
let mut workers_table = state_.workers.lock().unwrap();
let worker = workers_table.get_mut(&id).unwrap();
- js_check(worker.execute("bootstrapWorkerRuntime()"));
+ js_check(worker.execute("runWorkerMessageLoop()"));
Ok(JsonOp::Sync(json!({})))
}