OLD | NEW |
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 Loading... |
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> createDataProperty(v8::Local<v8::Context> context, v8::Lo
cal<v8::Object> object, v8::Local<v8::Name> key, v8::Local<v8::Value> value) |
| 183 { |
| 184 v8::TryCatch tryCatch(context->GetIsolate()); |
| 185 v8::Isolate::DisallowJavascriptExecutionScope throwJs(context->GetIsolate(),
v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); |
| 186 return object->CreateDataProperty(context, key, value); |
| 187 } |
| 188 |
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) | 189 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 { | 190 { |
184 v8::Local<v8::String> funcName = v8String(context->GetIsolate(), name); | 191 v8::Local<v8::String> funcName = v8String(context->GetIsolate(), name); |
185 v8::Local<v8::Function> func; | 192 v8::Local<v8::Function> func; |
186 if (!v8::Function::New(context, callback, data, 0, v8::ConstructorBehavior::
kThrow).ToLocal(&func)) | 193 if (!v8::Function::New(context, callback, data, 0, v8::ConstructorBehavior::
kThrow).ToLocal(&func)) |
187 return; | 194 return; |
188 func->SetName(funcName); | 195 func->SetName(funcName); |
189 v8::Local<v8::String> returnValue = v8String(context->GetIsolate(), descript
ion); | 196 v8::Local<v8::String> returnValue = v8String(context->GetIsolate(), descript
ion); |
190 v8::Local<v8::Function> toStringFunction; | 197 v8::Local<v8::Function> toStringFunction; |
191 if (v8::Function::New(context, returnDataCallback, returnValue, 0, v8::Const
ructorBehavior::kThrow).ToLocal(&toStringFunction)) | 198 if (v8::Function::New(context, returnDataCallback, returnValue, 0, v8::Const
ructorBehavior::kThrow).ToLocal(&toStringFunction)) |
192 func->Set(v8String(context->GetIsolate(), "toString"), toStringFunction)
; | 199 createDataProperty(context, func, v8String(context->GetIsolate(), "toStr
ing"), toStringFunction); |
193 if (!object->Set(context, funcName, func).FromMaybe(false)) | 200 createDataProperty(context, object, funcName, func); |
194 return; | 201 } |
| 202 |
| 203 v8::Maybe<bool> ThreadDebugger::createDataPropertyInArray(v8::Local<v8::Context>
context, v8::Local<v8::Array> array, int index, v8::Local<v8::Value> value) |
| 204 { |
| 205 v8::TryCatch tryCatch(context->GetIsolate()); |
| 206 v8::Isolate::DisallowJavascriptExecutionScope throwJs(context->GetIsolate(),
v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); |
| 207 return array->CreateDataProperty(context, index, value); |
195 } | 208 } |
196 | 209 |
197 void ThreadDebugger::createFunctionProperty(v8::Local<v8::Context> context, v8::
Local<v8::Object> object, const char* name, v8::FunctionCallback callback, const
char* description) | 210 void ThreadDebugger::createFunctionProperty(v8::Local<v8::Context> context, v8::
Local<v8::Object> object, const char* name, v8::FunctionCallback callback, const
char* description) |
198 { | 211 { |
199 createFunctionPropertyWithData(context, object, name, callback, v8::External
::New(context->GetIsolate(), this), description); | 212 createFunctionPropertyWithData(context, object, name, callback, v8::External
::New(context->GetIsolate(), this), description); |
200 } | 213 } |
201 | 214 |
202 void ThreadDebugger::installAdditionalCommandLineAPI(v8::Local<v8::Context> cont
ext, v8::Local<v8::Object> object) | 215 void ThreadDebugger::installAdditionalCommandLineAPI(v8::Local<v8::Context> cont
ext, v8::Local<v8::Object> object) |
203 { | 216 { |
204 createFunctionProperty(context, object, "getEventListeners", ThreadDebugger:
:getEventListenersCallback, "function getEventListeners(node) { [Command Line AP
I] }"); | 217 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 Loading... |
285 | 298 |
286 // static | 299 // static |
287 void ThreadDebugger::getEventListenersCallback(const v8::FunctionCallbackInfo<v8
::Value>& info) | 300 void ThreadDebugger::getEventListenersCallback(const v8::FunctionCallbackInfo<v8
::Value>& info) |
288 { | 301 { |
289 if (info.Length() < 1) | 302 if (info.Length() < 1) |
290 return; | 303 return; |
291 | 304 |
292 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern
al>::Cast(info.Data())->Value()); | 305 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern
al>::Cast(info.Data())->Value()); |
293 DCHECK(debugger); | 306 DCHECK(debugger); |
294 v8::Isolate* isolate = info.GetIsolate(); | 307 v8::Isolate* isolate = info.GetIsolate(); |
295 int groupId = debugger->contextGroupId(toExecutionContext(isolate->GetCurren
tContext())); | 308 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 309 int groupId = debugger->contextGroupId(toExecutionContext(context)); |
296 | 310 |
297 V8EventListenerInfoList listenerInfo; | 311 V8EventListenerInfoList listenerInfo; |
298 // eventListeners call can produce message on ErrorEvent during lazy event l
istener compilation. | 312 // eventListeners call can produce message on ErrorEvent during lazy event l
istener compilation. |
299 if (groupId) | 313 if (groupId) |
300 debugger->muteMetrics(groupId); | 314 debugger->muteMetrics(groupId); |
301 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis
tenerInfo); | 315 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis
tenerInfo); |
302 if (groupId) | 316 if (groupId) |
303 debugger->unmuteMetrics(groupId); | 317 debugger->unmuteMetrics(groupId); |
304 | 318 |
305 v8::Local<v8::Object> result = v8::Object::New(isolate); | 319 v8::Local<v8::Object> result = v8::Object::New(isolate); |
306 AtomicString currentEventType; | 320 AtomicString currentEventType; |
307 v8::Local<v8::Array> listeners; | 321 v8::Local<v8::Array> listeners; |
308 size_t outputIndex = 0; | 322 size_t outputIndex = 0; |
309 for (auto& info : listenerInfo) { | 323 for (auto& info : listenerInfo) { |
310 if (currentEventType != info.eventType) { | 324 if (currentEventType != info.eventType) { |
311 currentEventType = info.eventType; | 325 currentEventType = info.eventType; |
312 listeners = v8::Array::New(isolate); | 326 listeners = v8::Array::New(isolate); |
313 outputIndex = 0; | 327 outputIndex = 0; |
314 result->Set(v8String(isolate, currentEventType), listeners); | 328 createDataProperty(context, result, v8String(isolate, currentEventTy
pe), listeners); |
315 } | 329 } |
316 | 330 |
317 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate); | 331 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate); |
318 listenerObject->Set(v8String(isolate, "listener"), info.handler); | 332 createDataProperty(context, listenerObject, v8String(isolate, "listener"
), info.handler); |
319 listenerObject->Set(v8String(isolate, "useCapture"), v8::Boolean::New(is
olate, info.useCapture)); | 333 createDataProperty(context, listenerObject, v8String(isolate, "useCaptur
e"), v8::Boolean::New(isolate, info.useCapture)); |
320 listenerObject->Set(v8String(isolate, "passive"), v8::Boolean::New(isola
te, info.passive)); | 334 createDataProperty(context, listenerObject, v8String(isolate, "passive")
, v8::Boolean::New(isolate, info.passive)); |
321 listenerObject->Set(v8String(isolate, "type"), v8String(isolate, current
EventType)); | 335 createDataProperty(context, listenerObject, v8String(isolate, "type"), v
8String(isolate, currentEventType)); |
322 v8::Local<v8::Function> removeFunction; | 336 v8::Local<v8::Function> removeFunction; |
323 if (info.removeFunction.ToLocal(&removeFunction)) | 337 if (info.removeFunction.ToLocal(&removeFunction)) |
324 listenerObject->Set(v8String(isolate, "remove"), removeFunction); | 338 createDataProperty(context, listenerObject, v8String(isolate, "remov
e"), removeFunction); |
325 listeners->Set(outputIndex++, listenerObject); | 339 createDataPropertyInArray(context, listeners, outputIndex++, listenerObj
ect); |
326 } | 340 } |
327 info.GetReturnValue().Set(result); | 341 info.GetReturnValue().Set(result); |
328 } | 342 } |
329 | 343 |
330 void ThreadDebugger::consoleTime(const String16& title) | 344 void ThreadDebugger::consoleTime(const String16& title) |
331 { | 345 { |
332 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", String(title).utf8().data(),
this); | 346 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", String(title).utf8().data(),
this); |
333 } | 347 } |
334 | 348 |
335 void ThreadDebugger::consoleTimeEnd(const String16& title) | 349 void ThreadDebugger::consoleTimeEnd(const String16& title) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 { | 385 { |
372 for (size_t index = 0; index < m_timers.size(); ++index) { | 386 for (size_t index = 0; index < m_timers.size(); ++index) { |
373 if (m_timers[index].get() == timer) { | 387 if (m_timers[index].get() == timer) { |
374 m_timerCallbacks[index](m_timerData[index]); | 388 m_timerCallbacks[index](m_timerData[index]); |
375 return; | 389 return; |
376 } | 390 } |
377 } | 391 } |
378 } | 392 } |
379 | 393 |
380 } // namespace blink | 394 } // namespace blink |
OLD | NEW |