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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 124 } |
125 return temp->Value(); | 125 return temp->Value(); |
126 } | 126 } |
127 | 127 |
128 bool IsNull(base::DictionaryValue* value, const std::string& key) { | 128 bool IsNull(base::DictionaryValue* value, const std::string& key) { |
129 base::Value* child = NULL; | 129 base::Value* child = NULL; |
130 if (!value->Get(key, &child)) { | 130 if (!value->Get(key, &child)) { |
131 ADD_FAILURE(); | 131 ADD_FAILURE(); |
132 return false; | 132 return false; |
133 } | 133 } |
134 return child->GetType() == base::Value::TYPE_NULL; | 134 return child->GetType() == base::Value::Type::NONE; |
135 } | 135 } |
136 | 136 |
137 bool IsNull(v8::Local<v8::Object> value, const std::string& key) { | 137 bool IsNull(v8::Local<v8::Object> value, const std::string& key) { |
138 v8::Local<v8::Value> child = | 138 v8::Local<v8::Value> child = |
139 value->Get(v8::String::NewFromUtf8(isolate_, key.c_str())); | 139 value->Get(v8::String::NewFromUtf8(isolate_, key.c_str())); |
140 if (child.IsEmpty()) { | 140 if (child.IsEmpty()) { |
141 ADD_FAILURE(); | 141 ADD_FAILURE(); |
142 return false; | 142 return false; |
143 } | 143 } |
144 return child->IsNull(); | 144 return child->IsNull(); |
145 } | 145 } |
146 | 146 |
147 bool IsNull(base::ListValue* value, uint32_t index) { | 147 bool IsNull(base::ListValue* value, uint32_t index) { |
148 base::Value* child = NULL; | 148 base::Value* child = NULL; |
149 if (!value->Get(static_cast<size_t>(index), &child)) { | 149 if (!value->Get(static_cast<size_t>(index), &child)) { |
150 ADD_FAILURE(); | 150 ADD_FAILURE(); |
151 return false; | 151 return false; |
152 } | 152 } |
153 return child->GetType() == base::Value::TYPE_NULL; | 153 return child->GetType() == base::Value::Type::NONE; |
154 } | 154 } |
155 | 155 |
156 bool IsNull(v8::Local<v8::Array> value, uint32_t index) { | 156 bool IsNull(v8::Local<v8::Array> value, uint32_t index) { |
157 v8::Local<v8::Value> child = value->Get(index); | 157 v8::Local<v8::Value> child = value->Get(index); |
158 if (child.IsEmpty()) { | 158 if (child.IsEmpty()) { |
159 ADD_FAILURE(); | 159 ADD_FAILURE(); |
160 return false; | 160 return false; |
161 } | 161 } |
162 return child->IsNull(); | 162 return child->IsNull(); |
163 } | 163 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 if (expected_value) { | 201 if (expected_value) { |
202 base::Value* temp = NULL; | 202 base::Value* temp = NULL; |
203 ASSERT_TRUE(list->Get(0, &temp)); | 203 ASSERT_TRUE(list->Get(0, &temp)); |
204 EXPECT_EQ(expected_type, temp->GetType()); | 204 EXPECT_EQ(expected_type, temp->GetType()); |
205 EXPECT_TRUE(expected_value->Equals(temp)); | 205 EXPECT_TRUE(expected_value->Equals(temp)); |
206 } else { | 206 } else { |
207 // Arrays should preserve their length, and convert unconvertible | 207 // Arrays should preserve their length, and convert unconvertible |
208 // types into null. | 208 // types into null. |
209 base::Value* temp = NULL; | 209 base::Value* temp = NULL; |
210 ASSERT_TRUE(list->Get(0, &temp)); | 210 ASSERT_TRUE(list->Get(0, &temp)); |
211 EXPECT_EQ(base::Value::TYPE_NULL, temp->GetType()); | 211 EXPECT_EQ(base::Value::Type::NONE, temp->GetType()); |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 v8::Isolate* isolate_; | 215 v8::Isolate* isolate_; |
216 | 216 |
217 // Context for the JavaScript in the test. | 217 // Context for the JavaScript in the test. |
218 v8::Persistent<v8::Context> context_; | 218 v8::Persistent<v8::Context> context_; |
219 }; | 219 }; |
220 | 220 |
221 TEST_F(V8ValueConverterImplTest, BasicRoundTrip) { | 221 TEST_F(V8ValueConverterImplTest, BasicRoundTrip) { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 v8::HandleScope handle_scope(isolate_); | 396 v8::HandleScope handle_scope(isolate_); |
397 v8::Local<v8::Context> context = | 397 v8::Local<v8::Context> context = |
398 v8::Local<v8::Context>::New(isolate_, context_); | 398 v8::Local<v8::Context>::New(isolate_, context_); |
399 v8::Context::Scope context_scope(context); | 399 v8::Context::Scope context_scope(context); |
400 | 400 |
401 v8::Local<v8::RegExp> regex(v8::RegExp::New( | 401 v8::Local<v8::RegExp> regex(v8::RegExp::New( |
402 v8::String::NewFromUtf8(isolate_, "."), v8::RegExp::kNone)); | 402 v8::String::NewFromUtf8(isolate_, "."), v8::RegExp::kNone)); |
403 | 403 |
404 V8ValueConverterImpl converter; | 404 V8ValueConverterImpl converter; |
405 TestWeirdType(converter, v8::Undefined(isolate_), | 405 TestWeirdType(converter, v8::Undefined(isolate_), |
406 base::Value::TYPE_NULL, // Arbitrary type, result is NULL. | 406 base::Value::Type::NONE, // Arbitrary type, result is NULL. |
407 std::unique_ptr<base::Value>()); | 407 std::unique_ptr<base::Value>()); |
408 TestWeirdType(converter, v8::Date::New(isolate_, 1000), | 408 TestWeirdType(converter, v8::Date::New(isolate_, 1000), |
409 base::Value::TYPE_DICTIONARY, | 409 base::Value::Type::DICTIONARY, |
410 std::unique_ptr<base::Value>(new base::DictionaryValue())); | 410 std::unique_ptr<base::Value>(new base::DictionaryValue())); |
411 TestWeirdType(converter, regex, base::Value::TYPE_DICTIONARY, | 411 TestWeirdType(converter, regex, base::Value::Type::DICTIONARY, |
412 std::unique_ptr<base::Value>(new base::DictionaryValue())); | 412 std::unique_ptr<base::Value>(new base::DictionaryValue())); |
413 | 413 |
414 converter.SetDateAllowed(true); | 414 converter.SetDateAllowed(true); |
415 TestWeirdType(converter, v8::Date::New(isolate_, 1000), | 415 TestWeirdType(converter, v8::Date::New(isolate_, 1000), |
416 base::Value::TYPE_DOUBLE, | 416 base::Value::Type::DOUBLE, |
417 std::unique_ptr<base::Value>(new base::FundamentalValue(1.0))); | 417 std::unique_ptr<base::Value>(new base::FundamentalValue(1.0))); |
418 | 418 |
419 converter.SetRegExpAllowed(true); | 419 converter.SetRegExpAllowed(true); |
420 TestWeirdType(converter, regex, base::Value::TYPE_STRING, | 420 TestWeirdType(converter, regex, base::Value::Type::STRING, |
421 std::unique_ptr<base::Value>(new base::StringValue("/./"))); | 421 std::unique_ptr<base::Value>(new base::StringValue("/./"))); |
422 } | 422 } |
423 | 423 |
424 TEST_F(V8ValueConverterImplTest, Prototype) { | 424 TEST_F(V8ValueConverterImplTest, Prototype) { |
425 v8::HandleScope handle_scope(isolate_); | 425 v8::HandleScope handle_scope(isolate_); |
426 v8::Local<v8::Context> context = | 426 v8::Local<v8::Context> context = |
427 v8::Local<v8::Context>::New(isolate_, context_); | 427 v8::Local<v8::Context>::New(isolate_, context_); |
428 v8::Context::Scope context_scope(context); | 428 v8::Context::Scope context_scope(context); |
429 v8::MicrotasksScope microtasks( | 429 v8::MicrotasksScope microtasks( |
430 isolate_, v8::MicrotasksScope::kDoNotRunMicrotasks); | 430 isolate_, v8::MicrotasksScope::kDoNotRunMicrotasks); |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 EXPECT_TRUE( | 1120 EXPECT_TRUE( |
1121 base::Value::Equals(reference_number_value.get(), number_value.get())); | 1121 base::Value::Equals(reference_number_value.get(), number_value.get())); |
1122 | 1122 |
1123 v8::Local<v8::Primitive> undefined(v8::Undefined(isolate_)); | 1123 v8::Local<v8::Primitive> undefined(v8::Undefined(isolate_)); |
1124 std::unique_ptr<base::Value> undefined_value( | 1124 std::unique_ptr<base::Value> undefined_value( |
1125 converter.FromV8Value(undefined, context)); | 1125 converter.FromV8Value(undefined, context)); |
1126 EXPECT_FALSE(undefined_value); | 1126 EXPECT_FALSE(undefined_value); |
1127 } | 1127 } |
1128 | 1128 |
1129 } // namespace content | 1129 } // namespace content |
OLD | NEW |