-
-
Save TooTallNate/39f29d797c6dd8427ddb to your computer and use it in GitHub Desktop.
add FatalException(Handle<Value> error) to node.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/node.cc b/src/node.cc | |
index b07d2ee..2f20a97 100644 | |
--- a/src/node.cc | |
+++ b/src/node.cc | |
@@ -1847,6 +1847,57 @@ static void OnFatalError(const char* location, const char* message) { | |
exit(1); | |
} | |
+void FatalException(Handle<Value> error) { | |
+ HandleScope scope; | |
+ | |
+ if (listeners_symbol.IsEmpty()) { | |
+ listeners_symbol = NODE_PSYMBOL("listeners"); | |
+ uncaught_exception_symbol = NODE_PSYMBOL("uncaughtException"); | |
+ emit_symbol = NODE_PSYMBOL("emit"); | |
+ } | |
+ | |
+ Local<Value> listeners_v = process->Get(listeners_symbol); | |
+ assert(listeners_v->IsFunction()); | |
+ | |
+ Local<Function> listeners = Local<Function>::Cast(listeners_v); | |
+ | |
+ Local<String> uncaught_exception_symbol_l = Local<String>::New(uncaught_exception_symbol); | |
+ Local<Value> argv[1] = { uncaught_exception_symbol_l }; | |
+ Local<Value> ret = listeners->Call(process, 1, argv); | |
+ | |
+ assert(ret->IsArray()); | |
+ | |
+ Local<Array> listener_array = Local<Array>::Cast(ret); | |
+ | |
+ uint32_t length = listener_array->Length(); | |
+ // Report and exit if process has no "uncaughtException" listener | |
+ if (length == 0) { | |
+ //ReportException(try_catch, true); | |
+ fprintf(stderr, "Uncaught exception bro!\n"); | |
+ exit(1); | |
+ } | |
+ | |
+ // Otherwise fire the process "uncaughtException" event | |
+ Local<Value> emit_v = process->Get(emit_symbol); | |
+ assert(emit_v->IsFunction()); | |
+ | |
+ Local<Function> emit = Local<Function>::Cast(emit_v); | |
+ | |
+ Handle<Value> event_argv[2] = { uncaught_exception_symbol_l, error }; | |
+ | |
+ TryCatch event_try_catch; | |
+ emit->Call(process, 2, event_argv); | |
+ | |
+ if (event_try_catch.HasCaught()) { | |
+ // the uncaught exception event threw, so we must exit. | |
+ ReportException(event_try_catch, true); | |
+ exit(1); | |
+ } | |
+ | |
+ // This makes sure uncaught exceptions don't interfere with process.nextTick | |
+ StartTickSpinner(); | |
+} | |
+ | |
void FatalException(TryCatch &try_catch) { | |
HandleScope scope; | |
diff --git a/src/node.h b/src/node.h | |
index 40e9705..0d20bf8 100644 | |
--- a/src/node.h | |
+++ b/src/node.h | |
@@ -130,6 +130,7 @@ void SetPrototypeMethod(target_t target, | |
enum encoding {ASCII, UTF8, BASE64, UCS2, BINARY, HEX}; | |
enum encoding ParseEncoding(v8::Handle<v8::Value> encoding_v, | |
enum encoding _default = BINARY); | |
+NODE_EXTERN void FatalException(v8::Handle<v8::Value> error); | |
NODE_EXTERN void FatalException(v8::TryCatch &try_catch); | |
void DisplayExceptionLine(v8::TryCatch &try_catch); // hack | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment