diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 7299e71db52970..08daeb191551e5 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -318,6 +318,21 @@ 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 { SafeSet } = NativeModule.require('internal/safe_globals'); + const processBinding = process.binding; + // internalBindingWhitelist contains the name of internalBinding modules + // that are whitelisted for access via process.binding()... this is used + // to provide a transition path for modules that are being moved over to + // internalBinding. + const internalBindingWhitelist = new SafeSet(['uv']); + process.binding = function binding(name) { + return internalBindingWhitelist.has(name) ? + internalBinding(name) : + processBinding(name); + }; } function setupGlobalVariables() { diff --git a/test/parallel/test-process-binding-internalbinding-whitelist.js b/test/parallel/test-process-binding-internalbinding-whitelist.js new file mode 100644 index 00000000000000..ece967a0b76ab9 --- /dev/null +++ b/test/parallel/test-process-binding-internalbinding-whitelist.js @@ -0,0 +1,9 @@ +// Flags: --no-warnings +'use strict'; + +require('../common'); +const assert = require('assert'); + +// Assert that whitelisted internalBinding modules are accessible via +// process.binding(). +assert(process.binding('uv'));