Skip to content

Commit 71a4b24

Browse files
addaleaxBridgeAR
authored andcommitted
test: remove usage of process.binding()
Prefer `internalBinding` or other equivalents over `process.binding()` (except in tests checking `process.binding()` itself). PR-URL: #26304 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 8c864de commit 71a4b24

12 files changed

Lines changed: 37 additions & 34 deletions

‎test/abort/test-zlib-invalid-internals-usage.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ const os = require('os');
55
constcp=require('child_process');
66

77
if(process.argv[2]==='child'){
8+
const{ internalBinding }=require('internal/test/binding');
89
// This is the heart of the test.
9-
new(process.binding('zlib').Zlib)(0).init(1,2,3,4,5);
10+
new(internalBinding('zlib').Zlib)(0).init(1,2,3,4,5);
1011
}else{
11-
constchild=cp.spawnSync(`${process.execPath}`,[`${__filename}`,'child']);
12+
constchild=cp.spawnSync(
13+
`${process.execPath}`,['--expose-internals',`${__filename}`,'child']);
1214

1315
assert.strictEqual(child.stdout.toString(),'');
1416
assert.ok(child.stderr.includes(

‎test/async-hooks/test-zlib.zlib-binding.deflate.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const hooks = initHooks();
1111
hooks.enable();
1212
const{ internalBinding }=require('internal/test/binding');
1313
const{ Zlib }=internalBinding('zlib');
14-
constconstants=internalBinding('constants').zlib;
14+
constconstants=require('zlib').constants;
1515

1616
consthandle=newZlib(constants.DEFLATE);
1717

‎test/common/index.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ const os = require('os');
2929
const{ exec, execSync, spawnSync }=require('child_process');
3030
constutil=require('util');
3131
consttmpdir=require('./tmpdir');
32-
const{
33-
bits,
34-
hasIntl
35-
}=process.binding('config');
32+
constbits=['arm64','mips','mipsel','ppc64','s390x','x64']
33+
.includes(process.arch) ? 64 : 32;
34+
consthasIntl=!!process.config.variables.v8_enable_i18n_support;
3635
const{ isMainThread }=require('worker_threads');
3736

3837
// Some tests assume a umask of 0o022 so set that up front. Tests that need a

‎test/common/inspector-helper.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class InspectorSession {
314314
}
315315

316316
classNodeInstanceextendsEventEmitter{
317-
constructor(inspectorFlags=['--inspect-brk=0'],
317+
constructor(inspectorFlags=['--inspect-brk=0','--expose-internals'],
318318
scriptContents='',
319319
scriptFile=_MAINSCRIPT){
320320
super();
@@ -348,7 +348,8 @@ class NodeInstance extends EventEmitter {
348348

349349
staticasyncstartViaSignal(scriptContents){
350350
constinstance=newNodeInstance(
351-
[],`${scriptContents}\nprocess._rawDebug('started');`,undefined);
351+
['--expose-internals'],
352+
`${scriptContents}\nprocess._rawDebug('started');`,undefined);
352353
constmsg='Timed out waiting for process to start';
353354
while(awaitfires(instance.nextStderrString(),msg,TIMEOUT)!==
354355
'started'){}

‎test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
importmodulefrom'module';
22

3-
constbuiltins=newSet(
4-
Object.keys(process.binding('natives')).filter(str=>
5-
/^(?!(?:internal|node|v8)\/)/.test(str))
6-
);
7-
83
exportfunctiondynamicInstantiate(url){
94
constbuiltinInstance=module._load(url.substr(5));
105
constbuiltinExports=['default', ...Object.keys(builtinInstance)];
@@ -19,7 +14,7 @@ export function dynamicInstantiate(url) {
1914
}
2015

2116
exportfunctionresolve(specifier,base,defaultResolver){
22-
if(builtins.has(specifier)){
17+
if(module.builtinModules.includes(specifier)){
2318
return{
2419
url: `node:${specifier}`,
2520
format: 'dynamic'

‎test/fixtures/es-module-loaders/example-loader.mjs‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
importurlfrom'url';
22
importpathfrom'path';
33
importprocessfrom'process';
4+
import{builtinModules}from'module';
45

5-
constbuiltins=newSet(
6-
Object.keys(process.binding('natives')).filter((str)=>
7-
/^(?!(?:internal|node|v8)\/)/.test(str))
8-
);
96
constJS_EXTENSIONS=newSet(['.js','.mjs']);
107

118
constbaseURL=newurl.URL('file://');
129
baseURL.pathname=process.cwd()+'/';
1310

1411
exportfunctionresolve(specifier,parentModuleURL=baseURL/*, defaultResolve */){
15-
if(builtins.has(specifier)){
12+
if(builtinModules.includes(specifier)){
1613
return{
1714
url: specifier,
1815
format: 'builtin'

‎test/fixtures/es-module-loaders/js-loader.mjs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import{URL}from'url';
2-
3-
constbuiltins=newSet(
4-
Object.keys(process.binding('natives')).filter(str=>
5-
/^(?!(?:internal|node|v8)\/)/.test(str))
6-
)
2+
import{builtinModules}from'module';
73

84
constbaseURL=newURL('file://');
95
baseURL.pathname=process.cwd()+'/';
106

117
exportfunctionresolve(specifier,base=baseURL){
12-
if(builtins.has(specifier)){
8+
if(builtinModules.includes(specifier)){
139
return{
1410
url: specifier,
1511
format: 'builtin'

‎test/parallel/test-trace-events-api.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
constcommon=require('../common');
55

6-
if(!process.binding('config').hasTracing)
6+
try{
7+
require('trace_events');
8+
}catch{
79
common.skip('missing trace events');
10+
}
11+
812
common.skipIfWorker();// https://github.com/nodejs/node/issues/22767
913

1014
constassert=require('assert');

‎test/parallel/test-trace-events-async-hooks-dynamic.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
'use strict';
22

33
constcommon=require('../common');
4-
if(!process.binding('config').hasTracing)
4+
try{
5+
require('trace_events');
6+
}catch{
57
common.skip('missing trace events');
8+
}
69

710
constassert=require('assert');
811
constcp=require('child_process');

‎test/parallel/test-trace-events-async-hooks-worker.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
'use strict';
22

33
constcommon=require('../common');
4-
if(!process.binding('config').hasTracing)
4+
try{
5+
require('trace_events');
6+
}catch{
57
common.skip('missing trace events');
8+
}
69

710
constassert=require('assert');
811
constcp=require('child_process');

0 commit comments

Comments
 (0)