diff options
Diffstat (limited to 'cli/ops/mod.rs')
-rw-r--r-- | cli/ops/mod.rs | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs index b450f8989..56c0f1ad5 100644 --- a/cli/ops/mod.rs +++ b/cli/ops/mod.rs @@ -27,7 +27,6 @@ pub mod websocket; pub mod worker_host; use crate::metrics::metrics_op; -use crate::program_state::ProgramState; use deno_core::error::AnyError; use deno_core::json_op_async; use deno_core::json_op_sync; @@ -39,7 +38,6 @@ use deno_core::ZeroCopyBuf; use std::cell::RefCell; use std::future::Future; use std::rc::Rc; -use std::sync::Arc; pub fn reg_json_async<F, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F) where @@ -57,24 +55,33 @@ where rt.register_op(name, metrics_op(json_op_sync(op_fn))); } +pub struct UnstableChecker { + pub unstable: bool, +} + +impl UnstableChecker { + /// 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. + // NOTE(bartlomieju): keep in sync with `cli/program_state.rs` + pub fn check_unstable(&self, api_name: &str) { + if !self.unstable { + eprintln!( + "Unstable API '{}'. The --unstable flag must be provided.", + api_name + ); + std::process::exit(70); + } + } +} /// Helper for checking unstable features. Used for sync ops. pub fn check_unstable(state: &OpState, api_name: &str) { - state.borrow::<Arc<ProgramState>>().check_unstable(api_name) + state.borrow::<UnstableChecker>().check_unstable(api_name) } /// Helper for checking unstable features. Used for async ops. pub fn check_unstable2(state: &Rc<RefCell<OpState>>, api_name: &str) { let state = state.borrow(); - state.borrow::<Arc<ProgramState>>().check_unstable(api_name) -} - -/// Helper for extracting the commonly used state. Used for sync ops. -pub fn program_state(state: &OpState) -> Arc<ProgramState> { - state.borrow::<Arc<ProgramState>>().clone() -} - -/// Helper for extracting the commonly used state. Used for async ops. -pub fn global_state2(state: &Rc<RefCell<OpState>>) -> Arc<ProgramState> { - let state = state.borrow(); - state.borrow::<Arc<ProgramState>>().clone() + state.borrow::<UnstableChecker>().check_unstable(api_name) } |