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

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

Issue 2016123002: Remove ScriptCallStack. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2006893004
Patch Set: rebased 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/inspector_protocol/TypeBuilder.h"
17 #include "platform/v8_inspector/public/V8Debugger.h" 18 #include "platform/v8_inspector/public/V8Debugger.h"
18 19
19 namespace blink { 20 namespace blink {
20 21
21 namespace { 22 namespace {
22 23
23 std::unique_ptr<V8StackTrace> captureStackTrace() 24 std::unique_ptr<V8StackTrace> captureStackTrace(bool full)
24 { 25 {
25 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 26 v8::Isolate* isolate = v8::Isolate::GetCurrent();
26 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 27 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
27 if (!data->threadDebugger() || !isolate->InContext()) 28 if (!data->threadDebugger() || !isolate->InContext())
28 return nullptr; 29 return nullptr;
29 size_t stackSize = 1; 30 size_t stackSize = full ? V8StackTrace::maxCallStackSizeToCapture : 1;
30 if (InspectorInstrumentation::hasFrontends()) { 31 if (InspectorInstrumentation::hasFrontends()) {
31 if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContex t(isolate))) 32 if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContex t(isolate)))
32 stackSize = V8StackTrace::maxCallStackSizeToCapture; 33 stackSize = V8StackTrace::maxCallStackSizeToCapture;
33 } 34 }
34 ScriptForbiddenScope::AllowUserAgentScript allowScripting; 35 ScriptForbiddenScope::AllowUserAgentScript allowScripting;
35 return data->threadDebugger()->debugger()->captureStackTrace(stackSize); 36 return data->threadDebugger()->debugger()->captureStackTrace(stackSize);
36 } 37 }
37 38
38 } 39 }
39 40
40 // static 41 // static
41 PassOwnPtr<SourceLocation> SourceLocation::capture(const String& url, unsigned l ineNumber, unsigned columnNumber) 42 PassOwnPtr<SourceLocation> SourceLocation::capture(const String& url, unsigned l ineNumber, unsigned columnNumber)
42 { 43 {
43 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(); 44 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(false);
44 if (stackTrace && !stackTrace->isEmpty()) 45 if (stackTrace && !stackTrace->isEmpty())
45 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0); 46 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0);
46 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack Trace)); 47 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack Trace));
47 } 48 }
48 49
49 // static 50 // static
50 PassOwnPtr<SourceLocation> SourceLocation::capture(ExecutionContext* executionCo ntext) 51 PassOwnPtr<SourceLocation> SourceLocation::capture(ExecutionContext* executionCo ntext)
51 { 52 {
52 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(); 53 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(false);
53 if (stackTrace && !stackTrace->isEmpty()) 54 if (stackTrace && !stackTrace->isEmpty())
54 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0); 55 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0);
55 56
56 Document* document = executionContext && executionContext->isDocument() ? to Document(executionContext) : nullptr; 57 Document* document = executionContext && executionContext->isDocument() ? to Document(executionContext) : nullptr;
57 if (document) { 58 if (document) {
58 unsigned lineNumber = 0; 59 unsigned lineNumber = 0;
59 if (document->scriptableDocumentParser() && !document->isInDocumentWrite ()) { 60 if (document->scriptableDocumentParser() && !document->isInDocumentWrite ()) {
60 if (document->scriptableDocumentParser()->isParsingAtLineNumber()) 61 if (document->scriptableDocumentParser()->isParsingAtLineNumber())
61 lineNumber = document->scriptableDocumentParser()->lineNumber(). oneBasedInt(); 62 lineNumber = document->scriptableDocumentParser()->lineNumber(). oneBasedInt();
62 } 63 }
63 return SourceLocation::create(document->url().getString(), lineNumber, 0 , std::move(stackTrace)); 64 return SourceLocation::create(document->url().getString(), lineNumber, 0 , std::move(stackTrace));
64 } 65 }
65 66
66 return SourceLocation::create(executionContext ? executionContext->url().get String() : "", 0, 0, std::move(stackTrace)); 67 return SourceLocation::create(executionContext ? executionContext->url().get String() : String(), 0, 0, std::move(stackTrace));
67 } 68 }
68 69
69 // static 70 // static
70 PassOwnPtr<SourceLocation> SourceLocation::fromMessage(v8::Isolate* isolate, v8: :Local<v8::Message> message, ExecutionContext* executionContext) 71 PassOwnPtr<SourceLocation> SourceLocation::fromMessage(v8::Isolate* isolate, v8: :Local<v8::Message> message, ExecutionContext* executionContext)
71 { 72 {
72 v8::Local<v8::StackTrace> stack = message->GetStackTrace(); 73 v8::Local<v8::StackTrace> stack = message->GetStackTrace();
73 std::unique_ptr<V8StackTrace> stackTrace = nullptr; 74 std::unique_ptr<V8StackTrace> stackTrace = nullptr;
74 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 75 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
75 if (data && data->threadDebugger()) 76 if (data && data->threadDebugger())
76 stackTrace = data->threadDebugger()->debugger()->createStackTrace(stack) ; 77 stackTrace = data->threadDebugger()->debugger()->createStackTrace(stack) ;
(...skipping 29 matching lines...) Expand all
106 // static 107 // static
107 PassOwnPtr<SourceLocation> SourceLocation::createFromNonEmptyV8StackTrace(std::u nique_ptr<V8StackTrace> stackTrace, int scriptId) 108 PassOwnPtr<SourceLocation> SourceLocation::createFromNonEmptyV8StackTrace(std::u nique_ptr<V8StackTrace> stackTrace, int scriptId)
108 { 109 {
109 // Retrieve the data before passing the ownership to SourceLocation. 110 // Retrieve the data before passing the ownership to SourceLocation.
110 const String& url = stackTrace->topSourceURL(); 111 const String& url = stackTrace->topSourceURL();
111 unsigned lineNumber = stackTrace->topLineNumber(); 112 unsigned lineNumber = stackTrace->topLineNumber();
112 unsigned columnNumber = stackTrace->topColumnNumber(); 113 unsigned columnNumber = stackTrace->topColumnNumber();
113 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move( stackTrace), scriptId)); 114 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move( stackTrace), scriptId));
114 } 115 }
115 116
117 // static
118 PassOwnPtr<SourceLocation> SourceLocation::fromFunction(v8::Local<v8::Function> function)
119 {
120 if (!function.IsEmpty())
121 return SourceLocation::create(toCoreStringWithUndefinedOrNullCheck(funct ion->GetScriptOrigin().ResourceName()), function->GetScriptLineNumber() + 1, fun ction->GetScriptColumnNumber() + 1, nullptr, function->ScriptId());
122 return SourceLocation::create(String(), 0, 0, nullptr, 0);
123 }
124
125 // static
126 PassOwnPtr<SourceLocation> SourceLocation::captureWithFullStackTrace()
127 {
128 std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace(true);
129 if (stackTrace && !stackTrace->isEmpty())
130 return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTra ce), 0);
131 return SourceLocation::create(String(), 0, 0, nullptr, 0);
132 }
133
116 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId) 134 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId)
117 : m_url(url) 135 : m_url(url)
118 , m_lineNumber(lineNumber) 136 , m_lineNumber(lineNumber)
119 , m_columnNumber(columnNumber) 137 , m_columnNumber(columnNumber)
120 , m_stackTrace(std::move(stackTrace)) 138 , m_stackTrace(std::move(stackTrace))
121 , m_scriptId(scriptId) 139 , m_scriptId(scriptId)
122 { 140 {
123 } 141 }
124 142
125 SourceLocation::~SourceLocation() 143 SourceLocation::~SourceLocation()
(...skipping 18 matching lines...) Expand all
144 PassOwnPtr<SourceLocation> SourceLocation::clone() const 162 PassOwnPtr<SourceLocation> SourceLocation::clone() const
145 { 163 {
146 return adoptPtr(new SourceLocation(m_url, m_lineNumber, m_columnNumber, m_st ackTrace ? m_stackTrace->clone() : nullptr, m_scriptId)); 164 return adoptPtr(new SourceLocation(m_url, m_lineNumber, m_columnNumber, m_st ackTrace ? m_stackTrace->clone() : nullptr, m_scriptId));
147 } 165 }
148 166
149 PassOwnPtr<SourceLocation> SourceLocation::isolatedCopy() const 167 PassOwnPtr<SourceLocation> SourceLocation::isolatedCopy() const
150 { 168 {
151 return adoptPtr(new SourceLocation(m_url.isolatedCopy(), m_lineNumber, m_col umnNumber, m_stackTrace ? m_stackTrace->isolatedCopy() : nullptr, m_scriptId)); 169 return adoptPtr(new SourceLocation(m_url.isolatedCopy(), m_lineNumber, m_col umnNumber, m_stackTrace ? m_stackTrace->isolatedCopy() : nullptr, m_scriptId));
152 } 170 }
153 171
172 std::unique_ptr<protocol::Runtime::StackTrace> SourceLocation::buildInspectorObj ect() const
173 {
174 return m_stackTrace ? m_stackTrace->buildInspectorObject() : nullptr;
175 }
176
177 String SourceLocation::toString() const
178 {
179 if (!m_stackTrace)
180 return String();
181 return m_stackTrace->toString();
182 }
183
154 } // namespace blink 184 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/SourceLocation.h ('k') | third_party/WebKit/Source/bindings/core/v8/v8.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698