From 8e6dd52683fee931235994c415aa4b9d303b1a32 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 15 Jan 2010 10:45:04 -0800 Subject: [PATCH] Hack to display more useful SyntaxError exceptions. For some reason v8 doesn't include the frame with the syntax error in the stack trace - so have to special case it. --- src/node.cc | 22 +++++++++++++++------- src/node.js | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/node.cc b/src/node.cc index 30802665e5d..96f131939fa 100644 --- a/src/node.cc +++ b/src/node.cc @@ -316,7 +316,7 @@ const char* ToCString(const v8::String::Utf8Value& value) { return *value ? *value : ""; } -static void ReportException(TryCatch *try_catch) { +static void ReportException(TryCatch *try_catch, bool show_line = false) { Handle message = try_catch->Message(); if (message.IsEmpty()) { fprintf(stderr, "Error: (no message)\n"); @@ -333,7 +333,7 @@ static void ReportException(TryCatch *try_catch) { if (raw_stack->IsString()) stack = Handle::Cast(raw_stack); } - if (stack.IsEmpty()) { + if (show_line) { // Print (filename):(line number): (message). String::Utf8Value filename(message->GetScriptResourceName()); const char* filename_string = ToCString(filename); @@ -353,7 +353,9 @@ static void ReportException(TryCatch *try_catch) { fprintf(stderr, "^"); } fprintf(stderr, "\n"); + } + if (stack.IsEmpty()) { message->PrintCurrentStackTrace(stderr); } else { String::Utf8Value trace(stack); @@ -736,7 +738,7 @@ Handle DLOpen(const v8::Arguments& args) { return Undefined(); } -v8::Handle Compile(const v8::Arguments& args) { +Handle Compile(const Arguments& args) { HandleScope scope; if (args.Length() < 2) { @@ -747,11 +749,17 @@ v8::Handle Compile(const v8::Arguments& args) { Local source = args[0]->ToString(); Local filename = args[1]->ToString(); - Handle