diff options
-rw-r--r-- | runtime/js/11_timers.js | 4 | ||||
-rw-r--r-- | runtime/ops/timers.rs | 16 |
2 files changed, 7 insertions, 13 deletions
diff --git a/runtime/js/11_timers.js b/runtime/js/11_timers.js index 7a0307c06..200c764b7 100644 --- a/runtime/js/11_timers.js +++ b/runtime/js/11_timers.js @@ -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) { diff --git a/runtime/ops/timers.rs b/runtime/ops/timers.rs index b283125de..c709e3173 100644 --- a/runtime/ops/timers.rs +++ b/runtime/ops/timers.rs @@ -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)] |