OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 = | |
784 m_contexts.find(groupId); | |
dgozman
2016/06/24 23:31:47
nit: place it on the same line
| |
785 if (contextGroupIt == m_contexts.cend()) | |
786 return nullptr; | |
787 | |
788 ContextByIdMap::iterator contextIt = contextGroupIt->second->find(contextId) ; | |
789 if (contextIt == contextGroupIt->second->end()) | |
790 return nullptr; | |
791 | |
792 return contextIt->second.get(); | |
773 } | 793 } |
774 | 794 |
775 void V8DebuggerImpl::contextCreated(const V8ContextInfo& info) | 795 void V8DebuggerImpl::contextCreated(const V8ContextInfo& info) |
776 { | 796 { |
777 DCHECK(info.context->GetIsolate() == m_isolate); | 797 DCHECK(info.context->GetIsolate() == m_isolate); |
778 // TODO(dgozman): make s_lastContextId non-static. | 798 // TODO(dgozman): make s_lastContextId non-static. |
779 int contextId = atomicIncrement(&s_lastContextId); | 799 int contextId = atomicIncrement(&s_lastContextId); |
780 String16 debugData = String16::number(info.contextGroupId) + "," + String16: :number(contextId) + "," + (info.isDefault ? "default" : "nondefault"); | 800 String16 debugData = String16::number(info.contextGroupId) + "," + String16: :number(contextId) + "," + (info.isDefault ? "default" : "nondefault"); |
781 v8::HandleScope scope(m_isolate); | 801 v8::HandleScope scope(m_isolate); |
782 v8::Context::Scope contextScope(info.context); | 802 v8::Context::Scope contextScope(info.context); |
783 info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex), toV8String(m_isolate, debugData)); | 803 info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex), toV8String(m_isolate, debugData)); |
784 | 804 |
785 if (!m_contexts.contains(info.contextGroupId)) | 805 ContextsByGroupMap::iterator contextIt = m_contexts.find(info.contextGroupId ); |
786 m_contexts.set(info.contextGroupId, wrapUnique(new ContextByIdMap())); | 806 if (contextIt == m_contexts.end()) |
787 DCHECK(!m_contexts.get(info.contextGroupId)->contains(contextId)); | 807 contextIt = m_contexts.insert(std::make_pair(info.contextGroupId, wrapUn ique(new ContextByIdMap()))).first; |
788 | 808 |
789 std::unique_ptr<InspectedContext> contextOwner(new InspectedContext(this, in fo, contextId)); | 809 const auto& contextById = contextIt->second; |
790 InspectedContext* inspectedContext = contextOwner.get(); | |
791 m_contexts.get(info.contextGroupId)->set(contextId, std::move(contextOwner)) ; | |
792 | 810 |
793 if (V8InspectorSessionImpl* session = m_sessions.get(info.contextGroupId)) | 811 DCHECK(contextById->find(contextId) == contextById->cend()); |
794 session->runtimeAgent()->reportExecutionContextCreated(inspectedContext) ; | 812 InspectedContext* context = new InspectedContext(this, info, contextId); |
813 (*contextById)[contextId] = wrapUnique(context); | |
814 SessionMap::iterator sessionIt = m_sessions.find(info.contextGroupId); | |
815 if (sessionIt != m_sessions.end()) | |
816 sessionIt->second->runtimeAgent()->reportExecutionContextCreated(context ); | |
795 } | 817 } |
796 | 818 |
797 void V8DebuggerImpl::contextDestroyed(v8::Local<v8::Context> context) | 819 void V8DebuggerImpl::contextDestroyed(v8::Local<v8::Context> context) |
798 { | 820 { |
799 int contextId = V8Debugger::contextId(context); | 821 int contextId = V8Debugger::contextId(context); |
800 int contextGroupId = getGroupId(context); | 822 int contextGroupId = getGroupId(context); |
801 if (!m_contexts.contains(contextGroupId) || !m_contexts.get(contextGroupId)- >contains(contextId)) | 823 InspectedContext* inspectedContext = getContext(contextGroupId, contextId); |
824 if (!inspectedContext) | |
802 return; | 825 return; |
803 | 826 |
804 InspectedContext* inspectedContext = m_contexts.get(contextGroupId)->get(con textId); | 827 SessionMap::iterator iter = m_sessions.find(contextGroupId); |
805 if (V8InspectorSessionImpl* session = m_sessions.get(contextGroupId)) | 828 if (iter != m_sessions.end()) |
806 session->runtimeAgent()->reportExecutionContextDestroyed(inspectedContex t); | 829 iter->second->runtimeAgent()->reportExecutionContextDestroyed(inspectedC ontext); |
807 | 830 discardInspectedContext(contextGroupId, contextId); |
808 m_contexts.get(contextGroupId)->remove(contextId); | |
809 if (m_contexts.get(contextGroupId)->isEmpty()) | |
810 m_contexts.remove(contextGroupId); | |
811 } | 831 } |
812 | 832 |
813 void V8DebuggerImpl::resetContextGroup(int contextGroupId) | 833 void V8DebuggerImpl::resetContextGroup(int contextGroupId) |
814 { | 834 { |
815 if (V8InspectorSessionImpl* session = m_sessions.get(contextGroupId)) | 835 SessionMap::iterator session = m_sessions.find(contextGroupId); |
816 session->reset(); | 836 if (session != m_sessions.end() && session->second) |
dgozman
2016/06/24 23:31:47
Drop session->second check.
| |
817 m_contexts.remove(contextGroupId); | 837 session->second->reset(); |
838 m_contexts.erase(contextGroupId); | |
818 } | 839 } |
819 | 840 |
820 void V8DebuggerImpl::setAsyncCallStackDepth(V8DebuggerAgentImpl* agent, int dept h) | 841 void V8DebuggerImpl::setAsyncCallStackDepth(V8DebuggerAgentImpl* agent, int dept h) |
821 { | 842 { |
822 if (depth <= 0) | 843 if (depth <= 0) |
823 m_maxAsyncCallStackDepthMap.remove(agent); | 844 m_maxAsyncCallStackDepthMap.erase(agent); |
824 else | 845 else |
825 m_maxAsyncCallStackDepthMap.set(agent, depth); | 846 m_maxAsyncCallStackDepthMap[agent] = depth; |
826 | 847 |
827 int maxAsyncCallStackDepth = 0; | 848 int maxAsyncCallStackDepth = 0; |
828 for (const auto& pair : m_maxAsyncCallStackDepthMap) { | 849 for (const auto& pair : m_maxAsyncCallStackDepthMap) { |
829 if (*pair.second > maxAsyncCallStackDepth) | 850 if (pair.second > maxAsyncCallStackDepth) |
830 maxAsyncCallStackDepth = *pair.second; | 851 maxAsyncCallStackDepth = pair.second; |
831 } | 852 } |
832 | 853 |
833 if (m_maxAsyncCallStackDepth == maxAsyncCallStackDepth) | 854 if (m_maxAsyncCallStackDepth == maxAsyncCallStackDepth) |
834 return; | 855 return; |
835 | 856 |
836 if (maxAsyncCallStackDepth && !m_maxAsyncCallStackDepth) | 857 if (maxAsyncCallStackDepth && !m_maxAsyncCallStackDepth) |
837 m_client->enableAsyncInstrumentation(); | 858 m_client->enableAsyncInstrumentation(); |
838 else if (!maxAsyncCallStackDepth && m_maxAsyncCallStackDepth) | 859 else if (!maxAsyncCallStackDepth && m_maxAsyncCallStackDepth) |
839 m_client->disableAsyncInstrumentation(); | 860 m_client->disableAsyncInstrumentation(); |
840 | 861 |
841 m_maxAsyncCallStackDepth = maxAsyncCallStackDepth; | 862 m_maxAsyncCallStackDepth = maxAsyncCallStackDepth; |
842 if (!maxAsyncCallStackDepth) | 863 if (!maxAsyncCallStackDepth) |
843 allAsyncTasksCanceled(); | 864 allAsyncTasksCanceled(); |
844 } | 865 } |
845 | 866 |
846 void V8DebuggerImpl::asyncTaskScheduled(const String16& taskName, void* task, bo ol recurring) | 867 void V8DebuggerImpl::asyncTaskScheduled(const String16& taskName, void* task, bo ol recurring) |
847 { | 868 { |
848 if (!m_maxAsyncCallStackDepth) | 869 if (!m_maxAsyncCallStackDepth) |
849 return; | 870 return; |
850 v8::HandleScope scope(m_isolate); | 871 v8::HandleScope scope(m_isolate); |
851 int contextGroupId = m_isolate->InContext() ? getGroupId(m_isolate->GetCurre ntContext()) : 0; | 872 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); | 873 std::unique_ptr<V8StackTraceImpl> chain = V8StackTraceImpl::capture(this, co ntextGroupId, V8StackTrace::maxCallStackSizeToCapture, taskName); |
853 if (chain) { | 874 if (chain) { |
854 m_asyncTaskStacks.set(task, std::move(chain)); | 875 m_asyncTaskStacks[task] = std::move(chain); |
855 if (recurring) | 876 if (recurring) |
856 m_recurringTasks.add(task); | 877 m_recurringTasks.insert(task); |
857 } | 878 } |
858 } | 879 } |
859 | 880 |
860 void V8DebuggerImpl::asyncTaskCanceled(void* task) | 881 void V8DebuggerImpl::asyncTaskCanceled(void* task) |
861 { | 882 { |
862 if (!m_maxAsyncCallStackDepth) | 883 if (!m_maxAsyncCallStackDepth) |
863 return; | 884 return; |
864 m_asyncTaskStacks.remove(task); | 885 m_asyncTaskStacks.erase(task); |
865 m_recurringTasks.remove(task); | 886 m_recurringTasks.erase(task); |
866 } | 887 } |
867 | 888 |
868 void V8DebuggerImpl::asyncTaskStarted(void* task) | 889 void V8DebuggerImpl::asyncTaskStarted(void* task) |
869 { | 890 { |
870 // Not enabled, return. | 891 // Not enabled, return. |
871 if (!m_maxAsyncCallStackDepth) | 892 if (!m_maxAsyncCallStackDepth) |
872 return; | 893 return; |
873 | 894 |
874 m_currentTasks.append(task); | 895 m_currentTasks.push_back(task); |
875 V8StackTraceImpl* stack = m_asyncTaskStacks.get(task); | 896 const std::unique_ptr<V8StackTraceImpl>& stack = m_asyncTaskStacks[task]; |
dgozman
2016/06/24 23:31:47
It could be that m_asyncTasksStacks doesn't have t
| |
876 // Needs to support following order of events: | 897 // Needs to support following order of events: |
877 // - asyncTaskScheduled | 898 // - asyncTaskScheduled |
878 // <-- attached here --> | 899 // <-- attached here --> |
879 // - asyncTaskStarted | 900 // - asyncTaskStarted |
880 // - asyncTaskCanceled <-- canceled before finished | 901 // - asyncTaskCanceled <-- canceled before finished |
881 // <-- async stack requested here --> | 902 // <-- async stack requested here --> |
882 // - asyncTaskFinished | 903 // - asyncTaskFinished |
883 m_currentStacks.append(stack ? stack->cloneImpl() : nullptr); | 904 m_currentStacks.push_back(stack ? stack->cloneImpl() : nullptr); |
884 } | 905 } |
885 | 906 |
886 void V8DebuggerImpl::asyncTaskFinished(void* task) | 907 void V8DebuggerImpl::asyncTaskFinished(void* task) |
887 { | 908 { |
888 if (!m_maxAsyncCallStackDepth) | 909 if (!m_maxAsyncCallStackDepth) |
889 return; | 910 return; |
890 // We could start instrumenting half way and the stack is empty. | 911 // We could start instrumenting half way and the stack is empty. |
891 if (!m_currentStacks.size()) | 912 if (!m_currentStacks.size()) |
892 return; | 913 return; |
893 | 914 |
894 DCHECK(m_currentTasks.last() == task); | 915 DCHECK(m_currentTasks.back() == task); |
895 m_currentTasks.removeLast(); | 916 m_currentTasks.pop_back(); |
896 | 917 |
897 m_currentStacks.removeLast(); | 918 m_currentStacks.pop_back(); |
898 if (!m_recurringTasks.contains(task)) | 919 if (m_recurringTasks.find(task) == m_recurringTasks.end()) |
899 m_asyncTaskStacks.remove(task); | 920 m_asyncTaskStacks.erase(task); |
900 } | 921 } |
901 | 922 |
902 void V8DebuggerImpl::allAsyncTasksCanceled() | 923 void V8DebuggerImpl::allAsyncTasksCanceled() |
903 { | 924 { |
904 m_asyncTaskStacks.clear(); | 925 m_asyncTaskStacks.clear(); |
905 m_recurringTasks.clear(); | 926 m_recurringTasks.clear(); |
906 m_currentStacks.clear(); | 927 m_currentStacks.clear(); |
907 m_currentTasks.clear(); | 928 m_currentTasks.clear(); |
908 } | 929 } |
909 | 930 |
(...skipping 27 matching lines...) Expand all Loading... | |
937 | 958 |
938 v8::Local<v8::Context> V8DebuggerImpl::regexContext() | 959 v8::Local<v8::Context> V8DebuggerImpl::regexContext() |
939 { | 960 { |
940 if (m_regexContext.IsEmpty()) | 961 if (m_regexContext.IsEmpty()) |
941 m_regexContext.Reset(m_isolate, v8::Context::New(m_isolate)); | 962 m_regexContext.Reset(m_isolate, v8::Context::New(m_isolate)); |
942 return m_regexContext.Get(m_isolate); | 963 return m_regexContext.Get(m_isolate); |
943 } | 964 } |
944 | 965 |
945 void V8DebuggerImpl::discardInspectedContext(int contextGroupId, int contextId) | 966 void V8DebuggerImpl::discardInspectedContext(int contextGroupId, int contextId) |
946 { | 967 { |
947 if (!m_contexts.contains(contextGroupId) || !m_contexts.get(contextGroupId)- >contains(contextId)) | 968 if (!getContext(contextGroupId, contextId)) |
948 return; | 969 return; |
949 m_contexts.get(contextGroupId)->remove(contextId); | 970 m_contexts[contextGroupId]->erase(contextId); |
950 if (m_contexts.get(contextGroupId)->isEmpty()) | 971 if (m_contexts[contextGroupId]->empty()) |
951 m_contexts.remove(contextGroupId); | 972 m_contexts.erase(contextGroupId); |
952 } | 973 } |
953 | 974 |
954 const V8DebuggerImpl::ContextByIdMap* V8DebuggerImpl::contextGroup(int contextGr oupId) | 975 const V8DebuggerImpl::ContextByIdMap* V8DebuggerImpl::contextGroup(int contextGr oupId) |
955 { | 976 { |
956 if (!m_contexts.contains(contextGroupId)) | 977 ContextsByGroupMap::iterator iter = m_contexts.find(contextGroupId); |
957 return nullptr; | 978 return iter == m_contexts.end() ? nullptr : iter->second.get(); |
958 return m_contexts.get(contextGroupId); | |
959 } | 979 } |
960 | 980 |
961 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI d) | 981 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI d) |
962 { | 982 { |
963 return contextGroupId ? m_sessions.get(contextGroupId) : nullptr; | 983 if (!contextGroupId) |
984 return nullptr; | |
985 SessionMap::iterator iter = m_sessions.find(contextGroupId); | |
986 return iter == m_sessions.end() ? nullptr : iter->second; | |
964 } | 987 } |
965 | 988 |
966 } // namespace blink | 989 } // namespace blink |
OLD | NEW |