|
19 | 19 |
|
20 | 20 | const { |
21 | 21 | _setupNextTick, |
22 | | - _setupPromises, _chdir, _cpuUsage, |
23 | | - _hrtime, _hrtimeBigInt, |
24 | | - _memoryUsage, _rawDebug, |
25 | | - _umask, |
26 | | - _shouldAbortOnUncaughtToggle |
| 22 | + _setupPromises |
27 | 23 | } = bootstrappers; |
28 | 24 | const { internalBinding, NativeModule } = loaderExports; |
29 | 25 |
|
@@ -56,15 +52,57 @@ function startup() { |
56 | 52 | ); |
57 | 53 | } |
58 | 54 |
|
59 | | - perThreadSetup.setupAssert(); |
60 | | - perThreadSetup.setupConfig(); |
| 55 | + // process.config is serialized config.gypi |
| 56 | + process.config = JSON.parse(internalBinding('native_module').config); |
61 | 57 |
|
| 58 | + const rawMethods = internalBinding('process_methods'); |
| 59 | + // Set up methods and events on the process object for the main thread |
62 | 60 | if (isMainThread) { |
| 61 | + // This depends on process being an event emitter |
63 | 62 | mainThreadSetup.setupSignalHandlers(internalBinding); |
| 63 | + |
| 64 | + process.abort = rawMethods.abort; |
| 65 | + const wrapped = mainThreadSetup.wrapProcessMethods(rawMethods); |
| 66 | + process.umask = wrapped.umask; |
| 67 | + process.chdir = wrapped.chdir; |
| 68 | + |
| 69 | + // TODO(joyeecheung): deprecate and remove these underscore methods |
| 70 | + process._debugProcess = rawMethods._debugProcess; |
| 71 | + process._debugEnd = rawMethods._debugEnd; |
| 72 | + process._startProfilerIdleNotifier = |
| 73 | + rawMethods._startProfilerIdleNotifier; |
| 74 | + process._stopProfilerIdleNotifier = rawMethods._stopProfilerIdleNotifier; |
64 | 75 | } |
65 | 76 |
|
66 | | - perThreadSetup.setupUncaughtExceptionCapture(exceptionHandlerState, |
67 | | - _shouldAbortOnUncaughtToggle); |
| 77 | + // Set up methods on the process object for all threads |
| 78 | + { |
| 79 | + process.cwd = rawMethods.cwd; |
| 80 | + process.dlopen = rawMethods.dlopen; |
| 81 | + process.uptime = rawMethods.uptime; |
| 82 | + |
| 83 | + // TODO(joyeecheung): either remove them or make them public |
| 84 | + process._getActiveRequests = rawMethods._getActiveRequests; |
| 85 | + process._getActiveHandles = rawMethods._getActiveHandles; |
| 86 | + |
| 87 | + // TODO(joyeecheung): remove these |
| 88 | + process.reallyExit = rawMethods.reallyExit; |
| 89 | + process._kill = rawMethods._kill; |
| 90 | + |
| 91 | + const wrapped = perThreadSetup.wrapProcessMethods( |
| 92 | + rawMethods, exceptionHandlerState |
| 93 | + ); |
| 94 | + process._rawDebug = wrapped._rawDebug; |
| 95 | + process.hrtime = wrapped.hrtime; |
| 96 | + process.hrtime.bigint = wrapped.hrtimeBigInt; |
| 97 | + process.cpuUsage = wrapped.cpuUsage; |
| 98 | + process.memoryUsage = wrapped.memoryUsage; |
| 99 | + process.kill = wrapped.kill; |
| 100 | + process.exit = wrapped.exit; |
| 101 | + process.setUncaughtExceptionCaptureCallback = |
| 102 | + wrapped.setUncaughtExceptionCaptureCallback; |
| 103 | + process.hasUncaughtExceptionCaptureCallback = |
| 104 | + wrapped.hasUncaughtExceptionCaptureCallback; |
| 105 | + } |
68 | 106 |
|
69 | 107 | NativeModule.require('internal/process/warning').setup(); |
70 | 108 | NativeModule.require('internal/process/next_tick').setup(_setupNextTick, |
@@ -90,22 +128,10 @@ function startup() { |
90 | 128 |
|
91 | 129 | if (isMainThread) { |
92 | 130 | mainThreadSetup.setupStdio(); |
93 | | - mainThreadSetup.setupProcessMethods(_chdir, _umask); |
94 | 131 | } else { |
95 | 132 | workerThreadSetup.setupStdio(); |
96 | 133 | } |
97 | 134 |
|
98 | | - const perf = internalBinding('performance'); |
99 | | - const { |
100 | | - NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE, |
101 | | - } = perf.constants; |
102 | | - |
103 | | - perThreadSetup.setupRawDebug(_rawDebug); |
104 | | - perThreadSetup.setupHrtime(_hrtime, _hrtimeBigInt); |
105 | | - perThreadSetup.setupCpuUsage(_cpuUsage); |
106 | | - perThreadSetup.setupMemoryUsage(_memoryUsage); |
107 | | - perThreadSetup.setupKillAndExit(); |
108 | | - |
109 | 135 | if (global.__coverage__) |
110 | 136 | NativeModule.require('internal/process/write-coverage').setup(); |
111 | 137 |
|
@@ -237,9 +263,37 @@ function startup() { |
237 | 263 | } |
238 | 264 | } |
239 | 265 |
|
240 | | - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE); |
| 266 | + // process.allowedNodeEnvironmentFlags |
| 267 | + Object.defineProperty(process, 'allowedNodeEnvironmentFlags', { |
| 268 | + get() { |
| 269 | + const flags = perThreadSetup.buildAllowedFlags(); |
| 270 | + process.allowedNodeEnvironmentFlags = flags; |
| 271 | + return process.allowedNodeEnvironmentFlags; |
| 272 | + }, |
| 273 | + // If the user tries to set this to another value, override |
| 274 | + // this completely to that value. |
| 275 | + set(value) { |
| 276 | + Object.defineProperty(this, 'allowedNodeEnvironmentFlags', { |
| 277 | + value, |
| 278 | + configurable: true, |
| 279 | + enumerable: true, |
| 280 | + writable: true |
| 281 | + }); |
| 282 | + }, |
| 283 | + enumerable: true, |
| 284 | + configurable: true |
| 285 | + }); |
| 286 | + // process.assert |
| 287 | + process.assert = deprecate( |
| 288 | + perThreadSetup.assert, |
| 289 | + 'process.assert() is deprecated. Please use the `assert` module instead.', |
| 290 | + 'DEP0100'); |
241 | 291 |
|
242 | | - perThreadSetup.setupAllowedFlags(); |
| 292 | + const perf = internalBinding('performance'); |
| 293 | + const { |
| 294 | + NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE, |
| 295 | + } = perf.constants; |
| 296 | + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE); |
243 | 297 |
|
244 | 298 | startExecution(); |
245 | 299 | } |
|