Skip to content

Commit b0ba27b

Browse files
committed
process: wrap process.binding for selective deprecation
Selectively deprecate `process.binding()` and fallthrough Refs: nodejs#22163
1 parent e039524 commit b0ba27b

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

lib/internal/bootstrap/node.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,24 @@
318318
for (var i = 0; i < arguments.length; i++)
319319
this.push(arguments[i]);
320320
}
321+
322+
// Deprecated specific process.binding() modules, but not all, allow
323+
// selective fallback to internalBinding for the deprecated ones.
324+
const processBinding = process.binding;
325+
const internalBindingWhitelist = new Set(['uv']);
326+
const internalBindingWarned = new Set();
327+
process.binding = function binding(name) {
328+
if (internalBindingWhitelist.has(name)) {
329+
if (!internalBindingWarned.has(name)) {
330+
process.emitWarning(
331+
`Use of process.binding('${name}') is deprecated.`,
332+
'DeprecationWarning', 'DEP0111');
333+
internalBindingWarned.add(name);
334+
}
335+
return internalBinding(name);
336+
}
337+
return processBinding(name);
338+
};
321339
}
322340

323341
function setupGlobalVariables() {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Flags: --no-warnings
2+
'use strict';
3+
4+
const common = require('../common');
5+
const assert = require('assert');
6+
7+
common.expectWarning(
8+
'DeprecationWarning',
9+
'Use of process.binding(\'uv\') is deprecated.',
10+
'DEP0111'
11+
);
12+
13+
assert(process.binding('uv'));

0 commit comments

Comments
 (0)