diff options
Diffstat (limited to 'cli/ops')
-rw-r--r-- | cli/ops/fetch.rs | 10 | ||||
-rw-r--r-- | cli/ops/random.rs | 9 | ||||
-rw-r--r-- | cli/ops/runtime.rs | 7 | ||||
-rw-r--r-- | cli/ops/timers.rs | 6 | ||||
-rw-r--r-- | cli/ops/web_worker.rs | 2 | ||||
-rw-r--r-- | cli/ops/worker_host.rs | 10 |
6 files changed, 38 insertions, 6 deletions
diff --git a/cli/ops/fetch.rs b/cli/ops/fetch.rs index 54585dc3d..8c1a2b39c 100644 --- a/cli/ops/fetch.rs +++ b/cli/ops/fetch.rs @@ -1,7 +1,15 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use crate::permissions::Permissions; +use deno_fetch::reqwest; -pub fn init(rt: &mut deno_core::JsRuntime) { +pub fn init(rt: &mut deno_core::JsRuntime, maybe_ca_file: Option<&str>) { + { + let op_state = rt.op_state(); + let mut state = op_state.borrow_mut(); + state.put::<reqwest::Client>({ + crate::http_util::create_http_client(maybe_ca_file).unwrap() + }); + } super::reg_json_async(rt, "op_fetch", deno_fetch::op_fetch::<Permissions>); super::reg_json_async(rt, "op_fetch_read", deno_fetch::op_fetch_read); super::reg_json_sync( diff --git a/cli/ops/random.rs b/cli/ops/random.rs index 53aedb73f..20296c667 100644 --- a/cli/ops/random.rs +++ b/cli/ops/random.rs @@ -8,8 +8,15 @@ use deno_core::ZeroCopyBuf; use rand::rngs::StdRng; use rand::thread_rng; use rand::Rng; +use rand::SeedableRng; -pub fn init(rt: &mut deno_core::JsRuntime) { +pub fn init(rt: &mut deno_core::JsRuntime, maybe_seed: Option<u64>) { + if let Some(seed) = maybe_seed { + let rng = StdRng::seed_from_u64(seed); + let op_state = rt.op_state(); + let mut state = op_state.borrow_mut(); + state.put::<StdRng>(rng); + } super::reg_json_sync(rt, "op_get_random_values", op_get_random_values); } diff --git a/cli/ops/runtime.rs b/cli/ops/runtime.rs index d059301f1..b1eddc265 100644 --- a/cli/ops/runtime.rs +++ b/cli/ops/runtime.rs @@ -14,7 +14,12 @@ use deno_core::OpState; use deno_core::ZeroCopyBuf; use std::env; -pub fn init(rt: &mut deno_core::JsRuntime) { +pub fn init(rt: &mut deno_core::JsRuntime, main_module: ModuleSpecifier) { + { + let op_state = rt.op_state(); + let mut state = op_state.borrow_mut(); + state.put::<ModuleSpecifier>(main_module); + } super::reg_json_sync(rt, "op_start", op_start); super::reg_json_sync(rt, "op_main_module", op_main_module); super::reg_json_sync(rt, "op_metrics", op_metrics); diff --git a/cli/ops/timers.rs b/cli/ops/timers.rs index eb6561193..74edc7267 100644 --- a/cli/ops/timers.rs +++ b/cli/ops/timers.rs @@ -67,6 +67,12 @@ impl GlobalTimer { } pub fn init(rt: &mut deno_core::JsRuntime) { + { + let op_state = rt.op_state(); + let mut state = op_state.borrow_mut(); + state.put::<GlobalTimer>(GlobalTimer::default()); + state.put::<StartTime>(StartTime::now()); + } super::reg_json_sync(rt, "op_global_timer_stop", op_global_timer_stop); super::reg_json_sync(rt, "op_global_timer_start", op_global_timer_start); super::reg_json_async(rt, "op_global_timer", op_global_timer); diff --git a/cli/ops/web_worker.rs b/cli/ops/web_worker.rs index e57edaf6c..42b6a56ce 100644 --- a/cli/ops/web_worker.rs +++ b/cli/ops/web_worker.rs @@ -1,6 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -use crate::web_worker::WebWorkerHandle; +use crate::worker::WebWorkerHandle; use crate::worker::WorkerEvent; use deno_core::futures::channel::mpsc; use deno_core::serde_json::json; diff --git a/cli/ops/worker_host.rs b/cli/ops/worker_host.rs index 60262b4f6..9175ca0f1 100644 --- a/cli/ops/worker_host.rs +++ b/cli/ops/worker_host.rs @@ -5,8 +5,8 @@ use crate::global_state::GlobalState; use crate::ops::io::get_stdio; use crate::permissions::Permissions; use crate::tokio_util::create_basic_runtime; -use crate::web_worker::WebWorker; -use crate::web_worker::WebWorkerHandle; +use crate::worker::WebWorker; +use crate::worker::WebWorkerHandle; use crate::worker::WorkerEvent; use deno_core::error::AnyError; use deno_core::futures::future::FutureExt; @@ -26,6 +26,12 @@ use std::sync::Arc; use std::thread::JoinHandle; pub fn init(rt: &mut deno_core::JsRuntime) { + { + let op_state = rt.op_state(); + let mut state = op_state.borrow_mut(); + state.put::<WorkersTable>(WorkersTable::default()); + state.put::<WorkerId>(WorkerId::default()); + } super::reg_json_sync(rt, "op_create_worker", op_create_worker); super::reg_json_sync( rt, |