LCOV - code coverage report
Current view: top level - out/Release/gen/src/inspector/protocol - Protocol.h (source / functions) Hit Total Coverage
Test: app.info Lines: 124 142 87.3 %
Date: 2019-01-20 Functions: 53 85 62.4 %

          Line data    Source code
       1             : // Copyright 2016 The Chromium Authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef v8_inspector_protocol_ErrorSupport_h
       6             : #define v8_inspector_protocol_ErrorSupport_h
       7             : 
       8             : #include "src/inspector/protocol/Forward.h"
       9             : 
      10             : namespace v8_inspector {
      11             : namespace protocol {
      12             : 
      13             : class  ErrorSupport {
      14             : public:
      15             :     ErrorSupport();
      16             :     ~ErrorSupport();
      17             : 
      18             :     void push();
      19             :     void setName(const char*);
      20             :     void setName(const String&);
      21             :     void pop();
      22             :     void addError(const char*);
      23             :     void addError(const String&);
      24             :     bool hasErrors();
      25             :     String errors();
      26             : 
      27             : private:
      28             :     std::vector<String> m_path;
      29             :     std::vector<String> m_errors;
      30             : };
      31             : 
      32             : } // namespace v8_inspector
      33             : } // namespace protocol
      34             : 
      35             : #endif // !defined(v8_inspector_protocol_ErrorSupport_h)
      36             : 
      37             : 
      38             : // Copyright 2016 The Chromium Authors. All rights reserved.
      39             : // Use of this source code is governed by a BSD-style license that can be
      40             : // found in the LICENSE file.
      41             : 
      42             : #ifndef v8_inspector_protocol_Values_h
      43             : #define v8_inspector_protocol_Values_h
      44             : 
      45             : //#include "Allocator.h"
      46             : //#include "Forward.h"
      47             : 
      48             : namespace v8_inspector {
      49             : namespace protocol {
      50             : 
      51             : class ListValue;
      52             : class DictionaryValue;
      53             : class Value;
      54             : 
      55             : class  Value : public Serializable {
      56             :     PROTOCOL_DISALLOW_COPY(Value);
      57             : public:
      58    38417972 :     virtual ~Value() override { }
      59             : 
      60             :     static std::unique_ptr<Value> null()
      61             :     {
      62        5421 :         return std::unique_ptr<Value>(new Value());
      63             :     }
      64             : 
      65             :     enum ValueType {
      66             :         TypeNull = 0,
      67             :         TypeBoolean,
      68             :         TypeInteger,
      69             :         TypeDouble,
      70             :         TypeString,
      71             :         TypeObject,
      72             :         TypeArray,
      73             :         TypeSerialized
      74             :     };
      75             : 
      76             :     ValueType type() const { return m_type; }
      77             : 
      78             :     bool isNull() const { return m_type == TypeNull; }
      79             : 
      80             :     virtual bool asBoolean(bool* output) const;
      81             :     virtual bool asDouble(double* output) const;
      82             :     virtual bool asInteger(int* output) const;
      83             :     virtual bool asString(String* output) const;
      84             :     virtual bool asSerialized(String* output) const;
      85             : 
      86             :     virtual void writeJSON(StringBuilder* output) const;
      87             :     virtual std::unique_ptr<Value> clone() const;
      88             :     String serialize() override;
      89             : 
      90             : protected:
      91        5421 :     Value() : m_type(TypeNull) { }
      92    38407130 :     explicit Value(ValueType type) : m_type(type) { }
      93             : 
      94             : private:
      95             :     friend class DictionaryValue;
      96             :     friend class ListValue;
      97             : 
      98             :     ValueType m_type;
      99             : };
     100             : 
     101    25732522 : class  FundamentalValue : public Value {
     102             : public:
     103    10301653 :     static std::unique_ptr<FundamentalValue> create(bool value)
     104             :     {
     105    20603306 :         return std::unique_ptr<FundamentalValue>(new FundamentalValue(value));
     106             :     }
     107             : 
     108     2268923 :     static std::unique_ptr<FundamentalValue> create(int value)
     109             :     {
     110     4537846 :         return std::unique_ptr<FundamentalValue>(new FundamentalValue(value));
     111             :     }
     112             : 
     113      295685 :     static std::unique_ptr<FundamentalValue> create(double value)
     114             :     {
     115      591370 :         return std::unique_ptr<FundamentalValue>(new FundamentalValue(value));
     116             :     }
     117             : 
     118             :     bool asBoolean(bool* output) const override;
     119             :     bool asDouble(double* output) const override;
     120             :     bool asInteger(int* output) const override;
     121             :     void writeJSON(StringBuilder* output) const override;
     122             :     std::unique_ptr<Value> clone() const override;
     123             : 
     124             : private:
     125    10301653 :     explicit FundamentalValue(bool value) : Value(TypeBoolean), m_boolValue(value) { }
     126     2268923 :     explicit FundamentalValue(int value) : Value(TypeInteger), m_integerValue(value) { }
     127      295685 :     explicit FundamentalValue(double value) : Value(TypeDouble), m_doubleValue(value) { }
     128             : 
     129             :     union {
     130             :         bool m_boolValue;
     131             :         double m_doubleValue;
     132             :         int m_integerValue;
     133             :     };
     134             : };
     135             : 
     136    33594600 : class  StringValue : public Value {
     137             : public:
     138    16797300 :     static std::unique_ptr<StringValue> create(const String& value)
     139             :     {
     140    33594600 :         return std::unique_ptr<StringValue>(new StringValue(value));
     141             :     }
     142             : 
     143             :     static std::unique_ptr<StringValue> create(const char* value)
     144             :     {
     145             :         return std::unique_ptr<StringValue>(new StringValue(value));
     146             :     }
     147             : 
     148             :     bool asString(String* output) const override;
     149             :     void writeJSON(StringBuilder* output) const override;
     150             :     std::unique_ptr<Value> clone() const override;
     151             : 
     152             : private:
     153    16797300 :     explicit StringValue(const String& value) : Value(TypeString), m_stringValue(value) { }
     154             :     explicit StringValue(const char* value) : Value(TypeString), m_stringValue(value) { }
     155             : 
     156             :     String m_stringValue;
     157             : };
     158             : 
     159      695014 : class  SerializedValue : public Value {
     160             : public:
     161      347507 :     static std::unique_ptr<SerializedValue> create(const String& value)
     162             :     {
     163      695014 :         return std::unique_ptr<SerializedValue>(new SerializedValue(value));
     164             :     }
     165             : 
     166             :     bool asSerialized(String* output) const override;
     167             :     void writeJSON(StringBuilder* output) const override;
     168             :     std::unique_ptr<Value> clone() const override;
     169             : 
     170             : private:
     171      347507 :     explicit SerializedValue(const String& value) : Value(TypeSerialized), m_serializedValue(value) { }
     172             : 
     173             :     String m_serializedValue;
     174             : };
     175             : 
     176             : class  DictionaryValue : public Value {
     177             : public:
     178             :     using Entry = std::pair<String, Value*>;
     179     7986620 :     static std::unique_ptr<DictionaryValue> create()
     180             :     {
     181    15973240 :         return std::unique_ptr<DictionaryValue>(new DictionaryValue());
     182             :     }
     183             : 
     184      554941 :     static DictionaryValue* cast(Value* value)
     185             :     {
     186     1373600 :         if (!value || value->type() != TypeObject)
     187             :             return nullptr;
     188             :         return static_cast<DictionaryValue*>(value);
     189             :     }
     190             : 
     191             :     static std::unique_ptr<DictionaryValue> cast(std::unique_ptr<Value> value)
     192             :     {
     193             :         return std::unique_ptr<DictionaryValue>(DictionaryValue::cast(value.release()));
     194             :     }
     195             : 
     196             :     void writeJSON(StringBuilder* output) const override;
     197             :     std::unique_ptr<Value> clone() const override;
     198             : 
     199             :     size_t size() const { return m_data.size(); }
     200             : 
     201             :     void setBoolean(const String& name, bool);
     202             :     void setInteger(const String& name, int);
     203             :     void setDouble(const String& name, double);
     204             :     void setString(const String& name, const String&);
     205             :     void setValue(const String& name, std::unique_ptr<Value>);
     206             :     void setObject(const String& name, std::unique_ptr<DictionaryValue>);
     207             :     void setArray(const String& name, std::unique_ptr<ListValue>);
     208             : 
     209             :     bool getBoolean(const String& name, bool* output) const;
     210             :     bool getInteger(const String& name, int* output) const;
     211             :     bool getDouble(const String& name, double* output) const;
     212             :     bool getString(const String& name, String* output) const;
     213             : 
     214             :     DictionaryValue* getObject(const String& name) const;
     215             :     ListValue* getArray(const String& name) const;
     216             :     Value* get(const String& name) const;
     217             :     Entry at(size_t index) const;
     218             : 
     219             :     bool booleanProperty(const String& name, bool defaultValue) const;
     220             :     int integerProperty(const String& name, int defaultValue) const;
     221             :     double doubleProperty(const String& name, double defaultValue) const;
     222             :     void remove(const String& name);
     223             : 
     224             :     ~DictionaryValue() override;
     225             : 
     226             : private:
     227             :     DictionaryValue();
     228             :     template<typename T>
     229    34089395 :     void set(const String& key, std::unique_ptr<T>& value)
     230             :     {
     231             :         DCHECK(value);
     232             :         bool isNew = m_data.find(key) == m_data.end();
     233             :         m_data[key] = std::move(value);
     234    34089395 :         if (isNew)
     235    34077762 :             m_order.push_back(key);
     236    34089395 :     }
     237             : 
     238             :     using Dictionary = std::unordered_map<String, std::unique_ptr<Value>>;
     239             :     Dictionary m_data;
     240             :     std::vector<String> m_order;
     241             : };
     242             : 
     243             : class  ListValue : public Value {
     244             : public:
     245      409442 :     static std::unique_ptr<ListValue> create()
     246             :     {
     247      818884 :         return std::unique_ptr<ListValue>(new ListValue());
     248             :     }
     249             : 
     250         285 :     static ListValue* cast(Value* value)
     251             :     {
     252         570 :         if (!value || value->type() != TypeArray)
     253             :             return nullptr;
     254             :         return static_cast<ListValue*>(value);
     255             :     }
     256             : 
     257             :     static std::unique_ptr<ListValue> cast(std::unique_ptr<Value> value)
     258             :     {
     259             :         return std::unique_ptr<ListValue>(ListValue::cast(value.release()));
     260             :     }
     261             : 
     262             :     ~ListValue() override;
     263             : 
     264             :     void writeJSON(StringBuilder* output) const override;
     265             :     std::unique_ptr<Value> clone() const override;
     266             : 
     267             :     void pushValue(std::unique_ptr<Value>);
     268             : 
     269             :     Value* at(size_t index);
     270         630 :     size_t size() const { return m_data.size(); }
     271             : 
     272             : private:
     273             :     ListValue();
     274             :     std::vector<std::unique_ptr<Value>> m_data;
     275             : };
     276             : 
     277             : void escapeLatinStringForJSON(const uint8_t* str, unsigned len, StringBuilder* dst);
     278             : void escapeWideStringForJSON(const uint16_t* str, unsigned len, StringBuilder* dst);
     279             : 
     280             : } // namespace v8_inspector
     281             : } // namespace protocol
     282             : 
     283             : #endif // v8_inspector_protocol_Values_h
     284             : 
     285             : 
     286             : // Copyright 2016 The Chromium Authors. All rights reserved.
     287             : // Use of this source code is governed by a BSD-style license that can be
     288             : // found in the LICENSE file.
     289             : 
     290             : #ifndef v8_inspector_protocol_Object_h
     291             : #define v8_inspector_protocol_Object_h
     292             : 
     293             : //#include "ErrorSupport.h"
     294             : //#include "Forward.h"
     295             : //#include "Values.h"
     296             : 
     297             : namespace v8_inspector {
     298             : namespace protocol {
     299             : 
     300             : class  Object {
     301             : public:
     302             :     static std::unique_ptr<Object> fromValue(protocol::Value*, ErrorSupport*);
     303             :     explicit Object(std::unique_ptr<protocol::DictionaryValue>);
     304             :     ~Object();
     305             : 
     306             :     std::unique_ptr<protocol::DictionaryValue> toValue() const;
     307             :     std::unique_ptr<Object> clone() const;
     308             : private:
     309             :     std::unique_ptr<protocol::DictionaryValue> m_object;
     310             : };
     311             : 
     312             : } // namespace v8_inspector
     313             : } // namespace protocol
     314             : 
     315             : #endif // !defined(v8_inspector_protocol_Object_h)
     316             : 
     317             : 
     318             : // Copyright 2016 The Chromium Authors. All rights reserved.
     319             : // Use of this source code is governed by a BSD-style license that can be
     320             : // found in the LICENSE file.
     321             : 
     322             : #ifndef v8_inspector_protocol_ValueConversions_h
     323             : #define v8_inspector_protocol_ValueConversions_h
     324             : 
     325             : //#include "ErrorSupport.h"
     326             : //#include "Forward.h"
     327             : //#include "Values.h"
     328             : 
     329             : namespace v8_inspector {
     330             : namespace protocol {
     331             : 
     332             : template<typename T>
     333             : struct ValueConversions {
     334           0 :     static std::unique_ptr<T> fromValue(protocol::Value* value, ErrorSupport* errors)
     335             :     {
     336        3275 :         return T::fromValue(value, errors);
     337             :     }
     338             : 
     339       12155 :     static std::unique_ptr<protocol::Value> toValue(T* value)
     340             :     {
     341     8290662 :         return value->toValue();
     342             :     }
     343             : 
     344         215 :     static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<T>& value)
     345             :     {
     346     6238766 :         return value->toValue();
     347             :     }
     348             : };
     349             : 
     350             : template<>
     351             : struct ValueConversions<bool> {
     352       81934 :     static bool fromValue(protocol::Value* value, ErrorSupport* errors)
     353             :     {
     354       81934 :         bool result = false;
     355       81934 :         bool success = value ? value->asBoolean(&result) : false;
     356       81934 :         if (!success)
     357           0 :             errors->addError("boolean value expected");
     358       81934 :         return result;
     359             :     }
     360             : 
     361             :     static std::unique_ptr<protocol::Value> toValue(bool value)
     362             :     {
     363    20300888 :         return FundamentalValue::create(value);
     364             :     }
     365             : };
     366             : 
     367             : template<>
     368             : struct ValueConversions<int> {
     369        5654 :     static int fromValue(protocol::Value* value, ErrorSupport* errors)
     370             :     {
     371        5654 :         int result = 0;
     372        5654 :         bool success = value ? value->asInteger(&result) : false;
     373        5654 :         if (!success)
     374           0 :             errors->addError("integer value expected");
     375        5654 :         return result;
     376             :     }
     377             : 
     378             :     static std::unique_ptr<protocol::Value> toValue(int value)
     379             :     {
     380     3444134 :         return FundamentalValue::create(value);
     381             :     }
     382             : };
     383             : 
     384             : template<>
     385             : struct ValueConversions<double> {
     386          30 :     static double fromValue(protocol::Value* value, ErrorSupport* errors)
     387             :     {
     388          30 :         double result = 0;
     389          30 :         bool success = value ? value->asDouble(&result) : false;
     390          30 :         if (!success)
     391           0 :             errors->addError("double value expected");
     392          30 :         return result;
     393             :     }
     394             : 
     395             :     static std::unique_ptr<protocol::Value> toValue(double value)
     396             :     {
     397       14020 :         return FundamentalValue::create(value);
     398             :     }
     399             : };
     400             : 
     401             : template<>
     402             : struct ValueConversions<String> {
     403      127461 :     static String fromValue(protocol::Value* value, ErrorSupport* errors)
     404             :     {
     405      127461 :         String result;
     406      127461 :         bool success = value ? value->asString(&result) : false;
     407      127461 :         if (!success)
     408          23 :             errors->addError("string value expected");
     409      127461 :         return result;
     410             :     }
     411             : 
     412             :     static std::unique_ptr<protocol::Value> toValue(const String& value)
     413             :     {
     414    32383886 :         return StringValue::create(value);
     415             :     }
     416             : };
     417             : 
     418             : template<>
     419             : struct ValueConversions<Binary> {
     420             :     static Binary fromValue(protocol::Value* value, ErrorSupport* errors)
     421             :     {
     422             :         String result;
     423             :         bool success = value ? value->asString(&result) : false;
     424             :         if (!success) {
     425             :             errors->addError("string value expected");
     426             :             return Binary();
     427             :         }
     428             :         Binary out = Binary::fromBase64(result, &success);
     429             :         if (!success)
     430             :           errors->addError("base64 decoding error");
     431             :         return out;
     432             :     }
     433             : 
     434             :     static std::unique_ptr<protocol::Value> toValue(const Binary& value)
     435             :     {
     436             :         return StringValue::create(value.toBase64());
     437             :     }
     438             : };
     439             : 
     440             : template<>
     441             : struct ValueConversions<Value> {
     442         271 :     static std::unique_ptr<Value> fromValue(protocol::Value* value, ErrorSupport* errors)
     443             :     {
     444             :         bool success = !!value;
     445         271 :         if (!success) {
     446           0 :             errors->addError("value expected");
     447             :             return nullptr;
     448             :         }
     449         271 :         return value->clone();
     450             :     }
     451             : 
     452             :     static std::unique_ptr<protocol::Value> toValue(Value* value)
     453             :     {
     454      227905 :         return value->clone();
     455             :     }
     456             : 
     457             :     static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<Value>& value)
     458             :     {
     459             :         return value->clone();
     460             :     }
     461             : };
     462             : 
     463             : template<>
     464             : struct ValueConversions<DictionaryValue> {
     465           0 :     static std::unique_ptr<DictionaryValue> fromValue(protocol::Value* value, ErrorSupport* errors)
     466             :     {
     467           0 :         bool success = value && value->type() == protocol::Value::TypeObject;
     468           0 :         if (!success)
     469           0 :             errors->addError("object expected");
     470           0 :         return DictionaryValue::cast(value->clone());
     471             :     }
     472             : 
     473             :     static std::unique_ptr<protocol::Value> toValue(DictionaryValue* value)
     474             :     {
     475        2032 :         return value->clone();
     476             :     }
     477             : 
     478             :     static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<DictionaryValue>& value)
     479             :     {
     480             :         return value->clone();
     481             :     }
     482             : };
     483             : 
     484             : template<>
     485             : struct ValueConversions<ListValue> {
     486             :     static std::unique_ptr<ListValue> fromValue(protocol::Value* value, ErrorSupport* errors)
     487             :     {
     488             :         bool success = value && value->type() == protocol::Value::TypeArray;
     489             :         if (!success)
     490             :             errors->addError("list expected");
     491             :         return ListValue::cast(value->clone());
     492             :     }
     493             : 
     494             :     static std::unique_ptr<protocol::Value> toValue(ListValue* value)
     495             :     {
     496             :         return value->clone();
     497             :     }
     498             : 
     499             :     static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<ListValue>& value)
     500             :     {
     501             :         return value->clone();
     502             :     }
     503             : };
     504             : 
     505             : } // namespace v8_inspector
     506             : } // namespace protocol
     507             : 
     508             : #endif // !defined(v8_inspector_protocol_ValueConversions_h)
     509             : 
     510             : 
     511             : // Copyright 2016 The Chromium Authors. All rights reserved.
     512             : // Use of this source code is governed by a BSD-style license that can be
     513             : // found in the LICENSE file.
     514             : 
     515             : #ifndef v8_inspector_protocol_Maybe_h
     516             : #define v8_inspector_protocol_Maybe_h
     517             : 
     518             : // This macro allows to test for the version of the GNU C++ compiler.
     519             : // Note that this also applies to compilers that masquerade as GCC,
     520             : // for example clang and the Intel C++ compiler for Linux.
     521             : // Use like:
     522             : //  #if IP_GNUC_PREREQ(4, 3, 1)
     523             : //   ...
     524             : //  #endif
     525             : #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
     526             : #define IP_GNUC_PREREQ(major, minor, patchlevel)                      \
     527             :   ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \
     528             :    ((major)*10000 + (minor)*100 + (patchlevel)))
     529             : #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
     530             : #define IP_GNUC_PREREQ(major, minor, patchlevel) \
     531             :   ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >=  \
     532             :    ((major)*10000 + (minor)*100 + (patchlevel)))
     533             : #else
     534             : #define IP_GNUC_PREREQ(major, minor, patchlevel) 0
     535             : #endif
     536             : 
     537             : #if defined(__mips64)
     538             : #define IP_TARGET_ARCH_MIPS64 1
     539             : #elif defined(__MIPSEB__) || defined(__MIPSEL__)
     540             : #define IP_TARGET_ARCH_MIPS 1
     541             : #endif
     542             : 
     543             : // Allowing the use of noexcept by removing the keyword on older compilers that
     544             : // do not support adding noexcept to default members.
     545             : #if ((IP_GNUC_PREREQ(4, 9, 0) && !defined(IP_TARGET_ARCH_MIPS) && \
     546             :       !defined(IP_TARGET_ARCH_MIPS64)) ||                         \
     547             :      (defined(__clang__) && __cplusplus > 201300L))
     548             : #define IP_NOEXCEPT noexcept
     549             : #else
     550             : #define IP_NOEXCEPT
     551             : #endif
     552             : 
     553             : //#include "Forward.h"
     554             : 
     555             : namespace v8_inspector {
     556             : namespace protocol {
     557             : 
     558             : template<typename T>
     559             : class Maybe {
     560             : public:
     561             :     Maybe() : m_value() { }
     562             :     Maybe(std::unique_ptr<T> value) : m_value(std::move(value)) { }
     563             :     Maybe(Maybe&& other) IP_NOEXCEPT : m_value(std::move(other.m_value)) {}
     564             :     void operator=(std::unique_ptr<T> value) { m_value = std::move(value); }
     565             :     T* fromJust() const { DCHECK(m_value); return m_value.get(); }
     566             :     T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defaultValue; }
     567             :     bool isJust() const { return !!m_value; }
     568             :     std::unique_ptr<T> takeJust() { DCHECK(m_value); return std::move(m_value); }
     569             : private:
     570             :     std::unique_ptr<T> m_value;
     571             : };
     572             : 
     573             : template<typename T>
     574             : class MaybeBase {
     575             : public:
     576    12336583 :     MaybeBase() : m_isJust(false) { }
     577      297019 :     MaybeBase(T value) : m_isJust(true), m_value(value) { }
     578             :     MaybeBase(MaybeBase&& other) IP_NOEXCEPT
     579             :         : m_isJust(other.m_isJust),
     580      205340 :           m_value(std::move(other.m_value)) {}
     581    14586492 :     void operator=(T value) { m_value = value; m_isJust = true; }
     582     8675415 :     T fromJust() const { DCHECK(m_isJust); return m_value; }
     583      452102 :     T fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defaultValue; }
     584             :     bool isJust() const { return m_isJust; }
     585       60573 :     T takeJust() { DCHECK(m_isJust); return m_value; }
     586             : 
     587             : protected:
     588             :     bool m_isJust;
     589             :     T m_value;
     590             : };
     591             : 
     592             : template<>
     593             : class Maybe<bool> : public MaybeBase<bool> {
     594             : public:
     595             :     Maybe() { }
     596             :     Maybe(bool value) : MaybeBase(value) { }
     597             :     Maybe(Maybe&& other) IP_NOEXCEPT : MaybeBase(std::move(other)) {}
     598             :     using MaybeBase::operator=;
     599             : };
     600             : 
     601             : template<>
     602             : class Maybe<int> : public MaybeBase<int> {
     603             : public:
     604             :     Maybe() { }
     605             :     Maybe(int value) : MaybeBase(value) { }
     606             :     Maybe(Maybe&& other) IP_NOEXCEPT : MaybeBase(std::move(other)) {}
     607             :     using MaybeBase::operator=;
     608             : };
     609             : 
     610             : template<>
     611             : class Maybe<double> : public MaybeBase<double> {
     612             : public:
     613             :     Maybe() { }
     614             :     Maybe(double value) : MaybeBase(value) { }
     615             :     Maybe(Maybe&& other) IP_NOEXCEPT : MaybeBase(std::move(other)) {}
     616             :     using MaybeBase::operator=;
     617             : };
     618             : 
     619             : template<>
     620             : class Maybe<String> : public MaybeBase<String> {
     621             : public:
     622             :     Maybe() { }
     623      121006 :     Maybe(const String& value) : MaybeBase(value) { }
     624             :     Maybe(Maybe&& other) IP_NOEXCEPT : MaybeBase(std::move(other)) {}
     625             :     using MaybeBase::operator=;
     626             : };
     627             : 
     628             : template<>
     629             : class Maybe<Binary> : public MaybeBase<Binary> {
     630             : public:
     631             :     Maybe() { }
     632             :     Maybe(Binary value) : MaybeBase(value) { }
     633             :     Maybe(Maybe&& other) IP_NOEXCEPT : MaybeBase(std::move(other)) {}
     634             :     using MaybeBase::operator=;
     635             : };
     636             : 
     637             : } // namespace v8_inspector
     638             : } // namespace protocol
     639             : 
     640             : #undef IP_GNUC_PREREQ
     641             : #undef IP_TARGET_ARCH_MIPS64
     642             : #undef IP_TARGET_ARCH_MIPS
     643             : #undef IP_NOEXCEPT
     644             : 
     645             : #endif // !defined(v8_inspector_protocol_Maybe_h)
     646             : 
     647             : 
     648             : // Copyright 2016 The Chromium Authors. All rights reserved.
     649             : // Use of this source code is governed by a BSD-style license that can be
     650             : // found in the LICENSE file.
     651             : 
     652             : #ifndef v8_inspector_protocol_Array_h
     653             : #define v8_inspector_protocol_Array_h
     654             : 
     655             : //#include "ErrorSupport.h"
     656             : //#include "Forward.h"
     657             : //#include "ValueConversions.h"
     658             : //#include "Values.h"
     659             : 
     660             : namespace v8_inspector {
     661             : namespace protocol {
     662             : 
     663             : template<typename T>
     664      420623 : class Array {
     665             : public:
     666             :     static std::unique_ptr<Array<T>> create()
     667             :     {
     668      420443 :         return std::unique_ptr<Array<T>>(new Array<T>());
     669             :     }
     670             : 
     671         180 :     static std::unique_ptr<Array<T>> fromValue(protocol::Value* value, ErrorSupport* errors)
     672             :     {
     673             :         protocol::ListValue* array = ListValue::cast(value);
     674         180 :         if (!array) {
     675           0 :             errors->addError("array expected");
     676             :             return nullptr;
     677             :         }
     678         180 :         std::unique_ptr<Array<T>> result(new Array<T>());
     679         180 :         errors->push();
     680         830 :         for (size_t i = 0; i < array->size(); ++i) {
     681         470 :             errors->setName(StringUtil::fromInteger(i));
     682         235 :             std::unique_ptr<T> item = ValueConversions<T>::fromValue(array->at(i), errors);
     683         235 :             result->m_vector.push_back(std::move(item));
     684             :         }
     685         180 :         errors->pop();
     686         180 :         if (errors->hasErrors())
     687             :             return nullptr;
     688             :         return result;
     689             :     }
     690             : 
     691             :     void addItem(std::unique_ptr<T> value)
     692             :     {
     693     3119413 :         m_vector.push_back(std::move(value));
     694             :     }
     695             : 
     696             :     size_t length()
     697             :     {
     698       68772 :         return m_vector.size();
     699             :     }
     700             : 
     701             :     T* get(size_t index)
     702             :     {
     703         140 :         return m_vector[index].get();
     704             :     }
     705             : 
     706      352418 :     std::unique_ptr<protocol::ListValue> toValue()
     707             :     {
     708      352418 :         std::unique_ptr<protocol::ListValue> result = ListValue::create();
     709     3824219 :         for (auto& item : m_vector)
     710     6238981 :             result->pushValue(ValueConversions<T>::toValue(item));
     711      352418 :         return result;
     712             :     }
     713             : 
     714             : private:
     715             :     std::vector<std::unique_ptr<T>> m_vector;
     716             : };
     717             : 
     718             : template<typename T>
     719       55694 : class ArrayBase {
     720             : public:
     721             :     static std::unique_ptr<Array<T>> create()
     722             :     {
     723       55734 :         return std::unique_ptr<Array<T>>(new Array<T>());
     724             :     }
     725             : 
     726         105 :     static std::unique_ptr<Array<T>> fromValue(protocol::Value* value, ErrorSupport* errors)
     727             :     {
     728             :         protocol::ListValue* array = ListValue::cast(value);
     729         105 :         if (!array) {
     730           0 :             errors->addError("array expected");
     731             :             return nullptr;
     732             :         }
     733         105 :         errors->push();
     734         105 :         std::unique_ptr<Array<T>> result(new Array<T>());
     735         430 :         for (size_t i = 0; i < array->size(); ++i) {
     736         220 :             errors->setName(StringUtil::fromInteger(i));
     737         110 :             T item = ValueConversions<T>::fromValue(array->at(i), errors);
     738         110 :             result->m_vector.push_back(item);
     739             :         }
     740         105 :         errors->pop();
     741         105 :         if (errors->hasErrors())
     742             :             return nullptr;
     743             :         return result;
     744             :     }
     745             : 
     746             :     void addItem(const T& value)
     747             :     {
     748        2775 :         m_vector.push_back(value);
     749             :     }
     750             : 
     751             :     size_t length()
     752             :     {
     753         215 :         return m_vector.size();
     754             :     }
     755             : 
     756             :     T get(size_t index)
     757             :     {
     758         110 :         return m_vector[index];
     759             :     }
     760             : 
     761       55734 :     std::unique_ptr<protocol::ListValue> toValue()
     762             :     {
     763       55734 :         std::unique_ptr<protocol::ListValue> result = ListValue::create();
     764      114243 :         for (auto& item : m_vector)
     765        5700 :             result->pushValue(ValueConversions<T>::toValue(item));
     766       55734 :         return result;
     767             :     }
     768             : 
     769             : private:
     770             :     std::vector<T> m_vector;
     771             : };
     772             : 
     773             : template<> class Array<String> : public ArrayBase<String> {};
     774             : template<> class Array<int> : public ArrayBase<int> {};
     775             : template<> class Array<double> : public ArrayBase<double> {};
     776             : template<> class Array<bool> : public ArrayBase<bool> {};
     777             : 
     778             : } // namespace v8_inspector
     779             : } // namespace protocol
     780             : 
     781             : #endif // !defined(v8_inspector_protocol_Array_h)
     782             : 
     783             : 
     784             : // Copyright 2016 The Chromium Authors. All rights reserved.
     785             : // Use of this source code is governed by a BSD-style license that can be
     786             : // found in the LICENSE file.
     787             : 
     788             : #ifndef v8_inspector_protocol_DispatcherBase_h
     789             : #define v8_inspector_protocol_DispatcherBase_h
     790             : 
     791             : //#include "Forward.h"
     792             : //#include "ErrorSupport.h"
     793             : //#include "Values.h"
     794             : 
     795             : namespace v8_inspector {
     796             : namespace protocol {
     797             : 
     798             : class WeakPtr;
     799             : 
     800    19011592 : class  DispatchResponse {
     801             : public:
     802             :     enum Status {
     803             :         kSuccess = 0,
     804             :         kError = 1,
     805             :         kFallThrough = 2,
     806             :     };
     807             : 
     808             :     enum ErrorCode {
     809             :         kParseError = -32700,
     810             :         kInvalidRequest = -32600,
     811             :         kMethodNotFound = -32601,
     812             :         kInvalidParams = -32602,
     813             :         kInternalError = -32603,
     814             :         kServerError = -32000,
     815             :     };
     816             : 
     817             :     Status status() const { return m_status; }
     818             :     const String& errorMessage() const { return m_errorMessage; }
     819             :     ErrorCode errorCode() const { return m_errorCode; }
     820             :     bool isSuccess() const { return m_status == kSuccess; }
     821             : 
     822             :     static DispatchResponse OK();
     823             :     static DispatchResponse Error(const String&);
     824             :     static DispatchResponse InternalError();
     825             :     static DispatchResponse InvalidParams(const String&);
     826             :     static DispatchResponse FallThrough();
     827             : 
     828             : private:
     829             :     Status m_status;
     830             :     String m_errorMessage;
     831             :     ErrorCode m_errorCode;
     832             : };
     833             : 
     834             : class  DispatcherBase {
     835             :     PROTOCOL_DISALLOW_COPY(DispatcherBase);
     836             : public:
     837             :     static const char kInvalidParamsString[];
     838             :     class  WeakPtr {
     839             :     public:
     840             :         explicit WeakPtr(DispatcherBase*);
     841             :         ~WeakPtr();
     842      281114 :         DispatcherBase* get() { return m_dispatcher; }
     843          10 :         void dispose() { m_dispatcher = nullptr; }
     844             : 
     845             :     private:
     846             :         DispatcherBase* m_dispatcher;
     847             :     };
     848             : 
     849       19216 :     class  Callback {
     850             :     public:
     851             :         Callback(std::unique_ptr<WeakPtr> backendImpl, int callId, const String& method, const String& message);
     852             :         virtual ~Callback();
     853             :         void dispose();
     854             : 
     855             :     protected:
     856             :         void sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage, const DispatchResponse& response);
     857             :         void fallThroughIfActive();
     858             : 
     859             :     private:
     860             :         std::unique_ptr<WeakPtr> m_backendImpl;
     861             :         int m_callId;
     862             :         String m_method;
     863             :         String m_message;
     864             :     };
     865             : 
     866             :     explicit DispatcherBase(FrontendChannel*);
     867             :     virtual ~DispatcherBase();
     868             : 
     869             :     virtual bool canDispatch(const String& method) = 0;
     870             :     virtual void dispatch(int callId, const String& method, const String& rawMessage, std::unique_ptr<protocol::DictionaryValue> messageObject) = 0;
     871             :     FrontendChannel* channel() { return m_frontendChannel; }
     872             : 
     873             :     void sendResponse(int callId, const DispatchResponse&, std::unique_ptr<protocol::DictionaryValue> result);
     874             :     void sendResponse(int callId, const DispatchResponse&);
     875             : 
     876             :     void reportProtocolError(int callId, DispatchResponse::ErrorCode, const String& errorMessage, ErrorSupport* errors);
     877             :     void clearFrontend();
     878             : 
     879             :     std::unique_ptr<WeakPtr> weakPtr();
     880             : 
     881             : private:
     882             :     FrontendChannel* m_frontendChannel;
     883             :     std::unordered_set<WeakPtr*> m_weakPtrs;
     884             : };
     885             : 
     886        7668 : class  UberDispatcher {
     887             :     PROTOCOL_DISALLOW_COPY(UberDispatcher);
     888             : public:
     889             :     explicit UberDispatcher(FrontendChannel*);
     890             :     void registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase>);
     891             :     void setupRedirects(const std::unordered_map<String, String>&);
     892             :     bool parseCommand(Value* message, int* callId, String* method);
     893             :     bool canDispatch(const String& method);
     894             :     void dispatch(int callId, const String& method, std::unique_ptr<Value> message, const String& rawMessage);
     895             :     FrontendChannel* channel() { return m_frontendChannel; }
     896             :     virtual ~UberDispatcher();
     897             : 
     898             : private:
     899             :     protocol::DispatcherBase* findDispatcher(const String& method);
     900             :     FrontendChannel* m_frontendChannel;
     901             :     std::unordered_map<String, String> m_redirects;
     902             :     std::unordered_map<String, std::unique_ptr<protocol::DispatcherBase>> m_dispatchers;
     903             : };
     904             : 
     905             : class InternalResponse : public Serializable {
     906             :     PROTOCOL_DISALLOW_COPY(InternalResponse);
     907             : public:
     908             :     static std::unique_ptr<InternalResponse> createResponse(int callId, std::unique_ptr<Serializable> params);
     909             :     static std::unique_ptr<InternalResponse> createNotification(const String& notification, std::unique_ptr<Serializable> params = nullptr);
     910             : 
     911             :     String serialize() override;
     912             : 
     913     1042521 :     ~InternalResponse() override {}
     914             : 
     915             : private:
     916             :     InternalResponse(int callId, const String& notification, std::unique_ptr<Serializable> params);
     917             : 
     918             :     int m_callId;
     919             :     String m_notification;
     920             :     std::unique_ptr<Serializable> m_params;
     921             : };
     922             : 
     923             : class InternalRawNotification : public Serializable {
     924             : public:
     925           0 :     static std::unique_ptr<InternalRawNotification> create(const String& notification)
     926             :     {
     927           0 :         return std::unique_ptr<InternalRawNotification>(new InternalRawNotification(notification));
     928             :     }
     929           0 :     ~InternalRawNotification() override {}
     930             : 
     931           0 :     String serialize() override
     932             :     {
     933           0 :         return m_notification;
     934             :     }
     935             : 
     936             : private:
     937             :   explicit InternalRawNotification(const String& notification)
     938           0 :     : m_notification(notification)
     939             :   {
     940             :   }
     941             : 
     942             :   String m_notification;
     943             : };
     944             : 
     945             : } // namespace v8_inspector
     946             : } // namespace protocol
     947             : 
     948             : #endif // !defined(v8_inspector_protocol_DispatcherBase_h)
     949             : 
     950             : 
     951             : // Copyright 2016 The Chromium Authors. All rights reserved.
     952             : // Use of this source code is governed by a BSD-style license that can be
     953             : // found in the LICENSE file.
     954             : 
     955             : #ifndef v8_inspector_protocol_Parser_h
     956             : #define v8_inspector_protocol_Parser_h
     957             : 
     958             : //#include "Forward.h"
     959             : //#include "Values.h"
     960             : 
     961             : namespace v8_inspector {
     962             : namespace protocol {
     963             : 
     964             :  std::unique_ptr<Value> parseJSONCharacters(const uint8_t*, unsigned);
     965             :  std::unique_ptr<Value> parseJSONCharacters(const uint16_t*, unsigned);
     966             : 
     967             : } // namespace v8_inspector
     968             : } // namespace protocol
     969             : 
     970             : #endif // !defined(v8_inspector_protocol_Parser_h)

Generated by: LCOV version 1.10