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

Unified Diff: content/child/v8_value_converter_impl.cc

Issue 2709103004: [Content] Allow V8ValueConverter to convert -0 to an integer (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « content/child/v8_value_converter_impl.h ('k') | content/child/v8_value_converter_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/v8_value_converter_impl.cc
diff --git a/content/child/v8_value_converter_impl.cc b/content/child/v8_value_converter_impl.cc
index 86554c33915beb1850a49f10781c027f097594e8..50dde0fdd5ae01c477bf1992d2ed5c7017507a12 100644
--- a/content/child/v8_value_converter_impl.cc
+++ b/content/child/v8_value_converter_impl.cc
@@ -184,6 +184,7 @@ V8ValueConverterImpl::V8ValueConverterImpl()
reg_exp_allowed_(false),
function_allowed_(false),
strip_null_from_objects_(false),
+ convert_negative_zero_to_int_(false),
avoid_identity_hash_for_testing_(false),
strategy_(NULL) {}
@@ -203,6 +204,10 @@ void V8ValueConverterImpl::SetStripNullFromObjects(bool val) {
strip_null_from_objects_ = val;
}
+void V8ValueConverterImpl::SetConvertNegativeZeroToInt(bool val) {
+ convert_negative_zero_to_int_ = val;
+}
+
void V8ValueConverterImpl::SetStrategy(Strategy* strategy) {
strategy_ = strategy;
}
@@ -373,6 +378,11 @@ std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8ValueImpl(
double val_as_double = val.As<v8::Number>()->Value();
if (!std::isfinite(val_as_double))
return nullptr;
+ // Normally, this would be an integer, and fall into IsInt32(). But if the
+ // value is -0, it's treated internally as a double. Consumers are allowed
+ // to ignore this esoterica and treat it as an integer.
+ if (convert_negative_zero_to_int_ && val_as_double == 0.0)
+ return base::MakeUnique<base::FundamentalValue>(0);
return base::MakeUnique<base::FundamentalValue>(val_as_double);
}
« no previous file with comments | « content/child/v8_value_converter_impl.h ('k') | content/child/v8_value_converter_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698