@@ -1152,18 +1152,26 @@ void Isolate::DoThrow(Object* exception, MessageLocation* location) {
11521152 thread_local_top ()->pending_message_end_pos_ = location->end_pos ();
11531153 }
11541154
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).
11591158 if (fatal_exception_depth == 0 &&
11601159 FLAG_abort_on_uncaught_exception &&
11611160 (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+ }
11671175 }
11681176 } else if (location != NULL && !location->script ().is_null ()) {
11691177 // We are bootstrapping and caught an error where the location is set
@@ -1339,6 +1347,10 @@ void Isolate::SetCaptureStackTraceForUncaughtExceptions(
13391347 stack_trace_for_uncaught_exceptions_options_ = options;
13401348}
13411349
1350+ void Isolate::SetAbortOnUncaughtException (
1351+ v8::Isolate::abort_on_uncaught_exception_t callback) {
1352+ abort_on_uncaught_exception_callback_ = callback;
1353+ }
13421354
13431355bool Isolate::is_out_of_memory () {
13441356 if (has_pending_exception ()) {
@@ -1534,7 +1546,8 @@ Isolate::Isolate()
15341546 date_cache_(NULL ),
15351547 context_exit_happened_(false ),
15361548 deferred_handles_head_(NULL ),
1537- optimizing_compiler_thread_(this ) {
1549+ optimizing_compiler_thread_(this ),
1550+ abort_on_uncaught_exception_callback_(NULL ) {
15381551 TRACE_ISOLATE (constructor);
15391552
15401553 memset (isolate_addresses_, 0 ,
0 commit comments