Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/SourceLocation.cpp

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/InspectorInstrumentation.h" 13 #include "core/inspector/InspectorInstrumentation.h"
14 #include "core/inspector/ThreadDebugger.h" 14 #include "core/inspector/ThreadDebugger.h"
15 #include "platform/ScriptForbiddenScope.h" 15 #include "platform/ScriptForbiddenScope.h"
16 #include "platform/TracedValue.h" 16 #include "platform/TracedValue.h"
17 #include "platform/v8_inspector/public/V8Debugger.h" 17 #include "platform/v8_inspector/public/V8Debugger.h"
18 #include "wtf/PtrUtil.h"
19 #include <memory>
20 18
21 namespace blink { 19 namespace blink {
22 20
23 namespace { 21 namespace {
24 22
25 std::unique_ptr<V8StackTrace> captureStackTrace(bool full) 23 std::unique_ptr<V8StackTrace> captureStackTrace(bool full)
26 { 24 {
27 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 25 v8::Isolate* isolate = v8::Isolate::GetCurrent();
28 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 26 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
29 if (!data->threadDebugger() || !isolate->InContext()) 27 if (!data->threadDebugger() || !isolate->InContext())
30 return nullptr; 28 return nullptr;
31 size_t stackSize = full ? V8StackTrace::maxCallStackSizeToCapture : 1; 29 size_t stackSize = full ? V8StackTrace::maxCallStackSizeToCapture : 1;
32 if (InspectorInstrumentation::hasFrontends()) { 30 if (InspectorInstrumentation::hasFrontends()) {
33 if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContex t(isolate))) 31 if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContex t(isolate)))
34 stackSize = V8StackTrace::maxCallStackSizeToCapture; 32 stackSize = V8StackTrace::maxCallStackSizeToCapture;
35 } 33 }
36 ScriptForbiddenScope::AllowUserAgentScript allowScripting; 34 ScriptForbiddenScope::AllowUserAgentScript allowScripting;
37 return data->threadDebugger()->debugger()->captureStackTrace(stackSize); 35 return data->threadDebugger()->debugger()->captureStackTrace(stackSize);
38 } 36 }
39 37
40 } 38 }
41 39
42 // static 40 // static
43 std::unique_ptr<SourceLocation> SourceLocation::capture(const String& url, unsig ned lineNumber, unsigned columnNumber) 41 PassOwnPtr<SourceLocation> SourceLocation::capture(const String& url, unsigned l ineNumber, unsigned columnNumber)
44 { 42 {
45 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(false); 43 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(false);
46 if (stackTrace && !stackTrace->isEmpty()) 44 if (stackTrace && !stackTrace->isEmpty())
47 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0); 45 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0);
48 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack Trace)); 46 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack Trace));
49 } 47 }
50 48
51 // static 49 // static
52 std::unique_ptr<SourceLocation> SourceLocation::capture(ExecutionContext* execut ionContext) 50 PassOwnPtr<SourceLocation> SourceLocation::capture(ExecutionContext* executionCo ntext)
53 { 51 {
54 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(false); 52 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(false);
55 if (stackTrace && !stackTrace->isEmpty()) 53 if (stackTrace && !stackTrace->isEmpty())
56 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0); 54 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0);
57 55
58 Document* document = executionContext && executionContext->isDocument() ? to Document(executionContext) : nullptr; 56 Document* document = executionContext && executionContext->isDocument() ? to Document(executionContext) : nullptr;
59 if (document) { 57 if (document) {
60 unsigned lineNumber = 0; 58 unsigned lineNumber = 0;
61 if (document->scriptableDocumentParser() && !document->isInDocumentWrite ()) { 59 if (document->scriptableDocumentParser() && !document->isInDocumentWrite ()) {
62 if (document->scriptableDocumentParser()->isParsingAtLineNumber()) 60 if (document->scriptableDocumentParser()->isParsingAtLineNumber())
63 lineNumber = document->scriptableDocumentParser()->lineNumber(). oneBasedInt(); 61 lineNumber = document->scriptableDocumentParser()->lineNumber(). oneBasedInt();
64 } 62 }
65 return SourceLocation::create(document->url().getString(), lineNumber, 0 , std::move(stackTrace)); 63 return SourceLocation::create(document->url().getString(), lineNumber, 0 , std::move(stackTrace));
66 } 64 }
67 65
68 return SourceLocation::create(executionContext ? executionContext->url().get String() : String(), 0, 0, std::move(stackTrace)); 66 return SourceLocation::create(executionContext ? executionContext->url().get String() : String(), 0, 0, std::move(stackTrace));
69 } 67 }
70 68
71 // static 69 // static
72 std::unique_ptr<SourceLocation> SourceLocation::fromMessage(v8::Isolate* isolate , v8::Local<v8::Message> message, ExecutionContext* executionContext) 70 PassOwnPtr<SourceLocation> SourceLocation::fromMessage(v8::Isolate* isolate, v8: :Local<v8::Message> message, ExecutionContext* executionContext)
73 { 71 {
74 v8::Local<v8::StackTrace> stack = message->GetStackTrace(); 72 v8::Local<v8::StackTrace> stack = message->GetStackTrace();
75 std::unique_ptr<V8StackTrace> stackTrace = nullptr; 73 std::unique_ptr<V8StackTrace> stackTrace = nullptr;
76 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 74 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
77 if (data && data->threadDebugger()) 75 if (data && data->threadDebugger())
78 stackTrace = data->threadDebugger()->debugger()->createStackTrace(stack) ; 76 stackTrace = data->threadDebugger()->debugger()->createStackTrace(stack) ;
79 77
80 int scriptId = message->GetScriptOrigin().ScriptID()->Value(); 78 int scriptId = message->GetScriptOrigin().ScriptID()->Value();
81 if (!stack.IsEmpty() && stack->GetFrameCount() > 0) { 79 if (!stack.IsEmpty() && stack->GetFrameCount() > 0) {
82 int topScriptId = stack->GetFrame(0)->GetScriptId(); 80 int topScriptId = stack->GetFrame(0)->GetScriptId();
(...skipping 10 matching lines...) Expand all
93 if ((!scriptId || !lineNumber) && stackTrace && !stackTrace->isEmpty()) 91 if ((!scriptId || !lineNumber) && stackTrace && !stackTrace->isEmpty())
94 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0); 92 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0);
95 93
96 String url = toCoreStringWithUndefinedOrNullCheck(message->GetScriptOrigin() .ResourceName()); 94 String url = toCoreStringWithUndefinedOrNullCheck(message->GetScriptOrigin() .ResourceName());
97 if (url.isNull()) 95 if (url.isNull())
98 url = executionContext->url(); 96 url = executionContext->url();
99 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack Trace), scriptId); 97 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack Trace), scriptId);
100 } 98 }
101 99
102 // static 100 // static
103 std::unique_ptr<SourceLocation> SourceLocation::create(const String& url, unsign ed lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId) 101 PassOwnPtr<SourceLocation> SourceLocation::create(const String& url, unsigned li neNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int s criptId)
104 { 102 {
105 return wrapUnique(new SourceLocation(url, lineNumber, columnNumber, std::mov e(stackTrace), scriptId)); 103 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move( stackTrace), scriptId));
106 } 104 }
107 105
108 // static 106 // static
109 std::unique_ptr<SourceLocation> SourceLocation::createFromNonEmptyV8StackTrace(s td::unique_ptr<V8StackTrace> stackTrace, int scriptId) 107 PassOwnPtr<SourceLocation> SourceLocation::createFromNonEmptyV8StackTrace(std::u nique_ptr<V8StackTrace> stackTrace, int scriptId)
110 { 108 {
111 // Retrieve the data before passing the ownership to SourceLocation. 109 // Retrieve the data before passing the ownership to SourceLocation.
112 const String& url = stackTrace->topSourceURL(); 110 const String& url = stackTrace->topSourceURL();
113 unsigned lineNumber = stackTrace->topLineNumber(); 111 unsigned lineNumber = stackTrace->topLineNumber();
114 unsigned columnNumber = stackTrace->topColumnNumber(); 112 unsigned columnNumber = stackTrace->topColumnNumber();
115 return wrapUnique(new SourceLocation(url, lineNumber, columnNumber, std::mov e(stackTrace), scriptId)); 113 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move( stackTrace), scriptId));
116 } 114 }
117 115
118 // static 116 // static
119 std::unique_ptr<SourceLocation> SourceLocation::fromFunction(v8::Local<v8::Funct ion> function) 117 PassOwnPtr<SourceLocation> SourceLocation::fromFunction(v8::Local<v8::Function> function)
120 { 118 {
121 if (!function.IsEmpty()) 119 if (!function.IsEmpty())
122 return SourceLocation::create(toCoreStringWithUndefinedOrNullCheck(funct ion->GetScriptOrigin().ResourceName()), function->GetScriptLineNumber() + 1, fun ction->GetScriptColumnNumber() + 1, nullptr, function->ScriptId()); 120 return SourceLocation::create(toCoreStringWithUndefinedOrNullCheck(funct ion->GetScriptOrigin().ResourceName()), function->GetScriptLineNumber() + 1, fun ction->GetScriptColumnNumber() + 1, nullptr, function->ScriptId());
123 return SourceLocation::create(String(), 0, 0, nullptr, 0); 121 return SourceLocation::create(String(), 0, 0, nullptr, 0);
124 } 122 }
125 123
126 // static 124 // static
127 std::unique_ptr<SourceLocation> SourceLocation::captureWithFullStackTrace() 125 PassOwnPtr<SourceLocation> SourceLocation::captureWithFullStackTrace()
128 { 126 {
129 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(true); 127 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(true);
130 if (stackTrace && !stackTrace->isEmpty()) 128 if (stackTrace && !stackTrace->isEmpty())
131 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0); 129 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0);
132 return SourceLocation::create(String(), 0, 0, nullptr, 0); 130 return SourceLocation::create(String(), 0, 0, nullptr, 0);
133 } 131 }
134 132
135 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId) 133 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId)
136 : m_url(url) 134 : m_url(url)
137 , m_lineNumber(lineNumber) 135 , m_lineNumber(lineNumber)
(...skipping 15 matching lines...) Expand all
153 value->beginDictionary(); 151 value->beginDictionary();
154 value->setString("functionName", m_stackTrace->topFunctionName()); 152 value->setString("functionName", m_stackTrace->topFunctionName());
155 value->setString("scriptId", m_stackTrace->topScriptId()); 153 value->setString("scriptId", m_stackTrace->topScriptId());
156 value->setString("url", m_stackTrace->topSourceURL()); 154 value->setString("url", m_stackTrace->topSourceURL());
157 value->setInteger("lineNumber", m_stackTrace->topLineNumber()); 155 value->setInteger("lineNumber", m_stackTrace->topLineNumber());
158 value->setInteger("columnNumber", m_stackTrace->topColumnNumber()); 156 value->setInteger("columnNumber", m_stackTrace->topColumnNumber());
159 value->endDictionary(); 157 value->endDictionary();
160 value->endArray(); 158 value->endArray();
161 } 159 }
162 160
163 std::unique_ptr<SourceLocation> SourceLocation::clone() const 161 PassOwnPtr<SourceLocation> SourceLocation::clone() const
164 { 162 {
165 return wrapUnique(new SourceLocation(m_url, m_lineNumber, m_columnNumber, m_ stackTrace ? m_stackTrace->clone() : nullptr, m_scriptId)); 163 return adoptPtr(new SourceLocation(m_url, m_lineNumber, m_columnNumber, m_st ackTrace ? m_stackTrace->clone() : nullptr, m_scriptId));
166 } 164 }
167 165
168 std::unique_ptr<SourceLocation> SourceLocation::isolatedCopy() const 166 PassOwnPtr<SourceLocation> SourceLocation::isolatedCopy() const
169 { 167 {
170 return wrapUnique(new SourceLocation(m_url.isolatedCopy(), m_lineNumber, m_c olumnNumber, m_stackTrace ? m_stackTrace->isolatedCopy() : nullptr, m_scriptId)) ; 168 return adoptPtr(new SourceLocation(m_url.isolatedCopy(), m_lineNumber, m_col umnNumber, m_stackTrace ? m_stackTrace->isolatedCopy() : nullptr, m_scriptId));
171 } 169 }
172 170
173 std::unique_ptr<protocol::Runtime::StackTrace> SourceLocation::buildInspectorObj ect() const 171 std::unique_ptr<protocol::Runtime::StackTrace> SourceLocation::buildInspectorObj ect() const
174 { 172 {
175 return m_stackTrace ? m_stackTrace->buildInspectorObject() : nullptr; 173 return m_stackTrace ? m_stackTrace->buildInspectorObject() : nullptr;
176 } 174 }
177 175
178 String SourceLocation::toString() const 176 String SourceLocation::toString() const
179 { 177 {
180 if (!m_stackTrace) 178 if (!m_stackTrace)
181 return String(); 179 return String();
182 return m_stackTrace->toString(); 180 return m_stackTrace->toString();
183 } 181 }
184 182
185 } // namespace blink 183 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698