diff --git a/src/node.cc b/src/node.cc index 41e06f8828..286e68d0e7 100644 --- a/src/node.cc +++ b/src/node.cc @@ -151,39 +151,38 @@ static void ReportException(TryCatch *try_catch) { fflush(stderr); 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); - // Print line of source code. - String::Utf8Value sourceline(message->GetSourceLine()); - const char* sourceline_string = ToCString(sourceline); - fprintf(stderr, "%s\n", sourceline_string); - // Print wavy underline (GetUnderline is deprecated). - int start = message->GetStartColumn(); - for (int i = 0; i < start; i++) { - fprintf(stderr, " "); - } - int end = message->GetEndColumn(); - for (int i = start; i < end; i++) { - fprintf(stderr, "^"); - } - fprintf(stderr, "\n"); - - message->PrintCurrentStackTrace(stderr); + // Print (filename):(line number): (message). + String::Utf8Value filename(message->GetScriptResourceName()); + const char* filename_string = ToCString(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); + fprintf(stderr, "%s\n", sourceline_string); + // Print wavy underline (GetUnderline is deprecated). + int start = message->GetStartColumn(); + for (int i = 0; i < start; i++) { + fprintf(stderr, " "); + } + int end = message->GetEndColumn(); + for (int i = start; i < end; i++) { + fprintf(stderr, "^"); + } + fprintf(stderr, "\n"); + if (stack.IsEmpty()) { + message->PrintCurrentStackTrace(stderr); } else { String::Utf8Value trace(stack); fprintf(stderr, "%s\n", *trace); @@ -265,15 +264,21 @@ Handle DLOpen(const v8::Arguments& args) { } v8::Handle Compile(const v8::Arguments& args) { - if (args.Length() < 2) - return Undefined(); - HandleScope scope; + if (args.Length() < 2) { + return ThrowException(Exception::TypeError( + String::New("needs two arguments."))); + } + Local source = args[0]->ToString(); Local filename = args[1]->ToString(); - Handle result = ExecuteString(source, filename); + Handle