diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-10-12 17:55:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-12 15:55:50 +0000 |
commit | c464cd7073c761780b3170a48542c387560e3f26 (patch) | |
tree | 881a26d05423f9c696c8f35ce8bd2d72d562b1ea /runtime/ops | |
parent | 5dd010a4fbeb0602891ea537b98216b8ad7d27a7 (diff) |
refactor: FeatureChecker integration in ext/ crates (#20797)
Towards https://github.com/denoland/deno/issues/20779.
Diffstat (limited to 'runtime/ops')
-rw-r--r-- | runtime/ops/http.rs | 4 | ||||
-rw-r--r-- | runtime/ops/mod.rs | 6 | ||||
-rw-r--r-- | runtime/ops/process.rs | 8 | ||||
-rw-r--r-- | runtime/ops/worker_host.rs | 8 |
4 files changed, 19 insertions, 7 deletions
diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs index 07757850c..f0f0510da 100644 --- a/runtime/ops/http.rs +++ b/runtime/ops/http.rs @@ -27,6 +27,8 @@ use deno_net::io::UnixStreamResource; #[cfg(unix)] use tokio::net::UnixStream; +pub const UNSTABLE_FEATURE_NAME: &str = "http"; + deno_core::extension!( deno_http_runtime, ops = [op_http_start, op_http_upgrade], @@ -73,7 +75,7 @@ fn op_http_start( .resource_table .take::<deno_net::io::UnixStreamResource>(tcp_stream_rid) { - super::check_unstable(state, "Deno.serveHttp"); + super::check_unstable(state, UNSTABLE_FEATURE_NAME, "Deno.serveHttp"); // This UNIX socket might be used somewhere else. If it's the case, we cannot proceed with the // process of starting a HTTP server on top of this UNIX socket, so we just return a bad diff --git a/runtime/ops/mod.rs b/runtime/ops/mod.rs index cdafd61ec..bafa6c571 100644 --- a/runtime/ops/mod.rs +++ b/runtime/ops/mod.rs @@ -15,10 +15,12 @@ pub mod worker_host; use deno_core::OpState; /// Helper for checking unstable features. Used for sync ops. -pub fn check_unstable(state: &OpState, api_name: &str) { +pub fn check_unstable(state: &OpState, feature: &str, api_name: &str) { + // TODO(bartlomieju): replace with `state.feature_checker.check_or_exit` + // once we phase out `check_or_exit_with_legacy_fallback` state .feature_checker - .check_legacy_unstable_or_exit(api_name); + .check_or_exit_with_legacy_fallback(feature, api_name); } pub struct TestingFeaturesEnabled(pub bool); diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index 51c9f961a..1fdd4bf4d 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -34,6 +34,8 @@ use std::os::unix::prelude::ExitStatusExt; #[cfg(unix)] use std::os::unix::process::CommandExt; +pub const UNSTABLE_FEATURE_NAME: &str = "process"; + #[derive(Copy, Clone, Eq, PartialEq, Deserialize)] #[serde(rename_all = "camelCase")] pub enum Stdio { @@ -503,7 +505,7 @@ mod deprecated { cwd.map(|d| c.current_dir(d)); if run_args.clear_env { - super::check_unstable(state, "Deno.run.clearEnv"); + super::check_unstable(state, UNSTABLE_FEATURE_NAME, "Deno.run.clearEnv"); c.env_clear(); } for (key, value) in &env { @@ -512,12 +514,12 @@ mod deprecated { #[cfg(unix)] if let Some(gid) = run_args.gid { - super::check_unstable(state, "Deno.run.gid"); + super::check_unstable(state, UNSTABLE_FEATURE_NAME, "Deno.run.gid"); c.gid(gid); } #[cfg(unix)] if let Some(uid) = run_args.uid { - super::check_unstable(state, "Deno.run.uid"); + super::check_unstable(state, UNSTABLE_FEATURE_NAME, "Deno.run.uid"); c.uid(uid); } #[cfg(unix)] diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index a77f57b60..960e35b3d 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -26,6 +26,8 @@ use std::collections::HashMap; use std::rc::Rc; use std::sync::Arc; +pub const UNSTABLE_FEATURE_NAME: &str = "worker"; + pub struct CreateWebWorkerArgs { pub name: String, pub worker_id: WorkerId, @@ -140,7 +142,11 @@ fn op_create_worker( } if args.permissions.is_some() { - super::check_unstable(state, "Worker.deno.permissions"); + super::check_unstable( + state, + UNSTABLE_FEATURE_NAME, + "Worker.deno.permissions", + ); } let parent_permissions = state.borrow_mut::<PermissionsContainer>(); let worker_permissions = if let Some(child_permissions_arg) = args.permissions |