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:
parent
cbb05eda20
commit
6b686ffb75
3 changed files with 25 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue