diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/broadcast_channel/lib.rs | 16 | ||||
-rw-r--r-- | ext/ffi/call.rs | 6 | ||||
-rw-r--r-- | ext/ffi/lib.rs | 25 | ||||
-rw-r--r-- | ext/fs/lib.rs | 32 | ||||
-rw-r--r-- | ext/fs/ops.rs | 5 | ||||
-rw-r--r-- | ext/http/http_next.rs | 5 | ||||
-rw-r--r-- | ext/kv/lib.rs | 22 | ||||
-rw-r--r-- | ext/net/lib.rs | 39 | ||||
-rw-r--r-- | ext/net/ops.rs | 6 | ||||
-rw-r--r-- | ext/net/ops_tls.rs | 4 | ||||
-rw-r--r-- | ext/net/ops_unix.rs | 2 |
11 files changed, 32 insertions, 130 deletions
diff --git a/ext/broadcast_channel/lib.rs b/ext/broadcast_channel/lib.rs index 6ee10f9c0..49cc78415 100644 --- a/ext/broadcast_channel/lib.rs +++ b/ext/broadcast_channel/lib.rs @@ -40,8 +40,6 @@ pub trait BroadcastChannel: Clone { pub type Message = (String, Vec<u8>); -struct Unstable(bool); // --unstable - #[op2(fast)] #[smi] pub fn op_broadcast_subscribe<BC>( @@ -50,15 +48,9 @@ pub fn op_broadcast_subscribe<BC>( where BC: BroadcastChannel + 'static, { - let unstable = state.borrow::<Unstable>().0; - - if !unstable { - eprintln!( - "Unstable API 'BroadcastChannel'. The --unstable flag must be provided.", - ); - std::process::exit(70); - } - + state + .feature_checker + .check_legacy_unstable_or_exit("BroadcastChannel"); let bc = state.borrow::<BC>(); let resource = bc.subscribe()?; Ok(state.resource_table.add(resource)) @@ -118,11 +110,9 @@ deno_core::extension!(deno_broadcast_channel, esm = [ "01_broadcast_channel.js" ], options = { bc: BC, - unstable: bool, }, state = |state, options| { state.put(options.bc); - state.put(Unstable(options.unstable)); }, ); diff --git a/ext/ffi/call.rs b/ext/ffi/call.rs index ad12d0985..ea7875108 100644 --- a/ext/ffi/call.rs +++ b/ext/ffi/call.rs @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use crate::callback::PtrSymbol; -use crate::check_unstable2; +use crate::check_unstable; use crate::dlfcn::DynamicLibraryResource; use crate::ir::*; use crate::symbol::NativeType; @@ -285,7 +285,7 @@ pub fn op_ffi_call_ptr_nonblocking<FP>( where FP: FfiPermissions + 'static, { - check_unstable2(&state, "Deno.UnsafeFnPointer#call"); + check_unstable(&state.borrow(), "Deno.UnsafeFnPointer#call"); { let mut state = state.borrow_mut(); let permissions = state.borrow_mut::<FP>(); @@ -381,7 +381,7 @@ pub fn op_ffi_call_ptr<FP>( where FP: FfiPermissions + 'static, { - check_unstable2(&state, "Deno.UnsafeFnPointer#call"); + check_unstable(&state.borrow(), "Deno.UnsafeFnPointer#call"); { let mut state = state.borrow_mut(); let permissions = state.borrow_mut::<FP>(); diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs index b5a2a3bd5..1ca921119 100644 --- a/ext/ffi/lib.rs +++ b/ext/ffi/lib.rs @@ -45,22 +45,10 @@ const _: () = { pub(crate) const MAX_SAFE_INTEGER: isize = 9007199254740991; pub(crate) const MIN_SAFE_INTEGER: isize = -9007199254740991; -pub struct Unstable(pub bool); - fn check_unstable(state: &OpState, api_name: &str) { - let unstable = state.borrow::<Unstable>(); - - if !unstable.0 { - eprintln!( - "Unstable API '{api_name}'. The --unstable flag must be provided." - ); - std::process::exit(70); - } -} - -pub fn check_unstable2(state: &Rc<RefCell<OpState>>, api_name: &str) { - let state = state.borrow(); - check_unstable(&state, api_name) + state + .feature_checker + .check_legacy_unstable_or_exit(api_name); } pub trait FfiPermissions { @@ -108,13 +96,6 @@ deno_core::extension!(deno_ffi, op_ffi_unsafe_callback_ref, ], esm = [ "00_ffi.js" ], - options = { - unstable: bool, - }, - state = |state, options| { - // Stolen from deno_webgpu, is there a better option? - state.put(Unstable(options.unstable)); - }, event_loop_middleware = event_loop_middleware, ); diff --git a/ext/fs/lib.rs b/ext/fs/lib.rs index b028b12c1..ab19540b5 100644 --- a/ext/fs/lib.rs +++ b/ext/fs/lib.rs @@ -18,9 +18,7 @@ use crate::ops::*; use deno_core::error::AnyError; use deno_core::OpState; -use std::cell::RefCell; use std::path::Path; -use std::rc::Rc; pub trait FsPermissions { fn check_read(&mut self, path: &Path, api_name: &str) @@ -66,31 +64,11 @@ pub trait FsPermissions { } } -struct UnstableChecker { - pub unstable: bool, -} - -impl UnstableChecker { - // NOTE(bartlomieju): keep in sync with `cli/program_state.rs` - pub fn check_unstable(&self, api_name: &str) { - if !self.unstable { - eprintln!( - "Unstable API '{api_name}'. The --unstable flag must be provided." - ); - std::process::exit(70); - } - } -} - /// Helper for checking unstable features. Used for sync ops. -pub(crate) fn check_unstable(state: &OpState, api_name: &str) { - state.borrow::<UnstableChecker>().check_unstable(api_name) -} - -/// Helper for checking unstable features. Used for async ops. -pub(crate) fn check_unstable2(state: &Rc<RefCell<OpState>>, api_name: &str) { - let state = state.borrow(); - state.borrow::<UnstableChecker>().check_unstable(api_name) +fn check_unstable(state: &OpState, api_name: &str) { + state + .feature_checker + .check_legacy_unstable_or_exit(api_name); } deno_core::extension!(deno_fs, @@ -164,11 +142,9 @@ deno_core::extension!(deno_fs, ], esm = [ "30_fs.js" ], options = { - unstable: bool, fs: FileSystemRc, }, state = |state, options| { - state.put(UnstableChecker { unstable: options.unstable }); state.put(options.fs); }, ); diff --git a/ext/fs/ops.rs b/ext/fs/ops.rs index bc09a4a25..9fa8cf918 100644 --- a/ext/fs/ops.rs +++ b/ext/fs/ops.rs @@ -27,7 +27,6 @@ use rand::Rng; use serde::Serialize; use crate::check_unstable; -use crate::check_unstable2; use crate::interface::FileSystemRc; use crate::interface::FsDirEntry; use crate::interface::FsFileType; @@ -1422,7 +1421,7 @@ pub async fn op_fs_flock_async( #[smi] rid: ResourceId, exclusive: bool, ) -> Result<(), AnyError> { - check_unstable2(&state, "Deno.flock"); + check_unstable(&state.borrow(), "Deno.flock"); let file = FileResource::get_file(&state.borrow(), rid)?; file.lock_async(exclusive).await?; Ok(()) @@ -1444,7 +1443,7 @@ pub async fn op_fs_funlock_async( state: Rc<RefCell<OpState>>, #[smi] rid: ResourceId, ) -> Result<(), AnyError> { - check_unstable2(&state, "Deno.funlock"); + check_unstable(&state.borrow(), "Deno.funlock"); let file = FileResource::get_file(&state.borrow(), rid)?; file.unlock_async().await?; Ok(()) diff --git a/ext/http/http_next.rs b/ext/http/http_next.rs index 880925603..90f7f0b1d 100644 --- a/ext/http/http_next.rs +++ b/ext/http/http_next.rs @@ -1105,7 +1105,10 @@ pub async fn op_http_close( .take::<HttpJoinHandle>(rid)?; if graceful { - deno_net::check_unstable2(&state, "Deno.Server.shutdown"); + state + .borrow() + .feature_checker + .check_legacy_unstable_or_exit("Deno.Server.shutdown"); // In a graceful shutdown, we close the listener and allow all the remaining connections to drain join_handle.listen_cancel_handle().cancel(); } else { diff --git a/ext/kv/lib.rs b/ext/kv/lib.rs index 762009d2a..3056e4660 100644 --- a/ext/kv/lib.rs +++ b/ext/kv/lib.rs @@ -44,22 +44,6 @@ const MAX_MUTATIONS: usize = 1000; const MAX_TOTAL_MUTATION_SIZE_BYTES: usize = 800 * 1024; const MAX_TOTAL_KEY_SIZE_BYTES: usize = 80 * 1024; -struct UnstableChecker { - pub unstable: bool, -} - -impl UnstableChecker { - // NOTE(bartlomieju): keep in sync with `cli/program_state.rs` - pub fn check_unstable(&self, api_name: &str) { - if !self.unstable { - eprintln!( - "Unstable API '{api_name}'. The --unstable flag must be provided." - ); - std::process::exit(70); - } - } -} - deno_core::extension!(deno_kv, deps = [ deno_console ], parameters = [ DBH: DatabaseHandler ], @@ -74,11 +58,9 @@ deno_core::extension!(deno_kv, esm = [ "01_db.ts" ], options = { handler: DBH, - unstable: bool, }, state = |state, options| { state.put(Rc::new(options.handler)); - state.put(UnstableChecker { unstable: options.unstable }) } ); @@ -108,8 +90,8 @@ where let handler = { let state = state.borrow(); state - .borrow::<UnstableChecker>() - .check_unstable("Deno.openKv"); + .feature_checker + .check_legacy_unstable_or_exit("Deno.openKv"); state.borrow::<Rc<DBH>>().clone() }; let db = handler.open(state.clone(), path).await?; diff --git a/ext/net/lib.rs b/ext/net/lib.rs index 0e3778d5a..1fc7e3420 100644 --- a/ext/net/lib.rs +++ b/ext/net/lib.rs @@ -12,10 +12,8 @@ use deno_core::error::AnyError; use deno_core::OpState; use deno_tls::rustls::RootCertStore; use deno_tls::RootCertStoreProvider; -use std::cell::RefCell; use std::path::Path; use std::path::PathBuf; -use std::rc::Rc; use std::sync::Arc; pub trait NetPermissions { @@ -29,38 +27,11 @@ pub trait NetPermissions { -> Result<(), AnyError>; } -/// `UnstableChecker` is a struct so it can be placed inside `GothamState`; -/// using type alias for a bool could work, but there's a high chance -/// that there might be another type alias pointing to a bool, which -/// would override previously used alias. -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 '{api_name}'. The --unstable flag must be provided." - ); - std::process::exit(70); - } - } -} /// Helper for checking unstable features. Used for sync ops. -pub fn check_unstable(state: &OpState, api_name: &str) { - 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::<UnstableChecker>().check_unstable(api_name) +fn check_unstable(state: &OpState, api_name: &str) { + state + .feature_checker + .check_legacy_unstable_or_exit(api_name); } pub fn get_declaration() -> PathBuf { @@ -125,14 +96,12 @@ deno_core::extension!(deno_net, esm = [ "01_net.js", "02_tls.js" ], options = { root_cert_store_provider: Option<Arc<dyn RootCertStoreProvider>>, - unstable: bool, unsafely_ignore_certificate_errors: Option<Vec<String>>, }, state = |state, options| { state.put(DefaultTlsOptions { root_cert_store_provider: options.root_cert_store_provider, }); - state.put(UnstableChecker { unstable: options.unstable }); state.put(UnsafelyIgnoreCertificateErrors( options.unsafely_ignore_certificate_errors, )); diff --git a/ext/net/ops.rs b/ext/net/ops.rs index 5deaeb61e..5738620f8 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -771,7 +771,6 @@ fn rdata_to_return_record( #[cfg(test)] mod tests { use super::*; - use crate::UnstableChecker; use deno_core::futures::FutureExt; use deno_core::JsRuntime; use deno_core::RuntimeOptions; @@ -1039,7 +1038,6 @@ mod tests { test_ext, state = |state| { state.put(TestPermission {}); - state.put(UnstableChecker { unstable: true }); } ); @@ -1049,6 +1047,10 @@ mod tests { }); let conn_state = runtime.op_state(); + conn_state + .borrow_mut() + .feature_checker + .enable_legacy_unstable(); let server_addr: Vec<&str> = clone_addr.split(':').collect(); let ip_addr = IpAddr { diff --git a/ext/net/ops_tls.rs b/ext/net/ops_tls.rs index 0b84415b9..fe0e70a5c 100644 --- a/ext/net/ops_tls.rs +++ b/ext/net/ops_tls.rs @@ -878,10 +878,10 @@ where .and_then(|it| it.0.clone()); if args.cert_chain.is_some() { - super::check_unstable2(&state, "ConnectTlsOptions.certChain"); + super::check_unstable(&state.borrow(), "ConnectTlsOptions.certChain"); } if args.private_key.is_some() { - super::check_unstable2(&state, "ConnectTlsOptions.privateKey"); + super::check_unstable(&state.borrow(), "ConnectTlsOptions.privateKey"); } { diff --git a/ext/net/ops_unix.rs b/ext/net/ops_unix.rs index 7a5da9fa1..a36f1c30b 100644 --- a/ext/net/ops_unix.rs +++ b/ext/net/ops_unix.rs @@ -114,7 +114,7 @@ where NP: NetPermissions + 'static, { let address_path = Path::new(&path); - super::check_unstable2(&state, "Deno.connect"); + super::check_unstable(&state.borrow(), "Deno.connect"); { let mut state_ = state.borrow_mut(); state_ |