Skip to content

Commit d30d54f

Browse files
committed
test: add fast api tests for getLibuvNow()
1 parent f8c9ab4 commit d30d54f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/timers.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "timers.h"
2+
23
#include "env-inl.h"
4+
#include "node_debug.h"
35
#include "node_external_reference.h"
46
#include "util-inl.h"
57
#include "v8.h"
@@ -35,6 +37,7 @@ void BindingData::SlowGetLibuvNow(const FunctionCallbackInfo<Value>& args) {
3537

3638
double BindingData::FastGetLibuvNow(Local<Object> unused,
3739
Local<Object> receiver) {
40+
TRACK_V8_FAST_API_CALL("timers.getLibuvNow");
3841
return GetLibuvNowImpl(FromJSObject<BindingData>(receiver));
3942
}
4043

test/parallel/test-timers-now.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1+
// Flags: --expose-internals --no-warnings --allow-natives-syntax
12
'use strict';
2-
// Flags: --expose-internals
33

4-
require('../common');
5-
const assert = require('assert');
4+
const common = require('../common');
5+
const assert = require('node:assert');
66
const { internalBinding } = require('internal/test/binding');
77
const binding = internalBinding('timers');
88

99
// Return value of getLibuvNow() should easily fit in a SMI after start-up.
1010
// We need to use the binding as the receiver for fast API calls.
1111
assert(binding.getLibuvNow() < 0x3ffffff);
12+
13+
{
14+
// V8 Fast API
15+
function optimized() {
16+
return binding.getLibuvNow();
17+
}
18+
function testFastPaths() {
19+
assert(binding.getLibuvNow() < 0x3ffffff);
20+
}
21+
22+
eval('%PrepareFunctionForOptimization(optimized)');
23+
testFastPaths();
24+
eval('%OptimizeFunctionOnNextCall(optimized)');
25+
testFastPaths();
26+
27+
if (common.isDebug) {
28+
const { getV8FastApiCallCount } = internalBinding('debug');
29+
assert.strictEqual(getV8FastApiCallCount('timers.getLibuvNow'), 1);
30+
}
31+
}

0 commit comments

Comments
 (0)