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

Side by Side Diff: third_party/WebKit/Source/core/inspector/ThreadDebugger.cpp

Issue 2260233002: [DevTools] Migrate v8_inspector/public from String16 to String{View,Buffer}. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: styling Created 4 years, 3 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 "core/inspector/ThreadDebugger.h" 5 #include "core/inspector/ThreadDebugger.h"
6 6
7 #include "bindings/core/v8/SourceLocation.h" 7 #include "bindings/core/v8/SourceLocation.h"
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/core/v8/V8DOMException.h" 9 #include "bindings/core/v8/V8DOMException.h"
10 #include "bindings/core/v8/V8DOMTokenList.h" 10 #include "bindings/core/v8/V8DOMTokenList.h"
11 #include "bindings/core/v8/V8Event.h" 11 #include "bindings/core/v8/V8Event.h"
12 #include "bindings/core/v8/V8EventListener.h" 12 #include "bindings/core/v8/V8EventListener.h"
13 #include "bindings/core/v8/V8EventListenerInfo.h" 13 #include "bindings/core/v8/V8EventListenerInfo.h"
14 #include "bindings/core/v8/V8EventListenerList.h" 14 #include "bindings/core/v8/V8EventListenerList.h"
15 #include "bindings/core/v8/V8HTMLAllCollection.h" 15 #include "bindings/core/v8/V8HTMLAllCollection.h"
16 #include "bindings/core/v8/V8HTMLCollection.h" 16 #include "bindings/core/v8/V8HTMLCollection.h"
17 #include "bindings/core/v8/V8Node.h" 17 #include "bindings/core/v8/V8Node.h"
18 #include "bindings/core/v8/V8NodeList.h" 18 #include "bindings/core/v8/V8NodeList.h"
19 #include "bindings/core/v8/V8ScriptRunner.h" 19 #include "bindings/core/v8/V8ScriptRunner.h"
20 #include "core/inspector/ConsoleMessage.h" 20 #include "core/inspector/ConsoleMessage.h"
21 #include "core/inspector/InspectorDOMDebuggerAgent.h" 21 #include "core/inspector/InspectorDOMDebuggerAgent.h"
22 #include "core/inspector/InspectorTraceEvents.h" 22 #include "core/inspector/InspectorTraceEvents.h"
23 #include "core/inspector/V8InspectorString.h"
23 #include "platform/ScriptForbiddenScope.h" 24 #include "platform/ScriptForbiddenScope.h"
24 #include "wtf/CurrentTime.h" 25 #include "wtf/CurrentTime.h"
25 #include "wtf/PtrUtil.h" 26 #include "wtf/PtrUtil.h"
26 #include <memory> 27 #include <memory>
27 28
28 namespace blink { 29 namespace blink {
29 30
30 ThreadDebugger::ThreadDebugger(v8::Isolate* isolate) 31 ThreadDebugger::ThreadDebugger(v8::Isolate* isolate)
31 : m_isolate(isolate) 32 : m_isolate(isolate)
32 , m_v8Inspector(v8_inspector::V8Inspector::create(isolate, this)) 33 , m_v8Inspector(v8_inspector::V8Inspector::create(isolate, this))
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 79 }
79 80
80 void ThreadDebugger::idleFinished(v8::Isolate* isolate) 81 void ThreadDebugger::idleFinished(v8::Isolate* isolate)
81 { 82 {
82 if (ThreadDebugger* debugger = ThreadDebugger::from(isolate)) 83 if (ThreadDebugger* debugger = ThreadDebugger::from(isolate))
83 debugger->v8Inspector()->idleFinished(); 84 debugger->v8Inspector()->idleFinished();
84 } 85 }
85 86
86 void ThreadDebugger::asyncTaskScheduled(const String& operationName, void* task, bool recurring) 87 void ThreadDebugger::asyncTaskScheduled(const String& operationName, void* task, bool recurring)
87 { 88 {
88 m_v8Inspector->asyncTaskScheduled(operationName, task, recurring); 89 m_v8Inspector->asyncTaskScheduled(toV8InspectorStringView(operationName), ta sk, recurring);
89 } 90 }
90 91
91 void ThreadDebugger::asyncTaskCanceled(void* task) 92 void ThreadDebugger::asyncTaskCanceled(void* task)
92 { 93 {
93 m_v8Inspector->asyncTaskCanceled(task); 94 m_v8Inspector->asyncTaskCanceled(task);
94 } 95 }
95 96
96 void ThreadDebugger::allAsyncTasksCanceled() 97 void ThreadDebugger::allAsyncTasksCanceled()
97 { 98 {
98 m_v8Inspector->allAsyncTasksCanceled(); 99 m_v8Inspector->allAsyncTasksCanceled();
(...skipping 12 matching lines...) Expand all
111 unsigned ThreadDebugger::promiseRejected(v8::Local<v8::Context> context, const S tring& errorMessage, v8::Local<v8::Value> exception, std::unique_ptr<SourceLocat ion> location) 112 unsigned ThreadDebugger::promiseRejected(v8::Local<v8::Context> context, const S tring& errorMessage, v8::Local<v8::Value> exception, std::unique_ptr<SourceLocat ion> location)
112 { 113 {
113 const String defaultMessage = "Uncaught (in promise)"; 114 const String defaultMessage = "Uncaught (in promise)";
114 String message = errorMessage; 115 String message = errorMessage;
115 if (message.isEmpty()) 116 if (message.isEmpty())
116 message = defaultMessage; 117 message = defaultMessage;
117 else if (message.startsWith("Uncaught ")) 118 else if (message.startsWith("Uncaught "))
118 message = message.substring(0, 8) + " (in promise)" + message.substring( 8); 119 message = message.substring(0, 8) + " (in promise)" + message.substring( 8);
119 120
120 reportConsoleMessage(toExecutionContext(context), JSMessageSource, ErrorMess ageLevel, message, location.get()); 121 reportConsoleMessage(toExecutionContext(context), JSMessageSource, ErrorMess ageLevel, message, location.get());
121 return v8Inspector()->exceptionThrown(context, defaultMessage, exception, me ssage, location->url(), location->lineNumber(), location->columnNumber(), locati on->takeStackTrace(), location->scriptId()); 122 String url = location->url();
123 return v8Inspector()->exceptionThrown(context, toV8InspectorStringView(defau ltMessage), exception, toV8InspectorStringView(message), toV8InspectorStringView (url), location->lineNumber(), location->columnNumber(), location->takeStackTrac e(), location->scriptId());
122 } 124 }
123 125
124 void ThreadDebugger::promiseRejectionRevoked(v8::Local<v8::Context> context, uns igned promiseRejectionId) 126 void ThreadDebugger::promiseRejectionRevoked(v8::Local<v8::Context> context, uns igned promiseRejectionId)
125 { 127 {
126 const String message = "Handler added to rejected promise"; 128 const String message = "Handler added to rejected promise";
127 v8Inspector()->exceptionRevoked(context, promiseRejectionId, message); 129 v8Inspector()->exceptionRevoked(context, promiseRejectionId, toV8InspectorSt ringView(message));
128 } 130 }
129 131
130 void ThreadDebugger::beginUserGesture() 132 void ThreadDebugger::beginUserGesture()
131 { 133 {
132 m_userGestureIndicator = wrapUnique(new UserGestureIndicator(DefinitelyProce ssingNewUserGesture)); 134 m_userGestureIndicator = wrapUnique(new UserGestureIndicator(DefinitelyProce ssingNewUserGesture));
133 } 135 }
134 136
135 void ThreadDebugger::endUserGesture() 137 void ThreadDebugger::endUserGesture()
136 { 138 {
137 m_userGestureIndicator.reset(); 139 m_userGestureIndicator.reset();
138 } 140 }
139 141
140 String16 ThreadDebugger::valueSubtype(v8::Local<v8::Value> value) 142 std::unique_ptr<v8_inspector::StringBuffer> ThreadDebugger::valueSubtype(v8::Loc al<v8::Value> value)
141 { 143 {
144 static const char kNode[] = "node";
145 static const char kArray[] = "array";
146 static const char kError[] = "error";
142 if (V8Node::hasInstance(value, m_isolate)) 147 if (V8Node::hasInstance(value, m_isolate))
143 return "node"; 148 return toV8InspectorStringBuffer(kNode);
144 if (V8NodeList::hasInstance(value, m_isolate) 149 if (V8NodeList::hasInstance(value, m_isolate)
145 || V8DOMTokenList::hasInstance(value, m_isolate) 150 || V8DOMTokenList::hasInstance(value, m_isolate)
146 || V8HTMLCollection::hasInstance(value, m_isolate) 151 || V8HTMLCollection::hasInstance(value, m_isolate)
147 || V8HTMLAllCollection::hasInstance(value, m_isolate)) { 152 || V8HTMLAllCollection::hasInstance(value, m_isolate)) {
148 return "array"; 153 return toV8InspectorStringBuffer(kArray);
149 } 154 }
150 if (V8DOMException::hasInstance(value, m_isolate)) 155 if (V8DOMException::hasInstance(value, m_isolate))
151 return "error"; 156 return toV8InspectorStringBuffer(kError);
152 return String(); 157 return nullptr;
153 } 158 }
154 159
155 bool ThreadDebugger::formatAccessorsAsProperties(v8::Local<v8::Value> value) 160 bool ThreadDebugger::formatAccessorsAsProperties(v8::Local<v8::Value> value)
156 { 161 {
157 return V8DOMWrapper::isWrapper(m_isolate, value); 162 return V8DOMWrapper::isWrapper(m_isolate, value);
158 } 163 }
159 164
160 double ThreadDebugger::currentTimeMS() 165 double ThreadDebugger::currentTimeMS()
161 { 166 {
162 return WTF::currentTimeMS(); 167 return WTF::currentTimeMS();
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 createDataProperty(context, listenerObject, v8String(isolate, "passive") , v8::Boolean::New(isolate, info.passive)); 339 createDataProperty(context, listenerObject, v8String(isolate, "passive") , v8::Boolean::New(isolate, info.passive));
335 createDataProperty(context, listenerObject, v8String(isolate, "type"), v 8String(isolate, currentEventType)); 340 createDataProperty(context, listenerObject, v8String(isolate, "type"), v 8String(isolate, currentEventType));
336 v8::Local<v8::Function> removeFunction; 341 v8::Local<v8::Function> removeFunction;
337 if (info.removeFunction.ToLocal(&removeFunction)) 342 if (info.removeFunction.ToLocal(&removeFunction))
338 createDataProperty(context, listenerObject, v8String(isolate, "remov e"), removeFunction); 343 createDataProperty(context, listenerObject, v8String(isolate, "remov e"), removeFunction);
339 createDataPropertyInArray(context, listeners, outputIndex++, listenerObj ect); 344 createDataPropertyInArray(context, listeners, outputIndex++, listenerObj ect);
340 } 345 }
341 info.GetReturnValue().Set(result); 346 info.GetReturnValue().Set(result);
342 } 347 }
343 348
344 void ThreadDebugger::consoleTime(const String16& title) 349 void ThreadDebugger::consoleTime(const v8_inspector::StringView& title)
345 { 350 {
346 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", String(title).utf8().data(), this); 351 // TODO(dgozman): we can save on a copy here if trace macro would take a poi nter with length.
352 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", toCoreString(title).utf8().da ta(), this);
347 } 353 }
348 354
349 void ThreadDebugger::consoleTimeEnd(const String16& title) 355 void ThreadDebugger::consoleTimeEnd(const v8_inspector::StringView& title)
350 { 356 {
351 TRACE_EVENT_COPY_ASYNC_END0("blink.console", String(title).utf8().data(), th is); 357 // TODO(dgozman): we can save on a copy here if trace macro would take a poi nter with length.
358 TRACE_EVENT_COPY_ASYNC_END0("blink.console", toCoreString(title).utf8().data (), this);
352 } 359 }
353 360
354 void ThreadDebugger::consoleTimeStamp(const String16& title) 361 void ThreadDebugger::consoleTimeStamp(const v8_inspector::StringView& title)
355 { 362 {
356 v8::Isolate* isolate = m_isolate; 363 v8::Isolate* isolate = m_isolate;
357 TRACE_EVENT_INSTANT1("devtools.timeline", "TimeStamp", TRACE_EVENT_SCOPE_THR EAD, "data", InspectorTimeStampEvent::data(currentExecutionContext(isolate), tit le)); 364 // TODO(dgozman): we can save on a copy here if TracedValue would take a Str ingView.
365 TRACE_EVENT_INSTANT1("devtools.timeline", "TimeStamp", TRACE_EVENT_SCOPE_THR EAD, "data", InspectorTimeStampEvent::data(currentExecutionContext(isolate), toC oreString(title)));
358 } 366 }
359 367
360 void ThreadDebugger::startRepeatingTimer(double interval, V8InspectorClient::Tim erCallback callback, void* data) 368 void ThreadDebugger::startRepeatingTimer(double interval, V8InspectorClient::Tim erCallback callback, void* data)
361 { 369 {
362 m_timerData.append(data); 370 m_timerData.append(data);
363 m_timerCallbacks.append(callback); 371 m_timerCallbacks.append(callback);
364 372
365 std::unique_ptr<Timer<ThreadDebugger>> timer = wrapUnique(new Timer<ThreadDe bugger>(this, &ThreadDebugger::onTimer)); 373 std::unique_ptr<Timer<ThreadDebugger>> timer = wrapUnique(new Timer<ThreadDe bugger>(this, &ThreadDebugger::onTimer));
366 Timer<ThreadDebugger>* timerPtr = timer.get(); 374 Timer<ThreadDebugger>* timerPtr = timer.get();
367 m_timers.append(std::move(timer)); 375 m_timers.append(std::move(timer));
(...skipping 17 matching lines...) Expand all
385 { 393 {
386 for (size_t index = 0; index < m_timers.size(); ++index) { 394 for (size_t index = 0; index < m_timers.size(); ++index) {
387 if (m_timers[index].get() == timer) { 395 if (m_timers[index].get() == timer) {
388 m_timerCallbacks[index](m_timerData[index]); 396 m_timerCallbacks[index](m_timerData[index]);
389 return; 397 return;
390 } 398 }
391 } 399 }
392 } 400 }
393 401
394 } // namespace blink 402 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698