Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: runtime deprecate process.binding() #48568

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
Comment on lines -154 to -158
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this do the opposite of runtime deprecating?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was emitting a warning whenever a runtime deprecated module is called with process.binding. Example, process.binding('async_wrap'). Now, all the modules are deprecated, so I removed them in favor of:

process.binding = deprecate(process.binding,
                              'process.binding() is deprecated. ' +
    'Please use public APIs instead.', 'DEP0111');

Otherwise, users were going to see two warning deprecations for the same operation.

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/);

Check failure on line 59 in test/parallel/test-process-binding-allowedlist-deprecation.js

View workflow job for this annotation

GitHub Actions / test-asan

--- stderr --- node:assert:1026 throw err; ^ AssertionError [ERR_ASSERTION]: The input did not match the regular expression /process\.binding\(\) is deprecated/. Input: '' at Object.<anonymous> (/home/runner/work/node/node/test/parallel/test-process-binding-allowedlist-deprecation.js:59:10) at Module._compile (node:internal/modules/cjs/loader:1257:14) at Module._extensions..js (node:internal/modules/cjs/loader:1311:10) at Module.load (node:internal/modules/cjs/loader:1115:32) at Module._load (node:internal/modules/cjs/loader:962:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) at node:internal/main/run_main_module:23:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: '', expected: /process\.binding\(\) is deprecated/, operator: 'match' } Node.js v21.0.0-pre Command: out/Release/node /home/runner/work/node/node/test/parallel/test-process-binding-allowedlist-deprecation.js
}
Loading