| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bindings/core/v8/SourceLocation.h" | 5 #include "bindings/core/v8/SourceLocation.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8BindingMacros.h" | 7 #include "bindings/core/v8/V8BindingMacros.h" |
| 8 #include "bindings/core/v8/V8PerIsolateData.h" | 8 #include "bindings/core/v8/V8PerIsolateData.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 namespace blink { | 21 namespace blink { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 std::unique_ptr<V8StackTrace> captureStackTrace(bool full) | 25 std::unique_ptr<V8StackTrace> captureStackTrace(bool full) |
| 26 { | 26 { |
| 27 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 27 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 28 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 28 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
| 29 if (!data->threadDebugger() || !isolate->InContext()) | 29 if (!data->threadDebugger() || !isolate->InContext()) |
| 30 return nullptr; | 30 return nullptr; |
| 31 size_t stackSize = full ? V8StackTrace::maxCallStackSizeToCapture : 1; | |
| 32 if (InspectorInstrumentation::hasFrontends()) { | |
| 33 if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContex
t(isolate))) | |
| 34 stackSize = V8StackTrace::maxCallStackSizeToCapture; | |
| 35 } | |
| 36 ScriptForbiddenScope::AllowUserAgentScript allowScripting; | 31 ScriptForbiddenScope::AllowUserAgentScript allowScripting; |
| 37 return data->threadDebugger()->debugger()->captureStackTrace(stackSize); | 32 return data->threadDebugger()->debugger()->captureStackTrace(full); |
| 38 } | 33 } |
| 39 | 34 |
| 40 } | 35 } |
| 41 | 36 |
| 42 // static | 37 // static |
| 43 std::unique_ptr<SourceLocation> SourceLocation::capture(const String& url, unsig
ned lineNumber, unsigned columnNumber) | 38 std::unique_ptr<SourceLocation> SourceLocation::capture(const String& url, unsig
ned lineNumber, unsigned columnNumber) |
| 44 { | 39 { |
| 45 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(false); | 40 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(false); |
| 46 if (stackTrace && !stackTrace->isEmpty()) | 41 if (stackTrace && !stackTrace->isEmpty()) |
| 47 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra
ce), 0); | 42 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra
ce), 0); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 value->beginDictionary(); | 148 value->beginDictionary(); |
| 154 value->setString("functionName", m_stackTrace->topFunctionName()); | 149 value->setString("functionName", m_stackTrace->topFunctionName()); |
| 155 value->setString("scriptId", m_stackTrace->topScriptId()); | 150 value->setString("scriptId", m_stackTrace->topScriptId()); |
| 156 value->setString("url", m_stackTrace->topSourceURL()); | 151 value->setString("url", m_stackTrace->topSourceURL()); |
| 157 value->setInteger("lineNumber", m_stackTrace->topLineNumber()); | 152 value->setInteger("lineNumber", m_stackTrace->topLineNumber()); |
| 158 value->setInteger("columnNumber", m_stackTrace->topColumnNumber()); | 153 value->setInteger("columnNumber", m_stackTrace->topColumnNumber()); |
| 159 value->endDictionary(); | 154 value->endDictionary(); |
| 160 value->endArray(); | 155 value->endArray(); |
| 161 } | 156 } |
| 162 | 157 |
| 158 std::unique_ptr<V8StackTrace> SourceLocation::cloneStackTrace() const |
| 159 { |
| 160 return m_stackTrace ? m_stackTrace->clone() : nullptr; |
| 161 } |
| 162 |
| 163 std::unique_ptr<SourceLocation> SourceLocation::clone() const | 163 std::unique_ptr<SourceLocation> SourceLocation::clone() const |
| 164 { | 164 { |
| 165 return wrapUnique(new SourceLocation(m_url, m_lineNumber, m_columnNumber, m_
stackTrace ? m_stackTrace->clone() : nullptr, m_scriptId)); | 165 return wrapUnique(new SourceLocation(m_url, m_lineNumber, m_columnNumber, m_
stackTrace ? m_stackTrace->clone() : nullptr, m_scriptId)); |
| 166 } | 166 } |
| 167 | 167 |
| 168 std::unique_ptr<SourceLocation> SourceLocation::isolatedCopy() const | 168 std::unique_ptr<SourceLocation> SourceLocation::isolatedCopy() const |
| 169 { | 169 { |
| 170 return wrapUnique(new SourceLocation(m_url.isolatedCopy(), m_lineNumber, m_c
olumnNumber, m_stackTrace ? m_stackTrace->isolatedCopy() : nullptr, m_scriptId))
; | 170 return wrapUnique(new SourceLocation(m_url.isolatedCopy(), m_lineNumber, m_c
olumnNumber, m_stackTrace ? m_stackTrace->isolatedCopy() : nullptr, m_scriptId))
; |
| 171 } | 171 } |
| 172 | 172 |
| 173 std::unique_ptr<protocol::Runtime::StackTrace> SourceLocation::buildInspectorObj
ect() const | 173 std::unique_ptr<protocol::Runtime::StackTrace> SourceLocation::buildInspectorObj
ect() const |
| 174 { | 174 { |
| 175 return m_stackTrace ? m_stackTrace->buildInspectorObject() : nullptr; | 175 return m_stackTrace ? m_stackTrace->buildInspectorObject() : nullptr; |
| 176 } | 176 } |
| 177 | 177 |
| 178 String SourceLocation::toString() const | 178 String SourceLocation::toString() const |
| 179 { | 179 { |
| 180 if (!m_stackTrace) | 180 if (!m_stackTrace) |
| 181 return String(); | 181 return String(); |
| 182 return m_stackTrace->toString(); | 182 return m_stackTrace->toString(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 } // namespace blink | 185 } // namespace blink |
| OLD | NEW |