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

Unified Diff: content/child/v8_value_converter_impl_unittest.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.cc ('k') | content/public/child/v8_value_converter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/v8_value_converter_impl_unittest.cc
diff --git a/content/child/v8_value_converter_impl_unittest.cc b/content/child/v8_value_converter_impl_unittest.cc
index 84d03fc25bb2d378a9a8685f47d9114a6781f5f6..c08bc57c9eb9e2b36699007dfad0f2478eb7c561 100644
--- a/content/child/v8_value_converter_impl_unittest.cc
+++ b/content/child/v8_value_converter_impl_unittest.cc
@@ -952,6 +952,37 @@ TEST_F(V8ValueConverterImplTest, MaxRecursionDepth) {
EXPECT_TRUE(base::Value::Equals(&empty, current)) << *current;
}
+TEST_F(V8ValueConverterImplTest, NegativeZero) {
+ v8::HandleScope handle_scope(isolate_);
+ v8::Local<v8::Context> context =
+ v8::Local<v8::Context>::New(isolate_, context_);
+ v8::MicrotasksScope microtasks(isolate_,
+ v8::MicrotasksScope::kDoNotRunMicrotasks);
+
+ v8::Context::Scope context_scope(context);
+ const char* source = "(function() { return -0; })();";
+
+ v8::Local<v8::Script> script(
+ v8::Script::Compile(v8::String::NewFromUtf8(isolate_, source)));
+ v8::Local<v8::Value> value = script->Run();
+ ASSERT_FALSE(value.IsEmpty());
+
+ {
+ V8ValueConverterImpl converter;
+ std::unique_ptr<base::Value> result = converter.FromV8Value(value, context);
+ ASSERT_TRUE(result->is_double())
+ << base::Value::GetTypeName(result->type());
+ EXPECT_EQ(0, result->GetDouble());
+ }
+ {
+ V8ValueConverterImpl converter;
+ converter.SetConvertNegativeZeroToInt(true);
+ std::unique_ptr<base::Value> result = converter.FromV8Value(value, context);
+ ASSERT_TRUE(result->is_int()) << base::Value::GetTypeName(result->type());
+ EXPECT_EQ(0, result->GetInt());
+ }
+}
+
class V8ValueConverterOverridingStrategyForTesting
: public V8ValueConverter::Strategy {
public:
« no previous file with comments | « content/child/v8_value_converter_impl.cc ('k') | content/public/child/v8_value_converter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698