|
101 | 101 |
|
102 | 102 | const internalModule = NativeModule.require('internal/module'); |
103 | 103 | internalModule.addBuiltinLibsToObject(global); |
104 | | - evalScript('[eval]'); |
| 104 | + run(() => { |
| 105 | + evalScript('[eval]'); |
| 106 | + }); |
105 | 107 | } else if (process.argv[1]) { |
106 | 108 | // make process.argv[1] into a full path |
107 | 109 | var path = NativeModule.require('path'); |
|
127 | 129 | } |
128 | 130 |
|
129 | 131 | preloadModules(); |
130 | | - |
131 | | - if (process._debugWaitConnect && |
132 | | - process.execArgv.some(function(arg) { |
133 | | - return arg.match(/^--debug-brk(=[0-9]*)?$/); |
134 | | - })) { |
135 | | - |
136 | | - // XXX Fix this terrible hack! |
137 | | - // |
138 | | - // Give the client program a few ticks to connect. |
139 | | - // Otherwise, there's a race condition where `node debug foo.js` |
140 | | - // will not be able to connect in time to catch the first |
141 | | - // breakpoint message on line 1. |
142 | | - // |
143 | | - // A better fix would be to somehow get a message from the |
144 | | - // V8 debug object about a connection, and runMain when |
145 | | - // that occurs. --isaacs |
146 | | - |
147 | | - var debugTimeout = +process.env.NODE_DEBUG_TIMEOUT || 50; |
148 | | - setTimeout(Module.runMain, debugTimeout); |
149 | | - |
150 | | - } else { |
151 | | - // Main entry point into most programs: |
152 | | - Module.runMain(); |
153 | | - } |
154 | | - |
| 132 | + run(Module.runMain); |
155 | 133 | } else { |
156 | 134 | preloadModules(); |
157 | 135 | // If -i or --interactive were passed, or stdin is a TTY. |
|
334 | 312 | } |
335 | 313 | } |
336 | 314 |
|
| 315 | + function isDebugBreak() { |
| 316 | + return process.execArgv.some((arg) => { |
| 317 | + return arg.match(/^--debug-brk(=[0-9]*)?$/); |
| 318 | + }); |
| 319 | + } |
| 320 | + |
| 321 | + function run(entryFunction) { |
| 322 | + if (process._debugWaitConnect && isDebugBreak()) { |
| 323 | + |
| 324 | + // XXX Fix this terrible hack! |
| 325 | + // |
| 326 | + // Give the client program a few ticks to connect. |
| 327 | + // Otherwise, there's a race condition where `node debug foo.js` |
| 328 | + // will not be able to connect in time to catch the first |
| 329 | + // breakpoint message on line 1. |
| 330 | + // |
| 331 | + // A better fix would be to somehow get a message from the |
| 332 | + // V8 debug object about a connection, and runMain when |
| 333 | + // that occurs. --isaacs |
| 334 | + |
| 335 | + var debugTimeout = +process.env.NODE_DEBUG_TIMEOUT || 50; |
| 336 | + setTimeout(entryFunction, debugTimeout); |
| 337 | + |
| 338 | + } else { |
| 339 | + // Main entry point into most programs: |
| 340 | + entryFunction(); |
| 341 | + } |
| 342 | + } |
| 343 | + |
337 | 344 | // Below you find a minimal module system, which is used to load the node |
338 | 345 | // core modules found in lib/*.js. All core modules are compiled into the |
339 | 346 | // node binary, so they can be loaded faster. |
|
0 commit comments