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" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 if (dataString.isEmpty()) return 0; | 109 if (dataString.isEmpty()) return 0; |
110 size_t commaPos = dataString.find(","); | 110 size_t commaPos = dataString.find(","); |
111 if (commaPos == String16::kNotFound) return 0; | 111 if (commaPos == String16::kNotFound) return 0; |
112 return dataString.substring(0, commaPos).toInteger(); | 112 return dataString.substring(0, commaPos).toInteger(); |
113 } | 113 } |
114 | 114 |
115 void V8Debugger::getCompiledScripts( | 115 void V8Debugger::getCompiledScripts( |
116 int contextGroupId, | 116 int contextGroupId, |
117 std::vector<std::unique_ptr<V8DebuggerScript>>& result) { | 117 std::vector<std::unique_ptr<V8DebuggerScript>>& result) { |
118 v8::HandleScope scope(m_isolate); | 118 v8::HandleScope scope(m_isolate); |
119 v8::MicrotasksScope microtasks(m_isolate, | |
120 v8::MicrotasksScope::kDoNotRunMicrotasks); | |
121 v8::Local<v8::Context> context = debuggerContext(); | 119 v8::Local<v8::Context> context = debuggerContext(); |
122 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); | 120 v8::Context::Scope contextScope(context); |
123 DCHECK(!debuggerScript->IsUndefined()); | 121 v8::Local<v8::Array> allScripts; |
124 v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast( | 122 if (!v8::DebugInterface::GetLoadedScripts(m_isolate).ToLocal(&allScripts)) |
125 debuggerScript | |
126 ->Get(context, toV8StringInternalized(m_isolate, "getScripts")) | |
127 .ToLocalChecked()); | |
128 v8::Local<v8::Value> argv[] = {v8::Integer::New(m_isolate, contextGroupId)}; | |
129 v8::Local<v8::Value> value; | |
130 if (!getScriptsFunction->Call(context, debuggerScript, arraysize(argv), argv) | |
131 .ToLocal(&value)) | |
132 return; | 123 return; |
133 DCHECK(value->IsArray()); | 124 String16 contextPrefix = String16::fromInteger(contextGroupId) + ","; |
134 v8::Local<v8::Array> scriptsArray = v8::Local<v8::Array>::Cast(value); | 125 for (uint32_t i = 0; i < allScripts->Length(); ++i) { |
135 result.reserve(scriptsArray->Length()); | 126 v8::Local<v8::Value> scriptValue; |
136 for (unsigned i = 0; i < scriptsArray->Length(); ++i) { | 127 if (!allScripts->Get(context, i).ToLocal(&scriptValue)) continue; |
137 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast( | 128 if (!scriptValue->IsObject()) continue; |
138 scriptsArray->Get(context, v8::Integer::New(m_isolate, i)) | 129 v8::Local<v8::DebugInterface::Script> script; |
139 .ToLocalChecked()); | 130 if (!v8::DebugInterface::Script::Wrap( |
140 result.push_back(wrapUnique( | 131 context, v8::Local<v8::Object>::Cast(scriptValue)) |
141 new V8DebuggerScript(context, scriptObject, inLiveEditScope))); | 132 .ToLocal(&script)) { |
| 133 continue; |
| 134 } |
| 135 if (!script->WasCompiled()) continue; |
| 136 v8::ScriptOriginOptions origin = script->OriginOptions(); |
| 137 if (origin.IsEmbedderDebugScript()) continue; |
| 138 v8::Local<v8::String> v8ContextData; |
| 139 if (!script->ContextData(context).ToLocal(&v8ContextData)) continue; |
| 140 String16 contextData = toProtocolString(v8ContextData); |
| 141 if (contextData.find(contextPrefix) != 0) continue; |
| 142 result.push_back(wrapUnique(new V8DebuggerScript(context, script, false))); |
142 } | 143 } |
143 } | 144 } |
144 | 145 |
145 String16 V8Debugger::setBreakpoint(const String16& sourceID, | 146 String16 V8Debugger::setBreakpoint(const String16& sourceID, |
146 const ScriptBreakpoint& scriptBreakpoint, | 147 const ScriptBreakpoint& scriptBreakpoint, |
147 int* actualLineNumber, | 148 int* actualLineNumber, |
148 int* actualColumnNumber) { | 149 int* actualColumnNumber) { |
149 v8::HandleScope scope(m_isolate); | 150 v8::HandleScope scope(m_isolate); |
150 v8::Local<v8::Context> context = debuggerContext(); | 151 v8::Local<v8::Context> context = debuggerContext(); |
151 v8::Context::Scope contextScope(context); | 152 v8::Context::Scope contextScope(context); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 eventDetails.GetEventData()); | 580 eventDetails.GetEventData()); |
580 return; | 581 return; |
581 } | 582 } |
582 | 583 |
583 V8DebuggerAgentImpl* agent = | 584 V8DebuggerAgentImpl* agent = |
584 m_inspector->enabledDebuggerAgentForGroup(getGroupId(eventContext)); | 585 m_inspector->enabledDebuggerAgentForGroup(getGroupId(eventContext)); |
585 if (agent) { | 586 if (agent) { |
586 v8::HandleScope scope(m_isolate); | 587 v8::HandleScope scope(m_isolate); |
587 if (m_ignoreScriptParsedEventsCounter == 0 && | 588 if (m_ignoreScriptParsedEventsCounter == 0 && |
588 (event == v8::AfterCompile || event == v8::CompileError)) { | 589 (event == v8::AfterCompile || event == v8::CompileError)) { |
589 v8::Context::Scope contextScope(debuggerContext()); | 590 v8::Local<v8::Context> context = debuggerContext(); |
| 591 v8::Context::Scope contextScope(context); |
590 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; | 592 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; |
591 v8::Local<v8::Value> value = | 593 v8::Local<v8::Value> value = |
592 callDebuggerMethod("getAfterCompileScript", 1, argv).ToLocalChecked(); | 594 callDebuggerMethod("getAfterCompileScript", 1, argv).ToLocalChecked(); |
593 if (value->IsNull()) return; | 595 if (value->IsNull()) return; |
594 DCHECK(value->IsObject()); | 596 DCHECK(value->IsObject()); |
595 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast(value); | 597 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast(value); |
| 598 v8::Local<v8::DebugInterface::Script> script; |
| 599 if (!v8::DebugInterface::Script::Wrap(context, scriptObject) |
| 600 .ToLocal(&script)) |
| 601 return; |
596 agent->didParseSource( | 602 agent->didParseSource( |
597 wrapUnique(new V8DebuggerScript(debuggerContext(), scriptObject, | 603 wrapUnique(new V8DebuggerScript(context, script, inLiveEditScope)), |
598 inLiveEditScope)), | |
599 event == v8::AfterCompile); | 604 event == v8::AfterCompile); |
600 } else if (event == v8::Exception) { | 605 } else if (event == v8::Exception) { |
601 v8::Local<v8::Object> eventData = eventDetails.GetEventData(); | 606 v8::Local<v8::Object> eventData = eventDetails.GetEventData(); |
602 v8::Local<v8::Value> exception = | 607 v8::Local<v8::Value> exception = |
603 callInternalGetterFunction(eventData, "exception"); | 608 callInternalGetterFunction(eventData, "exception"); |
604 v8::Local<v8::Value> promise = | 609 v8::Local<v8::Value> promise = |
605 callInternalGetterFunction(eventData, "promise"); | 610 callInternalGetterFunction(eventData, "promise"); |
606 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); | 611 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); |
607 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), | 612 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), |
608 exception, v8::Local<v8::Array>(), isPromiseRejection); | 613 exception, v8::Local<v8::Array>(), isPromiseRejection); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 | 981 |
977 size_t stackSize = | 982 size_t stackSize = |
978 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; | 983 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; |
979 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) | 984 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) |
980 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; | 985 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; |
981 | 986 |
982 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); | 987 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); |
983 } | 988 } |
984 | 989 |
985 } // namespace v8_inspector | 990 } // namespace v8_inspector |
OLD | NEW |