Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Unified Diff: Source/bindings/core/v8/V8Initializer.cpp

Issue 657063002: Show stack traces in console for unhandled promise rejection messages. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fixed debugger-pause-on-promise-rejection.html test Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/inspector/sources/debugger/debugger-uncaught-promise-on-pause-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/V8Initializer.cpp
diff --git a/Source/bindings/core/v8/V8Initializer.cpp b/Source/bindings/core/v8/V8Initializer.cpp
index 3e3157b30eea1a0a7b7052b561545c2c3e07bf16..552f93ef7f021b4fa284135b312a91fe3a6cac7d 100644
--- a/Source/bindings/core/v8/V8Initializer.cpp
+++ b/Source/bindings/core/v8/V8Initializer.cpp
@@ -158,7 +158,23 @@ static void messageHandlerInMainThread(v8::Handle<v8::Message> message, v8::Hand
}
}
-typedef WillBeHeapDeque<ScriptValue> PromiseRejectMessageQueue;
+namespace {
+
+class PromiseRejectMessage {
+public:
+ PromiseRejectMessage(const ScriptValue& promise, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack)
+ : m_promise(promise)
+ , m_callStack(callStack)
+ {
+ }
+
+ const ScriptValue m_promise;
+ const RefPtrWillBeMember<ScriptCallStack> m_callStack;
+};
+
+} // namespace
+
+typedef WillBeHeapDeque<PromiseRejectMessage> PromiseRejectMessageQueue;
static PromiseRejectMessageQueue& promiseRejectMessageQueue()
{
@@ -172,14 +188,14 @@ void V8Initializer::reportRejectedPromises()
PromiseRejectMessageQueue& queue = promiseRejectMessageQueue();
while (!queue.isEmpty()) {
- ScriptValue promise = queue.takeFirst();
- ScriptState* scriptState = promise.scriptState();
+ PromiseRejectMessage message = queue.takeFirst();
+ ScriptState* scriptState = message.m_promise.scriptState();
if (!scriptState->contextIsValid())
continue;
ScriptState::Scope scope(scriptState);
- ASSERT(!promise.isEmpty());
- v8::Handle<v8::Value> value = promise.v8Value();
+ ASSERT(!message.m_promise.isEmpty());
+ v8::Handle<v8::Value> value = message.m_promise.v8Value();
ASSERT(!value.IsEmpty() && value->IsPromise());
if (v8::Handle<v8::Promise>::Cast(value)->HasHandler())
continue;
@@ -191,11 +207,12 @@ void V8Initializer::reportRejectedPromises()
const String errorMessage = "Unhandled promise rejection";
Vector<ScriptValue> args;
args.append(ScriptValue(scriptState, v8String(scriptState->isolate(), errorMessage)));
- args.append(promise);
+ args.append(message.m_promise);
RefPtrWillBeRawPtr<ScriptArguments> arguments = ScriptArguments::create(scriptState, args);
- RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, errorMessage, "", 0);
+ RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, errorMessage);
consoleMessage->setScriptArguments(arguments);
+ consoleMessage->setCallStack(message.m_callStack);
executionContext->addConsoleMessage(consoleMessage.release());
}
}
@@ -226,8 +243,13 @@ static void promiseRejectHandlerInMainThread(v8::PromiseRejectMessage message)
if (!toFrameIfNotDetached(context))
return;
+ RefPtrWillBeRawPtr<ScriptCallStack> callStack = nullptr;
+ v8::Handle<v8::StackTrace> stackTrace = message.GetStackTrace();
+ if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0)
+ callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallStackSizeToCapture, isolate);
+
ScriptState* scriptState = ScriptState::from(context);
- promiseRejectMessageQueue().append(ScriptValue(scriptState, promise));
+ promiseRejectMessageQueue().append(PromiseRejectMessage(ScriptValue(scriptState, promise), callStack));
}
static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8::AccessType type, v8::Local<v8::Value> data)
« no previous file with comments | « LayoutTests/inspector/sources/debugger/debugger-uncaught-promise-on-pause-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698