Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

process: make NANOS_PER_SEC a 64 bits unsigned int

  • Loading branch information...
commit 72a85e7a7acdd59e00c282c5328c8a94120326ba 1 parent c45522d
@shigeki authored
Showing with 44 additions and 3 deletions.
  1. +3 −3 src/node.cc
  2. +41 −0 test/simple/test-process-hrtime.js
View
6 src/node.cc
@@ -1686,12 +1686,12 @@ Handle<Value> Hrtime(const v8::Arguments& args) {
Local<Array> inArray = Local<Array>::Cast(args[0]);
uint64_t seconds = inArray->Get(0)->Uint32Value();
uint64_t nanos = inArray->Get(1)->Uint32Value();
- t -= (seconds * NANOS_PER_SEC) + nanos;
+ t -= (seconds * (uint64_t) NANOS_PER_SEC) + nanos;
}
Local<Array> tuple = Array::New(2);
- tuple->Set(0, Integer::NewFromUnsigned(t / NANOS_PER_SEC));
- tuple->Set(1, Integer::NewFromUnsigned(t % NANOS_PER_SEC));
+ tuple->Set(0, Integer::NewFromUnsigned(t / (uint64_t) NANOS_PER_SEC));
+ tuple->Set(1, Integer::NewFromUnsigned(t % (uint64_t) NANOS_PER_SEC));
return scope.Close(tuple);
}
View
41 test/simple/test-process-hrtime.js
@@ -0,0 +1,41 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var assert = require('assert');
+var millisec = 1000;
+var nanosec = 1000000000;
+// testing is incremented up to 100
+// see. libuv #450
+var i = 100;
+function test() {
+ if (!i) return;
+ var a = process.hrtime();
+ setTimeout(function() {
+ var b = process.hrtime();
+ var diff = (b[0] * nanosec + b[1]) - (a[0] * nanosec + a[1]);
+ // console.log(i, diff);
+ assert(diff > 25 * nanosec / millisec);
+ assert(diff < 60 * nanosec / millisec);
+ i--;
+ test();
+ }, 45);
+}
+test();
Please sign in to comment.
Something went wrong with that request. Please try again.