1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

add javascript_stacktrace to the JavascriptError to view the full javascript stack.

This commit is contained in:
Charles Lowell 2010-03-01 00:25:02 -06:00
parent cbb05eda20
commit 6b686ffb75
3 changed files with 25 additions and 4 deletions

View file

@ -57,6 +57,8 @@ V8::Context.open(:with => V8::Shell.new) do |cxt|
result = cxt.eval(line)
puts(result) unless result.nil?
rescue V8::JavascriptError => e
puts e.javascript_stacktrace
rescue StandardError => e
puts e
end

View file

@ -58,6 +58,15 @@ VALUE v8_cxt_open(VALUE self) {
}
}
VALUE Racer_Error_Message(TryCatch& exception) {
VALUE msg = V8_Ref_Create(V8_C_Message, exception.Message());
Local<Value> stack = exception.StackTrace();
if (!stack.IsEmpty()) {
rb_iv_set(msg,"@stack",V82RB(stack));
}
return msg;
}
VALUE v8_cxt_eval(VALUE self, VALUE source, VALUE filename) {
HandleScope handles;
TryCatch exceptions;
@ -66,12 +75,12 @@ VALUE v8_cxt_eval(VALUE self, VALUE source, VALUE filename) {
Local<Value> source_str = RB2V8(source);
Local<Value> source_name = RTEST(filename) ? RB2V8(filename) : *String::New("<eval>");
Local<Script> script = Script::Compile(source_str->ToString(), source_name);
if (exceptions.HasCaught()) {
return V8_Ref_Create(V8_C_Message, exceptions.Message());
}
if (exceptions.HasCaught()) {
return Racer_Error_Message(exceptions);
}
Local<Value> result = script->Run();
if (exceptions.HasCaught()) {
return V8_Ref_Create(V8_C_Message, exceptions.Message());
return Racer_Error_Message(exceptions);
} else {
return V82RB(result);
}

View file

@ -95,7 +95,17 @@ module V8
@native.GetLineNumber()
end
def javascript_stacktrace
@native.stack
end
end
class RunawayScriptError < ContextError
end
module C
class Message
attr_reader :stack
end
end
end