mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 16:19:12 -05:00
fix(bench): require --unstable flag in JavaScript (#14091)
This commit is contained in:
parent
53dac7451b
commit
b82ded84d3
7 changed files with 35 additions and 2 deletions
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
1
cli/tests/testdata/bench/requires_unstable.js
vendored
Normal file
1
cli/tests/testdata/bench/requires_unstable.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Deno.bench("bench0", () => {});
|
1
cli/tests/testdata/bench/requires_unstable.out
vendored
Normal file
1
cli/tests/testdata/bench/requires_unstable.out
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Unstable API 'Deno.bench'. The --unstable flag must be provided.
|
|
@ -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 {
|
||||
|
|
|
@ -639,6 +639,7 @@
|
|||
optionsOrFn,
|
||||
maybeFn,
|
||||
) {
|
||||
core.opSync("op_bench_check_unstable");
|
||||
let benchDef;
|
||||
const defaults = {
|
||||
ignore: false,
|
||||
|
|
Loading…
Reference in a new issue