Skip to content

Commit 3d34c5f

Browse files
anonrigRafaelGSS
authored andcommitted
test: add fast api tests for getLibuvNow()
PR-URL: #58022 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
1 parent 4e02f23 commit 3d34c5f

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

src/timers.cc

Lines changed: 4 additions & 2 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"
@@ -33,8 +35,8 @@ void BindingData::SlowGetLibuvNow(const FunctionCallbackInfo<Value>& args) {
3335
args.GetReturnValue().Set(Number::New(args.GetIsolate(), now));
3436
}
3537

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");
3840
return GetLibuvNowImpl(FromJSObject<BindingData>(receiver));
3941
}
4042

src/timers.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ class BindingData : public SnapshotableObject {
2626
static void SetupTimers(const v8::FunctionCallbackInfo<v8::Value>& args);
2727

2828
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);
3130
static double GetLibuvNowImpl(BindingData* data);
3231

3332
static void SlowScheduleTimer(

test/parallel/test-timers-now.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
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+
// 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+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy