diff --git a/src/node.cc b/src/node.cc index f9797e664ef937..3a780b5d5f294c 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2128,18 +2128,8 @@ void Kill(const FunctionCallbackInfo& args) { // and nanoseconds, to avoid any integer overflow possibility. // Pass in an Array from a previous hrtime() call to instead get a time diff. void Hrtime(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - uint64_t t = uv_hrtime(); - if (!args[1]->IsUndefined()) { - if (!args[1]->IsArray()) { - return env->ThrowTypeError( - "process.hrtime() only accepts an Array tuple"); - } - args.GetReturnValue().Set(true); - } - Local ab = args[0].As()->Buffer(); uint32_t* fields = static_cast(ab->GetContents().Data()); diff --git a/src/node.js b/src/node.js index f91b20ef60d28b..d63ffac8b705fe 100644 --- a/src/node.js +++ b/src/node.js @@ -192,15 +192,23 @@ } process.hrtime = function hrtime(ar) { - const ret = [0, 0]; - if (_hrtime(hrValues, ar)) { - ret[0] = (hrValues[0] * 0x100000000 + hrValues[1]) - ar[0]; - ret[1] = hrValues[2] - ar[1]; - } else { - ret[0] = hrValues[0] * 0x100000000 + hrValues[1]; - ret[1] = hrValues[2]; + _hrtime(hrValues); + + if (typeof ar !== 'undefined') { + if (Array.isArray(ar)) { + return [ + (hrValues[0] * 0x100000000 + hrValues[1]) - ar[0], + hrValues[2] - ar[1] + ]; + } + + throw new TypeError('process.hrtime() only accepts an Array tuple'); } - return ret; + + return [ + hrValues[0] * 0x100000000 + hrValues[1], + hrValues[2] + ]; }; };