1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(bench): require --unstable flag in JavaScript (#14091)

This commit is contained in:
Bartek Iwańczuk 2022-03-23 16:33:42 +01:00 committed by GitHub
parent 53dac7451b
commit b82ded84d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 2 deletions

View file

@ -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",

View file

@ -12,7 +12,7 @@ use std::time;
use tokio::sync::mpsc::UnboundedSender;
use uuid::Uuid;
pub fn init(sender: UnboundedSender<BenchEvent>) -> Extension {
pub fn init(sender: UnboundedSender<BenchEvent>, unstable: bool) -> Extension {
Extension::builder()
.ops(vec![
op_pledge_test_permissions::decl(),
@ -20,14 +20,36 @@ pub fn init(sender: UnboundedSender<BenchEvent>) -> 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::<Unstable>();
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);

View file

@ -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,

View file

@ -0,0 +1 @@
Deno.bench("bench0", () => {});

View file

@ -0,0 +1 @@
Unstable API 'Deno.bench'. The --unstable flag must be provided.

View file

@ -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 {

View file

@ -639,6 +639,7 @@
optionsOrFn,
maybeFn,
) {
core.opSync("op_bench_check_unstable");
let benchDef;
const defaults = {
ignore: false,