Skip to content

Commit

Permalink
test: add fast api tests for getLibuvNow()
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Nov 27, 2024
1 parent f8c9ab4 commit 4b7036b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/timers.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "timers.h"

#include <node_debug.h>

#include "env-inl.h"
#include "node_external_reference.h"
#include "util-inl.h"
Expand Down Expand Up @@ -35,6 +38,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
26 changes: 23 additions & 3 deletions test/parallel/test-timers-now.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
// 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() {
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);
}
}

0 comments on commit 4b7036b

Please sign in to comment.