LCOV - code coverage report
Current view: top level - out/Release/gen/src/inspector/protocol - Profiler.cpp (source / functions) Hit Total Coverage
Test: app.info Lines: 210 481 43.7 %
Date: 2019-01-20 Functions: 30 55 54.5 %

          Line data    Source code
       1             : // This file is generated
       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/Profiler.h"
       8             : 
       9             : #include "src/inspector/protocol/Protocol.h"
      10             : 
      11             : namespace v8_inspector {
      12             : namespace protocol {
      13             : namespace Profiler {
      14             : 
      15             : // ------------- Enum values from types.
      16             : 
      17             : const char Metainfo::domainName[] = "Profiler";
      18             : const char Metainfo::commandPrefix[] = "Profiler.";
      19             : const char Metainfo::version[] = "1.3";
      20             : 
      21           0 : std::unique_ptr<ProfileNode> ProfileNode::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<ProfileNode> result(new ProfileNode());
      29             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
      30           0 :     errors->push();
      31           0 :     protocol::Value* idValue = object->get("id");
      32           0 :     errors->setName("id");
      33           0 :     result->m_id = ValueConversions<int>::fromValue(idValue, errors);
      34           0 :     protocol::Value* callFrameValue = object->get("callFrame");
      35           0 :     errors->setName("callFrame");
      36           0 :     result->m_callFrame = ValueConversions<protocol::Runtime::CallFrame>::fromValue(callFrameValue, errors);
      37           0 :     protocol::Value* hitCountValue = object->get("hitCount");
      38           0 :     if (hitCountValue) {
      39           0 :         errors->setName("hitCount");
      40           0 :         result->m_hitCount = ValueConversions<int>::fromValue(hitCountValue, errors);
      41             :     }
      42           0 :     protocol::Value* childrenValue = object->get("children");
      43           0 :     if (childrenValue) {
      44           0 :         errors->setName("children");
      45           0 :         result->m_children = ValueConversions<protocol::Array<int>>::fromValue(childrenValue, errors);
      46             :     }
      47           0 :     protocol::Value* deoptReasonValue = object->get("deoptReason");
      48           0 :     if (deoptReasonValue) {
      49           0 :         errors->setName("deoptReason");
      50           0 :         result->m_deoptReason = ValueConversions<String>::fromValue(deoptReasonValue, errors);
      51             :     }
      52           0 :     protocol::Value* positionTicksValue = object->get("positionTicks");
      53           0 :     if (positionTicksValue) {
      54           0 :         errors->setName("positionTicks");
      55           0 :         result->m_positionTicks = ValueConversions<protocol::Array<protocol::Profiler::PositionTickInfo>>::fromValue(positionTicksValue, errors);
      56             :     }
      57           0 :     errors->pop();
      58           0 :     if (errors->hasErrors())
      59             :         return nullptr;
      60             :     return result;
      61             : }
      62             : 
      63         107 : std::unique_ptr<protocol::DictionaryValue> ProfileNode::toValue() const
      64             : {
      65         107 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
      66         535 :     result->setValue("id", ValueConversions<int>::toValue(m_id));
      67         428 :     result->setValue("callFrame", ValueConversions<protocol::Runtime::CallFrame>::toValue(m_callFrame.get()));
      68         107 :     if (m_hitCount.isJust())
      69         428 :         result->setValue("hitCount", ValueConversions<int>::toValue(m_hitCount.fromJust()));
      70         107 :     if (m_children.isJust())
      71         220 :         result->setValue("children", ValueConversions<protocol::Array<int>>::toValue(m_children.fromJust()));
      72         107 :     if (m_deoptReason.isJust())
      73           0 :         result->setValue("deoptReason", ValueConversions<String>::toValue(m_deoptReason.fromJust()));
      74         107 :     if (m_positionTicks.isJust())
      75           8 :         result->setValue("positionTicks", ValueConversions<protocol::Array<protocol::Profiler::PositionTickInfo>>::toValue(m_positionTicks.fromJust()));
      76         107 :     return result;
      77             : }
      78             : 
      79           0 : std::unique_ptr<ProfileNode> ProfileNode::clone() const
      80             : {
      81           0 :     ErrorSupport errors;
      82           0 :     return fromValue(toValue().get(), &errors);
      83             : }
      84             : 
      85           0 : std::unique_ptr<Profile> Profile::fromValue(protocol::Value* value, ErrorSupport* errors)
      86             : {
      87           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
      88           0 :         errors->addError("object expected");
      89             :         return nullptr;
      90             :     }
      91             : 
      92           0 :     std::unique_ptr<Profile> result(new Profile());
      93             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
      94           0 :     errors->push();
      95           0 :     protocol::Value* nodesValue = object->get("nodes");
      96           0 :     errors->setName("nodes");
      97           0 :     result->m_nodes = ValueConversions<protocol::Array<protocol::Profiler::ProfileNode>>::fromValue(nodesValue, errors);
      98           0 :     protocol::Value* startTimeValue = object->get("startTime");
      99           0 :     errors->setName("startTime");
     100           0 :     result->m_startTime = ValueConversions<double>::fromValue(startTimeValue, errors);
     101           0 :     protocol::Value* endTimeValue = object->get("endTime");
     102           0 :     errors->setName("endTime");
     103           0 :     result->m_endTime = ValueConversions<double>::fromValue(endTimeValue, errors);
     104           0 :     protocol::Value* samplesValue = object->get("samples");
     105           0 :     if (samplesValue) {
     106           0 :         errors->setName("samples");
     107           0 :         result->m_samples = ValueConversions<protocol::Array<int>>::fromValue(samplesValue, errors);
     108             :     }
     109           0 :     protocol::Value* timeDeltasValue = object->get("timeDeltas");
     110           0 :     if (timeDeltasValue) {
     111           0 :         errors->setName("timeDeltas");
     112           0 :         result->m_timeDeltas = ValueConversions<protocol::Array<int>>::fromValue(timeDeltasValue, errors);
     113             :     }
     114           0 :     errors->pop();
     115           0 :     if (errors->hasErrors())
     116             :         return nullptr;
     117             :     return result;
     118             : }
     119             : 
     120          45 : std::unique_ptr<protocol::DictionaryValue> Profile::toValue() const
     121             : {
     122          45 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     123         180 :     result->setValue("nodes", ValueConversions<protocol::Array<protocol::Profiler::ProfileNode>>::toValue(m_nodes.get()));
     124         225 :     result->setValue("startTime", ValueConversions<double>::toValue(m_startTime));
     125         225 :     result->setValue("endTime", ValueConversions<double>::toValue(m_endTime));
     126          45 :     if (m_samples.isJust())
     127         180 :         result->setValue("samples", ValueConversions<protocol::Array<int>>::toValue(m_samples.fromJust()));
     128          45 :     if (m_timeDeltas.isJust())
     129         180 :         result->setValue("timeDeltas", ValueConversions<protocol::Array<int>>::toValue(m_timeDeltas.fromJust()));
     130          45 :     return result;
     131             : }
     132             : 
     133           0 : std::unique_ptr<Profile> Profile::clone() const
     134             : {
     135           0 :     ErrorSupport errors;
     136           0 :     return fromValue(toValue().get(), &errors);
     137             : }
     138             : 
     139           0 : std::unique_ptr<PositionTickInfo> PositionTickInfo::fromValue(protocol::Value* value, ErrorSupport* errors)
     140             : {
     141           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     142           0 :         errors->addError("object expected");
     143             :         return nullptr;
     144             :     }
     145             : 
     146           0 :     std::unique_ptr<PositionTickInfo> result(new PositionTickInfo());
     147             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     148           0 :     errors->push();
     149           0 :     protocol::Value* lineValue = object->get("line");
     150           0 :     errors->setName("line");
     151           0 :     result->m_line = ValueConversions<int>::fromValue(lineValue, errors);
     152           0 :     protocol::Value* ticksValue = object->get("ticks");
     153           0 :     errors->setName("ticks");
     154           0 :     result->m_ticks = ValueConversions<int>::fromValue(ticksValue, errors);
     155           0 :     errors->pop();
     156           0 :     if (errors->hasErrors())
     157             :         return nullptr;
     158             :     return result;
     159             : }
     160             : 
     161           2 : std::unique_ptr<protocol::DictionaryValue> PositionTickInfo::toValue() const
     162             : {
     163           2 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     164          10 :     result->setValue("line", ValueConversions<int>::toValue(m_line));
     165          10 :     result->setValue("ticks", ValueConversions<int>::toValue(m_ticks));
     166           2 :     return result;
     167             : }
     168             : 
     169           0 : std::unique_ptr<PositionTickInfo> PositionTickInfo::clone() const
     170             : {
     171           0 :     ErrorSupport errors;
     172           0 :     return fromValue(toValue().get(), &errors);
     173             : }
     174             : 
     175           0 : std::unique_ptr<CoverageRange> CoverageRange::fromValue(protocol::Value* value, ErrorSupport* errors)
     176             : {
     177           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     178           0 :         errors->addError("object expected");
     179             :         return nullptr;
     180             :     }
     181             : 
     182           0 :     std::unique_ptr<CoverageRange> result(new CoverageRange());
     183             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     184           0 :     errors->push();
     185           0 :     protocol::Value* startOffsetValue = object->get("startOffset");
     186           0 :     errors->setName("startOffset");
     187           0 :     result->m_startOffset = ValueConversions<int>::fromValue(startOffsetValue, errors);
     188           0 :     protocol::Value* endOffsetValue = object->get("endOffset");
     189           0 :     errors->setName("endOffset");
     190           0 :     result->m_endOffset = ValueConversions<int>::fromValue(endOffsetValue, errors);
     191           0 :     protocol::Value* countValue = object->get("count");
     192           0 :     errors->setName("count");
     193           0 :     result->m_count = ValueConversions<int>::fromValue(countValue, errors);
     194           0 :     errors->pop();
     195           0 :     if (errors->hasErrors())
     196             :         return nullptr;
     197             :     return result;
     198             : }
     199             : 
     200         515 : std::unique_ptr<protocol::DictionaryValue> CoverageRange::toValue() const
     201             : {
     202         515 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     203        2575 :     result->setValue("startOffset", ValueConversions<int>::toValue(m_startOffset));
     204        2575 :     result->setValue("endOffset", ValueConversions<int>::toValue(m_endOffset));
     205        2575 :     result->setValue("count", ValueConversions<int>::toValue(m_count));
     206         515 :     return result;
     207             : }
     208             : 
     209           0 : std::unique_ptr<CoverageRange> CoverageRange::clone() const
     210             : {
     211           0 :     ErrorSupport errors;
     212           0 :     return fromValue(toValue().get(), &errors);
     213             : }
     214             : 
     215           0 : std::unique_ptr<FunctionCoverage> FunctionCoverage::fromValue(protocol::Value* value, ErrorSupport* errors)
     216             : {
     217           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     218           0 :         errors->addError("object expected");
     219             :         return nullptr;
     220             :     }
     221             : 
     222           0 :     std::unique_ptr<FunctionCoverage> result(new FunctionCoverage());
     223             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     224           0 :     errors->push();
     225           0 :     protocol::Value* functionNameValue = object->get("functionName");
     226           0 :     errors->setName("functionName");
     227           0 :     result->m_functionName = ValueConversions<String>::fromValue(functionNameValue, errors);
     228           0 :     protocol::Value* rangesValue = object->get("ranges");
     229           0 :     errors->setName("ranges");
     230           0 :     result->m_ranges = ValueConversions<protocol::Array<protocol::Profiler::CoverageRange>>::fromValue(rangesValue, errors);
     231           0 :     protocol::Value* isBlockCoverageValue = object->get("isBlockCoverage");
     232           0 :     errors->setName("isBlockCoverage");
     233           0 :     result->m_isBlockCoverage = ValueConversions<bool>::fromValue(isBlockCoverageValue, errors);
     234           0 :     errors->pop();
     235           0 :     if (errors->hasErrors())
     236             :         return nullptr;
     237             :     return result;
     238             : }
     239             : 
     240         475 : std::unique_ptr<protocol::DictionaryValue> FunctionCoverage::toValue() const
     241             : {
     242         475 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     243        2375 :     result->setValue("functionName", ValueConversions<String>::toValue(m_functionName));
     244        1900 :     result->setValue("ranges", ValueConversions<protocol::Array<protocol::Profiler::CoverageRange>>::toValue(m_ranges.get()));
     245        2375 :     result->setValue("isBlockCoverage", ValueConversions<bool>::toValue(m_isBlockCoverage));
     246         475 :     return result;
     247             : }
     248             : 
     249           0 : std::unique_ptr<FunctionCoverage> FunctionCoverage::clone() const
     250             : {
     251           0 :     ErrorSupport errors;
     252           0 :     return fromValue(toValue().get(), &errors);
     253             : }
     254             : 
     255           0 : std::unique_ptr<ScriptCoverage> ScriptCoverage::fromValue(protocol::Value* value, ErrorSupport* errors)
     256             : {
     257           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     258           0 :         errors->addError("object expected");
     259             :         return nullptr;
     260             :     }
     261             : 
     262           0 :     std::unique_ptr<ScriptCoverage> result(new ScriptCoverage());
     263             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     264           0 :     errors->push();
     265           0 :     protocol::Value* scriptIdValue = object->get("scriptId");
     266           0 :     errors->setName("scriptId");
     267           0 :     result->m_scriptId = ValueConversions<String>::fromValue(scriptIdValue, errors);
     268           0 :     protocol::Value* urlValue = object->get("url");
     269           0 :     errors->setName("url");
     270           0 :     result->m_url = ValueConversions<String>::fromValue(urlValue, errors);
     271           0 :     protocol::Value* functionsValue = object->get("functions");
     272           0 :     errors->setName("functions");
     273           0 :     result->m_functions = ValueConversions<protocol::Array<protocol::Profiler::FunctionCoverage>>::fromValue(functionsValue, errors);
     274           0 :     errors->pop();
     275           0 :     if (errors->hasErrors())
     276             :         return nullptr;
     277             :     return result;
     278             : }
     279             : 
     280         200 : std::unique_ptr<protocol::DictionaryValue> ScriptCoverage::toValue() const
     281             : {
     282         200 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     283        1000 :     result->setValue("scriptId", ValueConversions<String>::toValue(m_scriptId));
     284        1000 :     result->setValue("url", ValueConversions<String>::toValue(m_url));
     285         800 :     result->setValue("functions", ValueConversions<protocol::Array<protocol::Profiler::FunctionCoverage>>::toValue(m_functions.get()));
     286         200 :     return result;
     287             : }
     288             : 
     289           0 : std::unique_ptr<ScriptCoverage> ScriptCoverage::clone() const
     290             : {
     291           0 :     ErrorSupport errors;
     292           0 :     return fromValue(toValue().get(), &errors);
     293             : }
     294             : 
     295           0 : std::unique_ptr<TypeObject> TypeObject::fromValue(protocol::Value* value, ErrorSupport* errors)
     296             : {
     297           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     298           0 :         errors->addError("object expected");
     299             :         return nullptr;
     300             :     }
     301             : 
     302           0 :     std::unique_ptr<TypeObject> result(new TypeObject());
     303             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     304           0 :     errors->push();
     305           0 :     protocol::Value* nameValue = object->get("name");
     306           0 :     errors->setName("name");
     307           0 :     result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
     308           0 :     errors->pop();
     309           0 :     if (errors->hasErrors())
     310             :         return nullptr;
     311             :     return result;
     312             : }
     313             : 
     314         245 : std::unique_ptr<protocol::DictionaryValue> TypeObject::toValue() const
     315             : {
     316         245 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     317        1225 :     result->setValue("name", ValueConversions<String>::toValue(m_name));
     318         245 :     return result;
     319             : }
     320             : 
     321           0 : std::unique_ptr<TypeObject> TypeObject::clone() const
     322             : {
     323           0 :     ErrorSupport errors;
     324           0 :     return fromValue(toValue().get(), &errors);
     325             : }
     326             : 
     327           0 : std::unique_ptr<TypeProfileEntry> TypeProfileEntry::fromValue(protocol::Value* value, ErrorSupport* errors)
     328             : {
     329           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     330           0 :         errors->addError("object expected");
     331             :         return nullptr;
     332             :     }
     333             : 
     334           0 :     std::unique_ptr<TypeProfileEntry> result(new TypeProfileEntry());
     335             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     336           0 :     errors->push();
     337           0 :     protocol::Value* offsetValue = object->get("offset");
     338           0 :     errors->setName("offset");
     339           0 :     result->m_offset = ValueConversions<int>::fromValue(offsetValue, errors);
     340           0 :     protocol::Value* typesValue = object->get("types");
     341           0 :     errors->setName("types");
     342           0 :     result->m_types = ValueConversions<protocol::Array<protocol::Profiler::TypeObject>>::fromValue(typesValue, errors);
     343           0 :     errors->pop();
     344           0 :     if (errors->hasErrors())
     345             :         return nullptr;
     346             :     return result;
     347             : }
     348             : 
     349         185 : std::unique_ptr<protocol::DictionaryValue> TypeProfileEntry::toValue() const
     350             : {
     351         185 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     352         925 :     result->setValue("offset", ValueConversions<int>::toValue(m_offset));
     353         740 :     result->setValue("types", ValueConversions<protocol::Array<protocol::Profiler::TypeObject>>::toValue(m_types.get()));
     354         185 :     return result;
     355             : }
     356             : 
     357           0 : std::unique_ptr<TypeProfileEntry> TypeProfileEntry::clone() const
     358             : {
     359           0 :     ErrorSupport errors;
     360           0 :     return fromValue(toValue().get(), &errors);
     361             : }
     362             : 
     363           0 : std::unique_ptr<ScriptTypeProfile> ScriptTypeProfile::fromValue(protocol::Value* value, ErrorSupport* errors)
     364             : {
     365           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     366           0 :         errors->addError("object expected");
     367             :         return nullptr;
     368             :     }
     369             : 
     370           0 :     std::unique_ptr<ScriptTypeProfile> result(new ScriptTypeProfile());
     371             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     372           0 :     errors->push();
     373           0 :     protocol::Value* scriptIdValue = object->get("scriptId");
     374           0 :     errors->setName("scriptId");
     375           0 :     result->m_scriptId = ValueConversions<String>::fromValue(scriptIdValue, errors);
     376           0 :     protocol::Value* urlValue = object->get("url");
     377           0 :     errors->setName("url");
     378           0 :     result->m_url = ValueConversions<String>::fromValue(urlValue, errors);
     379           0 :     protocol::Value* entriesValue = object->get("entries");
     380           0 :     errors->setName("entries");
     381           0 :     result->m_entries = ValueConversions<protocol::Array<protocol::Profiler::TypeProfileEntry>>::fromValue(entriesValue, errors);
     382           0 :     errors->pop();
     383           0 :     if (errors->hasErrors())
     384             :         return nullptr;
     385             :     return result;
     386             : }
     387             : 
     388          40 : std::unique_ptr<protocol::DictionaryValue> ScriptTypeProfile::toValue() const
     389             : {
     390          40 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     391         200 :     result->setValue("scriptId", ValueConversions<String>::toValue(m_scriptId));
     392         200 :     result->setValue("url", ValueConversions<String>::toValue(m_url));
     393         160 :     result->setValue("entries", ValueConversions<protocol::Array<protocol::Profiler::TypeProfileEntry>>::toValue(m_entries.get()));
     394          40 :     return result;
     395             : }
     396             : 
     397           0 : std::unique_ptr<ScriptTypeProfile> ScriptTypeProfile::clone() const
     398             : {
     399           0 :     ErrorSupport errors;
     400           0 :     return fromValue(toValue().get(), &errors);
     401             : }
     402             : 
     403           0 : std::unique_ptr<ConsoleProfileFinishedNotification> ConsoleProfileFinishedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     404             : {
     405           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     406           0 :         errors->addError("object expected");
     407             :         return nullptr;
     408             :     }
     409             : 
     410           0 :     std::unique_ptr<ConsoleProfileFinishedNotification> result(new ConsoleProfileFinishedNotification());
     411             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     412           0 :     errors->push();
     413           0 :     protocol::Value* idValue = object->get("id");
     414           0 :     errors->setName("id");
     415           0 :     result->m_id = ValueConversions<String>::fromValue(idValue, errors);
     416           0 :     protocol::Value* locationValue = object->get("location");
     417           0 :     errors->setName("location");
     418           0 :     result->m_location = ValueConversions<protocol::Debugger::Location>::fromValue(locationValue, errors);
     419           0 :     protocol::Value* profileValue = object->get("profile");
     420           0 :     errors->setName("profile");
     421           0 :     result->m_profile = ValueConversions<protocol::Profiler::Profile>::fromValue(profileValue, errors);
     422           0 :     protocol::Value* titleValue = object->get("title");
     423           0 :     if (titleValue) {
     424           0 :         errors->setName("title");
     425           0 :         result->m_title = ValueConversions<String>::fromValue(titleValue, errors);
     426             :     }
     427           0 :     errors->pop();
     428           0 :     if (errors->hasErrors())
     429             :         return nullptr;
     430             :     return result;
     431             : }
     432             : 
     433          35 : std::unique_ptr<protocol::DictionaryValue> ConsoleProfileFinishedNotification::toValue() const
     434             : {
     435          35 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     436         175 :     result->setValue("id", ValueConversions<String>::toValue(m_id));
     437         140 :     result->setValue("location", ValueConversions<protocol::Debugger::Location>::toValue(m_location.get()));
     438         140 :     result->setValue("profile", ValueConversions<protocol::Profiler::Profile>::toValue(m_profile.get()));
     439          35 :     if (m_title.isJust())
     440         175 :         result->setValue("title", ValueConversions<String>::toValue(m_title.fromJust()));
     441          35 :     return result;
     442             : }
     443             : 
     444           0 : std::unique_ptr<ConsoleProfileFinishedNotification> ConsoleProfileFinishedNotification::clone() const
     445             : {
     446           0 :     ErrorSupport errors;
     447           0 :     return fromValue(toValue().get(), &errors);
     448             : }
     449             : 
     450           0 : std::unique_ptr<ConsoleProfileStartedNotification> ConsoleProfileStartedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     451             : {
     452           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     453           0 :         errors->addError("object expected");
     454             :         return nullptr;
     455             :     }
     456             : 
     457           0 :     std::unique_ptr<ConsoleProfileStartedNotification> result(new ConsoleProfileStartedNotification());
     458             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     459           0 :     errors->push();
     460           0 :     protocol::Value* idValue = object->get("id");
     461           0 :     errors->setName("id");
     462           0 :     result->m_id = ValueConversions<String>::fromValue(idValue, errors);
     463           0 :     protocol::Value* locationValue = object->get("location");
     464           0 :     errors->setName("location");
     465           0 :     result->m_location = ValueConversions<protocol::Debugger::Location>::fromValue(locationValue, errors);
     466           0 :     protocol::Value* titleValue = object->get("title");
     467           0 :     if (titleValue) {
     468           0 :         errors->setName("title");
     469           0 :         result->m_title = ValueConversions<String>::fromValue(titleValue, errors);
     470             :     }
     471           0 :     errors->pop();
     472           0 :     if (errors->hasErrors())
     473             :         return nullptr;
     474             :     return result;
     475             : }
     476             : 
     477          40 : std::unique_ptr<protocol::DictionaryValue> ConsoleProfileStartedNotification::toValue() const
     478             : {
     479          40 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     480         200 :     result->setValue("id", ValueConversions<String>::toValue(m_id));
     481         160 :     result->setValue("location", ValueConversions<protocol::Debugger::Location>::toValue(m_location.get()));
     482          40 :     if (m_title.isJust())
     483         200 :         result->setValue("title", ValueConversions<String>::toValue(m_title.fromJust()));
     484          40 :     return result;
     485             : }
     486             : 
     487           0 : std::unique_ptr<ConsoleProfileStartedNotification> ConsoleProfileStartedNotification::clone() const
     488             : {
     489           0 :     ErrorSupport errors;
     490           0 :     return fromValue(toValue().get(), &errors);
     491             : }
     492             : 
     493             : // ------------- Enum values from params.
     494             : 
     495             : 
     496             : // ------------- Frontend notifications.
     497             : 
     498          35 : void Frontend::consoleProfileFinished(const String& id, std::unique_ptr<protocol::Debugger::Location> location, std::unique_ptr<protocol::Profiler::Profile> profile, Maybe<String> title)
     499             : {
     500          35 :     if (!m_frontendChannel)
     501          35 :         return;
     502             :     std::unique_ptr<ConsoleProfileFinishedNotification> messageData = ConsoleProfileFinishedNotification::create()
     503          35 :         .setId(id)
     504             :         .setLocation(std::move(location))
     505             :         .setProfile(std::move(profile))
     506             :         .build();
     507          35 :     if (title.isJust())
     508          70 :         messageData->setTitle(std::move(title).takeJust());
     509         245 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Profiler.consoleProfileFinished", std::move(messageData)));
     510             : }
     511             : 
     512          40 : void Frontend::consoleProfileStarted(const String& id, std::unique_ptr<protocol::Debugger::Location> location, Maybe<String> title)
     513             : {
     514          40 :     if (!m_frontendChannel)
     515          40 :         return;
     516             :     std::unique_ptr<ConsoleProfileStartedNotification> messageData = ConsoleProfileStartedNotification::create()
     517          40 :         .setId(id)
     518             :         .setLocation(std::move(location))
     519             :         .build();
     520          40 :     if (title.isJust())
     521          80 :         messageData->setTitle(std::move(title).takeJust());
     522         280 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Profiler.consoleProfileStarted", std::move(messageData)));
     523             : }
     524             : 
     525           0 : void Frontend::flush()
     526             : {
     527           0 :     m_frontendChannel->flushProtocolNotifications();
     528           0 : }
     529             : 
     530           0 : void Frontend::sendRawNotification(const String& notification)
     531             : {
     532           0 :     m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
     533           0 : }
     534             : 
     535             : // --------------------- Dispatcher.
     536             : 
     537             : class DispatcherImpl : public protocol::DispatcherBase {
     538             : public:
     539        3834 :     DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend)
     540             :         : DispatcherBase(frontendChannel)
     541       11502 :         , m_backend(backend) {
     542       11502 :         m_dispatchMap["Profiler.disable"] = &DispatcherImpl::disable;
     543       11502 :         m_dispatchMap["Profiler.enable"] = &DispatcherImpl::enable;
     544       11502 :         m_dispatchMap["Profiler.getBestEffortCoverage"] = &DispatcherImpl::getBestEffortCoverage;
     545       11502 :         m_dispatchMap["Profiler.setSamplingInterval"] = &DispatcherImpl::setSamplingInterval;
     546       11502 :         m_dispatchMap["Profiler.start"] = &DispatcherImpl::start;
     547       11502 :         m_dispatchMap["Profiler.startPreciseCoverage"] = &DispatcherImpl::startPreciseCoverage;
     548       11502 :         m_dispatchMap["Profiler.startTypeProfile"] = &DispatcherImpl::startTypeProfile;
     549       11502 :         m_dispatchMap["Profiler.stop"] = &DispatcherImpl::stop;
     550       11502 :         m_dispatchMap["Profiler.stopPreciseCoverage"] = &DispatcherImpl::stopPreciseCoverage;
     551       11502 :         m_dispatchMap["Profiler.stopTypeProfile"] = &DispatcherImpl::stopTypeProfile;
     552       11502 :         m_dispatchMap["Profiler.takePreciseCoverage"] = &DispatcherImpl::takePreciseCoverage;
     553       11502 :         m_dispatchMap["Profiler.takeTypeProfile"] = &DispatcherImpl::takeTypeProfile;
     554        3834 :     }
     555       11502 :     ~DispatcherImpl() override { }
     556             :     bool canDispatch(const String& method) override;
     557             :     void dispatch(int callId, const String& method, const String& message, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
     558             :     std::unordered_map<String, String>& redirects() { return m_redirects; }
     559             : 
     560             : protected:
     561             :     using CallHandler = void (DispatcherImpl::*)(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
     562             :     using DispatchMap = std::unordered_map<String, CallHandler>;
     563             :     DispatchMap m_dispatchMap;
     564             :     std::unordered_map<String, String> m_redirects;
     565             : 
     566             :     void disable(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     567             :     void enable(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     568             :     void getBestEffortCoverage(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     569             :     void setSamplingInterval(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     570             :     void start(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     571             :     void startPreciseCoverage(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     572             :     void startTypeProfile(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     573             :     void stop(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     574             :     void stopPreciseCoverage(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     575             :     void stopTypeProfile(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     576             :     void takePreciseCoverage(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     577             :     void takeTypeProfile(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     578             : 
     579             :     Backend* m_backend;
     580             : };
     581             : 
     582         930 : bool DispatcherImpl::canDispatch(const String& method) {
     583         930 :     return m_dispatchMap.find(method) != m_dispatchMap.end();
     584             : }
     585             : 
     586         925 : void DispatcherImpl::dispatch(int callId, const String& method, const String& message, std::unique_ptr<protocol::DictionaryValue> messageObject)
     587             : {
     588             :     std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
     589             :     DCHECK(it != m_dispatchMap.end());
     590         925 :     protocol::ErrorSupport errors;
     591        2775 :     (this->*(it->second))(callId, method, message, std::move(messageObject), &errors);
     592         925 : }
     593             : 
     594             : 
     595         165 : void DispatcherImpl::disable(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     596             : {
     597             : 
     598         165 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     599         165 :     DispatchResponse response = m_backend->disable();
     600         165 :     if (response.status() == DispatchResponse::kFallThrough) {
     601           0 :         channel()->fallThrough(callId, method, message);
     602           0 :         return;
     603             :     }
     604         165 :     if (weak->get())
     605         165 :         weak->get()->sendResponse(callId, response);
     606             :     return;
     607             : }
     608             : 
     609         185 : void DispatcherImpl::enable(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     610             : {
     611             : 
     612         185 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     613         185 :     DispatchResponse response = m_backend->enable();
     614         185 :     if (response.status() == DispatchResponse::kFallThrough) {
     615           0 :         channel()->fallThrough(callId, method, message);
     616           0 :         return;
     617             :     }
     618         185 :     if (weak->get())
     619         185 :         weak->get()->sendResponse(callId, response);
     620             :     return;
     621             : }
     622             : 
     623          60 : void DispatcherImpl::getBestEffortCoverage(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     624             : {
     625             :     // Declare output parameters.
     626          60 :     std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>> out_result;
     627             : 
     628          60 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     629          60 :     DispatchResponse response = m_backend->getBestEffortCoverage(&out_result);
     630          60 :     if (response.status() == DispatchResponse::kFallThrough) {
     631           0 :         channel()->fallThrough(callId, method, message);
     632           0 :         return;
     633             :     }
     634          60 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     635          60 :     if (response.status() == DispatchResponse::kSuccess) {
     636         240 :         result->setValue("result", ValueConversions<protocol::Array<protocol::Profiler::ScriptCoverage>>::toValue(out_result.get()));
     637             :     }
     638          60 :     if (weak->get())
     639         120 :         weak->get()->sendResponse(callId, response, std::move(result));
     640             :     return;
     641             : }
     642             : 
     643           0 : void DispatcherImpl::setSamplingInterval(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     644             : {
     645             :     // Prepare input parameters.
     646           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     647           0 :     errors->push();
     648           0 :     protocol::Value* intervalValue = object ? object->get("interval") : nullptr;
     649           0 :     errors->setName("interval");
     650           0 :     int in_interval = ValueConversions<int>::fromValue(intervalValue, errors);
     651           0 :     errors->pop();
     652           0 :     if (errors->hasErrors()) {
     653           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     654           0 :         return;
     655             :     }
     656             : 
     657           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     658           0 :     DispatchResponse response = m_backend->setSamplingInterval(in_interval);
     659           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     660           0 :         channel()->fallThrough(callId, method, message);
     661           0 :         return;
     662             :     }
     663           0 :     if (weak->get())
     664           0 :         weak->get()->sendResponse(callId, response);
     665             :     return;
     666             : }
     667             : 
     668          20 : void DispatcherImpl::start(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     669             : {
     670             : 
     671          20 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     672          20 :     DispatchResponse response = m_backend->start();
     673          20 :     if (response.status() == DispatchResponse::kFallThrough) {
     674           0 :         channel()->fallThrough(callId, method, message);
     675           0 :         return;
     676             :     }
     677          20 :     if (weak->get())
     678          20 :         weak->get()->sendResponse(callId, response);
     679             :     return;
     680             : }
     681             : 
     682          85 : void DispatcherImpl::startPreciseCoverage(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     683             : {
     684             :     // Prepare input parameters.
     685         255 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     686          85 :     errors->push();
     687         170 :     protocol::Value* callCountValue = object ? object->get("callCount") : nullptr;
     688             :     Maybe<bool> in_callCount;
     689          85 :     if (callCountValue) {
     690          55 :         errors->setName("callCount");
     691          55 :         in_callCount = ValueConversions<bool>::fromValue(callCountValue, errors);
     692             :     }
     693         170 :     protocol::Value* detailedValue = object ? object->get("detailed") : nullptr;
     694             :     Maybe<bool> in_detailed;
     695          85 :     if (detailedValue) {
     696          85 :         errors->setName("detailed");
     697          85 :         in_detailed = ValueConversions<bool>::fromValue(detailedValue, errors);
     698             :     }
     699          85 :     errors->pop();
     700          85 :     if (errors->hasErrors()) {
     701           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     702           0 :         return;
     703             :     }
     704             : 
     705          85 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     706         170 :     DispatchResponse response = m_backend->startPreciseCoverage(std::move(in_callCount), std::move(in_detailed));
     707          85 :     if (response.status() == DispatchResponse::kFallThrough) {
     708           0 :         channel()->fallThrough(callId, method, message);
     709           0 :         return;
     710             :     }
     711          85 :     if (weak->get())
     712          85 :         weak->get()->sendResponse(callId, response);
     713             :     return;
     714             : }
     715             : 
     716          65 : void DispatcherImpl::startTypeProfile(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     717             : {
     718             : 
     719          65 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     720          65 :     DispatchResponse response = m_backend->startTypeProfile();
     721          65 :     if (response.status() == DispatchResponse::kFallThrough) {
     722           0 :         channel()->fallThrough(callId, method, message);
     723           0 :         return;
     724             :     }
     725          65 :     if (weak->get())
     726          65 :         weak->get()->sendResponse(callId, response);
     727             :     return;
     728             : }
     729             : 
     730          20 : void DispatcherImpl::stop(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     731             : {
     732             :     // Declare output parameters.
     733          20 :     std::unique_ptr<protocol::Profiler::Profile> out_profile;
     734             : 
     735          20 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     736          20 :     DispatchResponse response = m_backend->stop(&out_profile);
     737          20 :     if (response.status() == DispatchResponse::kFallThrough) {
     738           0 :         channel()->fallThrough(callId, method, message);
     739           0 :         return;
     740             :     }
     741          20 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     742          20 :     if (response.status() == DispatchResponse::kSuccess) {
     743          40 :         result->setValue("profile", ValueConversions<protocol::Profiler::Profile>::toValue(out_profile.get()));
     744             :     }
     745          20 :     if (weak->get())
     746          40 :         weak->get()->sendResponse(callId, response, std::move(result));
     747             :     return;
     748             : }
     749             : 
     750          85 : void DispatcherImpl::stopPreciseCoverage(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     751             : {
     752             : 
     753          85 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     754          85 :     DispatchResponse response = m_backend->stopPreciseCoverage();
     755          85 :     if (response.status() == DispatchResponse::kFallThrough) {
     756           0 :         channel()->fallThrough(callId, method, message);
     757           0 :         return;
     758             :     }
     759          85 :     if (weak->get())
     760          85 :         weak->get()->sendResponse(callId, response);
     761             :     return;
     762             : }
     763             : 
     764          60 : void DispatcherImpl::stopTypeProfile(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     765             : {
     766             : 
     767          60 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     768          60 :     DispatchResponse response = m_backend->stopTypeProfile();
     769          60 :     if (response.status() == DispatchResponse::kFallThrough) {
     770           0 :         channel()->fallThrough(callId, method, message);
     771           0 :         return;
     772             :     }
     773          60 :     if (weak->get())
     774          60 :         weak->get()->sendResponse(callId, response);
     775             :     return;
     776             : }
     777             : 
     778         120 : void DispatcherImpl::takePreciseCoverage(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     779             : {
     780             :     // Declare output parameters.
     781         120 :     std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>> out_result;
     782             : 
     783         120 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     784         120 :     DispatchResponse response = m_backend->takePreciseCoverage(&out_result);
     785         120 :     if (response.status() == DispatchResponse::kFallThrough) {
     786           0 :         channel()->fallThrough(callId, method, message);
     787           0 :         return;
     788             :     }
     789         120 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     790         120 :     if (response.status() == DispatchResponse::kSuccess) {
     791         440 :         result->setValue("result", ValueConversions<protocol::Array<protocol::Profiler::ScriptCoverage>>::toValue(out_result.get()));
     792             :     }
     793         120 :     if (weak->get())
     794         240 :         weak->get()->sendResponse(callId, response, std::move(result));
     795             :     return;
     796             : }
     797             : 
     798          60 : void DispatcherImpl::takeTypeProfile(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     799             : {
     800             :     // Declare output parameters.
     801          60 :     std::unique_ptr<protocol::Array<protocol::Profiler::ScriptTypeProfile>> out_result;
     802             : 
     803          60 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     804          60 :     DispatchResponse response = m_backend->takeTypeProfile(&out_result);
     805          60 :     if (response.status() == DispatchResponse::kFallThrough) {
     806           0 :         channel()->fallThrough(callId, method, message);
     807           0 :         return;
     808             :     }
     809          60 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     810          60 :     if (response.status() == DispatchResponse::kSuccess) {
     811         200 :         result->setValue("result", ValueConversions<protocol::Array<protocol::Profiler::ScriptTypeProfile>>::toValue(out_result.get()));
     812             :     }
     813          60 :     if (weak->get())
     814         120 :         weak->get()->sendResponse(callId, response, std::move(result));
     815             :     return;
     816             : }
     817             : 
     818             : // static
     819        3834 : void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
     820             : {
     821        3834 :     std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend));
     822        3834 :     uber->setupRedirects(dispatcher->redirects());
     823       11502 :     uber->registerBackend("Profiler", std::move(dispatcher));
     824        3834 : }
     825             : 
     826             : } // Profiler
     827             : } // namespace v8_inspector
     828             : } // namespace protocol

Generated by: LCOV version 1.10