mirror of
https://github.com/denoland/deno.git
synced 2025-09-20 09:29:48 +00:00

Some checks are pending
ci / publish canary (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / build libs (push) Blocked by required conditions
62 lines
1.4 KiB
Rust
62 lines
1.4 KiB
Rust
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
|
|
mod r#gen;
|
|
mod structs;
|
|
|
|
use std::collections::BTreeSet;
|
|
|
|
pub use r#gen::UNSTABLE_ENV_VAR_NAMES;
|
|
pub use r#gen::UNSTABLE_FEATURES;
|
|
pub use structs::UnstableFeatureKind;
|
|
|
|
pub const JS_SOURCE: deno_core::FastStaticString =
|
|
deno_core::ascii_str_include!("./gen.js");
|
|
|
|
pub type ExitCb = Box<dyn Fn(&str, &str) + Send + Sync>;
|
|
|
|
#[allow(clippy::print_stderr)]
|
|
#[allow(clippy::disallowed_methods)]
|
|
fn exit(feature: &str, api_name: &str) {
|
|
eprintln!("Feature '{feature}' for '{api_name}' was not specified, exiting.");
|
|
std::process::exit(70);
|
|
}
|
|
|
|
pub struct FeatureChecker {
|
|
features: BTreeSet<&'static str>,
|
|
exit_cb: ExitCb,
|
|
}
|
|
|
|
impl Default for FeatureChecker {
|
|
fn default() -> Self {
|
|
Self {
|
|
features: BTreeSet::new(),
|
|
exit_cb: Box::new(exit),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl FeatureChecker {
|
|
#[inline(always)]
|
|
pub fn check(&self, feature: &str) -> bool {
|
|
self.features.contains(feature)
|
|
}
|
|
|
|
pub fn enable_feature(&mut self, feature: &'static str) {
|
|
let inserted = self.features.insert(feature);
|
|
assert!(
|
|
inserted,
|
|
"Trying to enable a feature that is already enabled: {feature}",
|
|
);
|
|
}
|
|
|
|
#[inline(always)]
|
|
pub fn check_or_exit(&self, feature: &str, api_name: &str) {
|
|
if !self.check(feature) {
|
|
(self.exit_cb)(feature, api_name);
|
|
}
|
|
}
|
|
|
|
pub fn set_exit_cb(&mut self, cb: ExitCb) {
|
|
self.exit_cb = cb;
|
|
}
|
|
}
|