Skip to content

Commit c37d18d

Browse files
joyeecheungtargos
authored andcommitted
lib: streamline process.binding() handling
- 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>
1 parent 30a6f19 commit c37d18d

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

lib/internal/bootstrap/realm.js

+14-18
Original file line numberDiff line numberDiff line change
@@ -87,34 +87,26 @@ ObjectDefineProperty(process, 'moduleLoadList', {
8787
// more, we just implement them as legacy wrappers instead. See the
8888
// legacyWrapperList.
8989
const processBindingAllowList = new SafeSet([
90-
'async_wrap',
9190
'buffer',
9291
'cares_wrap',
9392
'config',
9493
'constants',
9594
'contextify',
96-
'crypto',
9795
'fs',
9896
'fs_event_wrap',
99-
'http_parser',
10097
'icu',
10198
'inspector',
10299
'js_stream',
103-
'natives',
104100
'os',
105101
'pipe_wrap',
106102
'process_wrap',
107-
'signal_wrap',
108103
'spawn_sync',
109104
'stream_wrap',
110105
'tcp_wrap',
111106
'tls_wrap',
112107
'tty_wrap',
113108
'udp_wrap',
114-
'url',
115-
'util',
116109
'uv',
117-
'v8',
118110
'zlib',
119111
]);
120112

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

149141
process.binding = function binding(module) {
150142
module = String(module);
143+
const mod = bindingObj[module];
144+
if (typeof mod === 'object') {
145+
return mod;
146+
}
151147
// Deprecated specific process.binding() modules, but not all, allow
152148
// selective fallback to internalBinding for the deprecated ones.
149+
if (runtimeDeprecatedList.has(module)) {
150+
process.emitWarning(
151+
`Access to process.binding('${module}') is deprecated.`,
152+
'DeprecationWarning',
153+
'DEP0111');
154+
return internalBinding(module);
155+
}
156+
if (legacyWrapperList.has(module)) {
157+
return requireBuiltin('internal/legacy/processbinding')[module]();
158+
}
153159
if (processBindingAllowList.has(module)) {
154-
if (runtimeDeprecatedList.has(module)) {
155-
runtimeDeprecatedList.delete(module);
156-
process.emitWarning(
157-
`Access to process.binding('${module}') is deprecated.`,
158-
'DeprecationWarning',
159-
'DEP0111');
160-
}
161-
if (legacyWrapperList.has(module)) {
162-
return requireBuiltin('internal/legacy/processbinding')[module]();
163-
}
164160
return internalBinding(module);
165161
}
166162
// eslint-disable-next-line no-restricted-syntax

0 commit comments

Comments
 (0)