summaryrefslogtreecommitdiff
path: root/ext/fs/lib.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-10-04 21:42:17 +0200
committerGitHub <noreply@github.com>2023-10-04 21:42:17 +0200
commita5568066b3d979111134029f9e4f0c1b462b948e (patch)
tree14c4233cc01d55eda7f608b5194f6b088264b52e /ext/fs/lib.rs
parent9a46a824bd897e240af8a14f9d950ab6d95f42a5 (diff)
refactor: use deno_core::FeatureChecker for unstable checks (#20765)
Diffstat (limited to 'ext/fs/lib.rs')
-rw-r--r--ext/fs/lib.rs32
1 files changed, 4 insertions, 28 deletions
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);
},
);