Skip to content

Commit

Permalink
lib: streamline process.binding() handling
Browse files Browse the repository at this point in the history
- Make processBindingAllowList a separate list from
  runtimeDeprecatedList and legacyWrapperList instead of being
  an umbrella one, so it's easier to see the stages the bindings
  are in.
- Cache process.binding() results so we don't need to mutate
  runtimeDeprecatedList.

PR-URL: #50773
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung authored and richardlau committed Mar 25, 2024
1 parent f182696 commit be3205a
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions lib/internal/bootstrap/realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,26 @@ ObjectDefineProperty(process, 'moduleLoadList', {
// more, we just implement them as legacy wrappers instead. See the
// legacyWrapperList.
const processBindingAllowList = new SafeSet([
'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',
]);

Expand Down Expand Up @@ -148,19 +140,23 @@ const experimentalModuleList = new SafeSet();

process.binding = function binding(module) {
module = String(module);
const mod = bindingObj[module];
if (typeof mod === 'object') {
return mod;
}
// Deprecated specific process.binding() modules, but not all, allow
// selective fallback to internalBinding for the deprecated ones.
if (runtimeDeprecatedList.has(module)) {
process.emitWarning(
`Access to process.binding('${module}') is deprecated.`,
'DeprecationWarning',
'DEP0111');
return internalBinding(module);
}
if (legacyWrapperList.has(module)) {
return requireBuiltin('internal/legacy/processbinding')[module]();
}
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]();
}
return internalBinding(module);
}
// eslint-disable-next-line no-restricted-syntax
Expand Down

0 comments on commit be3205a

Please sign in to comment.