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 | |
parent | 5dd010a4fbeb0602891ea537b98216b8ad7d27a7 (diff) |
refactor: FeatureChecker integration in ext/ crates (#20797)
Towards https://github.com/denoland/deno/issues/20779.
Diffstat (limited to 'runtime')
-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 | ||||
-rw-r--r-- | runtime/web_worker.rs | 12 | ||||
-rw-r--r-- | runtime/worker.rs | 13 |
6 files changed, 26 insertions, 25 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 diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index f37a77d88..c1fe5a619 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -25,6 +25,7 @@ use deno_core::v8; use deno_core::CancelHandle; use deno_core::CompiledWasmModuleStore; use deno_core::Extension; +use deno_core::FeatureChecker; use deno_core::GetErrorClassFn; use deno_core::JsRuntime; use deno_core::ModuleCode; @@ -349,6 +350,7 @@ pub struct WebWorkerOptions { pub compiled_wasm_module_store: Option<CompiledWasmModuleStore>, pub cache_storage_dir: Option<std::path::PathBuf>, pub stdio: Stdio, + pub feature_checker: Arc<FeatureChecker>, } impl WebWorker { @@ -385,7 +387,6 @@ impl WebWorker { ); // Permissions: many ops depend on this - let unstable = options.bootstrap.unstable; let enable_testing_features = options.bootstrap.enable_testing_features; let create_cache = options.cache_storage_dir.map(|storage_dir| { let create_cache_fn = move || SqliteBackedCache::new(storage_dir.clone()); @@ -509,17 +510,10 @@ impl WebWorker { extensions, inspector: options.maybe_inspector_server.is_some(), preserve_snapshotted_modules, + feature_checker: Some(options.feature_checker.clone()), ..Default::default() }); - if unstable { - let op_state = js_runtime.op_state(); - op_state - .borrow_mut() - .feature_checker - .enable_legacy_unstable(); - } - if let Some(server) = options.maybe_inspector_server.clone() { server.register_inspector( main_module.to_string(), diff --git a/runtime/worker.rs b/runtime/worker.rs index e8874575a..e8d9ca6bc 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -18,6 +18,7 @@ use deno_core::futures::Future; use deno_core::v8; use deno_core::CompiledWasmModuleStore; use deno_core::Extension; +use deno_core::FeatureChecker; use deno_core::FsModuleLoader; use deno_core::GetErrorClassFn; use deno_core::JsRuntime; @@ -141,6 +142,7 @@ pub struct WorkerOptions { /// `WebAssembly.Module` objects cannot be serialized. pub compiled_wasm_module_store: Option<CompiledWasmModuleStore>, pub stdio: Stdio, + pub feature_checker: Arc<FeatureChecker>, } impl Default for WorkerOptions { @@ -172,6 +174,7 @@ impl Default for WorkerOptions { create_params: Default::default(), bootstrap: Default::default(), stdio: Default::default(), + feature_checker: Default::default(), } } } @@ -205,7 +208,6 @@ impl MainWorker { ); // Permissions: many ops depend on this - let unstable = options.bootstrap.unstable; let enable_testing_features = options.bootstrap.enable_testing_features; let exit_code = ExitCode(Arc::new(AtomicI32::new(0))); let create_cache = options.cache_storage_dir.map(|storage_dir| { @@ -334,17 +336,10 @@ impl MainWorker { preserve_snapshotted_modules, inspector: options.maybe_inspector_server.is_some(), is_main: true, + feature_checker: Some(options.feature_checker.clone()), ..Default::default() }); - if unstable { - let op_state = js_runtime.op_state(); - op_state - .borrow_mut() - .feature_checker - .enable_legacy_unstable(); - } - if let Some(server) = options.maybe_inspector_server.clone() { server.register_inspector( main_module.to_string(), |