| 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/inspector_protocol/Parser.h" | 7 #include "platform/inspector_protocol/Parser.h" |
| 8 #include "platform/inspector_protocol/String16.h" | 8 #include "platform/inspector_protocol/String16.h" |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 String16 Value::toJSONString() const | 93 String16 Value::toJSONString() const |
| 94 { | 94 { |
| 95 String16Builder result; | 95 String16Builder result; |
| 96 result.reserveCapacity(512); | 96 result.reserveCapacity(512); |
| 97 writeJSON(&result); | 97 writeJSON(&result); |
| 98 return result.toString(); | 98 return result.toString(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void Value::writeJSON(String16Builder* output) const | 101 void Value::writeJSON(String16Builder* output) const |
| 102 { | 102 { |
| 103 ASSERT(m_type == TypeNull); | 103 DCHECK(m_type == TypeNull); |
| 104 output->append(nullString, 4); | 104 output->append(nullString, 4); |
| 105 } | 105 } |
| 106 | 106 |
| 107 PassOwnPtr<Value> Value::clone() const | 107 PassOwnPtr<Value> Value::clone() const |
| 108 { | 108 { |
| 109 return Value::null(); | 109 return Value::null(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 bool FundamentalValue::asBoolean(bool* output) const | 112 bool FundamentalValue::asBoolean(bool* output) const |
| 113 { | 113 { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 128 bool FundamentalValue::asNumber(int* output) const | 128 bool FundamentalValue::asNumber(int* output) const |
| 129 { | 129 { |
| 130 if (type() != TypeNumber) | 130 if (type() != TypeNumber) |
| 131 return false; | 131 return false; |
| 132 *output = static_cast<int>(m_doubleValue); | 132 *output = static_cast<int>(m_doubleValue); |
| 133 return true; | 133 return true; |
| 134 } | 134 } |
| 135 | 135 |
| 136 void FundamentalValue::writeJSON(String16Builder* output) const | 136 void FundamentalValue::writeJSON(String16Builder* output) const |
| 137 { | 137 { |
| 138 ASSERT(type() == TypeBoolean || type() == TypeNumber); | 138 DCHECK(type() == TypeBoolean || type() == TypeNumber); |
| 139 if (type() == TypeBoolean) { | 139 if (type() == TypeBoolean) { |
| 140 if (m_boolValue) | 140 if (m_boolValue) |
| 141 output->append(trueString, 4); | 141 output->append(trueString, 4); |
| 142 else | 142 else |
| 143 output->append(falseString, 5); | 143 output->append(falseString, 5); |
| 144 } else if (type() == TypeNumber) { | 144 } else if (type() == TypeNumber) { |
| 145 if (!std::isfinite(m_doubleValue)) { | 145 if (!std::isfinite(m_doubleValue)) { |
| 146 output->append(nullString, 4); | 146 output->append(nullString, 4); |
| 147 return; | 147 return; |
| 148 } | 148 } |
| 149 output->append(String16::fromDouble(m_doubleValue)); | 149 output->append(String16::fromDouble(m_doubleValue)); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 PassOwnPtr<Value> FundamentalValue::clone() const | 153 PassOwnPtr<Value> FundamentalValue::clone() const |
| 154 { | 154 { |
| 155 return type() == TypeNumber ? FundamentalValue::create(m_doubleValue) : Fund
amentalValue::create(m_boolValue); | 155 return type() == TypeNumber ? FundamentalValue::create(m_doubleValue) : Fund
amentalValue::create(m_boolValue); |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool StringValue::asString(String16* output) const | 158 bool StringValue::asString(String16* output) const |
| 159 { | 159 { |
| 160 *output = m_stringValue; | 160 *output = m_stringValue; |
| 161 return true; | 161 return true; |
| 162 } | 162 } |
| 163 | 163 |
| 164 void StringValue::writeJSON(String16Builder* output) const | 164 void StringValue::writeJSON(String16Builder* output) const |
| 165 { | 165 { |
| 166 ASSERT(type() == TypeString); | 166 DCHECK(type() == TypeString); |
| 167 doubleQuoteStringForJSON(m_stringValue, output); | 167 doubleQuoteStringForJSON(m_stringValue, output); |
| 168 } | 168 } |
| 169 | 169 |
| 170 PassOwnPtr<Value> StringValue::clone() const | 170 PassOwnPtr<Value> StringValue::clone() const |
| 171 { | 171 { |
| 172 return StringValue::create(m_stringValue); | 172 return StringValue::create(m_stringValue); |
| 173 } | 173 } |
| 174 | 174 |
| 175 DictionaryValue::~DictionaryValue() | 175 DictionaryValue::~DictionaryValue() |
| 176 { | 176 { |
| 177 } | 177 } |
| 178 | 178 |
| 179 void DictionaryValue::setBoolean(const String16& name, bool value) | 179 void DictionaryValue::setBoolean(const String16& name, bool value) |
| 180 { | 180 { |
| 181 setValue(name, FundamentalValue::create(value)); | 181 setValue(name, FundamentalValue::create(value)); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void DictionaryValue::setNumber(const String16& name, double value) | 184 void DictionaryValue::setNumber(const String16& name, double value) |
| 185 { | 185 { |
| 186 setValue(name, FundamentalValue::create(value)); | 186 setValue(name, FundamentalValue::create(value)); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void DictionaryValue::setString(const String16& name, const String16& value) | 189 void DictionaryValue::setString(const String16& name, const String16& value) |
| 190 { | 190 { |
| 191 setValue(name, StringValue::create(value)); | 191 setValue(name, StringValue::create(value)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void DictionaryValue::setValue(const String16& name, PassOwnPtr<Value> value) | 194 void DictionaryValue::setValue(const String16& name, PassOwnPtr<Value> value) |
| 195 { | 195 { |
| 196 ASSERT(value); | 196 DCHECK(value); |
| 197 if (m_data.set(name, std::move(value))) | 197 if (m_data.set(name, std::move(value))) |
| 198 m_order.append(name); | 198 m_order.append(name); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void DictionaryValue::setObject(const String16& name, PassOwnPtr<DictionaryValue
> value) | 201 void DictionaryValue::setObject(const String16& name, PassOwnPtr<DictionaryValue
> value) |
| 202 { | 202 { |
| 203 ASSERT(value); | 203 DCHECK(value); |
| 204 if (m_data.set(name, std::move(value))) | 204 if (m_data.set(name, std::move(value))) |
| 205 m_order.append(name); | 205 m_order.append(name); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void DictionaryValue::setArray(const String16& name, PassOwnPtr<ListValue> value
) | 208 void DictionaryValue::setArray(const String16& name, PassOwnPtr<ListValue> value
) |
| 209 { | 209 { |
| 210 ASSERT(value); | 210 DCHECK(value); |
| 211 if (m_data.set(name, std::move(value))) | 211 if (m_data.set(name, std::move(value))) |
| 212 m_order.append(name); | 212 m_order.append(name); |
| 213 } | 213 } |
| 214 | 214 |
| 215 bool DictionaryValue::getBoolean(const String16& name, bool* output) const | 215 bool DictionaryValue::getBoolean(const String16& name, bool* output) const |
| 216 { | 216 { |
| 217 protocol::Value* value = get(name); | 217 protocol::Value* value = get(name); |
| 218 if (!value) | 218 if (!value) |
| 219 return false; | 219 return false; |
| 220 return value->asBoolean(output); | 220 return value->asBoolean(output); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 break; | 275 break; |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 void DictionaryValue::writeJSON(String16Builder* output) const | 280 void DictionaryValue::writeJSON(String16Builder* output) const |
| 281 { | 281 { |
| 282 output->append('{'); | 282 output->append('{'); |
| 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 Dictionary::const_iterator it = m_data.find(m_order[i]); |
| 285 ASSERT_WITH_SECURITY_IMPLICATION(it != m_data.end()); | 285 CHECK(it != m_data.end()); |
| 286 if (i) | 286 if (i) |
| 287 output->append(','); | 287 output->append(','); |
| 288 doubleQuoteStringForJSON(it->first, output); | 288 doubleQuoteStringForJSON(it->first, output); |
| 289 output->append(':'); | 289 output->append(':'); |
| 290 it->second->writeJSON(output); | 290 it->second->writeJSON(output); |
| 291 } | 291 } |
| 292 output->append('}'); | 292 output->append('}'); |
| 293 } | 293 } |
| 294 | 294 |
| 295 PassOwnPtr<Value> DictionaryValue::clone() const | 295 PassOwnPtr<Value> DictionaryValue::clone() const |
| 296 { | 296 { |
| 297 OwnPtr<DictionaryValue> result = DictionaryValue::create(); | 297 OwnPtr<DictionaryValue> result = DictionaryValue::create(); |
| 298 for (size_t i = 0; i < m_order.size(); ++i) { | 298 for (size_t i = 0; i < m_order.size(); ++i) { |
| 299 String16 key = m_order[i]; | 299 String16 key = m_order[i]; |
| 300 Value* value = m_data.get(key); | 300 Value* value = m_data.get(key); |
| 301 ASSERT(value); | 301 DCHECK(value); |
| 302 result->setValue(key, value->clone()); | 302 result->setValue(key, value->clone()); |
| 303 } | 303 } |
| 304 return std::move(result); | 304 return std::move(result); |
| 305 } | 305 } |
| 306 | 306 |
| 307 DictionaryValue::DictionaryValue() | 307 DictionaryValue::DictionaryValue() |
| 308 : Value(TypeObject) | 308 : Value(TypeObject) |
| 309 { | 309 { |
| 310 } | 310 } |
| 311 | 311 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 332 return std::move(result); | 332 return std::move(result); |
| 333 } | 333 } |
| 334 | 334 |
| 335 ListValue::ListValue() | 335 ListValue::ListValue() |
| 336 : Value(TypeArray) | 336 : Value(TypeArray) |
| 337 { | 337 { |
| 338 } | 338 } |
| 339 | 339 |
| 340 void ListValue::pushValue(PassOwnPtr<protocol::Value> value) | 340 void ListValue::pushValue(PassOwnPtr<protocol::Value> value) |
| 341 { | 341 { |
| 342 ASSERT(value); | 342 DCHECK(value); |
| 343 m_data.append(std::move(value)); | 343 m_data.append(std::move(value)); |
| 344 } | 344 } |
| 345 | 345 |
| 346 protocol::Value* ListValue::at(size_t index) | 346 protocol::Value* ListValue::at(size_t index) |
| 347 { | 347 { |
| 348 ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size()); | 348 ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size()); |
| 349 return m_data[index].get(); | 349 return m_data[index]; |
| 350 } | 350 } |
| 351 | 351 |
| 352 } // namespace protocol | 352 } // namespace protocol |
| 353 } // namespace blink | 353 } // namespace blink |
| OLD | NEW |