GeezerVison is showing github.com — test: add fast api tests for getLibuvNow() · nodejs/node@3d34c5f
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/timers.cc +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | #include "timers.h" |
| 2 | + |
2 | 3 | #include "env-inl.h" |
| 4 | +#include "node_debug.h" |
3 | 5 | #include "node_external_reference.h" |
4 | 6 | #include "util-inl.h" |
5 | 7 | #include "v8.h" |
@@ -33,8 +35,8 @@ void BindingData::SlowGetLibuvNow(const FunctionCallbackInfo<Value>& args) { |
33 | 35 | args.GetReturnValue().Set(Number::New(args.GetIsolate(), now)); |
34 | 36 | } |
35 | 37 |
|
36 | | -double BindingData::FastGetLibuvNow(Local<Object> unused, |
37 | | - Local<Object> receiver) { |
| 38 | +double BindingData::FastGetLibuvNow(Local<Value> receiver) { |
| 39 | + TRACK_V8_FAST_API_CALL("timers.getLibuvNow"); |
38 | 40 | return GetLibuvNowImpl(FromJSObject<BindingData>(receiver)); |
39 | 41 | } |
40 | 42 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: src/timers.h +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,8 +26,7 @@ class BindingData : public SnapshotableObject { |
26 | 26 | static void SetupTimers(const v8::FunctionCallbackInfo<v8::Value>& args); |
27 | 27 |
|
28 | 28 | static void SlowGetLibuvNow(const v8::FunctionCallbackInfo<v8::Value>& args); |
29 | | - static double FastGetLibuvNow(v8::Local<v8::Object> unused, |
30 | | - v8::Local<v8::Object> receiver); |
| 29 | + static double FastGetLibuvNow(v8::Local<v8::Value> receiver); |
31 | 30 | static double GetLibuvNowImpl(BindingData* data); |
32 | 31 |
|
33 | 32 | static void SlowScheduleTimer( |
|
Collapse file
Copy file name to clipboard +21-3Lines changed: 21 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Flags: --expose-internals --no-warnings --allow-natives-syntax |
1 | 2 | 'use strict'; |
2 | | -// Flags: --expose-internals |
3 | 3 |
|
4 | | -require('../common'); |
5 | | -const assert = require('assert'); |
| 4 | +const common = require('../common'); |
| 5 | +const assert = require('node:assert'); |
6 | 6 | const { internalBinding } = require('internal/test/binding'); |
7 | 7 | const binding = internalBinding('timers'); |
8 | 8 |
|
9 | 9 | // Return value of getLibuvNow() should easily fit in a SMI after start-up. |
10 | 10 | // We need to use the binding as the receiver for fast API calls. |
11 | 11 | assert(binding.getLibuvNow() < 0x3ffffff); |
| 12 | + |
| 13 | +{ |
| 14 | + // Only javascript methods can be optimized through %OptimizeFunctionOnNextCall |
| 15 | + // This is why we surround the C++ method we want to optimize with a JS function. |
| 16 | + function getLibuvNow() { |
| 17 | + return binding.getLibuvNow(); |
| 18 | + } |
| 19 | + |
| 20 | + eval('%PrepareFunctionForOptimization(getLibuvNow)'); |
| 21 | + getLibuvNow(); |
| 22 | + eval('%OptimizeFunctionOnNextCall(getLibuvNow)'); |
| 23 | + assert(getLibuvNow() < 0x3ffffff); |
| 24 | + |
| 25 | + if (common.isDebug) { |
| 26 | + const { getV8FastApiCallCount } = internalBinding('debug'); |
| 27 | + assert.strictEqual(getV8FastApiCallCount('timers.getLibuvNow'), 1); |
| 28 | + } |
| 29 | +} |