| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | 4 | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
| 5 | 5 | ||
| 6 | + #include "node_debug.h" | ||
| 6 | 7 | #include "node_snapshotable.h" | |
| 7 | 8 | #include "v8-fast-api-calls.h" | |
| 8 | 9 | #include "v8.h" | |
@@ -72,23 +73,23 @@ class BindingData : public SnapshotableObject { | |||
| 72 | 73 | SET_SELF_SIZE(BindingData) | |
| 73 | 74 | ||
| 74 | 75 | static BindingData* FromV8Value(v8::Local<v8::Value> receiver); | |
| 75 | - static void NumberImpl(BindingData* receiver); | ||
| 76 | + static void HrtimeImpl(BindingData* receiver); | ||
| 76 | 77 | ||
| 77 | - static void FastNumber(v8::Local<v8::Value> unused, | ||
| 78 | - v8::Local<v8::Value> receiver) { | ||
| 79 | - NumberImpl(FromV8Value(receiver)); | ||
| 78 | + static void FastHrtime(v8::Local<v8::Value> receiver) { | ||
| 79 | + TRACK_V8_FAST_API_CALL("process.hrtime"); | ||
| 80 | + HrtimeImpl(FromV8Value(receiver)); | ||
| 80 | 81 | } | |
| 81 | 82 | ||
| 82 | - static void SlowNumber(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 83 | + static void SlowHrtime(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 83 | 84 | ||
| 84 | - static void BigIntImpl(BindingData* receiver); | ||
| 85 | + static void HrtimeBigIntImpl(BindingData* receiver); | ||
| 85 | 86 | ||
| 86 | - static void FastBigInt(v8::Local<v8::Value> unused, | ||
| 87 | - v8::Local<v8::Value> receiver) { | ||
| 88 | - BigIntImpl(FromV8Value(receiver)); | ||
| 87 | + static void FastHrtimeBigInt(v8::Local<v8::Value> receiver) { | ||
| 88 | + TRACK_V8_FAST_API_CALL("process.hrtimeBigInt"); | ||
| 89 | + HrtimeBigIntImpl(FromV8Value(receiver)); | ||
| 89 | 90 | } | |
| 90 | 91 | ||
| 91 | - static void SlowBigInt(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 92 | + static void SlowHrtimeBigInt(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 92 | 93 | ||
| 93 | 94 | static void LoadEnvFile(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 94 | 95 | ||
@@ -101,8 +102,8 @@ class BindingData : public SnapshotableObject { | |||
| 101 | 102 | // These need to be static so that we have their addresses available to | |
| 102 | 103 | // register as external references in the snapshot at environment creation | |
| 103 | 104 | // time. | |
| 104 | - static v8::CFunction fast_number_; | ||
| 105 | - static v8::CFunction fast_bigint_; | ||
| 105 | + static v8::CFunction fast_hrtime_; | ||
| 106 | + static v8::CFunction fast_hrtime_bigint_; | ||
| 106 | 107 | }; | |
| 107 | 108 | ||
| 108 | 109 | } // namespace process | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -652,22 +652,22 @@ BindingData::BindingData(Realm* realm, | |||
| 652 | 652 | hrtime_buffer_.MakeWeak(); | |
| 653 | 653 | } | |
| 654 | 654 | ||
| 655 | - v8::CFunction BindingData::fast_number_(v8::CFunction::Make(FastNumber)); | ||
| 656 | - v8::CFunction BindingData::fast_bigint_(v8::CFunction::Make(FastBigInt)); | ||
| 655 | + CFunction BindingData::fast_hrtime_(CFunction::Make(FastHrtime)); | ||
| 656 | + CFunction BindingData::fast_hrtime_bigint_(CFunction::Make(FastHrtimeBigInt)); | ||
| 657 | 657 | ||
| 658 | 658 | void BindingData::AddMethods(Isolate* isolate, Local<ObjectTemplate> target) { | |
| 659 | 659 | SetFastMethodNoSideEffect( | |
| 660 | - isolate, target, "hrtime", SlowNumber, &fast_number_); | ||
| 660 | + isolate, target, "hrtime", SlowHrtime, &fast_hrtime_); | ||
| 661 | 661 | SetFastMethodNoSideEffect( | |
| 662 | - isolate, target, "hrtimeBigInt", SlowBigInt, &fast_bigint_); | ||
| 662 | + isolate, target, "hrtimeBigInt", SlowHrtimeBigInt, &fast_hrtime_bigint_); | ||
| 663 | 663 | } | |
| 664 | 664 | ||
| 665 | 665 | void BindingData::RegisterExternalReferences( | |
| 666 | 666 | ExternalReferenceRegistry* registry) { | |
| 667 | - registry->Register(SlowNumber); | ||
| 668 | - registry->Register(SlowBigInt); | ||
| 669 | - registry->Register(fast_number_); | ||
| 670 | - registry->Register(fast_bigint_); | ||
| 667 | + registry->Register(SlowHrtime); | ||
| 668 | + registry->Register(SlowHrtimeBigInt); | ||
| 669 | + registry->Register(fast_hrtime_); | ||
| 670 | + registry->Register(fast_hrtime_bigint_); | ||
| 671 | 671 | } | |
| 672 | 672 | ||
| 673 | 673 | BindingData* BindingData::FromV8Value(Local<Value> value) { | |
@@ -689,14 +689,14 @@ void BindingData::MemoryInfo(MemoryTracker* tracker) const { | |||
| 689 | 689 | // broken into the upper/lower 32 bits to be converted back in JS, | |
| 690 | 690 | // because there is no Uint64Array in JS. | |
| 691 | 691 | // The third entry contains the remaining nanosecond part of the value. | |
| 692 | - void BindingData::NumberImpl(BindingData* receiver) { | ||
| 692 | + void BindingData::HrtimeImpl(BindingData* receiver) { | ||
| 693 | 693 | uint64_t t = uv_hrtime(); | |
| 694 | 694 | receiver->hrtime_buffer_[0] = (t / NANOS_PER_SEC) >> 32; | |
| 695 | 695 | receiver->hrtime_buffer_[1] = (t / NANOS_PER_SEC) & 0xffffffff; | |
| 696 | 696 | receiver->hrtime_buffer_[2] = t % NANOS_PER_SEC; | |
| 697 | 697 | } | |
| 698 | 698 | ||
| 699 | - void BindingData::BigIntImpl(BindingData* receiver) { | ||
| 699 | + void BindingData::HrtimeBigIntImpl(BindingData* receiver) { | ||
| 700 | 700 | uint64_t t = uv_hrtime(); | |
| 701 | 701 | // The buffer is a Uint32Array, so we need to reinterpret it as a | |
| 702 | 702 | // Uint64Array to write the value. The buffer is valid at this scope so we | |
@@ -706,12 +706,12 @@ void BindingData::BigIntImpl(BindingData* receiver) { | |||
| 706 | 706 | fields[0] = t; | |
| 707 | 707 | } | |
| 708 | 708 | ||
| 709 | - void BindingData::SlowBigInt(const FunctionCallbackInfo<Value>& args) { | ||
| 710 | - BigIntImpl(FromJSObject<BindingData>(args.This())); | ||
| 709 | + void BindingData::SlowHrtimeBigInt(const FunctionCallbackInfo<Value>& args) { | ||
| 710 | + HrtimeBigIntImpl(FromJSObject<BindingData>(args.This())); | ||
| 711 | 711 | } | |
| 712 | 712 | ||
| 713 | - void BindingData::SlowNumber(const v8::FunctionCallbackInfo<v8::Value>& args) { | ||
| 714 | - NumberImpl(FromJSObject<BindingData>(args.This())); | ||
| 713 | + void BindingData::SlowHrtime(const FunctionCallbackInfo<Value>& args) { | ||
| 714 | + HrtimeImpl(FromJSObject<BindingData>(args.This())); | ||
| 715 | 715 | } | |
| 716 | 716 | ||
| 717 | 717 | bool BindingData::PrepareForSerialization(Local<Context> context, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,14 +1,27 @@ | |||
| 1 | + // Flags: --allow-natives-syntax --expose-internals --no-warnings | ||
| 1 | 2 | 'use strict'; | |
| 2 | 3 | ||
| 3 | 4 | // Tests that process.hrtime.bigint() works. | |
| 4 | 5 | ||
| 5 | - require('../common'); | ||
| 6 | + const common = require('../common'); | ||
| 6 | 7 | const assert = require('assert'); | |
| 7 | 8 | ||
| 9 | + const { internalBinding } = require('internal/test/binding'); | ||
| 10 | + | ||
| 8 | 11 | const start = process.hrtime.bigint(); | |
| 9 | 12 | assert.strictEqual(typeof start, 'bigint'); | |
| 10 | 13 | ||
| 11 | 14 | const end = process.hrtime.bigint(); | |
| 12 | 15 | assert.strictEqual(typeof end, 'bigint'); | |
| 13 | 16 | ||
| 14 | 17 | assert(end - start >= 0n); | |
| 18 | + | ||
| 19 | + eval('%PrepareFunctionForOptimization(process.hrtime.bigint)'); | ||
| 20 | + assert(process.hrtime.bigint()); | ||
| 21 | + eval('%OptimizeFunctionOnNextCall(process.hrtime.bigint)'); | ||
| 22 | + assert(process.hrtime.bigint()); | ||
| 23 | + | ||
| 24 | + if (common.isDebug) { | ||
| 25 | + const { getV8FastApiCallCount } = internalBinding('debug'); | ||
| 26 | + assert.strictEqual(getV8FastApiCallCount('process.hrtimeBigInt'), 1); | ||
| 27 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,10 +19,13 @@ | |||
| 19 | 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | |
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | + // Flags: --allow-natives-syntax --expose-internals --no-warnings | ||
| 22 | 23 | 'use strict'; | |
| 23 | - require('../common'); | ||
| 24 | + const common = require('../common'); | ||
| 24 | 25 | const assert = require('assert'); | |
| 25 | 26 | ||
| 27 | + const { internalBinding } = require('internal/test/binding'); | ||
| 28 | + | ||
| 26 | 29 | // The default behavior, return an Array "tuple" of numbers | |
| 27 | 30 | const tuple = process.hrtime(); | |
| 28 | 31 | ||
@@ -72,3 +75,13 @@ function validateTuple(tuple) { | |||
| 72 | 75 | ||
| 73 | 76 | const diff = process.hrtime([0, 1e9 - 1]); | |
| 74 | 77 | assert(diff[1] >= 0); // https://github.com/nodejs/node/issues/4751 | |
| 78 | + | ||
| 79 | + eval('%PrepareFunctionForOptimization(process.hrtime)'); | ||
| 80 | + assert(process.hrtime()); | ||
| 81 | + eval('%OptimizeFunctionOnNextCall(process.hrtime)'); | ||
| 82 | + assert(process.hrtime()); | ||
| 83 | + | ||
| 84 | + if (common.isDebug) { | ||
| 85 | + const { getV8FastApiCallCount } = internalBinding('debug'); | ||
| 86 | + assert.strictEqual(getV8FastApiCallCount('process.hrtime'), 1); | ||
| 87 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments