From 0257fd7ce91660b1f85b1a90a7d7acf0b90384ce Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 11 Aug 2018 09:54:41 -0700 Subject: [PATCH] process: wrap process.binding for selective fallthrough Selectively fallthrough `process.binding()` to `internalBinding()` Refs: https://github.com/nodejs/node/pull/22163 PR-URL: https://github.com/nodejs/node/pull/22269 Reviewed-By: Gus Caplan Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Jon Moss Reviewed-By: John-David Dalton Reviewed-By: Ruben Bridgewater --- lib/internal/bootstrap/node.js | 15 +++++++++++++++ ...t-process-binding-internalbinding-whitelist.js | 9 +++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/parallel/test-process-binding-internalbinding-whitelist.js 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'));