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

refactor: Switch op_now to be a json-op (#9974)

This commit is contained in:
Aaron O'Mullan 2021-04-03 20:35:28 +02:00 committed by GitHub
parent d2fbbfbbf3
commit 824bd2f5c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 13 deletions

View file

@ -17,10 +17,8 @@
await core.jsonOpAsync("op_global_timer");
}
const nowBytes = new Uint8Array(8);
function opNow() {
core.binOpSync("op_now", 0, nowBytes);
return new DataView(nowBytes.buffer).getFloat64();
return core.jsonOpSync("op_now");
}
function sleepSync(millis = 0) {

View file

@ -9,7 +9,6 @@
//! calls it) for an entire Isolate. This is what is implemented here.
use crate::permissions::Permissions;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::futures;
use deno_core::futures::channel::oneshot;
@ -76,7 +75,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_sync(rt, "op_global_timer_stop", op_global_timer_stop);
super::reg_json_sync(rt, "op_global_timer_start", op_global_timer_start);
super::reg_json_async(rt, "op_global_timer", op_global_timer);
super::reg_bin_sync(rt, "op_now", op_now);
super::reg_json_sync(rt, "op_now", op_now);
super::reg_json_sync(rt, "op_sleep_sync", op_sleep_sync);
}
@ -137,13 +136,12 @@ async fn op_global_timer(
// since the start time of the deno runtime.
// If the High precision flag is not set, the
// nanoseconds are rounded on 2ms.
#[allow(clippy::unnecessary_wraps)]
fn op_now(
op_state: &mut OpState,
_argument: u32,
zero_copy: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
let mut zero_copy = zero_copy.ok_or_else(null_opbuf)?;
_argument: (),
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<f64, AnyError> {
let start_time = op_state.borrow::<StartTime>();
let seconds = start_time.elapsed().as_secs();
let mut subsec_nanos = start_time.elapsed().subsec_nanos() as f64;
@ -158,9 +156,7 @@ fn op_now(
let result = (seconds * 1_000) as f64 + (subsec_nanos / 1_000_000.0);
(&mut zero_copy).copy_from_slice(&result.to_be_bytes());
Ok(0)
Ok(result)
}
#[derive(Deserialize)]