Skip to content

Commit 522d5a3

Browse files
targosRafaelGSS
authored andcommitted
test: run V8 Fast API tests in release mode too
Only keep the call count assertions under `common.isDebug`. PR-URL: #54570 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent edbecf5 commit 522d5a3

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

doc/contributing/adding-v8-fast-api.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,24 @@ A typical function that communicates between JavaScript and C++ is as follows.
173173
// We could also require a function that uses the internal binding internally.
174174
const { divide } = internalBinding('custom_namespace');
175175

176-
if (common.isDebug) {
177-
const { getV8FastApiCallCount } = internalBinding('debug');
178-
179-
// The function that will be optimized. It has to be a function written in
180-
// JavaScript. Since `divide` comes from the C++ side, we need to wrap it.
181-
function testFastPath(a, b) {
182-
return divide(a, b);
183-
}
176+
// The function that will be optimized. It has to be a function written in
177+
// JavaScript. Since `divide` comes from the C++ side, we need to wrap it.
178+
function testFastPath(a, b) {
179+
return divide(a, b);
180+
}
184181

185-
eval('%PrepareFunctionForOptimization(testFastPath)');
186-
// This call will let V8 know about the argument types that the function expects.
187-
assert.strictEqual(testFastPath(6, 3), 2);
182+
eval('%PrepareFunctionForOptimization(testFastPath)');
183+
// This call will let V8 know about the argument types that the function expects.
184+
assert.strictEqual(testFastPath(6, 3), 2);
188185

189-
eval('%OptimizeFunctionOnNextCall(testFastPath)');
190-
assert.strictEqual(testFastPath(8, 2), 4);
191-
assert.throws(() => testFastPath(1, 0), {
192-
code: 'ERR_INVALID_STATE',
193-
});
186+
eval('%OptimizeFunctionOnNextCall(testFastPath)');
187+
assert.strictEqual(testFastPath(8, 2), 4);
188+
assert.throws(() => testFastPath(1, 0), {
189+
code: 'ERR_INVALID_STATE',
190+
});
194191

192+
if (common.isDebug) {
193+
const { getV8FastApiCallCount } = internalBinding('debug');
195194
assert.strictEqual(getV8FastApiCallCount('custom_namespace.divide.ok'), 1);
196195
assert.strictEqual(getV8FastApiCallCount('custom_namespace.divide.error'), 1);
197196
}

test/parallel/test-whatwg-url-canparse.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ assert.throws(() => {
1919
// It should not throw when called without a base string
2020
assert.strictEqual(URL.canParse('https://example.org'), true);
2121

22-
if (common.isDebug) {
23-
const { getV8FastApiCallCount } = internalBinding('debug');
24-
22+
{
23+
// V8 Fast API
2524
function testFastPaths() {
2625
// `canParse` binding has two overloads.
2726
assert.strictEqual(URL.canParse('https://www.example.com/path/?query=param#hash'), true);
@@ -33,6 +32,9 @@ if (common.isDebug) {
3332
eval('%OptimizeFunctionOnNextCall(URL.canParse)');
3433
testFastPaths();
3534

36-
assert.strictEqual(getV8FastApiCallCount('url.canParse'), 1);
37-
assert.strictEqual(getV8FastApiCallCount('url.canParse.withBase'), 1);
35+
if (common.isDebug) {
36+
const { getV8FastApiCallCount } = internalBinding('debug');
37+
assert.strictEqual(getV8FastApiCallCount('url.canParse'), 1);
38+
assert.strictEqual(getV8FastApiCallCount('url.canParse.withBase'), 1);
39+
}
3840
}

test/sequential/test-crypto-timing-safe-equal.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ assert.throws(
9393
}
9494
);
9595

96-
if (common.isDebug) {
97-
const { internalBinding } = require('internal/test/binding');
98-
const { getV8FastApiCallCount } = internalBinding('debug');
99-
96+
{
97+
// V8 Fast API
10098
const foo = Buffer.from('foo');
10199
const bar = Buffer.from('bar');
102100
const longer = Buffer.from('longer');
@@ -111,6 +109,11 @@ if (common.isDebug) {
111109
assert.throws(() => testFastPath(foo, longer), {
112110
code: 'ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH',
113111
});
114-
assert.strictEqual(getV8FastApiCallCount('crypto.timingSafeEqual.ok'), 2);
115-
assert.strictEqual(getV8FastApiCallCount('crypto.timingSafeEqual.error'), 1);
112+
113+
if (common.isDebug) {
114+
const { internalBinding } = require('internal/test/binding');
115+
const { getV8FastApiCallCount } = internalBinding('debug');
116+
assert.strictEqual(getV8FastApiCallCount('crypto.timingSafeEqual.ok'), 2);
117+
assert.strictEqual(getV8FastApiCallCount('crypto.timingSafeEqual.error'), 1);
118+
}
116119
}

0 commit comments

Comments
 (0)