| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/child/v8_value_converter_impl.h" | 5 #include "content/child/v8_value_converter_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 base::DictionaryValue* current_as_object = NULL; | 945 base::DictionaryValue* current_as_object = NULL; |
| 946 ASSERT_TRUE(current->GetAsDictionary(¤t_as_object)) << i; | 946 ASSERT_TRUE(current->GetAsDictionary(¤t_as_object)) << i; |
| 947 ASSERT_TRUE(current_as_object->Get(kKey, ¤t)) << i; | 947 ASSERT_TRUE(current_as_object->Get(kKey, ¤t)) << i; |
| 948 } | 948 } |
| 949 | 949 |
| 950 // The leaf node shouldn't have any properties. | 950 // The leaf node shouldn't have any properties. |
| 951 base::DictionaryValue empty; | 951 base::DictionaryValue empty; |
| 952 EXPECT_TRUE(base::Value::Equals(&empty, current)) << *current; | 952 EXPECT_TRUE(base::Value::Equals(&empty, current)) << *current; |
| 953 } | 953 } |
| 954 | 954 |
| 955 TEST_F(V8ValueConverterImplTest, NegativeZero) { |
| 956 v8::HandleScope handle_scope(isolate_); |
| 957 v8::Local<v8::Context> context = |
| 958 v8::Local<v8::Context>::New(isolate_, context_); |
| 959 v8::MicrotasksScope microtasks(isolate_, |
| 960 v8::MicrotasksScope::kDoNotRunMicrotasks); |
| 961 |
| 962 v8::Context::Scope context_scope(context); |
| 963 const char* source = "(function() { return -0; })();"; |
| 964 |
| 965 v8::Local<v8::Script> script( |
| 966 v8::Script::Compile(v8::String::NewFromUtf8(isolate_, source))); |
| 967 v8::Local<v8::Value> value = script->Run(); |
| 968 ASSERT_FALSE(value.IsEmpty()); |
| 969 |
| 970 { |
| 971 V8ValueConverterImpl converter; |
| 972 std::unique_ptr<base::Value> result = converter.FromV8Value(value, context); |
| 973 ASSERT_TRUE(result->is_double()) |
| 974 << base::Value::GetTypeName(result->type()); |
| 975 EXPECT_EQ(0, result->GetDouble()); |
| 976 } |
| 977 { |
| 978 V8ValueConverterImpl converter; |
| 979 converter.SetConvertNegativeZeroToInt(true); |
| 980 std::unique_ptr<base::Value> result = converter.FromV8Value(value, context); |
| 981 ASSERT_TRUE(result->is_int()) << base::Value::GetTypeName(result->type()); |
| 982 EXPECT_EQ(0, result->GetInt()); |
| 983 } |
| 984 } |
| 985 |
| 955 class V8ValueConverterOverridingStrategyForTesting | 986 class V8ValueConverterOverridingStrategyForTesting |
| 956 : public V8ValueConverter::Strategy { | 987 : public V8ValueConverter::Strategy { |
| 957 public: | 988 public: |
| 958 V8ValueConverterOverridingStrategyForTesting() | 989 V8ValueConverterOverridingStrategyForTesting() |
| 959 : reference_value_(NewReferenceValue()) {} | 990 : reference_value_(NewReferenceValue()) {} |
| 960 bool FromV8Object(v8::Local<v8::Object> value, | 991 bool FromV8Object(v8::Local<v8::Object> value, |
| 961 std::unique_ptr<base::Value>* out, | 992 std::unique_ptr<base::Value>* out, |
| 962 v8::Isolate* isolate, | 993 v8::Isolate* isolate, |
| 963 const FromV8ValueCallback& callback) const override { | 994 const FromV8ValueCallback& callback) const override { |
| 964 *out = NewReferenceValue(); | 995 *out = NewReferenceValue(); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 EXPECT_TRUE( | 1172 EXPECT_TRUE( |
| 1142 base::Value::Equals(reference_number_value.get(), number_value.get())); | 1173 base::Value::Equals(reference_number_value.get(), number_value.get())); |
| 1143 | 1174 |
| 1144 v8::Local<v8::Primitive> undefined(v8::Undefined(isolate_)); | 1175 v8::Local<v8::Primitive> undefined(v8::Undefined(isolate_)); |
| 1145 std::unique_ptr<base::Value> undefined_value( | 1176 std::unique_ptr<base::Value> undefined_value( |
| 1146 converter.FromV8Value(undefined, context)); | 1177 converter.FromV8Value(undefined, context)); |
| 1147 EXPECT_FALSE(undefined_value); | 1178 EXPECT_FALSE(undefined_value); |
| 1148 } | 1179 } |
| 1149 | 1180 |
| 1150 } // namespace content | 1181 } // namespace content |
| OLD | NEW |