From 522d5a359d789fe66db9af95da34c3f2dba3cb10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Fri, 30 Aug 2024 12:25:01 +0200 Subject: [PATCH] test: run V8 Fast API tests in release mode too Only keep the call count assertions under `common.isDebug`. PR-URL: https://github.com/nodejs/node/pull/54570 Reviewed-By: Robert Nagy Reviewed-By: Benjamin Gruenbaum Reviewed-By: Yagiz Nizipli Reviewed-By: Rafael Gonzaga Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- doc/contributing/adding-v8-fast-api.md | 31 +++++++++---------- test/parallel/test-whatwg-url-canparse.js | 12 ++++--- .../test-crypto-timing-safe-equal.js | 15 +++++---- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/doc/contributing/adding-v8-fast-api.md b/doc/contributing/adding-v8-fast-api.md index 5326f8e5fd6987..7f7da32656d81b 100644 --- a/doc/contributing/adding-v8-fast-api.md +++ b/doc/contributing/adding-v8-fast-api.md @@ -173,25 +173,24 @@ A typical function that communicates between JavaScript and C++ is as follows. // We could also require a function that uses the internal binding internally. const { divide } = internalBinding('custom_namespace'); - if (common.isDebug) { - const { getV8FastApiCallCount } = internalBinding('debug'); - - // The function that will be optimized. It has to be a function written in - // JavaScript. Since `divide` comes from the C++ side, we need to wrap it. - function testFastPath(a, b) { - return divide(a, b); - } + // The function that will be optimized. It has to be a function written in + // JavaScript. Since `divide` comes from the C++ side, we need to wrap it. + function testFastPath(a, b) { + return divide(a, b); + } - eval('%PrepareFunctionForOptimization(testFastPath)'); - // This call will let V8 know about the argument types that the function expects. - assert.strictEqual(testFastPath(6, 3), 2); + eval('%PrepareFunctionForOptimization(testFastPath)'); + // This call will let V8 know about the argument types that the function expects. + assert.strictEqual(testFastPath(6, 3), 2); - eval('%OptimizeFunctionOnNextCall(testFastPath)'); - assert.strictEqual(testFastPath(8, 2), 4); - assert.throws(() => testFastPath(1, 0), { - code: 'ERR_INVALID_STATE', - }); + eval('%OptimizeFunctionOnNextCall(testFastPath)'); + assert.strictEqual(testFastPath(8, 2), 4); + assert.throws(() => testFastPath(1, 0), { + code: 'ERR_INVALID_STATE', + }); + if (common.isDebug) { + const { getV8FastApiCallCount } = internalBinding('debug'); assert.strictEqual(getV8FastApiCallCount('custom_namespace.divide.ok'), 1); assert.strictEqual(getV8FastApiCallCount('custom_namespace.divide.error'), 1); } diff --git a/test/parallel/test-whatwg-url-canparse.js b/test/parallel/test-whatwg-url-canparse.js index c67f957ec65f49..e49373324d36e3 100644 --- a/test/parallel/test-whatwg-url-canparse.js +++ b/test/parallel/test-whatwg-url-canparse.js @@ -19,9 +19,8 @@ assert.throws(() => { // It should not throw when called without a base string assert.strictEqual(URL.canParse('https://example.org'), true); -if (common.isDebug) { - const { getV8FastApiCallCount } = internalBinding('debug'); - +{ + // V8 Fast API function testFastPaths() { // `canParse` binding has two overloads. assert.strictEqual(URL.canParse('https://www.example.com/path/?query=param#hash'), true); @@ -33,6 +32,9 @@ if (common.isDebug) { eval('%OptimizeFunctionOnNextCall(URL.canParse)'); testFastPaths(); - assert.strictEqual(getV8FastApiCallCount('url.canParse'), 1); - assert.strictEqual(getV8FastApiCallCount('url.canParse.withBase'), 1); + if (common.isDebug) { + const { getV8FastApiCallCount } = internalBinding('debug'); + assert.strictEqual(getV8FastApiCallCount('url.canParse'), 1); + assert.strictEqual(getV8FastApiCallCount('url.canParse.withBase'), 1); + } } diff --git a/test/sequential/test-crypto-timing-safe-equal.js b/test/sequential/test-crypto-timing-safe-equal.js index 97fd35448c98b4..80b3a69e59cb2d 100644 --- a/test/sequential/test-crypto-timing-safe-equal.js +++ b/test/sequential/test-crypto-timing-safe-equal.js @@ -93,10 +93,8 @@ assert.throws( } ); -if (common.isDebug) { - const { internalBinding } = require('internal/test/binding'); - const { getV8FastApiCallCount } = internalBinding('debug'); - +{ + // V8 Fast API const foo = Buffer.from('foo'); const bar = Buffer.from('bar'); const longer = Buffer.from('longer'); @@ -111,6 +109,11 @@ if (common.isDebug) { assert.throws(() => testFastPath(foo, longer), { code: 'ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH', }); - assert.strictEqual(getV8FastApiCallCount('crypto.timingSafeEqual.ok'), 2); - assert.strictEqual(getV8FastApiCallCount('crypto.timingSafeEqual.error'), 1); + + if (common.isDebug) { + const { internalBinding } = require('internal/test/binding'); + const { getV8FastApiCallCount } = internalBinding('debug'); + assert.strictEqual(getV8FastApiCallCount('crypto.timingSafeEqual.ok'), 2); + assert.strictEqual(getV8FastApiCallCount('crypto.timingSafeEqual.error'), 1); + } }