1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-22 06:09:25 -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 MAX_SOURCE_LINE_LENGTH: usize = 150;
const UNSTABLE_DENO_PROPS: &[&str] = &[ const UNSTABLE_DENO_PROPS: &[&str] = &[
"BenchDefinition",
"CompilerOptions", "CompilerOptions",
"CreateHttpClientOptions", "CreateHttpClientOptions",
"DatagramConn", "DatagramConn",
@ -39,6 +40,7 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"UnixListenOptions", "UnixListenOptions",
"addSignalListener", "addSignalListener",
"applySourceMap", "applySourceMap",
"bench",
"connect", "connect",
"consoleSize", "consoleSize",
"createHttpClient", "createHttpClient",

View file

@ -12,7 +12,7 @@ use std::time;
use tokio::sync::mpsc::UnboundedSender; use tokio::sync::mpsc::UnboundedSender;
use uuid::Uuid; use uuid::Uuid;
pub fn init(sender: UnboundedSender<BenchEvent>) -> Extension { pub fn init(sender: UnboundedSender<BenchEvent>, unstable: bool) -> Extension {
Extension::builder() Extension::builder()
.ops(vec![ .ops(vec![
op_pledge_test_permissions::decl(), op_pledge_test_permissions::decl(),
@ -20,14 +20,36 @@ pub fn init(sender: UnboundedSender<BenchEvent>) -> Extension {
op_get_bench_origin::decl(), op_get_bench_origin::decl(),
op_dispatch_bench_event::decl(), op_dispatch_bench_event::decl(),
op_bench_now::decl(), op_bench_now::decl(),
op_bench_check_unstable::decl(),
]) ])
.state(move |state| { .state(move |state| {
state.put(sender.clone()); state.put(sender.clone());
state.put(Unstable(unstable));
Ok(()) Ok(())
}) })
.build() .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)] #[derive(Clone)]
struct PermissionsHolder(Uuid, Permissions); struct PermissionsHolder(Uuid, Permissions);

View file

@ -2,6 +2,12 @@
use crate::itest; use crate::itest;
itest!(requires_unstable {
args: "bench bench/requires_unstable.js",
exit_code: 70,
output: "bench/requires_unstable.out",
});
itest!(overloads { itest!(overloads {
args: "bench --unstable bench/overloads.ts", args: "bench --unstable bench/overloads.ts",
exit_code: 0, 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, &ps,
specifier.clone(), specifier.clone(),
permissions, permissions,
vec![ops::bench::init(channel.clone())], vec![ops::bench::init(channel.clone(), ps.flags.unstable)],
); );
if options.compat_mode { if options.compat_mode {

View file

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