| 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" |
| 11 #include "core/dom/ScriptableDocumentParser.h" | 11 #include "core/dom/ScriptableDocumentParser.h" |
| 12 #include "core/html/HTMLFrameOwnerElement.h" | 12 #include "core/html/HTMLFrameOwnerElement.h" |
| 13 #include "core/inspector/ThreadDebugger.h" | 13 #include "core/inspector/ThreadDebugger.h" |
| 14 #include "core/inspector/V8InspectorString.h" | 14 #include "core/inspector/V8InspectorString.h" |
| 15 #include "platform/ScriptForbiddenScope.h" | 15 #include "platform/ScriptForbiddenScope.h" |
| 16 #include "platform/instrumentation/tracing/TracedValue.h" | 16 #include "platform/instrumentation/tracing/TracedValue.h" |
| 17 #include "wtf/PtrUtil.h" | 17 #include "wtf/PtrUtil.h" |
| 18 #include <memory> | 18 #include <memory> |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 std::unique_ptr<v8_inspector::V8StackTrace> captureStackTrace(bool full) { | 24 std::unique_ptr<v8_inspector::V8StackTrace> captureStackTrace(bool full) { |
| 25 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 25 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 26 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 26 ThreadDebugger* debugger = ThreadDebugger::from(isolate); |
| 27 if (!data->threadDebugger() || !isolate->InContext()) | 27 if (!debugger || !isolate->InContext()) |
| 28 return nullptr; | 28 return nullptr; |
| 29 ScriptForbiddenScope::AllowUserAgentScript allowScripting; | 29 ScriptForbiddenScope::AllowUserAgentScript allowScripting; |
| 30 return data->threadDebugger()->v8Inspector()->captureStackTrace(full); | 30 return debugger->v8Inspector()->captureStackTrace(full); |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 // static | 34 // static |
| 35 std::unique_ptr<SourceLocation> SourceLocation::capture(const String& url, | 35 std::unique_ptr<SourceLocation> SourceLocation::capture(const String& url, |
| 36 unsigned lineNumber, | 36 unsigned lineNumber, |
| 37 unsigned columnNumber) { | 37 unsigned columnNumber) { |
| 38 std::unique_ptr<v8_inspector::V8StackTrace> stackTrace = | 38 std::unique_ptr<v8_inspector::V8StackTrace> stackTrace = |
| 39 captureStackTrace(false); | 39 captureStackTrace(false); |
| 40 if (stackTrace && !stackTrace->isEmpty()) | 40 if (stackTrace && !stackTrace->isEmpty()) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 std::move(stackTrace)); | 73 std::move(stackTrace)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 // static | 76 // static |
| 77 std::unique_ptr<SourceLocation> SourceLocation::fromMessage( | 77 std::unique_ptr<SourceLocation> SourceLocation::fromMessage( |
| 78 v8::Isolate* isolate, | 78 v8::Isolate* isolate, |
| 79 v8::Local<v8::Message> message, | 79 v8::Local<v8::Message> message, |
| 80 ExecutionContext* executionContext) { | 80 ExecutionContext* executionContext) { |
| 81 v8::Local<v8::StackTrace> stack = message->GetStackTrace(); | 81 v8::Local<v8::StackTrace> stack = message->GetStackTrace(); |
| 82 std::unique_ptr<v8_inspector::V8StackTrace> stackTrace = nullptr; | 82 std::unique_ptr<v8_inspector::V8StackTrace> stackTrace = nullptr; |
| 83 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 83 ThreadDebugger* debugger = ThreadDebugger::from(isolate); |
| 84 if (data && data->threadDebugger()) | 84 if (debugger) |
| 85 stackTrace = data->threadDebugger()->v8Inspector()->createStackTrace(stack); | 85 stackTrace = debugger->v8Inspector()->createStackTrace(stack); |
| 86 | 86 |
| 87 int scriptId = message->GetScriptOrigin().ScriptID()->Value(); | 87 int scriptId = message->GetScriptOrigin().ScriptID()->Value(); |
| 88 if (!stack.IsEmpty() && stack->GetFrameCount() > 0) { | 88 if (!stack.IsEmpty() && stack->GetFrameCount() > 0) { |
| 89 int topScriptId = stack->GetFrame(0)->GetScriptId(); | 89 int topScriptId = stack->GetFrame(0)->GetScriptId(); |
| 90 if (topScriptId == scriptId) | 90 if (topScriptId == scriptId) |
| 91 scriptId = 0; | 91 scriptId = 0; |
| 92 } | 92 } |
| 93 | 93 |
| 94 int lineNumber = 0; | 94 int lineNumber = 0; |
| 95 int columnNumber = 0; | 95 int columnNumber = 0; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return m_stackTrace ? m_stackTrace->buildInspectorObject() : nullptr; | 196 return m_stackTrace ? m_stackTrace->buildInspectorObject() : nullptr; |
| 197 } | 197 } |
| 198 | 198 |
| 199 String SourceLocation::toString() const { | 199 String SourceLocation::toString() const { |
| 200 if (!m_stackTrace) | 200 if (!m_stackTrace) |
| 201 return String(); | 201 return String(); |
| 202 return toCoreString(m_stackTrace->toString()); | 202 return toCoreString(m_stackTrace->toString()); |
| 203 } | 203 } |
| 204 | 204 |
| 205 } // namespace blink | 205 } // namespace blink |
| OLD | NEW |