Closed GoogleCodeExporter closed 8 years ago
It's a design issue, Google v8 will not generate the stack trace if you throw
something except a JS error object, because it store the stack trace in the
error object when it was created.
v8::Local<Value> v8::TryCatch::StackTrace() const {
ASSERT(isolate_ == i::Isolate::Current());
if (HasCaught()) {
i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_);
if (!raw_obj->IsJSObject()) return v8::Local<Value>();
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
i::HandleScope scope(isolate_);
i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_);
i::Handle<i::String> name = isolate_->factory()->LookupAsciiSymbol("stack");
if (!obj->HasProperty(*name)) return v8::Local<Value>();
i::Handle<i::Object> value = i::GetProperty(obj, name);
if (value.is_null()) return v8::Local<Value>();
return v8::Utils::ToLocal(scope.CloseAndEscape(value));
} else {
return v8::Local<Value>();
}
}
Original comment by flier...@gmail.com
on 1 Dec 2011 at 5:54
btw: if you want the detail of stack trace, please pass a name argument to the
eval method
ctxt = PyV8.JSContext()
ctxt.enter()
ctxt.eval("""function f() {
throw Error("err");
}""", 'test1')
ctxt.eval("function g() {f();}", 'test2')
try:
ctxt.eval("g();", 'test3')
and you could got the name and position
Error: err
at Error (unknown source)
at f (test1:2:19)
at g (test2:1:15)
at test3:1:1
the string format is easy to parse, I have add a JSError.frames property for it
def testParseStack(self):
self.assertEquals([
('Error', 'unknown source', None, None),
('test', 'native', None, None),
('<anonymous>', 'test0', 3, 5),
('f', 'test1', 2, 19),
('g', 'test2', 1, 15),
(None, 'test3', 1, None),
(None, 'test3', 1, 1),
], JSError.parse_stack("""Error: err
at Error (unknown source)
at test (native)
at new <anonymous> (test0:3:5)
at f (test1:2:19)
at g (test2:1:15)
at test3:1
at test3:1:1"""))
Original comment by flier...@gmail.com
on 1 Dec 2011 at 10:58
Original issue reported on code.google.com by
jo...@roxendal.com
on 29 Nov 2011 at 10:44