Chromium Code Reviews| 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..949e7327e9075e888afd5b9678310a329b4764e9 |
| --- /dev/null |
| +++ b/Source/bindings/common/StackTrace.cpp |
| @@ -0,0 +1,125 @@ |
| +/* |
| + * 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) |
| +{ |
| +} |
| + |
| +void StackTrace::merge(const StackTrace& other) |
| +{ |
| + if (other.hasJavaScript()) { |
| + m_hasJavaScript = true; |
| + m_scriptValue = other.asJavaScript(); |
| + m_v8ScriptState = other.v8ScriptState(); |
|
vsm
2014/08/29 08:42:07
What if this StackTrace already hasJavaScript with
Jacob
2014/09/05 23:35:55
Rolled back the changes that made StackTrace confu
|
| + } |
| + |
| + if (other.hasDart()) { |
| + m_hasDart = true; |
| + m_dartStackTrace = other.asDart(); |
| + m_dartScriptState = other.dartScriptState(); |
|
vsm
2014/08/29 08:42:07
Ditto - and what happens with multiple DOM isolate
Jacob
2014/09/05 23:35:55
Fixed. See previous comment.
|
| + } |
| +} |
| + |
| +StackTraceTimestamp::StackTraceTimestamp(size_t stackDepth) : m_stackDepth(stackDepth) |
| +{ |
| + DEFINE_STATIC_LOCAL(int64_t, nextTimestamp, (0)); |
|
vsm
2014/08/29 08:42:08
Maybe unsigned here?
Jacob
2014/09/05 23:35:55
Removed the timestamp tracker code with the switch
|
| + m_timestamp = ++nextTimestamp; |
|
vsm
2014/08/29 08:42:07
Overflow assert for good form? Might not trigger
Jacob
2014/09/05 23:35:55
this code was removed.
|
| +} |
| + |
| +int64_t StackTraceTimestampTracker::getTimestamp(size_t frame) |
| +{ |
| + // The timestamp for a frame is the timestamp of the sample with the |
| + // largest stack depth that does not exceed the stack depth of the frame. |
| + 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 |