| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010-2011 Google Inc. All rights reserved. | 2 * Copyright (c) 2010-2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/v8_inspector/V8DebuggerImpl.h" | 31 #include "platform/v8_inspector/V8InspectorImpl.h" |
| 32 | 32 |
| 33 #include "platform/inspector_protocol/Values.h" | 33 #include "platform/inspector_protocol/Values.h" |
| 34 #include "platform/v8_inspector/Atomics.h" | 34 #include "platform/v8_inspector/Atomics.h" |
| 35 #include "platform/v8_inspector/DebuggerScript.h" | 35 #include "platform/v8_inspector/DebuggerScript.h" |
| 36 #include "platform/v8_inspector/InspectedContext.h" | 36 #include "platform/v8_inspector/InspectedContext.h" |
| 37 #include "platform/v8_inspector/ScriptBreakpoint.h" | 37 #include "platform/v8_inspector/ScriptBreakpoint.h" |
| 38 #include "platform/v8_inspector/V8Compat.h" | 38 #include "platform/v8_inspector/V8Compat.h" |
| 39 #include "platform/v8_inspector/V8ConsoleAgentImpl.h" | 39 #include "platform/v8_inspector/V8ConsoleAgentImpl.h" |
| 40 #include "platform/v8_inspector/V8ConsoleMessage.h" | 40 #include "platform/v8_inspector/V8ConsoleMessage.h" |
| 41 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" | 41 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" |
| 42 #include "platform/v8_inspector/V8InjectedScriptHost.h" | 42 #include "platform/v8_inspector/V8InjectedScriptHost.h" |
| 43 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 43 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
| 44 #include "platform/v8_inspector/V8InternalValueType.h" | 44 #include "platform/v8_inspector/V8InternalValueType.h" |
| 45 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" | 45 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" |
| 46 #include "platform/v8_inspector/V8StackTraceImpl.h" | 46 #include "platform/v8_inspector/V8StackTraceImpl.h" |
| 47 #include "platform/v8_inspector/V8StringUtil.h" | 47 #include "platform/v8_inspector/V8StringUtil.h" |
| 48 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 48 #include "platform/v8_inspector/public/V8InspectorClient.h" |
| 49 #include <v8-profiler.h> | 49 #include <v8-profiler.h> |
| 50 | 50 |
| 51 namespace blink { | 51 namespace blink { |
| 52 | 52 |
| 53 namespace { | 53 namespace { |
| 54 const char stepIntoV8MethodName[] = "stepIntoStatement"; | 54 const char stepIntoV8MethodName[] = "stepIntoStatement"; |
| 55 const char stepOutV8MethodName[] = "stepOutOfFunction"; | 55 const char stepOutV8MethodName[] = "stepOutOfFunction"; |
| 56 volatile int s_lastContextId = 0; | 56 volatile int s_lastContextId = 0; |
| 57 static const char v8AsyncTaskEventEnqueue[] = "enqueue"; | 57 static const char v8AsyncTaskEventEnqueue[] = "enqueue"; |
| 58 static const char v8AsyncTaskEventWillHandle[] = "willHandle"; | 58 static const char v8AsyncTaskEventWillHandle[] = "willHandle"; |
| 59 static const char v8AsyncTaskEventDidHandle[] = "didHandle"; | 59 static const char v8AsyncTaskEventDidHandle[] = "didHandle"; |
| 60 | 60 |
| 61 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) | 61 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) |
| 62 { | 62 { |
| 63 return value ? v8::True(isolate) : v8::False(isolate); | 63 return value ? v8::True(isolate) : v8::False(isolate); |
| 64 } | 64 } |
| 65 | 65 |
| 66 } | 66 } |
| 67 | 67 |
| 68 static bool inLiveEditScope = false; | 68 static bool inLiveEditScope = false; |
| 69 | 69 |
| 70 v8::MaybeLocal<v8::Value> V8DebuggerImpl::callDebuggerMethod(const char* functio
nName, int argc, v8::Local<v8::Value> argv[]) | 70 v8::MaybeLocal<v8::Value> V8InspectorImpl::callDebuggerMethod(const char* functi
onName, int argc, v8::Local<v8::Value> argv[]) |
| 71 { | 71 { |
| 72 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr
otasks); | 72 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr
otasks); |
| 73 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); | 73 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); |
| 74 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(debuggerScr
ipt->Get(v8InternalizedString(functionName))); | 74 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(debuggerScr
ipt->Get(v8InternalizedString(functionName))); |
| 75 DCHECK(m_isolate->InContext()); | 75 DCHECK(m_isolate->InContext()); |
| 76 return function->Call(m_isolate->GetCurrentContext(), debuggerScript, argc,
argv); | 76 return function->Call(m_isolate->GetCurrentContext(), debuggerScript, argc,
argv); |
| 77 } | 77 } |
| 78 | 78 |
| 79 std::unique_ptr<V8Debugger> V8Debugger::create(v8::Isolate* isolate, V8DebuggerC
lient* client) | 79 std::unique_ptr<V8Inspector> V8Inspector::create(v8::Isolate* isolate, V8Inspect
orClient* client) |
| 80 { | 80 { |
| 81 return wrapUnique(new V8DebuggerImpl(isolate, client)); | 81 return wrapUnique(new V8InspectorImpl(isolate, client)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 V8DebuggerImpl::V8DebuggerImpl(v8::Isolate* isolate, V8DebuggerClient* client) | 84 V8InspectorImpl::V8InspectorImpl(v8::Isolate* isolate, V8InspectorClient* client
) |
| 85 : m_isolate(isolate) | 85 : m_isolate(isolate) |
| 86 , m_client(client) | 86 , m_client(client) |
| 87 , m_capturingStackTracesCount(0) | 87 , m_capturingStackTracesCount(0) |
| 88 , m_lastExceptionId(0) | 88 , m_lastExceptionId(0) |
| 89 , m_enabledAgentsCount(0) | 89 , m_enabledAgentsCount(0) |
| 90 , m_breakpointsActivated(true) | 90 , m_breakpointsActivated(true) |
| 91 , m_runningNestedMessageLoop(false) | 91 , m_runningNestedMessageLoop(false) |
| 92 , m_maxAsyncCallStackDepth(0) | 92 , m_maxAsyncCallStackDepth(0) |
| 93 { | 93 { |
| 94 } | 94 } |
| 95 | 95 |
| 96 V8DebuggerImpl::~V8DebuggerImpl() | 96 V8InspectorImpl::~V8InspectorImpl() |
| 97 { | 97 { |
| 98 } | 98 } |
| 99 | 99 |
| 100 void V8DebuggerImpl::enable() | 100 void V8InspectorImpl::enable() |
| 101 { | 101 { |
| 102 DCHECK(!enabled()); | 102 DCHECK(!enabled()); |
| 103 v8::HandleScope scope(m_isolate); | 103 v8::HandleScope scope(m_isolate); |
| 104 v8::Debug::SetDebugEventListener(m_isolate, &V8DebuggerImpl::v8DebugEventCal
lback, v8::External::New(m_isolate, this)); | 104 v8::Debug::SetDebugEventListener(m_isolate, &V8InspectorImpl::v8DebugEventCa
llback, v8::External::New(m_isolate, this)); |
| 105 m_debuggerContext.Reset(m_isolate, v8::Debug::GetDebugContext(m_isolate)); | 105 m_debuggerContext.Reset(m_isolate, v8::Debug::GetDebugContext(m_isolate)); |
| 106 compileDebuggerScript(); | 106 compileDebuggerScript(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void V8DebuggerImpl::disable() | 109 void V8InspectorImpl::disable() |
| 110 { | 110 { |
| 111 DCHECK(enabled()); | 111 DCHECK(enabled()); |
| 112 clearBreakpoints(); | 112 clearBreakpoints(); |
| 113 m_debuggerScript.Reset(); | 113 m_debuggerScript.Reset(); |
| 114 m_debuggerContext.Reset(); | 114 m_debuggerContext.Reset(); |
| 115 allAsyncTasksCanceled(); | 115 allAsyncTasksCanceled(); |
| 116 v8::Debug::SetDebugEventListener(m_isolate, nullptr); | 116 v8::Debug::SetDebugEventListener(m_isolate, nullptr); |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool V8DebuggerImpl::enabled() const | 119 bool V8InspectorImpl::enabled() const |
| 120 { | 120 { |
| 121 return !m_debuggerScript.IsEmpty(); | 121 return !m_debuggerScript.IsEmpty(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // static | 124 // static |
| 125 int V8DebuggerImpl::contextId(v8::Local<v8::Context> context) | 125 int V8InspectorImpl::contextId(v8::Local<v8::Context> context) |
| 126 { | 126 { |
| 127 v8::Local<v8::Value> data = context->GetEmbedderData(static_cast<int>(v8::Co
ntext::kDebugIdIndex)); | 127 v8::Local<v8::Value> data = context->GetEmbedderData(static_cast<int>(v8::Co
ntext::kDebugIdIndex)); |
| 128 if (data.IsEmpty() || !data->IsString()) | 128 if (data.IsEmpty() || !data->IsString()) |
| 129 return 0; | 129 return 0; |
| 130 String16 dataString = toProtocolString(data.As<v8::String>()); | 130 String16 dataString = toProtocolString(data.As<v8::String>()); |
| 131 if (dataString.isEmpty()) | 131 if (dataString.isEmpty()) |
| 132 return 0; | 132 return 0; |
| 133 size_t commaPos = dataString.find(","); | 133 size_t commaPos = dataString.find(","); |
| 134 if (commaPos == kNotFound) | 134 if (commaPos == kNotFound) |
| 135 return 0; | 135 return 0; |
| 136 size_t commaPos2 = dataString.find(",", commaPos + 1); | 136 size_t commaPos2 = dataString.find(",", commaPos + 1); |
| 137 if (commaPos2 == kNotFound) | 137 if (commaPos2 == kNotFound) |
| 138 return 0; | 138 return 0; |
| 139 return dataString.substring(commaPos + 1, commaPos2 - commaPos - 1).toInt(); | 139 return dataString.substring(commaPos + 1, commaPos2 - commaPos - 1).toInt(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // static | 142 // static |
| 143 int V8DebuggerImpl::getGroupId(v8::Local<v8::Context> context) | 143 int V8InspectorImpl::getGroupId(v8::Local<v8::Context> context) |
| 144 { | 144 { |
| 145 v8::Local<v8::Value> data = context->GetEmbedderData(static_cast<int>(v8::Co
ntext::kDebugIdIndex)); | 145 v8::Local<v8::Value> data = context->GetEmbedderData(static_cast<int>(v8::Co
ntext::kDebugIdIndex)); |
| 146 if (data.IsEmpty() || !data->IsString()) | 146 if (data.IsEmpty() || !data->IsString()) |
| 147 return 0; | 147 return 0; |
| 148 String16 dataString = toProtocolString(data.As<v8::String>()); | 148 String16 dataString = toProtocolString(data.As<v8::String>()); |
| 149 if (dataString.isEmpty()) | 149 if (dataString.isEmpty()) |
| 150 return 0; | 150 return 0; |
| 151 size_t commaPos = dataString.find(","); | 151 size_t commaPos = dataString.find(","); |
| 152 if (commaPos == kNotFound) | 152 if (commaPos == kNotFound) |
| 153 return 0; | 153 return 0; |
| 154 return dataString.substring(0, commaPos).toInt(); | 154 return dataString.substring(0, commaPos).toInt(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void V8DebuggerImpl::debuggerAgentEnabled() | 157 void V8InspectorImpl::debuggerAgentEnabled() |
| 158 { | 158 { |
| 159 if (!m_enabledAgentsCount++) | 159 if (!m_enabledAgentsCount++) |
| 160 enable(); | 160 enable(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void V8DebuggerImpl::debuggerAgentDisabled() | 163 void V8InspectorImpl::debuggerAgentDisabled() |
| 164 { | 164 { |
| 165 if (!--m_enabledAgentsCount) | 165 if (!--m_enabledAgentsCount) |
| 166 disable(); | 166 disable(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 V8DebuggerAgentImpl* V8DebuggerImpl::findEnabledDebuggerAgent(int contextGroupId
) | 169 V8DebuggerAgentImpl* V8InspectorImpl::findEnabledDebuggerAgent(int contextGroupI
d) |
| 170 { | 170 { |
| 171 if (!contextGroupId) | 171 if (!contextGroupId) |
| 172 return nullptr; | 172 return nullptr; |
| 173 SessionMap::iterator it = m_sessions.find(contextGroupId); | 173 SessionMap::iterator it = m_sessions.find(contextGroupId); |
| 174 if (it == m_sessions.end()) | 174 if (it == m_sessions.end()) |
| 175 return nullptr; | 175 return nullptr; |
| 176 V8DebuggerAgentImpl* agent = it->second->debuggerAgent(); | 176 V8DebuggerAgentImpl* agent = it->second->debuggerAgent(); |
| 177 if (!agent->enabled()) | 177 if (!agent->enabled()) |
| 178 return nullptr; | 178 return nullptr; |
| 179 return agent; | 179 return agent; |
| 180 } | 180 } |
| 181 | 181 |
| 182 V8DebuggerAgentImpl* V8DebuggerImpl::findEnabledDebuggerAgent(v8::Local<v8::Cont
ext> context) | 182 V8DebuggerAgentImpl* V8InspectorImpl::findEnabledDebuggerAgent(v8::Local<v8::Con
text> context) |
| 183 { | 183 { |
| 184 return findEnabledDebuggerAgent(getGroupId(context)); | 184 return findEnabledDebuggerAgent(getGroupId(context)); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void V8DebuggerImpl::getCompiledScripts(int contextGroupId, std::vector<std::uni
que_ptr<V8DebuggerScript>>& result) | 187 void V8InspectorImpl::getCompiledScripts(int contextGroupId, std::vector<std::un
ique_ptr<V8DebuggerScript>>& result) |
| 188 { | 188 { |
| 189 v8::HandleScope scope(m_isolate); | 189 v8::HandleScope scope(m_isolate); |
| 190 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr
otasks); | 190 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr
otasks); |
| 191 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); | 191 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); |
| 192 DCHECK(!debuggerScript->IsUndefined()); | 192 DCHECK(!debuggerScript->IsUndefined()); |
| 193 v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast(d
ebuggerScript->Get(v8InternalizedString("getScripts"))); | 193 v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast(d
ebuggerScript->Get(v8InternalizedString("getScripts"))); |
| 194 v8::Local<v8::Value> argv[] = { v8::Integer::New(m_isolate, contextGroupId)
}; | 194 v8::Local<v8::Value> argv[] = { v8::Integer::New(m_isolate, contextGroupId)
}; |
| 195 v8::Local<v8::Value> value; | 195 v8::Local<v8::Value> value; |
| 196 if (!getScriptsFunction->Call(debuggerContext(), debuggerScript, PROTOCOL_AR
RAY_LENGTH(argv), argv).ToLocal(&value)) | 196 if (!getScriptsFunction->Call(debuggerContext(), debuggerScript, PROTOCOL_AR
RAY_LENGTH(argv), argv).ToLocal(&value)) |
| 197 return; | 197 return; |
| 198 DCHECK(value->IsArray()); | 198 DCHECK(value->IsArray()); |
| 199 v8::Local<v8::Array> scriptsArray = v8::Local<v8::Array>::Cast(value); | 199 v8::Local<v8::Array> scriptsArray = v8::Local<v8::Array>::Cast(value); |
| 200 result.reserve(scriptsArray->Length()); | 200 result.reserve(scriptsArray->Length()); |
| 201 for (unsigned i = 0; i < scriptsArray->Length(); ++i) { | 201 for (unsigned i = 0; i < scriptsArray->Length(); ++i) { |
| 202 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast(scripts
Array->Get(v8::Integer::New(m_isolate, i))); | 202 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast(scripts
Array->Get(v8::Integer::New(m_isolate, i))); |
| 203 result.push_back(wrapUnique(new V8DebuggerScript(m_isolate, scriptObject
, inLiveEditScope))); | 203 result.push_back(wrapUnique(new V8DebuggerScript(m_isolate, scriptObject
, inLiveEditScope))); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 String16 V8DebuggerImpl::setBreakpoint(const String16& sourceID, const ScriptBre
akpoint& scriptBreakpoint, int* actualLineNumber, int* actualColumnNumber, bool
interstatementLocation) | 207 String16 V8InspectorImpl::setBreakpoint(const String16& sourceID, const ScriptBr
eakpoint& scriptBreakpoint, int* actualLineNumber, int* actualColumnNumber, bool
interstatementLocation) |
| 208 { | 208 { |
| 209 v8::HandleScope scope(m_isolate); | 209 v8::HandleScope scope(m_isolate); |
| 210 v8::Context::Scope contextScope(debuggerContext()); | 210 v8::Context::Scope contextScope(debuggerContext()); |
| 211 | 211 |
| 212 v8::Local<v8::Object> info = v8::Object::New(m_isolate); | 212 v8::Local<v8::Object> info = v8::Object::New(m_isolate); |
| 213 info->Set(v8InternalizedString("sourceID"), toV8String(m_isolate, sourceID))
; | 213 info->Set(v8InternalizedString("sourceID"), toV8String(m_isolate, sourceID))
; |
| 214 info->Set(v8InternalizedString("lineNumber"), v8::Integer::New(m_isolate, sc
riptBreakpoint.lineNumber)); | 214 info->Set(v8InternalizedString("lineNumber"), v8::Integer::New(m_isolate, sc
riptBreakpoint.lineNumber)); |
| 215 info->Set(v8InternalizedString("columnNumber"), v8::Integer::New(m_isolate,
scriptBreakpoint.columnNumber)); | 215 info->Set(v8InternalizedString("columnNumber"), v8::Integer::New(m_isolate,
scriptBreakpoint.columnNumber)); |
| 216 info->Set(v8InternalizedString("interstatementLocation"), v8Boolean(intersta
tementLocation, m_isolate)); | 216 info->Set(v8InternalizedString("interstatementLocation"), v8Boolean(intersta
tementLocation, m_isolate)); |
| 217 info->Set(v8InternalizedString("condition"), toV8String(m_isolate, scriptBre
akpoint.condition)); | 217 info->Set(v8InternalizedString("condition"), toV8String(m_isolate, scriptBre
akpoint.condition)); |
| 218 | 218 |
| 219 v8::Local<v8::Function> setBreakpointFunction = v8::Local<v8::Function>::Cas
t(m_debuggerScript.Get(m_isolate)->Get(v8InternalizedString("setBreakpoint"))); | 219 v8::Local<v8::Function> setBreakpointFunction = v8::Local<v8::Function>::Cas
t(m_debuggerScript.Get(m_isolate)->Get(v8InternalizedString("setBreakpoint"))); |
| 220 v8::Local<v8::Value> breakpointId = v8::Debug::Call(debuggerContext(), setBr
eakpointFunction, info).ToLocalChecked(); | 220 v8::Local<v8::Value> breakpointId = v8::Debug::Call(debuggerContext(), setBr
eakpointFunction, info).ToLocalChecked(); |
| 221 if (!breakpointId->IsString()) | 221 if (!breakpointId->IsString()) |
| 222 return ""; | 222 return ""; |
| 223 *actualLineNumber = info->Get(v8InternalizedString("lineNumber"))->Int32Valu
e(); | 223 *actualLineNumber = info->Get(v8InternalizedString("lineNumber"))->Int32Valu
e(); |
| 224 *actualColumnNumber = info->Get(v8InternalizedString("columnNumber"))->Int32
Value(); | 224 *actualColumnNumber = info->Get(v8InternalizedString("columnNumber"))->Int32
Value(); |
| 225 return toProtocolString(breakpointId.As<v8::String>()); | 225 return toProtocolString(breakpointId.As<v8::String>()); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void V8DebuggerImpl::removeBreakpoint(const String16& breakpointId) | 228 void V8InspectorImpl::removeBreakpoint(const String16& breakpointId) |
| 229 { | 229 { |
| 230 v8::HandleScope scope(m_isolate); | 230 v8::HandleScope scope(m_isolate); |
| 231 v8::Context::Scope contextScope(debuggerContext()); | 231 v8::Context::Scope contextScope(debuggerContext()); |
| 232 | 232 |
| 233 v8::Local<v8::Object> info = v8::Object::New(m_isolate); | 233 v8::Local<v8::Object> info = v8::Object::New(m_isolate); |
| 234 info->Set(v8InternalizedString("breakpointId"), toV8String(m_isolate, breakp
ointId)); | 234 info->Set(v8InternalizedString("breakpointId"), toV8String(m_isolate, breakp
ointId)); |
| 235 | 235 |
| 236 v8::Local<v8::Function> removeBreakpointFunction = v8::Local<v8::Function>::
Cast(m_debuggerScript.Get(m_isolate)->Get(v8InternalizedString("removeBreakpoint
"))); | 236 v8::Local<v8::Function> removeBreakpointFunction = v8::Local<v8::Function>::
Cast(m_debuggerScript.Get(m_isolate)->Get(v8InternalizedString("removeBreakpoint
"))); |
| 237 v8::Debug::Call(debuggerContext(), removeBreakpointFunction, info).ToLocalCh
ecked(); | 237 v8::Debug::Call(debuggerContext(), removeBreakpointFunction, info).ToLocalCh
ecked(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void V8DebuggerImpl::clearBreakpoints() | 240 void V8InspectorImpl::clearBreakpoints() |
| 241 { | 241 { |
| 242 v8::HandleScope scope(m_isolate); | 242 v8::HandleScope scope(m_isolate); |
| 243 v8::Context::Scope contextScope(debuggerContext()); | 243 v8::Context::Scope contextScope(debuggerContext()); |
| 244 | 244 |
| 245 v8::Local<v8::Function> clearBreakpoints = v8::Local<v8::Function>::Cast(m_d
ebuggerScript.Get(m_isolate)->Get(v8InternalizedString("clearBreakpoints"))); | 245 v8::Local<v8::Function> clearBreakpoints = v8::Local<v8::Function>::Cast(m_d
ebuggerScript.Get(m_isolate)->Get(v8InternalizedString("clearBreakpoints"))); |
| 246 v8::Debug::Call(debuggerContext(), clearBreakpoints).ToLocalChecked(); | 246 v8::Debug::Call(debuggerContext(), clearBreakpoints).ToLocalChecked(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void V8DebuggerImpl::setBreakpointsActivated(bool activated) | 249 void V8InspectorImpl::setBreakpointsActivated(bool activated) |
| 250 { | 250 { |
| 251 if (!enabled()) { | 251 if (!enabled()) { |
| 252 NOTREACHED(); | 252 NOTREACHED(); |
| 253 return; | 253 return; |
| 254 } | 254 } |
| 255 v8::HandleScope scope(m_isolate); | 255 v8::HandleScope scope(m_isolate); |
| 256 v8::Context::Scope contextScope(debuggerContext()); | 256 v8::Context::Scope contextScope(debuggerContext()); |
| 257 | 257 |
| 258 v8::Local<v8::Object> info = v8::Object::New(m_isolate); | 258 v8::Local<v8::Object> info = v8::Object::New(m_isolate); |
| 259 info->Set(v8InternalizedString("enabled"), v8::Boolean::New(m_isolate, activ
ated)); | 259 info->Set(v8InternalizedString("enabled"), v8::Boolean::New(m_isolate, activ
ated)); |
| 260 v8::Local<v8::Function> setBreakpointsActivated = v8::Local<v8::Function>::C
ast(m_debuggerScript.Get(m_isolate)->Get(v8InternalizedString("setBreakpointsAct
ivated"))); | 260 v8::Local<v8::Function> setBreakpointsActivated = v8::Local<v8::Function>::C
ast(m_debuggerScript.Get(m_isolate)->Get(v8InternalizedString("setBreakpointsAct
ivated"))); |
| 261 v8::Debug::Call(debuggerContext(), setBreakpointsActivated, info).ToLocalChe
cked(); | 261 v8::Debug::Call(debuggerContext(), setBreakpointsActivated, info).ToLocalChe
cked(); |
| 262 | 262 |
| 263 m_breakpointsActivated = activated; | 263 m_breakpointsActivated = activated; |
| 264 } | 264 } |
| 265 | 265 |
| 266 V8DebuggerImpl::PauseOnExceptionsState V8DebuggerImpl::getPauseOnExceptionsState
() | 266 V8InspectorImpl::PauseOnExceptionsState V8InspectorImpl::getPauseOnExceptionsSta
te() |
| 267 { | 267 { |
| 268 DCHECK(enabled()); | 268 DCHECK(enabled()); |
| 269 v8::HandleScope scope(m_isolate); | 269 v8::HandleScope scope(m_isolate); |
| 270 v8::Context::Scope contextScope(debuggerContext()); | 270 v8::Context::Scope contextScope(debuggerContext()); |
| 271 | 271 |
| 272 v8::Local<v8::Value> argv[] = { v8::Undefined(m_isolate) }; | 272 v8::Local<v8::Value> argv[] = { v8::Undefined(m_isolate) }; |
| 273 v8::Local<v8::Value> result = callDebuggerMethod("pauseOnExceptionsState", 0
, argv).ToLocalChecked(); | 273 v8::Local<v8::Value> result = callDebuggerMethod("pauseOnExceptionsState", 0
, argv).ToLocalChecked(); |
| 274 return static_cast<V8DebuggerImpl::PauseOnExceptionsState>(result->Int32Valu
e()); | 274 return static_cast<V8InspectorImpl::PauseOnExceptionsState>(result->Int32Val
ue()); |
| 275 } | 275 } |
| 276 | 276 |
| 277 void V8DebuggerImpl::setPauseOnExceptionsState(PauseOnExceptionsState pauseOnExc
eptionsState) | 277 void V8InspectorImpl::setPauseOnExceptionsState(PauseOnExceptionsState pauseOnEx
ceptionsState) |
| 278 { | 278 { |
| 279 DCHECK(enabled()); | 279 DCHECK(enabled()); |
| 280 v8::HandleScope scope(m_isolate); | 280 v8::HandleScope scope(m_isolate); |
| 281 v8::Context::Scope contextScope(debuggerContext()); | 281 v8::Context::Scope contextScope(debuggerContext()); |
| 282 | 282 |
| 283 v8::Local<v8::Value> argv[] = { v8::Int32::New(m_isolate, pauseOnExceptionsS
tate) }; | 283 v8::Local<v8::Value> argv[] = { v8::Int32::New(m_isolate, pauseOnExceptionsS
tate) }; |
| 284 callDebuggerMethod("setPauseOnExceptionsState", 1, argv); | 284 callDebuggerMethod("setPauseOnExceptionsState", 1, argv); |
| 285 } | 285 } |
| 286 | 286 |
| 287 void V8DebuggerImpl::setPauseOnNextStatement(bool pause) | 287 void V8InspectorImpl::setPauseOnNextStatement(bool pause) |
| 288 { | 288 { |
| 289 if (m_runningNestedMessageLoop) | 289 if (m_runningNestedMessageLoop) |
| 290 return; | 290 return; |
| 291 if (pause) | 291 if (pause) |
| 292 v8::Debug::DebugBreak(m_isolate); | 292 v8::Debug::DebugBreak(m_isolate); |
| 293 else | 293 else |
| 294 v8::Debug::CancelDebugBreak(m_isolate); | 294 v8::Debug::CancelDebugBreak(m_isolate); |
| 295 } | 295 } |
| 296 | 296 |
| 297 bool V8DebuggerImpl::canBreakProgram() | 297 bool V8InspectorImpl::canBreakProgram() |
| 298 { | 298 { |
| 299 if (!m_breakpointsActivated) | 299 if (!m_breakpointsActivated) |
| 300 return false; | 300 return false; |
| 301 return m_isolate->InContext(); | 301 return m_isolate->InContext(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 void V8DebuggerImpl::breakProgram() | 304 void V8InspectorImpl::breakProgram() |
| 305 { | 305 { |
| 306 if (isPaused()) { | 306 if (isPaused()) { |
| 307 DCHECK(!m_runningNestedMessageLoop); | 307 DCHECK(!m_runningNestedMessageLoop); |
| 308 v8::Local<v8::Value> exception; | 308 v8::Local<v8::Value> exception; |
| 309 v8::Local<v8::Array> hitBreakpoints; | 309 v8::Local<v8::Array> hitBreakpoints; |
| 310 handleProgramBreak(m_pausedContext, m_executionState, exception, hitBrea
kpoints); | 310 handleProgramBreak(m_pausedContext, m_executionState, exception, hitBrea
kpoints); |
| 311 return; | 311 return; |
| 312 } | 312 } |
| 313 | 313 |
| 314 if (!canBreakProgram()) | 314 if (!canBreakProgram()) |
| 315 return; | 315 return; |
| 316 | 316 |
| 317 v8::HandleScope scope(m_isolate); | 317 v8::HandleScope scope(m_isolate); |
| 318 v8::Local<v8::Function> breakFunction; | 318 v8::Local<v8::Function> breakFunction; |
| 319 if (!v8::Function::New(m_isolate->GetCurrentContext(), &V8DebuggerImpl::brea
kProgramCallback, v8::External::New(m_isolate, this), 0, v8::ConstructorBehavior
::kThrow).ToLocal(&breakFunction)) | 319 if (!v8::Function::New(m_isolate->GetCurrentContext(), &V8InspectorImpl::bre
akProgramCallback, v8::External::New(m_isolate, this), 0, v8::ConstructorBehavio
r::kThrow).ToLocal(&breakFunction)) |
| 320 return; | 320 return; |
| 321 v8::Debug::Call(debuggerContext(), breakFunction).ToLocalChecked(); | 321 v8::Debug::Call(debuggerContext(), breakFunction).ToLocalChecked(); |
| 322 } | 322 } |
| 323 | 323 |
| 324 void V8DebuggerImpl::continueProgram() | 324 void V8InspectorImpl::continueProgram() |
| 325 { | 325 { |
| 326 if (isPaused()) | 326 if (isPaused()) |
| 327 m_client->quitMessageLoopOnPause(); | 327 m_client->quitMessageLoopOnPause(); |
| 328 m_pausedContext.Clear(); | 328 m_pausedContext.Clear(); |
| 329 m_executionState.Clear(); | 329 m_executionState.Clear(); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void V8DebuggerImpl::stepIntoStatement() | 332 void V8InspectorImpl::stepIntoStatement() |
| 333 { | 333 { |
| 334 DCHECK(isPaused()); | 334 DCHECK(isPaused()); |
| 335 DCHECK(!m_executionState.IsEmpty()); | 335 DCHECK(!m_executionState.IsEmpty()); |
| 336 v8::HandleScope handleScope(m_isolate); | 336 v8::HandleScope handleScope(m_isolate); |
| 337 v8::Local<v8::Value> argv[] = { m_executionState }; | 337 v8::Local<v8::Value> argv[] = { m_executionState }; |
| 338 callDebuggerMethod(stepIntoV8MethodName, 1, argv); | 338 callDebuggerMethod(stepIntoV8MethodName, 1, argv); |
| 339 continueProgram(); | 339 continueProgram(); |
| 340 } | 340 } |
| 341 | 341 |
| 342 void V8DebuggerImpl::stepOverStatement() | 342 void V8InspectorImpl::stepOverStatement() |
| 343 { | 343 { |
| 344 DCHECK(isPaused()); | 344 DCHECK(isPaused()); |
| 345 DCHECK(!m_executionState.IsEmpty()); | 345 DCHECK(!m_executionState.IsEmpty()); |
| 346 v8::HandleScope handleScope(m_isolate); | 346 v8::HandleScope handleScope(m_isolate); |
| 347 v8::Local<v8::Value> argv[] = { m_executionState }; | 347 v8::Local<v8::Value> argv[] = { m_executionState }; |
| 348 callDebuggerMethod("stepOverStatement", 1, argv); | 348 callDebuggerMethod("stepOverStatement", 1, argv); |
| 349 continueProgram(); | 349 continueProgram(); |
| 350 } | 350 } |
| 351 | 351 |
| 352 void V8DebuggerImpl::stepOutOfFunction() | 352 void V8InspectorImpl::stepOutOfFunction() |
| 353 { | 353 { |
| 354 DCHECK(isPaused()); | 354 DCHECK(isPaused()); |
| 355 DCHECK(!m_executionState.IsEmpty()); | 355 DCHECK(!m_executionState.IsEmpty()); |
| 356 v8::HandleScope handleScope(m_isolate); | 356 v8::HandleScope handleScope(m_isolate); |
| 357 v8::Local<v8::Value> argv[] = { m_executionState }; | 357 v8::Local<v8::Value> argv[] = { m_executionState }; |
| 358 callDebuggerMethod(stepOutV8MethodName, 1, argv); | 358 callDebuggerMethod(stepOutV8MethodName, 1, argv); |
| 359 continueProgram(); | 359 continueProgram(); |
| 360 } | 360 } |
| 361 | 361 |
| 362 void V8DebuggerImpl::clearStepping() | 362 void V8InspectorImpl::clearStepping() |
| 363 { | 363 { |
| 364 DCHECK(enabled()); | 364 DCHECK(enabled()); |
| 365 v8::HandleScope scope(m_isolate); | 365 v8::HandleScope scope(m_isolate); |
| 366 v8::Context::Scope contextScope(debuggerContext()); | 366 v8::Context::Scope contextScope(debuggerContext()); |
| 367 | 367 |
| 368 v8::Local<v8::Value> argv[] = { v8::Undefined(m_isolate) }; | 368 v8::Local<v8::Value> argv[] = { v8::Undefined(m_isolate) }; |
| 369 callDebuggerMethod("clearStepping", 0, argv); | 369 callDebuggerMethod("clearStepping", 0, argv); |
| 370 } | 370 } |
| 371 | 371 |
| 372 bool V8DebuggerImpl::setScriptSource(const String16& sourceID, v8::Local<v8::Str
ing> newSource, bool preview, ErrorString* error, Maybe<protocol::Runtime::Excep
tionDetails>* exceptionDetails, JavaScriptCallFrames* newCallFrames, Maybe<bool>
* stackChanged) | 372 bool V8InspectorImpl::setScriptSource(const String16& sourceID, v8::Local<v8::St
ring> newSource, bool preview, ErrorString* error, Maybe<protocol::Runtime::Exce
ptionDetails>* exceptionDetails, JavaScriptCallFrames* newCallFrames, Maybe<bool
>* stackChanged) |
| 373 { | 373 { |
| 374 class EnableLiveEditScope { | 374 class EnableLiveEditScope { |
| 375 public: | 375 public: |
| 376 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) | 376 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) |
| 377 { | 377 { |
| 378 v8::Debug::SetLiveEditEnabled(m_isolate, true); | 378 v8::Debug::SetLiveEditEnabled(m_isolate, true); |
| 379 inLiveEditScope = true; | 379 inLiveEditScope = true; |
| 380 } | 380 } |
| 381 ~EnableLiveEditScope() | 381 ~EnableLiveEditScope() |
| 382 { | 382 { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 .setScriptId(String16("0")) | 434 .setScriptId(String16("0")) |
| 435 .setLineNumber(resultTuple->Get(3)->ToInteger(m_isolate)->Value(
) - 1) | 435 .setLineNumber(resultTuple->Get(3)->ToInteger(m_isolate)->Value(
) - 1) |
| 436 .setColumnNumber(resultTuple->Get(4)->ToInteger(m_isolate)->Valu
e() - 1).build(); | 436 .setColumnNumber(resultTuple->Get(4)->ToInteger(m_isolate)->Valu
e() - 1).build(); |
| 437 return false; | 437 return false; |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 *error = "Unknown error."; | 440 *error = "Unknown error."; |
| 441 return false; | 441 return false; |
| 442 } | 442 } |
| 443 | 443 |
| 444 JavaScriptCallFrames V8DebuggerImpl::currentCallFrames(int limit) | 444 JavaScriptCallFrames V8InspectorImpl::currentCallFrames(int limit) |
| 445 { | 445 { |
| 446 if (!m_isolate->InContext()) | 446 if (!m_isolate->InContext()) |
| 447 return JavaScriptCallFrames(); | 447 return JavaScriptCallFrames(); |
| 448 v8::Local<v8::Value> currentCallFramesV8; | 448 v8::Local<v8::Value> currentCallFramesV8; |
| 449 if (m_executionState.IsEmpty()) { | 449 if (m_executionState.IsEmpty()) { |
| 450 v8::Local<v8::Function> currentCallFramesFunction = v8::Local<v8::Functi
on>::Cast(m_debuggerScript.Get(m_isolate)->Get(v8InternalizedString("currentCall
Frames"))); | 450 v8::Local<v8::Function> currentCallFramesFunction = v8::Local<v8::Functi
on>::Cast(m_debuggerScript.Get(m_isolate)->Get(v8InternalizedString("currentCall
Frames"))); |
| 451 currentCallFramesV8 = v8::Debug::Call(debuggerContext(), currentCallFram
esFunction, v8::Integer::New(m_isolate, limit)).ToLocalChecked(); | 451 currentCallFramesV8 = v8::Debug::Call(debuggerContext(), currentCallFram
esFunction, v8::Integer::New(m_isolate, limit)).ToLocalChecked(); |
| 452 } else { | 452 } else { |
| 453 v8::Local<v8::Value> argv[] = { m_executionState, v8::Integer::New(m_iso
late, limit) }; | 453 v8::Local<v8::Value> argv[] = { m_executionState, v8::Integer::New(m_iso
late, limit) }; |
| 454 currentCallFramesV8 = callDebuggerMethod("currentCallFrames", PROTOCOL_A
RRAY_LENGTH(argv), argv).ToLocalChecked(); | 454 currentCallFramesV8 = callDebuggerMethod("currentCallFrames", PROTOCOL_A
RRAY_LENGTH(argv), argv).ToLocalChecked(); |
| 455 } | 455 } |
| 456 DCHECK(!currentCallFramesV8.IsEmpty()); | 456 DCHECK(!currentCallFramesV8.IsEmpty()); |
| 457 if (!currentCallFramesV8->IsArray()) | 457 if (!currentCallFramesV8->IsArray()) |
| 458 return JavaScriptCallFrames(); | 458 return JavaScriptCallFrames(); |
| 459 v8::Local<v8::Array> callFramesArray = currentCallFramesV8.As<v8::Array>(); | 459 v8::Local<v8::Array> callFramesArray = currentCallFramesV8.As<v8::Array>(); |
| 460 JavaScriptCallFrames callFrames; | 460 JavaScriptCallFrames callFrames; |
| 461 for (size_t i = 0; i < callFramesArray->Length(); ++i) { | 461 for (size_t i = 0; i < callFramesArray->Length(); ++i) { |
| 462 v8::Local<v8::Value> callFrameValue; | 462 v8::Local<v8::Value> callFrameValue; |
| 463 if (!callFramesArray->Get(debuggerContext(), i).ToLocal(&callFrameValue)
) | 463 if (!callFramesArray->Get(debuggerContext(), i).ToLocal(&callFrameValue)
) |
| 464 return JavaScriptCallFrames(); | 464 return JavaScriptCallFrames(); |
| 465 if (!callFrameValue->IsObject()) | 465 if (!callFrameValue->IsObject()) |
| 466 return JavaScriptCallFrames(); | 466 return JavaScriptCallFrames(); |
| 467 v8::Local<v8::Object> callFrameObject = callFrameValue.As<v8::Object>(); | 467 v8::Local<v8::Object> callFrameObject = callFrameValue.As<v8::Object>(); |
| 468 callFrames.push_back(JavaScriptCallFrame::create(debuggerContext(), v8::
Local<v8::Object>::Cast(callFrameObject))); | 468 callFrames.push_back(JavaScriptCallFrame::create(debuggerContext(), v8::
Local<v8::Object>::Cast(callFrameObject))); |
| 469 } | 469 } |
| 470 return callFrames; | 470 return callFrames; |
| 471 } | 471 } |
| 472 | 472 |
| 473 static V8DebuggerImpl* toV8DebuggerImpl(v8::Local<v8::Value> data) | 473 static V8InspectorImpl* toV8InspectorImpl(v8::Local<v8::Value> data) |
| 474 { | 474 { |
| 475 void* p = v8::Local<v8::External>::Cast(data)->Value(); | 475 void* p = v8::Local<v8::External>::Cast(data)->Value(); |
| 476 return static_cast<V8DebuggerImpl*>(p); | 476 return static_cast<V8InspectorImpl*>(p); |
| 477 } | 477 } |
| 478 | 478 |
| 479 void V8DebuggerImpl::breakProgramCallback(const v8::FunctionCallbackInfo<v8::Val
ue>& info) | 479 void V8InspectorImpl::breakProgramCallback(const v8::FunctionCallbackInfo<v8::Va
lue>& info) |
| 480 { | 480 { |
| 481 DCHECK_EQ(info.Length(), 2); | 481 DCHECK_EQ(info.Length(), 2); |
| 482 V8DebuggerImpl* thisPtr = toV8DebuggerImpl(info.Data()); | 482 V8InspectorImpl* thisPtr = toV8InspectorImpl(info.Data()); |
| 483 if (!thisPtr->enabled()) | 483 if (!thisPtr->enabled()) |
| 484 return; | 484 return; |
| 485 v8::Local<v8::Context> pausedContext = thisPtr->m_isolate->GetCurrentContext
(); | 485 v8::Local<v8::Context> pausedContext = thisPtr->m_isolate->GetCurrentContext
(); |
| 486 v8::Local<v8::Value> exception; | 486 v8::Local<v8::Value> exception; |
| 487 v8::Local<v8::Array> hitBreakpoints; | 487 v8::Local<v8::Array> hitBreakpoints; |
| 488 thisPtr->handleProgramBreak(pausedContext, v8::Local<v8::Object>::Cast(info[
0]), exception, hitBreakpoints); | 488 thisPtr->handleProgramBreak(pausedContext, v8::Local<v8::Object>::Cast(info[
0]), exception, hitBreakpoints); |
| 489 } | 489 } |
| 490 | 490 |
| 491 void V8DebuggerImpl::handleProgramBreak(v8::Local<v8::Context> pausedContext, v8
::Local<v8::Object> executionState, v8::Local<v8::Value> exception, v8::Local<v8
::Array> hitBreakpointNumbers, bool isPromiseRejection) | 491 void V8InspectorImpl::handleProgramBreak(v8::Local<v8::Context> pausedContext, v
8::Local<v8::Object> executionState, v8::Local<v8::Value> exception, v8::Local<v
8::Array> hitBreakpointNumbers, bool isPromiseRejection) |
| 492 { | 492 { |
| 493 // Don't allow nested breaks. | 493 // Don't allow nested breaks. |
| 494 if (m_runningNestedMessageLoop) | 494 if (m_runningNestedMessageLoop) |
| 495 return; | 495 return; |
| 496 | 496 |
| 497 V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(pausedContext); | 497 V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(pausedContext); |
| 498 if (!agent) | 498 if (!agent) |
| 499 return; | 499 return; |
| 500 | 500 |
| 501 std::vector<String16> breakpointIds; | 501 std::vector<String16> breakpointIds; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 530 callDebuggerMethod("stepFrameStatement", 1, argv); | 530 callDebuggerMethod("stepFrameStatement", 1, argv); |
| 531 } else if (result == V8DebuggerAgentImpl::RequestStepInto) { | 531 } else if (result == V8DebuggerAgentImpl::RequestStepInto) { |
| 532 v8::Local<v8::Value> argv[] = { executionState }; | 532 v8::Local<v8::Value> argv[] = { executionState }; |
| 533 callDebuggerMethod(stepIntoV8MethodName, 1, argv); | 533 callDebuggerMethod(stepIntoV8MethodName, 1, argv); |
| 534 } else if (result == V8DebuggerAgentImpl::RequestStepOut) { | 534 } else if (result == V8DebuggerAgentImpl::RequestStepOut) { |
| 535 v8::Local<v8::Value> argv[] = { executionState }; | 535 v8::Local<v8::Value> argv[] = { executionState }; |
| 536 callDebuggerMethod(stepOutV8MethodName, 1, argv); | 536 callDebuggerMethod(stepOutV8MethodName, 1, argv); |
| 537 } | 537 } |
| 538 } | 538 } |
| 539 | 539 |
| 540 void V8DebuggerImpl::v8DebugEventCallback(const v8::Debug::EventDetails& eventDe
tails) | 540 void V8InspectorImpl::v8DebugEventCallback(const v8::Debug::EventDetails& eventD
etails) |
| 541 { | 541 { |
| 542 V8DebuggerImpl* thisPtr = toV8DebuggerImpl(eventDetails.GetCallbackData()); | 542 V8InspectorImpl* thisPtr = toV8InspectorImpl(eventDetails.GetCallbackData())
; |
| 543 thisPtr->handleV8DebugEvent(eventDetails); | 543 thisPtr->handleV8DebugEvent(eventDetails); |
| 544 } | 544 } |
| 545 | 545 |
| 546 v8::Local<v8::Value> V8DebuggerImpl::callInternalGetterFunction(v8::Local<v8::Ob
ject> object, const char* functionName) | 546 v8::Local<v8::Value> V8InspectorImpl::callInternalGetterFunction(v8::Local<v8::O
bject> object, const char* functionName) |
| 547 { | 547 { |
| 548 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr
otasks); | 548 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr
otasks); |
| 549 v8::Local<v8::Value> getterValue = object->Get(v8InternalizedString(function
Name)); | 549 v8::Local<v8::Value> getterValue = object->Get(v8InternalizedString(function
Name)); |
| 550 DCHECK(!getterValue.IsEmpty() && getterValue->IsFunction()); | 550 DCHECK(!getterValue.IsEmpty() && getterValue->IsFunction()); |
| 551 return v8::Local<v8::Function>::Cast(getterValue)->Call(m_isolate->GetCurren
tContext(), object, 0, 0).ToLocalChecked(); | 551 return v8::Local<v8::Function>::Cast(getterValue)->Call(m_isolate->GetCurren
tContext(), object, 0, 0).ToLocalChecked(); |
| 552 } | 552 } |
| 553 | 553 |
| 554 void V8DebuggerImpl::handleV8DebugEvent(const v8::Debug::EventDetails& eventDeta
ils) | 554 void V8InspectorImpl::handleV8DebugEvent(const v8::Debug::EventDetails& eventDet
ails) |
| 555 { | 555 { |
| 556 if (!enabled()) | 556 if (!enabled()) |
| 557 return; | 557 return; |
| 558 v8::DebugEvent event = eventDetails.GetEvent(); | 558 v8::DebugEvent event = eventDetails.GetEvent(); |
| 559 if (event != v8::AsyncTaskEvent && event != v8::Break && event != v8::Except
ion && event != v8::AfterCompile && event != v8::BeforeCompile && event != v8::C
ompileError) | 559 if (event != v8::AsyncTaskEvent && event != v8::Break && event != v8::Except
ion && event != v8::AfterCompile && event != v8::BeforeCompile && event != v8::C
ompileError) |
| 560 return; | 560 return; |
| 561 | 561 |
| 562 v8::Local<v8::Context> eventContext = eventDetails.GetEventContext(); | 562 v8::Local<v8::Context> eventContext = eventDetails.GetEventContext(); |
| 563 DCHECK(!eventContext.IsEmpty()); | 563 DCHECK(!eventContext.IsEmpty()); |
| 564 | 564 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 586 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), e
xception, v8::Local<v8::Array>(), isPromiseRejection); | 586 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), e
xception, v8::Local<v8::Array>(), isPromiseRejection); |
| 587 } else if (event == v8::Break) { | 587 } else if (event == v8::Break) { |
| 588 v8::Local<v8::Value> argv[] = { eventDetails.GetEventData() }; | 588 v8::Local<v8::Value> argv[] = { eventDetails.GetEventData() }; |
| 589 v8::Local<v8::Value> hitBreakpoints = callDebuggerMethod("getBreakpo
intNumbers", 1, argv).ToLocalChecked(); | 589 v8::Local<v8::Value> hitBreakpoints = callDebuggerMethod("getBreakpo
intNumbers", 1, argv).ToLocalChecked(); |
| 590 DCHECK(hitBreakpoints->IsArray()); | 590 DCHECK(hitBreakpoints->IsArray()); |
| 591 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), v
8::Local<v8::Value>(), hitBreakpoints.As<v8::Array>()); | 591 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), v
8::Local<v8::Value>(), hitBreakpoints.As<v8::Array>()); |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 } | 594 } |
| 595 | 595 |
| 596 void V8DebuggerImpl::handleV8AsyncTaskEvent(v8::Local<v8::Context> context, v8::
Local<v8::Object> executionState, v8::Local<v8::Object> eventData) | 596 void V8InspectorImpl::handleV8AsyncTaskEvent(v8::Local<v8::Context> context, v8:
:Local<v8::Object> executionState, v8::Local<v8::Object> eventData) |
| 597 { | 597 { |
| 598 if (!m_maxAsyncCallStackDepth) | 598 if (!m_maxAsyncCallStackDepth) |
| 599 return; | 599 return; |
| 600 | 600 |
| 601 String16 type = toProtocolStringWithTypeCheck(callInternalGetterFunction(eve
ntData, "type")); | 601 String16 type = toProtocolStringWithTypeCheck(callInternalGetterFunction(eve
ntData, "type")); |
| 602 String16 name = toProtocolStringWithTypeCheck(callInternalGetterFunction(eve
ntData, "name")); | 602 String16 name = toProtocolStringWithTypeCheck(callInternalGetterFunction(eve
ntData, "name")); |
| 603 int id = callInternalGetterFunction(eventData, "id")->ToInteger(m_isolate)->
Value(); | 603 int id = callInternalGetterFunction(eventData, "id")->ToInteger(m_isolate)->
Value(); |
| 604 // The scopes for the ids are defined by the eventData.name namespaces. Ther
e are currently two namespaces: "Object." and "Promise.". | 604 // The scopes for the ids are defined by the eventData.name namespaces. Ther
e are currently two namespaces: "Object." and "Promise.". |
| 605 void* ptr = reinterpret_cast<void*>(id * 4 + (name[0] == 'P' ? 2 : 0) + 1); | 605 void* ptr = reinterpret_cast<void*>(id * 4 + (name[0] == 'P' ? 2 : 0) + 1); |
| 606 if (type == v8AsyncTaskEventEnqueue) | 606 if (type == v8AsyncTaskEventEnqueue) |
| 607 asyncTaskScheduled(name, ptr, false); | 607 asyncTaskScheduled(name, ptr, false); |
| 608 else if (type == v8AsyncTaskEventWillHandle) | 608 else if (type == v8AsyncTaskEventWillHandle) |
| 609 asyncTaskStarted(ptr); | 609 asyncTaskStarted(ptr); |
| 610 else if (type == v8AsyncTaskEventDidHandle) | 610 else if (type == v8AsyncTaskEventDidHandle) |
| 611 asyncTaskFinished(ptr); | 611 asyncTaskFinished(ptr); |
| 612 else | 612 else |
| 613 NOTREACHED(); | 613 NOTREACHED(); |
| 614 } | 614 } |
| 615 | 615 |
| 616 V8StackTraceImpl* V8DebuggerImpl::currentAsyncCallChain() | 616 V8StackTraceImpl* V8InspectorImpl::currentAsyncCallChain() |
| 617 { | 617 { |
| 618 if (!m_currentStacks.size()) | 618 if (!m_currentStacks.size()) |
| 619 return nullptr; | 619 return nullptr; |
| 620 return m_currentStacks.back().get(); | 620 return m_currentStacks.back().get(); |
| 621 } | 621 } |
| 622 | 622 |
| 623 void V8DebuggerImpl::compileDebuggerScript() | 623 void V8InspectorImpl::compileDebuggerScript() |
| 624 { | 624 { |
| 625 if (!m_debuggerScript.IsEmpty()) { | 625 if (!m_debuggerScript.IsEmpty()) { |
| 626 NOTREACHED(); | 626 NOTREACHED(); |
| 627 return; | 627 return; |
| 628 } | 628 } |
| 629 | 629 |
| 630 v8::HandleScope scope(m_isolate); | 630 v8::HandleScope scope(m_isolate); |
| 631 v8::Context::Scope contextScope(debuggerContext()); | 631 v8::Context::Scope contextScope(debuggerContext()); |
| 632 | 632 |
| 633 v8::Local<v8::String> scriptValue = v8::String::NewFromUtf8(m_isolate, Debug
gerScript_js, v8::NewStringType::kInternalized, sizeof(DebuggerScript_js)).ToLoc
alChecked(); | 633 v8::Local<v8::String> scriptValue = v8::String::NewFromUtf8(m_isolate, Debug
gerScript_js, v8::NewStringType::kInternalized, sizeof(DebuggerScript_js)).ToLoc
alChecked(); |
| 634 v8::Local<v8::Value> value; | 634 v8::Local<v8::Value> value; |
| 635 if (!compileAndRunInternalScript(debuggerContext(), scriptValue).ToLocal(&va
lue)) { | 635 if (!compileAndRunInternalScript(debuggerContext(), scriptValue).ToLocal(&va
lue)) { |
| 636 NOTREACHED(); | 636 NOTREACHED(); |
| 637 return; | 637 return; |
| 638 } | 638 } |
| 639 DCHECK(value->IsObject()); | 639 DCHECK(value->IsObject()); |
| 640 m_debuggerScript.Reset(m_isolate, value.As<v8::Object>()); | 640 m_debuggerScript.Reset(m_isolate, value.As<v8::Object>()); |
| 641 } | 641 } |
| 642 | 642 |
| 643 v8::Local<v8::Context> V8DebuggerImpl::debuggerContext() const | 643 v8::Local<v8::Context> V8InspectorImpl::debuggerContext() const |
| 644 { | 644 { |
| 645 DCHECK(!m_debuggerContext.IsEmpty()); | 645 DCHECK(!m_debuggerContext.IsEmpty()); |
| 646 return m_debuggerContext.Get(m_isolate); | 646 return m_debuggerContext.Get(m_isolate); |
| 647 } | 647 } |
| 648 | 648 |
| 649 v8::Local<v8::String> V8DebuggerImpl::v8InternalizedString(const char* str) cons
t | 649 v8::Local<v8::String> V8InspectorImpl::v8InternalizedString(const char* str) con
st |
| 650 { | 650 { |
| 651 return v8::String::NewFromUtf8(m_isolate, str, v8::NewStringType::kInternali
zed).ToLocalChecked(); | 651 return v8::String::NewFromUtf8(m_isolate, str, v8::NewStringType::kInternali
zed).ToLocalChecked(); |
| 652 } | 652 } |
| 653 | 653 |
| 654 v8::MaybeLocal<v8::Value> V8DebuggerImpl::functionScopes(v8::Local<v8::Function>
function) | 654 v8::MaybeLocal<v8::Value> V8InspectorImpl::functionScopes(v8::Local<v8::Function
> function) |
| 655 { | 655 { |
| 656 if (!enabled()) { | 656 if (!enabled()) { |
| 657 NOTREACHED(); | 657 NOTREACHED(); |
| 658 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); | 658 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); |
| 659 } | 659 } |
| 660 v8::Local<v8::Value> argv[] = { function }; | 660 v8::Local<v8::Value> argv[] = { function }; |
| 661 v8::Local<v8::Value> scopesValue; | 661 v8::Local<v8::Value> scopesValue; |
| 662 if (!callDebuggerMethod("getFunctionScopes", 1, argv).ToLocal(&scopesValue)
|| !scopesValue->IsArray()) | 662 if (!callDebuggerMethod("getFunctionScopes", 1, argv).ToLocal(&scopesValue)
|| !scopesValue->IsArray()) |
| 663 return v8::MaybeLocal<v8::Value>(); | 663 return v8::MaybeLocal<v8::Value>(); |
| 664 v8::Local<v8::Array> scopes = scopesValue.As<v8::Array>(); | 664 v8::Local<v8::Array> scopes = scopesValue.As<v8::Array>(); |
| 665 v8::Local<v8::Context> context = m_debuggerContext.Get(m_isolate); | 665 v8::Local<v8::Context> context = m_debuggerContext.Get(m_isolate); |
| 666 if (!markAsInternal(context, scopes, V8InternalValueType::kScopeList)) | 666 if (!markAsInternal(context, scopes, V8InternalValueType::kScopeList)) |
| 667 return v8::MaybeLocal<v8::Value>(); | 667 return v8::MaybeLocal<v8::Value>(); |
| 668 if (!markArrayEntriesAsInternal(context, scopes, V8InternalValueType::kScope
)) | 668 if (!markArrayEntriesAsInternal(context, scopes, V8InternalValueType::kScope
)) |
| 669 return v8::MaybeLocal<v8::Value>(); | 669 return v8::MaybeLocal<v8::Value>(); |
| 670 if (!scopes->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) | 670 if (!scopes->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) |
| 671 return v8::Undefined(m_isolate); | 671 return v8::Undefined(m_isolate); |
| 672 return scopes; | 672 return scopes; |
| 673 } | 673 } |
| 674 | 674 |
| 675 v8::MaybeLocal<v8::Array> V8DebuggerImpl::internalProperties(v8::Local<v8::Conte
xt> context, v8::Local<v8::Value> value) | 675 v8::MaybeLocal<v8::Array> V8InspectorImpl::internalProperties(v8::Local<v8::Cont
ext> context, v8::Local<v8::Value> value) |
| 676 { | 676 { |
| 677 v8::Local<v8::Array> properties; | 677 v8::Local<v8::Array> properties; |
| 678 if (!v8::Debug::GetInternalProperties(m_isolate, value).ToLocal(&properties)
) | 678 if (!v8::Debug::GetInternalProperties(m_isolate, value).ToLocal(&properties)
) |
| 679 return v8::MaybeLocal<v8::Array>(); | 679 return v8::MaybeLocal<v8::Array>(); |
| 680 if (value->IsFunction()) { | 680 if (value->IsFunction()) { |
| 681 v8::Local<v8::Function> function = value.As<v8::Function>(); | 681 v8::Local<v8::Function> function = value.As<v8::Function>(); |
| 682 v8::Local<v8::Value> location = functionLocation(context, function); | 682 v8::Local<v8::Value> location = functionLocation(context, function); |
| 683 if (location->IsObject()) { | 683 if (location->IsObject()) { |
| 684 properties->Set(properties->Length(), v8InternalizedString("[[Functi
onLocation]]")); | 684 properties->Set(properties->Length(), v8InternalizedString("[[Functi
onLocation]]")); |
| 685 properties->Set(properties->Length(), location); | 685 properties->Set(properties->Length(), location); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 710 v8::Local<v8::Value> boundFunction = function->GetBoundFunction(); | 710 v8::Local<v8::Value> boundFunction = function->GetBoundFunction(); |
| 711 v8::Local<v8::Value> scopes; | 711 v8::Local<v8::Value> scopes; |
| 712 if (boundFunction->IsUndefined() && functionScopes(function).ToLocal(&sc
opes)) { | 712 if (boundFunction->IsUndefined() && functionScopes(function).ToLocal(&sc
opes)) { |
| 713 properties->Set(properties->Length(), v8InternalizedString("[[Scopes
]]")); | 713 properties->Set(properties->Length(), v8InternalizedString("[[Scopes
]]")); |
| 714 properties->Set(properties->Length(), scopes); | 714 properties->Set(properties->Length(), scopes); |
| 715 } | 715 } |
| 716 } | 716 } |
| 717 return properties; | 717 return properties; |
| 718 } | 718 } |
| 719 | 719 |
| 720 v8::Local<v8::Value> V8DebuggerImpl::collectionEntries(v8::Local<v8::Context> co
ntext, v8::Local<v8::Object> object) | 720 v8::Local<v8::Value> V8InspectorImpl::collectionEntries(v8::Local<v8::Context> c
ontext, v8::Local<v8::Object> object) |
| 721 { | 721 { |
| 722 if (!enabled()) { | 722 if (!enabled()) { |
| 723 NOTREACHED(); | 723 NOTREACHED(); |
| 724 return v8::Undefined(m_isolate); | 724 return v8::Undefined(m_isolate); |
| 725 } | 725 } |
| 726 v8::Local<v8::Value> argv[] = { object }; | 726 v8::Local<v8::Value> argv[] = { object }; |
| 727 v8::Local<v8::Value> entriesValue = callDebuggerMethod("getCollectionEntries
", 1, argv).ToLocalChecked(); | 727 v8::Local<v8::Value> entriesValue = callDebuggerMethod("getCollectionEntries
", 1, argv).ToLocalChecked(); |
| 728 if (!entriesValue->IsArray()) | 728 if (!entriesValue->IsArray()) |
| 729 return v8::Undefined(m_isolate); | 729 return v8::Undefined(m_isolate); |
| 730 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>(); | 730 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>(); |
| 731 if (!markArrayEntriesAsInternal(context, entries, V8InternalValueType::kEntr
y)) | 731 if (!markArrayEntriesAsInternal(context, entries, V8InternalValueType::kEntr
y)) |
| 732 return v8::Undefined(m_isolate); | 732 return v8::Undefined(m_isolate); |
| 733 if (!entries->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) | 733 if (!entries->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) |
| 734 return v8::Undefined(m_isolate); | 734 return v8::Undefined(m_isolate); |
| 735 return entries; | 735 return entries; |
| 736 } | 736 } |
| 737 | 737 |
| 738 v8::Local<v8::Value> V8DebuggerImpl::generatorObjectLocation(v8::Local<v8::Objec
t> object) | 738 v8::Local<v8::Value> V8InspectorImpl::generatorObjectLocation(v8::Local<v8::Obje
ct> object) |
| 739 { | 739 { |
| 740 if (!enabled()) { | 740 if (!enabled()) { |
| 741 NOTREACHED(); | 741 NOTREACHED(); |
| 742 return v8::Null(m_isolate); | 742 return v8::Null(m_isolate); |
| 743 } | 743 } |
| 744 v8::Local<v8::Value> argv[] = { object }; | 744 v8::Local<v8::Value> argv[] = { object }; |
| 745 v8::Local<v8::Value> location = callDebuggerMethod("getGeneratorObjectLocati
on", 1, argv).ToLocalChecked(); | 745 v8::Local<v8::Value> location = callDebuggerMethod("getGeneratorObjectLocati
on", 1, argv).ToLocalChecked(); |
| 746 if (!location->IsObject()) | 746 if (!location->IsObject()) |
| 747 return v8::Null(m_isolate); | 747 return v8::Null(m_isolate); |
| 748 v8::Local<v8::Context> context = m_debuggerContext.Get(m_isolate); | 748 v8::Local<v8::Context> context = m_debuggerContext.Get(m_isolate); |
| 749 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(location), V8Intern
alValueType::kLocation)) | 749 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(location), V8Intern
alValueType::kLocation)) |
| 750 return v8::Null(m_isolate); | 750 return v8::Null(m_isolate); |
| 751 return location; | 751 return location; |
| 752 } | 752 } |
| 753 | 753 |
| 754 v8::Local<v8::Value> V8DebuggerImpl::functionLocation(v8::Local<v8::Context> con
text, v8::Local<v8::Function> function) | 754 v8::Local<v8::Value> V8InspectorImpl::functionLocation(v8::Local<v8::Context> co
ntext, v8::Local<v8::Function> function) |
| 755 { | 755 { |
| 756 int scriptId = function->ScriptId(); | 756 int scriptId = function->ScriptId(); |
| 757 if (scriptId == v8::UnboundScript::kNoScriptId) | 757 if (scriptId == v8::UnboundScript::kNoScriptId) |
| 758 return v8::Null(m_isolate); | 758 return v8::Null(m_isolate); |
| 759 int lineNumber = function->GetScriptLineNumber(); | 759 int lineNumber = function->GetScriptLineNumber(); |
| 760 int columnNumber = function->GetScriptColumnNumber(); | 760 int columnNumber = function->GetScriptColumnNumber(); |
| 761 if (lineNumber == v8::Function::kLineOffsetNotFound || columnNumber == v8::F
unction::kLineOffsetNotFound) | 761 if (lineNumber == v8::Function::kLineOffsetNotFound || columnNumber == v8::F
unction::kLineOffsetNotFound) |
| 762 return v8::Null(m_isolate); | 762 return v8::Null(m_isolate); |
| 763 v8::Local<v8::Object> location = v8::Object::New(m_isolate); | 763 v8::Local<v8::Object> location = v8::Object::New(m_isolate); |
| 764 if (!location->Set(context, v8InternalizedString("scriptId"), toV8String(m_i
solate, String16::fromInteger(scriptId))).FromMaybe(false)) | 764 if (!location->Set(context, v8InternalizedString("scriptId"), toV8String(m_i
solate, String16::fromInteger(scriptId))).FromMaybe(false)) |
| 765 return v8::Null(m_isolate); | 765 return v8::Null(m_isolate); |
| 766 if (!location->Set(context, v8InternalizedString("lineNumber"), v8::Integer:
:New(m_isolate, lineNumber)).FromMaybe(false)) | 766 if (!location->Set(context, v8InternalizedString("lineNumber"), v8::Integer:
:New(m_isolate, lineNumber)).FromMaybe(false)) |
| 767 return v8::Null(m_isolate); | 767 return v8::Null(m_isolate); |
| 768 if (!location->Set(context, v8InternalizedString("columnNumber"), v8::Intege
r::New(m_isolate, columnNumber)).FromMaybe(false)) | 768 if (!location->Set(context, v8InternalizedString("columnNumber"), v8::Intege
r::New(m_isolate, columnNumber)).FromMaybe(false)) |
| 769 return v8::Null(m_isolate); | 769 return v8::Null(m_isolate); |
| 770 if (!markAsInternal(context, location, V8InternalValueType::kLocation)) | 770 if (!markAsInternal(context, location, V8InternalValueType::kLocation)) |
| 771 return v8::Null(m_isolate); | 771 return v8::Null(m_isolate); |
| 772 return location; | 772 return location; |
| 773 } | 773 } |
| 774 | 774 |
| 775 bool V8DebuggerImpl::isPaused() | 775 bool V8InspectorImpl::isPaused() |
| 776 { | 776 { |
| 777 return !m_pausedContext.IsEmpty(); | 777 return !m_pausedContext.IsEmpty(); |
| 778 } | 778 } |
| 779 | 779 |
| 780 v8::MaybeLocal<v8::Value> V8DebuggerImpl::runCompiledScript(v8::Local<v8::Contex
t> context, v8::Local<v8::Script> script) | 780 v8::MaybeLocal<v8::Value> V8InspectorImpl::runCompiledScript(v8::Local<v8::Conte
xt> context, v8::Local<v8::Script> script) |
| 781 { | 781 { |
| 782 // TODO(dgozman): get rid of this check. | 782 // TODO(dgozman): get rid of this check. |
| 783 if (!m_client->isExecutionAllowed()) | 783 if (!m_client->isExecutionAllowed()) |
| 784 return v8::MaybeLocal<v8::Value>(); | 784 return v8::MaybeLocal<v8::Value>(); |
| 785 | 785 |
| 786 v8::MicrotasksScope microtasksScope(m_isolate, v8::MicrotasksScope::kRunMicr
otasks); | 786 v8::MicrotasksScope microtasksScope(m_isolate, v8::MicrotasksScope::kRunMicr
otasks); |
| 787 int groupId = getGroupId(context); | 787 int groupId = getGroupId(context); |
| 788 if (V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(groupId)) | 788 if (V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(groupId)) |
| 789 agent->willExecuteScript(script->GetUnboundScript()->GetId()); | 789 agent->willExecuteScript(script->GetUnboundScript()->GetId()); |
| 790 v8::MaybeLocal<v8::Value> result = script->Run(context); | 790 v8::MaybeLocal<v8::Value> result = script->Run(context); |
| 791 // Get agent from the map again, since it could have detached during script
execution. | 791 // Get agent from the map again, since it could have detached during script
execution. |
| 792 if (V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(groupId)) | 792 if (V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(groupId)) |
| 793 agent->didExecuteScript(); | 793 agent->didExecuteScript(); |
| 794 return result; | 794 return result; |
| 795 } | 795 } |
| 796 | 796 |
| 797 v8::MaybeLocal<v8::Value> V8DebuggerImpl::callFunction(v8::Local<v8::Function> f
unction, v8::Local<v8::Context> context, v8::Local<v8::Value> receiver, int argc
, v8::Local<v8::Value> info[]) | 797 v8::MaybeLocal<v8::Value> V8InspectorImpl::callFunction(v8::Local<v8::Function>
function, v8::Local<v8::Context> context, v8::Local<v8::Value> receiver, int arg
c, v8::Local<v8::Value> info[]) |
| 798 { | 798 { |
| 799 // TODO(dgozman): get rid of this check. | 799 // TODO(dgozman): get rid of this check. |
| 800 if (!m_client->isExecutionAllowed()) | 800 if (!m_client->isExecutionAllowed()) |
| 801 return v8::MaybeLocal<v8::Value>(); | 801 return v8::MaybeLocal<v8::Value>(); |
| 802 | 802 |
| 803 v8::MicrotasksScope microtasksScope(m_isolate, v8::MicrotasksScope::kRunMicr
otasks); | 803 v8::MicrotasksScope microtasksScope(m_isolate, v8::MicrotasksScope::kRunMicr
otasks); |
| 804 int groupId = getGroupId(context); | 804 int groupId = getGroupId(context); |
| 805 if (V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(groupId)) | 805 if (V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(groupId)) |
| 806 agent->willExecuteScript(function->ScriptId()); | 806 agent->willExecuteScript(function->ScriptId()); |
| 807 v8::MaybeLocal<v8::Value> result = function->Call(context, receiver, argc, i
nfo); | 807 v8::MaybeLocal<v8::Value> result = function->Call(context, receiver, argc, i
nfo); |
| 808 // Get agent from the map again, since it could have detached during script
execution. | 808 // Get agent from the map again, since it could have detached during script
execution. |
| 809 if (V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(groupId)) | 809 if (V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(groupId)) |
| 810 agent->didExecuteScript(); | 810 agent->didExecuteScript(); |
| 811 return result; | 811 return result; |
| 812 } | 812 } |
| 813 | 813 |
| 814 v8::MaybeLocal<v8::Value> V8DebuggerImpl::compileAndRunInternalScript(v8::Local<
v8::Context> context, v8::Local<v8::String> source) | 814 v8::MaybeLocal<v8::Value> V8InspectorImpl::compileAndRunInternalScript(v8::Local
<v8::Context> context, v8::Local<v8::String> source) |
| 815 { | 815 { |
| 816 v8::Local<v8::Script> script = compileScript(context, source, String(), true
); | 816 v8::Local<v8::Script> script = compileScript(context, source, String(), true
); |
| 817 if (script.IsEmpty()) | 817 if (script.IsEmpty()) |
| 818 return v8::MaybeLocal<v8::Value>(); | 818 return v8::MaybeLocal<v8::Value>(); |
| 819 v8::MicrotasksScope microtasksScope(m_isolate, v8::MicrotasksScope::kDoNotRu
nMicrotasks); | 819 v8::MicrotasksScope microtasksScope(m_isolate, v8::MicrotasksScope::kDoNotRu
nMicrotasks); |
| 820 return script->Run(context); | 820 return script->Run(context); |
| 821 } | 821 } |
| 822 | 822 |
| 823 v8::Local<v8::Script> V8DebuggerImpl::compileScript(v8::Local<v8::Context> conte
xt, v8::Local<v8::String> code, const String16& fileName, bool markAsInternal) | 823 v8::Local<v8::Script> V8InspectorImpl::compileScript(v8::Local<v8::Context> cont
ext, v8::Local<v8::String> code, const String16& fileName, bool markAsInternal) |
| 824 { | 824 { |
| 825 v8::ScriptOrigin origin( | 825 v8::ScriptOrigin origin( |
| 826 toV8String(m_isolate, fileName), | 826 toV8String(m_isolate, fileName), |
| 827 v8::Integer::New(m_isolate, 0), | 827 v8::Integer::New(m_isolate, 0), |
| 828 v8::Integer::New(m_isolate, 0), | 828 v8::Integer::New(m_isolate, 0), |
| 829 v8::False(m_isolate), // sharable | 829 v8::False(m_isolate), // sharable |
| 830 v8::Local<v8::Integer>(), | 830 v8::Local<v8::Integer>(), |
| 831 v8::Boolean::New(m_isolate, markAsInternal), // internal | 831 v8::Boolean::New(m_isolate, markAsInternal), // internal |
| 832 toV8String(m_isolate, String16()), // sourceMap | 832 toV8String(m_isolate, String16()), // sourceMap |
| 833 v8::True(m_isolate)); // opaqueresource | 833 v8::True(m_isolate)); // opaqueresource |
| 834 v8::ScriptCompiler::Source source(code, origin); | 834 v8::ScriptCompiler::Source source(code, origin); |
| 835 v8::Local<v8::Script> script; | 835 v8::Local<v8::Script> script; |
| 836 if (!v8::ScriptCompiler::Compile(context, &source, v8::ScriptCompiler::kNoCo
mpileOptions).ToLocal(&script)) | 836 if (!v8::ScriptCompiler::Compile(context, &source, v8::ScriptCompiler::kNoCo
mpileOptions).ToLocal(&script)) |
| 837 return v8::Local<v8::Script>(); | 837 return v8::Local<v8::Script>(); |
| 838 return script; | 838 return script; |
| 839 } | 839 } |
| 840 | 840 |
| 841 void V8DebuggerImpl::enableStackCapturingIfNeeded() | 841 void V8InspectorImpl::enableStackCapturingIfNeeded() |
| 842 { | 842 { |
| 843 if (!m_capturingStackTracesCount) | 843 if (!m_capturingStackTracesCount) |
| 844 V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions(m_isolate, t
rue); | 844 V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions(m_isolate, t
rue); |
| 845 ++m_capturingStackTracesCount; | 845 ++m_capturingStackTracesCount; |
| 846 } | 846 } |
| 847 | 847 |
| 848 void V8DebuggerImpl::disableStackCapturingIfNeeded() | 848 void V8InspectorImpl::disableStackCapturingIfNeeded() |
| 849 { | 849 { |
| 850 if (!(--m_capturingStackTracesCount)) | 850 if (!(--m_capturingStackTracesCount)) |
| 851 V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions(m_isolate, f
alse); | 851 V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions(m_isolate, f
alse); |
| 852 } | 852 } |
| 853 | 853 |
| 854 V8ConsoleMessageStorage* V8DebuggerImpl::ensureConsoleMessageStorage(int context
GroupId) | 854 V8ConsoleMessageStorage* V8InspectorImpl::ensureConsoleMessageStorage(int contex
tGroupId) |
| 855 { | 855 { |
| 856 ConsoleStorageMap::iterator storageIt = m_consoleStorageMap.find(contextGrou
pId); | 856 ConsoleStorageMap::iterator storageIt = m_consoleStorageMap.find(contextGrou
pId); |
| 857 if (storageIt == m_consoleStorageMap.end()) | 857 if (storageIt == m_consoleStorageMap.end()) |
| 858 storageIt = m_consoleStorageMap.insert(std::make_pair(contextGroupId, wr
apUnique(new V8ConsoleMessageStorage(this, contextGroupId)))).first; | 858 storageIt = m_consoleStorageMap.insert(std::make_pair(contextGroupId, wr
apUnique(new V8ConsoleMessageStorage(this, contextGroupId)))).first; |
| 859 return storageIt->second.get(); | 859 return storageIt->second.get(); |
| 860 } | 860 } |
| 861 | 861 |
| 862 std::unique_ptr<V8StackTrace> V8DebuggerImpl::createStackTrace(v8::Local<v8::Sta
ckTrace> stackTrace) | 862 std::unique_ptr<V8StackTrace> V8InspectorImpl::createStackTrace(v8::Local<v8::St
ackTrace> stackTrace) |
| 863 { | 863 { |
| 864 return createStackTraceImpl(stackTrace); | 864 return createStackTraceImpl(stackTrace); |
| 865 } | 865 } |
| 866 | 866 |
| 867 std::unique_ptr<V8StackTraceImpl> V8DebuggerImpl::createStackTraceImpl(v8::Local
<v8::StackTrace> stackTrace) | 867 std::unique_ptr<V8StackTraceImpl> V8InspectorImpl::createStackTraceImpl(v8::Loca
l<v8::StackTrace> stackTrace) |
| 868 { | 868 { |
| 869 int contextGroupId = m_isolate->InContext() ? getGroupId(m_isolate->GetCurre
ntContext()) : 0; | 869 int contextGroupId = m_isolate->InContext() ? getGroupId(m_isolate->GetCurre
ntContext()) : 0; |
| 870 return V8StackTraceImpl::create(this, contextGroupId, stackTrace, V8StackTra
ceImpl::maxCallStackSizeToCapture); | 870 return V8StackTraceImpl::create(this, contextGroupId, stackTrace, V8StackTra
ceImpl::maxCallStackSizeToCapture); |
| 871 } | 871 } |
| 872 | 872 |
| 873 std::unique_ptr<V8InspectorSession> V8DebuggerImpl::connect(int contextGroupId,
protocol::FrontendChannel* channel, V8InspectorSessionClient* client, const Stri
ng16* state) | 873 std::unique_ptr<V8InspectorSession> V8InspectorImpl::connect(int contextGroupId,
protocol::FrontendChannel* channel, V8InspectorSessionClient* client, const Str
ing16* state) |
| 874 { | 874 { |
| 875 DCHECK(m_sessions.find(contextGroupId) == m_sessions.cend()); | 875 DCHECK(m_sessions.find(contextGroupId) == m_sessions.cend()); |
| 876 std::unique_ptr<V8InspectorSessionImpl> session = | 876 std::unique_ptr<V8InspectorSessionImpl> session = |
| 877 V8InspectorSessionImpl::create(this, contextGroupId, channel, client, st
ate); | 877 V8InspectorSessionImpl::create(this, contextGroupId, channel, client, st
ate); |
| 878 m_sessions[contextGroupId] = session.get(); | 878 m_sessions[contextGroupId] = session.get(); |
| 879 return std::move(session); | 879 return std::move(session); |
| 880 } | 880 } |
| 881 | 881 |
| 882 void V8DebuggerImpl::disconnect(V8InspectorSessionImpl* session) | 882 void V8InspectorImpl::disconnect(V8InspectorSessionImpl* session) |
| 883 { | 883 { |
| 884 DCHECK(m_sessions.find(session->contextGroupId()) != m_sessions.end()); | 884 DCHECK(m_sessions.find(session->contextGroupId()) != m_sessions.end()); |
| 885 m_sessions.erase(session->contextGroupId()); | 885 m_sessions.erase(session->contextGroupId()); |
| 886 } | 886 } |
| 887 | 887 |
| 888 InspectedContext* V8DebuggerImpl::getContext(int groupId, int contextId) const | 888 InspectedContext* V8InspectorImpl::getContext(int groupId, int contextId) const |
| 889 { | 889 { |
| 890 ContextsByGroupMap::const_iterator contextGroupIt = m_contexts.find(groupId)
; | 890 ContextsByGroupMap::const_iterator contextGroupIt = m_contexts.find(groupId)
; |
| 891 if (contextGroupIt == m_contexts.end()) | 891 if (contextGroupIt == m_contexts.end()) |
| 892 return nullptr; | 892 return nullptr; |
| 893 | 893 |
| 894 ContextByIdMap::iterator contextIt = contextGroupIt->second->find(contextId)
; | 894 ContextByIdMap::iterator contextIt = contextGroupIt->second->find(contextId)
; |
| 895 if (contextIt == contextGroupIt->second->end()) | 895 if (contextIt == contextGroupIt->second->end()) |
| 896 return nullptr; | 896 return nullptr; |
| 897 | 897 |
| 898 return contextIt->second.get(); | 898 return contextIt->second.get(); |
| 899 } | 899 } |
| 900 | 900 |
| 901 void V8DebuggerImpl::contextCreated(const V8ContextInfo& info) | 901 void V8InspectorImpl::contextCreated(const V8ContextInfo& info) |
| 902 { | 902 { |
| 903 DCHECK(info.context->GetIsolate() == m_isolate); | 903 DCHECK(info.context->GetIsolate() == m_isolate); |
| 904 // TODO(dgozman): make s_lastContextId non-static. | 904 // TODO(dgozman): make s_lastContextId non-static. |
| 905 int contextId = atomicIncrement(&s_lastContextId); | 905 int contextId = atomicIncrement(&s_lastContextId); |
| 906 String16 debugData = String16::fromInteger(info.contextGroupId) + "," + Stri
ng16::fromInteger(contextId) + "," + (info.isDefault ? "default" : "nondefault")
; | 906 String16 debugData = String16::fromInteger(info.contextGroupId) + "," + Stri
ng16::fromInteger(contextId) + "," + (info.isDefault ? "default" : "nondefault")
; |
| 907 v8::HandleScope scope(m_isolate); | 907 v8::HandleScope scope(m_isolate); |
| 908 v8::Context::Scope contextScope(info.context); | 908 v8::Context::Scope contextScope(info.context); |
| 909 info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex),
toV8String(m_isolate, debugData)); | 909 info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex),
toV8String(m_isolate, debugData)); |
| 910 | 910 |
| 911 ContextsByGroupMap::iterator contextIt = m_contexts.find(info.contextGroupId
); | 911 ContextsByGroupMap::iterator contextIt = m_contexts.find(info.contextGroupId
); |
| 912 if (contextIt == m_contexts.end()) | 912 if (contextIt == m_contexts.end()) |
| 913 contextIt = m_contexts.insert(std::make_pair(info.contextGroupId, wrapUn
ique(new ContextByIdMap()))).first; | 913 contextIt = m_contexts.insert(std::make_pair(info.contextGroupId, wrapUn
ique(new ContextByIdMap()))).first; |
| 914 | 914 |
| 915 const auto& contextById = contextIt->second; | 915 const auto& contextById = contextIt->second; |
| 916 | 916 |
| 917 DCHECK(contextById->find(contextId) == contextById->cend()); | 917 DCHECK(contextById->find(contextId) == contextById->cend()); |
| 918 InspectedContext* context = new InspectedContext(this, info, contextId); | 918 InspectedContext* context = new InspectedContext(this, info, contextId); |
| 919 (*contextById)[contextId] = wrapUnique(context); | 919 (*contextById)[contextId] = wrapUnique(context); |
| 920 SessionMap::iterator sessionIt = m_sessions.find(info.contextGroupId); | 920 SessionMap::iterator sessionIt = m_sessions.find(info.contextGroupId); |
| 921 if (sessionIt != m_sessions.end()) | 921 if (sessionIt != m_sessions.end()) |
| 922 sessionIt->second->runtimeAgent()->reportExecutionContextCreated(context
); | 922 sessionIt->second->runtimeAgent()->reportExecutionContextCreated(context
); |
| 923 } | 923 } |
| 924 | 924 |
| 925 void V8DebuggerImpl::contextDestroyed(v8::Local<v8::Context> context) | 925 void V8InspectorImpl::contextDestroyed(v8::Local<v8::Context> context) |
| 926 { | 926 { |
| 927 int contextId = V8DebuggerImpl::contextId(context); | 927 int contextId = V8InspectorImpl::contextId(context); |
| 928 int contextGroupId = getGroupId(context); | 928 int contextGroupId = getGroupId(context); |
| 929 | 929 |
| 930 ConsoleStorageMap::iterator storageIt = m_consoleStorageMap.find(contextGrou
pId); | 930 ConsoleStorageMap::iterator storageIt = m_consoleStorageMap.find(contextGrou
pId); |
| 931 if (storageIt != m_consoleStorageMap.end()) | 931 if (storageIt != m_consoleStorageMap.end()) |
| 932 storageIt->second->contextDestroyed(contextId); | 932 storageIt->second->contextDestroyed(contextId); |
| 933 | 933 |
| 934 InspectedContext* inspectedContext = getContext(contextGroupId, contextId); | 934 InspectedContext* inspectedContext = getContext(contextGroupId, contextId); |
| 935 if (!inspectedContext) | 935 if (!inspectedContext) |
| 936 return; | 936 return; |
| 937 | 937 |
| 938 SessionMap::iterator iter = m_sessions.find(contextGroupId); | 938 SessionMap::iterator iter = m_sessions.find(contextGroupId); |
| 939 if (iter != m_sessions.end()) | 939 if (iter != m_sessions.end()) |
| 940 iter->second->runtimeAgent()->reportExecutionContextDestroyed(inspectedC
ontext); | 940 iter->second->runtimeAgent()->reportExecutionContextDestroyed(inspectedC
ontext); |
| 941 discardInspectedContext(contextGroupId, contextId); | 941 discardInspectedContext(contextGroupId, contextId); |
| 942 } | 942 } |
| 943 | 943 |
| 944 void V8DebuggerImpl::resetContextGroup(int contextGroupId) | 944 void V8InspectorImpl::resetContextGroup(int contextGroupId) |
| 945 { | 945 { |
| 946 m_consoleStorageMap.erase(contextGroupId); | 946 m_consoleStorageMap.erase(contextGroupId); |
| 947 SessionMap::iterator session = m_sessions.find(contextGroupId); | 947 SessionMap::iterator session = m_sessions.find(contextGroupId); |
| 948 if (session != m_sessions.end()) | 948 if (session != m_sessions.end()) |
| 949 session->second->reset(); | 949 session->second->reset(); |
| 950 m_contexts.erase(contextGroupId); | 950 m_contexts.erase(contextGroupId); |
| 951 } | 951 } |
| 952 | 952 |
| 953 void V8DebuggerImpl::setAsyncCallStackDepth(V8DebuggerAgentImpl* agent, int dept
h) | 953 void V8InspectorImpl::setAsyncCallStackDepth(V8DebuggerAgentImpl* agent, int dep
th) |
| 954 { | 954 { |
| 955 if (depth <= 0) | 955 if (depth <= 0) |
| 956 m_maxAsyncCallStackDepthMap.erase(agent); | 956 m_maxAsyncCallStackDepthMap.erase(agent); |
| 957 else | 957 else |
| 958 m_maxAsyncCallStackDepthMap[agent] = depth; | 958 m_maxAsyncCallStackDepthMap[agent] = depth; |
| 959 | 959 |
| 960 int maxAsyncCallStackDepth = 0; | 960 int maxAsyncCallStackDepth = 0; |
| 961 for (const auto& pair : m_maxAsyncCallStackDepthMap) { | 961 for (const auto& pair : m_maxAsyncCallStackDepthMap) { |
| 962 if (pair.second > maxAsyncCallStackDepth) | 962 if (pair.second > maxAsyncCallStackDepth) |
| 963 maxAsyncCallStackDepth = pair.second; | 963 maxAsyncCallStackDepth = pair.second; |
| 964 } | 964 } |
| 965 | 965 |
| 966 if (m_maxAsyncCallStackDepth == maxAsyncCallStackDepth) | 966 if (m_maxAsyncCallStackDepth == maxAsyncCallStackDepth) |
| 967 return; | 967 return; |
| 968 m_maxAsyncCallStackDepth = maxAsyncCallStackDepth; | 968 m_maxAsyncCallStackDepth = maxAsyncCallStackDepth; |
| 969 if (!maxAsyncCallStackDepth) | 969 if (!maxAsyncCallStackDepth) |
| 970 allAsyncTasksCanceled(); | 970 allAsyncTasksCanceled(); |
| 971 } | 971 } |
| 972 | 972 |
| 973 void V8DebuggerImpl::asyncTaskScheduled(const String16& taskName, void* task, bo
ol recurring) | 973 void V8InspectorImpl::asyncTaskScheduled(const String16& taskName, void* task, b
ool recurring) |
| 974 { | 974 { |
| 975 if (!m_maxAsyncCallStackDepth) | 975 if (!m_maxAsyncCallStackDepth) |
| 976 return; | 976 return; |
| 977 v8::HandleScope scope(m_isolate); | 977 v8::HandleScope scope(m_isolate); |
| 978 int contextGroupId = m_isolate->InContext() ? getGroupId(m_isolate->GetCurre
ntContext()) : 0; | 978 int contextGroupId = m_isolate->InContext() ? getGroupId(m_isolate->GetCurre
ntContext()) : 0; |
| 979 std::unique_ptr<V8StackTraceImpl> chain = V8StackTraceImpl::capture(this, co
ntextGroupId, V8StackTraceImpl::maxCallStackSizeToCapture, taskName); | 979 std::unique_ptr<V8StackTraceImpl> chain = V8StackTraceImpl::capture(this, co
ntextGroupId, V8StackTraceImpl::maxCallStackSizeToCapture, taskName); |
| 980 if (chain) { | 980 if (chain) { |
| 981 m_asyncTaskStacks[task] = std::move(chain); | 981 m_asyncTaskStacks[task] = std::move(chain); |
| 982 if (recurring) | 982 if (recurring) |
| 983 m_recurringTasks.insert(task); | 983 m_recurringTasks.insert(task); |
| 984 } | 984 } |
| 985 } | 985 } |
| 986 | 986 |
| 987 void V8DebuggerImpl::asyncTaskCanceled(void* task) | 987 void V8InspectorImpl::asyncTaskCanceled(void* task) |
| 988 { | 988 { |
| 989 if (!m_maxAsyncCallStackDepth) | 989 if (!m_maxAsyncCallStackDepth) |
| 990 return; | 990 return; |
| 991 m_asyncTaskStacks.erase(task); | 991 m_asyncTaskStacks.erase(task); |
| 992 m_recurringTasks.erase(task); | 992 m_recurringTasks.erase(task); |
| 993 } | 993 } |
| 994 | 994 |
| 995 void V8DebuggerImpl::asyncTaskStarted(void* task) | 995 void V8InspectorImpl::asyncTaskStarted(void* task) |
| 996 { | 996 { |
| 997 if (!m_maxAsyncCallStackDepth) | 997 if (!m_maxAsyncCallStackDepth) |
| 998 return; | 998 return; |
| 999 m_currentTasks.push_back(task); | 999 m_currentTasks.push_back(task); |
| 1000 AsyncTaskToStackTrace::iterator stackIt = m_asyncTaskStacks.find(task); | 1000 AsyncTaskToStackTrace::iterator stackIt = m_asyncTaskStacks.find(task); |
| 1001 // Needs to support following order of events: | 1001 // Needs to support following order of events: |
| 1002 // - asyncTaskScheduled | 1002 // - asyncTaskScheduled |
| 1003 // <-- attached here --> | 1003 // <-- attached here --> |
| 1004 // - asyncTaskStarted | 1004 // - asyncTaskStarted |
| 1005 // - asyncTaskCanceled <-- canceled before finished | 1005 // - asyncTaskCanceled <-- canceled before finished |
| 1006 // <-- async stack requested here --> | 1006 // <-- async stack requested here --> |
| 1007 // - asyncTaskFinished | 1007 // - asyncTaskFinished |
| 1008 std::unique_ptr<V8StackTraceImpl> stack; | 1008 std::unique_ptr<V8StackTraceImpl> stack; |
| 1009 if (stackIt != m_asyncTaskStacks.end() && stackIt->second) | 1009 if (stackIt != m_asyncTaskStacks.end() && stackIt->second) |
| 1010 stack = stackIt->second->cloneImpl(); | 1010 stack = stackIt->second->cloneImpl(); |
| 1011 m_currentStacks.push_back(std::move(stack)); | 1011 m_currentStacks.push_back(std::move(stack)); |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 void V8DebuggerImpl::asyncTaskFinished(void* task) | 1014 void V8InspectorImpl::asyncTaskFinished(void* task) |
| 1015 { | 1015 { |
| 1016 if (!m_maxAsyncCallStackDepth) | 1016 if (!m_maxAsyncCallStackDepth) |
| 1017 return; | 1017 return; |
| 1018 // We could start instrumenting half way and the stack is empty. | 1018 // We could start instrumenting half way and the stack is empty. |
| 1019 if (!m_currentStacks.size()) | 1019 if (!m_currentStacks.size()) |
| 1020 return; | 1020 return; |
| 1021 | 1021 |
| 1022 DCHECK(m_currentTasks.back() == task); | 1022 DCHECK(m_currentTasks.back() == task); |
| 1023 m_currentTasks.pop_back(); | 1023 m_currentTasks.pop_back(); |
| 1024 | 1024 |
| 1025 m_currentStacks.pop_back(); | 1025 m_currentStacks.pop_back(); |
| 1026 if (m_recurringTasks.find(task) == m_recurringTasks.end()) | 1026 if (m_recurringTasks.find(task) == m_recurringTasks.end()) |
| 1027 m_asyncTaskStacks.erase(task); | 1027 m_asyncTaskStacks.erase(task); |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 void V8DebuggerImpl::allAsyncTasksCanceled() | 1030 void V8InspectorImpl::allAsyncTasksCanceled() |
| 1031 { | 1031 { |
| 1032 m_asyncTaskStacks.clear(); | 1032 m_asyncTaskStacks.clear(); |
| 1033 m_recurringTasks.clear(); | 1033 m_recurringTasks.clear(); |
| 1034 m_currentStacks.clear(); | 1034 m_currentStacks.clear(); |
| 1035 m_currentTasks.clear(); | 1035 m_currentTasks.clear(); |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 void V8DebuggerImpl::willExecuteScript(v8::Local<v8::Context> context, int scrip
tId) | 1038 void V8InspectorImpl::willExecuteScript(v8::Local<v8::Context> context, int scri
ptId) |
| 1039 { | 1039 { |
| 1040 if (V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(context)) | 1040 if (V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(context)) |
| 1041 agent->willExecuteScript(scriptId); | 1041 agent->willExecuteScript(scriptId); |
| 1042 } | 1042 } |
| 1043 | 1043 |
| 1044 void V8DebuggerImpl::didExecuteScript(v8::Local<v8::Context> context) | 1044 void V8InspectorImpl::didExecuteScript(v8::Local<v8::Context> context) |
| 1045 { | 1045 { |
| 1046 if (V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(context)) | 1046 if (V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(context)) |
| 1047 agent->didExecuteScript(); | 1047 agent->didExecuteScript(); |
| 1048 } | 1048 } |
| 1049 | 1049 |
| 1050 void V8DebuggerImpl::idleStarted() | 1050 void V8InspectorImpl::idleStarted() |
| 1051 { | 1051 { |
| 1052 m_isolate->GetCpuProfiler()->SetIdle(true); | 1052 m_isolate->GetCpuProfiler()->SetIdle(true); |
| 1053 } | 1053 } |
| 1054 | 1054 |
| 1055 void V8DebuggerImpl::idleFinished() | 1055 void V8InspectorImpl::idleFinished() |
| 1056 { | 1056 { |
| 1057 m_isolate->GetCpuProfiler()->SetIdle(false); | 1057 m_isolate->GetCpuProfiler()->SetIdle(false); |
| 1058 } | 1058 } |
| 1059 | 1059 |
| 1060 unsigned V8DebuggerImpl::exceptionThrown(v8::Local<v8::Context> context, const S
tring16& message, v8::Local<v8::Value> exception, const String16& detailedMessag
e, const String16& url, unsigned lineNumber, unsigned columnNumber, std::unique_
ptr<V8StackTrace> stackTrace, int scriptId) | 1060 unsigned V8InspectorImpl::exceptionThrown(v8::Local<v8::Context> context, const
String16& message, v8::Local<v8::Value> exception, const String16& detailedMessa
ge, const String16& url, unsigned lineNumber, unsigned columnNumber, std::unique
_ptr<V8StackTrace> stackTrace, int scriptId) |
| 1061 { | 1061 { |
| 1062 int contextGroupId = getGroupId(context); | 1062 int contextGroupId = getGroupId(context); |
| 1063 if (!contextGroupId) | 1063 if (!contextGroupId) |
| 1064 return 0; | 1064 return 0; |
| 1065 std::unique_ptr<V8StackTraceImpl> stackTraceImpl = wrapUnique(static_cast<V8
StackTraceImpl*>(stackTrace.release())); | 1065 std::unique_ptr<V8StackTraceImpl> stackTraceImpl = wrapUnique(static_cast<V8
StackTraceImpl*>(stackTrace.release())); |
| 1066 unsigned exceptionId = ++m_lastExceptionId; | 1066 unsigned exceptionId = ++m_lastExceptionId; |
| 1067 std::unique_ptr<V8ConsoleMessage> consoleMessage = V8ConsoleMessage::createF
orException(m_client->currentTimeMS(), detailedMessage, url, lineNumber, columnN
umber, std::move(stackTraceImpl), scriptId, m_isolate, message, contextId(contex
t), exception, exceptionId); | 1067 std::unique_ptr<V8ConsoleMessage> consoleMessage = V8ConsoleMessage::createF
orException(m_client->currentTimeMS(), detailedMessage, url, lineNumber, columnN
umber, std::move(stackTraceImpl), scriptId, m_isolate, message, contextId(contex
t), exception, exceptionId); |
| 1068 ensureConsoleMessageStorage(contextGroupId)->addMessage(std::move(consoleMes
sage)); | 1068 ensureConsoleMessageStorage(contextGroupId)->addMessage(std::move(consoleMes
sage)); |
| 1069 return exceptionId; | 1069 return exceptionId; |
| 1070 } | 1070 } |
| 1071 | 1071 |
| 1072 void V8DebuggerImpl::exceptionRevoked(v8::Local<v8::Context> context, unsigned e
xceptionId, const String16& message) | 1072 void V8InspectorImpl::exceptionRevoked(v8::Local<v8::Context> context, unsigned
exceptionId, const String16& message) |
| 1073 { | 1073 { |
| 1074 int contextGroupId = getGroupId(context); | 1074 int contextGroupId = getGroupId(context); |
| 1075 if (!contextGroupId) | 1075 if (!contextGroupId) |
| 1076 return; | 1076 return; |
| 1077 | 1077 |
| 1078 std::unique_ptr<V8ConsoleMessage> consoleMessage = V8ConsoleMessage::createF
orRevokedException(m_client->currentTimeMS(), message, exceptionId); | 1078 std::unique_ptr<V8ConsoleMessage> consoleMessage = V8ConsoleMessage::createF
orRevokedException(m_client->currentTimeMS(), message, exceptionId); |
| 1079 ensureConsoleMessageStorage(contextGroupId)->addMessage(std::move(consoleMes
sage)); | 1079 ensureConsoleMessageStorage(contextGroupId)->addMessage(std::move(consoleMes
sage)); |
| 1080 } | 1080 } |
| 1081 | 1081 |
| 1082 std::unique_ptr<V8StackTrace> V8DebuggerImpl::captureStackTrace(bool fullStack) | 1082 std::unique_ptr<V8StackTrace> V8InspectorImpl::captureStackTrace(bool fullStack) |
| 1083 { | 1083 { |
| 1084 return captureStackTraceImpl(fullStack); | 1084 return captureStackTraceImpl(fullStack); |
| 1085 } | 1085 } |
| 1086 | 1086 |
| 1087 std::unique_ptr<V8StackTraceImpl> V8DebuggerImpl::captureStackTraceImpl(bool ful
lStack) | 1087 std::unique_ptr<V8StackTraceImpl> V8InspectorImpl::captureStackTraceImpl(bool fu
llStack) |
| 1088 { | 1088 { |
| 1089 if (!m_isolate->InContext()) | 1089 if (!m_isolate->InContext()) |
| 1090 return nullptr; | 1090 return nullptr; |
| 1091 | 1091 |
| 1092 v8::HandleScope handles(m_isolate); | 1092 v8::HandleScope handles(m_isolate); |
| 1093 int contextGroupId = getGroupId(m_isolate->GetCurrentContext()); | 1093 int contextGroupId = getGroupId(m_isolate->GetCurrentContext()); |
| 1094 if (!contextGroupId) | 1094 if (!contextGroupId) |
| 1095 return nullptr; | 1095 return nullptr; |
| 1096 | 1096 |
| 1097 size_t stackSize = fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture :
1; | 1097 size_t stackSize = fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture :
1; |
| 1098 SessionMap::iterator sessionIt = m_sessions.find(contextGroupId); | 1098 SessionMap::iterator sessionIt = m_sessions.find(contextGroupId); |
| 1099 if (sessionIt != m_sessions.end() && sessionIt->second->runtimeAgent()->enab
led()) | 1099 if (sessionIt != m_sessions.end() && sessionIt->second->runtimeAgent()->enab
led()) |
| 1100 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; | 1100 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; |
| 1101 | 1101 |
| 1102 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); | 1102 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); |
| 1103 } | 1103 } |
| 1104 | 1104 |
| 1105 v8::Local<v8::Context> V8DebuggerImpl::regexContext() | 1105 v8::Local<v8::Context> V8InspectorImpl::regexContext() |
| 1106 { | 1106 { |
| 1107 if (m_regexContext.IsEmpty()) | 1107 if (m_regexContext.IsEmpty()) |
| 1108 m_regexContext.Reset(m_isolate, v8::Context::New(m_isolate)); | 1108 m_regexContext.Reset(m_isolate, v8::Context::New(m_isolate)); |
| 1109 return m_regexContext.Get(m_isolate); | 1109 return m_regexContext.Get(m_isolate); |
| 1110 } | 1110 } |
| 1111 | 1111 |
| 1112 void V8DebuggerImpl::discardInspectedContext(int contextGroupId, int contextId) | 1112 void V8InspectorImpl::discardInspectedContext(int contextGroupId, int contextId) |
| 1113 { | 1113 { |
| 1114 if (!getContext(contextGroupId, contextId)) | 1114 if (!getContext(contextGroupId, contextId)) |
| 1115 return; | 1115 return; |
| 1116 m_contexts[contextGroupId]->erase(contextId); | 1116 m_contexts[contextGroupId]->erase(contextId); |
| 1117 if (m_contexts[contextGroupId]->empty()) | 1117 if (m_contexts[contextGroupId]->empty()) |
| 1118 m_contexts.erase(contextGroupId); | 1118 m_contexts.erase(contextGroupId); |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 const V8DebuggerImpl::ContextByIdMap* V8DebuggerImpl::contextGroup(int contextGr
oupId) | 1121 const V8InspectorImpl::ContextByIdMap* V8InspectorImpl::contextGroup(int context
GroupId) |
| 1122 { | 1122 { |
| 1123 ContextsByGroupMap::iterator iter = m_contexts.find(contextGroupId); | 1123 ContextsByGroupMap::iterator iter = m_contexts.find(contextGroupId); |
| 1124 return iter == m_contexts.end() ? nullptr : iter->second.get(); | 1124 return iter == m_contexts.end() ? nullptr : iter->second.get(); |
| 1125 } | 1125 } |
| 1126 | 1126 |
| 1127 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI
d) | 1127 V8InspectorSessionImpl* V8InspectorImpl::sessionForContextGroup(int contextGroup
Id) |
| 1128 { | 1128 { |
| 1129 if (!contextGroupId) | 1129 if (!contextGroupId) |
| 1130 return nullptr; | 1130 return nullptr; |
| 1131 SessionMap::iterator iter = m_sessions.find(contextGroupId); | 1131 SessionMap::iterator iter = m_sessions.find(contextGroupId); |
| 1132 return iter == m_sessions.end() ? nullptr : iter->second; | 1132 return iter == m_sessions.end() ? nullptr : iter->second; |
| 1133 } | 1133 } |
| 1134 | 1134 |
| 1135 } // namespace blink | 1135 } // namespace blink |
| OLD | NEW |