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

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

Issue 2269843002: [DevTools] Improve ConsoleAPI functions string description (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: replaced ->Set( in v8_inspector 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"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (!wrapper.IsEmpty() && wrapper->IsUndefined()) 172 if (!wrapper.IsEmpty() && wrapper->IsUndefined())
173 return false; 173 return false;
174 return true; 174 return true;
175 } 175 }
176 176
177 static void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 177 static void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
178 { 178 {
179 info.GetReturnValue().Set(info.Data()); 179 info.GetReturnValue().Set(info.Data());
180 } 180 }
181 181
182 static v8::Maybe<bool> safeCreateDataProperty(v8::Local<v8::Context> context, v8 ::Local<v8::Object> object, v8::Local<v8::Name> key, v8::Local<v8::Value> value)
dgozman 2016/08/23 19:27:37 Let's put this on ThreadDebugger as well, similar
kozy 2016/08/23 19:33:45 Acknowledged.
183 {
184 v8::Isolate::DisallowJavascriptExecutionScope throwJs(context->GetIsolate(), v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE);
185 return object->CreateDataProperty(context, key, value);
186 }
187
182 static void createFunctionPropertyWithData(v8::Local<v8::Context> context, v8::L ocal<v8::Object> object, const char* name, v8::FunctionCallback callback, v8::Lo cal<v8::Value> data, const char* description) 188 static void createFunctionPropertyWithData(v8::Local<v8::Context> context, v8::L ocal<v8::Object> object, const char* name, v8::FunctionCallback callback, v8::Lo cal<v8::Value> data, const char* description)
183 { 189 {
184 v8::Local<v8::String> funcName = v8String(context->GetIsolate(), name); 190 v8::Local<v8::String> funcName = v8String(context->GetIsolate(), name);
185 v8::Local<v8::Function> func; 191 v8::Local<v8::Function> func;
186 if (!v8::Function::New(context, callback, data, 0, v8::ConstructorBehavior:: kThrow).ToLocal(&func)) 192 if (!v8::Function::New(context, callback, data, 0, v8::ConstructorBehavior:: kThrow).ToLocal(&func))
187 return; 193 return;
188 func->SetName(funcName); 194 func->SetName(funcName);
189 v8::Local<v8::String> returnValue = v8String(context->GetIsolate(), descript ion); 195 v8::Local<v8::String> returnValue = v8String(context->GetIsolate(), descript ion);
190 v8::Local<v8::Function> toStringFunction; 196 v8::Local<v8::Function> toStringFunction;
191 if (v8::Function::New(context, returnDataCallback, returnValue, 0, v8::Const ructorBehavior::kThrow).ToLocal(&toStringFunction)) 197 if (v8::Function::New(context, returnDataCallback, returnValue, 0, v8::Const ructorBehavior::kThrow).ToLocal(&toStringFunction))
192 func->Set(v8String(context->GetIsolate(), "toString"), toStringFunction) ; 198 safeCreateDataProperty(context, func, v8String(context->GetIsolate(), "t oString"), toStringFunction);
193 if (!object->Set(context, funcName, func).FromMaybe(false)) 199 safeCreateDataProperty(context, object, funcName, func);
194 return; 200 }
201
202 v8::Maybe<bool> ThreadDebugger::safeCreateDataPropertyInArray(v8::Local<v8::Cont ext> context, v8::Local<v8::Array> array, int index, v8::Local<v8::Value> value)
203 {
204 v8::Isolate::DisallowJavascriptExecutionScope throwJs(context->GetIsolate(), v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE);
205 return array->CreateDataProperty(context, index, value);
195 } 206 }
196 207
197 void ThreadDebugger::createFunctionProperty(v8::Local<v8::Context> context, v8:: Local<v8::Object> object, const char* name, v8::FunctionCallback callback, const char* description) 208 void ThreadDebugger::createFunctionProperty(v8::Local<v8::Context> context, v8:: Local<v8::Object> object, const char* name, v8::FunctionCallback callback, const char* description)
198 { 209 {
199 createFunctionPropertyWithData(context, object, name, callback, v8::External ::New(context->GetIsolate(), this), description); 210 createFunctionPropertyWithData(context, object, name, callback, v8::External ::New(context->GetIsolate(), this), description);
200 } 211 }
201 212
202 void ThreadDebugger::installAdditionalCommandLineAPI(v8::Local<v8::Context> cont ext, v8::Local<v8::Object> object) 213 void ThreadDebugger::installAdditionalCommandLineAPI(v8::Local<v8::Context> cont ext, v8::Local<v8::Object> object)
203 { 214 {
204 createFunctionProperty(context, object, "getEventListeners", ThreadDebugger: :getEventListenersCallback, "function getEventListeners(node) { [Command Line AP I] }"); 215 createFunctionProperty(context, object, "getEventListeners", ThreadDebugger: :getEventListenersCallback, "function getEventListeners(node) { [Command Line AP I] }");
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 296
286 // static 297 // static
287 void ThreadDebugger::getEventListenersCallback(const v8::FunctionCallbackInfo<v8 ::Value>& info) 298 void ThreadDebugger::getEventListenersCallback(const v8::FunctionCallbackInfo<v8 ::Value>& info)
288 { 299 {
289 if (info.Length() < 1) 300 if (info.Length() < 1)
290 return; 301 return;
291 302
292 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern al>::Cast(info.Data())->Value()); 303 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern al>::Cast(info.Data())->Value());
293 DCHECK(debugger); 304 DCHECK(debugger);
294 v8::Isolate* isolate = info.GetIsolate(); 305 v8::Isolate* isolate = info.GetIsolate();
295 int groupId = debugger->contextGroupId(toExecutionContext(isolate->GetCurren tContext())); 306 v8::Local<v8::Context> context = isolate->GetCurrentContext();
307 int groupId = debugger->contextGroupId(toExecutionContext(context));
296 308
297 V8EventListenerInfoList listenerInfo; 309 V8EventListenerInfoList listenerInfo;
298 // eventListeners call can produce message on ErrorEvent during lazy event l istener compilation. 310 // eventListeners call can produce message on ErrorEvent during lazy event l istener compilation.
299 if (groupId) 311 if (groupId)
300 debugger->muteMetrics(groupId); 312 debugger->muteMetrics(groupId);
301 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis tenerInfo); 313 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis tenerInfo);
302 if (groupId) 314 if (groupId)
303 debugger->unmuteMetrics(groupId); 315 debugger->unmuteMetrics(groupId);
304 316
305 v8::Local<v8::Object> result = v8::Object::New(isolate); 317 v8::Local<v8::Object> result = v8::Object::New(isolate);
306 AtomicString currentEventType; 318 AtomicString currentEventType;
307 v8::Local<v8::Array> listeners; 319 v8::Local<v8::Array> listeners;
308 size_t outputIndex = 0; 320 size_t outputIndex = 0;
309 for (auto& info : listenerInfo) { 321 for (auto& info : listenerInfo) {
310 if (currentEventType != info.eventType) { 322 if (currentEventType != info.eventType) {
311 currentEventType = info.eventType; 323 currentEventType = info.eventType;
312 listeners = v8::Array::New(isolate); 324 listeners = v8::Array::New(isolate);
313 outputIndex = 0; 325 outputIndex = 0;
314 result->Set(v8String(isolate, currentEventType), listeners); 326 safeCreateDataProperty(context, result, v8String(isolate, currentEve ntType), listeners);
315 } 327 }
316 328
317 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate); 329 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate);
318 listenerObject->Set(v8String(isolate, "listener"), info.handler); 330 safeCreateDataProperty(context, listenerObject, v8String(isolate, "liste ner"), info.handler);
319 listenerObject->Set(v8String(isolate, "useCapture"), v8::Boolean::New(is olate, info.useCapture)); 331 safeCreateDataProperty(context, listenerObject, v8String(isolate, "useCa pture"), v8::Boolean::New(isolate, info.useCapture));
320 listenerObject->Set(v8String(isolate, "passive"), v8::Boolean::New(isola te, info.passive)); 332 safeCreateDataProperty(context, listenerObject, v8String(isolate, "passi ve"), v8::Boolean::New(isolate, info.passive));
321 listenerObject->Set(v8String(isolate, "type"), v8String(isolate, current EventType)); 333 safeCreateDataProperty(context, listenerObject, v8String(isolate, "type" ), v8String(isolate, currentEventType));
322 v8::Local<v8::Function> removeFunction; 334 v8::Local<v8::Function> removeFunction;
323 if (info.removeFunction.ToLocal(&removeFunction)) 335 if (info.removeFunction.ToLocal(&removeFunction))
324 listenerObject->Set(v8String(isolate, "remove"), removeFunction); 336 safeCreateDataProperty(context, listenerObject, v8String(isolate, "r emove"), removeFunction);
325 listeners->Set(outputIndex++, listenerObject); 337 safeCreateDataPropertyInArray(context, listeners, outputIndex++, listene rObject);
326 } 338 }
327 info.GetReturnValue().Set(result); 339 info.GetReturnValue().Set(result);
328 } 340 }
329 341
330 void ThreadDebugger::consoleTime(const String16& title) 342 void ThreadDebugger::consoleTime(const String16& title)
331 { 343 {
332 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", String(title).utf8().data(), this); 344 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", String(title).utf8().data(), this);
333 } 345 }
334 346
335 void ThreadDebugger::consoleTimeEnd(const String16& title) 347 void ThreadDebugger::consoleTimeEnd(const String16& title)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 { 383 {
372 for (size_t index = 0; index < m_timers.size(); ++index) { 384 for (size_t index = 0; index < m_timers.size(); ++index) {
373 if (m_timers[index].get() == timer) { 385 if (m_timers[index].get() == timer) {
374 m_timerCallbacks[index](m_timerData[index]); 386 m_timerCallbacks[index](m_timerData[index]);
375 return; 387 return;
376 } 388 }
377 } 389 }
378 } 390 }
379 391
380 } // namespace blink 392 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698