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