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

Unified Diff: Source/core/inspector/AsyncCallStackTracker.cpp

Issue 374903002: DevTools: Async call stacks for Promises and Object.observe. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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
Index: Source/core/inspector/AsyncCallStackTracker.cpp
diff --git a/Source/core/inspector/AsyncCallStackTracker.cpp b/Source/core/inspector/AsyncCallStackTracker.cpp
index 7c0da5d6e30a0e62d722ce88d5e4d3fb2fb62591..2ea60676f6ac7f85786ebde6dd140daac66ee6db 100644
--- a/Source/core/inspector/AsyncCallStackTracker.cpp
+++ b/Source/core/inspector/AsyncCallStackTracker.cpp
@@ -39,8 +39,8 @@
#include "core/events/EventTarget.h"
#include "core/xml/XMLHttpRequest.h"
#include "core/xml/XMLHttpRequestUpload.h"
-#include "wtf/text/AtomicStringHash.h"
#include "wtf/text/StringBuilder.h"
+#include "wtf/text/StringHash.h"
#include <v8.h>
namespace {
@@ -81,6 +81,7 @@ public:
HashMap<Event*, RefPtr<AsyncCallChain> > m_eventCallChains;
HashMap<EventTarget*, RefPtr<AsyncCallChain> > m_xhrCallChains;
HashMap<MutationObserver*, RefPtr<AsyncCallChain> > m_mutationObserverCallChains;
+ HashMap<String, RefPtr<AsyncCallChain> > m_v8AsyncTaskCallChains;
};
static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget)
@@ -296,6 +297,34 @@ void AsyncCallStackTracker::willDeliverMutationRecords(ExecutionContext* context
setCurrentAsyncCallChain(context, nullptr);
}
+static String makeV8AsyncTaskUniqueId(const String& eventName, int id)
+{
+ StringBuilder builder;
+ builder.append(eventName);
+ builder.appendNumber(id);
+ return builder.toString();
+}
+
+void AsyncCallStackTracker::didEnqueueV8AsyncTask(ExecutionContext* context, const String& eventName, int id, const ScriptValue& callFrames)
+{
+ ASSERT(context);
+ ASSERT(isEnabled());
+ if (!validateCallFrames(callFrames))
+ return;
+ ExecutionContextData* data = createContextDataIfNeeded(context);
+ data->m_v8AsyncTaskCallChains.set(makeV8AsyncTaskUniqueId(eventName, id), createAsyncCallChain(eventName, callFrames));
+}
+
+void AsyncCallStackTracker::willHandleV8AsyncTask(ExecutionContext* context, const String& eventName, int id)
+{
+ ASSERT(context);
+ ASSERT(isEnabled());
+ if (ExecutionContextData* data = m_executionContextDataMap.get(context))
+ setCurrentAsyncCallChain(context, data->m_v8AsyncTaskCallChains.take(makeV8AsyncTaskUniqueId(eventName, id)));
+ else
+ setCurrentAsyncCallChain(context, nullptr);
+}
+
void AsyncCallStackTracker::didFireAsyncCall()
{
clearCurrentAsyncCallChain();
@@ -303,6 +332,10 @@ void AsyncCallStackTracker::didFireAsyncCall()
PassRefPtr<AsyncCallStackTracker::AsyncCallChain> AsyncCallStackTracker::createAsyncCallChain(const String& description, const ScriptValue& callFrames)
{
+ if (callFrames.isEmpty()) {
+ ASSERT(m_currentAsyncCallChain);
+ return m_currentAsyncCallChain; // Propogate async call stack chain.
+ }
RefPtr<AsyncCallChain> chain = adoptRef(m_currentAsyncCallChain ? new AsyncCallStackTracker::AsyncCallChain(*m_currentAsyncCallChain) : new AsyncCallStackTracker::AsyncCallChain());
ensureMaxAsyncCallChainDepth(chain.get(), m_maxAsyncCallStackDepth - 1);
chain->m_callStacks.prepend(adoptRef(new AsyncCallStackTracker::AsyncCallStack(description, callFrames)));
@@ -338,7 +371,7 @@ void AsyncCallStackTracker::ensureMaxAsyncCallChainDepth(AsyncCallChain* chain,
bool AsyncCallStackTracker::validateCallFrames(const ScriptValue& callFrames)
{
- return !callFrames.isEmpty();
+ return !callFrames.isEmpty() || m_currentAsyncCallChain;
}
AsyncCallStackTracker::ExecutionContextData* AsyncCallStackTracker::createContextDataIfNeeded(ExecutionContext* context)

Powered by Google App Engine
This is Rietveld 408576698