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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8DebuggerImpl.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 /* 1 /*
2 * Copyright (c) 2010-2011 Google Inc. All rights reserved. 2 * Copyright (c) 2010-2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 if (session && session->debuggerAgent()->enabled()) 166 if (session && session->debuggerAgent()->enabled())
167 return session->debuggerAgent(); 167 return session->debuggerAgent();
168 return nullptr; 168 return nullptr;
169 } 169 }
170 170
171 V8DebuggerAgentImpl* V8DebuggerImpl::findEnabledDebuggerAgent(v8::Local<v8::Cont ext> context) 171 V8DebuggerAgentImpl* V8DebuggerImpl::findEnabledDebuggerAgent(v8::Local<v8::Cont ext> context)
172 { 172 {
173 return findEnabledDebuggerAgent(getGroupId(context)); 173 return findEnabledDebuggerAgent(getGroupId(context));
174 } 174 }
175 175
176 void V8DebuggerImpl::getCompiledScripts(int contextGroupId, protocol::Vector<V8D ebuggerParsedScript>& result) 176 void V8DebuggerImpl::getCompiledScripts(int contextGroupId, std::vector<std::uni que_ptr<V8DebuggerScript>>& result)
177 { 177 {
178 v8::HandleScope scope(m_isolate); 178 v8::HandleScope scope(m_isolate);
179 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr otasks); 179 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr otasks);
180 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); 180 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate);
181 DCHECK(!debuggerScript->IsUndefined()); 181 DCHECK(!debuggerScript->IsUndefined());
182 v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast(d ebuggerScript->Get(v8InternalizedString("getScripts"))); 182 v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast(d ebuggerScript->Get(v8InternalizedString("getScripts")));
183 v8::Local<v8::Value> argv[] = { v8::Integer::New(m_isolate, contextGroupId) }; 183 v8::Local<v8::Value> argv[] = { v8::Integer::New(m_isolate, contextGroupId) };
184 v8::Local<v8::Value> value; 184 v8::Local<v8::Value> value;
185 if (!getScriptsFunction->Call(debuggerContext(), debuggerScript, PROTOCOL_AR RAY_LENGTH(argv), argv).ToLocal(&value)) 185 if (!getScriptsFunction->Call(debuggerContext(), debuggerScript, PROTOCOL_AR RAY_LENGTH(argv), argv).ToLocal(&value))
186 return; 186 return;
187 DCHECK(value->IsArray()); 187 DCHECK(value->IsArray());
188 v8::Local<v8::Array> scriptsArray = v8::Local<v8::Array>::Cast(value); 188 v8::Local<v8::Array> scriptsArray = v8::Local<v8::Array>::Cast(value);
189 result.resize(scriptsArray->Length()); 189 result.reserve(scriptsArray->Length());
190 for (unsigned i = 0; i < scriptsArray->Length(); ++i) 190 for (unsigned i = 0; i < scriptsArray->Length(); ++i)
191 result[i] = createParsedScript(v8::Local<v8::Object>::Cast(scriptsArray- >Get(v8::Integer::New(m_isolate, i))), true); 191 result.push_back(createScript(v8::Local<v8::Object>::Cast(scriptsArray-> Get(v8::Integer::New(m_isolate, i)))));
192 } 192 }
193 193
194 String16 V8DebuggerImpl::setBreakpoint(const String16& sourceID, const ScriptBre akpoint& scriptBreakpoint, int* actualLineNumber, int* actualColumnNumber, bool interstatementLocation) 194 String16 V8DebuggerImpl::setBreakpoint(const String16& sourceID, const ScriptBre akpoint& scriptBreakpoint, int* actualLineNumber, int* actualColumnNumber, bool interstatementLocation)
195 { 195 {
196 v8::HandleScope scope(m_isolate); 196 v8::HandleScope scope(m_isolate);
197 v8::Context::Scope contextScope(debuggerContext()); 197 v8::Context::Scope contextScope(debuggerContext());
198 198
199 v8::Local<v8::Object> info = v8::Object::New(m_isolate); 199 v8::Local<v8::Object> info = v8::Object::New(m_isolate);
200 info->Set(v8InternalizedString("sourceID"), toV8String(m_isolate, sourceID)) ; 200 info->Set(v8InternalizedString("sourceID"), toV8String(m_isolate, sourceID)) ;
201 info->Set(v8InternalizedString("lineNumber"), v8::Integer::New(m_isolate, sc riptBreakpoint.lineNumber)); 201 info->Set(v8InternalizedString("lineNumber"), v8::Integer::New(m_isolate, sc riptBreakpoint.lineNumber));
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 void V8DebuggerImpl::clearStepping() 349 void V8DebuggerImpl::clearStepping()
350 { 350 {
351 DCHECK(enabled()); 351 DCHECK(enabled());
352 v8::HandleScope scope(m_isolate); 352 v8::HandleScope scope(m_isolate);
353 v8::Context::Scope contextScope(debuggerContext()); 353 v8::Context::Scope contextScope(debuggerContext());
354 354
355 v8::Local<v8::Value> argv[] = { v8::Undefined(m_isolate) }; 355 v8::Local<v8::Value> argv[] = { v8::Undefined(m_isolate) };
356 callDebuggerMethod("clearStepping", 0, argv); 356 callDebuggerMethod("clearStepping", 0, argv);
357 } 357 }
358 358
359 bool V8DebuggerImpl::setScriptSource(const String16& sourceID, const String16& n ewContent, bool preview, ErrorString* error, Maybe<protocol::Debugger::SetScript SourceError>* errorData, JavaScriptCallFrames* newCallFrames, Maybe<bool>* stack Changed) 359 bool V8DebuggerImpl::setScriptSource(const String16& sourceID, v8::Local<v8::Str ing> newSource, bool preview, ErrorString* error, Maybe<protocol::Debugger::SetS criptSourceError>* errorData, JavaScriptCallFrames* newCallFrames, Maybe<bool>* stackChanged)
360 { 360 {
361 class EnableLiveEditScope { 361 class EnableLiveEditScope {
362 public: 362 public:
363 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) 363 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate)
364 { 364 {
365 v8::Debug::SetLiveEditEnabled(m_isolate, true); 365 v8::Debug::SetLiveEditEnabled(m_isolate, true);
366 inLiveEditScope = true; 366 inLiveEditScope = true;
367 } 367 }
368 ~EnableLiveEditScope() 368 ~EnableLiveEditScope()
369 { 369 {
370 v8::Debug::SetLiveEditEnabled(m_isolate, false); 370 v8::Debug::SetLiveEditEnabled(m_isolate, false);
371 inLiveEditScope = false; 371 inLiveEditScope = false;
372 } 372 }
373 private: 373 private:
374 v8::Isolate* m_isolate; 374 v8::Isolate* m_isolate;
375 }; 375 };
376 376
377 DCHECK(enabled()); 377 DCHECK(enabled());
378 v8::HandleScope scope(m_isolate); 378 v8::HandleScope scope(m_isolate);
379 379
380 std::unique_ptr<v8::Context::Scope> contextScope; 380 std::unique_ptr<v8::Context::Scope> contextScope;
381 if (!isPaused()) 381 if (!isPaused())
382 contextScope = wrapUnique(new v8::Context::Scope(debuggerContext())); 382 contextScope = wrapUnique(new v8::Context::Scope(debuggerContext()));
383 383
384 v8::Local<v8::Value> argv[] = { toV8String(m_isolate, sourceID), toV8String( m_isolate, newContent), v8Boolean(preview, m_isolate) }; 384 v8::Local<v8::Value> argv[] = { toV8String(m_isolate, sourceID), newSource, v8Boolean(preview, m_isolate) };
385 385
386 v8::Local<v8::Value> v8result; 386 v8::Local<v8::Value> v8result;
387 { 387 {
388 EnableLiveEditScope enableLiveEditScope(m_isolate); 388 EnableLiveEditScope enableLiveEditScope(m_isolate);
389 v8::TryCatch tryCatch(m_isolate); 389 v8::TryCatch tryCatch(m_isolate);
390 tryCatch.SetVerbose(false); 390 tryCatch.SetVerbose(false);
391 v8::MaybeLocal<v8::Value> maybeResult = callDebuggerMethod("liveEditScri ptSource", 3, argv); 391 v8::MaybeLocal<v8::Value> maybeResult = callDebuggerMethod("liveEditScri ptSource", 3, argv);
392 if (tryCatch.HasCaught()) { 392 if (tryCatch.HasCaught()) {
393 v8::Local<v8::Message> message = tryCatch.Message(); 393 v8::Local<v8::Message> message = tryCatch.Message();
394 if (!message.IsEmpty()) 394 if (!message.IsEmpty())
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 552
553 V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(eventContext); 553 V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(eventContext);
554 if (agent) { 554 if (agent) {
555 v8::HandleScope scope(m_isolate); 555 v8::HandleScope scope(m_isolate);
556 if (event == v8::AfterCompile || event == v8::CompileError) { 556 if (event == v8::AfterCompile || event == v8::CompileError) {
557 v8::Context::Scope contextScope(debuggerContext()); 557 v8::Context::Scope contextScope(debuggerContext());
558 v8::Local<v8::Value> argv[] = { eventDetails.GetEventData() }; 558 v8::Local<v8::Value> argv[] = { eventDetails.GetEventData() };
559 v8::Local<v8::Value> value = callDebuggerMethod("getAfterCompileScri pt", 1, argv).ToLocalChecked(); 559 v8::Local<v8::Value> value = callDebuggerMethod("getAfterCompileScri pt", 1, argv).ToLocalChecked();
560 DCHECK(value->IsObject()); 560 DCHECK(value->IsObject());
561 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); 561 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
562 agent->didParseSource(createParsedScript(object, event == v8::AfterC ompile)); 562 agent->didParseSource(createScript(object), event == v8::AfterCompil e);
563 } else if (event == v8::Exception) { 563 } else if (event == v8::Exception) {
564 v8::Local<v8::Object> eventData = eventDetails.GetEventData(); 564 v8::Local<v8::Object> eventData = eventDetails.GetEventData();
565 v8::Local<v8::Value> exception = callInternalGetterFunction(eventDat a, "exception"); 565 v8::Local<v8::Value> exception = callInternalGetterFunction(eventDat a, "exception");
566 v8::Local<v8::Value> promise = callInternalGetterFunction(eventData, "promise"); 566 v8::Local<v8::Value> promise = callInternalGetterFunction(eventData, "promise");
567 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); 567 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject();
568 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), e xception, v8::Local<v8::Array>(), isPromiseRejection); 568 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), e xception, v8::Local<v8::Array>(), isPromiseRejection);
569 } else if (event == v8::Break) { 569 } else if (event == v8::Break) {
570 v8::Local<v8::Value> argv[] = { eventDetails.GetEventData() }; 570 v8::Local<v8::Value> argv[] = { eventDetails.GetEventData() };
571 v8::Local<v8::Value> hitBreakpoints = callDebuggerMethod("getBreakpo intNumbers", 1, argv).ToLocalChecked(); 571 v8::Local<v8::Value> hitBreakpoints = callDebuggerMethod("getBreakpo intNumbers", 1, argv).ToLocalChecked();
572 DCHECK(hitBreakpoints->IsArray()); 572 DCHECK(hitBreakpoints->IsArray());
(...skipping 22 matching lines...) Expand all
595 NOTREACHED(); 595 NOTREACHED();
596 } 596 }
597 597
598 V8StackTraceImpl* V8DebuggerImpl::currentAsyncCallChain() 598 V8StackTraceImpl* V8DebuggerImpl::currentAsyncCallChain()
599 { 599 {
600 if (!m_currentStacks.size()) 600 if (!m_currentStacks.size())
601 return nullptr; 601 return nullptr;
602 return m_currentStacks.last(); 602 return m_currentStacks.last();
603 } 603 }
604 604
605 V8DebuggerParsedScript V8DebuggerImpl::createParsedScript(v8::Local<v8::Object> object, bool success) 605 std::unique_ptr<V8DebuggerScript> V8DebuggerImpl::createScript(v8::Local<v8::Obj ect> object)
606 { 606 {
607 v8::Local<v8::Value> id = object->Get(v8InternalizedString("id")); 607 v8::Local<v8::Value> id = object->Get(v8InternalizedString("id"));
608 DCHECK(!id.IsEmpty() && id->IsInt32()); 608 DCHECK(!id.IsEmpty() && id->IsInt32());
609 609
610 V8DebuggerParsedScript parsedScript; 610 std::unique_ptr<V8DebuggerScript> script(new V8DebuggerScript());
611 parsedScript.scriptId = String16::number(id->Int32Value()); 611 script->setScriptId(String16::number(id->Int32Value()))
612 parsedScript.script.setURL(toProtocolStringWithTypeCheck(object->Get(v8Inter nalizedString("name")))) 612 ->setURL(toProtocolStringWithTypeCheck(object->Get(v8InternalizedString( "name"))))
613 .setSourceURL(toProtocolStringWithTypeCheck(object->Get(v8InternalizedSt ring("sourceURL")))) 613 ->setSourceURL(toProtocolStringWithTypeCheck(object->Get(v8InternalizedS tring("sourceURL"))))
614 .setSourceMappingURL(toProtocolStringWithTypeCheck(object->Get(v8Interna lizedString("sourceMappingURL")))) 614 ->setSourceMappingURL(toProtocolStringWithTypeCheck(object->Get(v8Intern alizedString("sourceMappingURL"))))
615 .setSource(toProtocolStringWithTypeCheck(object->Get(v8InternalizedStrin g("source")))) 615 ->setStartLine(object->Get(v8InternalizedString("startLine"))->ToInteger (m_isolate)->Value())
616 .setStartLine(object->Get(v8InternalizedString("startLine"))->ToInteger( m_isolate)->Value()) 616 ->setStartColumn(object->Get(v8InternalizedString("startColumn"))->ToInt eger(m_isolate)->Value())
617 .setStartColumn(object->Get(v8InternalizedString("startColumn"))->ToInte ger(m_isolate)->Value()) 617 ->setEndLine(object->Get(v8InternalizedString("endLine"))->ToInteger(m_i solate)->Value())
618 .setEndLine(object->Get(v8InternalizedString("endLine"))->ToInteger(m_is olate)->Value()) 618 ->setEndColumn(object->Get(v8InternalizedString("endColumn"))->ToInteger (m_isolate)->Value())
619 .setEndColumn(object->Get(v8InternalizedString("endColumn"))->ToInteger( m_isolate)->Value()) 619 ->setIsContentScript(object->Get(v8InternalizedString("isContentScript") )->ToBoolean(m_isolate)->Value())
620 .setIsContentScript(object->Get(v8InternalizedString("isContentScript")) ->ToBoolean(m_isolate)->Value()) 620 ->setIsInternalScript(object->Get(v8InternalizedString("isInternalScript "))->ToBoolean(m_isolate)->Value())
621 .setIsInternalScript(object->Get(v8InternalizedString("isInternalScript" ))->ToBoolean(m_isolate)->Value()) 621 ->setExecutionContextId(object->Get(v8InternalizedString("executionConte xtId"))->ToInteger(m_isolate)->Value())
622 .setExecutionContextId(object->Get(v8InternalizedString("executionContex tId"))->ToInteger(m_isolate)->Value()) 622 ->setIsLiveEdit(inLiveEditScope);
623 .setIsLiveEdit(inLiveEditScope); 623
624 parsedScript.success = success; 624 v8::Local<v8::Value> sourceValue = object->Get(v8InternalizedString("source" ));
625 return parsedScript; 625 if (!sourceValue.IsEmpty() && sourceValue->IsString())
626 script->setSource(m_isolate, sourceValue.As<v8::String>());
627
628 return script;
626 } 629 }
627 630
628 void V8DebuggerImpl::compileDebuggerScript() 631 void V8DebuggerImpl::compileDebuggerScript()
629 { 632 {
630 if (!m_debuggerScript.IsEmpty()) { 633 if (!m_debuggerScript.IsEmpty()) {
631 NOTREACHED(); 634 NOTREACHED();
632 return; 635 return;
633 } 636 }
634 637
635 v8::HandleScope scope(m_isolate); 638 v8::HandleScope scope(m_isolate);
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 return nullptr; 960 return nullptr;
958 return m_contexts.get(contextGroupId); 961 return m_contexts.get(contextGroupId);
959 } 962 }
960 963
961 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI d) 964 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI d)
962 { 965 {
963 return contextGroupId ? m_sessions.get(contextGroupId) : nullptr; 966 return contextGroupId ? m_sessions.get(contextGroupId) : nullptr;
964 } 967 }
965 968
966 } // namespace blink 969 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698