diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/lib.rs | 86 | ||||
-rw-r--r-- | runtime/ops/bootstrap.rs | 18 |
2 files changed, 104 insertions, 0 deletions
diff --git a/runtime/lib.rs b/runtime/lib.rs index 5aa4e21a1..fd791974d 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -43,3 +43,89 @@ pub use worker_bootstrap::WorkerLogLevel; mod shared; pub use shared::runtime; + +// NOTE(bartlomieju): keep IDs in sync with `runtime/90_deno_ns.js` (search for `unstableFeatures`) +pub static UNSTABLE_GRANULAR_FLAGS: &[( + // flag name + &str, + // help text + &str, + // id to enable it in runtime/99_main.js + i32, +)] = &[ + ( + deno_broadcast_channel::UNSTABLE_FEATURE_NAME, + "Enable unstable `BroadcastChannel` API", + 1, + ), + ( + deno_cron::UNSTABLE_FEATURE_NAME, + "Enable unstable Deno.cron API", + 2, + ), + ( + deno_ffi::UNSTABLE_FEATURE_NAME, + "Enable unstable FFI APIs", + 3, + ), + ( + deno_fs::UNSTABLE_FEATURE_NAME, + "Enable unstable file system APIs", + 4, + ), + ( + ops::http::UNSTABLE_FEATURE_NAME, + "Enable unstable HTTP APIs", + 5, + ), + ( + deno_kv::UNSTABLE_FEATURE_NAME, + "Enable unstable Key-Value store APIs", + 6, + ), + ( + deno_net::UNSTABLE_FEATURE_NAME, + "Enable unstable net APIs", + 7, + ), + ( + "temporal", + "Enable unstable Temporal API", + // Not used in JS + 8, + ), + ( + "unsafe-proto", + "Enable unsafe __proto__ support. This is a security risk.", + // This number is used directly in the JS code. Search + // for "unstableIds" to see where it's used. + 9, + ), + ( + deno_webgpu::UNSTABLE_FEATURE_NAME, + "Enable unstable `WebGPU` API", + 10, + ), + ( + ops::worker_host::UNSTABLE_FEATURE_NAME, + "Enable unstable Web Worker APIs", + 11, + ), +]; + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn unstable_granular_flag_names_sorted() { + let flags = UNSTABLE_GRANULAR_FLAGS + .iter() + .map(|(name, _, _)| name.to_string()) + .collect::<Vec<_>>(); + let mut sorted_flags = flags.clone(); + sorted_flags.sort(); + // sort the flags by name so they appear nicely in the help text + assert_eq!(flags, sorted_flags); + } +} diff --git a/runtime/ops/bootstrap.rs b/runtime/ops/bootstrap.rs index 1d4039d73..7de532a9f 100644 --- a/runtime/ops/bootstrap.rs +++ b/runtime/ops/bootstrap.rs @@ -17,6 +17,7 @@ deno_core::extension!( op_bootstrap_log_level, op_bootstrap_no_color, op_bootstrap_is_tty, + op_bootstrap_unstable_args, op_snapshot_options, ], options = { @@ -70,6 +71,23 @@ pub fn op_bootstrap_user_agent(state: &mut OpState) -> String { } #[op2] +#[serde] +pub fn op_bootstrap_unstable_args(state: &mut OpState) -> Vec<String> { + let options = state.borrow::<BootstrapOptions>(); + if options.unstable { + return vec!["--unstable".to_string()]; + } + + let mut flags = Vec::new(); + for (name, _, id) in crate::UNSTABLE_GRANULAR_FLAGS.iter() { + if options.unstable_features.contains(id) { + flags.push(format!("--unstable-{}", name)); + } + } + flags +} + +#[op2] #[string] pub fn op_bootstrap_language(state: &mut OpState) -> String { state.borrow::<BootstrapOptions>().locale.clone() |