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

process: wrap process.binding for selective fallthrough to internalBinding #22269

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Copy link
Member

Choose a reason for hiding this comment

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

please use SafeSet

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

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');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add docs in doc/api/deprecations.md

Copy link
Member

Choose a reason for hiding this comment

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

also it should be DEP00XX

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 is part of the existing DEP0111 process.binding deprecation. The documentation is already there. The odd but is that it's not a complete switch to a runtime deprecation.

internalBindingWarned.add(name);
}
return internalBinding(name);
}
return processBinding(name);
};
}

function setupGlobalVariables() {
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-process-binding-deprecation.js
Original file line number Diff line number Diff line change
@@ -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'));