|
236 | 236 |
|
237 | 237 | er.domain = domain;
|
238 | 238 | er.domainThrown = true;
|
239 |
| - // wrap this in a try/catch so we don't get infinite throwing |
240 |
| - try { |
241 |
| - // One of three things will happen here. |
242 |
| - // |
243 |
| - // 1. There is a handler, caught = true |
244 |
| - // 2. There is no handler, caught = false |
245 |
| - // 3. It throws, caught = false |
246 |
| - // |
247 |
| - // If caught is false after this, then there's no need to exit() |
248 |
| - // the domain, because we're going to crash the process anyway. |
249 |
| - caught = domain.emit('error', er); |
250 |
| - |
251 |
| - // Exit all domains on the stack. Uncaught exceptions end the |
252 |
| - // current tick and no domains should be left on the stack |
253 |
| - // between ticks. |
254 |
| - var domainModule = NativeModule.require('domain'); |
255 |
| - domainStack.length = 0; |
256 |
| - domainModule.active = process.domain = null; |
257 |
| - } catch (er2) { |
258 |
| - // The domain error handler threw! oh no! |
259 |
| - // See if another domain can catch THIS error, |
260 |
| - // or else crash on the original one. |
261 |
| - // If the user already exited it, then don't double-exit. |
262 |
| - if (domain === domainModule.active) |
263 |
| - domainStack.pop(); |
264 |
| - if (domainStack.length) { |
265 |
| - var parentDomain = domainStack[domainStack.length - 1]; |
266 |
| - process.domain = domainModule.active = parentDomain; |
267 |
| - caught = process._fatalException(er2); |
268 |
| - } else |
269 |
| - caught = false; |
| 239 | + |
| 240 | + // The top-level domain-handler is handled separately. |
| 241 | + // |
| 242 | + // The reason is that if V8 was passed a command line option |
| 243 | + // asking it to abort on an uncaught exception (currently |
| 244 | + // "--abort-on-uncaught-exception"), we want an uncaught exception |
| 245 | + // in the top-level domain error handler to make the |
| 246 | + // process abort. Using try/catch here would always make V8 think |
| 247 | + // that these exceptions are caught, and thus would prevent it from |
| 248 | + // aborting in these cases. |
| 249 | + if (domainStack.length === 1) { |
| 250 | + try { |
| 251 | + // Set the _emittingTopLevelDomainError so that we know that, even |
| 252 | + // if technically the top-level domain is still active, it would |
| 253 | + // be ok to abort on an uncaught exception at this point |
| 254 | + process._emittingTopLevelDomainError = true; |
| 255 | + caught = domain.emit('error', er); |
| 256 | + } finally { |
| 257 | + process._emittingTopLevelDomainError = false; |
| 258 | + } |
| 259 | + } else { |
| 260 | + // wrap this in a try/catch so we don't get infinite throwing |
| 261 | + try { |
| 262 | + // One of three things will happen here. |
| 263 | + // |
| 264 | + // 1. There is a handler, caught = true |
| 265 | + // 2. There is no handler, caught = false |
| 266 | + // 3. It throws, caught = false |
| 267 | + // |
| 268 | + // If caught is false after this, then there's no need to exit() |
| 269 | + // the domain, because we're going to crash the process anyway. |
| 270 | + caught = domain.emit('error', er); |
| 271 | + |
| 272 | + // Exit all domains on the stack. Uncaught exceptions end the |
| 273 | + // current tick and no domains should be left on the stack |
| 274 | + // between ticks. |
| 275 | + var domainModule = NativeModule.require('domain'); |
| 276 | + domainStack.length = 0; |
| 277 | + domainModule.active = process.domain = null; |
| 278 | + } catch (er2) { |
| 279 | + // The domain error handler threw! oh no! |
| 280 | + // See if another domain can catch THIS error, |
| 281 | + // or else crash on the original one. |
| 282 | + // If the user already exited it, then don't double-exit. |
| 283 | + if (domain === domainModule.active) |
| 284 | + domainStack.pop(); |
| 285 | + if (domainStack.length) { |
| 286 | + var parentDomain = domainStack[domainStack.length - 1]; |
| 287 | + process.domain = domainModule.active = parentDomain; |
| 288 | + caught = process._fatalException(er2); |
| 289 | + } else { |
| 290 | + caught = false; |
| 291 | + } |
| 292 | + } |
270 | 293 | }
|
271 | 294 | } else {
|
272 | 295 | caught = process.emit('uncaughtException', er);
|
|
0 commit comments