| 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/ScriptValue.h" | 7 #include "bindings/core/v8/ScriptValue.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 "core/inspector/ConsoleMessage.h" | 19 #include "core/inspector/ConsoleMessage.h" |
| 20 #include "core/inspector/InspectorDOMDebuggerAgent.h" | 20 #include "core/inspector/InspectorDOMDebuggerAgent.h" |
| 21 #include "core/inspector/InspectorTraceEvents.h" | 21 #include "core/inspector/InspectorTraceEvents.h" |
| 22 #include "core/inspector/ScriptArguments.h" | |
| 23 #include "platform/ScriptForbiddenScope.h" | 22 #include "platform/ScriptForbiddenScope.h" |
| 24 #include "wtf/CurrentTime.h" | 23 #include "wtf/CurrentTime.h" |
| 25 #include "wtf/OwnPtr.h" | 24 #include "wtf/OwnPtr.h" |
| 26 | 25 |
| 27 namespace blink { | 26 namespace blink { |
| 28 | 27 |
| 29 ThreadDebugger::ThreadDebugger(v8::Isolate* isolate) | 28 ThreadDebugger::ThreadDebugger(v8::Isolate* isolate) |
| 30 : m_isolate(isolate) | 29 : m_isolate(isolate) |
| 31 , m_debugger(V8Debugger::create(isolate, this)) | 30 , m_debugger(V8Debugger::create(isolate, this)) |
| 32 { | 31 { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 179 |
| 181 void ThreadDebugger::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info
) | 180 void ThreadDebugger::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info
) |
| 182 { | 181 { |
| 183 if (info.Length() < 1) | 182 if (info.Length() < 1) |
| 184 return; | 183 return; |
| 185 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern
al>::Cast(info.Data())->Value()); | 184 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern
al>::Cast(info.Data())->Value()); |
| 186 DCHECK(debugger); | 185 DCHECK(debugger); |
| 187 Event* event = V8Event::toImplWithTypeCheck(info.GetIsolate(), info[0]); | 186 Event* event = V8Event::toImplWithTypeCheck(info.GetIsolate(), info[0]); |
| 188 if (!event) | 187 if (!event) |
| 189 return; | 188 return; |
| 190 | 189 protocol::Vector<v8::Local<v8::Value>> arguments; |
| 191 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); | 190 arguments.append(v8String(info.GetIsolate(), event->type())); |
| 192 ScriptState* scriptState = ScriptState::from(context); | 191 arguments.append(info[0]); |
| 193 DCHECK(scriptState->contextIsValid()); | 192 debugger->debugger()->logToConsole(info.GetIsolate()->GetCurrentContext(), e
vent->type(), &arguments); |
| 194 Vector<ScriptValue> arguments = Vector<ScriptValue>({ | |
| 195 ScriptValue(scriptState, v8String(info.GetIsolate(), event->type())), | |
| 196 ScriptValue(scriptState, info[0]) | |
| 197 }); | |
| 198 | |
| 199 ConsoleMessage* consoleMessage = ConsoleMessage::createForConsoleAPI(LogMess
ageLevel, LogMessageType, event->type(), ScriptArguments::create(scriptState, ar
guments)); | |
| 200 debugger->reportMessageToConsole(context, consoleMessage); | |
| 201 } | 193 } |
| 202 | 194 |
| 203 v8::Local<v8::Function> ThreadDebugger::eventLogFunction() | 195 v8::Local<v8::Function> ThreadDebugger::eventLogFunction() |
| 204 { | 196 { |
| 205 if (m_eventLogFunction.IsEmpty()) | 197 if (m_eventLogFunction.IsEmpty()) |
| 206 m_eventLogFunction.Reset(m_isolate, v8::Function::New(m_isolate, logCall
back, v8::External::New(m_isolate, this))); | 198 m_eventLogFunction.Reset(m_isolate, v8::Function::New(m_isolate, logCall
back, v8::External::New(m_isolate, this))); |
| 207 return m_eventLogFunction.Get(m_isolate); | 199 return m_eventLogFunction.Get(m_isolate); |
| 208 } | 200 } |
| 209 | 201 |
| 210 static EventTarget* firstArgumentAsEventTarget(const v8::FunctionCallbackInfo<v8
::Value>& info) | 202 static EventTarget* firstArgumentAsEventTarget(const v8::FunctionCallbackInfo<v8
::Value>& info) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 if (info.Length() < 1) | 245 if (info.Length() < 1) |
| 254 return; | 246 return; |
| 255 | 247 |
| 256 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern
al>::Cast(info.Data())->Value()); | 248 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern
al>::Cast(info.Data())->Value()); |
| 257 DCHECK(debugger); | 249 DCHECK(debugger); |
| 258 v8::Isolate* isolate = info.GetIsolate(); | 250 v8::Isolate* isolate = info.GetIsolate(); |
| 259 | 251 |
| 260 V8EventListenerInfoList listenerInfo; | 252 V8EventListenerInfoList listenerInfo; |
| 261 // eventListeners call can produce message on ErrorEvent during lazy event l
istener compilation. | 253 // eventListeners call can produce message on ErrorEvent during lazy event l
istener compilation. |
| 262 debugger->muteWarningsAndDeprecations(); | 254 debugger->muteWarningsAndDeprecations(); |
| 255 debugger->debugger()->muteConsole(); |
| 263 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis
tenerInfo); | 256 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis
tenerInfo); |
| 257 debugger->debugger()->unmuteConsole(); |
| 264 debugger->unmuteWarningsAndDeprecations(); | 258 debugger->unmuteWarningsAndDeprecations(); |
| 265 | 259 |
| 266 v8::Local<v8::Object> result = v8::Object::New(isolate); | 260 v8::Local<v8::Object> result = v8::Object::New(isolate); |
| 267 AtomicString currentEventType; | 261 AtomicString currentEventType; |
| 268 v8::Local<v8::Array> listeners; | 262 v8::Local<v8::Array> listeners; |
| 269 size_t outputIndex = 0; | 263 size_t outputIndex = 0; |
| 270 for (auto& info : listenerInfo) { | 264 for (auto& info : listenerInfo) { |
| 271 if (currentEventType != info.eventType) { | 265 if (currentEventType != info.eventType) { |
| 272 currentEventType = info.eventType; | 266 currentEventType = info.eventType; |
| 273 listeners = v8::Array::New(isolate); | 267 listeners = v8::Array::New(isolate); |
| 274 outputIndex = 0; | 268 outputIndex = 0; |
| 275 result->Set(v8String(isolate, currentEventType), listeners); | 269 result->Set(v8String(isolate, currentEventType), listeners); |
| 276 } | 270 } |
| 277 | 271 |
| 278 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate); | 272 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate); |
| 279 listenerObject->Set(v8String(isolate, "listener"), info.handler); | 273 listenerObject->Set(v8String(isolate, "listener"), info.handler); |
| 280 listenerObject->Set(v8String(isolate, "useCapture"), v8::Boolean::New(is
olate, info.useCapture)); | 274 listenerObject->Set(v8String(isolate, "useCapture"), v8::Boolean::New(is
olate, info.useCapture)); |
| 281 listenerObject->Set(v8String(isolate, "passive"), v8::Boolean::New(isola
te, info.passive)); | 275 listenerObject->Set(v8String(isolate, "passive"), v8::Boolean::New(isola
te, info.passive)); |
| 282 listenerObject->Set(v8String(isolate, "type"), v8String(isolate, current
EventType)); | 276 listenerObject->Set(v8String(isolate, "type"), v8String(isolate, current
EventType)); |
| 283 v8::Local<v8::Function> removeFunction; | 277 v8::Local<v8::Function> removeFunction; |
| 284 if (info.removeFunction.ToLocal(&removeFunction)) | 278 if (info.removeFunction.ToLocal(&removeFunction)) |
| 285 listenerObject->Set(v8String(isolate, "remove"), removeFunction); | 279 listenerObject->Set(v8String(isolate, "remove"), removeFunction); |
| 286 listeners->Set(outputIndex++, listenerObject); | 280 listeners->Set(outputIndex++, listenerObject); |
| 287 } | 281 } |
| 288 info.GetReturnValue().Set(result); | 282 info.GetReturnValue().Set(result); |
| 289 } | 283 } |
| 290 | 284 |
| 291 void ThreadDebugger::reportMessageToConsole(v8::Local<v8::Context> context, Mess
ageType type, MessageLevel level, const String16& message, const v8::FunctionCal
lbackInfo<v8::Value>* arguments, unsigned skipArgumentCount) | |
| 292 { | |
| 293 ScriptState* scriptState = ScriptState::from(context); | |
| 294 ScriptArguments* scriptArguments = nullptr; | |
| 295 if (arguments && scriptState->contextIsValid()) | |
| 296 scriptArguments = ScriptArguments::create(scriptState, *arguments, skipA
rgumentCount); | |
| 297 String messageText = message; | |
| 298 if (messageText.isEmpty() && scriptArguments) | |
| 299 scriptArguments->getFirstArgumentAsString(messageText); | |
| 300 | |
| 301 reportMessageToConsole(context, ConsoleMessage::createForConsoleAPI(level, t
ype, messageText, scriptArguments)); | |
| 302 } | |
| 303 | |
| 304 void ThreadDebugger::consoleTime(const String16& title) | 285 void ThreadDebugger::consoleTime(const String16& title) |
| 305 { | 286 { |
| 306 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", String(title).utf8().data(),
this); | 287 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", String(title).utf8().data(),
this); |
| 307 } | 288 } |
| 308 | 289 |
| 309 void ThreadDebugger::consoleTimeEnd(const String16& title) | 290 void ThreadDebugger::consoleTimeEnd(const String16& title) |
| 310 { | 291 { |
| 311 TRACE_EVENT_COPY_ASYNC_END0("blink.console", String(title).utf8().data(), th
is); | 292 TRACE_EVENT_COPY_ASYNC_END0("blink.console", String(title).utf8().data(), th
is); |
| 312 } | 293 } |
| 313 | 294 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 { | 326 { |
| 346 for (size_t index = 0; index < m_timers.size(); ++index) { | 327 for (size_t index = 0; index < m_timers.size(); ++index) { |
| 347 if (m_timers[index] == timer) { | 328 if (m_timers[index] == timer) { |
| 348 m_timerCallbacks[index](m_timerData[index]); | 329 m_timerCallbacks[index](m_timerData[index]); |
| 349 return; | 330 return; |
| 350 } | 331 } |
| 351 } | 332 } |
| 352 } | 333 } |
| 353 | 334 |
| 354 } // namespace blink | 335 } // namespace blink |
| OLD | NEW |