diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-06-11 17:37:09 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-06-17 22:34:58 +0800 |
commit | 1d8a23173311337d93c365cba3357ac6f87eb39c (patch) | |
tree | a9518b91613f80cc5b7db530a66dea3d4578d619 /src/node_process.cc | |
parent | 54ee8cb5dd28e9e72770ee4ab6aa73d700232cb5 (diff) | |
download | android-node-v8-1d8a23173311337d93c365cba3357ac6f87eb39c.tar.gz android-node-v8-1d8a23173311337d93c365cba3357ac6f87eb39c.tar.bz2 android-node-v8-1d8a23173311337d93c365cba3357ac6f87eb39c.zip |
process: implement process.hrtime.bigint()
PR-URL: https://github.com/nodejs/node/pull/21256
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Diffstat (limited to 'src/node_process.cc')
-rw-r--r-- | src/node_process.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/node_process.cc b/src/node_process.cc index 3a7c12ec45..3655a05648 100644 --- a/src/node_process.cc +++ b/src/node_process.cc @@ -31,6 +31,7 @@ namespace node { using v8::Array; using v8::ArrayBuffer; +using v8::BigUint64Array; using v8::Float64Array; using v8::FunctionCallbackInfo; using v8::HeapStatistics; @@ -113,7 +114,11 @@ void Cwd(const FunctionCallbackInfo<Value>& args) { args.GetReturnValue().Set(cwd); } + // Hrtime exposes libuv's uv_hrtime() high-resolution timer. + +// This is the legacy version of hrtime before BigInt was introduced in +// JavaScript. // The value returned by uv_hrtime() is a 64-bit int representing nanoseconds, // so this function instead fills in an Uint32Array with 3 entries, // to avoid any integer overflow possibility. @@ -132,6 +137,12 @@ void Hrtime(const FunctionCallbackInfo<Value>& args) { fields[2] = t % NANOS_PER_SEC; } +void HrtimeBigInt(const FunctionCallbackInfo<Value>& args) { + Local<ArrayBuffer> ab = args[0].As<BigUint64Array>()->Buffer(); + uint64_t* fields = static_cast<uint64_t*>(ab->GetContents().Data()); + fields[0] = uv_hrtime(); +} + void Kill(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); |