From b57c1f51b9447b79d222f0c98b550eb6ed3f80ec Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 23 Nov 2010 18:46:13 -0800 Subject: [PATCH] Saner, yet still ugly, fix to displaying syntax errors --- src/node.cc | 22 ++++++++++++++-------- src/node.h | 1 + src/node_script.cc | 5 +++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/node.cc b/src/node.cc index 31f6d3cd2b75..d3012e95829a 100644 --- a/src/node.cc +++ b/src/node.cc @@ -925,26 +925,24 @@ ssize_t DecodeWrite(char *buf, return buflen; } -// Extracts a C str from a V8 Utf8Value. -const char* ToCString(const v8::String::Utf8Value& value) { - return *value ? *value : ""; -} -static void ReportException(TryCatch &try_catch, bool show_line) { +void DisplayExceptionLine (TryCatch &try_catch) { + HandleScope scope; + Handle message = try_catch.Message(); node::Stdio::DisableRawMode(STDIN_FILENO); fprintf(stderr, "\n"); - if (show_line && !message.IsEmpty()) { + if (!message.IsEmpty()) { // Print (filename):(line number): (message). String::Utf8Value filename(message->GetScriptResourceName()); - const char* filename_string = ToCString(filename); + const char* filename_string = *filename; int linenum = message->GetLineNumber(); fprintf(stderr, "%s:%i\n", filename_string, linenum); // Print line of source code. String::Utf8Value sourceline(message->GetSourceLine()); - const char* sourceline_string = ToCString(sourceline); + const char* sourceline_string = *sourceline; // HACK HACK HACK // @@ -978,6 +976,14 @@ static void ReportException(TryCatch &try_catch, bool show_line) { } fprintf(stderr, "\n"); } +} + + +static void ReportException(TryCatch &try_catch, bool show_line) { + HandleScope scope; + Handle message = try_catch.Message(); + + if (show_line) DisplayExceptionLine(try_catch); String::Utf8Value trace(try_catch.StackTrace()); diff --git a/src/node.h b/src/node.h index 07b7f5e17e73..dd5a36a66661 100644 --- a/src/node.h +++ b/src/node.h @@ -48,6 +48,7 @@ enum encoding {ASCII, UTF8, BASE64, BINARY}; enum encoding ParseEncoding(v8::Handle encoding_v, enum encoding _default = BINARY); void FatalException(v8::TryCatch &try_catch); +void DisplayExceptionLine(v8::TryCatch &try_catch); // hack v8::Local Encode(const void *buf, size_t len, enum encoding encoding = BINARY); diff --git a/src/node_script.cc b/src/node_script.cc index 9cae7483f308..5c4223d10e42 100644 --- a/src/node_script.cc +++ b/src/node_script.cc @@ -234,8 +234,9 @@ template