diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bootstrapper.cc | 1 | ||||
-rw-r--r-- | src/node_internals.h | 1 | ||||
-rw-r--r-- | src/node_process.cc | 11 |
3 files changed, 13 insertions, 0 deletions
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index f9db02562d..c470b99445 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -109,6 +109,7 @@ void SetupBootstrapObject(Environment* env, BOOTSTRAP_METHOD(_chdir, Chdir); BOOTSTRAP_METHOD(_cpuUsage, CPUUsage); BOOTSTRAP_METHOD(_hrtime, Hrtime); + BOOTSTRAP_METHOD(_hrtimeBigInt, HrtimeBigInt); BOOTSTRAP_METHOD(_memoryUsage, MemoryUsage); BOOTSTRAP_METHOD(_rawDebug, RawDebug); BOOTSTRAP_METHOD(_umask, Umask); diff --git a/src/node_internals.h b/src/node_internals.h index 9468770dbe..025fa10100 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -905,6 +905,7 @@ void Chdir(const v8::FunctionCallbackInfo<v8::Value>& args); void CPUUsage(const v8::FunctionCallbackInfo<v8::Value>& args); void Cwd(const v8::FunctionCallbackInfo<v8::Value>& args); void Hrtime(const v8::FunctionCallbackInfo<v8::Value>& args); +void HrtimeBigInt(const v8::FunctionCallbackInfo<v8::Value>& args); void Kill(const v8::FunctionCallbackInfo<v8::Value>& args); void MemoryUsage(const v8::FunctionCallbackInfo<v8::Value>& args); void RawDebug(const v8::FunctionCallbackInfo<v8::Value>& args); 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); |