diff --git a/cli/diagnostics.rs b/cli/diagnostics.rs index d49916f2d6..8181c5fa01 100644 --- a/cli/diagnostics.rs +++ b/cli/diagnostics.rs @@ -15,6 +15,7 @@ use std::fmt; const MAX_SOURCE_LINE_LENGTH: usize = 150; const UNSTABLE_DENO_PROPS: &[&str] = &[ + "BenchDefinition", "CompilerOptions", "CreateHttpClientOptions", "DatagramConn", @@ -39,6 +40,7 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[ "UnixListenOptions", "addSignalListener", "applySourceMap", + "bench", "connect", "consoleSize", "createHttpClient", diff --git a/cli/ops/bench.rs b/cli/ops/bench.rs index 4b7d6743fa..ea040b4a54 100644 --- a/cli/ops/bench.rs +++ b/cli/ops/bench.rs @@ -12,7 +12,7 @@ use std::time; use tokio::sync::mpsc::UnboundedSender; use uuid::Uuid; -pub fn init(sender: UnboundedSender) -> Extension { +pub fn init(sender: UnboundedSender, unstable: bool) -> Extension { Extension::builder() .ops(vec![ op_pledge_test_permissions::decl(), @@ -20,14 +20,36 @@ pub fn init(sender: UnboundedSender) -> Extension { op_get_bench_origin::decl(), op_dispatch_bench_event::decl(), op_bench_now::decl(), + op_bench_check_unstable::decl(), ]) .state(move |state| { state.put(sender.clone()); + state.put(Unstable(unstable)); Ok(()) }) .build() } +pub struct Unstable(pub bool); + +fn check_unstable(state: &OpState, api_name: &str) { + let unstable = state.borrow::(); + + if !unstable.0 { + eprintln!( + "Unstable API '{}'. The --unstable flag must be provided.", + api_name + ); + std::process::exit(70); + } +} + +#[op] +fn op_bench_check_unstable(state: &mut OpState) -> Result<(), AnyError> { + check_unstable(state, "Deno.bench"); + Ok(()) +} + #[derive(Clone)] struct PermissionsHolder(Uuid, Permissions); diff --git a/cli/tests/integration/bench_tests.rs b/cli/tests/integration/bench_tests.rs index 06806c0b7a..2df08bdb52 100644 --- a/cli/tests/integration/bench_tests.rs +++ b/cli/tests/integration/bench_tests.rs @@ -2,6 +2,12 @@ use crate::itest; +itest!(requires_unstable { + args: "bench bench/requires_unstable.js", + exit_code: 70, + output: "bench/requires_unstable.out", +}); + itest!(overloads { args: "bench --unstable bench/overloads.ts", exit_code: 0, diff --git a/cli/tests/testdata/bench/requires_unstable.js b/cli/tests/testdata/bench/requires_unstable.js new file mode 100644 index 0000000000..06a07bb38c --- /dev/null +++ b/cli/tests/testdata/bench/requires_unstable.js @@ -0,0 +1 @@ +Deno.bench("bench0", () => {}); diff --git a/cli/tests/testdata/bench/requires_unstable.out b/cli/tests/testdata/bench/requires_unstable.out new file mode 100644 index 0000000000..574fb07e1a --- /dev/null +++ b/cli/tests/testdata/bench/requires_unstable.out @@ -0,0 +1 @@ +Unstable API 'Deno.bench'. The --unstable flag must be provided. diff --git a/cli/tools/bench.rs b/cli/tools/bench.rs index 8c3b67943b..7a1e260ace 100644 --- a/cli/tools/bench.rs +++ b/cli/tools/bench.rs @@ -295,7 +295,7 @@ async fn bench_specifier( &ps, specifier.clone(), permissions, - vec![ops::bench::init(channel.clone())], + vec![ops::bench::init(channel.clone(), ps.flags.unstable)], ); if options.compat_mode { diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js index 2c2b55d565..3e4a57df1c 100644 --- a/runtime/js/40_testing.js +++ b/runtime/js/40_testing.js @@ -639,6 +639,7 @@ optionsOrFn, maybeFn, ) { + core.opSync("op_bench_check_unstable"); let benchDef; const defaults = { ignore: false,