From b0ba27b8b52493ecb08577e85afbc09770404df3 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 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'));