| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a4f50a6 commit dde7152
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,11 +19,7 @@ | |||
| 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 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,21 +25,25 @@ function setupStdio() { | |||
| 25 | 25 | setupProcessStdio(getMainThreadStdio()); | |
| 26 | 26 | } | |
| 27 | 27 | ||
| 28 | - // Non-POSIX platforms like Windows don't have certain methods. | ||
| 29 | - // Workers also lack these methods since they change process-global state. | ||
| 30 | - function setupProcessMethods(_chdir, _umask) { | ||
| 31 | - process.chdir = function chdir(directory) { | ||
| 28 | + // The execution of this function itself should not cause any side effects. | ||
| 29 | + function wrapProcessMethods(binding) { | ||
| 30 | + function chdir(directory) { | ||
| 32 | 31 | validateString(directory, 'directory'); | |
| 33 | - return _chdir(directory); | ||
| 34 | - }; | ||
| 32 | + return binding.chdir(directory); | ||
| 33 | + } | ||
| 35 | 34 | ||
| 36 | - process.umask = function umask(mask) { | ||
| 35 | + function umask(mask) { | ||
| 37 | 36 | if (mask === undefined) { | |
| 38 | 37 | // Get the mask | |
| 39 | - return _umask(mask); | ||
| 38 | + return binding.umask(mask); | ||
| 40 | 39 | } | |
| 41 | 40 | mask = validateMode(mask, 'mask'); | |
| 42 | - return _umask(mask); | ||
| 41 | + return binding.umask(mask); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + return { | ||
| 45 | + chdir, | ||
| 46 | + umask | ||
| 43 | 47 | }; | |
| 44 | 48 | } | |
| 45 | 49 | ||
@@ -171,7 +175,7 @@ function setupChildProcessIpcChannel() { | |||
| 171 | 175 | ||
| 172 | 176 | module.exports = { | |
| 173 | 177 | setupStdio, | |
| 174 | - setupProcessMethods, | ||
| 178 | + wrapProcessMethods, | ||
| 175 | 179 | setupSignalHandlers, | |
| 176 | 180 | setupChildProcessIpcChannel, | |
| 177 | 181 | wrapPosixCredentialSetters | |
| Back | FazBrowse Home | New Git URL |
0 commit comments