summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-10-12 17:55:50 +0200
committerGitHub <noreply@github.com>2023-10-12 15:55:50 +0000
commitc464cd7073c761780b3170a48542c387560e3f26 (patch)
tree881a26d05423f9c696c8f35ce8bd2d72d562b1ea /ext
parent5dd010a4fbeb0602891ea537b98216b8ad7d27a7 (diff)
refactor: FeatureChecker integration in ext/ crates (#20797)
Towards https://github.com/denoland/deno/issues/20779.
Diffstat (limited to 'ext')
-rw-r--r--ext/broadcast_channel/lib.rs11
-rw-r--r--ext/ffi/lib.rs6
-rw-r--r--ext/fs/lib.rs6
-rw-r--r--ext/http/http_next.rs10
-rw-r--r--ext/kv/lib.rs6
-rw-r--r--ext/net/lib.rs6
-rw-r--r--ext/net/ops.rs8
7 files changed, 41 insertions, 12 deletions
diff --git a/ext/broadcast_channel/lib.rs b/ext/broadcast_channel/lib.rs
index 49cc78415..6079a8310 100644
--- a/ext/broadcast_channel/lib.rs
+++ b/ext/broadcast_channel/lib.rs
@@ -17,6 +17,8 @@ use deno_core::OpState;
use deno_core::Resource;
use deno_core::ResourceId;
+pub const UNSTABLE_FEATURE_NAME: &str = "broadcast-channel";
+
#[async_trait]
pub trait BroadcastChannel: Clone {
type Resource: Resource;
@@ -48,9 +50,12 @@ pub fn op_broadcast_subscribe<BC>(
where
BC: BroadcastChannel + 'static,
{
- state
- .feature_checker
- .check_legacy_unstable_or_exit("BroadcastChannel");
+ // TODO(bartlomieju): replace with `state.feature_checker.check_or_exit`
+ // once we phase out `check_or_exit_with_legacy_fallback`
+ state.feature_checker.check_or_exit_with_legacy_fallback(
+ UNSTABLE_FEATURE_NAME,
+ "BroadcastChannel",
+ );
let bc = state.borrow::<BC>();
let resource = bc.subscribe()?;
Ok(state.resource_table.add(resource))
diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs
index a3cd0ebda..0541e1eeb 100644
--- a/ext/ffi/lib.rs
+++ b/ext/ffi/lib.rs
@@ -45,10 +45,14 @@ const _: () = {
pub(crate) const MAX_SAFE_INTEGER: isize = 9007199254740991;
pub(crate) const MIN_SAFE_INTEGER: isize = -9007199254740991;
+pub const UNSTABLE_FEATURE_NAME: &str = "ffi";
+
fn check_unstable(state: &OpState, 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(UNSTABLE_FEATURE_NAME, api_name)
}
pub trait FfiPermissions {
diff --git a/ext/fs/lib.rs b/ext/fs/lib.rs
index ab19540b5..d36d8b5c2 100644
--- a/ext/fs/lib.rs
+++ b/ext/fs/lib.rs
@@ -64,11 +64,15 @@ pub trait FsPermissions {
}
}
+pub const UNSTABLE_FEATURE_NAME: &str = "fs";
+
/// Helper for checking unstable features. Used for sync ops.
fn check_unstable(state: &OpState, 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(UNSTABLE_FEATURE_NAME, api_name);
}
deno_core::extension!(deno_fs,
diff --git a/ext/http/http_next.rs b/ext/http/http_next.rs
index 90f7f0b1d..522df280f 100644
--- a/ext/http/http_next.rs
+++ b/ext/http/http_next.rs
@@ -83,6 +83,8 @@ static USE_WRITEV: Lazy<bool> = Lazy::new(|| {
false
});
+pub const UNSTABLE_FEATURE_NAME: &str = "http";
+
/// All HTTP/2 connections start with this byte string.
///
/// In HTTP/2, each endpoint is required to send a connection preface as a final confirmation
@@ -1105,10 +1107,16 @@ pub async fn op_http_close(
.take::<HttpJoinHandle>(rid)?;
if graceful {
+ // TODO(bartlomieju): replace with `state.feature_checker.check_or_exit`
+ // once we phase out `check_or_exit_with_legacy_fallback`
state
.borrow()
.feature_checker
- .check_legacy_unstable_or_exit("Deno.Server.shutdown");
+ .check_or_exit_with_legacy_fallback(
+ UNSTABLE_FEATURE_NAME,
+ "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 3056e4660..e99b14552 100644
--- a/ext/kv/lib.rs
+++ b/ext/kv/lib.rs
@@ -33,6 +33,8 @@ use serde::Serialize;
pub use crate::interface::*;
+pub const UNSTABLE_FEATURE_NAME: &str = "kv";
+
const MAX_WRITE_KEY_SIZE_BYTES: usize = 2048;
// range selectors can contain 0x00 or 0xff suffixes
const MAX_READ_KEY_SIZE_BYTES: usize = MAX_WRITE_KEY_SIZE_BYTES + 1;
@@ -89,9 +91,11 @@ where
{
let handler = {
let state = state.borrow();
+ // 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("Deno.openKv");
+ .check_or_exit_with_legacy_fallback(UNSTABLE_FEATURE_NAME, "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 1fc7e3420..fb8dda514 100644
--- a/ext/net/lib.rs
+++ b/ext/net/lib.rs
@@ -16,6 +16,8 @@ use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
+pub const UNSTABLE_FEATURE_NAME: &str = "net";
+
pub trait NetPermissions {
fn check_net<T: AsRef<str>>(
&mut self,
@@ -29,9 +31,11 @@ pub trait NetPermissions {
/// Helper for checking unstable features. Used for sync ops.
fn check_unstable(state: &OpState, 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(UNSTABLE_FEATURE_NAME, api_name);
}
pub fn get_declaration() -> PathBuf {
diff --git a/ext/net/ops.rs b/ext/net/ops.rs
index 5738620f8..bbf897555 100644
--- a/ext/net/ops.rs
+++ b/ext/net/ops.rs
@@ -1041,16 +1041,16 @@ mod tests {
}
);
+ let mut feature_checker = deno_core::FeatureChecker::default();
+ feature_checker.enable_legacy_unstable();
+
let mut runtime = JsRuntime::new(RuntimeOptions {
extensions: vec![test_ext::init_ops()],
+ feature_checker: Some(Arc::new(feature_checker)),
..Default::default()
});
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 {