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

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

Issue 2004313003: DevTools: migrate from OwnPtr to std::unique_ptr for inspector protocol classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 4 years, 7 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/V8PerIsolateData.h" 7 #include "bindings/core/v8/V8PerIsolateData.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/ExecutionContext.h" 9 #include "core/dom/ExecutionContext.h"
10 #include "core/dom/ScriptableDocumentParser.h" 10 #include "core/dom/ScriptableDocumentParser.h"
11 #include "core/html/HTMLFrameOwnerElement.h" 11 #include "core/html/HTMLFrameOwnerElement.h"
12 #include "core/inspector/InspectorInstrumentation.h" 12 #include "core/inspector/InspectorInstrumentation.h"
13 #include "core/inspector/ThreadDebugger.h" 13 #include "core/inspector/ThreadDebugger.h"
14 #include "platform/ScriptForbiddenScope.h" 14 #include "platform/ScriptForbiddenScope.h"
15 #include "platform/TracedValue.h" 15 #include "platform/TracedValue.h"
16 #include "platform/v8_inspector/public/V8Debugger.h" 16 #include "platform/v8_inspector/public/V8Debugger.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 namespace { 20 namespace {
21 21
22 PassOwnPtr<V8StackTrace> captureStackTrace() 22 std::unique_ptr<V8StackTrace> captureStackTrace()
23 { 23 {
24 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 24 v8::Isolate* isolate = v8::Isolate::GetCurrent();
25 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 25 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
26 if (!data->threadDebugger() || !isolate->InContext()) 26 if (!data->threadDebugger() || !isolate->InContext())
27 return nullptr; 27 return nullptr;
28 size_t stackSize = 1; 28 size_t stackSize = 1;
29 if (InspectorInstrumentation::hasFrontends()) { 29 if (InspectorInstrumentation::hasFrontends()) {
30 if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContex t(isolate))) 30 if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContex t(isolate)))
31 stackSize = V8StackTrace::maxCallStackSizeToCapture; 31 stackSize = V8StackTrace::maxCallStackSizeToCapture;
32 } 32 }
33 ScriptForbiddenScope::AllowUserAgentScript allowScripting; 33 ScriptForbiddenScope::AllowUserAgentScript allowScripting;
34 return data->threadDebugger()->debugger()->captureStackTrace(stackSize); 34 return data->threadDebugger()->debugger()->captureStackTrace(stackSize);
35 } 35 }
36 36
37 } 37 }
38 38
39 // static 39 // static
40 PassOwnPtr<SourceLocation> SourceLocation::capture(const String& url, unsigned l ineNumber, unsigned columnNumber) 40 PassOwnPtr<SourceLocation> SourceLocation::capture(const String& url, unsigned l ineNumber, unsigned columnNumber)
41 { 41 {
42 OwnPtr<V8StackTrace> stackTrace = captureStackTrace(); 42 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace();
43 if (stackTrace && !stackTrace->isEmpty()) 43 if (stackTrace && !stackTrace->isEmpty())
44 return SourceLocation::create(stackTrace->topSourceURL(), stackTrace->to pLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0); 44 return SourceLocation::create(stackTrace->topSourceURL(), stackTrace->to pLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0);
45 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack Trace)); 45 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack Trace));
46 } 46 }
47 47
48 // static 48 // static
49 PassOwnPtr<SourceLocation> SourceLocation::capture(ExecutionContext* executionCo ntext) 49 PassOwnPtr<SourceLocation> SourceLocation::capture(ExecutionContext* executionCo ntext)
50 { 50 {
51 OwnPtr<V8StackTrace> stackTrace = captureStackTrace(); 51 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace();
52 if (stackTrace && !stackTrace->isEmpty()) 52 if (stackTrace && !stackTrace->isEmpty())
53 return SourceLocation::create(stackTrace->topSourceURL(), stackTrace->to pLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0); 53 return SourceLocation::create(stackTrace->topSourceURL(), stackTrace->to pLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0);
54 54
55 Document* document = executionContext && executionContext->isDocument() ? to Document(executionContext) : nullptr; 55 Document* document = executionContext && executionContext->isDocument() ? to Document(executionContext) : nullptr;
56 if (document) { 56 if (document) {
57 unsigned lineNumber = 0; 57 unsigned lineNumber = 0;
58 if (document->scriptableDocumentParser() && !document->isInDocumentWrite ()) { 58 if (document->scriptableDocumentParser() && !document->isInDocumentWrite ()) {
59 if (document->scriptableDocumentParser()->isParsingAtLineNumber()) 59 if (document->scriptableDocumentParser()->isParsingAtLineNumber())
60 lineNumber = document->scriptableDocumentParser()->lineNumber(). oneBasedInt(); 60 lineNumber = document->scriptableDocumentParser()->lineNumber(). oneBasedInt();
61 } 61 }
62 return SourceLocation::create(document->url().getString(), lineNumber, 0 , std::move(stackTrace)); 62 return SourceLocation::create(document->url().getString(), lineNumber, 0 , std::move(stackTrace));
63 } 63 }
64 64
65 return SourceLocation::create(executionContext ? executionContext->url().get String() : "", 0, 0, std::move(stackTrace)); 65 return SourceLocation::create(executionContext ? executionContext->url().get String() : "", 0, 0, std::move(stackTrace));
66 } 66 }
67 67
68 // static 68 // static
69 PassOwnPtr<SourceLocation> SourceLocation::create(const String& url, unsigned li neNumber, unsigned columnNumber, PassOwnPtr<V8StackTrace> stackTrace, int script Id) 69 PassOwnPtr<SourceLocation> SourceLocation::create(const String& url, unsigned li neNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int s criptId)
70 { 70 {
71 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move( stackTrace), scriptId)); 71 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move( stackTrace), scriptId));
72 } 72 }
73 73
74 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber, PassOwnPtr<V8StackTrace> stackTrace, int scriptId) 74 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId)
75 : m_url(url) 75 : m_url(url)
76 , m_lineNumber(lineNumber) 76 , m_lineNumber(lineNumber)
77 , m_columnNumber(columnNumber) 77 , m_columnNumber(columnNumber)
78 , m_stackTrace(std::move(stackTrace)) 78 , m_stackTrace(std::move(stackTrace))
79 , m_scriptId(scriptId) 79 , m_scriptId(scriptId)
80 { 80 {
81 } 81 }
82 82
83 SourceLocation::~SourceLocation() 83 SourceLocation::~SourceLocation()
84 { 84 {
85 } 85 }
86 86
87 void SourceLocation::toTracedValue(TracedValue* value, const char* name) const 87 void SourceLocation::toTracedValue(TracedValue* value, const char* name) const
88 { 88 {
89 if (!m_stackTrace || m_stackTrace->isEmpty()) 89 if (!m_stackTrace || m_stackTrace->isEmpty())
90 return; 90 return;
91 value->beginArray(name); 91 value->beginArray(name);
92 value->beginDictionary(); 92 value->beginDictionary();
93 value->setString("functionName", m_stackTrace->topFunctionName()); 93 value->setString("functionName", m_stackTrace->topFunctionName());
94 value->setString("scriptId", m_stackTrace->topScriptId()); 94 value->setString("scriptId", m_stackTrace->topScriptId());
95 value->setString("url", m_stackTrace->topSourceURL()); 95 value->setString("url", m_stackTrace->topSourceURL());
96 value->setInteger("lineNumber", m_stackTrace->topLineNumber()); 96 value->setInteger("lineNumber", m_stackTrace->topLineNumber());
97 value->setInteger("columnNumber", m_stackTrace->topColumnNumber()); 97 value->setInteger("columnNumber", m_stackTrace->topColumnNumber());
98 value->endDictionary(); 98 value->endDictionary();
99 value->endArray(); 99 value->endArray();
100 } 100 }
101 101
102 } // namespace blink 102 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/SourceLocation.h ('k') | third_party/WebKit/Source/core/inspector/ConsoleMessage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698