LCOV - code coverage report
Current view: top level - out/Release/gen/src/inspector/protocol - Runtime.cpp (source / functions) Hit Total Coverage
Test: app.info Lines: 679 1050 64.7 %
Date: 2017-04-26 Functions: 62 109 56.9 %

          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/Runtime.h"
       8             : 
       9             : #include "src/inspector/protocol/Protocol.h"
      10             : 
      11             : namespace v8_inspector {
      12             : namespace protocol {
      13             : namespace Runtime {
      14             : 
      15             : // ------------- Enum values from types.
      16             : 
      17             : const char Metainfo::domainName[] = "Runtime";
      18             : const char Metainfo::commandPrefix[] = "Runtime.";
      19             : const char Metainfo::version[] = "1.2";
      20             : 
      21             : namespace UnserializableValueEnum {
      22             : const char* Infinity = "Infinity";
      23             : const char* NaN = "NaN";
      24             : const char* NegativeInfinity = "-Infinity";
      25             : const char* Negative0 = "-0";
      26             : } // namespace UnserializableValueEnum
      27             : 
      28             : const char* RemoteObject::TypeEnum::Object = "object";
      29             : const char* RemoteObject::TypeEnum::Function = "function";
      30             : const char* RemoteObject::TypeEnum::Undefined = "undefined";
      31             : const char* RemoteObject::TypeEnum::String = "string";
      32             : const char* RemoteObject::TypeEnum::Number = "number";
      33             : const char* RemoteObject::TypeEnum::Boolean = "boolean";
      34             : const char* RemoteObject::TypeEnum::Symbol = "symbol";
      35             : 
      36             : const char* RemoteObject::SubtypeEnum::Array = "array";
      37             : const char* RemoteObject::SubtypeEnum::Null = "null";
      38             : const char* RemoteObject::SubtypeEnum::Node = "node";
      39             : const char* RemoteObject::SubtypeEnum::Regexp = "regexp";
      40             : const char* RemoteObject::SubtypeEnum::Date = "date";
      41             : const char* RemoteObject::SubtypeEnum::Map = "map";
      42             : const char* RemoteObject::SubtypeEnum::Set = "set";
      43             : const char* RemoteObject::SubtypeEnum::Weakmap = "weakmap";
      44             : const char* RemoteObject::SubtypeEnum::Weakset = "weakset";
      45             : const char* RemoteObject::SubtypeEnum::Iterator = "iterator";
      46             : const char* RemoteObject::SubtypeEnum::Generator = "generator";
      47             : const char* RemoteObject::SubtypeEnum::Error = "error";
      48             : const char* RemoteObject::SubtypeEnum::Proxy = "proxy";
      49             : const char* RemoteObject::SubtypeEnum::Promise = "promise";
      50             : const char* RemoteObject::SubtypeEnum::Typedarray = "typedarray";
      51             : 
      52     8451188 : std::unique_ptr<RemoteObject> RemoteObject::fromValue(protocol::Value* value, ErrorSupport* errors)
      53             : {
      54     8451188 :     if (!value || value->type() != protocol::Value::TypeObject) {
      55           0 :         errors->addError("object expected");
      56             :         return nullptr;
      57             :     }
      58             : 
      59     4225594 :     std::unique_ptr<RemoteObject> result(new RemoteObject());
      60             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
      61     4225594 :     errors->push();
      62     8451188 :     protocol::Value* typeValue = object->get("type");
      63     8451188 :     errors->setName("type");
      64     8451188 :     result->m_type = ValueConversions<String>::fromValue(typeValue, errors);
      65     8451188 :     protocol::Value* subtypeValue = object->get("subtype");
      66     4225594 :     if (subtypeValue) {
      67      178576 :         errors->setName("subtype");
      68      178576 :         result->m_subtype = ValueConversions<String>::fromValue(subtypeValue, errors);
      69             :     }
      70     8451188 :     protocol::Value* classNameValue = object->get("className");
      71     4225594 :     if (classNameValue) {
      72     7503636 :         errors->setName("className");
      73     7503636 :         result->m_className = ValueConversions<String>::fromValue(classNameValue, errors);
      74             :     }
      75     8451188 :     protocol::Value* valueValue = object->get("value");
      76     4225594 :     if (valueValue) {
      77      636522 :         errors->setName("value");
      78      636522 :         result->m_value = ValueConversions<protocol::Value>::fromValue(valueValue, errors);
      79             :     }
      80     8451188 :     protocol::Value* unserializableValueValue = object->get("unserializableValue");
      81     4225594 :     if (unserializableValueValue) {
      82      112656 :         errors->setName("unserializableValue");
      83      112656 :         result->m_unserializableValue = ValueConversions<String>::fromValue(unserializableValueValue, errors);
      84             :     }
      85     8451188 :     protocol::Value* descriptionValue = object->get("description");
      86     4225594 :     if (descriptionValue) {
      87     8058670 :         errors->setName("description");
      88     8058670 :         result->m_description = ValueConversions<String>::fromValue(descriptionValue, errors);
      89             :     }
      90     8451188 :     protocol::Value* objectIdValue = object->get("objectId");
      91     4225594 :     if (objectIdValue) {
      92     7560952 :         errors->setName("objectId");
      93     7560952 :         result->m_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
      94             :     }
      95     8451188 :     protocol::Value* previewValue = object->get("preview");
      96     4225594 :     if (previewValue) {
      97         660 :         errors->setName("preview");
      98         330 :         result->m_preview = ValueConversions<protocol::Runtime::ObjectPreview>::fromValue(previewValue, errors);
      99             :     }
     100     8451188 :     protocol::Value* customPreviewValue = object->get("customPreview");
     101     4225594 :     if (customPreviewValue) {
     102          12 :         errors->setName("customPreview");
     103           6 :         result->m_customPreview = ValueConversions<protocol::Runtime::CustomPreview>::fromValue(customPreviewValue, errors);
     104             :     }
     105     4225594 :     errors->pop();
     106     4225594 :     if (errors->hasErrors())
     107             :         return nullptr;
     108             :     return result;
     109             : }
     110             : 
     111     4225624 : std::unique_ptr<protocol::DictionaryValue> RemoteObject::toValue() const
     112             : {
     113     4225624 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     114    21128120 :     result->setValue("type", ValueConversions<String>::toValue(m_type));
     115     4225624 :     if (m_subtype.isJust())
     116      446440 :         result->setValue("subtype", ValueConversions<String>::toValue(m_subtype.fromJust()));
     117     4225624 :     if (m_className.isJust())
     118    18759090 :         result->setValue("className", ValueConversions<String>::toValue(m_className.fromJust()));
     119     4225624 :     if (m_value.isJust())
     120     1273164 :         result->setValue("value", ValueConversions<protocol::Value>::toValue(m_value.fromJust()));
     121     4225624 :     if (m_unserializableValue.isJust())
     122      281640 :         result->setValue("unserializableValue", ValueConversions<String>::toValue(m_unserializableValue.fromJust()));
     123     4225624 :     if (m_description.isJust())
     124    20146735 :         result->setValue("description", ValueConversions<String>::toValue(m_description.fromJust()));
     125     4225624 :     if (m_objectId.isJust())
     126    18902380 :         result->setValue("objectId", ValueConversions<String>::toValue(m_objectId.fromJust()));
     127     4225624 :     if (m_preview.isJust())
     128        1320 :         result->setValue("preview", ValueConversions<protocol::Runtime::ObjectPreview>::toValue(m_preview.fromJust()));
     129     4225624 :     if (m_customPreview.isJust())
     130          24 :         result->setValue("customPreview", ValueConversions<protocol::Runtime::CustomPreview>::toValue(m_customPreview.fromJust()));
     131     4225624 :     return result;
     132             : }
     133             : 
     134          30 : std::unique_ptr<RemoteObject> RemoteObject::clone() const
     135             : {
     136          30 :     ErrorSupport errors;
     137          90 :     return fromValue(toValue().get(), &errors);
     138             : }
     139             : 
     140           0 : std::unique_ptr<StringBuffer> RemoteObject::toJSONString() const
     141             : {
     142           0 :     String json = toValue()->serialize();
     143           0 :     return StringBufferImpl::adopt(json);
     144             : }
     145             : 
     146             : // static
     147           0 : std::unique_ptr<API::RemoteObject> API::RemoteObject::fromJSONString(const StringView& json)
     148             : {
     149           0 :     ErrorSupport errors;
     150           0 :     std::unique_ptr<Value> value = StringUtil::parseJSON(json);
     151           0 :     if (!value)
     152             :         return nullptr;
     153           0 :     return protocol::Runtime::RemoteObject::fromValue(value.get(), &errors);
     154             : }
     155             : 
     156          12 : std::unique_ptr<CustomPreview> CustomPreview::fromValue(protocol::Value* value, ErrorSupport* errors)
     157             : {
     158          12 :     if (!value || value->type() != protocol::Value::TypeObject) {
     159           0 :         errors->addError("object expected");
     160             :         return nullptr;
     161             :     }
     162             : 
     163           6 :     std::unique_ptr<CustomPreview> result(new CustomPreview());
     164             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     165           6 :     errors->push();
     166          12 :     protocol::Value* headerValue = object->get("header");
     167          12 :     errors->setName("header");
     168          12 :     result->m_header = ValueConversions<String>::fromValue(headerValue, errors);
     169          12 :     protocol::Value* hasBodyValue = object->get("hasBody");
     170          12 :     errors->setName("hasBody");
     171           6 :     result->m_hasBody = ValueConversions<bool>::fromValue(hasBodyValue, errors);
     172          12 :     protocol::Value* formatterObjectIdValue = object->get("formatterObjectId");
     173          12 :     errors->setName("formatterObjectId");
     174          12 :     result->m_formatterObjectId = ValueConversions<String>::fromValue(formatterObjectIdValue, errors);
     175          12 :     protocol::Value* bindRemoteObjectFunctionIdValue = object->get("bindRemoteObjectFunctionId");
     176          12 :     errors->setName("bindRemoteObjectFunctionId");
     177          12 :     result->m_bindRemoteObjectFunctionId = ValueConversions<String>::fromValue(bindRemoteObjectFunctionIdValue, errors);
     178          12 :     protocol::Value* configObjectIdValue = object->get("configObjectId");
     179           6 :     if (configObjectIdValue) {
     180           0 :         errors->setName("configObjectId");
     181           0 :         result->m_configObjectId = ValueConversions<String>::fromValue(configObjectIdValue, errors);
     182             :     }
     183           6 :     errors->pop();
     184           6 :     if (errors->hasErrors())
     185             :         return nullptr;
     186             :     return result;
     187             : }
     188             : 
     189           6 : std::unique_ptr<protocol::DictionaryValue> CustomPreview::toValue() const
     190             : {
     191           6 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     192          30 :     result->setValue("header", ValueConversions<String>::toValue(m_header));
     193          30 :     result->setValue("hasBody", ValueConversions<bool>::toValue(m_hasBody));
     194          30 :     result->setValue("formatterObjectId", ValueConversions<String>::toValue(m_formatterObjectId));
     195          30 :     result->setValue("bindRemoteObjectFunctionId", ValueConversions<String>::toValue(m_bindRemoteObjectFunctionId));
     196           6 :     if (m_configObjectId.isJust())
     197           0 :         result->setValue("configObjectId", ValueConversions<String>::toValue(m_configObjectId.fromJust()));
     198           6 :     return result;
     199             : }
     200             : 
     201           0 : std::unique_ptr<CustomPreview> CustomPreview::clone() const
     202             : {
     203           0 :     ErrorSupport errors;
     204           0 :     return fromValue(toValue().get(), &errors);
     205             : }
     206             : 
     207             : const char* ObjectPreview::TypeEnum::Object = "object";
     208             : const char* ObjectPreview::TypeEnum::Function = "function";
     209             : const char* ObjectPreview::TypeEnum::Undefined = "undefined";
     210             : const char* ObjectPreview::TypeEnum::String = "string";
     211             : const char* ObjectPreview::TypeEnum::Number = "number";
     212             : const char* ObjectPreview::TypeEnum::Boolean = "boolean";
     213             : const char* ObjectPreview::TypeEnum::Symbol = "symbol";
     214             : 
     215             : const char* ObjectPreview::SubtypeEnum::Array = "array";
     216             : const char* ObjectPreview::SubtypeEnum::Null = "null";
     217             : const char* ObjectPreview::SubtypeEnum::Node = "node";
     218             : const char* ObjectPreview::SubtypeEnum::Regexp = "regexp";
     219             : const char* ObjectPreview::SubtypeEnum::Date = "date";
     220             : const char* ObjectPreview::SubtypeEnum::Map = "map";
     221             : const char* ObjectPreview::SubtypeEnum::Set = "set";
     222             : const char* ObjectPreview::SubtypeEnum::Weakmap = "weakmap";
     223             : const char* ObjectPreview::SubtypeEnum::Weakset = "weakset";
     224             : const char* ObjectPreview::SubtypeEnum::Iterator = "iterator";
     225             : const char* ObjectPreview::SubtypeEnum::Generator = "generator";
     226             : const char* ObjectPreview::SubtypeEnum::Error = "error";
     227             : 
     228         960 : std::unique_ptr<ObjectPreview> ObjectPreview::fromValue(protocol::Value* value, ErrorSupport* errors)
     229             : {
     230         960 :     if (!value || value->type() != protocol::Value::TypeObject) {
     231           0 :         errors->addError("object expected");
     232             :         return nullptr;
     233             :     }
     234             : 
     235         480 :     std::unique_ptr<ObjectPreview> result(new ObjectPreview());
     236             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     237         480 :     errors->push();
     238         960 :     protocol::Value* typeValue = object->get("type");
     239         960 :     errors->setName("type");
     240         960 :     result->m_type = ValueConversions<String>::fromValue(typeValue, errors);
     241         960 :     protocol::Value* subtypeValue = object->get("subtype");
     242         480 :     if (subtypeValue) {
     243         468 :         errors->setName("subtype");
     244         468 :         result->m_subtype = ValueConversions<String>::fromValue(subtypeValue, errors);
     245             :     }
     246         960 :     protocol::Value* descriptionValue = object->get("description");
     247         480 :     if (descriptionValue) {
     248         960 :         errors->setName("description");
     249         960 :         result->m_description = ValueConversions<String>::fromValue(descriptionValue, errors);
     250             :     }
     251         960 :     protocol::Value* overflowValue = object->get("overflow");
     252         960 :     errors->setName("overflow");
     253         480 :     result->m_overflow = ValueConversions<bool>::fromValue(overflowValue, errors);
     254         960 :     protocol::Value* propertiesValue = object->get("properties");
     255         960 :     errors->setName("properties");
     256         960 :     result->m_properties = ValueConversions<protocol::Array<protocol::Runtime::PropertyPreview>>::fromValue(propertiesValue, errors);
     257         960 :     protocol::Value* entriesValue = object->get("entries");
     258         480 :     if (entriesValue) {
     259         108 :         errors->setName("entries");
     260          54 :         result->m_entries = ValueConversions<protocol::Array<protocol::Runtime::EntryPreview>>::fromValue(entriesValue, errors);
     261             :     }
     262         480 :     errors->pop();
     263         480 :     if (errors->hasErrors())
     264             :         return nullptr;
     265             :     return result;
     266             : }
     267             : 
     268         480 : std::unique_ptr<protocol::DictionaryValue> ObjectPreview::toValue() const
     269             : {
     270         480 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     271        2400 :     result->setValue("type", ValueConversions<String>::toValue(m_type));
     272         480 :     if (m_subtype.isJust())
     273        1170 :         result->setValue("subtype", ValueConversions<String>::toValue(m_subtype.fromJust()));
     274         480 :     if (m_description.isJust())
     275        2400 :         result->setValue("description", ValueConversions<String>::toValue(m_description.fromJust()));
     276        2400 :     result->setValue("overflow", ValueConversions<bool>::toValue(m_overflow));
     277        1920 :     result->setValue("properties", ValueConversions<protocol::Array<protocol::Runtime::PropertyPreview>>::toValue(m_properties.get()));
     278         480 :     if (m_entries.isJust())
     279         216 :         result->setValue("entries", ValueConversions<protocol::Array<protocol::Runtime::EntryPreview>>::toValue(m_entries.fromJust()));
     280         480 :     return result;
     281             : }
     282             : 
     283           0 : std::unique_ptr<ObjectPreview> ObjectPreview::clone() const
     284             : {
     285           0 :     ErrorSupport errors;
     286           0 :     return fromValue(toValue().get(), &errors);
     287             : }
     288             : 
     289             : const char* PropertyPreview::TypeEnum::Object = "object";
     290             : const char* PropertyPreview::TypeEnum::Function = "function";
     291             : const char* PropertyPreview::TypeEnum::Undefined = "undefined";
     292             : const char* PropertyPreview::TypeEnum::String = "string";
     293             : const char* PropertyPreview::TypeEnum::Number = "number";
     294             : const char* PropertyPreview::TypeEnum::Boolean = "boolean";
     295             : const char* PropertyPreview::TypeEnum::Symbol = "symbol";
     296             : const char* PropertyPreview::TypeEnum::Accessor = "accessor";
     297             : 
     298             : const char* PropertyPreview::SubtypeEnum::Array = "array";
     299             : const char* PropertyPreview::SubtypeEnum::Null = "null";
     300             : const char* PropertyPreview::SubtypeEnum::Node = "node";
     301             : const char* PropertyPreview::SubtypeEnum::Regexp = "regexp";
     302             : const char* PropertyPreview::SubtypeEnum::Date = "date";
     303             : const char* PropertyPreview::SubtypeEnum::Map = "map";
     304             : const char* PropertyPreview::SubtypeEnum::Set = "set";
     305             : const char* PropertyPreview::SubtypeEnum::Weakmap = "weakmap";
     306             : const char* PropertyPreview::SubtypeEnum::Weakset = "weakset";
     307             : const char* PropertyPreview::SubtypeEnum::Iterator = "iterator";
     308             : const char* PropertyPreview::SubtypeEnum::Generator = "generator";
     309             : const char* PropertyPreview::SubtypeEnum::Error = "error";
     310             : 
     311        2184 : std::unique_ptr<PropertyPreview> PropertyPreview::fromValue(protocol::Value* value, ErrorSupport* errors)
     312             : {
     313        2184 :     if (!value || value->type() != protocol::Value::TypeObject) {
     314           0 :         errors->addError("object expected");
     315             :         return nullptr;
     316             :     }
     317             : 
     318        1092 :     std::unique_ptr<PropertyPreview> result(new PropertyPreview());
     319             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     320        1092 :     errors->push();
     321        2184 :     protocol::Value* nameValue = object->get("name");
     322        2184 :     errors->setName("name");
     323        2184 :     result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
     324        2184 :     protocol::Value* typeValue = object->get("type");
     325        2184 :     errors->setName("type");
     326        2184 :     result->m_type = ValueConversions<String>::fromValue(typeValue, errors);
     327        2184 :     protocol::Value* valueValue = object->get("value");
     328        1092 :     if (valueValue) {
     329        2100 :         errors->setName("value");
     330        2100 :         result->m_value = ValueConversions<String>::fromValue(valueValue, errors);
     331             :     }
     332        2184 :     protocol::Value* valuePreviewValue = object->get("valuePreview");
     333        1092 :     if (valuePreviewValue) {
     334          36 :         errors->setName("valuePreview");
     335          18 :         result->m_valuePreview = ValueConversions<protocol::Runtime::ObjectPreview>::fromValue(valuePreviewValue, errors);
     336             :     }
     337        2184 :     protocol::Value* subtypeValue = object->get("subtype");
     338        1092 :     if (subtypeValue) {
     339         168 :         errors->setName("subtype");
     340         168 :         result->m_subtype = ValueConversions<String>::fromValue(subtypeValue, errors);
     341             :     }
     342        1092 :     errors->pop();
     343        1092 :     if (errors->hasErrors())
     344             :         return nullptr;
     345             :     return result;
     346             : }
     347             : 
     348        1092 : std::unique_ptr<protocol::DictionaryValue> PropertyPreview::toValue() const
     349             : {
     350        1092 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     351        5460 :     result->setValue("name", ValueConversions<String>::toValue(m_name));
     352        5460 :     result->setValue("type", ValueConversions<String>::toValue(m_type));
     353        1092 :     if (m_value.isJust())
     354        5250 :         result->setValue("value", ValueConversions<String>::toValue(m_value.fromJust()));
     355        1092 :     if (m_valuePreview.isJust())
     356          72 :         result->setValue("valuePreview", ValueConversions<protocol::Runtime::ObjectPreview>::toValue(m_valuePreview.fromJust()));
     357        1092 :     if (m_subtype.isJust())
     358         420 :         result->setValue("subtype", ValueConversions<String>::toValue(m_subtype.fromJust()));
     359        1092 :     return result;
     360             : }
     361             : 
     362           0 : std::unique_ptr<PropertyPreview> PropertyPreview::clone() const
     363             : {
     364           0 :     ErrorSupport errors;
     365           0 :     return fromValue(toValue().get(), &errors);
     366             : }
     367             : 
     368         228 : std::unique_ptr<EntryPreview> EntryPreview::fromValue(protocol::Value* value, ErrorSupport* errors)
     369             : {
     370         228 :     if (!value || value->type() != protocol::Value::TypeObject) {
     371           0 :         errors->addError("object expected");
     372             :         return nullptr;
     373             :     }
     374             : 
     375         114 :     std::unique_ptr<EntryPreview> result(new EntryPreview());
     376             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     377         114 :     errors->push();
     378         228 :     protocol::Value* keyValue = object->get("key");
     379         114 :     if (keyValue) {
     380          36 :         errors->setName("key");
     381          18 :         result->m_key = ValueConversions<protocol::Runtime::ObjectPreview>::fromValue(keyValue, errors);
     382             :     }
     383         228 :     protocol::Value* valueValue = object->get("value");
     384         228 :     errors->setName("value");
     385         114 :     result->m_value = ValueConversions<protocol::Runtime::ObjectPreview>::fromValue(valueValue, errors);
     386         114 :     errors->pop();
     387         114 :     if (errors->hasErrors())
     388             :         return nullptr;
     389             :     return result;
     390             : }
     391             : 
     392         114 : std::unique_ptr<protocol::DictionaryValue> EntryPreview::toValue() const
     393             : {
     394         114 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     395         114 :     if (m_key.isJust())
     396          72 :         result->setValue("key", ValueConversions<protocol::Runtime::ObjectPreview>::toValue(m_key.fromJust()));
     397         456 :     result->setValue("value", ValueConversions<protocol::Runtime::ObjectPreview>::toValue(m_value.get()));
     398         114 :     return result;
     399             : }
     400             : 
     401           0 : std::unique_ptr<EntryPreview> EntryPreview::clone() const
     402             : {
     403           0 :     ErrorSupport errors;
     404           0 :     return fromValue(toValue().get(), &errors);
     405             : }
     406             : 
     407     6935412 : std::unique_ptr<PropertyDescriptor> PropertyDescriptor::fromValue(protocol::Value* value, ErrorSupport* errors)
     408             : {
     409     6935412 :     if (!value || value->type() != protocol::Value::TypeObject) {
     410           0 :         errors->addError("object expected");
     411             :         return nullptr;
     412             :     }
     413             : 
     414     3467706 :     std::unique_ptr<PropertyDescriptor> result(new PropertyDescriptor());
     415             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     416     3467706 :     errors->push();
     417     6935412 :     protocol::Value* nameValue = object->get("name");
     418     6935412 :     errors->setName("name");
     419     6935412 :     result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
     420     6935412 :     protocol::Value* valueValue = object->get("value");
     421     3467706 :     if (valueValue) {
     422     6934812 :         errors->setName("value");
     423     3467406 :         result->m_value = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(valueValue, errors);
     424             :     }
     425     6935412 :     protocol::Value* writableValue = object->get("writable");
     426     3467706 :     if (writableValue) {
     427     6934812 :         errors->setName("writable");
     428     3467406 :         result->m_writable = ValueConversions<bool>::fromValue(writableValue, errors);
     429             :     }
     430     6935412 :     protocol::Value* getValue = object->get("get");
     431     3467706 :     if (getValue) {
     432         600 :         errors->setName("get");
     433         300 :         result->m_get = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(getValue, errors);
     434             :     }
     435     6935412 :     protocol::Value* setValue = object->get("set");
     436     3467706 :     if (setValue) {
     437         600 :         errors->setName("set");
     438         300 :         result->m_set = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(setValue, errors);
     439             :     }
     440     6935412 :     protocol::Value* configurableValue = object->get("configurable");
     441     6935412 :     errors->setName("configurable");
     442     3467706 :     result->m_configurable = ValueConversions<bool>::fromValue(configurableValue, errors);
     443     6935412 :     protocol::Value* enumerableValue = object->get("enumerable");
     444     6935412 :     errors->setName("enumerable");
     445     3467706 :     result->m_enumerable = ValueConversions<bool>::fromValue(enumerableValue, errors);
     446     6935412 :     protocol::Value* wasThrownValue = object->get("wasThrown");
     447     3467706 :     if (wasThrownValue) {
     448           0 :         errors->setName("wasThrown");
     449           0 :         result->m_wasThrown = ValueConversions<bool>::fromValue(wasThrownValue, errors);
     450             :     }
     451     6935412 :     protocol::Value* isOwnValue = object->get("isOwn");
     452     3467706 :     if (isOwnValue) {
     453     6927228 :         errors->setName("isOwn");
     454     3463614 :         result->m_isOwn = ValueConversions<bool>::fromValue(isOwnValue, errors);
     455             :     }
     456     6935412 :     protocol::Value* symbolValue = object->get("symbol");
     457     3467706 :     if (symbolValue) {
     458       57248 :         errors->setName("symbol");
     459       28624 :         result->m_symbol = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(symbolValue, errors);
     460             :     }
     461     3467706 :     errors->pop();
     462     3467706 :     if (errors->hasErrors())
     463             :         return nullptr;
     464             :     return result;
     465             : }
     466             : 
     467     3467706 : std::unique_ptr<protocol::DictionaryValue> PropertyDescriptor::toValue() const
     468             : {
     469     3467706 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     470    17338530 :     result->setValue("name", ValueConversions<String>::toValue(m_name));
     471     3467706 :     if (m_value.isJust())
     472    13869624 :         result->setValue("value", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_value.fromJust()));
     473     3467706 :     if (m_writable.isJust())
     474    13869624 :         result->setValue("writable", ValueConversions<bool>::toValue(m_writable.fromJust()));
     475     3467706 :     if (m_get.isJust())
     476        1200 :         result->setValue("get", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_get.fromJust()));
     477     3467706 :     if (m_set.isJust())
     478        1200 :         result->setValue("set", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_set.fromJust()));
     479    17338530 :     result->setValue("configurable", ValueConversions<bool>::toValue(m_configurable));
     480    17338530 :     result->setValue("enumerable", ValueConversions<bool>::toValue(m_enumerable));
     481     3467706 :     if (m_wasThrown.isJust())
     482           0 :         result->setValue("wasThrown", ValueConversions<bool>::toValue(m_wasThrown.fromJust()));
     483     3467706 :     if (m_isOwn.isJust())
     484    13854456 :         result->setValue("isOwn", ValueConversions<bool>::toValue(m_isOwn.fromJust()));
     485     3467706 :     if (m_symbol.isJust())
     486      114496 :         result->setValue("symbol", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_symbol.fromJust()));
     487     3467706 :     return result;
     488             : }
     489             : 
     490           0 : std::unique_ptr<PropertyDescriptor> PropertyDescriptor::clone() const
     491             : {
     492           0 :     ErrorSupport errors;
     493           0 :     return fromValue(toValue().get(), &errors);
     494             : }
     495             : 
     496           0 : std::unique_ptr<InternalPropertyDescriptor> InternalPropertyDescriptor::fromValue(protocol::Value* value, ErrorSupport* errors)
     497             : {
     498           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     499           0 :         errors->addError("object expected");
     500             :         return nullptr;
     501             :     }
     502             : 
     503           0 :     std::unique_ptr<InternalPropertyDescriptor> result(new InternalPropertyDescriptor());
     504             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     505           0 :     errors->push();
     506           0 :     protocol::Value* nameValue = object->get("name");
     507           0 :     errors->setName("name");
     508           0 :     result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
     509           0 :     protocol::Value* valueValue = object->get("value");
     510           0 :     if (valueValue) {
     511           0 :         errors->setName("value");
     512           0 :         result->m_value = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(valueValue, errors);
     513             :     }
     514           0 :     errors->pop();
     515           0 :     if (errors->hasErrors())
     516             :         return nullptr;
     517             :     return result;
     518             : }
     519             : 
     520         988 : std::unique_ptr<protocol::DictionaryValue> InternalPropertyDescriptor::toValue() const
     521             : {
     522         988 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     523        4940 :     result->setValue("name", ValueConversions<String>::toValue(m_name));
     524         988 :     if (m_value.isJust())
     525        3952 :         result->setValue("value", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_value.fromJust()));
     526         988 :     return result;
     527             : }
     528             : 
     529           0 : std::unique_ptr<InternalPropertyDescriptor> InternalPropertyDescriptor::clone() const
     530             : {
     531           0 :     ErrorSupport errors;
     532           0 :     return fromValue(toValue().get(), &errors);
     533             : }
     534             : 
     535         436 : std::unique_ptr<CallArgument> CallArgument::fromValue(protocol::Value* value, ErrorSupport* errors)
     536             : {
     537         436 :     if (!value || value->type() != protocol::Value::TypeObject) {
     538           0 :         errors->addError("object expected");
     539             :         return nullptr;
     540             :     }
     541             : 
     542         218 :     std::unique_ptr<CallArgument> result(new CallArgument());
     543             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     544         218 :     errors->push();
     545         436 :     protocol::Value* valueValue = object->get("value");
     546         218 :     if (valueValue) {
     547         352 :         errors->setName("value");
     548         352 :         result->m_value = ValueConversions<protocol::Value>::fromValue(valueValue, errors);
     549             :     }
     550         436 :     protocol::Value* unserializableValueValue = object->get("unserializableValue");
     551         218 :     if (unserializableValueValue) {
     552          12 :         errors->setName("unserializableValue");
     553          12 :         result->m_unserializableValue = ValueConversions<String>::fromValue(unserializableValueValue, errors);
     554             :     }
     555         436 :     protocol::Value* objectIdValue = object->get("objectId");
     556         218 :     if (objectIdValue) {
     557          60 :         errors->setName("objectId");
     558          60 :         result->m_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
     559             :     }
     560         218 :     errors->pop();
     561         218 :     if (errors->hasErrors())
     562             :         return nullptr;
     563             :     return result;
     564             : }
     565             : 
     566           0 : std::unique_ptr<protocol::DictionaryValue> CallArgument::toValue() const
     567             : {
     568           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     569           0 :     if (m_value.isJust())
     570           0 :         result->setValue("value", ValueConversions<protocol::Value>::toValue(m_value.fromJust()));
     571           0 :     if (m_unserializableValue.isJust())
     572           0 :         result->setValue("unserializableValue", ValueConversions<String>::toValue(m_unserializableValue.fromJust()));
     573           0 :     if (m_objectId.isJust())
     574           0 :         result->setValue("objectId", ValueConversions<String>::toValue(m_objectId.fromJust()));
     575           0 :     return result;
     576             : }
     577             : 
     578           0 : std::unique_ptr<CallArgument> CallArgument::clone() const
     579             : {
     580           0 :     ErrorSupport errors;
     581           0 :     return fromValue(toValue().get(), &errors);
     582             : }
     583             : 
     584           0 : std::unique_ptr<ExecutionContextDescription> ExecutionContextDescription::fromValue(protocol::Value* value, ErrorSupport* errors)
     585             : {
     586           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     587           0 :         errors->addError("object expected");
     588             :         return nullptr;
     589             :     }
     590             : 
     591           0 :     std::unique_ptr<ExecutionContextDescription> result(new ExecutionContextDescription());
     592             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     593           0 :     errors->push();
     594           0 :     protocol::Value* idValue = object->get("id");
     595           0 :     errors->setName("id");
     596           0 :     result->m_id = ValueConversions<int>::fromValue(idValue, errors);
     597           0 :     protocol::Value* originValue = object->get("origin");
     598           0 :     errors->setName("origin");
     599           0 :     result->m_origin = ValueConversions<String>::fromValue(originValue, errors);
     600           0 :     protocol::Value* nameValue = object->get("name");
     601           0 :     errors->setName("name");
     602           0 :     result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
     603           0 :     protocol::Value* auxDataValue = object->get("auxData");
     604           0 :     if (auxDataValue) {
     605           0 :         errors->setName("auxData");
     606           0 :         result->m_auxData = ValueConversions<protocol::DictionaryValue>::fromValue(auxDataValue, errors);
     607             :     }
     608           0 :     errors->pop();
     609           0 :     if (errors->hasErrors())
     610             :         return nullptr;
     611             :     return result;
     612             : }
     613             : 
     614         402 : std::unique_ptr<protocol::DictionaryValue> ExecutionContextDescription::toValue() const
     615             : {
     616         402 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     617        2010 :     result->setValue("id", ValueConversions<int>::toValue(m_id));
     618        2010 :     result->setValue("origin", ValueConversions<String>::toValue(m_origin));
     619        2010 :     result->setValue("name", ValueConversions<String>::toValue(m_name));
     620         402 :     if (m_auxData.isJust())
     621           0 :         result->setValue("auxData", ValueConversions<protocol::DictionaryValue>::toValue(m_auxData.fromJust()));
     622         402 :     return result;
     623             : }
     624             : 
     625           0 : std::unique_ptr<ExecutionContextDescription> ExecutionContextDescription::clone() const
     626             : {
     627           0 :     ErrorSupport errors;
     628           0 :     return fromValue(toValue().get(), &errors);
     629             : }
     630             : 
     631           0 : std::unique_ptr<ExceptionDetails> ExceptionDetails::fromValue(protocol::Value* value, ErrorSupport* errors)
     632             : {
     633           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     634           0 :         errors->addError("object expected");
     635             :         return nullptr;
     636             :     }
     637             : 
     638           0 :     std::unique_ptr<ExceptionDetails> result(new ExceptionDetails());
     639             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     640           0 :     errors->push();
     641           0 :     protocol::Value* exceptionIdValue = object->get("exceptionId");
     642           0 :     errors->setName("exceptionId");
     643           0 :     result->m_exceptionId = ValueConversions<int>::fromValue(exceptionIdValue, errors);
     644           0 :     protocol::Value* textValue = object->get("text");
     645           0 :     errors->setName("text");
     646           0 :     result->m_text = ValueConversions<String>::fromValue(textValue, errors);
     647           0 :     protocol::Value* lineNumberValue = object->get("lineNumber");
     648           0 :     errors->setName("lineNumber");
     649           0 :     result->m_lineNumber = ValueConversions<int>::fromValue(lineNumberValue, errors);
     650           0 :     protocol::Value* columnNumberValue = object->get("columnNumber");
     651           0 :     errors->setName("columnNumber");
     652           0 :     result->m_columnNumber = ValueConversions<int>::fromValue(columnNumberValue, errors);
     653           0 :     protocol::Value* scriptIdValue = object->get("scriptId");
     654           0 :     if (scriptIdValue) {
     655           0 :         errors->setName("scriptId");
     656           0 :         result->m_scriptId = ValueConversions<String>::fromValue(scriptIdValue, errors);
     657             :     }
     658           0 :     protocol::Value* urlValue = object->get("url");
     659           0 :     if (urlValue) {
     660           0 :         errors->setName("url");
     661           0 :         result->m_url = ValueConversions<String>::fromValue(urlValue, errors);
     662             :     }
     663           0 :     protocol::Value* stackTraceValue = object->get("stackTrace");
     664           0 :     if (stackTraceValue) {
     665           0 :         errors->setName("stackTrace");
     666           0 :         result->m_stackTrace = ValueConversions<protocol::Runtime::StackTrace>::fromValue(stackTraceValue, errors);
     667             :     }
     668           0 :     protocol::Value* exceptionValue = object->get("exception");
     669           0 :     if (exceptionValue) {
     670           0 :         errors->setName("exception");
     671           0 :         result->m_exception = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(exceptionValue, errors);
     672             :     }
     673           0 :     protocol::Value* executionContextIdValue = object->get("executionContextId");
     674           0 :     if (executionContextIdValue) {
     675           0 :         errors->setName("executionContextId");
     676           0 :         result->m_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
     677             :     }
     678           0 :     errors->pop();
     679           0 :     if (errors->hasErrors())
     680             :         return nullptr;
     681             :     return result;
     682             : }
     683             : 
     684        1674 : std::unique_ptr<protocol::DictionaryValue> ExceptionDetails::toValue() const
     685             : {
     686        1674 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     687        8370 :     result->setValue("exceptionId", ValueConversions<int>::toValue(m_exceptionId));
     688        8370 :     result->setValue("text", ValueConversions<String>::toValue(m_text));
     689        8370 :     result->setValue("lineNumber", ValueConversions<int>::toValue(m_lineNumber));
     690        8370 :     result->setValue("columnNumber", ValueConversions<int>::toValue(m_columnNumber));
     691        1674 :     if (m_scriptId.isJust())
     692        8010 :         result->setValue("scriptId", ValueConversions<String>::toValue(m_scriptId.fromJust()));
     693        1674 :     if (m_url.isJust())
     694          30 :         result->setValue("url", ValueConversions<String>::toValue(m_url.fromJust()));
     695        1674 :     if (m_stackTrace.isJust())
     696         312 :         result->setValue("stackTrace", ValueConversions<protocol::Runtime::StackTrace>::toValue(m_stackTrace.fromJust()));
     697        1674 :     if (m_exception.isJust())
     698        6648 :         result->setValue("exception", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_exception.fromJust()));
     699        1674 :     if (m_executionContextId.isJust())
     700         168 :         result->setValue("executionContextId", ValueConversions<int>::toValue(m_executionContextId.fromJust()));
     701        1674 :     return result;
     702             : }
     703             : 
     704           0 : std::unique_ptr<ExceptionDetails> ExceptionDetails::clone() const
     705             : {
     706           0 :     ErrorSupport errors;
     707           0 :     return fromValue(toValue().get(), &errors);
     708             : }
     709             : 
     710           0 : std::unique_ptr<CallFrame> CallFrame::fromValue(protocol::Value* value, ErrorSupport* errors)
     711             : {
     712           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     713           0 :         errors->addError("object expected");
     714             :         return nullptr;
     715             :     }
     716             : 
     717           0 :     std::unique_ptr<CallFrame> result(new CallFrame());
     718             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     719           0 :     errors->push();
     720           0 :     protocol::Value* functionNameValue = object->get("functionName");
     721           0 :     errors->setName("functionName");
     722           0 :     result->m_functionName = ValueConversions<String>::fromValue(functionNameValue, errors);
     723           0 :     protocol::Value* scriptIdValue = object->get("scriptId");
     724           0 :     errors->setName("scriptId");
     725           0 :     result->m_scriptId = ValueConversions<String>::fromValue(scriptIdValue, errors);
     726           0 :     protocol::Value* urlValue = object->get("url");
     727           0 :     errors->setName("url");
     728           0 :     result->m_url = ValueConversions<String>::fromValue(urlValue, errors);
     729           0 :     protocol::Value* lineNumberValue = object->get("lineNumber");
     730           0 :     errors->setName("lineNumber");
     731           0 :     result->m_lineNumber = ValueConversions<int>::fromValue(lineNumberValue, errors);
     732           0 :     protocol::Value* columnNumberValue = object->get("columnNumber");
     733           0 :     errors->setName("columnNumber");
     734           0 :     result->m_columnNumber = ValueConversions<int>::fromValue(columnNumberValue, errors);
     735           0 :     errors->pop();
     736           0 :     if (errors->hasErrors())
     737             :         return nullptr;
     738             :     return result;
     739             : }
     740             : 
     741       44034 : std::unique_ptr<protocol::DictionaryValue> CallFrame::toValue() const
     742             : {
     743       44034 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     744      220170 :     result->setValue("functionName", ValueConversions<String>::toValue(m_functionName));
     745      220170 :     result->setValue("scriptId", ValueConversions<String>::toValue(m_scriptId));
     746      220170 :     result->setValue("url", ValueConversions<String>::toValue(m_url));
     747      220170 :     result->setValue("lineNumber", ValueConversions<int>::toValue(m_lineNumber));
     748      220170 :     result->setValue("columnNumber", ValueConversions<int>::toValue(m_columnNumber));
     749       44034 :     return result;
     750             : }
     751             : 
     752           0 : std::unique_ptr<CallFrame> CallFrame::clone() const
     753             : {
     754           0 :     ErrorSupport errors;
     755           0 :     return fromValue(toValue().get(), &errors);
     756             : }
     757             : 
     758           0 : std::unique_ptr<StackTrace> StackTrace::fromValue(protocol::Value* value, ErrorSupport* errors)
     759             : {
     760           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     761           0 :         errors->addError("object expected");
     762             :         return nullptr;
     763             :     }
     764             : 
     765           0 :     std::unique_ptr<StackTrace> result(new StackTrace());
     766             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     767           0 :     errors->push();
     768           0 :     protocol::Value* descriptionValue = object->get("description");
     769           0 :     if (descriptionValue) {
     770           0 :         errors->setName("description");
     771           0 :         result->m_description = ValueConversions<String>::fromValue(descriptionValue, errors);
     772             :     }
     773           0 :     protocol::Value* callFramesValue = object->get("callFrames");
     774           0 :     errors->setName("callFrames");
     775           0 :     result->m_callFrames = ValueConversions<protocol::Array<protocol::Runtime::CallFrame>>::fromValue(callFramesValue, errors);
     776           0 :     protocol::Value* parentValue = object->get("parent");
     777           0 :     if (parentValue) {
     778           0 :         errors->setName("parent");
     779           0 :         result->m_parent = ValueConversions<protocol::Runtime::StackTrace>::fromValue(parentValue, errors);
     780             :     }
     781           0 :     protocol::Value* promiseCreationFrameValue = object->get("promiseCreationFrame");
     782           0 :     if (promiseCreationFrameValue) {
     783           0 :         errors->setName("promiseCreationFrame");
     784           0 :         result->m_promiseCreationFrame = ValueConversions<protocol::Runtime::CallFrame>::fromValue(promiseCreationFrameValue, errors);
     785             :     }
     786           0 :     errors->pop();
     787           0 :     if (errors->hasErrors())
     788             :         return nullptr;
     789             :     return result;
     790             : }
     791             : 
     792       42537 : std::unique_ptr<protocol::DictionaryValue> StackTrace::toValue() const
     793             : {
     794       42537 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     795       42537 :     if (m_description.isJust())
     796       11670 :         result->setValue("description", ValueConversions<String>::toValue(m_description.fromJust()));
     797      170148 :     result->setValue("callFrames", ValueConversions<protocol::Array<protocol::Runtime::CallFrame>>::toValue(m_callFrames.get()));
     798       42537 :     if (m_parent.isJust())
     799        7824 :         result->setValue("parent", ValueConversions<protocol::Runtime::StackTrace>::toValue(m_parent.fromJust()));
     800       42537 :     if (m_promiseCreationFrame.isJust())
     801        6528 :         result->setValue("promiseCreationFrame", ValueConversions<protocol::Runtime::CallFrame>::toValue(m_promiseCreationFrame.fromJust()));
     802       42537 :     return result;
     803             : }
     804             : 
     805           0 : std::unique_ptr<StackTrace> StackTrace::clone() const
     806             : {
     807           0 :     ErrorSupport errors;
     808           0 :     return fromValue(toValue().get(), &errors);
     809             : }
     810             : 
     811           0 : std::unique_ptr<StringBuffer> StackTrace::toJSONString() const
     812             : {
     813           0 :     String json = toValue()->serialize();
     814           0 :     return StringBufferImpl::adopt(json);
     815             : }
     816             : 
     817             : // static
     818           0 : std::unique_ptr<API::StackTrace> API::StackTrace::fromJSONString(const StringView& json)
     819             : {
     820           0 :     ErrorSupport errors;
     821           0 :     std::unique_ptr<Value> value = StringUtil::parseJSON(json);
     822           0 :     if (!value)
     823             :         return nullptr;
     824           0 :     return protocol::Runtime::StackTrace::fromValue(value.get(), &errors);
     825             : }
     826             : 
     827           0 : std::unique_ptr<ExecutionContextCreatedNotification> ExecutionContextCreatedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     828             : {
     829           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     830           0 :         errors->addError("object expected");
     831             :         return nullptr;
     832             :     }
     833             : 
     834           0 :     std::unique_ptr<ExecutionContextCreatedNotification> result(new ExecutionContextCreatedNotification());
     835             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     836           0 :     errors->push();
     837           0 :     protocol::Value* contextValue = object->get("context");
     838           0 :     errors->setName("context");
     839           0 :     result->m_context = ValueConversions<protocol::Runtime::ExecutionContextDescription>::fromValue(contextValue, errors);
     840           0 :     errors->pop();
     841           0 :     if (errors->hasErrors())
     842             :         return nullptr;
     843             :     return result;
     844             : }
     845             : 
     846         402 : std::unique_ptr<protocol::DictionaryValue> ExecutionContextCreatedNotification::toValue() const
     847             : {
     848         402 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     849        1608 :     result->setValue("context", ValueConversions<protocol::Runtime::ExecutionContextDescription>::toValue(m_context.get()));
     850         402 :     return result;
     851             : }
     852             : 
     853           0 : std::unique_ptr<ExecutionContextCreatedNotification> ExecutionContextCreatedNotification::clone() const
     854             : {
     855           0 :     ErrorSupport errors;
     856           0 :     return fromValue(toValue().get(), &errors);
     857             : }
     858             : 
     859           0 : std::unique_ptr<ExecutionContextDestroyedNotification> ExecutionContextDestroyedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     860             : {
     861           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     862           0 :         errors->addError("object expected");
     863             :         return nullptr;
     864             :     }
     865             : 
     866           0 :     std::unique_ptr<ExecutionContextDestroyedNotification> result(new ExecutionContextDestroyedNotification());
     867             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     868           0 :     errors->push();
     869           0 :     protocol::Value* executionContextIdValue = object->get("executionContextId");
     870           0 :     errors->setName("executionContextId");
     871           0 :     result->m_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
     872           0 :     errors->pop();
     873           0 :     if (errors->hasErrors())
     874             :         return nullptr;
     875             :     return result;
     876             : }
     877             : 
     878           6 : std::unique_ptr<protocol::DictionaryValue> ExecutionContextDestroyedNotification::toValue() const
     879             : {
     880           6 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     881          30 :     result->setValue("executionContextId", ValueConversions<int>::toValue(m_executionContextId));
     882           6 :     return result;
     883             : }
     884             : 
     885           0 : std::unique_ptr<ExecutionContextDestroyedNotification> ExecutionContextDestroyedNotification::clone() const
     886             : {
     887           0 :     ErrorSupport errors;
     888           0 :     return fromValue(toValue().get(), &errors);
     889             : }
     890             : 
     891           0 : std::unique_ptr<ExceptionThrownNotification> ExceptionThrownNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     892             : {
     893           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     894           0 :         errors->addError("object expected");
     895             :         return nullptr;
     896             :     }
     897             : 
     898           0 :     std::unique_ptr<ExceptionThrownNotification> result(new ExceptionThrownNotification());
     899             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     900           0 :     errors->push();
     901           0 :     protocol::Value* timestampValue = object->get("timestamp");
     902           0 :     errors->setName("timestamp");
     903           0 :     result->m_timestamp = ValueConversions<double>::fromValue(timestampValue, errors);
     904           0 :     protocol::Value* exceptionDetailsValue = object->get("exceptionDetails");
     905           0 :     errors->setName("exceptionDetails");
     906           0 :     result->m_exceptionDetails = ValueConversions<protocol::Runtime::ExceptionDetails>::fromValue(exceptionDetailsValue, errors);
     907           0 :     errors->pop();
     908           0 :     if (errors->hasErrors())
     909             :         return nullptr;
     910             :     return result;
     911             : }
     912             : 
     913          42 : std::unique_ptr<protocol::DictionaryValue> ExceptionThrownNotification::toValue() const
     914             : {
     915          42 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     916         210 :     result->setValue("timestamp", ValueConversions<double>::toValue(m_timestamp));
     917         168 :     result->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(m_exceptionDetails.get()));
     918          42 :     return result;
     919             : }
     920             : 
     921           0 : std::unique_ptr<ExceptionThrownNotification> ExceptionThrownNotification::clone() const
     922             : {
     923           0 :     ErrorSupport errors;
     924           0 :     return fromValue(toValue().get(), &errors);
     925             : }
     926             : 
     927           0 : std::unique_ptr<ExceptionRevokedNotification> ExceptionRevokedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     928             : {
     929           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     930           0 :         errors->addError("object expected");
     931             :         return nullptr;
     932             :     }
     933             : 
     934           0 :     std::unique_ptr<ExceptionRevokedNotification> result(new ExceptionRevokedNotification());
     935             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     936           0 :     errors->push();
     937           0 :     protocol::Value* reasonValue = object->get("reason");
     938           0 :     errors->setName("reason");
     939           0 :     result->m_reason = ValueConversions<String>::fromValue(reasonValue, errors);
     940           0 :     protocol::Value* exceptionIdValue = object->get("exceptionId");
     941           0 :     errors->setName("exceptionId");
     942           0 :     result->m_exceptionId = ValueConversions<int>::fromValue(exceptionIdValue, errors);
     943           0 :     errors->pop();
     944           0 :     if (errors->hasErrors())
     945             :         return nullptr;
     946             :     return result;
     947             : }
     948             : 
     949           0 : std::unique_ptr<protocol::DictionaryValue> ExceptionRevokedNotification::toValue() const
     950             : {
     951           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     952           0 :     result->setValue("reason", ValueConversions<String>::toValue(m_reason));
     953           0 :     result->setValue("exceptionId", ValueConversions<int>::toValue(m_exceptionId));
     954           0 :     return result;
     955             : }
     956             : 
     957           0 : std::unique_ptr<ExceptionRevokedNotification> ExceptionRevokedNotification::clone() const
     958             : {
     959           0 :     ErrorSupport errors;
     960           0 :     return fromValue(toValue().get(), &errors);
     961             : }
     962             : 
     963             : const char* ConsoleAPICalledNotification::TypeEnum::Log = "log";
     964             : const char* ConsoleAPICalledNotification::TypeEnum::Debug = "debug";
     965             : const char* ConsoleAPICalledNotification::TypeEnum::Info = "info";
     966             : const char* ConsoleAPICalledNotification::TypeEnum::Error = "error";
     967             : const char* ConsoleAPICalledNotification::TypeEnum::Warning = "warning";
     968             : const char* ConsoleAPICalledNotification::TypeEnum::Dir = "dir";
     969             : const char* ConsoleAPICalledNotification::TypeEnum::Dirxml = "dirxml";
     970             : const char* ConsoleAPICalledNotification::TypeEnum::Table = "table";
     971             : const char* ConsoleAPICalledNotification::TypeEnum::Trace = "trace";
     972             : const char* ConsoleAPICalledNotification::TypeEnum::Clear = "clear";
     973             : const char* ConsoleAPICalledNotification::TypeEnum::StartGroup = "startGroup";
     974             : const char* ConsoleAPICalledNotification::TypeEnum::StartGroupCollapsed = "startGroupCollapsed";
     975             : const char* ConsoleAPICalledNotification::TypeEnum::EndGroup = "endGroup";
     976             : const char* ConsoleAPICalledNotification::TypeEnum::Assert = "assert";
     977             : const char* ConsoleAPICalledNotification::TypeEnum::Profile = "profile";
     978             : const char* ConsoleAPICalledNotification::TypeEnum::ProfileEnd = "profileEnd";
     979             : const char* ConsoleAPICalledNotification::TypeEnum::Count = "count";
     980             : const char* ConsoleAPICalledNotification::TypeEnum::TimeEnd = "timeEnd";
     981             : 
     982           0 : std::unique_ptr<ConsoleAPICalledNotification> ConsoleAPICalledNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     983             : {
     984           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     985           0 :         errors->addError("object expected");
     986             :         return nullptr;
     987             :     }
     988             : 
     989           0 :     std::unique_ptr<ConsoleAPICalledNotification> result(new ConsoleAPICalledNotification());
     990             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     991           0 :     errors->push();
     992           0 :     protocol::Value* typeValue = object->get("type");
     993           0 :     errors->setName("type");
     994           0 :     result->m_type = ValueConversions<String>::fromValue(typeValue, errors);
     995           0 :     protocol::Value* argsValue = object->get("args");
     996           0 :     errors->setName("args");
     997           0 :     result->m_args = ValueConversions<protocol::Array<protocol::Runtime::RemoteObject>>::fromValue(argsValue, errors);
     998           0 :     protocol::Value* executionContextIdValue = object->get("executionContextId");
     999           0 :     errors->setName("executionContextId");
    1000           0 :     result->m_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
    1001           0 :     protocol::Value* timestampValue = object->get("timestamp");
    1002           0 :     errors->setName("timestamp");
    1003           0 :     result->m_timestamp = ValueConversions<double>::fromValue(timestampValue, errors);
    1004           0 :     protocol::Value* stackTraceValue = object->get("stackTrace");
    1005           0 :     if (stackTraceValue) {
    1006           0 :         errors->setName("stackTrace");
    1007           0 :         result->m_stackTrace = ValueConversions<protocol::Runtime::StackTrace>::fromValue(stackTraceValue, errors);
    1008             :     }
    1009           0 :     errors->pop();
    1010           0 :     if (errors->hasErrors())
    1011             :         return nullptr;
    1012             :     return result;
    1013             : }
    1014             : 
    1015        7350 : std::unique_ptr<protocol::DictionaryValue> ConsoleAPICalledNotification::toValue() const
    1016             : {
    1017        7350 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
    1018       36750 :     result->setValue("type", ValueConversions<String>::toValue(m_type));
    1019       29400 :     result->setValue("args", ValueConversions<protocol::Array<protocol::Runtime::RemoteObject>>::toValue(m_args.get()));
    1020       36750 :     result->setValue("executionContextId", ValueConversions<int>::toValue(m_executionContextId));
    1021       36750 :     result->setValue("timestamp", ValueConversions<double>::toValue(m_timestamp));
    1022        7350 :     if (m_stackTrace.isJust())
    1023       29400 :         result->setValue("stackTrace", ValueConversions<protocol::Runtime::StackTrace>::toValue(m_stackTrace.fromJust()));
    1024        7350 :     return result;
    1025             : }
    1026             : 
    1027           0 : std::unique_ptr<ConsoleAPICalledNotification> ConsoleAPICalledNotification::clone() const
    1028             : {
    1029           0 :     ErrorSupport errors;
    1030           0 :     return fromValue(toValue().get(), &errors);
    1031             : }
    1032             : 
    1033           0 : std::unique_ptr<InspectRequestedNotification> InspectRequestedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
    1034             : {
    1035           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
    1036           0 :         errors->addError("object expected");
    1037             :         return nullptr;
    1038             :     }
    1039             : 
    1040           0 :     std::unique_ptr<InspectRequestedNotification> result(new InspectRequestedNotification());
    1041             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
    1042           0 :     errors->push();
    1043           0 :     protocol::Value* objectValue = object->get("object");
    1044           0 :     errors->setName("object");
    1045           0 :     result->m_object = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(objectValue, errors);
    1046           0 :     protocol::Value* hintsValue = object->get("hints");
    1047           0 :     errors->setName("hints");
    1048           0 :     result->m_hints = ValueConversions<protocol::DictionaryValue>::fromValue(hintsValue, errors);
    1049           0 :     errors->pop();
    1050           0 :     if (errors->hasErrors())
    1051             :         return nullptr;
    1052             :     return result;
    1053             : }
    1054             : 
    1055          30 : std::unique_ptr<protocol::DictionaryValue> InspectRequestedNotification::toValue() const
    1056             : {
    1057          30 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
    1058         120 :     result->setValue("object", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_object.get()));
    1059         120 :     result->setValue("hints", ValueConversions<protocol::DictionaryValue>::toValue(m_hints.get()));
    1060          30 :     return result;
    1061             : }
    1062             : 
    1063           0 : std::unique_ptr<InspectRequestedNotification> InspectRequestedNotification::clone() const
    1064             : {
    1065           0 :     ErrorSupport errors;
    1066           0 :     return fromValue(toValue().get(), &errors);
    1067             : }
    1068             : 
    1069             : // ------------- Enum values from params.
    1070             : 
    1071             : 
    1072             : namespace ConsoleAPICalled {
    1073             : namespace TypeEnum {
    1074             : const char* Log = "log";
    1075             : const char* Debug = "debug";
    1076             : const char* Info = "info";
    1077             : const char* Error = "error";
    1078             : const char* Warning = "warning";
    1079             : const char* Dir = "dir";
    1080             : const char* Dirxml = "dirxml";
    1081             : const char* Table = "table";
    1082             : const char* Trace = "trace";
    1083             : const char* Clear = "clear";
    1084             : const char* StartGroup = "startGroup";
    1085             : const char* StartGroupCollapsed = "startGroupCollapsed";
    1086             : const char* EndGroup = "endGroup";
    1087             : const char* Assert = "assert";
    1088             : const char* Profile = "profile";
    1089             : const char* ProfileEnd = "profileEnd";
    1090             : const char* Count = "count";
    1091             : const char* TimeEnd = "timeEnd";
    1092             : } // namespace TypeEnum
    1093             : } // namespace ConsoleAPICalled
    1094             : 
    1095             : // ------------- Frontend notifications.
    1096             : 
    1097         402 : void Frontend::executionContextCreated(std::unique_ptr<protocol::Runtime::ExecutionContextDescription> context)
    1098             : {
    1099         402 :     if (!m_frontendChannel)
    1100         402 :         return;
    1101             :     std::unique_ptr<ExecutionContextCreatedNotification> messageData = ExecutionContextCreatedNotification::create()
    1102             :         .setContext(std::move(context))
    1103             :         .build();
    1104        2814 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.executionContextCreated", std::move(messageData)));
    1105             : }
    1106             : 
    1107           6 : void Frontend::executionContextDestroyed(int executionContextId)
    1108             : {
    1109           6 :     if (!m_frontendChannel)
    1110           6 :         return;
    1111             :     std::unique_ptr<ExecutionContextDestroyedNotification> messageData = ExecutionContextDestroyedNotification::create()
    1112             :         .setExecutionContextId(executionContextId)
    1113             :         .build();
    1114          42 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.executionContextDestroyed", std::move(messageData)));
    1115             : }
    1116             : 
    1117          30 : void Frontend::executionContextsCleared()
    1118             : {
    1119          30 :     if (!m_frontendChannel)
    1120          30 :         return;
    1121         210 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.executionContextsCleared"));
    1122             : }
    1123             : 
    1124          42 : void Frontend::exceptionThrown(double timestamp, std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetails)
    1125             : {
    1126          42 :     if (!m_frontendChannel)
    1127          42 :         return;
    1128             :     std::unique_ptr<ExceptionThrownNotification> messageData = ExceptionThrownNotification::create()
    1129          42 :         .setTimestamp(timestamp)
    1130             :         .setExceptionDetails(std::move(exceptionDetails))
    1131             :         .build();
    1132         294 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.exceptionThrown", std::move(messageData)));
    1133             : }
    1134             : 
    1135           0 : void Frontend::exceptionRevoked(const String& reason, int exceptionId)
    1136             : {
    1137           0 :     if (!m_frontendChannel)
    1138           0 :         return;
    1139             :     std::unique_ptr<ExceptionRevokedNotification> messageData = ExceptionRevokedNotification::create()
    1140           0 :         .setReason(reason)
    1141             :         .setExceptionId(exceptionId)
    1142             :         .build();
    1143           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.exceptionRevoked", std::move(messageData)));
    1144             : }
    1145             : 
    1146        7350 : void Frontend::consoleAPICalled(const String& type, std::unique_ptr<protocol::Array<protocol::Runtime::RemoteObject>> args, int executionContextId, double timestamp, Maybe<protocol::Runtime::StackTrace> stackTrace)
    1147             : {
    1148        7350 :     if (!m_frontendChannel)
    1149        7350 :         return;
    1150             :     std::unique_ptr<ConsoleAPICalledNotification> messageData = ConsoleAPICalledNotification::create()
    1151        7350 :         .setType(type)
    1152             :         .setArgs(std::move(args))
    1153             :         .setExecutionContextId(executionContextId)
    1154             :         .setTimestamp(timestamp)
    1155             :         .build();
    1156        7350 :     if (stackTrace.isJust())
    1157             :         messageData->setStackTrace(std::move(stackTrace).takeJust());
    1158       51450 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.consoleAPICalled", std::move(messageData)));
    1159             : }
    1160             : 
    1161          30 : void Frontend::inspectRequested(std::unique_ptr<protocol::Runtime::RemoteObject> object, std::unique_ptr<protocol::DictionaryValue> hints)
    1162             : {
    1163          30 :     if (!m_frontendChannel)
    1164          30 :         return;
    1165             :     std::unique_ptr<InspectRequestedNotification> messageData = InspectRequestedNotification::create()
    1166          30 :         .setObject(std::move(object))
    1167             :         .setHints(std::move(hints))
    1168             :         .build();
    1169         210 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.inspectRequested", std::move(messageData)));
    1170             : }
    1171             : 
    1172        7392 : void Frontend::flush()
    1173             : {
    1174        7392 :     m_frontendChannel->flushProtocolNotifications();
    1175        7392 : }
    1176             : 
    1177           0 : void Frontend::sendRawNotification(const String& notification)
    1178             : {
    1179           0 :     m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
    1180           0 : }
    1181             : 
    1182             : // --------------------- Dispatcher.
    1183             : 
    1184             : class DispatcherImpl : public protocol::DispatcherBase {
    1185             : public:
    1186        4573 :     DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fallThroughForNotFound)
    1187             :         : DispatcherBase(frontendChannel)
    1188             :         , m_backend(backend)
    1189        9146 :         , m_fallThroughForNotFound(fallThroughForNotFound) {
    1190       13719 :         m_dispatchMap["Runtime.evaluate"] = &DispatcherImpl::evaluate;
    1191       13719 :         m_dispatchMap["Runtime.awaitPromise"] = &DispatcherImpl::awaitPromise;
    1192       13719 :         m_dispatchMap["Runtime.callFunctionOn"] = &DispatcherImpl::callFunctionOn;
    1193       13719 :         m_dispatchMap["Runtime.getProperties"] = &DispatcherImpl::getProperties;
    1194       13719 :         m_dispatchMap["Runtime.releaseObject"] = &DispatcherImpl::releaseObject;
    1195       13719 :         m_dispatchMap["Runtime.releaseObjectGroup"] = &DispatcherImpl::releaseObjectGroup;
    1196       13719 :         m_dispatchMap["Runtime.runIfWaitingForDebugger"] = &DispatcherImpl::runIfWaitingForDebugger;
    1197       13719 :         m_dispatchMap["Runtime.enable"] = &DispatcherImpl::enable;
    1198       13719 :         m_dispatchMap["Runtime.disable"] = &DispatcherImpl::disable;
    1199       13719 :         m_dispatchMap["Runtime.discardConsoleEntries"] = &DispatcherImpl::discardConsoleEntries;
    1200       13719 :         m_dispatchMap["Runtime.setCustomObjectFormatterEnabled"] = &DispatcherImpl::setCustomObjectFormatterEnabled;
    1201       13719 :         m_dispatchMap["Runtime.compileScript"] = &DispatcherImpl::compileScript;
    1202       13719 :         m_dispatchMap["Runtime.runScript"] = &DispatcherImpl::runScript;
    1203        4573 :     }
    1204       13719 :     ~DispatcherImpl() override { }
    1205             :     DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
    1206             : 
    1207             : protected:
    1208             :     using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
    1209             :     using DispatchMap = protocol::HashMap<String, CallHandler>;
    1210             :     DispatchMap m_dispatchMap;
    1211             : 
    1212             :     DispatchResponse::Status evaluate(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1213             :     DispatchResponse::Status awaitPromise(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1214             :     DispatchResponse::Status callFunctionOn(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1215             :     DispatchResponse::Status getProperties(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1216             :     DispatchResponse::Status releaseObject(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1217             :     DispatchResponse::Status releaseObjectGroup(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1218             :     DispatchResponse::Status runIfWaitingForDebugger(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1219             :     DispatchResponse::Status enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1220             :     DispatchResponse::Status disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1221             :     DispatchResponse::Status discardConsoleEntries(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1222             :     DispatchResponse::Status setCustomObjectFormatterEnabled(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1223             :     DispatchResponse::Status compileScript(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1224             :     DispatchResponse::Status runScript(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
    1225             : 
    1226             :     Backend* m_backend;
    1227             :     bool m_fallThroughForNotFound;
    1228             : };
    1229             : 
    1230      112251 : DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
    1231             : {
    1232             :     protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
    1233      112251 :     if (it == m_dispatchMap.end()) {
    1234           0 :         if (m_fallThroughForNotFound)
    1235             :             return DispatchResponse::kFallThrough;
    1236           0 :         reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
    1237           0 :         return DispatchResponse::kError;
    1238             :     }
    1239             : 
    1240      112251 :     protocol::ErrorSupport errors;
    1241      336753 :     return (this->*(it->second))(callId, std::move(messageObject), &errors);
    1242             : }
    1243             : 
    1244             : 
    1245        8782 : class EvaluateCallbackImpl : public Backend::EvaluateCallback, public DispatcherBase::Callback {
    1246             : public:
    1247        4745 :     EvaluateCallbackImpl(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, int callbackId)
    1248        9490 :         : DispatcherBase::Callback(std::move(backendImpl), callId, callbackId) { }
    1249             : 
    1250        4709 :     void sendSuccess(std::unique_ptr<protocol::Runtime::RemoteObject> result, Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails) override
    1251             :     {
    1252        4709 :         std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
    1253       18836 :         resultObject->setValue("result", ValueConversions<protocol::Runtime::RemoteObject>::toValue(result.get()));
    1254        4709 :         if (exceptionDetails.isJust())
    1255         264 :             resultObject->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(exceptionDetails.fromJust()));
    1256       18836 :         sendIfActive(std::move(resultObject), DispatchResponse::OK());
    1257        4709 :     }
    1258             : 
    1259           0 :     void fallThrough() override
    1260             :     {
    1261           0 :         fallThroughIfActive();
    1262           0 :     }
    1263             : 
    1264          42 :     void sendFailure(const DispatchResponse& response) override
    1265             :     {
    1266             :         DCHECK(response.status() == DispatchResponse::kError);
    1267          84 :         sendIfActive(nullptr, response);
    1268          42 :     }
    1269             : };
    1270             : 
    1271        4749 : DispatchResponse::Status DispatcherImpl::evaluate(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1272             : {
    1273             :     // Prepare input parameters.
    1274       14247 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
    1275        4749 :     errors->push();
    1276        9498 :     protocol::Value* expressionValue = object ? object->get("expression") : nullptr;
    1277        9498 :     errors->setName("expression");
    1278        4749 :     String in_expression = ValueConversions<String>::fromValue(expressionValue, errors);
    1279        9498 :     protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr;
    1280             :     Maybe<String> in_objectGroup;
    1281        4749 :     if (objectGroupValue) {
    1282         396 :         errors->setName("objectGroup");
    1283         396 :         in_objectGroup = ValueConversions<String>::fromValue(objectGroupValue, errors);
    1284             :     }
    1285        9498 :     protocol::Value* includeCommandLineAPIValue = object ? object->get("includeCommandLineAPI") : nullptr;
    1286             :     Maybe<bool> in_includeCommandLineAPI;
    1287        4749 :     if (includeCommandLineAPIValue) {
    1288        1112 :         errors->setName("includeCommandLineAPI");
    1289         556 :         in_includeCommandLineAPI = ValueConversions<bool>::fromValue(includeCommandLineAPIValue, errors);
    1290             :     }
    1291        9498 :     protocol::Value* silentValue = object ? object->get("silent") : nullptr;
    1292             :     Maybe<bool> in_silent;
    1293        4749 :     if (silentValue) {
    1294          12 :         errors->setName("silent");
    1295           6 :         in_silent = ValueConversions<bool>::fromValue(silentValue, errors);
    1296             :     }
    1297        9498 :     protocol::Value* contextIdValue = object ? object->get("contextId") : nullptr;
    1298             :     Maybe<int> in_contextId;
    1299        4749 :     if (contextIdValue) {
    1300          12 :         errors->setName("contextId");
    1301           6 :         in_contextId = ValueConversions<int>::fromValue(contextIdValue, errors);
    1302             :     }
    1303        9498 :     protocol::Value* returnByValueValue = object ? object->get("returnByValue") : nullptr;
    1304             :     Maybe<bool> in_returnByValue;
    1305        4749 :     if (returnByValueValue) {
    1306         144 :         errors->setName("returnByValue");
    1307          72 :         in_returnByValue = ValueConversions<bool>::fromValue(returnByValueValue, errors);
    1308             :     }
    1309        9498 :     protocol::Value* generatePreviewValue = object ? object->get("generatePreview") : nullptr;
    1310             :     Maybe<bool> in_generatePreview;
    1311        4749 :     if (generatePreviewValue) {
    1312         480 :         errors->setName("generatePreview");
    1313         240 :         in_generatePreview = ValueConversions<bool>::fromValue(generatePreviewValue, errors);
    1314             :     }
    1315        9498 :     protocol::Value* userGestureValue = object ? object->get("userGesture") : nullptr;
    1316             :     Maybe<bool> in_userGesture;
    1317        4749 :     if (userGestureValue) {
    1318           0 :         errors->setName("userGesture");
    1319           0 :         in_userGesture = ValueConversions<bool>::fromValue(userGestureValue, errors);
    1320             :     }
    1321        9498 :     protocol::Value* awaitPromiseValue = object ? object->get("awaitPromise") : nullptr;
    1322             :     Maybe<bool> in_awaitPromise;
    1323        4749 :     if (awaitPromiseValue) {
    1324         996 :         errors->setName("awaitPromise");
    1325         498 :         in_awaitPromise = ValueConversions<bool>::fromValue(awaitPromiseValue, errors);
    1326             :     }
    1327        4749 :     errors->pop();
    1328        4749 :     if (errors->hasErrors()) {
    1329           8 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
    1330           4 :         return DispatchResponse::kError;
    1331             :     }
    1332             : 
    1333        4745 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1334        9490 :     std::unique_ptr<EvaluateCallbackImpl> callback(new EvaluateCallbackImpl(weakPtr(), callId, nextCallbackId()));
    1335       18980 :     m_backend->evaluate(in_expression, std::move(in_objectGroup), std::move(in_includeCommandLineAPI), std::move(in_silent), std::move(in_contextId), std::move(in_returnByValue), std::move(in_generatePreview), std::move(in_userGesture), std::move(in_awaitPromise), std::move(callback));
    1336        4745 :     return (weak->get() && weak->get()->lastCallbackFallThrough()) ? DispatchResponse::kFallThrough : DispatchResponse::kAsync;
    1337             : }
    1338             : 
    1339          72 : class AwaitPromiseCallbackImpl : public Backend::AwaitPromiseCallback, public DispatcherBase::Callback {
    1340             : public:
    1341          36 :     AwaitPromiseCallbackImpl(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, int callbackId)
    1342          72 :         : DispatcherBase::Callback(std::move(backendImpl), callId, callbackId) { }
    1343             : 
    1344          30 :     void sendSuccess(std::unique_ptr<protocol::Runtime::RemoteObject> result, Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails) override
    1345             :     {
    1346          30 :         std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
    1347         120 :         resultObject->setValue("result", ValueConversions<protocol::Runtime::RemoteObject>::toValue(result.get()));
    1348          30 :         if (exceptionDetails.isJust())
    1349          48 :             resultObject->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(exceptionDetails.fromJust()));
    1350         120 :         sendIfActive(std::move(resultObject), DispatchResponse::OK());
    1351          30 :     }
    1352             : 
    1353           0 :     void fallThrough() override
    1354             :     {
    1355           0 :         fallThroughIfActive();
    1356           0 :     }
    1357             : 
    1358          36 :     void sendFailure(const DispatchResponse& response) override
    1359             :     {
    1360             :         DCHECK(response.status() == DispatchResponse::kError);
    1361          72 :         sendIfActive(nullptr, response);
    1362          36 :     }
    1363             : };
    1364             : 
    1365          36 : DispatchResponse::Status DispatcherImpl::awaitPromise(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1366             : {
    1367             :     // Prepare input parameters.
    1368         108 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
    1369          36 :     errors->push();
    1370          72 :     protocol::Value* promiseObjectIdValue = object ? object->get("promiseObjectId") : nullptr;
    1371          72 :     errors->setName("promiseObjectId");
    1372          36 :     String in_promiseObjectId = ValueConversions<String>::fromValue(promiseObjectIdValue, errors);
    1373          72 :     protocol::Value* returnByValueValue = object ? object->get("returnByValue") : nullptr;
    1374             :     Maybe<bool> in_returnByValue;
    1375          36 :     if (returnByValueValue) {
    1376          36 :         errors->setName("returnByValue");
    1377          18 :         in_returnByValue = ValueConversions<bool>::fromValue(returnByValueValue, errors);
    1378             :     }
    1379          72 :     protocol::Value* generatePreviewValue = object ? object->get("generatePreview") : nullptr;
    1380             :     Maybe<bool> in_generatePreview;
    1381          36 :     if (generatePreviewValue) {
    1382          36 :         errors->setName("generatePreview");
    1383          18 :         in_generatePreview = ValueConversions<bool>::fromValue(generatePreviewValue, errors);
    1384             :     }
    1385          36 :     errors->pop();
    1386          36 :     if (errors->hasErrors()) {
    1387           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
    1388           0 :         return DispatchResponse::kError;
    1389             :     }
    1390             : 
    1391          36 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1392          72 :     std::unique_ptr<AwaitPromiseCallbackImpl> callback(new AwaitPromiseCallbackImpl(weakPtr(), callId, nextCallbackId()));
    1393         108 :     m_backend->awaitPromise(in_promiseObjectId, std::move(in_returnByValue), std::move(in_generatePreview), std::move(callback));
    1394          36 :     return (weak->get() && weak->get()->lastCallbackFallThrough()) ? DispatchResponse::kFallThrough : DispatchResponse::kAsync;
    1395             : }
    1396             : 
    1397         648 : class CallFunctionOnCallbackImpl : public Backend::CallFunctionOnCallback, public DispatcherBase::Callback {
    1398             : public:
    1399         342 :     CallFunctionOnCallbackImpl(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, int callbackId)
    1400         684 :         : DispatcherBase::Callback(std::move(backendImpl), callId, callbackId) { }
    1401             : 
    1402         336 :     void sendSuccess(std::unique_ptr<protocol::Runtime::RemoteObject> result, Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails) override
    1403             :     {
    1404         336 :         std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
    1405        1344 :         resultObject->setValue("result", ValueConversions<protocol::Runtime::RemoteObject>::toValue(result.get()));
    1406         336 :         if (exceptionDetails.isJust())
    1407          96 :             resultObject->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(exceptionDetails.fromJust()));
    1408        1344 :         sendIfActive(std::move(resultObject), DispatchResponse::OK());
    1409         336 :     }
    1410             : 
    1411           0 :     void fallThrough() override
    1412             :     {
    1413           0 :         fallThroughIfActive();
    1414           0 :     }
    1415             : 
    1416           6 :     void sendFailure(const DispatchResponse& response) override
    1417             :     {
    1418             :         DCHECK(response.status() == DispatchResponse::kError);
    1419          12 :         sendIfActive(nullptr, response);
    1420           6 :     }
    1421             : };
    1422             : 
    1423         342 : DispatchResponse::Status DispatcherImpl::callFunctionOn(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1424             : {
    1425             :     // Prepare input parameters.
    1426        1026 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
    1427         342 :     errors->push();
    1428         684 :     protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
    1429         684 :     errors->setName("objectId");
    1430         342 :     String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
    1431         684 :     protocol::Value* functionDeclarationValue = object ? object->get("functionDeclaration") : nullptr;
    1432         684 :     errors->setName("functionDeclaration");
    1433         342 :     String in_functionDeclaration = ValueConversions<String>::fromValue(functionDeclarationValue, errors);
    1434         684 :     protocol::Value* argumentsValue = object ? object->get("arguments") : nullptr;
    1435             :     Maybe<protocol::Array<protocol::Runtime::CallArgument>> in_arguments;
    1436         342 :     if (argumentsValue) {
    1437          84 :         errors->setName("arguments");
    1438          42 :         in_arguments = ValueConversions<protocol::Array<protocol::Runtime::CallArgument>>::fromValue(argumentsValue, errors);
    1439             :     }
    1440         684 :     protocol::Value* silentValue = object ? object->get("silent") : nullptr;
    1441             :     Maybe<bool> in_silent;
    1442         342 :     if (silentValue) {
    1443           0 :         errors->setName("silent");
    1444           0 :         in_silent = ValueConversions<bool>::fromValue(silentValue, errors);
    1445             :     }
    1446         684 :     protocol::Value* returnByValueValue = object ? object->get("returnByValue") : nullptr;
    1447             :     Maybe<bool> in_returnByValue;
    1448         342 :     if (returnByValueValue) {
    1449         300 :         errors->setName("returnByValue");
    1450         150 :         in_returnByValue = ValueConversions<bool>::fromValue(returnByValueValue, errors);
    1451             :     }
    1452         684 :     protocol::Value* generatePreviewValue = object ? object->get("generatePreview") : nullptr;
    1453             :     Maybe<bool> in_generatePreview;
    1454         342 :     if (generatePreviewValue) {
    1455          84 :         errors->setName("generatePreview");
    1456          42 :         in_generatePreview = ValueConversions<bool>::fromValue(generatePreviewValue, errors);
    1457             :     }
    1458         684 :     protocol::Value* userGestureValue = object ? object->get("userGesture") : nullptr;
    1459             :     Maybe<bool> in_userGesture;
    1460         342 :     if (userGestureValue) {
    1461           0 :         errors->setName("userGesture");
    1462           0 :         in_userGesture = ValueConversions<bool>::fromValue(userGestureValue, errors);
    1463             :     }
    1464         684 :     protocol::Value* awaitPromiseValue = object ? object->get("awaitPromise") : nullptr;
    1465             :     Maybe<bool> in_awaitPromise;
    1466         342 :     if (awaitPromiseValue) {
    1467          84 :         errors->setName("awaitPromise");
    1468          42 :         in_awaitPromise = ValueConversions<bool>::fromValue(awaitPromiseValue, errors);
    1469             :     }
    1470         342 :     errors->pop();
    1471         342 :     if (errors->hasErrors()) {
    1472           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
    1473           0 :         return DispatchResponse::kError;
    1474             :     }
    1475             : 
    1476         342 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1477         684 :     std::unique_ptr<CallFunctionOnCallbackImpl> callback(new CallFunctionOnCallbackImpl(weakPtr(), callId, nextCallbackId()));
    1478        1368 :     m_backend->callFunctionOn(in_objectId, in_functionDeclaration, std::move(in_arguments), std::move(in_silent), std::move(in_returnByValue), std::move(in_generatePreview), std::move(in_userGesture), std::move(in_awaitPromise), std::move(callback));
    1479         342 :     return (weak->get() && weak->get()->lastCallbackFallThrough()) ? DispatchResponse::kFallThrough : DispatchResponse::kAsync;
    1480             : }
    1481             : 
    1482      106254 : DispatchResponse::Status DispatcherImpl::getProperties(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1483             : {
    1484             :     // Prepare input parameters.
    1485      318762 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
    1486      106254 :     errors->push();
    1487      212508 :     protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
    1488      212508 :     errors->setName("objectId");
    1489      106254 :     String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
    1490      212508 :     protocol::Value* ownPropertiesValue = object ? object->get("ownProperties") : nullptr;
    1491             :     Maybe<bool> in_ownProperties;
    1492      106254 :     if (ownPropertiesValue) {
    1493      211572 :         errors->setName("ownProperties");
    1494      105786 :         in_ownProperties = ValueConversions<bool>::fromValue(ownPropertiesValue, errors);
    1495             :     }
    1496      212508 :     protocol::Value* accessorPropertiesOnlyValue = object ? object->get("accessorPropertiesOnly") : nullptr;
    1497             :     Maybe<bool> in_accessorPropertiesOnly;
    1498      106254 :     if (accessorPropertiesOnlyValue) {
    1499          12 :         errors->setName("accessorPropertiesOnly");
    1500           6 :         in_accessorPropertiesOnly = ValueConversions<bool>::fromValue(accessorPropertiesOnlyValue, errors);
    1501             :     }
    1502      212508 :     protocol::Value* generatePreviewValue = object ? object->get("generatePreview") : nullptr;
    1503             :     Maybe<bool> in_generatePreview;
    1504      106254 :     if (generatePreviewValue) {
    1505          24 :         errors->setName("generatePreview");
    1506          12 :         in_generatePreview = ValueConversions<bool>::fromValue(generatePreviewValue, errors);
    1507             :     }
    1508      106254 :     errors->pop();
    1509      106254 :     if (errors->hasErrors()) {
    1510          12 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
    1511           6 :         return DispatchResponse::kError;
    1512             :     }
    1513             :     // Declare output parameters.
    1514      106248 :     std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>> out_result;
    1515             :     Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>> out_internalProperties;
    1516             :     Maybe<protocol::Runtime::ExceptionDetails> out_exceptionDetails;
    1517             : 
    1518      106248 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1519      212496 :     DispatchResponse response = m_backend->getProperties(in_objectId, std::move(in_ownProperties), std::move(in_accessorPropertiesOnly), std::move(in_generatePreview), &out_result, &out_internalProperties, &out_exceptionDetails);
    1520      106248 :     if (response.status() == DispatchResponse::kFallThrough)
    1521             :         return response.status();
    1522      106248 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
    1523      106248 :     if (response.status() == DispatchResponse::kSuccess) {
    1524      424992 :         result->setValue("result", ValueConversions<protocol::Array<protocol::Runtime::PropertyDescriptor>>::toValue(out_result.get()));
    1525      106248 :         if (out_internalProperties.isJust())
    1526        1672 :             result->setValue("internalProperties", ValueConversions<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>::toValue(out_internalProperties.fromJust()));
    1527      106248 :         if (out_exceptionDetails.isJust())
    1528           0 :             result->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(out_exceptionDetails.fromJust()));
    1529             :     }
    1530      106248 :     if (weak->get())
    1531      212496 :         weak->get()->sendResponse(callId, response, std::move(result));
    1532      106248 :     return response.status();
    1533             : }
    1534             : 
    1535           6 : DispatchResponse::Status DispatcherImpl::releaseObject(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1536             : {
    1537             :     // Prepare input parameters.
    1538          18 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
    1539           6 :     errors->push();
    1540          12 :     protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
    1541          12 :     errors->setName("objectId");
    1542           6 :     String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
    1543           6 :     errors->pop();
    1544           6 :     if (errors->hasErrors()) {
    1545           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
    1546           0 :         return DispatchResponse::kError;
    1547             :     }
    1548             : 
    1549           6 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1550           6 :     DispatchResponse response = m_backend->releaseObject(in_objectId);
    1551           6 :     if (weak->get())
    1552           6 :         weak->get()->sendResponse(callId, response);
    1553           6 :     return response.status();
    1554             : }
    1555             : 
    1556           0 : DispatchResponse::Status DispatcherImpl::releaseObjectGroup(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1557             : {
    1558             :     // Prepare input parameters.
    1559           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
    1560           0 :     errors->push();
    1561           0 :     protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr;
    1562           0 :     errors->setName("objectGroup");
    1563           0 :     String in_objectGroup = ValueConversions<String>::fromValue(objectGroupValue, errors);
    1564           0 :     errors->pop();
    1565           0 :     if (errors->hasErrors()) {
    1566           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
    1567           0 :         return DispatchResponse::kError;
    1568             :     }
    1569             : 
    1570           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1571           0 :     DispatchResponse response = m_backend->releaseObjectGroup(in_objectGroup);
    1572           0 :     if (weak->get())
    1573           0 :         weak->get()->sendResponse(callId, response);
    1574           0 :     return response.status();
    1575             : }
    1576             : 
    1577           0 : DispatchResponse::Status DispatcherImpl::runIfWaitingForDebugger(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1578             : {
    1579             : 
    1580           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1581           0 :     DispatchResponse response = m_backend->runIfWaitingForDebugger();
    1582           0 :     if (weak->get())
    1583           0 :         weak->get()->sendResponse(callId, response);
    1584           0 :     return response.status();
    1585             : }
    1586             : 
    1587         366 : DispatchResponse::Status DispatcherImpl::enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1588             : {
    1589             : 
    1590         366 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1591         366 :     DispatchResponse response = m_backend->enable();
    1592         366 :     if (weak->get())
    1593         366 :         weak->get()->sendResponse(callId, response);
    1594         732 :     return response.status();
    1595             : }
    1596             : 
    1597         192 : DispatchResponse::Status DispatcherImpl::disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1598             : {
    1599             : 
    1600         192 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1601         192 :     DispatchResponse response = m_backend->disable();
    1602         192 :     if (weak->get())
    1603         192 :         weak->get()->sendResponse(callId, response);
    1604         384 :     return response.status();
    1605             : }
    1606             : 
    1607           0 : DispatchResponse::Status DispatcherImpl::discardConsoleEntries(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1608             : {
    1609             : 
    1610           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1611           0 :     DispatchResponse response = m_backend->discardConsoleEntries();
    1612           0 :     if (weak->get())
    1613           0 :         weak->get()->sendResponse(callId, response);
    1614           0 :     return response.status();
    1615             : }
    1616             : 
    1617           6 : DispatchResponse::Status DispatcherImpl::setCustomObjectFormatterEnabled(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1618             : {
    1619             :     // Prepare input parameters.
    1620          18 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
    1621           6 :     errors->push();
    1622          12 :     protocol::Value* enabledValue = object ? object->get("enabled") : nullptr;
    1623          12 :     errors->setName("enabled");
    1624           6 :     bool in_enabled = ValueConversions<bool>::fromValue(enabledValue, errors);
    1625           6 :     errors->pop();
    1626           6 :     if (errors->hasErrors()) {
    1627           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
    1628           0 :         return DispatchResponse::kError;
    1629             :     }
    1630             : 
    1631           6 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1632           6 :     DispatchResponse response = m_backend->setCustomObjectFormatterEnabled(in_enabled);
    1633           6 :     if (weak->get())
    1634           6 :         weak->get()->sendResponse(callId, response);
    1635           6 :     return response.status();
    1636             : }
    1637             : 
    1638         180 : DispatchResponse::Status DispatcherImpl::compileScript(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1639             : {
    1640             :     // Prepare input parameters.
    1641         540 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
    1642         180 :     errors->push();
    1643         360 :     protocol::Value* expressionValue = object ? object->get("expression") : nullptr;
    1644         360 :     errors->setName("expression");
    1645         180 :     String in_expression = ValueConversions<String>::fromValue(expressionValue, errors);
    1646         360 :     protocol::Value* sourceURLValue = object ? object->get("sourceURL") : nullptr;
    1647         360 :     errors->setName("sourceURL");
    1648         180 :     String in_sourceURL = ValueConversions<String>::fromValue(sourceURLValue, errors);
    1649         360 :     protocol::Value* persistScriptValue = object ? object->get("persistScript") : nullptr;
    1650         360 :     errors->setName("persistScript");
    1651         180 :     bool in_persistScript = ValueConversions<bool>::fromValue(persistScriptValue, errors);
    1652         360 :     protocol::Value* executionContextIdValue = object ? object->get("executionContextId") : nullptr;
    1653             :     Maybe<int> in_executionContextId;
    1654         180 :     if (executionContextIdValue) {
    1655          48 :         errors->setName("executionContextId");
    1656          24 :         in_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
    1657             :     }
    1658         180 :     errors->pop();
    1659         180 :     if (errors->hasErrors()) {
    1660           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
    1661           0 :         return DispatchResponse::kError;
    1662             :     }
    1663             :     // Declare output parameters.
    1664             :     Maybe<String> out_scriptId;
    1665             :     Maybe<protocol::Runtime::ExceptionDetails> out_exceptionDetails;
    1666             : 
    1667         180 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1668         360 :     DispatchResponse response = m_backend->compileScript(in_expression, in_sourceURL, in_persistScript, std::move(in_executionContextId), &out_scriptId, &out_exceptionDetails);
    1669         180 :     if (response.status() == DispatchResponse::kFallThrough)
    1670             :         return response.status();
    1671         180 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
    1672         180 :     if (response.status() == DispatchResponse::kSuccess) {
    1673         174 :         if (out_scriptId.isJust())
    1674         660 :             result->setValue("scriptId", ValueConversions<String>::toValue(out_scriptId.fromJust()));
    1675         174 :         if (out_exceptionDetails.isJust())
    1676         120 :             result->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(out_exceptionDetails.fromJust()));
    1677             :     }
    1678         180 :     if (weak->get())
    1679         360 :         weak->get()->sendResponse(callId, response, std::move(result));
    1680         180 :     return response.status();
    1681             : }
    1682             : 
    1683         216 : class RunScriptCallbackImpl : public Backend::RunScriptCallback, public DispatcherBase::Callback {
    1684             : public:
    1685         120 :     RunScriptCallbackImpl(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, int callbackId)
    1686         240 :         : DispatcherBase::Callback(std::move(backendImpl), callId, callbackId) { }
    1687             : 
    1688          90 :     void sendSuccess(std::unique_ptr<protocol::Runtime::RemoteObject> result, Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails) override
    1689             :     {
    1690          90 :         std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
    1691         360 :         resultObject->setValue("result", ValueConversions<protocol::Runtime::RemoteObject>::toValue(result.get()));
    1692          90 :         if (exceptionDetails.isJust())
    1693          48 :             resultObject->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(exceptionDetails.fromJust()));
    1694         360 :         sendIfActive(std::move(resultObject), DispatchResponse::OK());
    1695          90 :     }
    1696             : 
    1697           0 :     void fallThrough() override
    1698             :     {
    1699           0 :         fallThroughIfActive();
    1700           0 :     }
    1701             : 
    1702          30 :     void sendFailure(const DispatchResponse& response) override
    1703             :     {
    1704             :         DCHECK(response.status() == DispatchResponse::kError);
    1705          60 :         sendIfActive(nullptr, response);
    1706          30 :     }
    1707             : };
    1708             : 
    1709         120 : DispatchResponse::Status DispatcherImpl::runScript(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
    1710             : {
    1711             :     // Prepare input parameters.
    1712         360 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
    1713         120 :     errors->push();
    1714         240 :     protocol::Value* scriptIdValue = object ? object->get("scriptId") : nullptr;
    1715         240 :     errors->setName("scriptId");
    1716         120 :     String in_scriptId = ValueConversions<String>::fromValue(scriptIdValue, errors);
    1717         240 :     protocol::Value* executionContextIdValue = object ? object->get("executionContextId") : nullptr;
    1718             :     Maybe<int> in_executionContextId;
    1719         120 :     if (executionContextIdValue) {
    1720           0 :         errors->setName("executionContextId");
    1721           0 :         in_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
    1722             :     }
    1723         240 :     protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr;
    1724             :     Maybe<String> in_objectGroup;
    1725         120 :     if (objectGroupValue) {
    1726           0 :         errors->setName("objectGroup");
    1727           0 :         in_objectGroup = ValueConversions<String>::fromValue(objectGroupValue, errors);
    1728             :     }
    1729         240 :     protocol::Value* silentValue = object ? object->get("silent") : nullptr;
    1730             :     Maybe<bool> in_silent;
    1731         120 :     if (silentValue) {
    1732           0 :         errors->setName("silent");
    1733           0 :         in_silent = ValueConversions<bool>::fromValue(silentValue, errors);
    1734             :     }
    1735         240 :     protocol::Value* includeCommandLineAPIValue = object ? object->get("includeCommandLineAPI") : nullptr;
    1736             :     Maybe<bool> in_includeCommandLineAPI;
    1737         120 :     if (includeCommandLineAPIValue) {
    1738           0 :         errors->setName("includeCommandLineAPI");
    1739           0 :         in_includeCommandLineAPI = ValueConversions<bool>::fromValue(includeCommandLineAPIValue, errors);
    1740             :     }
    1741         240 :     protocol::Value* returnByValueValue = object ? object->get("returnByValue") : nullptr;
    1742             :     Maybe<bool> in_returnByValue;
    1743         120 :     if (returnByValueValue) {
    1744          36 :         errors->setName("returnByValue");
    1745          18 :         in_returnByValue = ValueConversions<bool>::fromValue(returnByValueValue, errors);
    1746             :     }
    1747         240 :     protocol::Value* generatePreviewValue = object ? object->get("generatePreview") : nullptr;
    1748             :     Maybe<bool> in_generatePreview;
    1749         120 :     if (generatePreviewValue) {
    1750          12 :         errors->setName("generatePreview");
    1751           6 :         in_generatePreview = ValueConversions<bool>::fromValue(generatePreviewValue, errors);
    1752             :     }
    1753         240 :     protocol::Value* awaitPromiseValue = object ? object->get("awaitPromise") : nullptr;
    1754             :     Maybe<bool> in_awaitPromise;
    1755         120 :     if (awaitPromiseValue) {
    1756          36 :         errors->setName("awaitPromise");
    1757          18 :         in_awaitPromise = ValueConversions<bool>::fromValue(awaitPromiseValue, errors);
    1758             :     }
    1759         120 :     errors->pop();
    1760         120 :     if (errors->hasErrors()) {
    1761           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
    1762           0 :         return DispatchResponse::kError;
    1763             :     }
    1764             : 
    1765         120 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
    1766         240 :     std::unique_ptr<RunScriptCallbackImpl> callback(new RunScriptCallbackImpl(weakPtr(), callId, nextCallbackId()));
    1767         480 :     m_backend->runScript(in_scriptId, std::move(in_executionContextId), std::move(in_objectGroup), std::move(in_silent), std::move(in_includeCommandLineAPI), std::move(in_returnByValue), std::move(in_generatePreview), std::move(in_awaitPromise), std::move(callback));
    1768         120 :     return (weak->get() && weak->get()->lastCallbackFallThrough()) ? DispatchResponse::kFallThrough : DispatchResponse::kAsync;
    1769             : }
    1770             : 
    1771             : // static
    1772        4573 : void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend)
    1773             : {
    1774       18292 :     dispatcher->registerBackend("Runtime", std::unique_ptr<protocol::DispatcherBase>(new DispatcherImpl(dispatcher->channel(), backend, dispatcher->fallThroughForNotFound())));
    1775        4573 : }
    1776             : 
    1777             : } // Runtime
    1778             : } // namespace v8_inspector
    1779             : } // namespace protocol

Generated by: LCOV version 1.10