@@ -1090,19 +1090,30 @@ void Isolate::DoThrow(Object* exception, MessageLocation* location) {
1090
1090
thread_local_top ()->pending_message_end_pos_ = location->end_pos ();
1091
1091
}
1092
1092
1093
- // If the abort-on-uncaught-exception flag is specified, abort on any
1094
- // exception not caught by JavaScript, even when an external handler is
1095
- // present. This flag is intended for use by JavaScript developers, so
1096
- // print a user-friendly stack trace (not an internal one).
1093
+ // If the abort-on-uncaught-exception flag is specified, and if the
1094
+ // exception is not caught by JavaScript (even when an external handler is
1095
+ // present).
1097
1096
if (fatal_exception_depth == 0 &&
1098
1097
FLAG_abort_on_uncaught_exception &&
1099
1098
(report_exception || can_be_caught_externally)) {
1100
- fatal_exception_depth++;
1101
- PrintF (stderr,
1102
- " %s\n\n FROM\n " ,
1103
- MessageHandler::GetLocalizedMessage (this , message_obj).get ());
1104
- PrintCurrentStackTrace (stderr);
1105
- base::OS::Abort ();
1099
+ // If the embedder didn't specify a custom uncaught exception callback,
1100
+ // or if the custom callback determined that V8 should abort, then
1101
+ // abort
1102
+ bool should_abort = !abort_on_uncaught_exception_callback_ ||
1103
+ abort_on_uncaught_exception_callback_ (
1104
+ reinterpret_cast <v8::Isolate*>(this )
1105
+ );
1106
+
1107
+ if (should_abort) {
1108
+ fatal_exception_depth++;
1109
+ // This flag is intended for use by JavaScript developers, so
1110
+ // print a user-friendly stack trace (not an internal one).
1111
+ PrintF (stderr,
1112
+ " %s\n\n FROM\n " ,
1113
+ MessageHandler::GetLocalizedMessage (this , message_obj).get ());
1114
+ PrintCurrentStackTrace (stderr);
1115
+ base::OS::Abort ();
1116
+ }
1106
1117
}
1107
1118
} else if (location != NULL && !location->script ().is_null ()) {
1108
1119
// We are bootstrapping and caught an error where the location is set
@@ -1299,6 +1310,12 @@ void Isolate::SetCaptureStackTraceForUncaughtExceptions(
1299
1310
}
1300
1311
1301
1312
1313
+ void Isolate::SetAbortOnUncaughtException (
1314
+ v8::Isolate::abort_on_uncaught_exception_t callback) {
1315
+ abort_on_uncaught_exception_callback_ = callback;
1316
+ }
1317
+
1318
+
1302
1319
Handle <Context> Isolate::native_context () {
1303
1320
return handle (context ()->native_context ());
1304
1321
}
@@ -1474,7 +1491,8 @@ Isolate::Isolate()
1474
1491
num_sweeper_threads_(0 ),
1475
1492
stress_deopt_count_(0 ),
1476
1493
next_optimization_id_(0 ),
1477
- use_counter_callback_(NULL ) {
1494
+ use_counter_callback_(NULL ),
1495
+ abort_on_uncaught_exception_callback_(NULL ) {
1478
1496
id_ = base::NoBarrier_AtomicIncrement (&isolate_counter_, 1 );
1479
1497
TRACE_ISOLATE (constructor);
1480
1498
0 commit comments