From b82ded84d341cda98821592556804a529638589c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 23 Mar 2022 16:33:42 +0100 Subject: fix(bench): require --unstable flag in JavaScript (#14091) --- cli/ops/bench.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'cli/ops') diff --git a/cli/ops/bench.rs b/cli/ops/bench.rs index 4b7d6743f..ea040b4a5 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); -- cgit v1.2.3