Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add fast api tests for getLibuvNow() #55905

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/timers.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "timers.h"

#include "env-inl.h"
#include "node_debug.h"
#include "node_external_reference.h"
#include "util-inl.h"
#include "v8.h"
Expand Down Expand Up @@ -35,6 +37,7 @@ void BindingData::SlowGetLibuvNow(const FunctionCallbackInfo<Value>& args) {

double BindingData::FastGetLibuvNow(Local<Object> unused,
Local<Object> receiver) {
TRACK_V8_FAST_API_CALL("timers.getLibuvNow");
return GetLibuvNowImpl(FromJSObject<BindingData>(receiver));
}

Expand Down
27 changes: 24 additions & 3 deletions test/parallel/test-timers-now.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
// Flags: --expose-internals --no-warnings --allow-natives-syntax
'use strict';
// Flags: --expose-internals

require('../common');
const assert = require('assert');
const common = require('../common');
const assert = require('node:assert');
const { internalBinding } = require('internal/test/binding');
const binding = internalBinding('timers');

// Return value of getLibuvNow() should easily fit in a SMI after start-up.
// We need to use the binding as the receiver for fast API calls.
assert(binding.getLibuvNow() < 0x3ffffff);

{
// V8 Fast API
function optimized() { // eslint-disable-line no-unused-vars
return binding.getLibuvNow();
}

function testFastPaths() {
assert(binding.getLibuvNow() < 0x3ffffff);
}

eval('%PrepareFunctionForOptimization(optimized)');
testFastPaths();
eval('%OptimizeFunctionOnNextCall(optimized)');
testFastPaths();

if (common.isDebug) {
const { getV8FastApiCallCount } = internalBinding('debug');
assert.strictEqual(getV8FastApiCallCount('timers.getLibuvNow'), 1);
}
}
Loading