|
70 | 70 | writable: false
|
71 | 71 | });
|
72 | 72 |
|
| 73 | + // internalBindingWhitelist contains the name of internalBinding modules |
| 74 | + // that are whitelisted for access via process.binding()... this is used |
| 75 | + // to provide a transition path for modules that are being moved over to |
| 76 | + // internalBinding. |
| 77 | + const internalBindingWhitelist = [ |
| 78 | + 'cares_wrap', |
| 79 | + 'fs_event_wrap', |
| 80 | + 'icu', |
| 81 | + 'udp_wrap', |
| 82 | + 'uv', |
| 83 | + 'pipe_wrap', |
| 84 | + 'http_parser', |
| 85 | + 'process_wrap', |
| 86 | + 'v8', |
| 87 | + 'tty_wrap', |
| 88 | + 'stream_wrap', |
| 89 | + 'signal_wrap', |
| 90 | + 'crypto', |
| 91 | + 'contextify', |
| 92 | + 'tcp_wrap', |
| 93 | + 'tls_wrap', |
| 94 | + 'util', |
| 95 | + 'async_wrap', |
| 96 | + 'url', |
| 97 | + 'spawn_sync', |
| 98 | + 'js_stream', |
| 99 | + 'zlib', |
| 100 | + 'buffer', |
| 101 | + 'natives', |
| 102 | + 'constants' |
| 103 | + ]; |
| 104 | + // We will use a lazy loaded SafeSet in internalBindingWhitelistHas |
| 105 | + // for checking existence in this list. |
| 106 | + let internalBindingWhitelistSet; |
| 107 | + |
73 | 108 | // Set up process.binding() and process._linkedBinding()
|
74 | 109 | {
|
75 | 110 | const bindingObj = ObjectCreate(null);
|
76 | 111 |
|
77 | 112 | process.binding = function binding(module) {
|
78 | 113 | module = String(module);
|
| 114 | + // Deprecated specific process.binding() modules, but not all, allow |
| 115 | + // selective fallback to internalBinding for the deprecated ones. |
| 116 | + if (internalBindingWhitelistHas(module)) { |
| 117 | + return internalBinding(module); |
| 118 | + } |
79 | 119 | let mod = bindingObj[module];
|
80 | 120 | if (typeof mod !== 'object') {
|
81 | 121 | mod = bindingObj[module] = getBinding(module);
|
|
376 | 416 | NativeModule.require('internal/process/coverage').setup();
|
377 | 417 | }
|
378 | 418 |
|
| 419 | + function internalBindingWhitelistHas(name) { |
| 420 | + if (!internalBindingWhitelistSet) { |
| 421 | + const { SafeSet } = NativeModule.require('internal/safe_globals'); |
| 422 | + internalBindingWhitelistSet = new SafeSet(internalBindingWhitelist); |
| 423 | + } |
| 424 | + return internalBindingWhitelistSet.has(name); |
| 425 | + } |
| 426 | + |
379 | 427 | // This will be passed to the bootstrapNodeJSCore function in
|
380 | 428 | // bootstrap/node.js.
|
381 | 429 | return loaderExports;
|
|
0 commit comments