| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 "src/inspector/V8Debugger.h" | 5 #include "src/inspector/V8Debugger.h" |
| 6 | 6 |
| 7 #include "src/inspector/DebuggerScript.h" | 7 #include "src/inspector/DebuggerScript.h" |
| 8 #include "src/inspector/ScriptBreakpoint.h" | 8 #include "src/inspector/ScriptBreakpoint.h" |
| 9 #include "src/inspector/StringUtil.h" | 9 #include "src/inspector/StringUtil.h" |
| 10 #include "src/inspector/V8DebuggerAgentImpl.h" | 10 #include "src/inspector/V8DebuggerAgentImpl.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 static bool inLiveEditScope = false; | 32 static bool inLiveEditScope = false; |
| 33 | 33 |
| 34 v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod( | 34 v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod( |
| 35 const char* functionName, int argc, v8::Local<v8::Value> argv[]) { | 35 const char* functionName, int argc, v8::Local<v8::Value> argv[]) { |
| 36 v8::MicrotasksScope microtasks(m_isolate, | 36 v8::MicrotasksScope microtasks(m_isolate, |
| 37 v8::MicrotasksScope::kDoNotRunMicrotasks); | 37 v8::MicrotasksScope::kDoNotRunMicrotasks); |
| 38 DCHECK(m_isolate->InContext()); |
| 39 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); |
| 38 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); | 40 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); |
| 39 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 41 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 40 debuggerScript->Get(toV8StringInternalized(m_isolate, functionName))); | 42 debuggerScript |
| 41 DCHECK(m_isolate->InContext()); | 43 ->Get(context, toV8StringInternalized(m_isolate, functionName)) |
| 42 return function->Call(m_isolate->GetCurrentContext(), debuggerScript, argc, | 44 .ToLocalChecked()); |
| 43 argv); | 45 return function->Call(context, debuggerScript, argc, argv); |
| 44 } | 46 } |
| 45 | 47 |
| 46 V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector) | 48 V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector) |
| 47 : m_isolate(isolate), | 49 : m_isolate(isolate), |
| 48 m_inspector(inspector), | 50 m_inspector(inspector), |
| 49 m_lastContextId(0), | 51 m_lastContextId(0), |
| 50 m_enableCount(0), | 52 m_enableCount(0), |
| 51 m_breakpointsActivated(true), | 53 m_breakpointsActivated(true), |
| 52 m_runningNestedMessageLoop(false), | 54 m_runningNestedMessageLoop(false), |
| 53 m_ignoreScriptParsedEventsCounter(0), | 55 m_ignoreScriptParsedEventsCounter(0), |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 if (commaPos == String16::kNotFound) return 0; | 105 if (commaPos == String16::kNotFound) return 0; |
| 104 return dataString.substring(0, commaPos).toInteger(); | 106 return dataString.substring(0, commaPos).toInteger(); |
| 105 } | 107 } |
| 106 | 108 |
| 107 void V8Debugger::getCompiledScripts( | 109 void V8Debugger::getCompiledScripts( |
| 108 int contextGroupId, | 110 int contextGroupId, |
| 109 std::vector<std::unique_ptr<V8DebuggerScript>>& result) { | 111 std::vector<std::unique_ptr<V8DebuggerScript>>& result) { |
| 110 v8::HandleScope scope(m_isolate); | 112 v8::HandleScope scope(m_isolate); |
| 111 v8::MicrotasksScope microtasks(m_isolate, | 113 v8::MicrotasksScope microtasks(m_isolate, |
| 112 v8::MicrotasksScope::kDoNotRunMicrotasks); | 114 v8::MicrotasksScope::kDoNotRunMicrotasks); |
| 115 v8::Local<v8::Context> context = debuggerContext(); |
| 113 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); | 116 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); |
| 114 DCHECK(!debuggerScript->IsUndefined()); | 117 DCHECK(!debuggerScript->IsUndefined()); |
| 115 v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast( | 118 v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast( |
| 116 debuggerScript->Get(toV8StringInternalized(m_isolate, "getScripts"))); | 119 debuggerScript |
| 120 ->Get(context, toV8StringInternalized(m_isolate, "getScripts")) |
| 121 .ToLocalChecked()); |
| 117 v8::Local<v8::Value> argv[] = {v8::Integer::New(m_isolate, contextGroupId)}; | 122 v8::Local<v8::Value> argv[] = {v8::Integer::New(m_isolate, contextGroupId)}; |
| 118 v8::Local<v8::Value> value; | 123 v8::Local<v8::Value> value; |
| 119 if (!getScriptsFunction | 124 if (!getScriptsFunction |
| 120 ->Call(debuggerContext(), debuggerScript, | 125 ->Call(context, debuggerScript, V8_INSPECTOR_ARRAY_LENGTH(argv), |
| 121 V8_INSPECTOR_ARRAY_LENGTH(argv), argv) | 126 argv) |
| 122 .ToLocal(&value)) | 127 .ToLocal(&value)) |
| 123 return; | 128 return; |
| 124 DCHECK(value->IsArray()); | 129 DCHECK(value->IsArray()); |
| 125 v8::Local<v8::Array> scriptsArray = v8::Local<v8::Array>::Cast(value); | 130 v8::Local<v8::Array> scriptsArray = v8::Local<v8::Array>::Cast(value); |
| 126 result.reserve(scriptsArray->Length()); | 131 result.reserve(scriptsArray->Length()); |
| 127 for (unsigned i = 0; i < scriptsArray->Length(); ++i) { | 132 for (unsigned i = 0; i < scriptsArray->Length(); ++i) { |
| 128 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast( | 133 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast( |
| 129 scriptsArray->Get(v8::Integer::New(m_isolate, i))); | 134 scriptsArray->Get(context, v8::Integer::New(m_isolate, i)) |
| 135 .ToLocalChecked()); |
| 130 result.push_back(wrapUnique( | 136 result.push_back(wrapUnique( |
| 131 new V8DebuggerScript(m_isolate, scriptObject, inLiveEditScope))); | 137 new V8DebuggerScript(context, scriptObject, inLiveEditScope))); |
| 132 } | 138 } |
| 133 } | 139 } |
| 134 | 140 |
| 135 String16 V8Debugger::setBreakpoint(const String16& sourceID, | 141 String16 V8Debugger::setBreakpoint(const String16& sourceID, |
| 136 const ScriptBreakpoint& scriptBreakpoint, | 142 const ScriptBreakpoint& scriptBreakpoint, |
| 137 int* actualLineNumber, | 143 int* actualLineNumber, |
| 138 int* actualColumnNumber) { | 144 int* actualColumnNumber) { |
| 139 v8::HandleScope scope(m_isolate); | 145 v8::HandleScope scope(m_isolate); |
| 140 v8::Context::Scope contextScope(debuggerContext()); | 146 v8::Local<v8::Context> context = debuggerContext(); |
| 147 v8::Context::Scope contextScope(context); |
| 141 | 148 |
| 142 v8::Local<v8::Object> info = v8::Object::New(m_isolate); | 149 v8::Local<v8::Object> info = v8::Object::New(m_isolate); |
| 143 info->Set(toV8StringInternalized(m_isolate, "sourceID"), | 150 bool success = false; |
| 144 toV8String(m_isolate, sourceID)); | 151 success = info->Set(context, toV8StringInternalized(m_isolate, "sourceID"), |
| 145 info->Set(toV8StringInternalized(m_isolate, "lineNumber"), | 152 toV8String(m_isolate, sourceID)) |
| 146 v8::Integer::New(m_isolate, scriptBreakpoint.lineNumber)); | 153 .FromMaybe(false); |
| 147 info->Set(toV8StringInternalized(m_isolate, "columnNumber"), | 154 DCHECK(success); |
| 148 v8::Integer::New(m_isolate, scriptBreakpoint.columnNumber)); | 155 success = info->Set(context, toV8StringInternalized(m_isolate, "lineNumber"), |
| 149 info->Set(toV8StringInternalized(m_isolate, "condition"), | 156 v8::Integer::New(m_isolate, scriptBreakpoint.lineNumber)) |
| 150 toV8String(m_isolate, scriptBreakpoint.condition)); | 157 .FromMaybe(false); |
| 158 DCHECK(success); |
| 159 success = |
| 160 info->Set(context, toV8StringInternalized(m_isolate, "columnNumber"), |
| 161 v8::Integer::New(m_isolate, scriptBreakpoint.columnNumber)) |
| 162 .FromMaybe(false); |
| 163 DCHECK(success); |
| 164 success = info->Set(context, toV8StringInternalized(m_isolate, "condition"), |
| 165 toV8String(m_isolate, scriptBreakpoint.condition)) |
| 166 .FromMaybe(false); |
| 167 DCHECK(success); |
| 151 | 168 |
| 152 v8::Local<v8::Function> setBreakpointFunction = | 169 v8::Local<v8::Function> setBreakpointFunction = v8::Local<v8::Function>::Cast( |
| 153 v8::Local<v8::Function>::Cast(m_debuggerScript.Get(m_isolate)->Get( | 170 m_debuggerScript.Get(m_isolate) |
| 154 toV8StringInternalized(m_isolate, "setBreakpoint"))); | 171 ->Get(context, toV8StringInternalized(m_isolate, "setBreakpoint")) |
| 172 .ToLocalChecked()); |
| 155 v8::Local<v8::Value> breakpointId = | 173 v8::Local<v8::Value> breakpointId = |
| 156 v8::Debug::Call(debuggerContext(), setBreakpointFunction, info) | 174 v8::Debug::Call(debuggerContext(), setBreakpointFunction, info) |
| 157 .ToLocalChecked(); | 175 .ToLocalChecked(); |
| 158 if (!breakpointId->IsString()) return ""; | 176 if (!breakpointId->IsString()) return ""; |
| 159 *actualLineNumber = | 177 *actualLineNumber = |
| 160 info->Get(toV8StringInternalized(m_isolate, "lineNumber"))->Int32Value(); | 178 info->Get(context, toV8StringInternalized(m_isolate, "lineNumber")) |
| 179 .ToLocalChecked() |
| 180 ->Int32Value(context) |
| 181 .FromJust(); |
| 161 *actualColumnNumber = | 182 *actualColumnNumber = |
| 162 info->Get(toV8StringInternalized(m_isolate, "columnNumber")) | 183 info->Get(context, toV8StringInternalized(m_isolate, "columnNumber")) |
| 163 ->Int32Value(); | 184 .ToLocalChecked() |
| 185 ->Int32Value(context) |
| 186 .FromJust(); |
| 164 return toProtocolString(breakpointId.As<v8::String>()); | 187 return toProtocolString(breakpointId.As<v8::String>()); |
| 165 } | 188 } |
| 166 | 189 |
| 167 void V8Debugger::removeBreakpoint(const String16& breakpointId) { | 190 void V8Debugger::removeBreakpoint(const String16& breakpointId) { |
| 168 v8::HandleScope scope(m_isolate); | 191 v8::HandleScope scope(m_isolate); |
| 169 v8::Context::Scope contextScope(debuggerContext()); | 192 v8::Local<v8::Context> context = debuggerContext(); |
| 193 v8::Context::Scope contextScope(context); |
| 170 | 194 |
| 171 v8::Local<v8::Object> info = v8::Object::New(m_isolate); | 195 v8::Local<v8::Object> info = v8::Object::New(m_isolate); |
| 172 info->Set(toV8StringInternalized(m_isolate, "breakpointId"), | 196 bool success = false; |
| 173 toV8String(m_isolate, breakpointId)); | 197 success = |
| 198 info->Set(context, toV8StringInternalized(m_isolate, "breakpointId"), |
| 199 toV8String(m_isolate, breakpointId)) |
| 200 .FromMaybe(false); |
| 201 DCHECK(success); |
| 174 | 202 |
| 175 v8::Local<v8::Function> removeBreakpointFunction = | 203 v8::Local<v8::Function> removeBreakpointFunction = |
| 176 v8::Local<v8::Function>::Cast(m_debuggerScript.Get(m_isolate)->Get( | 204 v8::Local<v8::Function>::Cast( |
| 177 toV8StringInternalized(m_isolate, "removeBreakpoint"))); | 205 m_debuggerScript.Get(m_isolate) |
| 206 ->Get(context, |
| 207 toV8StringInternalized(m_isolate, "removeBreakpoint")) |
| 208 .ToLocalChecked()); |
| 178 v8::Debug::Call(debuggerContext(), removeBreakpointFunction, info) | 209 v8::Debug::Call(debuggerContext(), removeBreakpointFunction, info) |
| 179 .ToLocalChecked(); | 210 .ToLocalChecked(); |
| 180 } | 211 } |
| 181 | 212 |
| 182 void V8Debugger::clearBreakpoints() { | 213 void V8Debugger::clearBreakpoints() { |
| 183 v8::HandleScope scope(m_isolate); | 214 v8::HandleScope scope(m_isolate); |
| 184 v8::Context::Scope contextScope(debuggerContext()); | 215 v8::Local<v8::Context> context = debuggerContext(); |
| 216 v8::Context::Scope contextScope(context); |
| 185 | 217 |
| 186 v8::Local<v8::Function> clearBreakpoints = | 218 v8::Local<v8::Function> clearBreakpoints = v8::Local<v8::Function>::Cast( |
| 187 v8::Local<v8::Function>::Cast(m_debuggerScript.Get(m_isolate)->Get( | 219 m_debuggerScript.Get(m_isolate) |
| 188 toV8StringInternalized(m_isolate, "clearBreakpoints"))); | 220 ->Get(context, toV8StringInternalized(m_isolate, "clearBreakpoints")) |
| 221 .ToLocalChecked()); |
| 189 v8::Debug::Call(debuggerContext(), clearBreakpoints).ToLocalChecked(); | 222 v8::Debug::Call(debuggerContext(), clearBreakpoints).ToLocalChecked(); |
| 190 } | 223 } |
| 191 | 224 |
| 192 void V8Debugger::setBreakpointsActivated(bool activated) { | 225 void V8Debugger::setBreakpointsActivated(bool activated) { |
| 193 if (!enabled()) { | 226 if (!enabled()) { |
| 194 UNREACHABLE(); | 227 UNREACHABLE(); |
| 195 return; | 228 return; |
| 196 } | 229 } |
| 197 v8::HandleScope scope(m_isolate); | 230 v8::HandleScope scope(m_isolate); |
| 198 v8::Context::Scope contextScope(debuggerContext()); | 231 v8::Local<v8::Context> context = debuggerContext(); |
| 232 v8::Context::Scope contextScope(context); |
| 199 | 233 |
| 200 v8::Local<v8::Object> info = v8::Object::New(m_isolate); | 234 v8::Local<v8::Object> info = v8::Object::New(m_isolate); |
| 201 info->Set(toV8StringInternalized(m_isolate, "enabled"), | 235 bool success = false; |
| 202 v8::Boolean::New(m_isolate, activated)); | 236 success = info->Set(context, toV8StringInternalized(m_isolate, "enabled"), |
| 237 v8::Boolean::New(m_isolate, activated)) |
| 238 .FromMaybe(false); |
| 239 DCHECK(success); |
| 203 v8::Local<v8::Function> setBreakpointsActivated = | 240 v8::Local<v8::Function> setBreakpointsActivated = |
| 204 v8::Local<v8::Function>::Cast(m_debuggerScript.Get(m_isolate)->Get( | 241 v8::Local<v8::Function>::Cast( |
| 205 toV8StringInternalized(m_isolate, "setBreakpointsActivated"))); | 242 m_debuggerScript.Get(m_isolate) |
| 243 ->Get(context, toV8StringInternalized(m_isolate, |
| 244 "setBreakpointsActivated")) |
| 245 .ToLocalChecked()); |
| 206 v8::Debug::Call(debuggerContext(), setBreakpointsActivated, info) | 246 v8::Debug::Call(debuggerContext(), setBreakpointsActivated, info) |
| 207 .ToLocalChecked(); | 247 .ToLocalChecked(); |
| 208 | 248 |
| 209 m_breakpointsActivated = activated; | 249 m_breakpointsActivated = activated; |
| 210 } | 250 } |
| 211 | 251 |
| 212 V8Debugger::PauseOnExceptionsState V8Debugger::getPauseOnExceptionsState() { | 252 V8Debugger::PauseOnExceptionsState V8Debugger::getPauseOnExceptionsState() { |
| 213 DCHECK(enabled()); | 253 DCHECK(enabled()); |
| 214 v8::HandleScope scope(m_isolate); | 254 v8::HandleScope scope(m_isolate); |
| 215 v8::Context::Scope contextScope(debuggerContext()); | 255 v8::Local<v8::Context> context = debuggerContext(); |
| 256 v8::Context::Scope contextScope(context); |
| 216 | 257 |
| 217 v8::Local<v8::Value> argv[] = {v8::Undefined(m_isolate)}; | 258 v8::Local<v8::Value> argv[] = {v8::Undefined(m_isolate)}; |
| 218 v8::Local<v8::Value> result = | 259 v8::Local<v8::Value> result = |
| 219 callDebuggerMethod("pauseOnExceptionsState", 0, argv).ToLocalChecked(); | 260 callDebuggerMethod("pauseOnExceptionsState", 0, argv).ToLocalChecked(); |
| 220 return static_cast<V8Debugger::PauseOnExceptionsState>(result->Int32Value()); | 261 return static_cast<V8Debugger::PauseOnExceptionsState>( |
| 262 result->Int32Value(context).FromJust()); |
| 221 } | 263 } |
| 222 | 264 |
| 223 void V8Debugger::setPauseOnExceptionsState( | 265 void V8Debugger::setPauseOnExceptionsState( |
| 224 PauseOnExceptionsState pauseOnExceptionsState) { | 266 PauseOnExceptionsState pauseOnExceptionsState) { |
| 225 DCHECK(enabled()); | 267 DCHECK(enabled()); |
| 226 v8::HandleScope scope(m_isolate); | 268 v8::HandleScope scope(m_isolate); |
| 227 v8::Context::Scope contextScope(debuggerContext()); | 269 v8::Context::Scope contextScope(debuggerContext()); |
| 228 | 270 |
| 229 v8::Local<v8::Value> argv[] = { | 271 v8::Local<v8::Value> argv[] = { |
| 230 v8::Int32::New(m_isolate, pauseOnExceptionsState)}; | 272 v8::Int32::New(m_isolate, pauseOnExceptionsState)}; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 v8::Local<v8::Message> message = tryCatch.Message(); | 392 v8::Local<v8::Message> message = tryCatch.Message(); |
| 351 if (!message.IsEmpty()) | 393 if (!message.IsEmpty()) |
| 352 *error = toProtocolStringWithTypeCheck(message->Get()); | 394 *error = toProtocolStringWithTypeCheck(message->Get()); |
| 353 else | 395 else |
| 354 *error = "Unknown error."; | 396 *error = "Unknown error."; |
| 355 return false; | 397 return false; |
| 356 } | 398 } |
| 357 v8result = maybeResult.ToLocalChecked(); | 399 v8result = maybeResult.ToLocalChecked(); |
| 358 } | 400 } |
| 359 DCHECK(!v8result.IsEmpty()); | 401 DCHECK(!v8result.IsEmpty()); |
| 360 v8::Local<v8::Object> resultTuple = v8result->ToObject(m_isolate); | 402 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); |
| 361 int code = | 403 v8::Local<v8::Object> resultTuple = |
| 362 static_cast<int>(resultTuple->Get(0)->ToInteger(m_isolate)->Value()); | 404 v8result->ToObject(context).ToLocalChecked(); |
| 405 int code = static_cast<int>(resultTuple->Get(context, 0) |
| 406 .ToLocalChecked() |
| 407 ->ToInteger(context) |
| 408 .ToLocalChecked() |
| 409 ->Value()); |
| 363 switch (code) { | 410 switch (code) { |
| 364 case 0: { | 411 case 0: { |
| 365 *stackChanged = resultTuple->Get(1)->BooleanValue(); | 412 *stackChanged = resultTuple->Get(context, 1) |
| 413 .ToLocalChecked() |
| 414 ->BooleanValue(context) |
| 415 .FromJust(); |
| 366 // Call stack may have changed after if the edited function was on the | 416 // Call stack may have changed after if the edited function was on the |
| 367 // stack. | 417 // stack. |
| 368 if (!dryRun && isPaused()) { | 418 if (!dryRun && isPaused()) { |
| 369 JavaScriptCallFrames frames = currentCallFrames(); | 419 JavaScriptCallFrames frames = currentCallFrames(); |
| 370 newCallFrames->swap(frames); | 420 newCallFrames->swap(frames); |
| 371 } | 421 } |
| 372 return true; | 422 return true; |
| 373 } | 423 } |
| 374 // Compile error. | 424 // Compile error. |
| 375 case 1: { | 425 case 1: { |
| 376 *exceptionDetails = | 426 *exceptionDetails = |
| 377 protocol::Runtime::ExceptionDetails::create() | 427 protocol::Runtime::ExceptionDetails::create() |
| 378 .setExceptionId(m_inspector->nextExceptionId()) | 428 .setExceptionId(m_inspector->nextExceptionId()) |
| 379 .setText(toProtocolStringWithTypeCheck(resultTuple->Get(2))) | 429 .setText(toProtocolStringWithTypeCheck( |
| 380 .setLineNumber( | 430 resultTuple->Get(context, 2).ToLocalChecked())) |
| 381 resultTuple->Get(3)->ToInteger(m_isolate)->Value() - 1) | 431 .setLineNumber(resultTuple->Get(context, 3) |
| 382 .setColumnNumber( | 432 .ToLocalChecked() |
| 383 resultTuple->Get(4)->ToInteger(m_isolate)->Value() - 1) | 433 ->ToInteger(context) |
| 434 .ToLocalChecked() |
| 435 ->Value() - |
| 436 1) |
| 437 .setColumnNumber(resultTuple->Get(context, 4) |
| 438 .ToLocalChecked() |
| 439 ->ToInteger(context) |
| 440 .ToLocalChecked() |
| 441 ->Value() - |
| 442 1) |
| 384 .build(); | 443 .build(); |
| 385 return false; | 444 return false; |
| 386 } | 445 } |
| 387 } | 446 } |
| 388 *error = "Unknown error."; | 447 *error = "Unknown error."; |
| 389 return false; | 448 return false; |
| 390 } | 449 } |
| 391 | 450 |
| 392 JavaScriptCallFrames V8Debugger::currentCallFrames(int limit) { | 451 JavaScriptCallFrames V8Debugger::currentCallFrames(int limit) { |
| 393 if (!m_isolate->InContext()) return JavaScriptCallFrames(); | 452 if (!m_isolate->InContext()) return JavaScriptCallFrames(); |
| 394 v8::Local<v8::Value> currentCallFramesV8; | 453 v8::Local<v8::Value> currentCallFramesV8; |
| 395 if (m_executionState.IsEmpty()) { | 454 if (m_executionState.IsEmpty()) { |
| 396 v8::Local<v8::Function> currentCallFramesFunction = | 455 v8::Local<v8::Function> currentCallFramesFunction = |
| 397 v8::Local<v8::Function>::Cast(m_debuggerScript.Get(m_isolate)->Get( | 456 v8::Local<v8::Function>::Cast( |
| 398 toV8StringInternalized(m_isolate, "currentCallFrames"))); | 457 m_debuggerScript.Get(m_isolate) |
| 458 ->Get(debuggerContext(), |
| 459 toV8StringInternalized(m_isolate, "currentCallFrames")) |
| 460 .ToLocalChecked()); |
| 399 currentCallFramesV8 = | 461 currentCallFramesV8 = |
| 400 v8::Debug::Call(debuggerContext(), currentCallFramesFunction, | 462 v8::Debug::Call(debuggerContext(), currentCallFramesFunction, |
| 401 v8::Integer::New(m_isolate, limit)) | 463 v8::Integer::New(m_isolate, limit)) |
| 402 .ToLocalChecked(); | 464 .ToLocalChecked(); |
| 403 } else { | 465 } else { |
| 404 v8::Local<v8::Value> argv[] = {m_executionState, | 466 v8::Local<v8::Value> argv[] = {m_executionState, |
| 405 v8::Integer::New(m_isolate, limit)}; | 467 v8::Integer::New(m_isolate, limit)}; |
| 406 currentCallFramesV8 = | 468 currentCallFramesV8 = |
| 407 callDebuggerMethod("currentCallFrames", V8_INSPECTOR_ARRAY_LENGTH(argv), | 469 callDebuggerMethod("currentCallFrames", V8_INSPECTOR_ARRAY_LENGTH(argv), |
| 408 argv) | 470 argv) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 if (m_runningNestedMessageLoop) return; | 514 if (m_runningNestedMessageLoop) return; |
| 453 | 515 |
| 454 V8DebuggerAgentImpl* agent = | 516 V8DebuggerAgentImpl* agent = |
| 455 m_inspector->enabledDebuggerAgentForGroup(getGroupId(pausedContext)); | 517 m_inspector->enabledDebuggerAgentForGroup(getGroupId(pausedContext)); |
| 456 if (!agent) return; | 518 if (!agent) return; |
| 457 | 519 |
| 458 std::vector<String16> breakpointIds; | 520 std::vector<String16> breakpointIds; |
| 459 if (!hitBreakpointNumbers.IsEmpty()) { | 521 if (!hitBreakpointNumbers.IsEmpty()) { |
| 460 breakpointIds.reserve(hitBreakpointNumbers->Length()); | 522 breakpointIds.reserve(hitBreakpointNumbers->Length()); |
| 461 for (size_t i = 0; i < hitBreakpointNumbers->Length(); i++) { | 523 for (size_t i = 0; i < hitBreakpointNumbers->Length(); i++) { |
| 462 v8::Local<v8::Value> hitBreakpointNumber = hitBreakpointNumbers->Get(i); | 524 v8::Local<v8::Value> hitBreakpointNumber = |
| 463 DCHECK(!hitBreakpointNumber.IsEmpty() && hitBreakpointNumber->IsInt32()); | 525 hitBreakpointNumbers->Get(debuggerContext(), i).ToLocalChecked(); |
| 464 breakpointIds.push_back( | 526 DCHECK(hitBreakpointNumber->IsInt32()); |
| 465 String16::fromInteger(hitBreakpointNumber->Int32Value())); | 527 breakpointIds.push_back(String16::fromInteger( |
| 528 hitBreakpointNumber->Int32Value(debuggerContext()).FromJust())); |
| 466 } | 529 } |
| 467 } | 530 } |
| 468 | 531 |
| 469 m_pausedContext = pausedContext; | 532 m_pausedContext = pausedContext; |
| 470 m_executionState = executionState; | 533 m_executionState = executionState; |
| 471 V8DebuggerAgentImpl::SkipPauseRequest result = agent->didPause( | 534 V8DebuggerAgentImpl::SkipPauseRequest result = agent->didPause( |
| 472 pausedContext, exception, breakpointIds, isPromiseRejection); | 535 pausedContext, exception, breakpointIds, isPromiseRejection); |
| 473 if (result == V8DebuggerAgentImpl::RequestNoSkip) { | 536 if (result == V8DebuggerAgentImpl::RequestNoSkip) { |
| 474 m_runningNestedMessageLoop = true; | 537 m_runningNestedMessageLoop = true; |
| 475 int groupId = getGroupId(pausedContext); | 538 int groupId = getGroupId(pausedContext); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 500 const v8::Debug::EventDetails& eventDetails) { | 563 const v8::Debug::EventDetails& eventDetails) { |
| 501 V8Debugger* thisPtr = toV8Debugger(eventDetails.GetCallbackData()); | 564 V8Debugger* thisPtr = toV8Debugger(eventDetails.GetCallbackData()); |
| 502 thisPtr->handleV8DebugEvent(eventDetails); | 565 thisPtr->handleV8DebugEvent(eventDetails); |
| 503 } | 566 } |
| 504 | 567 |
| 505 v8::Local<v8::Value> V8Debugger::callInternalGetterFunction( | 568 v8::Local<v8::Value> V8Debugger::callInternalGetterFunction( |
| 506 v8::Local<v8::Object> object, const char* functionName) { | 569 v8::Local<v8::Object> object, const char* functionName) { |
| 507 v8::MicrotasksScope microtasks(m_isolate, | 570 v8::MicrotasksScope microtasks(m_isolate, |
| 508 v8::MicrotasksScope::kDoNotRunMicrotasks); | 571 v8::MicrotasksScope::kDoNotRunMicrotasks); |
| 509 v8::Local<v8::Value> getterValue = | 572 v8::Local<v8::Value> getterValue = |
| 510 object->Get(toV8StringInternalized(m_isolate, functionName)); | 573 object |
| 574 ->Get(m_isolate->GetCurrentContext(), |
| 575 toV8StringInternalized(m_isolate, functionName)) |
| 576 .ToLocalChecked(); |
| 511 DCHECK(!getterValue.IsEmpty() && getterValue->IsFunction()); | 577 DCHECK(!getterValue.IsEmpty() && getterValue->IsFunction()); |
| 512 return v8::Local<v8::Function>::Cast(getterValue) | 578 return v8::Local<v8::Function>::Cast(getterValue) |
| 513 ->Call(m_isolate->GetCurrentContext(), object, 0, 0) | 579 ->Call(m_isolate->GetCurrentContext(), object, 0, 0) |
| 514 .ToLocalChecked(); | 580 .ToLocalChecked(); |
| 515 } | 581 } |
| 516 | 582 |
| 517 void V8Debugger::handleV8DebugEvent( | 583 void V8Debugger::handleV8DebugEvent( |
| 518 const v8::Debug::EventDetails& eventDetails) { | 584 const v8::Debug::EventDetails& eventDetails) { |
| 519 if (!enabled()) return; | 585 if (!enabled()) return; |
| 520 v8::DebugEvent event = eventDetails.GetEvent(); | 586 v8::DebugEvent event = eventDetails.GetEvent(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 539 v8::HandleScope scope(m_isolate); | 605 v8::HandleScope scope(m_isolate); |
| 540 if (m_ignoreScriptParsedEventsCounter == 0 && | 606 if (m_ignoreScriptParsedEventsCounter == 0 && |
| 541 (event == v8::AfterCompile || event == v8::CompileError)) { | 607 (event == v8::AfterCompile || event == v8::CompileError)) { |
| 542 v8::Context::Scope contextScope(debuggerContext()); | 608 v8::Context::Scope contextScope(debuggerContext()); |
| 543 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; | 609 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; |
| 544 v8::Local<v8::Value> value = | 610 v8::Local<v8::Value> value = |
| 545 callDebuggerMethod("getAfterCompileScript", 1, argv).ToLocalChecked(); | 611 callDebuggerMethod("getAfterCompileScript", 1, argv).ToLocalChecked(); |
| 546 if (value->IsNull()) return; | 612 if (value->IsNull()) return; |
| 547 DCHECK(value->IsObject()); | 613 DCHECK(value->IsObject()); |
| 548 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast(value); | 614 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast(value); |
| 549 agent->didParseSource(wrapUnique(new V8DebuggerScript( | 615 agent->didParseSource( |
| 550 m_isolate, scriptObject, inLiveEditScope)), | 616 wrapUnique(new V8DebuggerScript(debuggerContext(), scriptObject, |
| 551 event == v8::AfterCompile); | 617 inLiveEditScope)), |
| 618 event == v8::AfterCompile); |
| 552 } else if (event == v8::Exception) { | 619 } else if (event == v8::Exception) { |
| 553 v8::Local<v8::Object> eventData = eventDetails.GetEventData(); | 620 v8::Local<v8::Object> eventData = eventDetails.GetEventData(); |
| 554 v8::Local<v8::Value> exception = | 621 v8::Local<v8::Value> exception = |
| 555 callInternalGetterFunction(eventData, "exception"); | 622 callInternalGetterFunction(eventData, "exception"); |
| 556 v8::Local<v8::Value> promise = | 623 v8::Local<v8::Value> promise = |
| 557 callInternalGetterFunction(eventData, "promise"); | 624 callInternalGetterFunction(eventData, "promise"); |
| 558 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); | 625 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); |
| 559 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), | 626 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), |
| 560 exception, v8::Local<v8::Array>(), isPromiseRejection); | 627 exception, v8::Local<v8::Array>(), isPromiseRejection); |
| 561 } else if (event == v8::Break) { | 628 } else if (event == v8::Break) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 573 void V8Debugger::handleV8AsyncTaskEvent(v8::Local<v8::Context> context, | 640 void V8Debugger::handleV8AsyncTaskEvent(v8::Local<v8::Context> context, |
| 574 v8::Local<v8::Object> executionState, | 641 v8::Local<v8::Object> executionState, |
| 575 v8::Local<v8::Object> eventData) { | 642 v8::Local<v8::Object> eventData) { |
| 576 if (!m_maxAsyncCallStackDepth) return; | 643 if (!m_maxAsyncCallStackDepth) return; |
| 577 | 644 |
| 578 String16 type = toProtocolStringWithTypeCheck( | 645 String16 type = toProtocolStringWithTypeCheck( |
| 579 callInternalGetterFunction(eventData, "type")); | 646 callInternalGetterFunction(eventData, "type")); |
| 580 String16 name = toProtocolStringWithTypeCheck( | 647 String16 name = toProtocolStringWithTypeCheck( |
| 581 callInternalGetterFunction(eventData, "name")); | 648 callInternalGetterFunction(eventData, "name")); |
| 582 int id = callInternalGetterFunction(eventData, "id") | 649 int id = callInternalGetterFunction(eventData, "id") |
| 583 ->ToInteger(m_isolate) | 650 ->ToInteger(context) |
| 651 .ToLocalChecked() |
| 584 ->Value(); | 652 ->Value(); |
| 585 // The scopes for the ids are defined by the eventData.name namespaces. There | 653 // The scopes for the ids are defined by the eventData.name namespaces. There |
| 586 // are currently two namespaces: "Object." and "Promise.". | 654 // are currently two namespaces: "Object." and "Promise.". |
| 587 void* ptr = reinterpret_cast<void*>(id * 4 + (name[0] == 'P' ? 2 : 0) + 1); | 655 void* ptr = reinterpret_cast<void*>(id * 4 + (name[0] == 'P' ? 2 : 0) + 1); |
| 588 if (type == v8AsyncTaskEventEnqueue) | 656 if (type == v8AsyncTaskEventEnqueue) |
| 589 asyncTaskScheduled(name, ptr, false); | 657 asyncTaskScheduled(name, ptr, false); |
| 590 else if (type == v8AsyncTaskEventWillHandle) | 658 else if (type == v8AsyncTaskEventWillHandle) |
| 591 asyncTaskStarted(ptr); | 659 asyncTaskStarted(ptr); |
| 592 else if (type == v8AsyncTaskEventDidHandle) | 660 else if (type == v8AsyncTaskEventDidHandle) |
| 593 asyncTaskFinished(ptr); | 661 asyncTaskFinished(ptr); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 | 975 |
| 908 size_t stackSize = | 976 size_t stackSize = |
| 909 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; | 977 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; |
| 910 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) | 978 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) |
| 911 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; | 979 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; |
| 912 | 980 |
| 913 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); | 981 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); |
| 914 } | 982 } |
| 915 | 983 |
| 916 } // namespace v8_inspector | 984 } // namespace v8_inspector |
| OLD | NEW |