diff options
author | Kamil Ogórek <kamil.ogorek@gmail.com> | 2022-12-27 00:16:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-27 00:16:12 +0100 |
commit | 7ce2b58bcf412924464578f3469c210b34894c8b (patch) | |
tree | 571ef978ec8ff59bc2f3c229ea44b0786251e6b9 /runtime/ops/os/mod.rs | |
parent | a67fd3e23e6965ce0bf25e19e5467bc5cc538d23 (diff) |
feat(unstable): Add "Deno.osUptime()" API (#17179)
This PR adds support for `Deno.osUptime` which reports number of seconds
since os was booted. It will allow us to be compatible with Node's `os.uptime` -
https://nodejs.org/api/os.html#osuptime
Partially based on
https://docs.rs/uptime_lib/latest/src/uptime_lib/lib.rs.html
Diffstat (limited to 'runtime/ops/os/mod.rs')
-rw-r--r-- | runtime/ops/os/mod.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index 613b4507d..e82afbf7c 100644 --- a/runtime/ops/os/mod.rs +++ b/runtime/ops/os/mod.rs @@ -29,6 +29,7 @@ fn init_ops(builder: &mut ExtensionBuilder) -> &mut ExtensionBuilder { op_loadavg::decl(), op_network_interfaces::decl(), op_os_release::decl(), + op_os_uptime::decl(), op_set_env::decl(), op_set_exit_code::decl(), op_system_memory_info::decl(), @@ -423,3 +424,13 @@ fn rss() -> usize { } } } + +#[op] +fn op_os_uptime(state: &mut OpState) -> Result<u64, AnyError> { + super::check_unstable(state, "Deno.osUptime"); + state + .borrow_mut::<Permissions>() + .sys + .check("osUptime", Some("Deno.osUptime()"))?; + Ok(sys_info::os_uptime()) +} |