Skip to content

Commit

Permalink
lib: runtime deprecate process.binding
Browse files Browse the repository at this point in the history
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
  • Loading branch information
RafaelGSS committed Jun 27, 2023
1 parent b38bc9f commit a2b9fec
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 23 deletions.
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,9 @@ The `produceCachedData` option is deprecated. Use

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/48568
description: Runtime deprecation.
- version: v11.12.0
pr-url: https://github.com/nodejs/node/pull/26500
description: Added support for `--pending-deprecation`.
Expand All @@ -2211,7 +2214,7 @@ changes:
description: Documentation-only deprecation.
-->

Type: Documentation-only (supports [`--pending-deprecation`][])
Type: Runtime

`process.binding()` is for use by Node.js internal code only.

Expand Down
18 changes: 0 additions & 18 deletions lib/internal/bootstrap/realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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]();
}
Expand Down
7 changes: 3 additions & 4 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
60 changes: 60 additions & 0 deletions test/parallel/test-process-binding-allowedlist-deprecation.js
Original file line number Diff line number Diff line change
@@ -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/);
}

0 comments on commit a2b9fec

Please sign in to comment.