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/V8PerIsolateData.h" | 8 #include "bindings/core/v8/V8PerIsolateData.h" |
8 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
9 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
10 #include "core/dom/ScriptableDocumentParser.h" | 11 #include "core/dom/ScriptableDocumentParser.h" |
11 #include "core/html/HTMLFrameOwnerElement.h" | 12 #include "core/html/HTMLFrameOwnerElement.h" |
12 #include "core/inspector/InspectorInstrumentation.h" | 13 #include "core/inspector/InspectorInstrumentation.h" |
13 #include "core/inspector/ThreadDebugger.h" | 14 #include "core/inspector/ThreadDebugger.h" |
14 #include "platform/ScriptForbiddenScope.h" | 15 #include "platform/ScriptForbiddenScope.h" |
15 #include "platform/TracedValue.h" | 16 #include "platform/TracedValue.h" |
16 #include "platform/v8_inspector/public/V8Debugger.h" | 17 #include "platform/v8_inspector/public/V8Debugger.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 if (document->scriptableDocumentParser()->isParsingAtLineNumber()) | 60 if (document->scriptableDocumentParser()->isParsingAtLineNumber()) |
60 lineNumber = document->scriptableDocumentParser()->lineNumber().
oneBasedInt(); | 61 lineNumber = document->scriptableDocumentParser()->lineNumber().
oneBasedInt(); |
61 } | 62 } |
62 return SourceLocation::create(document->url().getString(), lineNumber, 0
, std::move(stackTrace)); | 63 return SourceLocation::create(document->url().getString(), lineNumber, 0
, std::move(stackTrace)); |
63 } | 64 } |
64 | 65 |
65 return SourceLocation::create(executionContext ? executionContext->url().get
String() : "", 0, 0, std::move(stackTrace)); | 66 return SourceLocation::create(executionContext ? executionContext->url().get
String() : "", 0, 0, std::move(stackTrace)); |
66 } | 67 } |
67 | 68 |
68 // static | 69 // static |
| 70 PassOwnPtr<SourceLocation> SourceLocation::fromMessage(v8::Isolate* isolate, v8:
:Local<v8::Message> message, ExecutionContext* executionContext) |
| 71 { |
| 72 v8::Local<v8::StackTrace> stack = message->GetStackTrace(); |
| 73 std::unique_ptr<V8StackTrace> stackTrace = nullptr; |
| 74 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
| 75 if (data && data->threadDebugger()) |
| 76 stackTrace = data->threadDebugger()->debugger()->createStackTrace(stack)
; |
| 77 |
| 78 int scriptId = message->GetScriptOrigin().ScriptID()->Value(); |
| 79 if (!stack.IsEmpty() && stack->GetFrameCount() > 0) { |
| 80 int topScriptId = stack->GetFrame(0)->GetScriptId(); |
| 81 if (topScriptId == scriptId) |
| 82 scriptId = 0; |
| 83 } |
| 84 |
| 85 int lineNumber = 0; |
| 86 int columnNumber = 0; |
| 87 if (v8Call(message->GetLineNumber(isolate->GetCurrentContext()), lineNumber) |
| 88 && v8Call(message->GetStartColumn(isolate->GetCurrentContext()), columnN
umber)) |
| 89 ++columnNumber; |
| 90 |
| 91 if ((!scriptId || !lineNumber) && stackTrace && !stackTrace->isEmpty()) |
| 92 return adoptPtr(new SourceLocation(stackTrace->topSourceURL(), stackTrac
e->topLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0)); |
| 93 |
| 94 String url = toCoreStringWithUndefinedOrNullCheck(message->GetScriptOrigin()
.ResourceName()); |
| 95 if (url.isNull()) |
| 96 url = executionContext->url(); |
| 97 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move(
stackTrace), scriptId)); |
| 98 } |
| 99 |
| 100 // static |
69 PassOwnPtr<SourceLocation> SourceLocation::create(const String& url, unsigned li
neNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int s
criptId) | 101 PassOwnPtr<SourceLocation> SourceLocation::create(const String& url, unsigned li
neNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int s
criptId) |
70 { | 102 { |
71 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move(
stackTrace), scriptId)); | 103 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move(
stackTrace), scriptId)); |
72 } | 104 } |
73 | 105 |
74 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned
columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId) | 106 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned
columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId) |
75 : m_url(url) | 107 : m_url(url) |
76 , m_lineNumber(lineNumber) | 108 , m_lineNumber(lineNumber) |
77 , m_columnNumber(columnNumber) | 109 , m_columnNumber(columnNumber) |
78 , m_stackTrace(std::move(stackTrace)) | 110 , m_stackTrace(std::move(stackTrace)) |
(...skipping 19 matching lines...) Expand all Loading... |
98 value->endDictionary(); | 130 value->endDictionary(); |
99 value->endArray(); | 131 value->endArray(); |
100 } | 132 } |
101 | 133 |
102 PassOwnPtr<SourceLocation> SourceLocation::clone() const | 134 PassOwnPtr<SourceLocation> SourceLocation::clone() const |
103 { | 135 { |
104 return adoptPtr(new SourceLocation(m_url, m_lineNumber, m_columnNumber, m_st
ackTrace ? m_stackTrace->clone() : nullptr, m_scriptId)); | 136 return adoptPtr(new SourceLocation(m_url, m_lineNumber, m_columnNumber, m_st
ackTrace ? m_stackTrace->clone() : nullptr, m_scriptId)); |
105 } | 137 } |
106 | 138 |
107 } // namespace blink | 139 } // namespace blink |
OLD | NEW |