diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 7299e71db52970..9f99d149d9fd71 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -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() { diff --git a/test/parallel/test-process-binding-deprecation.js b/test/parallel/test-process-binding-deprecation.js new file mode 100644 index 00000000000000..25a1dfd772ea5d --- /dev/null +++ b/test/parallel/test-process-binding-deprecation.js @@ -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'));