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

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

Issue 2246233002: [DevTools] Move platform/v8_inspector classes under v8_inspector namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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/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/V8Inspector.h" 16 #include "platform/v8_inspector/public/V8Inspector.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<V8StackTrace> captureStackTrace(bool full) 24 std::unique_ptr<v8_inspector::V8StackTrace> captureStackTrace(bool full)
25 { 25 {
26 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 26 v8::Isolate* isolate = v8::Isolate::GetCurrent();
27 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 27 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
28 if (!data->threadDebugger() || !isolate->InContext()) 28 if (!data->threadDebugger() || !isolate->InContext())
29 return nullptr; 29 return nullptr;
30 ScriptForbiddenScope::AllowUserAgentScript allowScripting; 30 ScriptForbiddenScope::AllowUserAgentScript allowScripting;
31 return data->threadDebugger()->v8Inspector()->captureStackTrace(full); 31 return data->threadDebugger()->v8Inspector()->captureStackTrace(full);
32 } 32 }
33 33
34 } 34 }
35 35
36 // static 36 // static
37 std::unique_ptr<SourceLocation> SourceLocation::capture(const String& url, unsig ned lineNumber, unsigned columnNumber) 37 std::unique_ptr<SourceLocation> SourceLocation::capture(const String& url, unsig ned lineNumber, unsigned columnNumber)
38 { 38 {
39 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(false); 39 std::unique_ptr<v8_inspector::V8StackTrace> stackTrace = captureStackTrace(f alse);
40 if (stackTrace && !stackTrace->isEmpty()) 40 if (stackTrace && !stackTrace->isEmpty())
41 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0); 41 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0);
42 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack Trace)); 42 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack Trace));
43 } 43 }
44 44
45 // static 45 // static
46 std::unique_ptr<SourceLocation> SourceLocation::capture(ExecutionContext* execut ionContext) 46 std::unique_ptr<SourceLocation> SourceLocation::capture(ExecutionContext* execut ionContext)
47 { 47 {
48 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(false); 48 std::unique_ptr<v8_inspector::V8StackTrace> stackTrace = captureStackTrace(f alse);
49 if (stackTrace && !stackTrace->isEmpty()) 49 if (stackTrace && !stackTrace->isEmpty())
50 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0); 50 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0);
51 51
52 Document* document = executionContext && executionContext->isDocument() ? to Document(executionContext) : nullptr; 52 Document* document = executionContext && executionContext->isDocument() ? to Document(executionContext) : nullptr;
53 if (document) { 53 if (document) {
54 unsigned lineNumber = 0; 54 unsigned lineNumber = 0;
55 if (document->scriptableDocumentParser() && !document->isInDocumentWrite ()) { 55 if (document->scriptableDocumentParser() && !document->isInDocumentWrite ()) {
56 if (document->scriptableDocumentParser()->isParsingAtLineNumber()) 56 if (document->scriptableDocumentParser()->isParsingAtLineNumber())
57 lineNumber = document->scriptableDocumentParser()->lineNumber(). oneBasedInt(); 57 lineNumber = document->scriptableDocumentParser()->lineNumber(). oneBasedInt();
58 } 58 }
59 return SourceLocation::create(document->url().getString(), lineNumber, 0 , std::move(stackTrace)); 59 return SourceLocation::create(document->url().getString(), lineNumber, 0 , std::move(stackTrace));
60 } 60 }
61 61
62 return SourceLocation::create(executionContext ? executionContext->url().get String() : String(), 0, 0, std::move(stackTrace)); 62 return SourceLocation::create(executionContext ? executionContext->url().get String() : String(), 0, 0, std::move(stackTrace));
63 } 63 }
64 64
65 // static 65 // static
66 std::unique_ptr<SourceLocation> SourceLocation::fromMessage(v8::Isolate* isolate , v8::Local<v8::Message> message, ExecutionContext* executionContext) 66 std::unique_ptr<SourceLocation> SourceLocation::fromMessage(v8::Isolate* isolate , v8::Local<v8::Message> message, ExecutionContext* executionContext)
67 { 67 {
68 v8::Local<v8::StackTrace> stack = message->GetStackTrace(); 68 v8::Local<v8::StackTrace> stack = message->GetStackTrace();
69 std::unique_ptr<V8StackTrace> stackTrace = nullptr; 69 std::unique_ptr<v8_inspector::V8StackTrace> stackTrace = nullptr;
70 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 70 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
71 if (data && data->threadDebugger()) 71 if (data && data->threadDebugger())
72 stackTrace = data->threadDebugger()->v8Inspector()->createStackTrace(sta ck); 72 stackTrace = data->threadDebugger()->v8Inspector()->createStackTrace(sta ck);
73 73
74 int scriptId = message->GetScriptOrigin().ScriptID()->Value(); 74 int scriptId = message->GetScriptOrigin().ScriptID()->Value();
75 if (!stack.IsEmpty() && stack->GetFrameCount() > 0) { 75 if (!stack.IsEmpty() && stack->GetFrameCount() > 0) {
76 int topScriptId = stack->GetFrame(0)->GetScriptId(); 76 int topScriptId = stack->GetFrame(0)->GetScriptId();
77 if (topScriptId == scriptId) 77 if (topScriptId == scriptId)
78 scriptId = 0; 78 scriptId = 0;
79 } 79 }
80 80
81 int lineNumber = 0; 81 int lineNumber = 0;
82 int columnNumber = 0; 82 int columnNumber = 0;
83 if (v8Call(message->GetLineNumber(isolate->GetCurrentContext()), lineNumber) 83 if (v8Call(message->GetLineNumber(isolate->GetCurrentContext()), lineNumber)
84 && v8Call(message->GetStartColumn(isolate->GetCurrentContext()), columnN umber)) 84 && v8Call(message->GetStartColumn(isolate->GetCurrentContext()), columnN umber))
85 ++columnNumber; 85 ++columnNumber;
86 86
87 if ((!scriptId || !lineNumber) && stackTrace && !stackTrace->isEmpty()) 87 if ((!scriptId || !lineNumber) && stackTrace && !stackTrace->isEmpty())
88 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0); 88 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0);
89 89
90 String url = toCoreStringWithUndefinedOrNullCheck(message->GetScriptOrigin() .ResourceName()); 90 String url = toCoreStringWithUndefinedOrNullCheck(message->GetScriptOrigin() .ResourceName());
91 if (url.isNull()) 91 if (url.isNull())
92 url = executionContext->url(); 92 url = executionContext->url();
93 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack Trace), scriptId); 93 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack Trace), scriptId);
94 } 94 }
95 95
96 // static 96 // static
97 std::unique_ptr<SourceLocation> SourceLocation::create(const String& url, unsign ed lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId) 97 std::unique_ptr<SourceLocation> SourceLocation::create(const String& url, unsign ed lineNumber, unsigned columnNumber, std::unique_ptr<v8_inspector::V8StackTrace > stackTrace, int scriptId)
98 { 98 {
99 return wrapUnique(new SourceLocation(url, lineNumber, columnNumber, std::mov e(stackTrace), scriptId)); 99 return wrapUnique(new SourceLocation(url, lineNumber, columnNumber, std::mov e(stackTrace), scriptId));
100 } 100 }
101 101
102 // static 102 // static
103 std::unique_ptr<SourceLocation> SourceLocation::createFromNonEmptyV8StackTrace(s td::unique_ptr<V8StackTrace> stackTrace, int scriptId) 103 std::unique_ptr<SourceLocation> SourceLocation::createFromNonEmptyV8StackTrace(s td::unique_ptr<v8_inspector::V8StackTrace> stackTrace, int scriptId)
104 { 104 {
105 // Retrieve the data before passing the ownership to SourceLocation. 105 // Retrieve the data before passing the ownership to SourceLocation.
106 const String& url = stackTrace->topSourceURL(); 106 const String& url = stackTrace->topSourceURL();
107 unsigned lineNumber = stackTrace->topLineNumber(); 107 unsigned lineNumber = stackTrace->topLineNumber();
108 unsigned columnNumber = stackTrace->topColumnNumber(); 108 unsigned columnNumber = stackTrace->topColumnNumber();
109 return wrapUnique(new SourceLocation(url, lineNumber, columnNumber, std::mov e(stackTrace), scriptId)); 109 return wrapUnique(new SourceLocation(url, lineNumber, columnNumber, std::mov e(stackTrace), scriptId));
110 } 110 }
111 111
112 // static 112 // static
113 std::unique_ptr<SourceLocation> SourceLocation::fromFunction(v8::Local<v8::Funct ion> function) 113 std::unique_ptr<SourceLocation> SourceLocation::fromFunction(v8::Local<v8::Funct ion> function)
114 { 114 {
115 if (!function.IsEmpty()) 115 if (!function.IsEmpty())
116 return SourceLocation::create(toCoreStringWithUndefinedOrNullCheck(funct ion->GetScriptOrigin().ResourceName()), function->GetScriptLineNumber() + 1, fun ction->GetScriptColumnNumber() + 1, nullptr, function->ScriptId()); 116 return SourceLocation::create(toCoreStringWithUndefinedOrNullCheck(funct ion->GetScriptOrigin().ResourceName()), function->GetScriptLineNumber() + 1, fun ction->GetScriptColumnNumber() + 1, nullptr, function->ScriptId());
117 return SourceLocation::create(String(), 0, 0, nullptr, 0); 117 return SourceLocation::create(String(), 0, 0, nullptr, 0);
118 } 118 }
119 119
120 // static 120 // static
121 std::unique_ptr<SourceLocation> SourceLocation::captureWithFullStackTrace() 121 std::unique_ptr<SourceLocation> SourceLocation::captureWithFullStackTrace()
122 { 122 {
123 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(true); 123 std::unique_ptr<v8_inspector::V8StackTrace> stackTrace = captureStackTrace(t rue);
124 if (stackTrace && !stackTrace->isEmpty()) 124 if (stackTrace && !stackTrace->isEmpty())
125 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0); 125 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0);
126 return SourceLocation::create(String(), 0, 0, nullptr, 0); 126 return SourceLocation::create(String(), 0, 0, nullptr, 0);
127 } 127 }
128 128
129 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId) 129 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<v8_inspector::V8StackTrace> stackTrace, int script Id)
130 : m_url(url) 130 : m_url(url)
131 , m_lineNumber(lineNumber) 131 , m_lineNumber(lineNumber)
132 , m_columnNumber(columnNumber) 132 , m_columnNumber(columnNumber)
133 , m_stackTrace(std::move(stackTrace)) 133 , m_stackTrace(std::move(stackTrace))
134 , m_scriptId(scriptId) 134 , m_scriptId(scriptId)
135 { 135 {
136 } 136 }
137 137
138 SourceLocation::~SourceLocation() 138 SourceLocation::~SourceLocation()
139 { 139 {
(...skipping 25 matching lines...) Expand all
165 } 165 }
166 166
167 String SourceLocation::toString() const 167 String SourceLocation::toString() const
168 { 168 {
169 if (!m_stackTrace) 169 if (!m_stackTrace)
170 return String(); 170 return String();
171 return m_stackTrace->toString(); 171 return m_stackTrace->toString();
172 } 172 }
173 173
174 } // namespace blink 174 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698