mirror of
https://github.com/denoland/deno.git
synced 2025-01-12 00:54:02 -05:00
Rename --allow-high-precision to --allow-hrtime (#2398)
This commit is contained in:
parent
1386b6ead5
commit
2952fb5405
13 changed files with 47 additions and 53 deletions
38
cli/flags.rs
38
cli/flags.rs
|
@ -23,7 +23,7 @@ pub struct DenoFlags {
|
||||||
pub net_whitelist: Vec<String>,
|
pub net_whitelist: Vec<String>,
|
||||||
pub allow_env: bool,
|
pub allow_env: bool,
|
||||||
pub allow_run: bool,
|
pub allow_run: bool,
|
||||||
pub allow_high_precision: bool,
|
pub allow_hrtime: bool,
|
||||||
pub no_prompts: bool,
|
pub no_prompts: bool,
|
||||||
pub no_fetch: bool,
|
pub no_fetch: bool,
|
||||||
pub v8_flags: Option<Vec<String>>,
|
pub v8_flags: Option<Vec<String>>,
|
||||||
|
@ -230,9 +230,9 @@ ability to spawn subprocesses.
|
||||||
.long("allow-run")
|
.long("allow-run")
|
||||||
.help("Allow running subprocesses"),
|
.help("Allow running subprocesses"),
|
||||||
).arg(
|
).arg(
|
||||||
Arg::with_name("allow-high-precision")
|
Arg::with_name("allow-hrtime")
|
||||||
.long("allow-high-precision")
|
.long("allow-hrtime")
|
||||||
.help("Allow high precision time measurement"),
|
.help("Allow high resolution time measurement"),
|
||||||
).arg(
|
).arg(
|
||||||
Arg::with_name("allow-all")
|
Arg::with_name("allow-all")
|
||||||
.short("A")
|
.short("A")
|
||||||
|
@ -377,8 +377,8 @@ pub fn parse_flags(matches: ArgMatches) -> DenoFlags {
|
||||||
if run_matches.is_present("allow-run") {
|
if run_matches.is_present("allow-run") {
|
||||||
flags.allow_run = true;
|
flags.allow_run = true;
|
||||||
}
|
}
|
||||||
if run_matches.is_present("allow-high-precision") {
|
if run_matches.is_present("allow-hrtime") {
|
||||||
flags.allow_high_precision = true;
|
flags.allow_hrtime = true;
|
||||||
}
|
}
|
||||||
if run_matches.is_present("allow-all") {
|
if run_matches.is_present("allow-all") {
|
||||||
flags.allow_read = true;
|
flags.allow_read = true;
|
||||||
|
@ -387,7 +387,7 @@ pub fn parse_flags(matches: ArgMatches) -> DenoFlags {
|
||||||
flags.allow_run = true;
|
flags.allow_run = true;
|
||||||
flags.allow_read = true;
|
flags.allow_read = true;
|
||||||
flags.allow_write = true;
|
flags.allow_write = true;
|
||||||
flags.allow_high_precision = true;
|
flags.allow_hrtime = true;
|
||||||
}
|
}
|
||||||
if run_matches.is_present("no-prompt") {
|
if run_matches.is_present("no-prompt") {
|
||||||
flags.no_prompts = true;
|
flags.no_prompts = true;
|
||||||
|
@ -429,7 +429,7 @@ pub fn flags_from_vec(
|
||||||
flags.allow_run = true;
|
flags.allow_run = true;
|
||||||
flags.allow_read = true;
|
flags.allow_read = true;
|
||||||
flags.allow_write = true;
|
flags.allow_write = true;
|
||||||
flags.allow_high_precision = true;
|
flags.allow_hrtime = true;
|
||||||
let code: &str = eval_match.value_of("code").unwrap();
|
let code: &str = eval_match.value_of("code").unwrap();
|
||||||
argv.extend(vec![code.to_string()]);
|
argv.extend(vec![code.to_string()]);
|
||||||
DenoSubcommand::Eval
|
DenoSubcommand::Eval
|
||||||
|
@ -487,7 +487,7 @@ pub fn flags_from_vec(
|
||||||
flags.allow_run = true;
|
flags.allow_run = true;
|
||||||
flags.allow_read = true;
|
flags.allow_read = true;
|
||||||
flags.allow_write = true;
|
flags.allow_write = true;
|
||||||
flags.allow_high_precision = true;
|
flags.allow_hrtime = true;
|
||||||
let code: &str = eval_match.value_of("code").unwrap();
|
let code: &str = eval_match.value_of("code").unwrap();
|
||||||
flags.xeval_replvar =
|
flags.xeval_replvar =
|
||||||
Some(eval_match.value_of("replvar").unwrap_or("$").to_owned());
|
Some(eval_match.value_of("replvar").unwrap_or("$").to_owned());
|
||||||
|
@ -505,7 +505,7 @@ pub fn flags_from_vec(
|
||||||
flags.allow_run = true;
|
flags.allow_run = true;
|
||||||
flags.allow_read = true;
|
flags.allow_read = true;
|
||||||
flags.allow_write = true;
|
flags.allow_write = true;
|
||||||
flags.allow_high_precision = true;
|
flags.allow_hrtime = true;
|
||||||
DenoSubcommand::Repl
|
DenoSubcommand::Repl
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -651,7 +651,7 @@ mod tests {
|
||||||
allow_run: true,
|
allow_run: true,
|
||||||
allow_read: true,
|
allow_read: true,
|
||||||
allow_write: true,
|
allow_write: true,
|
||||||
allow_high_precision: true,
|
allow_hrtime: true,
|
||||||
..DenoFlags::default()
|
..DenoFlags::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -676,16 +676,12 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_flags_from_vec_9() {
|
fn test_flags_from_vec_9() {
|
||||||
let (flags, subcommand, argv) = flags_from_vec(svec![
|
let (flags, subcommand, argv) =
|
||||||
"deno",
|
flags_from_vec(svec!["deno", "run", "--allow-hrtime", "script.ts"]);
|
||||||
"run",
|
|
||||||
"--allow-high-precision",
|
|
||||||
"script.ts"
|
|
||||||
]);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
flags,
|
flags,
|
||||||
DenoFlags {
|
DenoFlags {
|
||||||
allow_high_precision: true,
|
allow_hrtime: true,
|
||||||
..DenoFlags::default()
|
..DenoFlags::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -795,7 +791,7 @@ mod tests {
|
||||||
allow_run: true,
|
allow_run: true,
|
||||||
allow_read: true,
|
allow_read: true,
|
||||||
allow_write: true,
|
allow_write: true,
|
||||||
allow_high_precision: true,
|
allow_hrtime: true,
|
||||||
..DenoFlags::default()
|
..DenoFlags::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -814,7 +810,7 @@ mod tests {
|
||||||
allow_run: true,
|
allow_run: true,
|
||||||
allow_read: true,
|
allow_read: true,
|
||||||
allow_write: true,
|
allow_write: true,
|
||||||
allow_high_precision: true,
|
allow_hrtime: true,
|
||||||
..DenoFlags::default()
|
..DenoFlags::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -841,7 +837,7 @@ mod tests {
|
||||||
allow_run: true,
|
allow_run: true,
|
||||||
allow_read: true,
|
allow_read: true,
|
||||||
allow_write: true,
|
allow_write: true,
|
||||||
allow_high_precision: true,
|
allow_hrtime: true,
|
||||||
xeval_replvar: Some("val".to_owned()),
|
xeval_replvar: Some("val".to_owned()),
|
||||||
xeval_delim: Some(" ".to_owned()),
|
xeval_delim: Some(" ".to_owned()),
|
||||||
..DenoFlags::default()
|
..DenoFlags::default()
|
||||||
|
|
|
@ -298,7 +298,7 @@ table PermissionsRes {
|
||||||
write: bool;
|
write: bool;
|
||||||
net: bool;
|
net: bool;
|
||||||
env: bool;
|
env: bool;
|
||||||
high_precision: bool;
|
hrtime: bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note this represents The WHOLE header of an http message, not just the key
|
// Note this represents The WHOLE header of an http message, not just the key
|
||||||
|
|
|
@ -261,7 +261,7 @@ fn op_now(
|
||||||
// If the permission is not enabled
|
// If the permission is not enabled
|
||||||
// Round the nano result on 2 milliseconds
|
// Round the nano result on 2 milliseconds
|
||||||
// see: https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp#Reduced_time_precision
|
// see: https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp#Reduced_time_precision
|
||||||
if !state.permissions.allows_high_precision() {
|
if !state.permissions.allows_hrtime() {
|
||||||
subsec_nanos -= subsec_nanos % reduced_time_precision
|
subsec_nanos -= subsec_nanos % reduced_time_precision
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,7 +640,7 @@ fn op_permissions(
|
||||||
write: state.permissions.allows_write(),
|
write: state.permissions.allows_write(),
|
||||||
net: state.permissions.allows_net(),
|
net: state.permissions.allows_net(),
|
||||||
env: state.permissions.allows_env(),
|
env: state.permissions.allows_env(),
|
||||||
high_precision: state.permissions.allows_high_precision(),
|
hrtime: state.permissions.allows_hrtime(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
ok_future(serialize_response(
|
ok_future(serialize_response(
|
||||||
|
@ -668,7 +668,7 @@ fn op_revoke_permission(
|
||||||
"write" => state.permissions.revoke_write(),
|
"write" => state.permissions.revoke_write(),
|
||||||
"net" => state.permissions.revoke_net(),
|
"net" => state.permissions.revoke_net(),
|
||||||
"env" => state.permissions.revoke_env(),
|
"env" => state.permissions.revoke_env(),
|
||||||
"highPrecision" => state.permissions.revoke_high_precision(),
|
"hrtime" => state.permissions.revoke_hrtime(),
|
||||||
_ => Ok(()),
|
_ => Ok(()),
|
||||||
};
|
};
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
|
|
|
@ -135,7 +135,7 @@ pub struct DenoPermissions {
|
||||||
pub net_whitelist: Arc<HashSet<String>>,
|
pub net_whitelist: Arc<HashSet<String>>,
|
||||||
pub allow_env: PermissionAccessor,
|
pub allow_env: PermissionAccessor,
|
||||||
pub allow_run: PermissionAccessor,
|
pub allow_run: PermissionAccessor,
|
||||||
pub allow_high_precision: PermissionAccessor,
|
pub allow_hrtime: PermissionAccessor,
|
||||||
pub no_prompts: AtomicBool,
|
pub no_prompts: AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,9 +152,7 @@ impl DenoPermissions {
|
||||||
net_whitelist: Arc::new(flags.net_whitelist.iter().cloned().collect()),
|
net_whitelist: Arc::new(flags.net_whitelist.iter().cloned().collect()),
|
||||||
allow_env: PermissionAccessor::from(flags.allow_env),
|
allow_env: PermissionAccessor::from(flags.allow_env),
|
||||||
allow_run: PermissionAccessor::from(flags.allow_run),
|
allow_run: PermissionAccessor::from(flags.allow_run),
|
||||||
allow_high_precision: PermissionAccessor::from(
|
allow_hrtime: PermissionAccessor::from(flags.allow_hrtime),
|
||||||
flags.allow_high_precision,
|
|
||||||
),
|
|
||||||
no_prompts: AtomicBool::new(flags.no_prompts),
|
no_prompts: AtomicBool::new(flags.no_prompts),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -350,8 +348,8 @@ impl DenoPermissions {
|
||||||
self.allow_env.is_allow()
|
self.allow_env.is_allow()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allows_high_precision(&self) -> bool {
|
pub fn allows_hrtime(&self) -> bool {
|
||||||
self.allow_high_precision.is_allow()
|
self.allow_hrtime.is_allow()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn revoke_run(&self) -> DenoResult<()> {
|
pub fn revoke_run(&self) -> DenoResult<()> {
|
||||||
|
@ -378,8 +376,8 @@ impl DenoPermissions {
|
||||||
self.allow_env.revoke();
|
self.allow_env.revoke();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn revoke_high_precision(&self) -> DenoResult<()> {
|
pub fn revoke_hrtime(&self) -> DenoResult<()> {
|
||||||
self.allow_high_precision.revoke();
|
self.allow_hrtime.revoke();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ import * as flatbuffers from "./flatbuffers";
|
||||||
import { assert } from "./util";
|
import { assert } from "./util";
|
||||||
|
|
||||||
export class Performance {
|
export class Performance {
|
||||||
/** Returns a current time from Deno's start.
|
/** Returns a current time from Deno's start in milliseconds.
|
||||||
* In milliseconds. Flag --allow-high-precision give
|
*
|
||||||
* a precise measure.
|
* Use the flag --allow-hrtime return a precise value.
|
||||||
*
|
*
|
||||||
* const t = performance.now();
|
* const t = performance.now();
|
||||||
* console.log(`${t} ms since start!`);
|
* console.log(`${t} ms since start!`);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
import { testPerm, assert } from "./test_util.ts";
|
import { testPerm, assert } from "./test_util.ts";
|
||||||
|
|
||||||
testPerm({ highPrecision: false }, function now(): void {
|
testPerm({ hrtime: false }, function now(): void {
|
||||||
const start = performance.now();
|
const start = performance.now();
|
||||||
setTimeout((): void => {
|
setTimeout((): void => {
|
||||||
const end = performance.now();
|
const end = performance.now();
|
||||||
|
|
|
@ -11,7 +11,7 @@ export interface Permissions {
|
||||||
net: boolean;
|
net: boolean;
|
||||||
env: boolean;
|
env: boolean;
|
||||||
run: boolean;
|
run: boolean;
|
||||||
highPrecision: boolean;
|
hrtime: boolean;
|
||||||
// NOTE: Keep in sync with src/permissions.rs
|
// NOTE: Keep in sync with src/permissions.rs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ function createPermissions(inner: msg.PermissionsRes): Permissions {
|
||||||
net: inner.net(),
|
net: inner.net(),
|
||||||
env: inner.env(),
|
env: inner.env(),
|
||||||
run: inner.run(),
|
run: inner.run(),
|
||||||
highPrecision: inner.highPrecision()
|
hrtime: inner.hrtime()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ const knownPermissions: Deno.Permission[] = [
|
||||||
"write",
|
"write",
|
||||||
"net",
|
"net",
|
||||||
"env",
|
"env",
|
||||||
"highPrecision"
|
"hrtime"
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let grant of knownPermissions) {
|
for (let grant of knownPermissions) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ interface TestPermissions {
|
||||||
net?: boolean;
|
net?: boolean;
|
||||||
env?: boolean;
|
env?: boolean;
|
||||||
run?: boolean;
|
run?: boolean;
|
||||||
highPrecision?: boolean;
|
hrtime?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const processPerms = Deno.permissions();
|
const processPerms = Deno.permissions();
|
||||||
|
@ -51,7 +51,7 @@ function permToString(perms: Deno.Permissions): string {
|
||||||
const n = perms.net ? 1 : 0;
|
const n = perms.net ? 1 : 0;
|
||||||
const e = perms.env ? 1 : 0;
|
const e = perms.env ? 1 : 0;
|
||||||
const u = perms.run ? 1 : 0;
|
const u = perms.run ? 1 : 0;
|
||||||
const h = perms.highPrecision ? 1 : 0;
|
const h = perms.hrtime ? 1 : 0;
|
||||||
return `permR${r}W${w}N${n}E${e}U${u}H${h}`;
|
return `permR${r}W${w}N${n}E${e}U${u}H${h}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ function normalizeTestPermissions(perms: TestPermissions): Deno.Permissions {
|
||||||
net: !!perms.net,
|
net: !!perms.net,
|
||||||
run: !!perms.run,
|
run: !!perms.run,
|
||||||
env: !!perms.env,
|
env: !!perms.env,
|
||||||
highPrecision: !!perms.highPrecision
|
hrtime: !!perms.hrtime
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ export function test(fn: testing.TestFunction): void {
|
||||||
net: false,
|
net: false,
|
||||||
env: false,
|
env: false,
|
||||||
run: false,
|
run: false,
|
||||||
highPrecision: false
|
hrtime: false
|
||||||
},
|
},
|
||||||
fn
|
fn
|
||||||
);
|
);
|
||||||
|
@ -152,7 +152,7 @@ test(function permissionsMatches(): void {
|
||||||
net: false,
|
net: false,
|
||||||
env: false,
|
env: false,
|
||||||
run: false,
|
run: false,
|
||||||
highPrecision: false
|
hrtime: false
|
||||||
},
|
},
|
||||||
normalizeTestPermissions({ read: true })
|
normalizeTestPermissions({ read: true })
|
||||||
)
|
)
|
||||||
|
@ -166,7 +166,7 @@ test(function permissionsMatches(): void {
|
||||||
net: false,
|
net: false,
|
||||||
env: false,
|
env: false,
|
||||||
run: false,
|
run: false,
|
||||||
highPrecision: false
|
hrtime: false
|
||||||
},
|
},
|
||||||
normalizeTestPermissions({})
|
normalizeTestPermissions({})
|
||||||
)
|
)
|
||||||
|
@ -180,7 +180,7 @@ test(function permissionsMatches(): void {
|
||||||
net: true,
|
net: true,
|
||||||
env: true,
|
env: true,
|
||||||
run: true,
|
run: true,
|
||||||
highPrecision: true
|
hrtime: true
|
||||||
},
|
},
|
||||||
normalizeTestPermissions({ read: true })
|
normalizeTestPermissions({ read: true })
|
||||||
),
|
),
|
||||||
|
@ -195,7 +195,7 @@ test(function permissionsMatches(): void {
|
||||||
net: true,
|
net: true,
|
||||||
env: false,
|
env: false,
|
||||||
run: false,
|
run: false,
|
||||||
highPrecision: false
|
hrtime: false
|
||||||
},
|
},
|
||||||
normalizeTestPermissions({ read: true })
|
normalizeTestPermissions({ read: true })
|
||||||
),
|
),
|
||||||
|
@ -210,7 +210,7 @@ test(function permissionsMatches(): void {
|
||||||
net: true,
|
net: true,
|
||||||
env: true,
|
env: true,
|
||||||
run: true,
|
run: true,
|
||||||
highPrecision: true
|
hrtime: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
read: true,
|
read: true,
|
||||||
|
@ -218,7 +218,7 @@ test(function permissionsMatches(): void {
|
||||||
net: true,
|
net: true,
|
||||||
env: true,
|
env: true,
|
||||||
run: true,
|
run: true,
|
||||||
highPrecision: true
|
hrtime: true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
args: run --allow-high-precision --reload tests/025_high_precision.ts
|
|
||||||
output: tests/025_high_precision.ts.out
|
|
2
tests/025_hrtime.test
Normal file
2
tests/025_hrtime.test
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
args: run --allow-hrtime --reload tests/025_hrtime.ts
|
||||||
|
output: tests/025_hrtime.ts.out
|
|
@ -1,3 +1,3 @@
|
||||||
console.log(performance.now() % 2 !== 0);
|
console.log(performance.now() % 2 !== 0);
|
||||||
Deno.revokePermission("highPrecision");
|
Deno.revokePermission("hrtime");
|
||||||
console.log(performance.now() % 2 === 0);
|
console.log(performance.now() % 2 === 0);
|
Loading…
Reference in a new issue