diff --git a/benchmark/common.js b/benchmark/common.js index 148f51830f7b8d..79aef5a55f9bcd 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -242,3 +242,13 @@ Benchmark.prototype.report = function(rate, elapsed) { type: 'report' }); }; + +exports.binding = function(bindingName) { + try { + const { internalBinding } = require('internal/test/binding'); + + return internalBinding(bindingName); + } catch { + return process.binding(bindingName); + } +}; diff --git a/benchmark/http/bench-parser.js b/benchmark/http/bench-parser.js index 8208df11223b90..a54f0efa75e3c1 100644 --- a/benchmark/http/bench-parser.js +++ b/benchmark/http/bench-parser.js @@ -10,8 +10,7 @@ const bench = common.createBenchmark(main, { }); function main({ len, n }) { - const { internalBinding } = require('internal/test/binding'); - const { HTTPParser } = internalBinding('http_parser'); + const { HTTPParser } = common.binding('http_parser'); const REQUEST = HTTPParser.REQUEST; const kOnHeaders = HTTPParser.kOnHeaders | 0; const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0; diff --git a/benchmark/misc/punycode.js b/benchmark/misc/punycode.js index 369adcf17d3973..a55660fbc07247 100644 --- a/benchmark/misc/punycode.js +++ b/benchmark/misc/punycode.js @@ -3,7 +3,7 @@ const common = require('../common.js'); let icu; try { - icu = process.binding('icu'); + icu = common.binding('icu'); } catch (err) {} const punycode = require('punycode'); diff --git a/benchmark/misc/trace.js b/benchmark/misc/trace.js index fb51c91e9e3e7e..d76f53cf04e82d 100644 --- a/benchmark/misc/trace.js +++ b/benchmark/misc/trace.js @@ -11,7 +11,7 @@ const bench = common.createBenchmark(main, { const { TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent -} = process.binding('constants').trace; +} = common.binding('constants').trace; function doTrace(n, trace) { bench.start(); @@ -31,12 +31,10 @@ function doIsTraceCategoryEnabled(n, isTraceCategoryEnabled) { } function main({ n, method }) { - const { internalBinding } = require('internal/test/binding'); - const { trace, isTraceCategoryEnabled - } = internalBinding('trace_events'); + } = common.binding('trace_events'); switch (method) { case '': diff --git a/benchmark/net/tcp-raw-c2s.js b/benchmark/net/tcp-raw-c2s.js index d6666011d5601d..1f10ae7c839d87 100644 --- a/benchmark/net/tcp-raw-c2s.js +++ b/benchmark/net/tcp-raw-c2s.js @@ -15,10 +15,12 @@ const bench = common.createBenchmark(main, { }, { flags: [ '--expose-internals', '--no-warnings' ] }); function main({ dur, len, type }) { - const { internalBinding } = require('internal/test/binding'); - const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); - const { TCPConnectWrap } = process.binding('tcp_wrap'); - const { WriteWrap } = internalBinding('stream_wrap'); + const { + TCP, + TCPConnectWrap, + constants: TCPConstants + } = common.binding('tcp_wrap'); + const { WriteWrap } = common.binding('stream_wrap'); const PORT = common.PORT; const serverHandle = new TCP(TCPConstants.SERVER); diff --git a/benchmark/net/tcp-raw-pipe.js b/benchmark/net/tcp-raw-pipe.js index 8203abca6e92b9..16dc6955c46240 100644 --- a/benchmark/net/tcp-raw-pipe.js +++ b/benchmark/net/tcp-raw-pipe.js @@ -17,10 +17,12 @@ const bench = common.createBenchmark(main, { }); function main({ dur, len, type }) { - const { internalBinding } = require('internal/test/binding'); - const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); - const { TCPConnectWrap } = process.binding('tcp_wrap'); - const { WriteWrap } = internalBinding('stream_wrap'); + const { + TCP, + TCPConnectWrap, + constants: TCPConstants + } = common.binding('tcp_wrap'); + const { WriteWrap } = common.binding('stream_wrap'); const PORT = common.PORT; function fail(err, syscall) { diff --git a/benchmark/net/tcp-raw-s2c.js b/benchmark/net/tcp-raw-s2c.js index 1e42b311ad7b2a..1700d23890a3b5 100644 --- a/benchmark/net/tcp-raw-s2c.js +++ b/benchmark/net/tcp-raw-s2c.js @@ -17,10 +17,12 @@ const bench = common.createBenchmark(main, { }); function main({ dur, len, type }) { - const { internalBinding } = require('internal/test/binding'); - const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); - const { TCPConnectWrap } = process.binding('tcp_wrap'); - const { WriteWrap } = internalBinding('stream_wrap'); + const { + TCP, + TCPConnectWrap, + constants: TCPConstants + } = common.binding('tcp_wrap'); + const { WriteWrap } = common.binding('stream_wrap'); const PORT = common.PORT; const serverHandle = new TCP(TCPConstants.SERVER); diff --git a/benchmark/util/type-check.js b/benchmark/util/type-check.js index d9acdaedf5a57f..f11471980d9216 100644 --- a/benchmark/util/type-check.js +++ b/benchmark/util/type-check.js @@ -38,8 +38,7 @@ function main({ type, argument, version, n }) { // For testing, if supplied with an empty type, default to ArrayBufferView. type = type || 'ArrayBufferView'; - const { internalBinding } = require('internal/test/binding'); - const util = internalBinding('util'); + const util = common.binding('util'); const types = require('internal/util/types'); const func = { native: util, js: types }[version][`is${type}`];