| 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/protocol/Protocol.h" | 8 #include "src/inspector/protocol/Protocol.h" |
| 9 #include "src/inspector/script-breakpoint.h" | 9 #include "src/inspector/script-breakpoint.h" |
| 10 #include "src/inspector/string-util.h" | 10 #include "src/inspector/string-util.h" |
| 11 #include "src/inspector/v8-debugger-agent-impl.h" | 11 #include "src/inspector/v8-debugger-agent-impl.h" |
| 12 #include "src/inspector/v8-inspector-impl.h" | 12 #include "src/inspector/v8-inspector-impl.h" |
| 13 #include "src/inspector/v8-internal-value-type.h" | 13 #include "src/inspector/v8-internal-value-type.h" |
| 14 #include "src/inspector/v8-stack-trace-impl.h" | 14 #include "src/inspector/v8-stack-trace-impl.h" |
| 15 #include "src/inspector/v8-value-copier.h" | 15 #include "src/inspector/v8-value-copier.h" |
| 16 | 16 |
| 17 #include "include/v8-util.h" |
| 18 |
| 17 namespace v8_inspector { | 19 namespace v8_inspector { |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 static const char v8AsyncTaskEventEnqueue[] = "enqueue"; | 22 static const char v8AsyncTaskEventEnqueue[] = "enqueue"; |
| 21 static const char v8AsyncTaskEventEnqueueRecurring[] = "enqueueRecurring"; | 23 static const char v8AsyncTaskEventEnqueueRecurring[] = "enqueueRecurring"; |
| 22 static const char v8AsyncTaskEventWillHandle[] = "willHandle"; | 24 static const char v8AsyncTaskEventWillHandle[] = "willHandle"; |
| 23 static const char v8AsyncTaskEventDidHandle[] = "didHandle"; | 25 static const char v8AsyncTaskEventDidHandle[] = "didHandle"; |
| 24 static const char v8AsyncTaskEventCancel[] = "cancel"; | 26 static const char v8AsyncTaskEventCancel[] = "cancel"; |
| 25 | 27 |
| 26 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) { | 28 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 if (dataString.isEmpty()) return 0; | 111 if (dataString.isEmpty()) return 0; |
| 110 size_t commaPos = dataString.find(","); | 112 size_t commaPos = dataString.find(","); |
| 111 if (commaPos == String16::kNotFound) return 0; | 113 if (commaPos == String16::kNotFound) return 0; |
| 112 return dataString.substring(0, commaPos).toInteger(); | 114 return dataString.substring(0, commaPos).toInteger(); |
| 113 } | 115 } |
| 114 | 116 |
| 115 void V8Debugger::getCompiledScripts( | 117 void V8Debugger::getCompiledScripts( |
| 116 int contextGroupId, | 118 int contextGroupId, |
| 117 std::vector<std::unique_ptr<V8DebuggerScript>>& result) { | 119 std::vector<std::unique_ptr<V8DebuggerScript>>& result) { |
| 118 v8::HandleScope scope(m_isolate); | 120 v8::HandleScope scope(m_isolate); |
| 119 v8::MicrotasksScope microtasks(m_isolate, | |
| 120 v8::MicrotasksScope::kDoNotRunMicrotasks); | |
| 121 v8::Local<v8::Context> context = debuggerContext(); | 121 v8::Local<v8::Context> context = debuggerContext(); |
| 122 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); | 122 v8::Context::Scope contextScope(context); |
| 123 DCHECK(!debuggerScript->IsUndefined()); | 123 |
| 124 v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast( | 124 v8::PersistentValueVector<v8::DebugInterface::Script> scripts(m_isolate); |
| 125 debuggerScript | 125 v8::DebugInterface::GetLoadedScripts(m_isolate, scripts); |
| 126 ->Get(context, toV8StringInternalized(m_isolate, "getScripts")) | 126 String16 contextPrefix = String16::fromInteger(contextGroupId) + ","; |
| 127 .ToLocalChecked()); | 127 for (size_t i = 0; i < scripts.Size(); ++i) { |
| 128 v8::Local<v8::Value> argv[] = {v8::Integer::New(m_isolate, contextGroupId)}; | 128 v8::Local<v8::DebugInterface::Script> script = scripts.Get(i); |
| 129 v8::Local<v8::Value> value; | 129 if (!script->WasCompiled()) continue; |
| 130 if (!getScriptsFunction->Call(context, debuggerScript, arraysize(argv), argv) | 130 v8::ScriptOriginOptions origin = script->OriginOptions(); |
| 131 .ToLocal(&value)) | 131 if (origin.IsEmbedderDebugScript()) continue; |
| 132 return; | 132 v8::Local<v8::String> v8ContextData; |
| 133 DCHECK(value->IsArray()); | 133 if (!script->ContextData(context).ToLocal(&v8ContextData)) continue; |
| 134 v8::Local<v8::Array> scriptsArray = v8::Local<v8::Array>::Cast(value); | 134 String16 contextData = toProtocolString(v8ContextData); |
| 135 result.reserve(scriptsArray->Length()); | 135 if (contextData.find(contextPrefix) != 0) continue; |
| 136 for (unsigned i = 0; i < scriptsArray->Length(); ++i) { | 136 result.push_back(wrapUnique(new V8DebuggerScript(context, script, false))); |
| 137 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast( | |
| 138 scriptsArray->Get(context, v8::Integer::New(m_isolate, i)) | |
| 139 .ToLocalChecked()); | |
| 140 result.push_back(wrapUnique( | |
| 141 new V8DebuggerScript(context, scriptObject, inLiveEditScope))); | |
| 142 } | 137 } |
| 143 } | 138 } |
| 144 | 139 |
| 145 String16 V8Debugger::setBreakpoint(const String16& sourceID, | 140 String16 V8Debugger::setBreakpoint(const String16& sourceID, |
| 146 const ScriptBreakpoint& scriptBreakpoint, | 141 const ScriptBreakpoint& scriptBreakpoint, |
| 147 int* actualLineNumber, | 142 int* actualLineNumber, |
| 148 int* actualColumnNumber) { | 143 int* actualColumnNumber) { |
| 149 v8::HandleScope scope(m_isolate); | 144 v8::HandleScope scope(m_isolate); |
| 150 v8::Local<v8::Context> context = debuggerContext(); | 145 v8::Local<v8::Context> context = debuggerContext(); |
| 151 v8::Context::Scope contextScope(context); | 146 v8::Context::Scope contextScope(context); |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 eventDetails.GetEventData()); | 574 eventDetails.GetEventData()); |
| 580 return; | 575 return; |
| 581 } | 576 } |
| 582 | 577 |
| 583 V8DebuggerAgentImpl* agent = | 578 V8DebuggerAgentImpl* agent = |
| 584 m_inspector->enabledDebuggerAgentForGroup(getGroupId(eventContext)); | 579 m_inspector->enabledDebuggerAgentForGroup(getGroupId(eventContext)); |
| 585 if (agent) { | 580 if (agent) { |
| 586 v8::HandleScope scope(m_isolate); | 581 v8::HandleScope scope(m_isolate); |
| 587 if (m_ignoreScriptParsedEventsCounter == 0 && | 582 if (m_ignoreScriptParsedEventsCounter == 0 && |
| 588 (event == v8::AfterCompile || event == v8::CompileError)) { | 583 (event == v8::AfterCompile || event == v8::CompileError)) { |
| 589 v8::Context::Scope contextScope(debuggerContext()); | 584 v8::Local<v8::Context> context = debuggerContext(); |
| 585 v8::Context::Scope contextScope(context); |
| 590 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; | 586 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; |
| 591 v8::Local<v8::Value> value = | 587 v8::Local<v8::Value> value = |
| 592 callDebuggerMethod("getAfterCompileScript", 1, argv).ToLocalChecked(); | 588 callDebuggerMethod("getAfterCompileScript", 1, argv).ToLocalChecked(); |
| 593 if (value->IsNull()) return; | 589 if (value->IsNull()) return; |
| 594 DCHECK(value->IsObject()); | 590 DCHECK(value->IsObject()); |
| 595 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast(value); | 591 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast(value); |
| 592 v8::Local<v8::DebugInterface::Script> script; |
| 593 if (!v8::DebugInterface::Script::Wrap(context, scriptObject) |
| 594 .ToLocal(&script)) |
| 595 return; |
| 596 agent->didParseSource( | 596 agent->didParseSource( |
| 597 wrapUnique(new V8DebuggerScript(debuggerContext(), scriptObject, | 597 wrapUnique(new V8DebuggerScript(context, script, inLiveEditScope)), |
| 598 inLiveEditScope)), | |
| 599 event == v8::AfterCompile); | 598 event == v8::AfterCompile); |
| 600 } else if (event == v8::Exception) { | 599 } else if (event == v8::Exception) { |
| 601 v8::Local<v8::Object> eventData = eventDetails.GetEventData(); | 600 v8::Local<v8::Object> eventData = eventDetails.GetEventData(); |
| 602 v8::Local<v8::Value> exception = | 601 v8::Local<v8::Value> exception = |
| 603 callInternalGetterFunction(eventData, "exception"); | 602 callInternalGetterFunction(eventData, "exception"); |
| 604 v8::Local<v8::Value> promise = | 603 v8::Local<v8::Value> promise = |
| 605 callInternalGetterFunction(eventData, "promise"); | 604 callInternalGetterFunction(eventData, "promise"); |
| 606 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); | 605 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); |
| 607 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), | 606 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), |
| 608 exception, v8::Local<v8::Array>(), isPromiseRejection); | 607 exception, v8::Local<v8::Array>(), isPromiseRejection); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 | 975 |
| 977 size_t stackSize = | 976 size_t stackSize = |
| 978 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; | 977 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; |
| 979 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) | 978 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) |
| 980 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; | 979 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; |
| 981 | 980 |
| 982 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); | 981 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); |
| 983 } | 982 } |
| 984 | 983 |
| 985 } // namespace v8_inspector | 984 } // namespace v8_inspector |
| OLD | NEW |