Browse Source

Bugfix: ReportException shouldn't forget the top frame.

v0.7.4-release
Ryan Dahl 16 years ago
parent
commit
ef300d19cb
  1. 23
      src/node.cc

23
src/node.cc

@ -151,21 +151,21 @@ static void ReportException(TryCatch *try_catch) {
fflush(stderr); fflush(stderr);
return; return;
} }
Handle<Value> error = try_catch->Exception(); Handle<Value> error = try_catch->Exception();
Handle<String> stack; Handle<String> stack;
if (error->IsObject()) { if (error->IsObject()) {
Handle<Object> obj = Handle<Object>::Cast(error); Handle<Object> obj = Handle<Object>::Cast(error);
Handle<Value> raw_stack = obj->Get(String::New("stack")); Handle<Value> raw_stack = obj->Get(String::New("stack"));
if (raw_stack->IsString()) stack = Handle<String>::Cast(raw_stack); if (raw_stack->IsString()) stack = Handle<String>::Cast(raw_stack);
} }
if (stack.IsEmpty()) {
String::Utf8Value exception(error);
// Print (filename):(line number): (message). // Print (filename):(line number): (message).
String::Utf8Value filename(message->GetScriptResourceName()); String::Utf8Value filename(message->GetScriptResourceName());
const char* filename_string = ToCString(filename); const char* filename_string = ToCString(filename);
int linenum = message->GetLineNumber(); int linenum = message->GetLineNumber();
fprintf(stderr, "%s:%i: %s\n", filename_string, linenum, *exception); fprintf(stderr, "%s:%i\n", filename_string, linenum);
// Print line of source code. // Print line of source code.
String::Utf8Value sourceline(message->GetSourceLine()); String::Utf8Value sourceline(message->GetSourceLine());
const char* sourceline_string = ToCString(sourceline); const char* sourceline_string = ToCString(sourceline);
@ -181,9 +181,8 @@ static void ReportException(TryCatch *try_catch) {
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
if (stack.IsEmpty()) {
message->PrintCurrentStackTrace(stderr); message->PrintCurrentStackTrace(stderr);
} else { } else {
String::Utf8Value trace(stack); String::Utf8Value trace(stack);
fprintf(stderr, "%s\n", *trace); fprintf(stderr, "%s\n", *trace);
@ -265,15 +264,21 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
} }
v8::Handle<v8::Value> Compile(const v8::Arguments& args) { v8::Handle<v8::Value> Compile(const v8::Arguments& args) {
if (args.Length() < 2)
return Undefined();
HandleScope scope; HandleScope scope;
if (args.Length() < 2) {
return ThrowException(Exception::TypeError(
String::New("needs two arguments.")));
}
Local<String> source = args[0]->ToString(); Local<String> source = args[0]->ToString();
Local<String> filename = args[1]->ToString(); Local<String> filename = args[1]->ToString();
Handle<Value> result = ExecuteString(source, filename); Handle<Script> script = Script::Compile(source, filename);
if (script.IsEmpty()) return Undefined();
Handle<Value> result = script->Run();
if (result.IsEmpty()) return Undefined();
return scope.Close(result); return scope.Close(result);
} }

Loading…
Cancel
Save