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 24 matching lines...) Expand all Loading... |
35 return data->threadDebugger()->debugger()->captureStackTrace(stackSize); | 35 return data->threadDebugger()->debugger()->captureStackTrace(stackSize); |
36 } | 36 } |
37 | 37 |
38 } | 38 } |
39 | 39 |
40 // static | 40 // static |
41 PassOwnPtr<SourceLocation> SourceLocation::capture(const String& url, unsigned l
ineNumber, unsigned columnNumber) | 41 PassOwnPtr<SourceLocation> SourceLocation::capture(const String& url, unsigned l
ineNumber, unsigned columnNumber) |
42 { | 42 { |
43 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(); | 43 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(); |
44 if (stackTrace && !stackTrace->isEmpty()) | 44 if (stackTrace && !stackTrace->isEmpty()) |
45 return SourceLocation::create(stackTrace->topSourceURL(), stackTrace->to
pLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0); | 45 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra
ce), 0); |
46 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack
Trace)); | 46 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack
Trace)); |
47 } | 47 } |
48 | 48 |
49 // static | 49 // static |
50 PassOwnPtr<SourceLocation> SourceLocation::capture(ExecutionContext* executionCo
ntext) | 50 PassOwnPtr<SourceLocation> SourceLocation::capture(ExecutionContext* executionCo
ntext) |
51 { | 51 { |
52 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(); | 52 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(); |
53 if (stackTrace && !stackTrace->isEmpty()) | 53 if (stackTrace && !stackTrace->isEmpty()) |
54 return SourceLocation::create(stackTrace->topSourceURL(), stackTrace->to
pLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0); | 54 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra
ce), 0); |
55 | 55 |
56 Document* document = executionContext && executionContext->isDocument() ? to
Document(executionContext) : nullptr; | 56 Document* document = executionContext && executionContext->isDocument() ? to
Document(executionContext) : nullptr; |
57 if (document) { | 57 if (document) { |
58 unsigned lineNumber = 0; | 58 unsigned lineNumber = 0; |
59 if (document->scriptableDocumentParser() && !document->isInDocumentWrite
()) { | 59 if (document->scriptableDocumentParser() && !document->isInDocumentWrite
()) { |
60 if (document->scriptableDocumentParser()->isParsingAtLineNumber()) | 60 if (document->scriptableDocumentParser()->isParsingAtLineNumber()) |
61 lineNumber = document->scriptableDocumentParser()->lineNumber().
oneBasedInt(); | 61 lineNumber = document->scriptableDocumentParser()->lineNumber().
oneBasedInt(); |
62 } | 62 } |
63 return SourceLocation::create(document->url().getString(), lineNumber, 0
, std::move(stackTrace)); | 63 return SourceLocation::create(document->url().getString(), lineNumber, 0
, std::move(stackTrace)); |
64 } | 64 } |
(...skipping 17 matching lines...) Expand all Loading... |
82 scriptId = 0; | 82 scriptId = 0; |
83 } | 83 } |
84 | 84 |
85 int lineNumber = 0; | 85 int lineNumber = 0; |
86 int columnNumber = 0; | 86 int columnNumber = 0; |
87 if (v8Call(message->GetLineNumber(isolate->GetCurrentContext()), lineNumber) | 87 if (v8Call(message->GetLineNumber(isolate->GetCurrentContext()), lineNumber) |
88 && v8Call(message->GetStartColumn(isolate->GetCurrentContext()), columnN
umber)) | 88 && v8Call(message->GetStartColumn(isolate->GetCurrentContext()), columnN
umber)) |
89 ++columnNumber; | 89 ++columnNumber; |
90 | 90 |
91 if ((!scriptId || !lineNumber) && stackTrace && !stackTrace->isEmpty()) | 91 if ((!scriptId || !lineNumber) && stackTrace && !stackTrace->isEmpty()) |
92 return adoptPtr(new SourceLocation(stackTrace->topSourceURL(), stackTrac
e->topLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0)); | 92 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra
ce), 0); |
93 | 93 |
94 String url = toCoreStringWithUndefinedOrNullCheck(message->GetScriptOrigin()
.ResourceName()); | 94 String url = toCoreStringWithUndefinedOrNullCheck(message->GetScriptOrigin()
.ResourceName()); |
95 if (url.isNull()) | 95 if (url.isNull()) |
96 url = executionContext->url(); | 96 url = executionContext->url(); |
97 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move(
stackTrace), scriptId)); | 97 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack
Trace), scriptId); |
98 } | 98 } |
99 | 99 |
100 // static | 100 // static |
101 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) |
102 { | 102 { |
103 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move(
stackTrace), scriptId)); | 103 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move(
stackTrace), scriptId)); |
104 } | 104 } |
105 | 105 |
| 106 // static |
| 107 PassOwnPtr<SourceLocation> SourceLocation::createFromNonEmptyV8StackTrace(std::u
nique_ptr<V8StackTrace> stackTrace, int scriptId) |
| 108 { |
| 109 // Retrieve the data before passing the ownership to SourceLocation. |
| 110 const String& url = stackTrace->topSourceURL(); |
| 111 unsigned lineNumber = stackTrace->topLineNumber(); |
| 112 unsigned columnNumber = stackTrace->topColumnNumber(); |
| 113 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move(
stackTrace), scriptId)); |
| 114 } |
| 115 |
106 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned
columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId) | 116 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned
columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId) |
107 : m_url(url) | 117 : m_url(url) |
108 , m_lineNumber(lineNumber) | 118 , m_lineNumber(lineNumber) |
109 , m_columnNumber(columnNumber) | 119 , m_columnNumber(columnNumber) |
110 , m_stackTrace(std::move(stackTrace)) | 120 , m_stackTrace(std::move(stackTrace)) |
111 , m_scriptId(scriptId) | 121 , m_scriptId(scriptId) |
112 { | 122 { |
113 } | 123 } |
114 | 124 |
115 SourceLocation::~SourceLocation() | 125 SourceLocation::~SourceLocation() |
(...skipping 14 matching lines...) Expand all Loading... |
130 value->endDictionary(); | 140 value->endDictionary(); |
131 value->endArray(); | 141 value->endArray(); |
132 } | 142 } |
133 | 143 |
134 PassOwnPtr<SourceLocation> SourceLocation::clone() const | 144 PassOwnPtr<SourceLocation> SourceLocation::clone() const |
135 { | 145 { |
136 return adoptPtr(new SourceLocation(m_url, m_lineNumber, m_columnNumber, m_st
ackTrace ? m_stackTrace->clone() : nullptr, m_scriptId)); | 146 return adoptPtr(new SourceLocation(m_url, m_lineNumber, m_columnNumber, m_st
ackTrace ? m_stackTrace->clone() : nullptr, m_scriptId)); |
137 } | 147 } |
138 | 148 |
139 } // namespace blink | 149 } // namespace blink |
OLD | NEW |