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

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

Issue 1095943002: DevTools: [console] Logged promise rejections do not change state once handled (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: for landing Created 5 years, 8 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 | « Source/bindings/core/v8/RejectedPromises.h ('k') | Source/bindings/core/v8/V8Initializer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/RejectedPromises.cpp
diff --git a/Source/bindings/core/v8/RejectedPromises.cpp b/Source/bindings/core/v8/RejectedPromises.cpp
index 97e5a1b1569b3a13becff0088dc014207bde6f53..569b9457ac4a663eab1538e0b574eb2203668863 100644
--- a/Source/bindings/core/v8/RejectedPromises.cpp
+++ b/Source/bindings/core/v8/RejectedPromises.cpp
@@ -14,6 +14,8 @@
namespace blink {
+static const unsigned maxReportedHandlersPendingResolution = 1000;
+
class RejectedPromises::Message final : public NoBaseWillBeGarbageCollectedFinalized<RejectedPromises::Message> {
public:
static PassOwnPtrWillBeRawPtr<Message> create(const ScriptValue& promise, const ScriptValue& exception, const String& errorMessage, const String& resourceName, int scriptId, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack)
@@ -36,6 +38,7 @@ private:
, m_lineNumber(lineNumber)
, m_columnNumber(columnNumber)
, m_callStack(callStack)
+ , m_consoleMessageId(0)
{
}
@@ -49,6 +52,7 @@ private:
const int m_lineNumber;
const int m_columnNumber;
const RefPtrWillBeMember<ScriptCallStack> m_callStack;
+ unsigned m_consoleMessageId;
};
RejectedPromises::RejectedPromises()
@@ -62,7 +66,7 @@ DEFINE_TRACE(RejectedPromises)
visitor->trace(m_queue);
}
-void RejectedPromises::add(ScriptState* scriptState, v8::PromiseRejectMessage data, const String& errorMessage, const String& resourceName, int scriptId, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack)
+void RejectedPromises::rejectedWithNoHandler(ScriptState* scriptState, v8::PromiseRejectMessage data, const String& errorMessage, const String& resourceName, int scriptId, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack)
{
v8::Handle<v8::Promise> promise = data.GetPromise();
OwnPtrWillBeRawPtr<Message> message = Message::create(ScriptValue(scriptState, promise), ScriptValue(scriptState, data.GetValue()), errorMessage, resourceName, scriptId, lineNumber, columnNumber, callStack);
@@ -70,6 +74,46 @@ void RejectedPromises::add(ScriptState* scriptState, v8::PromiseRejectMessage da
m_queue.append(message.release());
}
+void RejectedPromises::handlerAdded(v8::PromiseRejectMessage data)
+{
+ // First look it up in the pending messages and fast return, it'll be covered by processQueue().
+ for (auto it = m_queue.begin(); it != m_queue.end(); ++it) {
+ ScriptState* scriptState = (*it)->m_promise.scriptState();
+ if (!scriptState->contextIsValid())
+ continue;
+
+ ScriptState::Scope scope(scriptState);
+ v8::Handle<v8::Value> promise = (*it)->m_promise.v8Value();
+ if (promise == data.GetPromise())
+ return;
+ }
+
+ // Then look it up in the reported errors.
+ for (auto it = m_reportedAsErrors.begin(); it != m_reportedAsErrors.end(); ++it) {
+ ScriptState* scriptState = (*it)->m_promise.scriptState();
+ if (!scriptState->contextIsValid())
+ continue;
+
+ ScriptState::Scope scope(scriptState);
+ v8::Handle<v8::Value> promise = (*it)->m_promise.v8Value();
+ if (promise != data.GetPromise())
+ continue;
+
+ // If execution termination has been triggered, quietly bail out.
+ if (v8::V8::IsExecutionTerminating(scriptState->isolate()))
+ continue;
+ ExecutionContext* executionContext = scriptState->executionContext();
+ if (!executionContext)
+ continue;
+
+ RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(JSMessageSource, RevokedErrorMessageLevel, "Handler added to rejected promise");
+ consoleMessage->setRelatedMessageId((*it)->m_consoleMessageId);
+ executionContext->addConsoleMessage(consoleMessage.release());
+ m_reportedAsErrors.remove(it);
+ break;
+ }
+}
+
void RejectedPromises::dispose()
{
processQueue();
@@ -115,7 +159,12 @@ void RejectedPromises::processQueue()
consoleMessage->setScriptArguments(arguments);
consoleMessage->setCallStack(message->m_callStack);
consoleMessage->setScriptId(message->m_scriptId);
+ message->m_consoleMessageId = consoleMessage->assignMessageId();
executionContext->addConsoleMessage(consoleMessage.release());
+
+ m_reportedAsErrors.append(message.release());
+ if (m_reportedAsErrors.size() > maxReportedHandlersPendingResolution)
+ m_reportedAsErrors.removeFirst();
}
}
« no previous file with comments | « Source/bindings/core/v8/RejectedPromises.h ('k') | Source/bindings/core/v8/V8Initializer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698