LCOV - code coverage report
Current view: top level - out/Release/gen/src/inspector/protocol - HeapProfiler.cpp (source / functions) Hit Total Coverage
Test: app.info Lines: 115 399 28.8 %
Date: 2019-02-19 Functions: 18 47 38.3 %

          Line data    Source code
       1             : // This file is generated by TypeBuilder_cpp.template.
       2             : 
       3             : // Copyright (c) 2016 The Chromium Authors. All rights reserved.
       4             : // Use of this source code is governed by a BSD-style license that can be
       5             : // found in the LICENSE file.
       6             : 
       7             : #include "src/inspector/protocol/HeapProfiler.h"
       8             : 
       9             : #include "src/inspector/protocol/Protocol.h"
      10             : 
      11             : namespace v8_inspector {
      12             : namespace protocol {
      13             : namespace HeapProfiler {
      14             : 
      15             : // ------------- Enum values from types.
      16             : 
      17             : const char Metainfo::domainName[] = "HeapProfiler";
      18             : const char Metainfo::commandPrefix[] = "HeapProfiler.";
      19             : const char Metainfo::version[] = "1.3";
      20             : 
      21           0 : std::unique_ptr<SamplingHeapProfileNode> SamplingHeapProfileNode::fromValue(protocol::Value* value, ErrorSupport* errors)
      22             : {
      23           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
      24           0 :         errors->addError("object expected");
      25             :         return nullptr;
      26             :     }
      27             : 
      28           0 :     std::unique_ptr<SamplingHeapProfileNode> result(new SamplingHeapProfileNode());
      29             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
      30           0 :     errors->push();
      31           0 :     protocol::Value* callFrameValue = object->get("callFrame");
      32           0 :     errors->setName("callFrame");
      33           0 :     result->m_callFrame = ValueConversions<protocol::Runtime::CallFrame>::fromValue(callFrameValue, errors);
      34           0 :     protocol::Value* selfSizeValue = object->get("selfSize");
      35           0 :     errors->setName("selfSize");
      36           0 :     result->m_selfSize = ValueConversions<double>::fromValue(selfSizeValue, errors);
      37           0 :     protocol::Value* idValue = object->get("id");
      38           0 :     errors->setName("id");
      39           0 :     result->m_id = ValueConversions<int>::fromValue(idValue, errors);
      40           0 :     protocol::Value* childrenValue = object->get("children");
      41           0 :     errors->setName("children");
      42           0 :     result->m_children = ValueConversions<protocol::Array<protocol::HeapProfiler::SamplingHeapProfileNode>>::fromValue(childrenValue, errors);
      43           0 :     errors->pop();
      44           0 :     if (errors->hasErrors())
      45             :         return nullptr;
      46             :     return result;
      47             : }
      48             : 
      49          50 : std::unique_ptr<protocol::DictionaryValue> SamplingHeapProfileNode::toValue() const
      50             : {
      51          50 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
      52         200 :     result->setValue("callFrame", ValueConversions<protocol::Runtime::CallFrame>::toValue(m_callFrame.get()));
      53         250 :     result->setValue("selfSize", ValueConversions<double>::toValue(m_selfSize));
      54         250 :     result->setValue("id", ValueConversions<int>::toValue(m_id));
      55         200 :     result->setValue("children", ValueConversions<protocol::Array<protocol::HeapProfiler::SamplingHeapProfileNode>>::toValue(m_children.get()));
      56          50 :     return result;
      57             : }
      58             : 
      59           0 : std::unique_ptr<SamplingHeapProfileNode> SamplingHeapProfileNode::clone() const
      60             : {
      61           0 :     ErrorSupport errors;
      62           0 :     return fromValue(toValue().get(), &errors);
      63             : }
      64             : 
      65           0 : std::unique_ptr<SamplingHeapProfileSample> SamplingHeapProfileSample::fromValue(protocol::Value* value, ErrorSupport* errors)
      66             : {
      67           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
      68           0 :         errors->addError("object expected");
      69             :         return nullptr;
      70             :     }
      71             : 
      72           0 :     std::unique_ptr<SamplingHeapProfileSample> result(new SamplingHeapProfileSample());
      73             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
      74           0 :     errors->push();
      75           0 :     protocol::Value* sizeValue = object->get("size");
      76           0 :     errors->setName("size");
      77           0 :     result->m_size = ValueConversions<double>::fromValue(sizeValue, errors);
      78           0 :     protocol::Value* nodeIdValue = object->get("nodeId");
      79           0 :     errors->setName("nodeId");
      80           0 :     result->m_nodeId = ValueConversions<int>::fromValue(nodeIdValue, errors);
      81           0 :     protocol::Value* ordinalValue = object->get("ordinal");
      82           0 :     errors->setName("ordinal");
      83           0 :     result->m_ordinal = ValueConversions<double>::fromValue(ordinalValue, errors);
      84           0 :     errors->pop();
      85           0 :     if (errors->hasErrors())
      86             :         return nullptr;
      87             :     return result;
      88             : }
      89             : 
      90          25 : std::unique_ptr<protocol::DictionaryValue> SamplingHeapProfileSample::toValue() const
      91             : {
      92          25 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
      93         125 :     result->setValue("size", ValueConversions<double>::toValue(m_size));
      94         125 :     result->setValue("nodeId", ValueConversions<int>::toValue(m_nodeId));
      95         125 :     result->setValue("ordinal", ValueConversions<double>::toValue(m_ordinal));
      96          25 :     return result;
      97             : }
      98             : 
      99           0 : std::unique_ptr<SamplingHeapProfileSample> SamplingHeapProfileSample::clone() const
     100             : {
     101           0 :     ErrorSupport errors;
     102           0 :     return fromValue(toValue().get(), &errors);
     103             : }
     104             : 
     105           0 : std::unique_ptr<SamplingHeapProfile> SamplingHeapProfile::fromValue(protocol::Value* value, ErrorSupport* errors)
     106             : {
     107           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     108           0 :         errors->addError("object expected");
     109             :         return nullptr;
     110             :     }
     111             : 
     112           0 :     std::unique_ptr<SamplingHeapProfile> result(new SamplingHeapProfile());
     113             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     114           0 :     errors->push();
     115           0 :     protocol::Value* headValue = object->get("head");
     116           0 :     errors->setName("head");
     117           0 :     result->m_head = ValueConversions<protocol::HeapProfiler::SamplingHeapProfileNode>::fromValue(headValue, errors);
     118           0 :     protocol::Value* samplesValue = object->get("samples");
     119           0 :     errors->setName("samples");
     120           0 :     result->m_samples = ValueConversions<protocol::Array<protocol::HeapProfiler::SamplingHeapProfileSample>>::fromValue(samplesValue, errors);
     121           0 :     errors->pop();
     122           0 :     if (errors->hasErrors())
     123             :         return nullptr;
     124             :     return result;
     125             : }
     126             : 
     127          20 : std::unique_ptr<protocol::DictionaryValue> SamplingHeapProfile::toValue() const
     128             : {
     129          20 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     130          80 :     result->setValue("head", ValueConversions<protocol::HeapProfiler::SamplingHeapProfileNode>::toValue(m_head.get()));
     131          80 :     result->setValue("samples", ValueConversions<protocol::Array<protocol::HeapProfiler::SamplingHeapProfileSample>>::toValue(m_samples.get()));
     132          20 :     return result;
     133             : }
     134             : 
     135           0 : std::unique_ptr<SamplingHeapProfile> SamplingHeapProfile::clone() const
     136             : {
     137           0 :     ErrorSupport errors;
     138           0 :     return fromValue(toValue().get(), &errors);
     139             : }
     140             : 
     141           0 : std::unique_ptr<AddHeapSnapshotChunkNotification> AddHeapSnapshotChunkNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     142             : {
     143           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     144           0 :         errors->addError("object expected");
     145             :         return nullptr;
     146             :     }
     147             : 
     148           0 :     std::unique_ptr<AddHeapSnapshotChunkNotification> result(new AddHeapSnapshotChunkNotification());
     149             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     150           0 :     errors->push();
     151           0 :     protocol::Value* chunkValue = object->get("chunk");
     152           0 :     errors->setName("chunk");
     153           0 :     result->m_chunk = ValueConversions<String>::fromValue(chunkValue, errors);
     154           0 :     errors->pop();
     155           0 :     if (errors->hasErrors())
     156             :         return nullptr;
     157             :     return result;
     158             : }
     159             : 
     160         170 : std::unique_ptr<protocol::DictionaryValue> AddHeapSnapshotChunkNotification::toValue() const
     161             : {
     162         170 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     163         850 :     result->setValue("chunk", ValueConversions<String>::toValue(m_chunk));
     164         170 :     return result;
     165             : }
     166             : 
     167           0 : std::unique_ptr<AddHeapSnapshotChunkNotification> AddHeapSnapshotChunkNotification::clone() const
     168             : {
     169           0 :     ErrorSupport errors;
     170           0 :     return fromValue(toValue().get(), &errors);
     171             : }
     172             : 
     173           0 : std::unique_ptr<HeapStatsUpdateNotification> HeapStatsUpdateNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     174             : {
     175           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     176           0 :         errors->addError("object expected");
     177             :         return nullptr;
     178             :     }
     179             : 
     180           0 :     std::unique_ptr<HeapStatsUpdateNotification> result(new HeapStatsUpdateNotification());
     181             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     182           0 :     errors->push();
     183           0 :     protocol::Value* statsUpdateValue = object->get("statsUpdate");
     184           0 :     errors->setName("statsUpdate");
     185             :     result->m_statsUpdate = ValueConversions<protocol::Array<int>>::fromValue(statsUpdateValue, errors);
     186           0 :     errors->pop();
     187           0 :     if (errors->hasErrors())
     188             :         return nullptr;
     189             :     return result;
     190             : }
     191             : 
     192           0 : std::unique_ptr<protocol::DictionaryValue> HeapStatsUpdateNotification::toValue() const
     193             : {
     194           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     195           0 :     result->setValue("statsUpdate", ValueConversions<protocol::Array<int>>::toValue(m_statsUpdate.get()));
     196           0 :     return result;
     197             : }
     198             : 
     199           0 : std::unique_ptr<HeapStatsUpdateNotification> HeapStatsUpdateNotification::clone() const
     200             : {
     201           0 :     ErrorSupport errors;
     202           0 :     return fromValue(toValue().get(), &errors);
     203             : }
     204             : 
     205           0 : std::unique_ptr<LastSeenObjectIdNotification> LastSeenObjectIdNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     206             : {
     207           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     208           0 :         errors->addError("object expected");
     209             :         return nullptr;
     210             :     }
     211             : 
     212           0 :     std::unique_ptr<LastSeenObjectIdNotification> result(new LastSeenObjectIdNotification());
     213             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     214           0 :     errors->push();
     215           0 :     protocol::Value* lastSeenObjectIdValue = object->get("lastSeenObjectId");
     216           0 :     errors->setName("lastSeenObjectId");
     217           0 :     result->m_lastSeenObjectId = ValueConversions<int>::fromValue(lastSeenObjectIdValue, errors);
     218           0 :     protocol::Value* timestampValue = object->get("timestamp");
     219           0 :     errors->setName("timestamp");
     220           0 :     result->m_timestamp = ValueConversions<double>::fromValue(timestampValue, errors);
     221           0 :     errors->pop();
     222           0 :     if (errors->hasErrors())
     223             :         return nullptr;
     224             :     return result;
     225             : }
     226             : 
     227           0 : std::unique_ptr<protocol::DictionaryValue> LastSeenObjectIdNotification::toValue() const
     228             : {
     229           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     230           0 :     result->setValue("lastSeenObjectId", ValueConversions<int>::toValue(m_lastSeenObjectId));
     231           0 :     result->setValue("timestamp", ValueConversions<double>::toValue(m_timestamp));
     232           0 :     return result;
     233             : }
     234             : 
     235           0 : std::unique_ptr<LastSeenObjectIdNotification> LastSeenObjectIdNotification::clone() const
     236             : {
     237           0 :     ErrorSupport errors;
     238           0 :     return fromValue(toValue().get(), &errors);
     239             : }
     240             : 
     241           0 : std::unique_ptr<ReportHeapSnapshotProgressNotification> ReportHeapSnapshotProgressNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     242             : {
     243           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     244           0 :         errors->addError("object expected");
     245             :         return nullptr;
     246             :     }
     247             : 
     248           0 :     std::unique_ptr<ReportHeapSnapshotProgressNotification> result(new ReportHeapSnapshotProgressNotification());
     249             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     250           0 :     errors->push();
     251           0 :     protocol::Value* doneValue = object->get("done");
     252           0 :     errors->setName("done");
     253           0 :     result->m_done = ValueConversions<int>::fromValue(doneValue, errors);
     254           0 :     protocol::Value* totalValue = object->get("total");
     255           0 :     errors->setName("total");
     256           0 :     result->m_total = ValueConversions<int>::fromValue(totalValue, errors);
     257           0 :     protocol::Value* finishedValue = object->get("finished");
     258           0 :     if (finishedValue) {
     259           0 :         errors->setName("finished");
     260           0 :         result->m_finished = ValueConversions<bool>::fromValue(finishedValue, errors);
     261             :     }
     262           0 :     errors->pop();
     263           0 :     if (errors->hasErrors())
     264             :         return nullptr;
     265             :     return result;
     266             : }
     267             : 
     268           0 : std::unique_ptr<protocol::DictionaryValue> ReportHeapSnapshotProgressNotification::toValue() const
     269             : {
     270           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     271           0 :     result->setValue("done", ValueConversions<int>::toValue(m_done));
     272           0 :     result->setValue("total", ValueConversions<int>::toValue(m_total));
     273           0 :     if (m_finished.isJust())
     274           0 :         result->setValue("finished", ValueConversions<bool>::toValue(m_finished.fromJust()));
     275           0 :     return result;
     276             : }
     277             : 
     278           0 : std::unique_ptr<ReportHeapSnapshotProgressNotification> ReportHeapSnapshotProgressNotification::clone() const
     279             : {
     280           0 :     ErrorSupport errors;
     281           0 :     return fromValue(toValue().get(), &errors);
     282             : }
     283             : 
     284             : // ------------- Enum values from params.
     285             : 
     286             : 
     287             : // ------------- Frontend notifications.
     288             : 
     289         170 : void Frontend::addHeapSnapshotChunk(const String& chunk)
     290             : {
     291         170 :     if (!m_frontendChannel)
     292         170 :         return;
     293             :     std::unique_ptr<AddHeapSnapshotChunkNotification> messageData = AddHeapSnapshotChunkNotification::create()
     294         170 :         .setChunk(chunk)
     295             :         .build();
     296        1190 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.addHeapSnapshotChunk", std::move(messageData)));
     297             : }
     298             : 
     299           0 : void Frontend::heapStatsUpdate(std::unique_ptr<protocol::Array<int>> statsUpdate)
     300             : {
     301           0 :     if (!m_frontendChannel)
     302           0 :         return;
     303             :     std::unique_ptr<HeapStatsUpdateNotification> messageData = HeapStatsUpdateNotification::create()
     304             :         .setStatsUpdate(std::move(statsUpdate))
     305             :         .build();
     306           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.heapStatsUpdate", std::move(messageData)));
     307             : }
     308             : 
     309           0 : void Frontend::lastSeenObjectId(int lastSeenObjectId, double timestamp)
     310             : {
     311           0 :     if (!m_frontendChannel)
     312           0 :         return;
     313             :     std::unique_ptr<LastSeenObjectIdNotification> messageData = LastSeenObjectIdNotification::create()
     314           0 :         .setLastSeenObjectId(lastSeenObjectId)
     315             :         .setTimestamp(timestamp)
     316             :         .build();
     317           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.lastSeenObjectId", std::move(messageData)));
     318             : }
     319             : 
     320           0 : void Frontend::reportHeapSnapshotProgress(int done, int total, Maybe<bool> finished)
     321             : {
     322           0 :     if (!m_frontendChannel)
     323           0 :         return;
     324             :     std::unique_ptr<ReportHeapSnapshotProgressNotification> messageData = ReportHeapSnapshotProgressNotification::create()
     325           0 :         .setDone(done)
     326             :         .setTotal(total)
     327             :         .build();
     328           0 :     if (finished.isJust())
     329           0 :         messageData->setFinished(std::move(finished).takeJust());
     330           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.reportHeapSnapshotProgress", std::move(messageData)));
     331             : }
     332             : 
     333           0 : void Frontend::resetProfiles()
     334             : {
     335           0 :     if (!m_frontendChannel)
     336           0 :         return;
     337           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.resetProfiles"));
     338             : }
     339             : 
     340         170 : void Frontend::flush()
     341             : {
     342         170 :     m_frontendChannel->flushProtocolNotifications();
     343         170 : }
     344             : 
     345           0 : void Frontend::sendRawNotification(String notification)
     346             : {
     347           0 :     m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromJSON(std::move(notification)));
     348           0 : }
     349             : 
     350           0 : void Frontend::sendRawNotification(std::vector<uint8_t> notification)
     351             : {
     352           0 :     m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromBinary(std::move(notification)));
     353           0 : }
     354             : 
     355             : // --------------------- Dispatcher.
     356             : 
     357             : class DispatcherImpl : public protocol::DispatcherBase {
     358             : public:
     359        3832 :     DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend)
     360             :         : DispatcherBase(frontendChannel)
     361       11496 :         , m_backend(backend) {
     362       11496 :         m_dispatchMap["HeapProfiler.addInspectedHeapObject"] = &DispatcherImpl::addInspectedHeapObject;
     363       11496 :         m_dispatchMap["HeapProfiler.collectGarbage"] = &DispatcherImpl::collectGarbage;
     364       11496 :         m_dispatchMap["HeapProfiler.disable"] = &DispatcherImpl::disable;
     365       11496 :         m_dispatchMap["HeapProfiler.enable"] = &DispatcherImpl::enable;
     366       11496 :         m_dispatchMap["HeapProfiler.getHeapObjectId"] = &DispatcherImpl::getHeapObjectId;
     367       11496 :         m_dispatchMap["HeapProfiler.getObjectByHeapObjectId"] = &DispatcherImpl::getObjectByHeapObjectId;
     368       11496 :         m_dispatchMap["HeapProfiler.getSamplingProfile"] = &DispatcherImpl::getSamplingProfile;
     369       11496 :         m_dispatchMap["HeapProfiler.startSampling"] = &DispatcherImpl::startSampling;
     370       11496 :         m_dispatchMap["HeapProfiler.startTrackingHeapObjects"] = &DispatcherImpl::startTrackingHeapObjects;
     371       11496 :         m_dispatchMap["HeapProfiler.stopSampling"] = &DispatcherImpl::stopSampling;
     372       11496 :         m_dispatchMap["HeapProfiler.stopTrackingHeapObjects"] = &DispatcherImpl::stopTrackingHeapObjects;
     373       11496 :         m_dispatchMap["HeapProfiler.takeHeapSnapshot"] = &DispatcherImpl::takeHeapSnapshot;
     374        3832 :     }
     375       11496 :     ~DispatcherImpl() override { }
     376             :     bool canDispatch(const String& method) override;
     377             :     void dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
     378             :     std::unordered_map<String, String>& redirects() { return m_redirects; }
     379             : 
     380             : protected:
     381             :     using CallHandler = void (DispatcherImpl::*)(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
     382             :     using DispatchMap = std::unordered_map<String, CallHandler>;
     383             :     DispatchMap m_dispatchMap;
     384             :     std::unordered_map<String, String> m_redirects;
     385             : 
     386             :     void addInspectedHeapObject(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     387             :     void collectGarbage(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     388             :     void disable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     389             :     void enable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     390             :     void getHeapObjectId(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     391             :     void getObjectByHeapObjectId(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     392             :     void getSamplingProfile(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     393             :     void startSampling(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     394             :     void startTrackingHeapObjects(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     395             :     void stopSampling(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     396             :     void stopTrackingHeapObjects(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     397             :     void takeHeapSnapshot(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     398             : 
     399             :     Backend* m_backend;
     400             : };
     401             : 
     402         272 : bool DispatcherImpl::canDispatch(const String& method) {
     403         272 :     return m_dispatchMap.find(method) != m_dispatchMap.end();
     404             : }
     405             : 
     406         272 : void DispatcherImpl::dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject)
     407             : {
     408             :     std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
     409             :     DCHECK(it != m_dispatchMap.end());
     410         272 :     protocol::ErrorSupport errors;
     411         816 :     (this->*(it->second))(callId, method, message, std::move(messageObject), &errors);
     412         272 : }
     413             : 
     414             : 
     415           0 : void DispatcherImpl::addInspectedHeapObject(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     416             : {
     417             :     // Prepare input parameters.
     418           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     419           0 :     errors->push();
     420           0 :     protocol::Value* heapObjectIdValue = object ? object->get("heapObjectId") : nullptr;
     421           0 :     errors->setName("heapObjectId");
     422           0 :     String in_heapObjectId = ValueConversions<String>::fromValue(heapObjectIdValue, errors);
     423           0 :     errors->pop();
     424           0 :     if (errors->hasErrors()) {
     425           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     426           0 :         return;
     427             :     }
     428             : 
     429           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     430           0 :     DispatchResponse response = m_backend->addInspectedHeapObject(in_heapObjectId);
     431           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     432           0 :         channel()->fallThrough(callId, method, message);
     433           0 :         return;
     434             :     }
     435           0 :     if (weak->get())
     436           0 :         weak->get()->sendResponse(callId, response);
     437             :     return;
     438             : }
     439             : 
     440         197 : void DispatcherImpl::collectGarbage(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     441             : {
     442             : 
     443         197 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     444         197 :     DispatchResponse response = m_backend->collectGarbage();
     445         197 :     if (response.status() == DispatchResponse::kFallThrough) {
     446           0 :         channel()->fallThrough(callId, method, message);
     447           0 :         return;
     448             :     }
     449         197 :     if (weak->get())
     450         197 :         weak->get()->sendResponse(callId, response);
     451             :     return;
     452             : }
     453             : 
     454           0 : void DispatcherImpl::disable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     455             : {
     456             : 
     457           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     458           0 :     DispatchResponse response = m_backend->disable();
     459           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     460           0 :         channel()->fallThrough(callId, method, message);
     461           0 :         return;
     462             :     }
     463           0 :     if (weak->get())
     464           0 :         weak->get()->sendResponse(callId, response);
     465             :     return;
     466             : }
     467             : 
     468          20 : void DispatcherImpl::enable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     469             : {
     470             : 
     471          20 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     472          20 :     DispatchResponse response = m_backend->enable();
     473          20 :     if (response.status() == DispatchResponse::kFallThrough) {
     474           0 :         channel()->fallThrough(callId, method, message);
     475           0 :         return;
     476             :     }
     477          20 :     if (weak->get())
     478          20 :         weak->get()->sendResponse(callId, response);
     479             :     return;
     480             : }
     481             : 
     482           0 : void DispatcherImpl::getHeapObjectId(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     483             : {
     484             :     // Prepare input parameters.
     485           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     486           0 :     errors->push();
     487           0 :     protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
     488           0 :     errors->setName("objectId");
     489           0 :     String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
     490           0 :     errors->pop();
     491           0 :     if (errors->hasErrors()) {
     492           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     493           0 :         return;
     494             :     }
     495             :     // Declare output parameters.
     496             :     String out_heapSnapshotObjectId;
     497             : 
     498           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     499           0 :     DispatchResponse response = m_backend->getHeapObjectId(in_objectId, &out_heapSnapshotObjectId);
     500           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     501           0 :         channel()->fallThrough(callId, method, message);
     502           0 :         return;
     503             :     }
     504           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     505           0 :     if (response.status() == DispatchResponse::kSuccess) {
     506           0 :         result->setValue("heapSnapshotObjectId", ValueConversions<String>::toValue(out_heapSnapshotObjectId));
     507             :     }
     508           0 :     if (weak->get())
     509           0 :         weak->get()->sendResponse(callId, response, std::move(result));
     510             :     return;
     511             : }
     512             : 
     513           0 : void DispatcherImpl::getObjectByHeapObjectId(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     514             : {
     515             :     // Prepare input parameters.
     516           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     517           0 :     errors->push();
     518           0 :     protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
     519           0 :     errors->setName("objectId");
     520           0 :     String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
     521           0 :     protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr;
     522             :     Maybe<String> in_objectGroup;
     523           0 :     if (objectGroupValue) {
     524           0 :         errors->setName("objectGroup");
     525           0 :         in_objectGroup = ValueConversions<String>::fromValue(objectGroupValue, errors);
     526             :     }
     527           0 :     errors->pop();
     528           0 :     if (errors->hasErrors()) {
     529           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     530           0 :         return;
     531             :     }
     532             :     // Declare output parameters.
     533           0 :     std::unique_ptr<protocol::Runtime::RemoteObject> out_result;
     534             : 
     535           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     536           0 :     DispatchResponse response = m_backend->getObjectByHeapObjectId(in_objectId, std::move(in_objectGroup), &out_result);
     537           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     538           0 :         channel()->fallThrough(callId, method, message);
     539           0 :         return;
     540             :     }
     541           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     542           0 :     if (response.status() == DispatchResponse::kSuccess) {
     543           0 :         result->setValue("result", ValueConversions<protocol::Runtime::RemoteObject>::toValue(out_result.get()));
     544             :     }
     545           0 :     if (weak->get())
     546           0 :         weak->get()->sendResponse(callId, response, std::move(result));
     547             :     return;
     548             : }
     549             : 
     550          20 : void DispatcherImpl::getSamplingProfile(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     551             : {
     552             :     // Declare output parameters.
     553          20 :     std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile> out_profile;
     554             : 
     555          20 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     556          20 :     DispatchResponse response = m_backend->getSamplingProfile(&out_profile);
     557          20 :     if (response.status() == DispatchResponse::kFallThrough) {
     558           0 :         channel()->fallThrough(callId, method, message);
     559           0 :         return;
     560             :     }
     561          20 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     562          20 :     if (response.status() == DispatchResponse::kSuccess) {
     563          60 :         result->setValue("profile", ValueConversions<protocol::HeapProfiler::SamplingHeapProfile>::toValue(out_profile.get()));
     564             :     }
     565          20 :     if (weak->get())
     566          40 :         weak->get()->sendResponse(callId, response, std::move(result));
     567             :     return;
     568             : }
     569             : 
     570           5 : void DispatcherImpl::startSampling(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     571             : {
     572             :     // Prepare input parameters.
     573          15 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     574           5 :     errors->push();
     575          10 :     protocol::Value* samplingIntervalValue = object ? object->get("samplingInterval") : nullptr;
     576             :     Maybe<double> in_samplingInterval;
     577           5 :     if (samplingIntervalValue) {
     578           0 :         errors->setName("samplingInterval");
     579           0 :         in_samplingInterval = ValueConversions<double>::fromValue(samplingIntervalValue, errors);
     580             :     }
     581           5 :     errors->pop();
     582           5 :     if (errors->hasErrors()) {
     583           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     584           0 :         return;
     585             :     }
     586             : 
     587           5 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     588          10 :     DispatchResponse response = m_backend->startSampling(std::move(in_samplingInterval));
     589           5 :     if (response.status() == DispatchResponse::kFallThrough) {
     590           0 :         channel()->fallThrough(callId, method, message);
     591           0 :         return;
     592             :     }
     593           5 :     if (weak->get())
     594           5 :         weak->get()->sendResponse(callId, response);
     595             :     return;
     596             : }
     597             : 
     598           0 : void DispatcherImpl::startTrackingHeapObjects(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     599             : {
     600             :     // Prepare input parameters.
     601           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     602           0 :     errors->push();
     603           0 :     protocol::Value* trackAllocationsValue = object ? object->get("trackAllocations") : nullptr;
     604             :     Maybe<bool> in_trackAllocations;
     605           0 :     if (trackAllocationsValue) {
     606           0 :         errors->setName("trackAllocations");
     607           0 :         in_trackAllocations = ValueConversions<bool>::fromValue(trackAllocationsValue, errors);
     608             :     }
     609           0 :     errors->pop();
     610           0 :     if (errors->hasErrors()) {
     611           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     612           0 :         return;
     613             :     }
     614             : 
     615           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     616           0 :     DispatchResponse response = m_backend->startTrackingHeapObjects(std::move(in_trackAllocations));
     617           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     618           0 :         channel()->fallThrough(callId, method, message);
     619           0 :         return;
     620             :     }
     621           0 :     if (weak->get())
     622           0 :         weak->get()->sendResponse(callId, response);
     623             :     return;
     624             : }
     625             : 
     626           5 : void DispatcherImpl::stopSampling(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     627             : {
     628             :     // Declare output parameters.
     629           5 :     std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile> out_profile;
     630             : 
     631           5 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     632           5 :     DispatchResponse response = m_backend->stopSampling(&out_profile);
     633           5 :     if (response.status() == DispatchResponse::kFallThrough) {
     634           0 :         channel()->fallThrough(callId, method, message);
     635           0 :         return;
     636             :     }
     637           5 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     638           5 :     if (response.status() == DispatchResponse::kSuccess) {
     639          20 :         result->setValue("profile", ValueConversions<protocol::HeapProfiler::SamplingHeapProfile>::toValue(out_profile.get()));
     640             :     }
     641           5 :     if (weak->get())
     642          10 :         weak->get()->sendResponse(callId, response, std::move(result));
     643             :     return;
     644             : }
     645             : 
     646           0 : void DispatcherImpl::stopTrackingHeapObjects(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     647             : {
     648             :     // Prepare input parameters.
     649           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     650           0 :     errors->push();
     651           0 :     protocol::Value* reportProgressValue = object ? object->get("reportProgress") : nullptr;
     652             :     Maybe<bool> in_reportProgress;
     653           0 :     if (reportProgressValue) {
     654           0 :         errors->setName("reportProgress");
     655           0 :         in_reportProgress = ValueConversions<bool>::fromValue(reportProgressValue, errors);
     656             :     }
     657           0 :     errors->pop();
     658           0 :     if (errors->hasErrors()) {
     659           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     660           0 :         return;
     661             :     }
     662             : 
     663           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     664           0 :     DispatchResponse response = m_backend->stopTrackingHeapObjects(std::move(in_reportProgress));
     665           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     666           0 :         channel()->fallThrough(callId, method, message);
     667           0 :         return;
     668             :     }
     669           0 :     if (weak->get())
     670           0 :         weak->get()->sendResponse(callId, response);
     671             :     return;
     672             : }
     673             : 
     674          25 : void DispatcherImpl::takeHeapSnapshot(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     675             : {
     676             :     // Prepare input parameters.
     677          75 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     678          25 :     errors->push();
     679          50 :     protocol::Value* reportProgressValue = object ? object->get("reportProgress") : nullptr;
     680             :     Maybe<bool> in_reportProgress;
     681          25 :     if (reportProgressValue) {
     682          15 :         errors->setName("reportProgress");
     683          15 :         in_reportProgress = ValueConversions<bool>::fromValue(reportProgressValue, errors);
     684             :     }
     685          25 :     errors->pop();
     686          25 :     if (errors->hasErrors()) {
     687           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     688           0 :         return;
     689             :     }
     690             : 
     691          25 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     692          50 :     DispatchResponse response = m_backend->takeHeapSnapshot(std::move(in_reportProgress));
     693          25 :     if (response.status() == DispatchResponse::kFallThrough) {
     694           0 :         channel()->fallThrough(callId, method, message);
     695           0 :         return;
     696             :     }
     697          25 :     if (weak->get())
     698          25 :         weak->get()->sendResponse(callId, response);
     699             :     return;
     700             : }
     701             : 
     702             : // static
     703        3832 : void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
     704             : {
     705        3832 :     std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend));
     706        3832 :     uber->setupRedirects(dispatcher->redirects());
     707       11496 :     uber->registerBackend("HeapProfiler", std::move(dispatcher));
     708        3832 : }
     709             : 
     710             : } // HeapProfiler
     711             : } // namespace v8_inspector
     712             : } // namespace protocol

Generated by: LCOV version 1.10