@@ -1152,18 +1152,26 @@ void Isolate::DoThrow(Object* exception, MessageLocation* location) {
1152
1152
thread_local_top ()->pending_message_end_pos_ = location->end_pos ();
1153
1153
}
1154
1154
1155
- // If the abort-on-uncaught-exception flag is specified, abort on any
1156
- // exception not caught by JavaScript, even when an external handler is
1157
- // present. This flag is intended for use by JavaScript developers, so
1158
- // print a user-friendly stack trace (not an internal one).
1155
+ // If the abort-on-uncaught-exception flag is specified, and if the
1156
+ // exception is not caught by JavaScript (even when an external handler is
1157
+ // present).
1159
1158
if (fatal_exception_depth == 0 &&
1160
1159
FLAG_abort_on_uncaught_exception &&
1161
1160
(report_exception || can_be_caught_externally)) {
1162
- fatal_exception_depth++;
1163
- fprintf (stderr, " %s\n\n FROM\n " ,
1164
- *MessageHandler::GetLocalizedMessage (message_obj));
1165
- PrintCurrentStackTrace (stderr);
1166
- OS::Abort ();
1161
+ // If the embedder didn't specify a custom uncaught exception callback,
1162
+ // or if the custom callback determined that V8 should abort, then
1163
+ // abort
1164
+ bool should_abort = !abort_on_uncaught_exception_callback_ ||
1165
+ abort_on_uncaught_exception_callback_ ();
1166
+ if (should_abort) {
1167
+ fatal_exception_depth++;
1168
+ // This flag is intended for use by JavaScript developers, so
1169
+ // print a user-friendly stack trace (not an internal one).
1170
+ fprintf (stderr, " %s\n\n FROM\n " ,
1171
+ *MessageHandler::GetLocalizedMessage (message_obj));
1172
+ PrintCurrentStackTrace (stderr);
1173
+ OS::Abort ();
1174
+ }
1167
1175
}
1168
1176
} else if (location != NULL && !location->script ().is_null ()) {
1169
1177
// We are bootstrapping and caught an error where the location is set
@@ -1339,6 +1347,10 @@ void Isolate::SetCaptureStackTraceForUncaughtExceptions(
1339
1347
stack_trace_for_uncaught_exceptions_options_ = options;
1340
1348
}
1341
1349
1350
+ void Isolate::SetAbortOnUncaughtException (
1351
+ v8::Isolate::abort_on_uncaught_exception_t callback) {
1352
+ abort_on_uncaught_exception_callback_ = callback;
1353
+ }
1342
1354
1343
1355
bool Isolate::is_out_of_memory () {
1344
1356
if (has_pending_exception ()) {
@@ -1534,7 +1546,8 @@ Isolate::Isolate()
1534
1546
date_cache_(NULL ),
1535
1547
context_exit_happened_(false ),
1536
1548
deferred_handles_head_(NULL ),
1537
- optimizing_compiler_thread_(this ) {
1549
+ optimizing_compiler_thread_(this ),
1550
+ abort_on_uncaught_exception_callback_(NULL ) {
1538
1551
TRACE_ISOLATE (constructor);
1539
1552
1540
1553
memset (isolate_addresses_, 0 ,
0 commit comments