From a2b9fecd191943774043e2c6339a4f6be9b9a571 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Mon, 26 Jun 2023 20:45:02 -0300 Subject: [PATCH] lib: runtime deprecate process.binding Signed-off-by: RafaelGSS --- doc/api/deprecations.md | 5 +- lib/internal/bootstrap/realm.js | 18 ------ lib/internal/process/pre_execution.js | 7 +-- ...process-binding-allowedlist-deprecation.js | 60 +++++++++++++++++++ 4 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 test/parallel/test-process-binding-allowedlist-deprecation.js diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index d26d62a2c14dd0..3d4ffe75a9a081 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2203,6 +2203,9 @@ The `produceCachedData` option is deprecated. Use -Type: Documentation-only (supports [`--pending-deprecation`][]) +Type: Runtime `process.binding()` is for use by Node.js internal code only. diff --git a/lib/internal/bootstrap/realm.js b/lib/internal/bootstrap/realm.js index 608e3072850d45..496832d0fd97e6 100644 --- a/lib/internal/bootstrap/realm.js +++ b/lib/internal/bootstrap/realm.js @@ -116,15 +116,6 @@ const processBindingAllowList = new SafeSet([ 'zlib', ]); -const runtimeDeprecatedList = new SafeSet([ - 'async_wrap', - 'crypto', - 'http_parser', - 'signal_wrap', - 'url', - 'v8', -]); - const legacyWrapperList = new SafeSet([ 'natives', 'util', @@ -146,16 +137,7 @@ const experimentalModuleList = new SafeSet(); process.binding = function binding(module) { module = String(module); - // Deprecated specific process.binding() modules, but not all, allow - // selective fallback to internalBinding for the deprecated ones. if (processBindingAllowList.has(module)) { - if (runtimeDeprecatedList.has(module)) { - runtimeDeprecatedList.delete(module); - process.emitWarning( - `Access to process.binding('${module}') is deprecated.`, - 'DeprecationWarning', - 'DEP0111'); - } if (legacyWrapperList.has(module)) { return requireBuiltin('internal/legacy/processbinding')[module](); } diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js index 5f8569b1531c92..407513d2422551 100644 --- a/lib/internal/process/pre_execution.js +++ b/lib/internal/process/pre_execution.js @@ -477,11 +477,10 @@ function initializeDeprecations() { }); } + process.binding = deprecate(process.binding, + 'process.binding() is deprecated. ' + + 'Please use public APIs instead.', 'DEP0111'); if (pendingDeprecation) { - process.binding = deprecate(process.binding, - 'process.binding() is deprecated. ' + - 'Please use public APIs instead.', 'DEP0111'); - process._tickCallback = deprecate(process._tickCallback, 'process._tickCallback() is deprecated', 'DEP0134'); diff --git a/test/parallel/test-process-binding-allowedlist-deprecation.js b/test/parallel/test-process-binding-allowedlist-deprecation.js new file mode 100644 index 00000000000000..cf3594a12240f8 --- /dev/null +++ b/test/parallel/test-process-binding-allowedlist-deprecation.js @@ -0,0 +1,60 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const { spawnSync } = require('child_process'); + +// Assert that all allowed process.binding modules are +// runtime deprecated. +const processBindingAllowList = [ + 'async_wrap', + 'buffer', + 'cares_wrap', + 'config', + 'constants', + 'contextify', + 'crypto', + 'fs', + 'fs_event_wrap', + 'http_parser', + 'icu', + 'inspector', + 'js_stream', + 'natives', + 'os', + 'pipe_wrap', + 'process_wrap', + 'signal_wrap', + 'spawn_sync', + 'stream_wrap', + 'tcp_wrap', + 'tls_wrap', + 'tty_wrap', + 'udp_wrap', + 'url', + 'util', + 'uv', + 'v8', + 'zlib', +]; + +const requireCryptoModules = ['crypto', 'tls_wrap']; +const requireIntlModules = ['icu']; + +for (const module of processBindingAllowList) { + if (requireCryptoModules.includes(module) && !common.hasCrypto) { + continue; + } + + if (requireIntlModules.includes(module) && !common.hasIntl) { + continue; + } + + const { stderr } = spawnSync( + process.execPath, + [ + '-p', `process.binding('${module}');`, + ] + ); + assert.match(stderr.toString(), /process\.binding\(\) is deprecated/); +}