From afd9e714d3937288de51116a45234c1e86a9444f Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 31 Aug 2009 18:22:09 +0200 Subject: [PATCH] Stack traces for mjsunit errors, better error reporting function. The error reporting function tries to look at the "stack" element of the exception. --- src/node.cc | 46 ++++++++++++++++++++++++++--------------- test/mjsunit/mjsunit.js | 1 + 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/node.cc b/src/node.cc index 21c134c9ab..bd160164b2 100644 --- a/src/node.cc +++ b/src/node.cc @@ -32,23 +32,29 @@ ToCString(const v8::String::Utf8Value& value) return *value ? *value : ""; } -void -ReportException(TryCatch* try_catch) +static void +ReportException (TryCatch &try_catch) { - HandleScope handle_scope; - String::Utf8Value exception(try_catch->Exception()); - const char* exception_string = ToCString(exception); - Handle message = try_catch->Message(); + Handle message = try_catch.Message(); if (message.IsEmpty()) { - // V8 didn't provide any extra information about this error; just - // print the exception. - fprintf(stderr, "%s\n", exception_string); - } else { + fprintf(stderr, "Error: (no message)\n"); + return; + } + Handle error = try_catch.Exception(); + Handle stack; + if (error->IsObject()) { + Handle obj = Handle::Cast(error); + Handle raw_stack = obj->Get(String::New("stack")); + if (raw_stack->IsString()) stack = Handle::Cast(raw_stack); + } + if (stack.IsEmpty()) { + String::Utf8Value exception(error); + // Print (filename):(line number): (message). String::Utf8Value filename(message->GetScriptResourceName()); const char* filename_string = ToCString(filename); int linenum = message->GetLineNumber(); - fprintf(stderr, "%s:%i: %s\n", filename_string, linenum, exception_string); + fprintf(stderr, "%s:%i: %s\n", filename_string, linenum, *exception); // Print line of source code. String::Utf8Value sourceline(message->GetSourceLine()); const char* sourceline_string = ToCString(sourceline); @@ -65,6 +71,11 @@ ReportException(TryCatch* try_catch) fprintf(stderr, "\n"); message->PrintCurrentStackTrace(stderr); + + + } else { + String::Utf8Value trace(stack); + fprintf(stderr, "%s\n", *trace); } } @@ -78,13 +89,13 @@ ExecuteString(v8::Handle source, Handle