| 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 12 matching lines...) Expand all Loading... |
| 23 #include "platform/ScriptForbiddenScope.h" | 23 #include "platform/ScriptForbiddenScope.h" |
| 24 #include "wtf/CurrentTime.h" | 24 #include "wtf/CurrentTime.h" |
| 25 #include "wtf/PtrUtil.h" | 25 #include "wtf/PtrUtil.h" |
| 26 #include <memory> | 26 #include <memory> |
| 27 | 27 |
| 28 namespace blink { | 28 namespace blink { |
| 29 | 29 |
| 30 ThreadDebugger::ThreadDebugger(v8::Isolate* isolate) | 30 ThreadDebugger::ThreadDebugger(v8::Isolate* isolate) |
| 31 : m_isolate(isolate) | 31 : m_isolate(isolate) |
| 32 , m_debugger(V8Debugger::create(isolate, this)) | 32 , m_debugger(V8Debugger::create(isolate, this)) |
| 33 , m_asyncInstrumentationEnabled(false) | |
| 34 { | 33 { |
| 35 } | 34 } |
| 36 | 35 |
| 37 ThreadDebugger::~ThreadDebugger() | 36 ThreadDebugger::~ThreadDebugger() |
| 38 { | 37 { |
| 39 } | 38 } |
| 40 | 39 |
| 41 // static | 40 // static |
| 42 ThreadDebugger* ThreadDebugger::from(v8::Isolate* isolate) | 41 ThreadDebugger* ThreadDebugger::from(v8::Isolate* isolate) |
| 43 { | 42 { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 66 } | 65 } |
| 67 | 66 |
| 68 void ThreadDebugger::idleFinished(v8::Isolate* isolate) | 67 void ThreadDebugger::idleFinished(v8::Isolate* isolate) |
| 69 { | 68 { |
| 70 if (ThreadDebugger* debugger = ThreadDebugger::from(isolate)) | 69 if (ThreadDebugger* debugger = ThreadDebugger::from(isolate)) |
| 71 debugger->debugger()->idleFinished(); | 70 debugger->debugger()->idleFinished(); |
| 72 } | 71 } |
| 73 | 72 |
| 74 void ThreadDebugger::asyncTaskScheduled(const String& operationName, void* task,
bool recurring) | 73 void ThreadDebugger::asyncTaskScheduled(const String& operationName, void* task,
bool recurring) |
| 75 { | 74 { |
| 76 if (m_asyncInstrumentationEnabled) | 75 m_debugger->asyncTaskScheduled(operationName, task, recurring); |
| 77 m_debugger->asyncTaskScheduled(operationName, task, recurring); | |
| 78 } | 76 } |
| 79 | 77 |
| 80 void ThreadDebugger::asyncTaskCanceled(void* task) | 78 void ThreadDebugger::asyncTaskCanceled(void* task) |
| 81 { | 79 { |
| 82 if (m_asyncInstrumentationEnabled) | 80 m_debugger->asyncTaskCanceled(task); |
| 83 m_debugger->asyncTaskCanceled(task); | |
| 84 } | 81 } |
| 85 | 82 |
| 86 void ThreadDebugger::allAsyncTasksCanceled() | 83 void ThreadDebugger::allAsyncTasksCanceled() |
| 87 { | 84 { |
| 88 if (m_asyncInstrumentationEnabled) | 85 m_debugger->allAsyncTasksCanceled(); |
| 89 m_debugger->allAsyncTasksCanceled(); | |
| 90 } | 86 } |
| 91 | 87 |
| 92 void ThreadDebugger::asyncTaskStarted(void* task) | 88 void ThreadDebugger::asyncTaskStarted(void* task) |
| 93 { | 89 { |
| 94 if (m_asyncInstrumentationEnabled) | 90 m_debugger->asyncTaskStarted(task); |
| 95 m_debugger->asyncTaskStarted(task); | |
| 96 } | 91 } |
| 97 | 92 |
| 98 void ThreadDebugger::asyncTaskFinished(void* task) | 93 void ThreadDebugger::asyncTaskFinished(void* task) |
| 99 { | 94 { |
| 100 if (m_asyncInstrumentationEnabled) | 95 m_debugger->asyncTaskFinished(task); |
| 101 m_debugger->asyncTaskFinished(task); | |
| 102 } | 96 } |
| 103 | 97 |
| 104 unsigned ThreadDebugger::promiseRejected(v8::Local<v8::Context> context, const S
tring16& errorMessage, v8::Local<v8::Value> exception, std::unique_ptr<SourceLoc
ation> location) | 98 unsigned ThreadDebugger::promiseRejected(v8::Local<v8::Context> context, const S
tring16& errorMessage, v8::Local<v8::Value> exception, std::unique_ptr<SourceLoc
ation> location) |
| 105 { | 99 { |
| 106 const String16 defaultMessage = "Uncaught (in promise)"; | 100 const String16 defaultMessage = "Uncaught (in promise)"; |
| 107 String16 message = errorMessage; | 101 String16 message = errorMessage; |
| 108 if (message.isEmpty()) | 102 if (message.isEmpty()) |
| 109 message = defaultMessage; | 103 message = defaultMessage; |
| 110 else if (message.startWith("Uncaught ")) | 104 else if (message.startWith("Uncaught ")) |
| 111 message = message.substring(0, 8) + " (in promise)" + message.substring(
8); | 105 message = message.substring(0, 8) + " (in promise)" + message.substring(
8); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 if (object->InternalFieldCount() < v8DefaultWrapperInternalFieldCount) | 155 if (object->InternalFieldCount() < v8DefaultWrapperInternalFieldCount) |
| 162 return true; | 156 return true; |
| 163 v8::Local<v8::Value> wrapper = object->GetInternalField(v8DOMWrapperObjectIn
dex); | 157 v8::Local<v8::Value> wrapper = object->GetInternalField(v8DOMWrapperObjectIn
dex); |
| 164 // Skip wrapper boilerplates which are like regular wrappers but don't have | 158 // Skip wrapper boilerplates which are like regular wrappers but don't have |
| 165 // native object. | 159 // native object. |
| 166 if (!wrapper.IsEmpty() && wrapper->IsUndefined()) | 160 if (!wrapper.IsEmpty() && wrapper->IsUndefined()) |
| 167 return false; | 161 return false; |
| 168 return true; | 162 return true; |
| 169 } | 163 } |
| 170 | 164 |
| 171 void ThreadDebugger::enableAsyncInstrumentation() | |
| 172 { | |
| 173 DCHECK(!m_asyncInstrumentationEnabled); | |
| 174 m_asyncInstrumentationEnabled = true; | |
| 175 } | |
| 176 | |
| 177 void ThreadDebugger::disableAsyncInstrumentation() | |
| 178 { | |
| 179 DCHECK(m_asyncInstrumentationEnabled); | |
| 180 m_asyncInstrumentationEnabled = false; | |
| 181 } | |
| 182 | |
| 183 static void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) | 165 static void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 184 { | 166 { |
| 185 info.GetReturnValue().Set(info.Data()); | 167 info.GetReturnValue().Set(info.Data()); |
| 186 } | 168 } |
| 187 | 169 |
| 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) | 170 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 { | 171 { |
| 190 v8::Local<v8::String> funcName = v8String(context->GetIsolate(), name); | 172 v8::Local<v8::String> funcName = v8String(context->GetIsolate(), name); |
| 191 v8::Local<v8::Function> func; | 173 v8::Local<v8::Function> func; |
| 192 if (!v8::Function::New(context, callback, data, 0, v8::ConstructorBehavior::
kThrow).ToLocal(&func)) | 174 if (!v8::Function::New(context, callback, data, 0, v8::ConstructorBehavior::
kThrow).ToLocal(&func)) |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 { | 359 { |
| 378 for (size_t index = 0; index < m_timers.size(); ++index) { | 360 for (size_t index = 0; index < m_timers.size(); ++index) { |
| 379 if (m_timers[index].get() == timer) { | 361 if (m_timers[index].get() == timer) { |
| 380 m_timerCallbacks[index](m_timerData[index]); | 362 m_timerCallbacks[index](m_timerData[index]); |
| 381 return; | 363 return; |
| 382 } | 364 } |
| 383 } | 365 } |
| 384 } | 366 } |
| 385 | 367 |
| 386 } // namespace blink | 368 } // namespace blink |
| OLD | NEW |