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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp

Issue 2104063002: [DevTools] Store script source in v8::Global. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium 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 "platform/v8_inspector/V8DebuggerAgentImpl.h" 5 #include "platform/v8_inspector/V8DebuggerAgentImpl.h"
6 6
7 #include "platform/inspector_protocol/String16.h" 7 #include "platform/inspector_protocol/String16.h"
8 #include "platform/inspector_protocol/Values.h" 8 #include "platform/inspector_protocol/Values.h"
9 #include "platform/v8_inspector/InjectedScript.h" 9 #include "platform/v8_inspector/InjectedScript.h"
10 #include "platform/v8_inspector/InspectedContext.h" 10 #include "platform/v8_inspector/InspectedContext.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 183 }
184 184
185 void V8DebuggerAgentImpl::enable() 185 void V8DebuggerAgentImpl::enable()
186 { 186 {
187 // debugger().addListener may result in reporting all parsed scripts to 187 // debugger().addListener may result in reporting all parsed scripts to
188 // the agent so it should already be in enabled state by then. 188 // the agent so it should already be in enabled state by then.
189 m_enabled = true; 189 m_enabled = true;
190 m_state->setBoolean(DebuggerAgentState::debuggerEnabled, true); 190 m_state->setBoolean(DebuggerAgentState::debuggerEnabled, true);
191 debugger().debuggerAgentEnabled(); 191 debugger().debuggerAgentEnabled();
192 192
193 protocol::Vector<V8DebuggerParsedScript> compiledScripts; 193 std::vector<std::unique_ptr<V8DebuggerScript>> compiledScripts;
194 debugger().getCompiledScripts(m_session->contextGroupId(), compiledScripts); 194 debugger().getCompiledScripts(m_session->contextGroupId(), compiledScripts);
195 for (size_t i = 0; i < compiledScripts.size(); i++) 195 for (size_t i = 0; i < compiledScripts.size(); i++)
196 didParseSource(compiledScripts[i]); 196 didParseSource(std::move(compiledScripts[i]), true);
197 197
198 // FIXME(WK44513): breakpoints activated flag should be synchronized between all front-ends 198 // FIXME(WK44513): breakpoints activated flag should be synchronized between all front-ends
199 debugger().setBreakpointsActivated(true); 199 debugger().setBreakpointsActivated(true);
200 m_session->changeInstrumentationCounter(+1); 200 m_session->changeInstrumentationCounter(+1);
201 } 201 }
202 202
203 bool V8DebuggerAgentImpl::enabled() 203 bool V8DebuggerAgentImpl::enabled()
204 { 204 {
205 return m_enabled; 205 return m_enabled;
206 } 206 }
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 debuggerBreakpointIdsIterator->second->append(debuggerBreakpointId); 568 debuggerBreakpointIdsIterator->second->append(debuggerBreakpointId);
569 569
570 return buildProtocolLocation(scriptId, actualLineNumber, actualColumnNumber) ; 570 return buildProtocolLocation(scriptId, actualLineNumber, actualColumnNumber) ;
571 } 571 }
572 572
573 void V8DebuggerAgentImpl::searchInContent(ErrorString* error, const String16& sc riptId, const String16& query, 573 void V8DebuggerAgentImpl::searchInContent(ErrorString* error, const String16& sc riptId, const String16& query,
574 const Maybe<bool>& optionalCaseSensitive, 574 const Maybe<bool>& optionalCaseSensitive,
575 const Maybe<bool>& optionalIsRegex, 575 const Maybe<bool>& optionalIsRegex,
576 std::unique_ptr<Array<protocol::Debugger::SearchMatch>>* results) 576 std::unique_ptr<Array<protocol::Debugger::SearchMatch>>* results)
577 { 577 {
578 v8::HandleScope handles(m_isolate);
578 ScriptsMap::iterator it = m_scripts.find(scriptId); 579 ScriptsMap::iterator it = m_scripts.find(scriptId);
579 if (it != m_scripts.end()) 580 if (it != m_scripts.end())
580 *results = V8ContentSearchUtil::searchInTextByLines(m_session, it->secon d->source(), query, optionalCaseSensitive.fromMaybe(false), optionalIsRegex.from Maybe(false)); 581 *results = V8ContentSearchUtil::searchInTextByLines(m_session, toProtoco lString(it->second->source(m_isolate)), query, optionalCaseSensitive.fromMaybe(f alse), optionalIsRegex.fromMaybe(false));
581 else 582 else
582 *error = String16("No script for id: " + scriptId); 583 *error = String16("No script for id: " + scriptId);
583 } 584 }
584 585
585 void V8DebuggerAgentImpl::setScriptSource(ErrorString* errorString, 586 void V8DebuggerAgentImpl::setScriptSource(ErrorString* errorString,
586 const String16& scriptId, 587 const String16& scriptId,
587 const String16& newContent, 588 const String16& newContent,
588 const Maybe<bool>& preview, 589 const Maybe<bool>& preview,
589 Maybe<protocol::Array<protocol::Debugger::CallFrame>>* newCallFrames, 590 Maybe<protocol::Array<protocol::Debugger::CallFrame>>* newCallFrames,
590 Maybe<bool>* stackChanged, 591 Maybe<bool>* stackChanged,
591 Maybe<StackTrace>* asyncStackTrace, 592 Maybe<StackTrace>* asyncStackTrace,
592 Maybe<protocol::Debugger::SetScriptSourceError>* optOutCompileError) 593 Maybe<protocol::Debugger::SetScriptSourceError>* optOutCompileError)
593 { 594 {
594 if (!checkEnabled(errorString)) 595 if (!checkEnabled(errorString))
595 return; 596 return;
596 if (!debugger().setScriptSource(scriptId, newContent, preview.fromMaybe(fals e), errorString, optOutCompileError, &m_pausedCallFrames, stackChanged)) 597
598 v8::HandleScope handles(m_isolate);
599 v8::Local<v8::String> newSource = toV8String(m_isolate, newContent);
600 if (!debugger().setScriptSource(scriptId, newSource, preview.fromMaybe(false ), errorString, optOutCompileError, &m_pausedCallFrames, stackChanged))
597 return; 601 return;
598 602
603 ScriptsMap::iterator it = m_scripts.find(scriptId);
604 if (it != m_scripts.end())
605 it->second->setSource(m_isolate, newSource);
606
599 std::unique_ptr<Array<CallFrame>> callFrames = currentCallFrames(errorString ); 607 std::unique_ptr<Array<CallFrame>> callFrames = currentCallFrames(errorString );
600 if (!callFrames) 608 if (!callFrames)
601 return; 609 return;
602 *newCallFrames = std::move(callFrames); 610 *newCallFrames = std::move(callFrames);
603 *asyncStackTrace = currentAsyncStackTrace(); 611 *asyncStackTrace = currentAsyncStackTrace();
604
605 ScriptsMap::iterator it = m_scripts.find(scriptId);
606 if (it == m_scripts.end())
607 return;
608 it->second->setSource(newContent);
609 } 612 }
610 613
611 void V8DebuggerAgentImpl::restartFrame(ErrorString* errorString, 614 void V8DebuggerAgentImpl::restartFrame(ErrorString* errorString,
612 const String16& callFrameId, 615 const String16& callFrameId,
613 std::unique_ptr<Array<CallFrame>>* newCallFrames, 616 std::unique_ptr<Array<CallFrame>>* newCallFrames,
614 Maybe<StackTrace>* asyncStackTrace) 617 Maybe<StackTrace>* asyncStackTrace)
615 { 618 {
616 if (!assertPaused(errorString)) 619 if (!assertPaused(errorString))
617 return; 620 return;
618 InjectedScript::CallFrameScope scope(errorString, m_debugger, m_session->con textGroupId(), callFrameId); 621 InjectedScript::CallFrameScope scope(errorString, m_debugger, m_session->con textGroupId(), callFrameId);
(...skipping 20 matching lines...) Expand all
639 642
640 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource) 643 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource)
641 { 644 {
642 if (!checkEnabled(error)) 645 if (!checkEnabled(error))
643 return; 646 return;
644 ScriptsMap::iterator it = m_scripts.find(scriptId); 647 ScriptsMap::iterator it = m_scripts.find(scriptId);
645 if (it == m_scripts.end()) { 648 if (it == m_scripts.end()) {
646 *error = "No script for id: " + scriptId; 649 *error = "No script for id: " + scriptId;
647 return; 650 return;
648 } 651 }
649 *scriptSource = it->second->source(); 652 v8::HandleScope handles(m_isolate);
653 *scriptSource = toProtocolString(it->second->source(m_isolate));
650 } 654 }
651 655
652 void V8DebuggerAgentImpl::getFunctionDetails(ErrorString* errorString, const Str ing16& functionId, std::unique_ptr<FunctionDetails>* details) 656 void V8DebuggerAgentImpl::getFunctionDetails(ErrorString* errorString, const Str ing16& functionId, std::unique_ptr<FunctionDetails>* details)
653 { 657 {
654 if (!checkEnabled(errorString)) 658 if (!checkEnabled(errorString))
655 return; 659 return;
656 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex tGroupId(), functionId); 660 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex tGroupId(), functionId);
657 if (!scope.initialize()) 661 if (!scope.initialize())
658 return; 662 return;
659 if (!scope.object()->IsFunction()) { 663 if (!scope.object()->IsFunction()) {
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 } 1130 }
1127 1131
1128 std::unique_ptr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace() 1132 std::unique_ptr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace()
1129 { 1133 {
1130 if (m_pausedContext.IsEmpty()) 1134 if (m_pausedContext.IsEmpty())
1131 return nullptr; 1135 return nullptr;
1132 V8StackTraceImpl* stackTrace = m_debugger->currentAsyncCallChain(); 1136 V8StackTraceImpl* stackTrace = m_debugger->currentAsyncCallChain();
1133 return stackTrace ? stackTrace->buildInspectorObjectForTail(m_debugger) : nu llptr; 1137 return stackTrace ? stackTrace->buildInspectorObjectForTail(m_debugger) : nu llptr;
1134 } 1138 }
1135 1139
1136 void V8DebuggerAgentImpl::didParseSource(const V8DebuggerParsedScript& parsedScr ipt) 1140 void V8DebuggerAgentImpl::didParseSource(std::unique_ptr<V8DebuggerScript> scrip t, bool success)
1137 { 1141 {
1138 V8DebuggerScript script = parsedScript.script; 1142 v8::HandleScope handles(m_isolate);
1139 1143 String16 scriptSource = toProtocolString(script->source(m_isolate));
1140 bool isDeprecatedSourceURL = false; 1144 bool isDeprecatedSourceURL = false;
1141 if (!parsedScript.success) 1145 if (!success)
1142 script.setSourceURL(V8ContentSearchUtil::findSourceURL(script.source(), false, &isDeprecatedSourceURL)); 1146 script->setSourceURL(V8ContentSearchUtil::findSourceURL(scriptSource, fa lse, &isDeprecatedSourceURL));
1143 else if (script.hasSourceURL()) 1147 else if (script->hasSourceURL())
1144 V8ContentSearchUtil::findSourceURL(script.source(), false, &isDeprecated SourceURL); 1148 V8ContentSearchUtil::findSourceURL(scriptSource, false, &isDeprecatedSou rceURL);
1145 1149
1146 bool isDeprecatedSourceMappingURL = false; 1150 bool isDeprecatedSourceMappingURL = false;
1147 if (!parsedScript.success) 1151 if (!success)
1148 script.setSourceMappingURL(V8ContentSearchUtil::findSourceMapURL(script. source(), false, &isDeprecatedSourceMappingURL)); 1152 script->setSourceMappingURL(V8ContentSearchUtil::findSourceMapURL(script Source, false, &isDeprecatedSourceMappingURL));
1149 else if (!script.sourceMappingURL().isEmpty()) 1153 else if (!script->sourceMappingURL().isEmpty())
1150 V8ContentSearchUtil::findSourceMapURL(script.source(), false, &isDepreca tedSourceMappingURL); 1154 V8ContentSearchUtil::findSourceMapURL(scriptSource, false, &isDeprecated SourceMappingURL);
1151 1155
1152 script.setHash(calculateHash(script.source())); 1156 script->setHash(calculateHash(scriptSource));
1153 1157
1154 int executionContextId = script.executionContextId(); 1158 int executionContextId = script->executionContextId();
1155 bool isContentScript = script.isContentScript(); 1159 bool isContentScript = script->isContentScript();
1156 bool isInternalScript = script.isInternalScript(); 1160 bool isInternalScript = script->isInternalScript();
1157 bool isLiveEdit = script.isLiveEdit(); 1161 bool isLiveEdit = script->isLiveEdit();
1158 bool hasSourceURL = script.hasSourceURL(); 1162 bool hasSourceURL = script->hasSourceURL();
1159 String16 scriptURL = script.sourceURL(); 1163 String16 scriptId = script->scriptId();
1160 String16 sourceMapURL = script.sourceMappingURL(); 1164 String16 scriptURL = script->sourceURL();
1165 String16 sourceMapURL = script->sourceMappingURL();
1161 bool deprecatedCommentWasUsed = isDeprecatedSourceURL || isDeprecatedSourceM appingURL; 1166 bool deprecatedCommentWasUsed = isDeprecatedSourceURL || isDeprecatedSourceM appingURL;
1162 1167
1163 const Maybe<String16>& sourceMapURLParam = sourceMapURL; 1168 const Maybe<String16>& sourceMapURLParam = sourceMapURL;
1164 const bool* isContentScriptParam = isContentScript ? &isContentScript : null ptr; 1169 const bool* isContentScriptParam = isContentScript ? &isContentScript : null ptr;
1165 const bool* isInternalScriptParam = isInternalScript ? &isInternalScript : n ullptr; 1170 const bool* isInternalScriptParam = isInternalScript ? &isInternalScript : n ullptr;
1166 const bool* isLiveEditParam = isLiveEdit ? &isLiveEdit : nullptr; 1171 const bool* isLiveEditParam = isLiveEdit ? &isLiveEdit : nullptr;
1167 const bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr; 1172 const bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr;
1168 const bool* deprecatedCommentWasUsedParam = deprecatedCommentWasUsed ? &depr ecatedCommentWasUsed : nullptr; 1173 const bool* deprecatedCommentWasUsedParam = deprecatedCommentWasUsed ? &depr ecatedCommentWasUsed : nullptr;
1169 if (parsedScript.success) 1174 if (success)
1170 m_frontend.scriptParsed(parsedScript.scriptId, scriptURL, script.startLi ne(), script.startColumn(), script.endLine(), script.endColumn(), executionConte xtId, script.hash(), isContentScriptParam, isInternalScriptParam, isLiveEditPara m, sourceMapURLParam, hasSourceURLParam, deprecatedCommentWasUsedParam); 1175 m_frontend.scriptParsed(scriptId, scriptURL, script->startLine(), script ->startColumn(), script->endLine(), script->endColumn(), executionContextId, scr ipt->hash(), isContentScriptParam, isInternalScriptParam, isLiveEditParam, sourc eMapURLParam, hasSourceURLParam, deprecatedCommentWasUsedParam);
1171 else 1176 else
1172 m_frontend.scriptFailedToParse(parsedScript.scriptId, scriptURL, script. startLine(), script.startColumn(), script.endLine(), script.endColumn(), executi onContextId, script.hash(), isContentScriptParam, isInternalScriptParam, sourceM apURLParam, hasSourceURLParam, deprecatedCommentWasUsedParam); 1177 m_frontend.scriptFailedToParse(scriptId, scriptURL, script->startLine(), script->startColumn(), script->endLine(), script->endColumn(), executionContext Id, script->hash(), isContentScriptParam, isInternalScriptParam, sourceMapURLPar am, hasSourceURLParam, deprecatedCommentWasUsedParam);
1173 1178
1174 m_scripts.set(parsedScript.scriptId, script); 1179 m_scripts.set(scriptId, std::move(script));
1175 1180
1176 if (scriptURL.isEmpty() || !parsedScript.success) 1181 if (scriptURL.isEmpty() || !success)
1177 return; 1182 return;
1178 1183
1179 protocol::DictionaryValue* breakpointsCookie = m_state->getObject(DebuggerAg entState::javaScriptBreakpoints); 1184 protocol::DictionaryValue* breakpointsCookie = m_state->getObject(DebuggerAg entState::javaScriptBreakpoints);
1180 if (!breakpointsCookie) 1185 if (!breakpointsCookie)
1181 return; 1186 return;
1182 1187
1183 for (size_t i = 0; i < breakpointsCookie->size(); ++i) { 1188 for (size_t i = 0; i < breakpointsCookie->size(); ++i) {
1184 auto cookie = breakpointsCookie->at(i); 1189 auto cookie = breakpointsCookie->at(i);
1185 protocol::DictionaryValue* breakpointObject = protocol::DictionaryValue: :cast(cookie.second); 1190 protocol::DictionaryValue* breakpointObject = protocol::DictionaryValue: :cast(cookie.second);
1186 bool isRegex; 1191 bool isRegex;
1187 breakpointObject->getBoolean(DebuggerAgentState::isRegex, &isRegex); 1192 breakpointObject->getBoolean(DebuggerAgentState::isRegex, &isRegex);
1188 String16 url; 1193 String16 url;
1189 breakpointObject->getString(DebuggerAgentState::url, &url); 1194 breakpointObject->getString(DebuggerAgentState::url, &url);
1190 if (!matches(m_debugger, scriptURL, url, isRegex)) 1195 if (!matches(m_debugger, scriptURL, url, isRegex))
1191 continue; 1196 continue;
1192 ScriptBreakpoint breakpoint; 1197 ScriptBreakpoint breakpoint;
1193 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber); 1198 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber);
1194 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber); 1199 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber);
1195 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition); 1200 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition);
1196 std::unique_ptr<protocol::Debugger::Location> location = resolveBreakpoi nt(cookie.first, parsedScript.scriptId, breakpoint, UserBreakpointSource); 1201 std::unique_ptr<protocol::Debugger::Location> location = resolveBreakpoi nt(cookie.first, scriptId, breakpoint, UserBreakpointSource);
1197 if (location) 1202 if (location)
1198 m_frontend.breakpointResolved(cookie.first, std::move(location)); 1203 m_frontend.breakpointResolved(cookie.first, std::move(location));
1199 } 1204 }
1200 } 1205 }
1201 1206
1202 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::didPause(v8::Local<v8 ::Context> context, v8::Local<v8::Value> exception, const protocol::Vector<Strin g16>& hitBreakpoints, bool isPromiseRejection) 1207 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::didPause(v8::Local<v8 ::Context> context, v8::Local<v8::Value> exception, const protocol::Vector<Strin g16>& hitBreakpoints, bool isPromiseRejection)
1203 { 1208 {
1204 JavaScriptCallFrames callFrames = debugger().currentCallFrames(1); 1209 JavaScriptCallFrames callFrames = debugger().currentCallFrames(1);
1205 JavaScriptCallFrame* topCallFrame = callFrames.size() > 0 ? callFrames[0] : nullptr; 1210 JavaScriptCallFrame* topCallFrame = callFrames.size() > 0 ? callFrames[0] : nullptr;
1206 1211
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 { 1334 {
1330 if (!enabled()) 1335 if (!enabled())
1331 return; 1336 return;
1332 m_scheduledDebuggerStep = NoStep; 1337 m_scheduledDebuggerStep = NoStep;
1333 m_scripts.clear(); 1338 m_scripts.clear();
1334 m_blackboxedPositions.clear(); 1339 m_blackboxedPositions.clear();
1335 m_breakpointIdToDebuggerBreakpointIds.clear(); 1340 m_breakpointIdToDebuggerBreakpointIds.clear();
1336 } 1341 }
1337 1342
1338 } // namespace blink 1343 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698