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

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

Issue 2087953004: Switch v8 inspector to stl collections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 void V8DebuggerImpl::debuggerAgentDisabled() 155 void V8DebuggerImpl::debuggerAgentDisabled()
156 { 156 {
157 if (!--m_enabledAgentsCount) 157 if (!--m_enabledAgentsCount)
158 disable(); 158 disable();
159 } 159 }
160 160
161 V8DebuggerAgentImpl* V8DebuggerImpl::findEnabledDebuggerAgent(int contextGroupId ) 161 V8DebuggerAgentImpl* V8DebuggerImpl::findEnabledDebuggerAgent(int contextGroupId )
162 { 162 {
163 if (!contextGroupId) 163 if (!contextGroupId)
164 return nullptr; 164 return nullptr;
165 V8InspectorSessionImpl* session = m_sessions.get(contextGroupId); 165 SessionMap::iterator it = m_sessions.find(contextGroupId);
166 if (session && session->debuggerAgent()->enabled()) 166 if (it == m_sessions.end())
167 return session->debuggerAgent(); 167 return nullptr;
168 return nullptr; 168 V8DebuggerAgentImpl* agent = it->second->debuggerAgent();
169 if (!agent->enabled())
170 return nullptr;
171 return agent;
169 } 172 }
170 173
171 V8DebuggerAgentImpl* V8DebuggerImpl::findEnabledDebuggerAgent(v8::Local<v8::Cont ext> context) 174 V8DebuggerAgentImpl* V8DebuggerImpl::findEnabledDebuggerAgent(v8::Local<v8::Cont ext> context)
172 { 175 {
173 return findEnabledDebuggerAgent(getGroupId(context)); 176 return findEnabledDebuggerAgent(getGroupId(context));
174 } 177 }
175 178
176 void V8DebuggerImpl::getCompiledScripts(int contextGroupId, protocol::Vector<V8D ebuggerParsedScript>& result) 179 void V8DebuggerImpl::getCompiledScripts(int contextGroupId, std::vector<V8Debugg erParsedScript>& result)
177 { 180 {
178 v8::HandleScope scope(m_isolate); 181 v8::HandleScope scope(m_isolate);
179 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr otasks); 182 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr otasks);
180 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); 183 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate);
181 DCHECK(!debuggerScript->IsUndefined()); 184 DCHECK(!debuggerScript->IsUndefined());
182 v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast(d ebuggerScript->Get(v8InternalizedString("getScripts"))); 185 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) }; 186 v8::Local<v8::Value> argv[] = { v8::Integer::New(m_isolate, contextGroupId) };
184 v8::Local<v8::Value> value; 187 v8::Local<v8::Value> value;
185 if (!getScriptsFunction->Call(debuggerContext(), debuggerScript, PROTOCOL_AR RAY_LENGTH(argv), argv).ToLocal(&value)) 188 if (!getScriptsFunction->Call(debuggerContext(), debuggerScript, PROTOCOL_AR RAY_LENGTH(argv), argv).ToLocal(&value))
186 return; 189 return;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 v8result = maybeResult.ToLocalChecked(); 403 v8result = maybeResult.ToLocalChecked();
401 } 404 }
402 DCHECK(!v8result.IsEmpty()); 405 DCHECK(!v8result.IsEmpty());
403 v8::Local<v8::Object> resultTuple = v8result->ToObject(m_isolate); 406 v8::Local<v8::Object> resultTuple = v8result->ToObject(m_isolate);
404 int code = static_cast<int>(resultTuple->Get(0)->ToInteger(m_isolate)->Value ()); 407 int code = static_cast<int>(resultTuple->Get(0)->ToInteger(m_isolate)->Value ());
405 switch (code) { 408 switch (code) {
406 case 0: 409 case 0:
407 { 410 {
408 *stackChanged = resultTuple->Get(1)->BooleanValue(); 411 *stackChanged = resultTuple->Get(1)->BooleanValue();
409 // Call stack may have changed after if the edited function was on t he stack. 412 // Call stack may have changed after if the edited function was on t he stack.
410 if (!preview && isPaused()) 413 if (!preview && isPaused()) {
411 newCallFrames->swap(currentCallFrames()); 414 JavaScriptCallFrames frames = currentCallFrames();
415 newCallFrames->swap(frames);
416 }
412 return true; 417 return true;
413 } 418 }
414 // Compile error. 419 // Compile error.
415 case 1: 420 case 1:
416 { 421 {
417 *errorData = protocol::Debugger::SetScriptSourceError::create() 422 *errorData = protocol::Debugger::SetScriptSourceError::create()
418 .setMessage(toProtocolStringWithTypeCheck(resultTuple->Get(2))) 423 .setMessage(toProtocolStringWithTypeCheck(resultTuple->Get(2)))
419 .setLineNumber(resultTuple->Get(3)->ToInteger(m_isolate)->Value( )) 424 .setLineNumber(resultTuple->Get(3)->ToInteger(m_isolate)->Value( ))
420 .setColumnNumber(resultTuple->Get(4)->ToInteger(m_isolate)->Valu e()).build(); 425 .setColumnNumber(resultTuple->Get(4)->ToInteger(m_isolate)->Valu e()).build();
421 return false; 426 return false;
(...skipping 20 matching lines...) Expand all
442 return JavaScriptCallFrames(); 447 return JavaScriptCallFrames();
443 v8::Local<v8::Array> callFramesArray = currentCallFramesV8.As<v8::Array>(); 448 v8::Local<v8::Array> callFramesArray = currentCallFramesV8.As<v8::Array>();
444 JavaScriptCallFrames callFrames; 449 JavaScriptCallFrames callFrames;
445 for (size_t i = 0; i < callFramesArray->Length(); ++i) { 450 for (size_t i = 0; i < callFramesArray->Length(); ++i) {
446 v8::Local<v8::Value> callFrameValue; 451 v8::Local<v8::Value> callFrameValue;
447 if (!callFramesArray->Get(debuggerContext(), i).ToLocal(&callFrameValue) ) 452 if (!callFramesArray->Get(debuggerContext(), i).ToLocal(&callFrameValue) )
448 return JavaScriptCallFrames(); 453 return JavaScriptCallFrames();
449 if (!callFrameValue->IsObject()) 454 if (!callFrameValue->IsObject())
450 return JavaScriptCallFrames(); 455 return JavaScriptCallFrames();
451 v8::Local<v8::Object> callFrameObject = callFrameValue.As<v8::Object>(); 456 v8::Local<v8::Object> callFrameObject = callFrameValue.As<v8::Object>();
452 callFrames.append(JavaScriptCallFrame::create(debuggerContext(), v8::Loc al<v8::Object>::Cast(callFrameObject))); 457 callFrames.push_back(JavaScriptCallFrame::create(debuggerContext(), v8:: Local<v8::Object>::Cast(callFrameObject)));
453 } 458 }
454 return callFrames; 459 return callFrames;
455 } 460 }
456 461
457 static V8DebuggerImpl* toV8DebuggerImpl(v8::Local<v8::Value> data) 462 static V8DebuggerImpl* toV8DebuggerImpl(v8::Local<v8::Value> data)
458 { 463 {
459 void* p = v8::Local<v8::External>::Cast(data)->Value(); 464 void* p = v8::Local<v8::External>::Cast(data)->Value();
460 return static_cast<V8DebuggerImpl*>(p); 465 return static_cast<V8DebuggerImpl*>(p);
461 } 466 }
462 467
(...skipping 10 matching lines...) Expand all
473 void V8DebuggerImpl::handleProgramBreak(v8::Local<v8::Context> pausedContext, v8 ::Local<v8::Object> executionState, v8::Local<v8::Value> exception, v8::Local<v8 ::Array> hitBreakpointNumbers, bool isPromiseRejection) 478 void V8DebuggerImpl::handleProgramBreak(v8::Local<v8::Context> pausedContext, v8 ::Local<v8::Object> executionState, v8::Local<v8::Value> exception, v8::Local<v8 ::Array> hitBreakpointNumbers, bool isPromiseRejection)
474 { 479 {
475 // Don't allow nested breaks. 480 // Don't allow nested breaks.
476 if (m_runningNestedMessageLoop) 481 if (m_runningNestedMessageLoop)
477 return; 482 return;
478 483
479 V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(pausedContext); 484 V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(pausedContext);
480 if (!agent) 485 if (!agent)
481 return; 486 return;
482 487
483 protocol::Vector<String16> breakpointIds; 488 std::vector<String16> breakpointIds;
484 if (!hitBreakpointNumbers.IsEmpty()) { 489 if (!hitBreakpointNumbers.IsEmpty()) {
485 breakpointIds.resize(hitBreakpointNumbers->Length()); 490 breakpointIds.reserve(hitBreakpointNumbers->Length());
486 for (size_t i = 0; i < hitBreakpointNumbers->Length(); i++) { 491 for (size_t i = 0; i < hitBreakpointNumbers->Length(); i++) {
487 v8::Local<v8::Value> hitBreakpointNumber = hitBreakpointNumbers->Get (i); 492 v8::Local<v8::Value> hitBreakpointNumber = hitBreakpointNumbers->Get (i);
488 DCHECK(!hitBreakpointNumber.IsEmpty() && hitBreakpointNumber->IsInt3 2()); 493 DCHECK(!hitBreakpointNumber.IsEmpty() && hitBreakpointNumber->IsInt3 2());
489 breakpointIds[i] = String16::number(hitBreakpointNumber->Int32Value( )); 494 breakpointIds.push_back(String16::number(hitBreakpointNumber->Int32V alue()));
490 } 495 }
491 } 496 }
492 497
493 m_pausedContext = pausedContext; 498 m_pausedContext = pausedContext;
494 m_executionState = executionState; 499 m_executionState = executionState;
495 V8DebuggerAgentImpl::SkipPauseRequest result = agent->didPause(pausedContext , exception, breakpointIds, isPromiseRejection); 500 V8DebuggerAgentImpl::SkipPauseRequest result = agent->didPause(pausedContext , exception, breakpointIds, isPromiseRejection);
496 if (result == V8DebuggerAgentImpl::RequestNoSkip) { 501 if (result == V8DebuggerAgentImpl::RequestNoSkip) {
497 m_runningNestedMessageLoop = true; 502 m_runningNestedMessageLoop = true;
498 int groupId = getGroupId(pausedContext); 503 int groupId = getGroupId(pausedContext);
499 DCHECK(groupId); 504 DCHECK(groupId);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 else if (type == v8AsyncTaskEventDidHandle) 597 else if (type == v8AsyncTaskEventDidHandle)
593 asyncTaskFinished(ptr); 598 asyncTaskFinished(ptr);
594 else 599 else
595 NOTREACHED(); 600 NOTREACHED();
596 } 601 }
597 602
598 V8StackTraceImpl* V8DebuggerImpl::currentAsyncCallChain() 603 V8StackTraceImpl* V8DebuggerImpl::currentAsyncCallChain()
599 { 604 {
600 if (!m_currentStacks.size()) 605 if (!m_currentStacks.size())
601 return nullptr; 606 return nullptr;
602 return m_currentStacks.last(); 607 return m_currentStacks.back().get();
603 } 608 }
604 609
605 V8DebuggerParsedScript V8DebuggerImpl::createParsedScript(v8::Local<v8::Object> object, bool success) 610 V8DebuggerParsedScript V8DebuggerImpl::createParsedScript(v8::Local<v8::Object> object, bool success)
606 { 611 {
607 v8::Local<v8::Value> id = object->Get(v8InternalizedString("id")); 612 v8::Local<v8::Value> id = object->Get(v8InternalizedString("id"));
608 DCHECK(!id.IsEmpty() && id->IsInt32()); 613 DCHECK(!id.IsEmpty() && id->IsInt32());
609 614
610 V8DebuggerParsedScript parsedScript; 615 V8DebuggerParsedScript parsedScript;
611 parsedScript.scriptId = String16::number(id->Int32Value()); 616 parsedScript.scriptId = String16::number(id->Int32Value());
612 parsedScript.script.setURL(toProtocolStringWithTypeCheck(object->Get(v8Inter nalizedString("name")))) 617 parsedScript.script.setURL(toProtocolStringWithTypeCheck(object->Get(v8Inter nalizedString("name"))))
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 } 758 }
754 759
755 std::unique_ptr<V8StackTrace> V8DebuggerImpl::createStackTrace(v8::Local<v8::Sta ckTrace> stackTrace) 760 std::unique_ptr<V8StackTrace> V8DebuggerImpl::createStackTrace(v8::Local<v8::Sta ckTrace> stackTrace)
756 { 761 {
757 int contextGroupId = m_isolate->InContext() ? getGroupId(m_isolate->GetCurre ntContext()) : 0; 762 int contextGroupId = m_isolate->InContext() ? getGroupId(m_isolate->GetCurre ntContext()) : 0;
758 return V8StackTraceImpl::create(this, contextGroupId, stackTrace, V8StackTra ce::maxCallStackSizeToCapture); 763 return V8StackTraceImpl::create(this, contextGroupId, stackTrace, V8StackTra ce::maxCallStackSizeToCapture);
759 } 764 }
760 765
761 std::unique_ptr<V8InspectorSession> V8DebuggerImpl::connect(int contextGroupId, protocol::FrontendChannel* channel, V8InspectorSessionClient* client, const Stri ng16* state) 766 std::unique_ptr<V8InspectorSession> V8DebuggerImpl::connect(int contextGroupId, protocol::FrontendChannel* channel, V8InspectorSessionClient* client, const Stri ng16* state)
762 { 767 {
763 DCHECK(!m_sessions.contains(contextGroupId)); 768 DCHECK(m_sessions.find(contextGroupId) == m_sessions.cend());
764 std::unique_ptr<V8InspectorSessionImpl> session = V8InspectorSessionImpl::cr eate(this, contextGroupId, channel, client, state); 769 std::unique_ptr<V8InspectorSessionImpl> session =
765 m_sessions.set(contextGroupId, session.get()); 770 V8InspectorSessionImpl::create(this, contextGroupId, channel, client, st ate);
771 m_sessions[contextGroupId] = session.get();
766 return std::move(session); 772 return std::move(session);
767 } 773 }
768 774
769 void V8DebuggerImpl::disconnect(V8InspectorSessionImpl* session) 775 void V8DebuggerImpl::disconnect(V8InspectorSessionImpl* session)
770 { 776 {
771 DCHECK(m_sessions.contains(session->contextGroupId())); 777 DCHECK(m_sessions.find(session->contextGroupId()) != m_sessions.end());
772 m_sessions.remove(session->contextGroupId()); 778 m_sessions.erase(session->contextGroupId());
779 }
780
781 InspectedContext* V8DebuggerImpl::getContext(int groupId, int contextId) const
782 {
783 ContextsByGroupMap::const_iterator contextGroupIt = m_contexts.find(groupId) ;
784 if (contextGroupIt == m_contexts.cend())
785 return nullptr;
786
787 ContextByIdMap::iterator contextIt = contextGroupIt->second->find(contextId) ;
788 if (contextIt == contextGroupIt->second->end())
789 return nullptr;
790
791 return contextIt->second.get();
773 } 792 }
774 793
775 void V8DebuggerImpl::contextCreated(const V8ContextInfo& info) 794 void V8DebuggerImpl::contextCreated(const V8ContextInfo& info)
776 { 795 {
777 DCHECK(info.context->GetIsolate() == m_isolate); 796 DCHECK(info.context->GetIsolate() == m_isolate);
778 // TODO(dgozman): make s_lastContextId non-static. 797 // TODO(dgozman): make s_lastContextId non-static.
779 int contextId = atomicIncrement(&s_lastContextId); 798 int contextId = atomicIncrement(&s_lastContextId);
780 String16 debugData = String16::number(info.contextGroupId) + "," + String16: :number(contextId) + "," + (info.isDefault ? "default" : "nondefault"); 799 String16 debugData = String16::number(info.contextGroupId) + "," + String16: :number(contextId) + "," + (info.isDefault ? "default" : "nondefault");
781 v8::HandleScope scope(m_isolate); 800 v8::HandleScope scope(m_isolate);
782 v8::Context::Scope contextScope(info.context); 801 v8::Context::Scope contextScope(info.context);
783 info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex), toV8String(m_isolate, debugData)); 802 info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex), toV8String(m_isolate, debugData));
784 803
785 if (!m_contexts.contains(info.contextGroupId)) 804 ContextsByGroupMap::iterator contextIt = m_contexts.find(info.contextGroupId );
786 m_contexts.set(info.contextGroupId, wrapUnique(new ContextByIdMap())); 805 if (contextIt == m_contexts.end())
787 DCHECK(!m_contexts.get(info.contextGroupId)->contains(contextId)); 806 contextIt = m_contexts.insert(std::make_pair(info.contextGroupId, wrapUn ique(new ContextByIdMap()))).first;
788 807
789 std::unique_ptr<InspectedContext> contextOwner(new InspectedContext(this, in fo, contextId)); 808 const auto& contextById = contextIt->second;
790 InspectedContext* inspectedContext = contextOwner.get();
791 m_contexts.get(info.contextGroupId)->set(contextId, std::move(contextOwner)) ;
792 809
793 if (V8InspectorSessionImpl* session = m_sessions.get(info.contextGroupId)) 810 DCHECK(contextById->find(contextId) == contextById->cend());
794 session->runtimeAgent()->reportExecutionContextCreated(inspectedContext) ; 811 InspectedContext* context = new InspectedContext(this, info, contextId);
812 (*contextById)[contextId] = wrapUnique(context);
813 SessionMap::iterator sessionIt = m_sessions.find(info.contextGroupId);
814 if (sessionIt != m_sessions.end())
815 sessionIt->second->runtimeAgent()->reportExecutionContextCreated(context );
795 } 816 }
796 817
797 void V8DebuggerImpl::contextDestroyed(v8::Local<v8::Context> context) 818 void V8DebuggerImpl::contextDestroyed(v8::Local<v8::Context> context)
798 { 819 {
799 int contextId = V8Debugger::contextId(context); 820 int contextId = V8Debugger::contextId(context);
800 int contextGroupId = getGroupId(context); 821 int contextGroupId = getGroupId(context);
801 if (!m_contexts.contains(contextGroupId) || !m_contexts.get(contextGroupId)- >contains(contextId)) 822 InspectedContext* inspectedContext = getContext(contextGroupId, contextId);
823 if (!inspectedContext)
802 return; 824 return;
803 825
804 InspectedContext* inspectedContext = m_contexts.get(contextGroupId)->get(con textId); 826 SessionMap::iterator iter = m_sessions.find(contextGroupId);
805 if (V8InspectorSessionImpl* session = m_sessions.get(contextGroupId)) 827 if (iter != m_sessions.end())
806 session->runtimeAgent()->reportExecutionContextDestroyed(inspectedContex t); 828 iter->second->runtimeAgent()->reportExecutionContextDestroyed(inspectedC ontext);
807 829 discardInspectedContext(contextGroupId, contextId);
808 m_contexts.get(contextGroupId)->remove(contextId);
809 if (m_contexts.get(contextGroupId)->isEmpty())
810 m_contexts.remove(contextGroupId);
811 } 830 }
812 831
813 void V8DebuggerImpl::resetContextGroup(int contextGroupId) 832 void V8DebuggerImpl::resetContextGroup(int contextGroupId)
814 { 833 {
815 if (V8InspectorSessionImpl* session = m_sessions.get(contextGroupId)) 834 SessionMap::iterator session = m_sessions.find(contextGroupId);
816 session->reset(); 835 if (session != m_sessions.end())
817 m_contexts.remove(contextGroupId); 836 session->second->reset();
837 m_contexts.erase(contextGroupId);
818 } 838 }
819 839
820 void V8DebuggerImpl::setAsyncCallStackDepth(V8DebuggerAgentImpl* agent, int dept h) 840 void V8DebuggerImpl::setAsyncCallStackDepth(V8DebuggerAgentImpl* agent, int dept h)
821 { 841 {
822 if (depth <= 0) 842 if (depth <= 0)
823 m_maxAsyncCallStackDepthMap.remove(agent); 843 m_maxAsyncCallStackDepthMap.erase(agent);
824 else 844 else
825 m_maxAsyncCallStackDepthMap.set(agent, depth); 845 m_maxAsyncCallStackDepthMap[agent] = depth;
826 846
827 int maxAsyncCallStackDepth = 0; 847 int maxAsyncCallStackDepth = 0;
828 for (const auto& pair : m_maxAsyncCallStackDepthMap) { 848 for (const auto& pair : m_maxAsyncCallStackDepthMap) {
829 if (*pair.second > maxAsyncCallStackDepth) 849 if (pair.second > maxAsyncCallStackDepth)
830 maxAsyncCallStackDepth = *pair.second; 850 maxAsyncCallStackDepth = pair.second;
831 } 851 }
832 852
833 if (m_maxAsyncCallStackDepth == maxAsyncCallStackDepth) 853 if (m_maxAsyncCallStackDepth == maxAsyncCallStackDepth)
834 return; 854 return;
835 855
836 if (maxAsyncCallStackDepth && !m_maxAsyncCallStackDepth) 856 if (maxAsyncCallStackDepth && !m_maxAsyncCallStackDepth)
837 m_client->enableAsyncInstrumentation(); 857 m_client->enableAsyncInstrumentation();
838 else if (!maxAsyncCallStackDepth && m_maxAsyncCallStackDepth) 858 else if (!maxAsyncCallStackDepth && m_maxAsyncCallStackDepth)
839 m_client->disableAsyncInstrumentation(); 859 m_client->disableAsyncInstrumentation();
840 860
841 m_maxAsyncCallStackDepth = maxAsyncCallStackDepth; 861 m_maxAsyncCallStackDepth = maxAsyncCallStackDepth;
842 if (!maxAsyncCallStackDepth) 862 if (!maxAsyncCallStackDepth)
843 allAsyncTasksCanceled(); 863 allAsyncTasksCanceled();
844 } 864 }
845 865
846 void V8DebuggerImpl::asyncTaskScheduled(const String16& taskName, void* task, bo ol recurring) 866 void V8DebuggerImpl::asyncTaskScheduled(const String16& taskName, void* task, bo ol recurring)
847 { 867 {
848 if (!m_maxAsyncCallStackDepth) 868 if (!m_maxAsyncCallStackDepth)
849 return; 869 return;
850 v8::HandleScope scope(m_isolate); 870 v8::HandleScope scope(m_isolate);
851 int contextGroupId = m_isolate->InContext() ? getGroupId(m_isolate->GetCurre ntContext()) : 0; 871 int contextGroupId = m_isolate->InContext() ? getGroupId(m_isolate->GetCurre ntContext()) : 0;
852 std::unique_ptr<V8StackTraceImpl> chain = V8StackTraceImpl::capture(this, co ntextGroupId, V8StackTrace::maxCallStackSizeToCapture, taskName); 872 std::unique_ptr<V8StackTraceImpl> chain = V8StackTraceImpl::capture(this, co ntextGroupId, V8StackTrace::maxCallStackSizeToCapture, taskName);
853 if (chain) { 873 if (chain) {
854 m_asyncTaskStacks.set(task, std::move(chain)); 874 m_asyncTaskStacks[task] = std::move(chain);
855 if (recurring) 875 if (recurring)
856 m_recurringTasks.add(task); 876 m_recurringTasks.insert(task);
857 } 877 }
858 } 878 }
859 879
860 void V8DebuggerImpl::asyncTaskCanceled(void* task) 880 void V8DebuggerImpl::asyncTaskCanceled(void* task)
861 { 881 {
862 if (!m_maxAsyncCallStackDepth) 882 if (!m_maxAsyncCallStackDepth)
863 return; 883 return;
864 m_asyncTaskStacks.remove(task); 884 m_asyncTaskStacks.erase(task);
865 m_recurringTasks.remove(task); 885 m_recurringTasks.erase(task);
866 } 886 }
867 887
868 void V8DebuggerImpl::asyncTaskStarted(void* task) 888 void V8DebuggerImpl::asyncTaskStarted(void* task)
869 { 889 {
870 // Not enabled, return. 890 // Not enabled, return.
871 if (!m_maxAsyncCallStackDepth) 891 if (!m_maxAsyncCallStackDepth)
872 return; 892 return;
873 893
874 m_currentTasks.append(task); 894 m_currentTasks.push_back(task);
875 V8StackTraceImpl* stack = m_asyncTaskStacks.get(task); 895 AsyncTaskToStackTrace::iterator stackIt = m_asyncTaskStacks.find(task);
876 // Needs to support following order of events: 896 // Needs to support following order of events:
877 // - asyncTaskScheduled 897 // - asyncTaskScheduled
878 // <-- attached here --> 898 // <-- attached here -->
879 // - asyncTaskStarted 899 // - asyncTaskStarted
880 // - asyncTaskCanceled <-- canceled before finished 900 // - asyncTaskCanceled <-- canceled before finished
881 // <-- async stack requested here --> 901 // <-- async stack requested here -->
882 // - asyncTaskFinished 902 // - asyncTaskFinished
883 m_currentStacks.append(stack ? stack->cloneImpl() : nullptr); 903 std::unique_ptr<V8StackTraceImpl> stack;
904 if (stackIt != m_asyncTaskStacks.end() && stackIt->second)
905 stack = stackIt->second->cloneImpl();
906 m_currentStacks.push_back(std::move(stack));
884 } 907 }
885 908
886 void V8DebuggerImpl::asyncTaskFinished(void* task) 909 void V8DebuggerImpl::asyncTaskFinished(void* task)
887 { 910 {
888 if (!m_maxAsyncCallStackDepth) 911 if (!m_maxAsyncCallStackDepth)
889 return; 912 return;
890 // We could start instrumenting half way and the stack is empty. 913 // We could start instrumenting half way and the stack is empty.
891 if (!m_currentStacks.size()) 914 if (!m_currentStacks.size())
892 return; 915 return;
893 916
894 DCHECK(m_currentTasks.last() == task); 917 DCHECK(m_currentTasks.back() == task);
895 m_currentTasks.removeLast(); 918 m_currentTasks.pop_back();
896 919
897 m_currentStacks.removeLast(); 920 m_currentStacks.pop_back();
898 if (!m_recurringTasks.contains(task)) 921 if (m_recurringTasks.find(task) == m_recurringTasks.end())
899 m_asyncTaskStacks.remove(task); 922 m_asyncTaskStacks.erase(task);
900 } 923 }
901 924
902 void V8DebuggerImpl::allAsyncTasksCanceled() 925 void V8DebuggerImpl::allAsyncTasksCanceled()
903 { 926 {
904 m_asyncTaskStacks.clear(); 927 m_asyncTaskStacks.clear();
905 m_recurringTasks.clear(); 928 m_recurringTasks.clear();
906 m_currentStacks.clear(); 929 m_currentStacks.clear();
907 m_currentTasks.clear(); 930 m_currentTasks.clear();
908 } 931 }
909 932
(...skipping 27 matching lines...) Expand all
937 960
938 v8::Local<v8::Context> V8DebuggerImpl::regexContext() 961 v8::Local<v8::Context> V8DebuggerImpl::regexContext()
939 { 962 {
940 if (m_regexContext.IsEmpty()) 963 if (m_regexContext.IsEmpty())
941 m_regexContext.Reset(m_isolate, v8::Context::New(m_isolate)); 964 m_regexContext.Reset(m_isolate, v8::Context::New(m_isolate));
942 return m_regexContext.Get(m_isolate); 965 return m_regexContext.Get(m_isolate);
943 } 966 }
944 967
945 void V8DebuggerImpl::discardInspectedContext(int contextGroupId, int contextId) 968 void V8DebuggerImpl::discardInspectedContext(int contextGroupId, int contextId)
946 { 969 {
947 if (!m_contexts.contains(contextGroupId) || !m_contexts.get(contextGroupId)- >contains(contextId)) 970 if (!getContext(contextGroupId, contextId))
948 return; 971 return;
949 m_contexts.get(contextGroupId)->remove(contextId); 972 m_contexts[contextGroupId]->erase(contextId);
950 if (m_contexts.get(contextGroupId)->isEmpty()) 973 if (m_contexts[contextGroupId]->empty())
951 m_contexts.remove(contextGroupId); 974 m_contexts.erase(contextGroupId);
952 } 975 }
953 976
954 const V8DebuggerImpl::ContextByIdMap* V8DebuggerImpl::contextGroup(int contextGr oupId) 977 const V8DebuggerImpl::ContextByIdMap* V8DebuggerImpl::contextGroup(int contextGr oupId)
955 { 978 {
956 if (!m_contexts.contains(contextGroupId)) 979 ContextsByGroupMap::iterator iter = m_contexts.find(contextGroupId);
957 return nullptr; 980 return iter == m_contexts.end() ? nullptr : iter->second.get();
958 return m_contexts.get(contextGroupId);
959 } 981 }
960 982
961 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI d) 983 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI d)
962 { 984 {
963 return contextGroupId ? m_sessions.get(contextGroupId) : nullptr; 985 if (!contextGroupId)
986 return nullptr;
987 SessionMap::iterator iter = m_sessions.find(contextGroupId);
988 return iter == m_sessions.end() ? nullptr : iter->second;
964 } 989 }
965 990
966 } // namespace blink 991 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698