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

Unified Diff: Source/bindings/common/StackTrace.cpp

Issue 466243002: Support merged Dart-JS callstacks (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/dartium
Patch Set: Created 6 years, 4 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/bindings/common/StackTrace.cpp
diff --git a/Source/bindings/common/StackTrace.cpp b/Source/bindings/common/StackTrace.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..877c51f139f289cbb2f27a33a15b0c288a91aec9
--- /dev/null
+++ b/Source/bindings/common/StackTrace.cpp
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2014 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "bindings/common/StackTrace.h"
+
+namespace WebCore {
+
+StackTrace::StackTrace() :
+ m_hasJavaScript(false),
+ m_hasDart(false),
+ m_dartStackTrace(0),
+ m_v8ScriptState(0),
+ m_dartScriptState(0)
+{
+}
+
+StackTrace::StackTrace(const StackTrace& javaScriptStackTrace, const StackTrace& dartStackTrace)
+{
+ ASSERT(!javaScriptStackTrace.hasDart() && !dartStackTrace.hasJavaScript());
+
+ if (javaScriptStackTrace.hasJavaScript()) {
+ m_hasJavaScript = true;
+ m_scriptValue = javaScriptStackTrace.asJavaScript();
+ m_v8ScriptState = javaScriptStackTrace.v8ScriptState();
+ } else {
+ m_hasJavaScript = false;
+ m_v8ScriptState = 0;
+ }
+
+ if (dartStackTrace.hasDart()) {
+ m_hasDart = true;
+ m_dartStackTrace = dartStackTrace.asDart();
+ m_dartScriptState = dartStackTrace.dartScriptState();
+ } else {
+ m_hasDart = false;
+ m_dartStackTrace = 0;
+ m_dartScriptState = 0;
+ }
+}
+
+StackTrace::StackTrace(const ScriptValue& stackTrace, V8ScriptState* v8ScriptState) :
+ m_hasJavaScript(!stackTrace.isEmpty()),
+ m_hasDart(false),
+ m_scriptValue(stackTrace),
+ m_dartStackTrace(0),
+ m_v8ScriptState(v8ScriptState),
+ m_dartScriptState(0)
+{
+}
+
+StackTrace::StackTrace(Dart_StackTrace stackTrace, DartScriptState* dartScriptState) :
+ m_hasJavaScript(false),
+ m_hasDart(!!stackTrace),
+ m_dartStackTrace(stackTrace),
+ m_v8ScriptState(0),
+ m_dartScriptState(dartScriptState)
+{
+}
+
+StackTraceTimestamp::StackTraceTimestamp(size_t stackDepth) : m_stackDepth(stackDepth)
+{
+ DEFINE_STATIC_LOCAL(int64_t, nextTimestamp, (0));
+ m_timestamp = ++nextTimestamp;
+}
+
+int64_t StackTraceTimestampTracker::getTimestamp(size_t frame)
vsm 2014/08/13 14:26:45 Can you add a comment here? Not really grokking w
Jacob 2014/08/13 21:36:15 Done.
+{
+ ASSERT(!m_samples.isEmpty());
+ if (m_samples.isEmpty())
+ return 0;
+
+ // m_samples.size() will typically be less than 3 and will be at most
+ // kMaxRecursionDepth (20) so binary search isn't needed.
+ size_t i = 1;
+ while (i < m_samples.size() && m_samples[i].stackDepth() <= frame)
+ i++;
+ return m_samples[i-1].timestamp();
+}
+
+} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698