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