Commit 3e7c0d77 authored by aandrey@chromium.org's avatar aandrey@chromium.org

Get stack trace for uncaught exceptions/promise rejections from the simple stack when available.

We can convert simple stack trace of an Error object to the detailed stack that
is used for debugging. Do so when available, and only then fall back to
reporting stack trace at throw site.

R=yangguo@chromium.org, Yang
LOG=Y

Review URL: https://codereview.chromium.org/674423002

Cr-Commit-Position: refs/heads/master@{#24938}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24938 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d518d3bc
......@@ -6960,12 +6960,7 @@ Local<StackTrace> Exception::GetStackTrace(Handle<Value> exception) {
i::Handle<i::JSObject> js_obj = i::Handle<i::JSObject>::cast(obj);
i::Isolate* isolate = js_obj->GetIsolate();
ENTER_V8(isolate);
i::Handle<i::Name> key = isolate->factory()->detailed_stack_trace_symbol();
i::Handle<i::Object> property = i::JSObject::GetDataProperty(js_obj, key);
if (property->IsJSArray()) {
return Utils::StackTraceToLocal(i::Handle<i::JSArray>::cast(property));
}
return Local<StackTrace>();
return Utils::StackTraceToLocal(isolate->GetDetailedStackTrace(js_obj));
}
......
This diff is collapsed.
......@@ -746,6 +746,9 @@ class Isolate {
void CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object);
void CaptureAndSetSimpleStackTrace(Handle<JSObject> error_object,
Handle<Object> caller);
Handle<JSArray> GetDetailedStackTrace(Handle<JSObject> error_object);
Handle<JSArray> GetDetailedFromSimpleStackTrace(
Handle<JSObject> error_object);
// Returns if the top context may access the given global object. If
// the result is false, the pending exception is guaranteed to be
......
......@@ -17627,6 +17627,7 @@ TEST(CaptureStackTrace) {
static void StackTraceForUncaughtExceptionListener(
v8::Handle<v8::Message> message,
v8::Handle<Value>) {
report_count++;
v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
CHECK_EQ(2, stack_trace->GetFrameCount());
checkStackFrame("origin", "foo", 2, 3, false, false,
......@@ -17657,6 +17658,38 @@ TEST(CaptureStackTraceForUncaughtException) {
Function::Cast(*trouble)->Call(global, 0, NULL);
v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener);
CHECK_EQ(1, report_count);
}
TEST(GetStackTraceForUncaughtExceptionFromSimpleStackTrace) {
report_count = 0;
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
// Create an Error object first.
CompileRunWithOrigin(
"function foo() {\n"
"e=new Error('err');\n"
"};\n"
"function bar() {\n"
" foo();\n"
"};\n"
"var e;",
"origin");
v8::Local<v8::Object> global = env->Global();
Local<Value> trouble = global->Get(v8_str("bar"));
CHECK(trouble->IsFunction());
Function::Cast(*trouble)->Call(global, 0, NULL);
// Enable capturing detailed stack trace late, and throw the exception.
// The detailed stack trace should be extracted from the simple stack.
v8::V8::AddMessageListener(StackTraceForUncaughtExceptionListener);
v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
CompileRunWithOrigin("throw e", "origin");
v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener);
CHECK_EQ(1, report_count);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment