From b0ba27b8b52493ecb08577e85afbc09770404df3 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 11 Aug 2018 09:54:41 -0700 Subject: [PATCH 1/3] process: wrap process.binding for selective deprecation Selectively deprecate `process.binding()` and fallthrough Refs: https://github.com/nodejs/node/pull/22163 --- lib/internal/bootstrap/node.js | 18 ++++++++++++++++++ .../test-process-binding-deprecation.js | 13 +++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/parallel/test-process-binding-deprecation.js 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')); From 7e4af610e5d98302e28ef2560c8386718bd4c617 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 13 Aug 2018 12:30:37 -0700 Subject: [PATCH 2/3] [Squash] address feedback --- lib/internal/bootstrap/node.js | 21 ++++++++----------- ...cess-binding-internalbinding-whitelist.js} | 8 ++----- 2 files changed, 11 insertions(+), 18 deletions(-) rename test/parallel/{test-process-binding-deprecation.js => test-process-binding-internalbinding-whitelist.js} (55%) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 9f99d149d9fd71..08daeb191551e5 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -321,20 +321,17 @@ // 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; - const internalBindingWhitelist = new Set(['uv']); - const internalBindingWarned = new Set(); + // 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) { - 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); + return internalBindingWhitelist.has(name) ? + internalBinding(name) : + processBinding(name); }; } diff --git a/test/parallel/test-process-binding-deprecation.js b/test/parallel/test-process-binding-internalbinding-whitelist.js similarity index 55% rename from test/parallel/test-process-binding-deprecation.js rename to test/parallel/test-process-binding-internalbinding-whitelist.js index 25a1dfd772ea5d..4e9136bac2fb18 100644 --- a/test/parallel/test-process-binding-deprecation.js +++ b/test/parallel/test-process-binding-internalbinding-whitelist.js @@ -4,10 +4,6 @@ const common = require('../common'); const assert = require('assert'); -common.expectWarning( - 'DeprecationWarning', - 'Use of process.binding(\'uv\') is deprecated.', - 'DEP0111' -); - +// Assert that whitelisted internalBinding modules are accessible via +// process.binding(). assert(process.binding('uv')); From 758fcf3cbb9b6ade352ad8feddae63b46c28bdfc Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 14 Aug 2018 13:38:30 -0700 Subject: [PATCH 3/3] [Squash] lint --- test/parallel/test-process-binding-internalbinding-whitelist.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-process-binding-internalbinding-whitelist.js b/test/parallel/test-process-binding-internalbinding-whitelist.js index 4e9136bac2fb18..ece967a0b76ab9 100644 --- a/test/parallel/test-process-binding-internalbinding-whitelist.js +++ b/test/parallel/test-process-binding-internalbinding-whitelist.js @@ -1,7 +1,7 @@ // Flags: --no-warnings 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); // Assert that whitelisted internalBinding modules are accessible via