| 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/v8-debugger.h" | 5 #include "src/inspector/v8-debugger.h" |
| 6 | 6 |
| 7 #include "src/inspector/debugger-script.h" | 7 #include "src/inspector/debugger-script.h" |
| 8 #include "src/inspector/inspected-context.h" | 8 #include "src/inspector/inspected-context.h" |
| 9 #include "src/inspector/protocol/Protocol.h" | 9 #include "src/inspector/protocol/Protocol.h" |
| 10 #include "src/inspector/script-breakpoint.h" | 10 #include "src/inspector/script-breakpoint.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 const char* functionName, int argc, v8::Local<v8::Value> argv[]) { | 43 const char* functionName, int argc, v8::Local<v8::Value> argv[]) { |
| 44 v8::MicrotasksScope microtasks(m_isolate, | 44 v8::MicrotasksScope microtasks(m_isolate, |
| 45 v8::MicrotasksScope::kDoNotRunMicrotasks); | 45 v8::MicrotasksScope::kDoNotRunMicrotasks); |
| 46 DCHECK(m_isolate->InContext()); | 46 DCHECK(m_isolate->InContext()); |
| 47 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); | 47 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); |
| 48 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); | 48 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); |
| 49 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 49 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 50 debuggerScript | 50 debuggerScript |
| 51 ->Get(context, toV8StringInternalized(m_isolate, functionName)) | 51 ->Get(context, toV8StringInternalized(m_isolate, functionName)) |
| 52 .ToLocalChecked()); | 52 .ToLocalChecked()); |
| 53 v8::TryCatch try_catch(m_isolate); | |
| 54 return function->Call(context, debuggerScript, argc, argv); | 53 return function->Call(context, debuggerScript, argc, argv); |
| 55 } | 54 } |
| 56 | 55 |
| 57 V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector) | 56 V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector) |
| 58 : m_isolate(isolate), | 57 : m_isolate(isolate), |
| 59 m_inspector(inspector), | 58 m_inspector(inspector), |
| 60 m_enableCount(0), | 59 m_enableCount(0), |
| 61 m_breakpointsActivated(true), | 60 m_breakpointsActivated(true), |
| 62 m_runningNestedMessageLoop(false), | 61 m_runningNestedMessageLoop(false), |
| 63 m_ignoreScriptParsedEventsCounter(0), | 62 m_ignoreScriptParsedEventsCounter(0), |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 JavaScriptCallFrames V8Debugger::currentCallFrames(int limit) { | 402 JavaScriptCallFrames V8Debugger::currentCallFrames(int limit) { |
| 404 if (!m_isolate->InContext()) return JavaScriptCallFrames(); | 403 if (!m_isolate->InContext()) return JavaScriptCallFrames(); |
| 405 v8::Local<v8::Value> currentCallFramesV8; | 404 v8::Local<v8::Value> currentCallFramesV8; |
| 406 if (m_executionState.IsEmpty()) { | 405 if (m_executionState.IsEmpty()) { |
| 407 v8::Local<v8::Function> currentCallFramesFunction = | 406 v8::Local<v8::Function> currentCallFramesFunction = |
| 408 v8::Local<v8::Function>::Cast( | 407 v8::Local<v8::Function>::Cast( |
| 409 m_debuggerScript.Get(m_isolate) | 408 m_debuggerScript.Get(m_isolate) |
| 410 ->Get(debuggerContext(), | 409 ->Get(debuggerContext(), |
| 411 toV8StringInternalized(m_isolate, "currentCallFrames")) | 410 toV8StringInternalized(m_isolate, "currentCallFrames")) |
| 412 .ToLocalChecked()); | 411 .ToLocalChecked()); |
| 413 if (!v8::debug::Call(debuggerContext(), currentCallFramesFunction, | 412 currentCallFramesV8 = |
| 414 v8::Integer::New(m_isolate, limit)) | 413 v8::debug::Call(debuggerContext(), currentCallFramesFunction, |
| 415 .ToLocal(¤tCallFramesV8)) | 414 v8::Integer::New(m_isolate, limit)) |
| 416 return JavaScriptCallFrames(); | 415 .ToLocalChecked(); |
| 417 } else { | 416 } else { |
| 418 v8::Local<v8::Value> argv[] = {m_executionState, | 417 v8::Local<v8::Value> argv[] = {m_executionState, |
| 419 v8::Integer::New(m_isolate, limit)}; | 418 v8::Integer::New(m_isolate, limit)}; |
| 420 if (!callDebuggerMethod("currentCallFrames", arraysize(argv), argv) | 419 currentCallFramesV8 = |
| 421 .ToLocal(¤tCallFramesV8)) | 420 callDebuggerMethod("currentCallFrames", arraysize(argv), argv) |
| 422 return JavaScriptCallFrames(); | 421 .ToLocalChecked(); |
| 423 } | 422 } |
| 424 DCHECK(!currentCallFramesV8.IsEmpty()); | 423 DCHECK(!currentCallFramesV8.IsEmpty()); |
| 425 if (!currentCallFramesV8->IsArray()) return JavaScriptCallFrames(); | 424 if (!currentCallFramesV8->IsArray()) return JavaScriptCallFrames(); |
| 426 v8::Local<v8::Array> callFramesArray = currentCallFramesV8.As<v8::Array>(); | 425 v8::Local<v8::Array> callFramesArray = currentCallFramesV8.As<v8::Array>(); |
| 427 JavaScriptCallFrames callFrames; | 426 JavaScriptCallFrames callFrames; |
| 428 for (uint32_t i = 0; i < callFramesArray->Length(); ++i) { | 427 for (uint32_t i = 0; i < callFramesArray->Length(); ++i) { |
| 429 v8::Local<v8::Value> callFrameValue; | 428 v8::Local<v8::Value> callFrameValue; |
| 430 if (!callFramesArray->Get(debuggerContext(), i).ToLocal(&callFrameValue)) | 429 if (!callFramesArray->Get(debuggerContext(), i).ToLocal(&callFrameValue)) |
| 431 return JavaScriptCallFrames(); | 430 return JavaScriptCallFrames(); |
| 432 if (!callFrameValue->IsObject()) return JavaScriptCallFrames(); | 431 if (!callFrameValue->IsObject()) return JavaScriptCallFrames(); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 callInternalGetterFunction(eventData, "promise"); | 581 callInternalGetterFunction(eventData, "promise"); |
| 583 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); | 582 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); |
| 584 v8::Local<v8::Value> uncaught = | 583 v8::Local<v8::Value> uncaught = |
| 585 callInternalGetterFunction(eventData, "uncaught"); | 584 callInternalGetterFunction(eventData, "uncaught"); |
| 586 bool isUncaught = uncaught->BooleanValue(context).FromJust(); | 585 bool isUncaught = uncaught->BooleanValue(context).FromJust(); |
| 587 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), | 586 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), |
| 588 exception, v8::Local<v8::Array>(), isPromiseRejection, | 587 exception, v8::Local<v8::Array>(), isPromiseRejection, |
| 589 isUncaught); | 588 isUncaught); |
| 590 } else if (event == v8::Break) { | 589 } else if (event == v8::Break) { |
| 591 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; | 590 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; |
| 592 v8::Local<v8::Value> hitBreakpoints; | 591 v8::Local<v8::Value> hitBreakpoints = |
| 593 if (!callDebuggerMethod("getBreakpointNumbers", 1, argv) | 592 callDebuggerMethod("getBreakpointNumbers", 1, argv).ToLocalChecked(); |
| 594 .ToLocal(&hitBreakpoints)) | |
| 595 return; | |
| 596 DCHECK(hitBreakpoints->IsArray()); | 593 DCHECK(hitBreakpoints->IsArray()); |
| 597 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), | 594 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), |
| 598 v8::Local<v8::Value>(), hitBreakpoints.As<v8::Array>()); | 595 v8::Local<v8::Value>(), hitBreakpoints.As<v8::Array>()); |
| 599 } | 596 } |
| 600 } | 597 } |
| 601 | 598 |
| 602 void V8Debugger::handleV8AsyncTaskEvent(v8::Local<v8::Context> context, | 599 void V8Debugger::handleV8AsyncTaskEvent(v8::Local<v8::Context> context, |
| 603 v8::Local<v8::Object> executionState, | 600 v8::Local<v8::Object> executionState, |
| 604 v8::Local<v8::Object> eventData) { | 601 v8::Local<v8::Object> eventData) { |
| 605 if (!m_maxAsyncCallStackDepth) return; | 602 if (!m_maxAsyncCallStackDepth) return; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 return properties; | 770 return properties; |
| 774 } | 771 } |
| 775 | 772 |
| 776 v8::Local<v8::Value> V8Debugger::collectionEntries( | 773 v8::Local<v8::Value> V8Debugger::collectionEntries( |
| 777 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { | 774 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { |
| 778 if (!enabled()) { | 775 if (!enabled()) { |
| 779 UNREACHABLE(); | 776 UNREACHABLE(); |
| 780 return v8::Undefined(m_isolate); | 777 return v8::Undefined(m_isolate); |
| 781 } | 778 } |
| 782 v8::Local<v8::Value> argv[] = {object}; | 779 v8::Local<v8::Value> argv[] = {object}; |
| 783 v8::Local<v8::Value> entriesValue; | 780 v8::Local<v8::Value> entriesValue = |
| 784 if (!callDebuggerMethod("getCollectionEntries", 1, argv) | 781 callDebuggerMethod("getCollectionEntries", 1, argv).ToLocalChecked(); |
| 785 .ToLocal(&entriesValue) || | 782 if (!entriesValue->IsArray()) return v8::Undefined(m_isolate); |
| 786 !entriesValue->IsArray()) | |
| 787 return v8::Undefined(m_isolate); | |
| 788 | 783 |
| 789 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>(); | 784 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>(); |
| 790 v8::Local<v8::Array> copiedArray = | 785 v8::Local<v8::Array> copiedArray = |
| 791 v8::Array::New(m_isolate, entries->Length()); | 786 v8::Array::New(m_isolate, entries->Length()); |
| 792 if (!copiedArray->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) | 787 if (!copiedArray->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) |
| 793 return v8::Undefined(m_isolate); | 788 return v8::Undefined(m_isolate); |
| 794 for (uint32_t i = 0; i < entries->Length(); ++i) { | 789 for (uint32_t i = 0; i < entries->Length(); ++i) { |
| 795 v8::Local<v8::Value> item; | 790 v8::Local<v8::Value> item; |
| 796 if (!entries->Get(debuggerContext(), i).ToLocal(&item)) | 791 if (!entries->Get(debuggerContext(), i).ToLocal(&item)) |
| 797 return v8::Undefined(m_isolate); | 792 return v8::Undefined(m_isolate); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 810 return copiedArray; | 805 return copiedArray; |
| 811 } | 806 } |
| 812 | 807 |
| 813 v8::Local<v8::Value> V8Debugger::generatorObjectLocation( | 808 v8::Local<v8::Value> V8Debugger::generatorObjectLocation( |
| 814 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { | 809 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { |
| 815 if (!enabled()) { | 810 if (!enabled()) { |
| 816 UNREACHABLE(); | 811 UNREACHABLE(); |
| 817 return v8::Null(m_isolate); | 812 return v8::Null(m_isolate); |
| 818 } | 813 } |
| 819 v8::Local<v8::Value> argv[] = {object}; | 814 v8::Local<v8::Value> argv[] = {object}; |
| 820 v8::Local<v8::Value> location; | 815 v8::Local<v8::Value> location = |
| 816 callDebuggerMethod("getGeneratorObjectLocation", 1, argv) |
| 817 .ToLocalChecked(); |
| 821 v8::Local<v8::Value> copied; | 818 v8::Local<v8::Value> copied; |
| 822 if (!callDebuggerMethod("getGeneratorObjectLocation", 1, argv) | 819 if (!copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, |
| 823 .ToLocal(&location) || | |
| 824 !copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, | |
| 825 location) | 820 location) |
| 826 .ToLocal(&copied) || | 821 .ToLocal(&copied) || |
| 827 !copied->IsObject()) | 822 !copied->IsObject()) |
| 828 return v8::Null(m_isolate); | 823 return v8::Null(m_isolate); |
| 829 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(copied), | 824 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(copied), |
| 830 V8InternalValueType::kLocation)) | 825 V8InternalValueType::kLocation)) |
| 831 return v8::Null(m_isolate); | 826 return v8::Null(m_isolate); |
| 832 return copied; | 827 return copied; |
| 833 } | 828 } |
| 834 | 829 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 | 993 |
| 999 size_t stackSize = | 994 size_t stackSize = |
| 1000 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; | 995 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; |
| 1001 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) | 996 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) |
| 1002 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; | 997 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; |
| 1003 | 998 |
| 1004 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); | 999 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); |
| 1005 } | 1000 } |
| 1006 | 1001 |
| 1007 } // namespace v8_inspector | 1002 } // namespace v8_inspector |
| OLD | NEW |