Skip to content

Commit

Permalink
process: wrap process.binding for selective deprecation
Browse files Browse the repository at this point in the history
Selectively deprecate `process.binding()` and fallthrough

Refs: nodejs#22163
  • Loading branch information
jasnell committed Aug 11, 2018
1 parent e039524 commit b0ba27b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,24 @@
for (var i = 0; i < arguments.length; i++)
this.push(arguments[i]);
}

// Deprecated specific process.binding() modules, but not all, allow
// selective fallback to internalBinding for the deprecated ones.
const processBinding = process.binding;
const internalBindingWhitelist = new Set(['uv']);
const internalBindingWarned = new Set();
process.binding = function binding(name) {
if (internalBindingWhitelist.has(name)) {
if (!internalBindingWarned.has(name)) {
process.emitWarning(
`Use of process.binding('${name}') is deprecated.`,
'DeprecationWarning', 'DEP0111');
internalBindingWarned.add(name);
}
return internalBinding(name);
}
return processBinding(name);
};
}

function setupGlobalVariables() {
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-process-binding-deprecation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Flags: --no-warnings
'use strict';

const common = require('../common');
const assert = require('assert');

common.expectWarning(
'DeprecationWarning',
'Use of process.binding(\'uv\') is deprecated.',
'DEP0111'
);

assert(process.binding('uv'));

0 comments on commit b0ba27b

Please sign in to comment.