mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
Rename deno::state::State to deno::state::CliState (#7480)
This commit is contained in:
parent
192b8f4b99
commit
70f070706d
6 changed files with 43 additions and 43 deletions
|
@ -60,12 +60,12 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper for extracting the commonly used state. Used for sync ops.
|
/// Helper for extracting the commonly used state. Used for sync ops.
|
||||||
pub fn cli_state(state: &OpState) -> Rc<crate::state::State> {
|
pub fn cli_state(state: &OpState) -> Rc<crate::state::CliState> {
|
||||||
state.borrow::<Rc<crate::state::State>>().clone()
|
state.borrow::<Rc<crate::state::CliState>>().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper for extracting the commonly used state. Used for async ops.
|
/// Helper for extracting the commonly used state. Used for async ops.
|
||||||
pub fn cli_state2(state: &Rc<RefCell<OpState>>) -> Rc<crate::state::State> {
|
pub fn cli_state2(state: &Rc<RefCell<OpState>>) -> Rc<crate::state::CliState> {
|
||||||
let state = state.borrow();
|
let state = state.borrow();
|
||||||
state.borrow::<Rc<crate::state::State>>().clone()
|
state.borrow::<Rc<crate::state::CliState>>().clone()
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ fn create_web_worker(
|
||||||
specifier: ModuleSpecifier,
|
specifier: ModuleSpecifier,
|
||||||
has_deno_namespace: bool,
|
has_deno_namespace: bool,
|
||||||
) -> Result<WebWorker, AnyError> {
|
) -> Result<WebWorker, AnyError> {
|
||||||
let cli_state = crate::state::State::new_for_worker(
|
let cli_state = crate::state::CliState::new_for_worker(
|
||||||
global_state,
|
global_state,
|
||||||
Some(permissions),
|
Some(permissions),
|
||||||
specifier,
|
specifier,
|
||||||
|
|
44
cli/state.rs
44
cli/state.rs
|
@ -28,9 +28,11 @@ use std::sync::Arc;
|
||||||
use std::thread::JoinHandle;
|
use std::thread::JoinHandle;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
// TODO(ry) Rename to CliState to avoid confusion with other states.
|
// This is named "CliState" instead of just "State" to avoid confusion with all
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(stutter))]
|
// other state structs (GlobalState, OpState, GothamState).
|
||||||
pub struct State {
|
// TODO(ry) Many of the items in this struct should be moved out and into
|
||||||
|
// OpState, removing redundant RefCell wrappers if possible.
|
||||||
|
pub struct CliState {
|
||||||
pub global_state: Arc<GlobalState>,
|
pub global_state: Arc<GlobalState>,
|
||||||
pub permissions: RefCell<Permissions>,
|
pub permissions: RefCell<Permissions>,
|
||||||
pub main_module: ModuleSpecifier,
|
pub main_module: ModuleSpecifier,
|
||||||
|
@ -49,20 +51,6 @@ pub struct State {
|
||||||
pub http_client: RefCell<reqwest::Client>,
|
pub http_client: RefCell<reqwest::Client>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
|
||||||
/// Quits the process if the --unstable flag was not provided.
|
|
||||||
///
|
|
||||||
/// This is intentionally a non-recoverable check so that people cannot probe
|
|
||||||
/// for unstable APIs from stable programs.
|
|
||||||
pub fn check_unstable(&self, api_name: &str) {
|
|
||||||
// TODO(ry) Maybe use IsolateHandle::terminate_execution here to provide a
|
|
||||||
// stack trace in JS.
|
|
||||||
if !self.global_state.flags.unstable {
|
|
||||||
exit_unstable(api_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn exit_unstable(api_name: &str) {
|
pub fn exit_unstable(api_name: &str) {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"Unstable API '{}'. The --unstable flag must be provided.",
|
"Unstable API '{}'. The --unstable flag must be provided.",
|
||||||
|
@ -71,7 +59,7 @@ pub fn exit_unstable(api_name: &str) {
|
||||||
std::process::exit(70);
|
std::process::exit(70);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleLoader for State {
|
impl ModuleLoader for CliState {
|
||||||
fn resolve(
|
fn resolve(
|
||||||
&self,
|
&self,
|
||||||
specifier: &str,
|
specifier: &str,
|
||||||
|
@ -166,7 +154,7 @@ impl ModuleLoader for State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl CliState {
|
||||||
/// If `shared_permission` is None then permissions from globa state are used.
|
/// If `shared_permission` is None then permissions from globa state are used.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
global_state: &Arc<GlobalState>,
|
global_state: &Arc<GlobalState>,
|
||||||
|
@ -176,7 +164,7 @@ impl State {
|
||||||
is_internal: bool,
|
is_internal: bool,
|
||||||
) -> Result<Rc<Self>, AnyError> {
|
) -> Result<Rc<Self>, AnyError> {
|
||||||
let fl = &global_state.flags;
|
let fl = &global_state.flags;
|
||||||
let state = State {
|
let state = CliState {
|
||||||
global_state: global_state.clone(),
|
global_state: global_state.clone(),
|
||||||
main_module,
|
main_module,
|
||||||
permissions: shared_permissions
|
permissions: shared_permissions
|
||||||
|
@ -204,7 +192,7 @@ impl State {
|
||||||
main_module: ModuleSpecifier,
|
main_module: ModuleSpecifier,
|
||||||
) -> Result<Rc<Self>, AnyError> {
|
) -> Result<Rc<Self>, AnyError> {
|
||||||
let fl = &global_state.flags;
|
let fl = &global_state.flags;
|
||||||
let state = State {
|
let state = CliState {
|
||||||
global_state: global_state.clone(),
|
global_state: global_state.clone(),
|
||||||
main_module,
|
main_module,
|
||||||
permissions: shared_permissions
|
permissions: shared_permissions
|
||||||
|
@ -308,7 +296,7 @@ impl State {
|
||||||
pub fn mock(main_module: &str) -> Rc<Self> {
|
pub fn mock(main_module: &str) -> Rc<Self> {
|
||||||
let module_specifier = ModuleSpecifier::resolve_url_or_path(main_module)
|
let module_specifier = ModuleSpecifier::resolve_url_or_path(main_module)
|
||||||
.expect("Invalid entry module");
|
.expect("Invalid entry module");
|
||||||
State::new(
|
CliState::new(
|
||||||
&GlobalState::mock(vec!["deno".to_string()], None),
|
&GlobalState::mock(vec!["deno".to_string()], None),
|
||||||
None,
|
None,
|
||||||
module_specifier,
|
module_specifier,
|
||||||
|
@ -317,4 +305,16 @@ impl State {
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Quits the process if the --unstable flag was not provided.
|
||||||
|
///
|
||||||
|
/// This is intentionally a non-recoverable check so that people cannot probe
|
||||||
|
/// for unstable APIs from stable programs.
|
||||||
|
pub fn check_unstable(&self, api_name: &str) {
|
||||||
|
// TODO(ry) Maybe use IsolateHandle::terminate_execution here to provide a
|
||||||
|
// stack trace in JS.
|
||||||
|
if !self.global_state.flags.unstable {
|
||||||
|
exit_unstable(api_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ use crate::msg::MediaType;
|
||||||
use crate::ops;
|
use crate::ops;
|
||||||
use crate::permissions::Permissions;
|
use crate::permissions::Permissions;
|
||||||
use crate::source_maps::SourceMapGetter;
|
use crate::source_maps::SourceMapGetter;
|
||||||
use crate::state::State;
|
use crate::state::CliState;
|
||||||
use crate::tsc_config;
|
use crate::tsc_config;
|
||||||
use crate::version;
|
use crate::version;
|
||||||
use crate::worker::Worker;
|
use crate::worker::Worker;
|
||||||
|
@ -132,7 +132,7 @@ pub struct CompilerWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompilerWorker {
|
impl CompilerWorker {
|
||||||
pub fn new(name: String, state: &Rc<State>) -> Self {
|
pub fn new(name: String, state: &Rc<CliState>) -> Self {
|
||||||
let mut worker =
|
let mut worker =
|
||||||
Worker::new(name, Some(js::compiler_isolate_init()), state);
|
Worker::new(name, Some(js::compiler_isolate_init()), state);
|
||||||
let response = Arc::new(Mutex::new(None));
|
let response = Arc::new(Mutex::new(None));
|
||||||
|
@ -218,7 +218,7 @@ fn create_compiler_worker(
|
||||||
let entry_point =
|
let entry_point =
|
||||||
ModuleSpecifier::resolve_url_or_path("./$deno$compiler.ts").unwrap();
|
ModuleSpecifier::resolve_url_or_path("./$deno$compiler.ts").unwrap();
|
||||||
let worker_state =
|
let worker_state =
|
||||||
State::new(&global_state, Some(permissions), entry_point, None, true)
|
CliState::new(&global_state, Some(permissions), entry_point, None, true)
|
||||||
.expect("Unable to create worker state");
|
.expect("Unable to create worker state");
|
||||||
|
|
||||||
// TODO(bartlomieju): this metric is never used anywhere
|
// TODO(bartlomieju): this metric is never used anywhere
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::js;
|
use crate::js;
|
||||||
use crate::ops;
|
use crate::ops;
|
||||||
use crate::state::State;
|
use crate::state::CliState;
|
||||||
use crate::worker::Worker;
|
use crate::worker::Worker;
|
||||||
use crate::worker::WorkerEvent;
|
use crate::worker::WorkerEvent;
|
||||||
use crate::worker::WorkerHandle;
|
use crate::worker::WorkerHandle;
|
||||||
|
@ -85,7 +85,7 @@ pub struct WebWorker {
|
||||||
impl WebWorker {
|
impl WebWorker {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
name: String,
|
name: String,
|
||||||
state: &Rc<State>,
|
state: &Rc<CliState>,
|
||||||
has_deno_namespace: bool,
|
has_deno_namespace: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut worker = Worker::new(name, Some(js::deno_isolate_init()), &state);
|
let mut worker = Worker::new(name, Some(js::deno_isolate_init()), &state);
|
||||||
|
@ -239,12 +239,12 @@ impl Future for WebWorker {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::state::State;
|
use crate::state::CliState;
|
||||||
use crate::tokio_util;
|
use crate::tokio_util;
|
||||||
use crate::worker::WorkerEvent;
|
use crate::worker::WorkerEvent;
|
||||||
|
|
||||||
fn create_test_worker() -> WebWorker {
|
fn create_test_worker() -> WebWorker {
|
||||||
let state = State::mock("./hello.js");
|
let state = CliState::mock("./hello.js");
|
||||||
let mut worker = WebWorker::new("TEST".to_string(), &state, false);
|
let mut worker = WebWorker::new("TEST".to_string(), &state, false);
|
||||||
worker
|
worker
|
||||||
.execute("bootstrap.workerRuntime(\"TEST\", false)")
|
.execute("bootstrap.workerRuntime(\"TEST\", false)")
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::inspector::DenoInspector;
|
||||||
use crate::js;
|
use crate::js;
|
||||||
use crate::ops;
|
use crate::ops;
|
||||||
use crate::ops::io::get_stdio;
|
use crate::ops::io::get_stdio;
|
||||||
use crate::state::State;
|
use crate::state::CliState;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::JsRuntime;
|
use deno_core::JsRuntime;
|
||||||
use deno_core::ModuleId;
|
use deno_core::ModuleId;
|
||||||
|
@ -94,7 +94,7 @@ pub struct Worker {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub isolate: JsRuntime,
|
pub isolate: JsRuntime,
|
||||||
pub inspector: Option<Box<DenoInspector>>,
|
pub inspector: Option<Box<DenoInspector>>,
|
||||||
pub state: Rc<State>,
|
pub state: Rc<CliState>,
|
||||||
pub waker: AtomicWaker,
|
pub waker: AtomicWaker,
|
||||||
pub(crate) internal_channels: WorkerChannelsInternal,
|
pub(crate) internal_channels: WorkerChannelsInternal,
|
||||||
external_channels: WorkerHandle,
|
external_channels: WorkerHandle,
|
||||||
|
@ -104,7 +104,7 @@ impl Worker {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
name: String,
|
name: String,
|
||||||
startup_snapshot: Option<Snapshot>,
|
startup_snapshot: Option<Snapshot>,
|
||||||
state: &Rc<State>,
|
state: &Rc<CliState>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut isolate = JsRuntime::new(RuntimeOptions {
|
let mut isolate = JsRuntime::new(RuntimeOptions {
|
||||||
module_loader: Some(state.clone()),
|
module_loader: Some(state.clone()),
|
||||||
|
@ -264,7 +264,7 @@ impl MainWorker {
|
||||||
fn new(
|
fn new(
|
||||||
name: String,
|
name: String,
|
||||||
startup_snapshot: Option<Snapshot>,
|
startup_snapshot: Option<Snapshot>,
|
||||||
state: &Rc<State>,
|
state: &Rc<CliState>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut worker = Worker::new(name, startup_snapshot, state);
|
let mut worker = Worker::new(name, startup_snapshot, state);
|
||||||
{
|
{
|
||||||
|
@ -298,7 +298,7 @@ impl MainWorker {
|
||||||
global_state: &Arc<GlobalState>,
|
global_state: &Arc<GlobalState>,
|
||||||
main_module: ModuleSpecifier,
|
main_module: ModuleSpecifier,
|
||||||
) -> Result<MainWorker, AnyError> {
|
) -> Result<MainWorker, AnyError> {
|
||||||
let state = State::new(
|
let state = CliState::new(
|
||||||
&global_state,
|
&global_state,
|
||||||
None,
|
None,
|
||||||
main_module,
|
main_module,
|
||||||
|
@ -362,7 +362,7 @@ mod tests {
|
||||||
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
|
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
|
||||||
let global_state = GlobalState::new(flags::Flags::default()).unwrap();
|
let global_state = GlobalState::new(flags::Flags::default()).unwrap();
|
||||||
let state =
|
let state =
|
||||||
State::new(&global_state, None, module_specifier.clone(), None, false)
|
CliState::new(&global_state, None, module_specifier.clone(), None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
tokio_util::run_basic(async {
|
tokio_util::run_basic(async {
|
||||||
let mut worker = MainWorker::new("TEST".to_string(), None, &state);
|
let mut worker = MainWorker::new("TEST".to_string(), None, &state);
|
||||||
|
@ -389,7 +389,7 @@ mod tests {
|
||||||
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
|
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
|
||||||
let global_state = GlobalState::new(flags::Flags::default()).unwrap();
|
let global_state = GlobalState::new(flags::Flags::default()).unwrap();
|
||||||
let state =
|
let state =
|
||||||
State::new(&global_state, None, module_specifier.clone(), None, false)
|
CliState::new(&global_state, None, module_specifier.clone(), None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
tokio_util::run_basic(async {
|
tokio_util::run_basic(async {
|
||||||
let mut worker = MainWorker::new("TEST".to_string(), None, &state);
|
let mut worker = MainWorker::new("TEST".to_string(), None, &state);
|
||||||
|
@ -424,7 +424,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
let global_state = GlobalState::new(flags).unwrap();
|
let global_state = GlobalState::new(flags).unwrap();
|
||||||
let state =
|
let state =
|
||||||
State::new(&global_state, None, module_specifier.clone(), None, false)
|
CliState::new(&global_state, None, module_specifier.clone(), None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut worker = MainWorker::new(
|
let mut worker = MainWorker::new(
|
||||||
"TEST".to_string(),
|
"TEST".to_string(),
|
||||||
|
@ -445,7 +445,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_test_worker() -> MainWorker {
|
fn create_test_worker() -> MainWorker {
|
||||||
let state = State::mock("./hello.js");
|
let state = CliState::mock("./hello.js");
|
||||||
let mut worker = MainWorker::new(
|
let mut worker = MainWorker::new(
|
||||||
"TEST".to_string(),
|
"TEST".to_string(),
|
||||||
Some(js::deno_isolate_init()),
|
Some(js::deno_isolate_init()),
|
||||||
|
|
Loading…
Reference in a new issue