mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
v8: add api for aborting on uncaught exception
Add v8::Isolate::SetAbortOnUncaughtException() so the user can be notified when an uncaught exception has bubbled. PR-URL: https://github.com/joyent/node/pull/8666 Reviewed-by: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
1 parent
8032a21025
commit
fbff7054a4
4 files changed
+44
-10
No files matched your search
Vendored
+11
@@ -2845,6 +2845,17 @@ class V8EXPORT Isolate {
|
|||||||
*/
|
*/
|
||||||
static Isolate* GetCurrent();
|
static Isolate* GetCurrent();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom callback used by embedders to help V8 determine if it should abort
|
||||||
|
* when it throws and no internal handler can catch the exception.
|
||||||
|
* If FLAG_abort_on_uncaught_exception is true, then V8 will abort if either:
|
||||||
|
* - no custom callback is set.
|
||||||
|
* - the custom callback set returns true.
|
||||||
|
* Otherwise it won't abort.
|
||||||
|
*/
|
||||||
|
typedef bool (*abort_on_uncaught_exception_t)();
|
||||||
|
void SetAbortOnUncaughtException(abort_on_uncaught_exception_t callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methods below this point require holding a lock (using Locker) in
|
* Methods below this point require holding a lock (using Locker) in
|
||||||
* a multi-threaded environment.
|
* a multi-threaded environment.
|
||||||
|
|||||||
Vendored
+5
@@ -5565,6 +5565,11 @@ void Isolate::Enter() {
|
|||||||
isolate->Enter();
|
isolate->Enter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Isolate::SetAbortOnUncaughtException(
|
||||||
|
abort_on_uncaught_exception_t callback) {
|
||||||
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
||||||
|
isolate->SetAbortOnUncaughtException(callback);
|
||||||
|
}
|
||||||
|
|
||||||
void Isolate::Exit() {
|
void Isolate::Exit() {
|
||||||
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
||||||
|
|||||||
Vendored
+23
-10
@@ -1152,18 +1152,26 @@ void Isolate::DoThrow(Object* exception, MessageLocation* location) {
|
|||||||
thread_local_top()->pending_message_end_pos_ = location->end_pos();
|
thread_local_top()->pending_message_end_pos_ = location->end_pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the abort-on-uncaught-exception flag is specified, abort on any
|
// If the abort-on-uncaught-exception flag is specified, and if the
|
||||||
// exception not caught by JavaScript, even when an external handler is
|
// exception is not caught by JavaScript (even when an external handler is
|
||||||
// present. This flag is intended for use by JavaScript developers, so
|
// present).
|
||||||
// print a user-friendly stack trace (not an internal one).
|
|
||||||
if (fatal_exception_depth == 0 &&
|
if (fatal_exception_depth == 0 &&
|
||||||
FLAG_abort_on_uncaught_exception &&
|
FLAG_abort_on_uncaught_exception &&
|
||||||
(report_exception || can_be_caught_externally)) {
|
(report_exception || can_be_caught_externally)) {
|
||||||
fatal_exception_depth++;
|
// If the embedder didn't specify a custom uncaught exception callback,
|
||||||
fprintf(stderr, "%s\n\nFROM\n",
|
// or if the custom callback determined that V8 should abort, then
|
||||||
*MessageHandler::GetLocalizedMessage(message_obj));
|
// abort
|
||||||
PrintCurrentStackTrace(stderr);
|
bool should_abort = !abort_on_uncaught_exception_callback_ ||
|
||||||
OS::Abort();
|
abort_on_uncaught_exception_callback_();
|
||||||
|
if (should_abort) {
|
||||||
|
fatal_exception_depth++;
|
||||||
|
// This flag is intended for use by JavaScript developers, so
|
||||||
|
// print a user-friendly stack trace (not an internal one).
|
||||||
|
fprintf(stderr, "%s\n\nFROM\n",
|
||||||
|
*MessageHandler::GetLocalizedMessage(message_obj));
|
||||||
|
PrintCurrentStackTrace(stderr);
|
||||||
|
OS::Abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (location != NULL && !location->script().is_null()) {
|
} else if (location != NULL && !location->script().is_null()) {
|
||||||
// We are bootstrapping and caught an error where the location is set
|
// We are bootstrapping and caught an error where the location is set
|
||||||
@@ -1339,6 +1347,10 @@ void Isolate::SetCaptureStackTraceForUncaughtExceptions(
|
|||||||
stack_trace_for_uncaught_exceptions_options_ = options;
|
stack_trace_for_uncaught_exceptions_options_ = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Isolate::SetAbortOnUncaughtException(
|
||||||
|
v8::Isolate::abort_on_uncaught_exception_t callback) {
|
||||||
|
abort_on_uncaught_exception_callback_ = callback;
|
||||||
|
}
|
||||||
|
|
||||||
bool Isolate::is_out_of_memory() {
|
bool Isolate::is_out_of_memory() {
|
||||||
if (has_pending_exception()) {
|
if (has_pending_exception()) {
|
||||||
@@ -1534,7 +1546,8 @@ Isolate::Isolate()
|
|||||||
date_cache_(NULL),
|
date_cache_(NULL),
|
||||||
context_exit_happened_(false),
|
context_exit_happened_(false),
|
||||||
deferred_handles_head_(NULL),
|
deferred_handles_head_(NULL),
|
||||||
optimizing_compiler_thread_(this) {
|
optimizing_compiler_thread_(this),
|
||||||
|
abort_on_uncaught_exception_callback_(NULL) {
|
||||||
TRACE_ISOLATE(constructor);
|
TRACE_ISOLATE(constructor);
|
||||||
|
|
||||||
memset(isolate_addresses_, 0,
|
memset(isolate_addresses_, 0,
|
||||||
|
|||||||
Vendored
+5
@@ -692,6 +692,9 @@ class Isolate {
|
|||||||
int frame_limit,
|
int frame_limit,
|
||||||
StackTrace::StackTraceOptions options);
|
StackTrace::StackTraceOptions options);
|
||||||
|
|
||||||
|
typedef bool (*abort_on_uncaught_exception_t)();
|
||||||
|
void SetAbortOnUncaughtException(abort_on_uncaught_exception_t callback);
|
||||||
|
|
||||||
// Tells whether the current context has experienced an out of memory
|
// Tells whether the current context has experienced an out of memory
|
||||||
// exception.
|
// exception.
|
||||||
bool is_out_of_memory();
|
bool is_out_of_memory();
|
||||||
@@ -1292,6 +1295,8 @@ class Isolate {
|
|||||||
DeferredHandles* deferred_handles_head_;
|
DeferredHandles* deferred_handles_head_;
|
||||||
OptimizingCompilerThread optimizing_compiler_thread_;
|
OptimizingCompilerThread optimizing_compiler_thread_;
|
||||||
|
|
||||||
|
abort_on_uncaught_exception_t abort_on_uncaught_exception_callback_;
|
||||||
|
|
||||||
friend class ExecutionAccess;
|
friend class ExecutionAccess;
|
||||||
friend class HandleScopeImplementer;
|
friend class HandleScopeImplementer;
|
||||||
friend class IsolateInitializer;
|
friend class IsolateInitializer;
|
||||||
|
|||||||
Reference in new issue
Block a user