eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Google Inc. All rights reserved. |
burg@cs.washington.edu | ba2d103 | 2014-09-30 03:30:54 +0000 | [diff] [blame] | 3 | * Copyright (C) 2014 University of Washington. All rights reserved. |
drousso@apple.com | b0d5aef | 2017-07-18 20:21:31 +0000 | [diff] [blame] | 4 | * Copyright (C) 2017 Apple Inc. All rights reserved. |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | */ |
| 32 | |
commit-queue@webkit.org | 35dd301 | 2016-08-15 20:55:16 +0000 | [diff] [blame] | 33 | #pragma once |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 34 | |
andersca@apple.com | 816a7d3 | 2015-07-15 21:29:34 +0000 | [diff] [blame] | 35 | #include "JSExportMacros.h" |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 36 | #include <wtf/Assertions.h> |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 37 | #include <wtf/HashMap.h> |
| 38 | #include <wtf/RefCounted.h> |
| 39 | #include <wtf/Vector.h> |
barraclough@apple.com | bbb3cd4 | 2010-08-10 17:45:41 +0000 | [diff] [blame] | 40 | #include <wtf/text/StringHash.h> |
weinig@apple.com | 3f5ab02 | 2012-09-06 17:36:48 +0000 | [diff] [blame] | 41 | #include <wtf/text/WTFString.h> |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 42 | |
joepeck@webkit.org | a319844 | 2013-12-11 22:40:23 +0000 | [diff] [blame] | 43 | namespace Inspector { |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 44 | |
eric@webkit.org | d82076b5 | 2010-06-07 11:33:11 +0000 | [diff] [blame] | 45 | class InspectorArray; |
burg@cs.washington.edu | b5d2afc | 2014-08-15 22:40:33 +0000 | [diff] [blame] | 46 | class InspectorArrayBase; |
eric@webkit.org | d82076b5 | 2010-06-07 11:33:11 +0000 | [diff] [blame] | 47 | class InspectorObject; |
burg@cs.washington.edu | b5d2afc | 2014-08-15 22:40:33 +0000 | [diff] [blame] | 48 | class InspectorObjectBase; |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 49 | |
joepeck@webkit.org | a319844 | 2013-12-11 22:40:23 +0000 | [diff] [blame] | 50 | class JS_EXPORT_PRIVATE InspectorValue : public RefCounted<InspectorValue> { |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 51 | public: |
yurys@chromium.org | 78119ca | 2011-08-05 09:37:02 +0000 | [diff] [blame] | 52 | static const int maxDepth = 1000; |
| 53 | |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 54 | virtual ~InspectorValue() |
| 55 | { |
| 56 | switch (m_type) { |
| 57 | case Type::Null: |
| 58 | case Type::Boolean: |
| 59 | case Type::Double: |
| 60 | case Type::Integer: |
| 61 | break; |
| 62 | case Type::String: |
| 63 | if (m_value.string) |
| 64 | m_value.string->deref(); |
| 65 | break; |
| 66 | case Type::Object: |
| 67 | case Type::Array: |
| 68 | break; |
| 69 | } |
| 70 | } |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 71 | |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 72 | static Ref<InspectorValue> null(); |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 73 | static Ref<InspectorValue> create(bool); |
| 74 | static Ref<InspectorValue> create(int); |
| 75 | static Ref<InspectorValue> create(double); |
| 76 | static Ref<InspectorValue> create(const String&); |
| 77 | static Ref<InspectorValue> create(const char*); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 78 | |
burg@cs.washington.edu | b5d2afc | 2014-08-15 22:40:33 +0000 | [diff] [blame] | 79 | enum class Type { |
| 80 | Null = 0, |
| 81 | Boolean, |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 82 | Double, |
| 83 | Integer, |
burg@cs.washington.edu | b5d2afc | 2014-08-15 22:40:33 +0000 | [diff] [blame] | 84 | String, |
| 85 | Object, |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 86 | Array, |
burg@cs.washington.edu | b5d2afc | 2014-08-15 22:40:33 +0000 | [diff] [blame] | 87 | }; |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 88 | |
| 89 | Type type() const { return m_type; } |
burg@cs.washington.edu | b5d2afc | 2014-08-15 22:40:33 +0000 | [diff] [blame] | 90 | bool isNull() const { return m_type == Type::Null; } |
commit-queue@webkit.org | c990326 | 2010-09-03 14:01:33 +0000 | [diff] [blame] | 91 | |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 92 | bool asBoolean(bool&) const; |
| 93 | bool asInteger(int&) const; |
| 94 | bool asInteger(unsigned&) const; |
| 95 | bool asInteger(long&) const; |
| 96 | bool asInteger(long long&) const; |
| 97 | bool asInteger(unsigned long&) const; |
| 98 | bool asInteger(unsigned long long&) const; |
| 99 | bool asDouble(double&) const; |
| 100 | bool asDouble(float&) const; |
| 101 | bool asString(String&) const; |
| 102 | bool asValue(RefPtr<InspectorValue>&); |
| 103 | |
burg@cs.washington.edu | ba2d103 | 2014-09-30 03:30:54 +0000 | [diff] [blame] | 104 | virtual bool asObject(RefPtr<InspectorObject>&); |
| 105 | virtual bool asArray(RefPtr<InspectorArray>&); |
eric@webkit.org | d82076b5 | 2010-06-07 11:33:11 +0000 | [diff] [blame] | 106 | |
burg@cs.washington.edu | ba2d103 | 2014-09-30 03:30:54 +0000 | [diff] [blame] | 107 | static bool parseJSON(const String& jsonInput, RefPtr<InspectorValue>& output); |
eric@webkit.org | d82076b5 | 2010-06-07 11:33:11 +0000 | [diff] [blame] | 108 | |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 109 | String toJSONString() const; |
burg@cs.washington.edu | ba2d103 | 2014-09-30 03:30:54 +0000 | [diff] [blame] | 110 | virtual void writeJSON(StringBuilder& output) const; |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 111 | |
drousso@apple.com | b0d5aef | 2017-07-18 20:21:31 +0000 | [diff] [blame] | 112 | virtual size_t memoryCost() const; |
| 113 | |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 114 | protected: |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 115 | InspectorValue() |
| 116 | : m_type(Type::Null) { } |
| 117 | |
| 118 | explicit InspectorValue(Type type) |
| 119 | : m_type(type) { } |
| 120 | |
| 121 | explicit InspectorValue(bool value) |
| 122 | : m_type(Type::Boolean) |
| 123 | { |
| 124 | m_value.boolean = value; |
| 125 | } |
| 126 | |
| 127 | explicit InspectorValue(int value) |
| 128 | : m_type(Type::Integer) |
| 129 | { |
| 130 | m_value.number = static_cast<double>(value); |
| 131 | } |
| 132 | |
| 133 | explicit InspectorValue(double value) |
| 134 | : m_type(Type::Double) |
| 135 | { |
| 136 | m_value.number = value; |
| 137 | } |
| 138 | |
| 139 | explicit InspectorValue(const String& value) |
| 140 | : m_type(Type::String) |
| 141 | { |
| 142 | m_value.string = value.impl(); |
| 143 | if (m_value.string) |
| 144 | m_value.string->ref(); |
| 145 | } |
| 146 | |
| 147 | explicit InspectorValue(const char* value) |
| 148 | : m_type(Type::String) |
| 149 | { |
| 150 | String wrapper(value); |
| 151 | m_value.string = wrapper.impl(); |
| 152 | if (m_value.string) |
| 153 | m_value.string->ref(); |
| 154 | } |
bburg@apple.com | 371eaff | 2016-04-08 19:59:25 +0000 | [diff] [blame] | 155 | |
| 156 | private: |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 157 | Type m_type { Type::Null }; |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 158 | union { |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 159 | bool boolean; |
| 160 | double number; |
| 161 | StringImpl* string; |
| 162 | } m_value; |
commit-queue@webkit.org | 70beb71 | 2016-04-09 20:54:57 +0000 | [diff] [blame] | 163 | }; |
| 164 | |
joepeck@webkit.org | a319844 | 2013-12-11 22:40:23 +0000 | [diff] [blame] | 165 | class JS_EXPORT_PRIVATE InspectorObjectBase : public InspectorValue { |
eric@webkit.org | d82076b5 | 2010-06-07 11:33:11 +0000 | [diff] [blame] | 166 | private: |
andersca@apple.com | c3523f8 | 2013-10-18 23:41:24 +0000 | [diff] [blame] | 167 | typedef HashMap<String, RefPtr<InspectorValue>> Dictionary; |
eric@webkit.org | d82076b5 | 2010-06-07 11:33:11 +0000 | [diff] [blame] | 168 | |
| 169 | public: |
| 170 | typedef Dictionary::iterator iterator; |
| 171 | typedef Dictionary::const_iterator const_iterator; |
| 172 | |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 173 | InspectorObject* openAccessors(); |
| 174 | |
drousso@apple.com | b0d5aef | 2017-07-18 20:21:31 +0000 | [diff] [blame] | 175 | size_t memoryCost() const final; |
| 176 | |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 177 | protected: |
andersca@apple.com | 70c6058 | 2013-10-07 16:26:16 +0000 | [diff] [blame] | 178 | virtual ~InspectorObjectBase(); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 179 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 180 | bool asObject(RefPtr<InspectorObject>& output) override; |
eric@webkit.org | d82076b5 | 2010-06-07 11:33:11 +0000 | [diff] [blame] | 181 | |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 182 | // FIXME: use templates to reduce the amount of duplicated set*() methods. |
loislo@chromium.org | ec5ebeb | 2010-08-26 13:11:28 +0000 | [diff] [blame] | 183 | void setBoolean(const String& name, bool); |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 184 | void setInteger(const String& name, int); |
| 185 | void setDouble(const String& name, double); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 186 | void setString(const String& name, const String&); |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 187 | void setValue(const String& name, RefPtr<InspectorValue>&&); |
| 188 | void setObject(const String& name, RefPtr<InspectorObjectBase>&&); |
| 189 | void setArray(const String& name, RefPtr<InspectorArrayBase>&&); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 190 | |
podivilov@chromium.org | ba4a88c | 2011-02-03 15:24:41 +0000 | [diff] [blame] | 191 | iterator find(const String& name); |
loislo@chromium.org | 12044a8 | 2010-08-23 14:07:09 +0000 | [diff] [blame] | 192 | const_iterator find(const String& name) const; |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 193 | |
| 194 | // FIXME: use templates to reduce the amount of duplicated get*() methods. |
burg@cs.washington.edu | ba2d103 | 2014-09-30 03:30:54 +0000 | [diff] [blame] | 195 | bool getBoolean(const String& name, bool& output) const; |
| 196 | template<class T> bool getDouble(const String& name, T& output) const |
podivilov@chromium.org | ba4a88c | 2011-02-03 15:24:41 +0000 | [diff] [blame] | 197 | { |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 198 | RefPtr<InspectorValue> value; |
| 199 | if (!getValue(name, value)) |
podivilov@chromium.org | ba4a88c | 2011-02-03 15:24:41 +0000 | [diff] [blame] | 200 | return false; |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 201 | |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 202 | return value->asDouble(output); |
podivilov@chromium.org | ba4a88c | 2011-02-03 15:24:41 +0000 | [diff] [blame] | 203 | } |
burg@cs.washington.edu | ba2d103 | 2014-09-30 03:30:54 +0000 | [diff] [blame] | 204 | template<class T> bool getInteger(const String& name, T& output) const |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 205 | { |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 206 | RefPtr<InspectorValue> value; |
| 207 | if (!getValue(name, value)) |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 208 | return false; |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 209 | |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 210 | return value->asInteger(output); |
| 211 | } |
| 212 | |
burg@cs.washington.edu | ba2d103 | 2014-09-30 03:30:54 +0000 | [diff] [blame] | 213 | bool getString(const String& name, String& output) const; |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 214 | bool getObject(const String& name, RefPtr<InspectorObject>&) const; |
| 215 | bool getArray(const String& name, RefPtr<InspectorArray>&) const; |
| 216 | bool getValue(const String& name, RefPtr<InspectorValue>&) const; |
eric@webkit.org | d82076b5 | 2010-06-07 11:33:11 +0000 | [diff] [blame] | 217 | |
podivilov@chromium.org | ba4a88c | 2011-02-03 15:24:41 +0000 | [diff] [blame] | 218 | void remove(const String& name); |
| 219 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 220 | void writeJSON(StringBuilder& output) const override; |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 221 | |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 222 | iterator begin() { return m_map.begin(); } |
| 223 | iterator end() { return m_map.end(); } |
| 224 | const_iterator begin() const { return m_map.begin(); } |
| 225 | const_iterator end() const { return m_map.end(); } |
eric@webkit.org | d82076b5 | 2010-06-07 11:33:11 +0000 | [diff] [blame] | 226 | |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 227 | int size() const { return m_map.size(); } |
yurys@chromium.org | a13f46b | 2012-01-25 11:54:51 +0000 | [diff] [blame] | 228 | |
yurys@chromium.org | 26c4592 | 2011-12-09 08:33:02 +0000 | [diff] [blame] | 229 | protected: |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 230 | InspectorObjectBase(); |
yurys@chromium.org | 26c4592 | 2011-12-09 08:33:02 +0000 | [diff] [blame] | 231 | |
| 232 | private: |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 233 | Dictionary m_map; |
loislo@chromium.org | 4bfbcc1 | 2010-06-04 17:23:10 +0000 | [diff] [blame] | 234 | Vector<String> m_order; |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 235 | }; |
| 236 | |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 237 | class InspectorObject : public InspectorObjectBase { |
| 238 | public: |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 239 | static JS_EXPORT_PRIVATE Ref<InspectorObject> create(); |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 240 | |
| 241 | using InspectorObjectBase::asObject; |
| 242 | |
drousso@apple.com | b0d5aef | 2017-07-18 20:21:31 +0000 | [diff] [blame] | 243 | // This class expected non-cyclic values, as we cannot serialize cycles in JSON. |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 244 | using InspectorObjectBase::setBoolean; |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 245 | using InspectorObjectBase::setInteger; |
| 246 | using InspectorObjectBase::setDouble; |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 247 | using InspectorObjectBase::setString; |
| 248 | using InspectorObjectBase::setValue; |
| 249 | using InspectorObjectBase::setObject; |
| 250 | using InspectorObjectBase::setArray; |
| 251 | |
| 252 | using InspectorObjectBase::find; |
| 253 | using InspectorObjectBase::getBoolean; |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 254 | using InspectorObjectBase::getInteger; |
| 255 | using InspectorObjectBase::getDouble; |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 256 | using InspectorObjectBase::getString; |
| 257 | using InspectorObjectBase::getObject; |
| 258 | using InspectorObjectBase::getArray; |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 259 | using InspectorObjectBase::getValue; |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 260 | |
| 261 | using InspectorObjectBase::remove; |
| 262 | |
| 263 | using InspectorObjectBase::begin; |
| 264 | using InspectorObjectBase::end; |
| 265 | |
| 266 | using InspectorObjectBase::size; |
| 267 | }; |
| 268 | |
| 269 | |
joepeck@webkit.org | a319844 | 2013-12-11 22:40:23 +0000 | [diff] [blame] | 270 | class JS_EXPORT_PRIVATE InspectorArrayBase : public InspectorValue { |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 271 | public: |
andersca@apple.com | c3523f8 | 2013-10-18 23:41:24 +0000 | [diff] [blame] | 272 | typedef Vector<RefPtr<InspectorValue>>::iterator iterator; |
| 273 | typedef Vector<RefPtr<InspectorValue>>::const_iterator const_iterator; |
pfeldman@chromium.org | 2f44edb | 2011-11-29 14:43:10 +0000 | [diff] [blame] | 274 | |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 275 | unsigned length() const { return static_cast<unsigned>(m_map.size()); } |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 276 | |
drousso@apple.com | b9f22de | 2017-07-26 21:45:22 +0000 | [diff] [blame] | 277 | RefPtr<InspectorValue> get(size_t index) const; |
| 278 | |
drousso@apple.com | b0d5aef | 2017-07-18 20:21:31 +0000 | [diff] [blame] | 279 | size_t memoryCost() const final; |
| 280 | |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 281 | protected: |
andersca@apple.com | 70c6058 | 2013-10-07 16:26:16 +0000 | [diff] [blame] | 282 | virtual ~InspectorArrayBase(); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 283 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 284 | bool asArray(RefPtr<InspectorArray>&) override; |
eric@webkit.org | d82076b5 | 2010-06-07 11:33:11 +0000 | [diff] [blame] | 285 | |
loislo@chromium.org | ec5ebeb | 2010-08-26 13:11:28 +0000 | [diff] [blame] | 286 | void pushBoolean(bool); |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 287 | void pushInteger(int); |
| 288 | void pushDouble(double); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 289 | void pushString(const String&); |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 290 | void pushValue(RefPtr<InspectorValue>&&); |
| 291 | void pushObject(RefPtr<InspectorObjectBase>&&); |
| 292 | void pushArray(RefPtr<InspectorArrayBase>&&); |
loislo@chromium.org | 5248655 | 2010-07-16 17:16:56 +0000 | [diff] [blame] | 293 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 294 | void writeJSON(StringBuilder& output) const override; |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 295 | |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 296 | iterator begin() { return m_map.begin(); } |
| 297 | iterator end() { return m_map.end(); } |
| 298 | const_iterator begin() const { return m_map.begin(); } |
| 299 | const_iterator end() const { return m_map.end(); } |
pfeldman@chromium.org | 2f44edb | 2011-11-29 14:43:10 +0000 | [diff] [blame] | 300 | |
commit-queue@webkit.org | 2191c91 | 2012-01-16 13:44:14 +0000 | [diff] [blame] | 301 | protected: |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 302 | InspectorArrayBase(); |
commit-queue@webkit.org | 2191c91 | 2012-01-16 13:44:14 +0000 | [diff] [blame] | 303 | |
| 304 | private: |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 305 | Vector<RefPtr<InspectorValue>> m_map; |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 306 | }; |
| 307 | |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 308 | class InspectorArray : public InspectorArrayBase { |
| 309 | public: |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 310 | static JS_EXPORT_PRIVATE Ref<InspectorArray> create(); |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 311 | |
| 312 | using InspectorArrayBase::asArray; |
| 313 | |
drousso@apple.com | b0d5aef | 2017-07-18 20:21:31 +0000 | [diff] [blame] | 314 | // This class expected non-cyclic values, as we cannot serialize cycles in JSON. |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 315 | using InspectorArrayBase::pushBoolean; |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 316 | using InspectorArrayBase::pushInteger; |
| 317 | using InspectorArrayBase::pushDouble; |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 318 | using InspectorArrayBase::pushString; |
| 319 | using InspectorArrayBase::pushValue; |
| 320 | using InspectorArrayBase::pushObject; |
| 321 | using InspectorArrayBase::pushArray; |
| 322 | |
| 323 | using InspectorArrayBase::get; |
| 324 | |
| 325 | using InspectorArrayBase::begin; |
| 326 | using InspectorArrayBase::end; |
| 327 | }; |
| 328 | |
| 329 | |
| 330 | inline InspectorObjectBase::iterator InspectorObjectBase::find(const String& name) |
podivilov@chromium.org | ba4a88c | 2011-02-03 15:24:41 +0000 | [diff] [blame] | 331 | { |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 332 | return m_map.find(name); |
podivilov@chromium.org | ba4a88c | 2011-02-03 15:24:41 +0000 | [diff] [blame] | 333 | } |
| 334 | |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 335 | inline InspectorObjectBase::const_iterator InspectorObjectBase::find(const String& name) const |
loislo@chromium.org | 12044a8 | 2010-08-23 14:07:09 +0000 | [diff] [blame] | 336 | { |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 337 | return m_map.find(name); |
loislo@chromium.org | 12044a8 | 2010-08-23 14:07:09 +0000 | [diff] [blame] | 338 | } |
| 339 | |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 340 | inline void InspectorObjectBase::setBoolean(const String& name, bool value) |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 341 | { |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 342 | setValue(name, InspectorValue::create(value)); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 343 | } |
| 344 | |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 345 | inline void InspectorObjectBase::setInteger(const String& name, int value) |
| 346 | { |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 347 | setValue(name, InspectorValue::create(value)); |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | inline void InspectorObjectBase::setDouble(const String& name, double value) |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 351 | { |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 352 | setValue(name, InspectorValue::create(value)); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 353 | } |
| 354 | |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 355 | inline void InspectorObjectBase::setString(const String& name, const String& value) |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 356 | { |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 357 | setValue(name, InspectorValue::create(value)); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 358 | } |
| 359 | |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 360 | inline void InspectorObjectBase::setValue(const String& name, RefPtr<InspectorValue>&& value) |
pfeldman@chromium.org | 7fab097 | 2010-08-13 13:22:17 +0000 | [diff] [blame] | 361 | { |
pfeldman@chromium.org | 6537d93 | 2011-11-09 11:49:13 +0000 | [diff] [blame] | 362 | ASSERT(value); |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 363 | if (m_map.set(name, WTFMove(value)).isNewEntry) |
pfeldman@chromium.org | 7fab097 | 2010-08-13 13:22:17 +0000 | [diff] [blame] | 364 | m_order.append(name); |
| 365 | } |
| 366 | |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 367 | inline void InspectorObjectBase::setObject(const String& name, RefPtr<InspectorObjectBase>&& value) |
pfeldman@chromium.org | 7fab097 | 2010-08-13 13:22:17 +0000 | [diff] [blame] | 368 | { |
pfeldman@chromium.org | 6537d93 | 2011-11-09 11:49:13 +0000 | [diff] [blame] | 369 | ASSERT(value); |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 370 | if (m_map.set(name, WTFMove(value)).isNewEntry) |
pfeldman@chromium.org | 7fab097 | 2010-08-13 13:22:17 +0000 | [diff] [blame] | 371 | m_order.append(name); |
| 372 | } |
| 373 | |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 374 | inline void InspectorObjectBase::setArray(const String& name, RefPtr<InspectorArrayBase>&& value) |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 375 | { |
pfeldman@chromium.org | 6537d93 | 2011-11-09 11:49:13 +0000 | [diff] [blame] | 376 | ASSERT(value); |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 377 | if (m_map.set(name, WTFMove(value)).isNewEntry) |
loislo@chromium.org | 4bfbcc1 | 2010-06-04 17:23:10 +0000 | [diff] [blame] | 378 | m_order.append(name); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 379 | } |
| 380 | |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 381 | inline void InspectorArrayBase::pushBoolean(bool value) |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 382 | { |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 383 | m_map.append(InspectorValue::create(value)); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 384 | } |
| 385 | |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 386 | inline void InspectorArrayBase::pushInteger(int value) |
vsevik@chromium.org | 7386112 | 2012-03-28 19:44:57 +0000 | [diff] [blame] | 387 | { |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 388 | m_map.append(InspectorValue::create(value)); |
vsevik@chromium.org | 7386112 | 2012-03-28 19:44:57 +0000 | [diff] [blame] | 389 | } |
| 390 | |
burg@cs.washington.edu | 68ca4db | 2014-09-12 04:53:35 +0000 | [diff] [blame] | 391 | inline void InspectorArrayBase::pushDouble(double value) |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 392 | { |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 393 | m_map.append(InspectorValue::create(value)); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 394 | } |
| 395 | |
commit-queue@webkit.org | 118a87a | 2012-04-10 22:39:39 +0000 | [diff] [blame] | 396 | inline void InspectorArrayBase::pushString(const String& value) |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 397 | { |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 398 | m_map.append(InspectorValue::create(value)); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 399 | } |
| 400 | |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 401 | inline void InspectorArrayBase::pushValue(RefPtr<InspectorValue>&& value) |
pfeldman@chromium.org | 7fab097 | 2010-08-13 13:22:17 +0000 | [diff] [blame] | 402 | { |
pfeldman@chromium.org | 6537d93 | 2011-11-09 11:49:13 +0000 | [diff] [blame] | 403 | ASSERT(value); |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 404 | m_map.append(WTFMove(value)); |
pfeldman@chromium.org | 7fab097 | 2010-08-13 13:22:17 +0000 | [diff] [blame] | 405 | } |
| 406 | |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 407 | inline void InspectorArrayBase::pushObject(RefPtr<InspectorObjectBase>&& value) |
pfeldman@chromium.org | 7fab097 | 2010-08-13 13:22:17 +0000 | [diff] [blame] | 408 | { |
pfeldman@chromium.org | 6537d93 | 2011-11-09 11:49:13 +0000 | [diff] [blame] | 409 | ASSERT(value); |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 410 | m_map.append(WTFMove(value)); |
pfeldman@chromium.org | 7fab097 | 2010-08-13 13:22:17 +0000 | [diff] [blame] | 411 | } |
| 412 | |
joepeck@webkit.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 413 | inline void InspectorArrayBase::pushArray(RefPtr<InspectorArrayBase>&& value) |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 414 | { |
pfeldman@chromium.org | 6537d93 | 2011-11-09 11:49:13 +0000 | [diff] [blame] | 415 | ASSERT(value); |
bburg@apple.com | 3e2abaa | 2016-04-11 23:22:16 +0000 | [diff] [blame] | 416 | m_map.append(WTFMove(value)); |
eric@webkit.org | 43974b6 | 2010-05-31 22:28:30 +0000 | [diff] [blame] | 417 | } |
| 418 | |
joepeck@webkit.org | a319844 | 2013-12-11 22:40:23 +0000 | [diff] [blame] | 419 | } // namespace Inspector |