@@ -1090,19 +1090,30 @@ void Isolate::DoThrow(Object* exception, MessageLocation* location) {
10901090 thread_local_top ()->pending_message_end_pos_ = location->end_pos ();
10911091 }
10921092
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).
10971096 if (fatal_exception_depth == 0 &&
10981097 FLAG_abort_on_uncaught_exception &&
10991098 (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+ }
11061117 }
11071118 } else if (location != NULL && !location->script ().is_null ()) {
11081119 // We are bootstrapping and caught an error where the location is set
@@ -1299,6 +1310,12 @@ void Isolate::SetCaptureStackTraceForUncaughtExceptions(
12991310}
13001311
13011312
1313+ void Isolate::SetAbortOnUncaughtException (
1314+ v8::Isolate::abort_on_uncaught_exception_t callback) {
1315+ abort_on_uncaught_exception_callback_ = callback;
1316+ }
1317+
1318+
13021319Handle<Context> Isolate::native_context () {
13031320 return handle (context ()->native_context ());
13041321}
@@ -1474,7 +1491,8 @@ Isolate::Isolate()
14741491 num_sweeper_threads_(0 ),
14751492 stress_deopt_count_(0 ),
14761493 next_optimization_id_(0 ),
1477- use_counter_callback_(NULL ) {
1494+ use_counter_callback_(NULL ),
1495+ abort_on_uncaught_exception_callback_(NULL ) {
14781496 id_ = base::NoBarrier_AtomicIncrement (&isolate_counter_, 1 );
14791497 TRACE_ISOLATE (constructor);
14801498
0 commit comments