Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Unified Diff: third_party/WebKit/Source/platform/inspector_protocol/Values.cpp

Issue 2151083002: DevTools: explicitly differentiate ints vs doubles in the protocol bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lcean Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/inspector_protocol/Values.cpp
diff --git a/third_party/WebKit/Source/platform/inspector_protocol/Values.cpp b/third_party/WebKit/Source/platform/inspector_protocol/Values.cpp
index 44acdd4688e4b5440db8af779277ee0c05bc93e8..7d4ec242ae4c51d2c557413daf72b9d9f61acdd6 100644
--- a/third_party/WebKit/Source/platform/inspector_protocol/Values.cpp
+++ b/third_party/WebKit/Source/platform/inspector_protocol/Values.cpp
@@ -77,12 +77,12 @@ bool Value::asBoolean(bool*) const
return false;
}
-bool Value::asNumber(double*) const
+bool Value::asDouble(double*) const
{
return false;
}
-bool Value::asNumber(int*) const
+bool Value::asInteger(int*) const
{
return false;
}
@@ -119,42 +119,56 @@ bool FundamentalValue::asBoolean(bool* output) const
return true;
}
-bool FundamentalValue::asNumber(double* output) const
+bool FundamentalValue::asDouble(double* output) const
{
- if (type() != TypeNumber)
- return false;
- *output = m_doubleValue;
- return true;
+ if (type() == TypeDouble) {
+ *output = m_doubleValue;
+ return true;
+ }
+ if (type() == TypeInteger) {
+ *output = m_integerValue;
+ return true;
+ }
+ return false;
}
-bool FundamentalValue::asNumber(int* output) const
+bool FundamentalValue::asInteger(int* output) const
{
- if (type() != TypeNumber)
+ if (type() != TypeInteger)
return false;
- *output = static_cast<int>(m_doubleValue);
+ *output = m_integerValue;
return true;
}
void FundamentalValue::writeJSON(String16Builder* output) const
{
- DCHECK(type() == TypeBoolean || type() == TypeNumber);
+ DCHECK(type() == TypeBoolean || type() == TypeInteger || type() == TypeDouble);
if (type() == TypeBoolean) {
if (m_boolValue)
output->append(trueString, 4);
else
output->append(falseString, 5);
- } else if (type() == TypeNumber) {
+ } else if (type() == TypeDouble) {
if (!std::isfinite(m_doubleValue)) {
output->append(nullString, 4);
return;
}
output->append(String16::fromDouble(m_doubleValue));
+ } else if (type() == TypeInteger) {
+ output->append(String16::fromInteger(m_integerValue));
}
}
std::unique_ptr<Value> FundamentalValue::clone() const
{
- return type() == TypeNumber ? FundamentalValue::create(m_doubleValue) : FundamentalValue::create(m_boolValue);
+ switch (type()) {
+ case TypeDouble: return FundamentalValue::create(m_doubleValue);
+ case TypeInteger: return FundamentalValue::create(m_integerValue);
+ case TypeBoolean: return FundamentalValue::create(m_boolValue);
+ default:
+ NOTREACHED();
+ }
+ return nullptr;
}
bool StringValue::asString(String16* output) const
@@ -183,7 +197,12 @@ void DictionaryValue::setBoolean(const String16& name, bool value)
setValue(name, FundamentalValue::create(value));
}
-void DictionaryValue::setNumber(const String16& name, double value)
+void DictionaryValue::setInteger(const String16& name, int value)
+{
+ setValue(name, FundamentalValue::create(value));
+}
+
+void DictionaryValue::setDouble(const String16& name, double value)
{
setValue(name, FundamentalValue::create(value));
}
@@ -216,6 +235,22 @@ bool DictionaryValue::getBoolean(const String16& name, bool* output) const
return value->asBoolean(output);
}
+bool DictionaryValue::getInteger(const String16& name, int* output) const
+{
+ Value* value = get(name);
+ if (!value)
+ return false;
+ return value->asInteger(output);
+}
+
+bool DictionaryValue::getDouble(const String16& name, double* output) const
+{
+ Value* value = get(name);
+ if (!value)
+ return false;
+ return value->asDouble(output);
+}
+
bool DictionaryValue::getString(const String16& name, String16* output) const
{
protocol::Value* value = get(name);
@@ -255,10 +290,17 @@ bool DictionaryValue::booleanProperty(const String16& name, bool defaultValue) c
return result;
}
-double DictionaryValue::numberProperty(const String16& name, double defaultValue) const
+int DictionaryValue::integerProperty(const String16& name, int defaultValue) const
+{
+ int result = defaultValue;
+ getInteger(name, &result);
+ return result;
+}
+
+double DictionaryValue::doubleProperty(const String16& name, double defaultValue) const
{
double result = defaultValue;
- getNumber(name, &result);
+ getDouble(name, &result);
return result;
}

Powered by Google App Engine
This is Rietveld 408576698