Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: src/inspector/v8-debugger.cc

Issue 2449213002: [inspector] migrate scriptParsed and getCompiledScripts to native (Closed)
Patch Set: addressed comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, 121 v8::PersistentValueVector<v8::DebugInterface::Script> scripts(m_isolate);
120 v8::MicrotasksScope::kDoNotRunMicrotasks); 122 v8::DebugInterface::GetLoadedScripts(m_isolate, scripts);
121 v8::Local<v8::Context> context = debuggerContext(); 123 String16 contextPrefix = String16::fromInteger(contextGroupId) + ",";
122 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); 124 for (size_t i = 0; i < scripts.Size(); ++i) {
123 DCHECK(!debuggerScript->IsUndefined()); 125 v8::Local<v8::DebugInterface::Script> script = scripts.Get(i);
124 v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast( 126 if (!script->WasCompiled()) continue;
125 debuggerScript 127 v8::ScriptOriginOptions origin = script->OriginOptions();
126 ->Get(context, toV8StringInternalized(m_isolate, "getScripts")) 128 if (origin.IsEmbedderDebugScript()) continue;
127 .ToLocalChecked()); 129 v8::Local<v8::String> v8ContextData;
128 v8::Local<v8::Value> argv[] = {v8::Integer::New(m_isolate, contextGroupId)}; 130 if (!script->ContextData().ToLocal(&v8ContextData)) continue;
129 v8::Local<v8::Value> value; 131 String16 contextData = toProtocolString(v8ContextData);
130 if (!getScriptsFunction->Call(context, debuggerScript, arraysize(argv), argv) 132 if (contextData.find(contextPrefix) != 0) continue;
131 .ToLocal(&value)) 133 result.push_back(
132 return; 134 wrapUnique(new V8DebuggerScript(m_isolate, script, false)));
133 DCHECK(value->IsArray());
134 v8::Local<v8::Array> scriptsArray = v8::Local<v8::Array>::Cast(value);
135 result.reserve(scriptsArray->Length());
136 for (unsigned i = 0; i < scriptsArray->Length(); ++i) {
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 } 135 }
143 } 136 }
144 137
145 String16 V8Debugger::setBreakpoint(const String16& sourceID, 138 String16 V8Debugger::setBreakpoint(const String16& sourceID,
146 const ScriptBreakpoint& scriptBreakpoint, 139 const ScriptBreakpoint& scriptBreakpoint,
147 int* actualLineNumber, 140 int* actualLineNumber,
148 int* actualColumnNumber) { 141 int* actualColumnNumber) {
149 v8::HandleScope scope(m_isolate); 142 v8::HandleScope scope(m_isolate);
150 v8::Local<v8::Context> context = debuggerContext(); 143 v8::Local<v8::Context> context = debuggerContext();
151 v8::Context::Scope contextScope(context); 144 v8::Context::Scope contextScope(context);
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 eventDetails.GetEventData()); 572 eventDetails.GetEventData());
580 return; 573 return;
581 } 574 }
582 575
583 V8DebuggerAgentImpl* agent = 576 V8DebuggerAgentImpl* agent =
584 m_inspector->enabledDebuggerAgentForGroup(getGroupId(eventContext)); 577 m_inspector->enabledDebuggerAgentForGroup(getGroupId(eventContext));
585 if (agent) { 578 if (agent) {
586 v8::HandleScope scope(m_isolate); 579 v8::HandleScope scope(m_isolate);
587 if (m_ignoreScriptParsedEventsCounter == 0 && 580 if (m_ignoreScriptParsedEventsCounter == 0 &&
588 (event == v8::AfterCompile || event == v8::CompileError)) { 581 (event == v8::AfterCompile || event == v8::CompileError)) {
589 v8::Context::Scope contextScope(debuggerContext()); 582 v8::Local<v8::Context> context = debuggerContext();
583 v8::Context::Scope contextScope(context);
590 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; 584 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()};
591 v8::Local<v8::Value> value = 585 v8::Local<v8::Value> value =
592 callDebuggerMethod("getAfterCompileScript", 1, argv).ToLocalChecked(); 586 callDebuggerMethod("getAfterCompileScript", 1, argv).ToLocalChecked();
593 if (value->IsNull()) return; 587 if (value->IsNull()) return;
594 DCHECK(value->IsObject()); 588 DCHECK(value->IsObject());
595 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast(value); 589 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast(value);
590 v8::Local<v8::DebugInterface::Script> script;
591 if (!v8::DebugInterface::Script::Wrap(m_isolate, scriptObject)
592 .ToLocal(&script))
593 return;
596 agent->didParseSource( 594 agent->didParseSource(
597 wrapUnique(new V8DebuggerScript(debuggerContext(), scriptObject, 595 wrapUnique(new V8DebuggerScript(m_isolate, script, inLiveEditScope)),
598 inLiveEditScope)),
599 event == v8::AfterCompile); 596 event == v8::AfterCompile);
600 } else if (event == v8::Exception) { 597 } else if (event == v8::Exception) {
601 v8::Local<v8::Object> eventData = eventDetails.GetEventData(); 598 v8::Local<v8::Object> eventData = eventDetails.GetEventData();
602 v8::Local<v8::Value> exception = 599 v8::Local<v8::Value> exception =
603 callInternalGetterFunction(eventData, "exception"); 600 callInternalGetterFunction(eventData, "exception");
604 v8::Local<v8::Value> promise = 601 v8::Local<v8::Value> promise =
605 callInternalGetterFunction(eventData, "promise"); 602 callInternalGetterFunction(eventData, "promise");
606 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); 603 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject();
607 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), 604 handleProgramBreak(eventContext, eventDetails.GetExecutionState(),
608 exception, v8::Local<v8::Array>(), isPromiseRejection); 605 exception, v8::Local<v8::Array>(), isPromiseRejection);
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 973
977 size_t stackSize = 974 size_t stackSize =
978 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; 975 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1;
979 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) 976 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId))
980 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; 977 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture;
981 978
982 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); 979 return V8StackTraceImpl::capture(this, contextGroupId, stackSize);
983 } 980 }
984 981
985 } // namespace v8_inspector 982 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698