| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/inspector_protocol/Values.h" | 5 #include "platform/inspector_protocol/Values.h" |
| 6 | 6 |
| 7 #include "platform/Decimal.h" | 7 #include "platform/Decimal.h" |
| 8 #include "platform/inspector_protocol/Parser.h" | 8 #include "platform/inspector_protocol/Parser.h" |
| 9 #include "wtf/text/StringBuilder.h" | 9 #include "wtf/text/StringBuilder.h" |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 179 } |
| 180 | 180 |
| 181 void DictionaryValue::setString(const String& name, const String& value) | 181 void DictionaryValue::setString(const String& name, const String& value) |
| 182 { | 182 { |
| 183 setValue(name, StringValue::create(value)); | 183 setValue(name, StringValue::create(value)); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void DictionaryValue::setValue(const String& name, PassOwnPtr<Value> value) | 186 void DictionaryValue::setValue(const String& name, PassOwnPtr<Value> value) |
| 187 { | 187 { |
| 188 ASSERT(value); | 188 ASSERT(value); |
| 189 if (m_data.set(name, value).isNewEntry) | 189 if (m_data.set(name, value)) |
| 190 m_order.append(name); | 190 m_order.append(name); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void DictionaryValue::setObject(const String& name, PassOwnPtr<DictionaryValue>
value) | 193 void DictionaryValue::setObject(const String& name, PassOwnPtr<DictionaryValue>
value) |
| 194 { | 194 { |
| 195 ASSERT(value); | 195 ASSERT(value); |
| 196 if (m_data.set(name, value).isNewEntry) | 196 if (m_data.set(name, value)) |
| 197 m_order.append(name); | 197 m_order.append(name); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void DictionaryValue::setArray(const String& name, PassOwnPtr<ListValue> value) | 200 void DictionaryValue::setArray(const String& name, PassOwnPtr<ListValue> value) |
| 201 { | 201 { |
| 202 ASSERT(value); | 202 ASSERT(value); |
| 203 if (m_data.set(name, value).isNewEntry) | 203 if (m_data.set(name, value)) |
| 204 m_order.append(name); | 204 m_order.append(name); |
| 205 } | 205 } |
| 206 | 206 |
| 207 bool DictionaryValue::getBoolean(const String& name, bool* output) const | 207 bool DictionaryValue::getBoolean(const String& name, bool* output) const |
| 208 { | 208 { |
| 209 protocol::Value* value = get(name); | 209 protocol::Value* value = get(name); |
| 210 if (!value) | 210 if (!value) |
| 211 return false; | 211 return false; |
| 212 return value->asBoolean(output); | 212 return value->asBoolean(output); |
| 213 } | 213 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 228 protocol::ListValue* DictionaryValue::getArray(const String& name) const | 228 protocol::ListValue* DictionaryValue::getArray(const String& name) const |
| 229 { | 229 { |
| 230 return ListValue::cast(get(name)); | 230 return ListValue::cast(get(name)); |
| 231 } | 231 } |
| 232 | 232 |
| 233 protocol::Value* DictionaryValue::get(const String& name) const | 233 protocol::Value* DictionaryValue::get(const String& name) const |
| 234 { | 234 { |
| 235 Dictionary::const_iterator it = m_data.find(name); | 235 Dictionary::const_iterator it = m_data.find(name); |
| 236 if (it == m_data.end()) | 236 if (it == m_data.end()) |
| 237 return nullptr; | 237 return nullptr; |
| 238 return it->value.get(); | 238 return it->second; |
| 239 } | 239 } |
| 240 | 240 |
| 241 DictionaryValue::Entry DictionaryValue::at(size_t index) const | 241 DictionaryValue::Entry DictionaryValue::at(size_t index) const |
| 242 { | 242 { |
| 243 String key = m_order[index]; | 243 String key = m_order[index]; |
| 244 return std::make_pair(key, m_data.get(key)); | 244 return std::make_pair(key, m_data.get(key)); |
| 245 } | 245 } |
| 246 | 246 |
| 247 bool DictionaryValue::booleanProperty(const String& name, bool defaultValue) con
st | 247 bool DictionaryValue::booleanProperty(const String& name, bool defaultValue) con
st |
| 248 { | 248 { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 263 } | 263 } |
| 264 | 264 |
| 265 void DictionaryValue::writeJSON(StringBuilder* output) const | 265 void DictionaryValue::writeJSON(StringBuilder* output) const |
| 266 { | 266 { |
| 267 output->append('{'); | 267 output->append('{'); |
| 268 for (size_t i = 0; i < m_order.size(); ++i) { | 268 for (size_t i = 0; i < m_order.size(); ++i) { |
| 269 Dictionary::const_iterator it = m_data.find(m_order[i]); | 269 Dictionary::const_iterator it = m_data.find(m_order[i]); |
| 270 ASSERT_WITH_SECURITY_IMPLICATION(it != m_data.end()); | 270 ASSERT_WITH_SECURITY_IMPLICATION(it != m_data.end()); |
| 271 if (i) | 271 if (i) |
| 272 output->append(','); | 272 output->append(','); |
| 273 doubleQuoteStringForJSON(it->key, output); | 273 doubleQuoteStringForJSON(it->first, output); |
| 274 output->append(':'); | 274 output->append(':'); |
| 275 it->value->writeJSON(output); | 275 it->second->writeJSON(output); |
| 276 } | 276 } |
| 277 output->append('}'); | 277 output->append('}'); |
| 278 } | 278 } |
| 279 | 279 |
| 280 PassOwnPtr<Value> DictionaryValue::clone() const | 280 PassOwnPtr<Value> DictionaryValue::clone() const |
| 281 { | 281 { |
| 282 OwnPtr<DictionaryValue> result = DictionaryValue::create(); | 282 OwnPtr<DictionaryValue> result = DictionaryValue::create(); |
| 283 for (size_t i = 0; i < m_order.size(); ++i) { | 283 for (size_t i = 0; i < m_order.size(); ++i) { |
| 284 Dictionary::const_iterator it = m_data.find(m_order[i]); | 284 String key = m_order[i]; |
| 285 ASSERT(it != m_data.end()); | 285 Value* value = m_data.get(key); |
| 286 result->setValue(it->key, it->value->clone()); | 286 ASSERT(value); |
| 287 result->setValue(key, value->clone()); |
| 287 } | 288 } |
| 288 return result.release(); | 289 return result.release(); |
| 289 } | 290 } |
| 290 | 291 |
| 291 DictionaryValue::DictionaryValue() | 292 DictionaryValue::DictionaryValue() |
| 292 : Value(TypeObject) | 293 : Value(TypeObject) |
| 293 , m_data() | |
| 294 , m_order() | |
| 295 { | 294 { |
| 296 } | 295 } |
| 297 | 296 |
| 298 ListValue::~ListValue() | 297 ListValue::~ListValue() |
| 299 { | 298 { |
| 300 } | 299 } |
| 301 | 300 |
| 302 void ListValue::writeJSON(StringBuilder* output) const | 301 void ListValue::writeJSON(StringBuilder* output) const |
| 303 { | 302 { |
| 304 output->append('['); | 303 output->append('['); |
| 305 for (Vector<OwnPtr<protocol::Value>>::const_iterator it = m_data.begin(); it
!= m_data.end(); ++it) { | 304 for (Vector<OwnPtr<protocol::Value>>::const_iterator it = m_data.begin(); it
!= m_data.end(); ++it) { |
| 306 if (it != m_data.begin()) | 305 if (it != m_data.begin()) |
| 307 output->append(','); | 306 output->append(','); |
| 308 (*it)->writeJSON(output); | 307 (*it)->writeJSON(output); |
| 309 } | 308 } |
| 310 output->append(']'); | 309 output->append(']'); |
| 311 } | 310 } |
| 312 | 311 |
| 313 PassOwnPtr<Value> ListValue::clone() const | 312 PassOwnPtr<Value> ListValue::clone() const |
| 314 { | 313 { |
| 315 OwnPtr<ListValue> result = ListValue::create(); | 314 OwnPtr<ListValue> result = ListValue::create(); |
| 316 for (Vector<OwnPtr<protocol::Value>>::const_iterator it = m_data.begin(); it
!= m_data.end(); ++it) | 315 for (Vector<OwnPtr<protocol::Value>>::const_iterator it = m_data.begin(); it
!= m_data.end(); ++it) |
| 317 result->pushValue((*it)->clone()); | 316 result->pushValue((*it)->clone()); |
| 318 return result.release(); | 317 return result.release(); |
| 319 } | 318 } |
| 320 | 319 |
| 321 ListValue::ListValue() | 320 ListValue::ListValue() |
| 322 : Value(TypeArray) | 321 : Value(TypeArray) |
| 323 , m_data() | |
| 324 { | 322 { |
| 325 } | 323 } |
| 326 | 324 |
| 327 void ListValue::pushValue(PassOwnPtr<protocol::Value> value) | 325 void ListValue::pushValue(PassOwnPtr<protocol::Value> value) |
| 328 { | 326 { |
| 329 ASSERT(value); | 327 ASSERT(value); |
| 330 m_data.append(value); | 328 m_data.append(value); |
| 331 } | 329 } |
| 332 | 330 |
| 333 protocol::Value* ListValue::at(size_t index) | 331 protocol::Value* ListValue::at(size_t index) |
| 334 { | 332 { |
| 335 ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size()); | 333 ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size()); |
| 336 return m_data[index].get(); | 334 return m_data[index].get(); |
| 337 } | 335 } |
| 338 | 336 |
| 339 } // namespace protocol | 337 } // namespace protocol |
| 340 } // namespace blink | 338 } // namespace blink |
| OLD | NEW |