| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "bindings/core/v8/ToV8.h" | 5 #include "bindings/core/v8/ToV8.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8Binding.h" | 7 #include "bindings/core/v8/V8Binding.h" |
| 8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
| 9 #include "core/testing/GarbageCollectedScriptWrappable.h" | 9 #include "core/testing/GarbageCollectedScriptWrappable.h" |
| 10 #include "platform/heap/Heap.h" | 10 #include "platform/heap/Heap.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 doubleVector.push_back(4.2); | 197 doubleVector.push_back(4.2); |
| 198 TEST_TOV8("2.3,4.2", doubleVector); | 198 TEST_TOV8("2.3,4.2", doubleVector); |
| 199 | 199 |
| 200 Vector<bool> boolVector; | 200 Vector<bool> boolVector; |
| 201 boolVector.push_back(true); | 201 boolVector.push_back(true); |
| 202 boolVector.push_back(true); | 202 boolVector.push_back(true); |
| 203 boolVector.push_back(false); | 203 boolVector.push_back(false); |
| 204 TEST_TOV8("true,true,false", boolVector); | 204 TEST_TOV8("true,true,false", boolVector); |
| 205 } | 205 } |
| 206 | 206 |
| 207 TEST(ToV8Test, dictionaryVector) { | 207 TEST(ToV8Test, pairVector) { |
| 208 V8TestingScope scope; | 208 V8TestingScope scope; |
| 209 Vector<std::pair<String, int>> dictionary; | 209 Vector<std::pair<String, int>> pairVector; |
| 210 dictionary.push_back(std::make_pair("one", 1)); | 210 pairVector.push_back(std::make_pair("one", 1)); |
| 211 dictionary.push_back(std::make_pair("two", 2)); | 211 pairVector.push_back(std::make_pair("two", 2)); |
| 212 TEST_TOV8("[object Object]", dictionary); | 212 TEST_TOV8("[object Object]", pairVector); |
| 213 v8::Local<v8::Context> context = scope.getScriptState()->context(); | 213 v8::Local<v8::Context> context = scope.getScriptState()->context(); |
| 214 v8::Local<v8::Object> result = | 214 v8::Local<v8::Object> result = |
| 215 ToV8(dictionary, context->Global(), scope.isolate()) | 215 ToV8(pairVector, context->Global(), scope.isolate()) |
| 216 ->ToObject(context) | 216 ->ToObject(context) |
| 217 .ToLocalChecked(); | 217 .ToLocalChecked(); |
| 218 v8::Local<v8::Value> one = | 218 v8::Local<v8::Value> one = |
| 219 result->Get(context, v8String(scope.isolate(), "one")).ToLocalChecked(); | 219 result->Get(context, v8String(scope.isolate(), "one")).ToLocalChecked(); |
| 220 EXPECT_EQ(1, one->NumberValue(context).FromJust()); | 220 EXPECT_EQ(1, one->NumberValue(context).FromJust()); |
| 221 v8::Local<v8::Value> two = | 221 v8::Local<v8::Value> two = |
| 222 result->Get(context, v8String(scope.isolate(), "two")).ToLocalChecked(); | 222 result->Get(context, v8String(scope.isolate(), "two")).ToLocalChecked(); |
| 223 EXPECT_EQ(2, two->NumberValue(context).FromJust()); | 223 EXPECT_EQ(2, two->NumberValue(context).FromJust()); |
| 224 } | 224 } |
| 225 | 225 |
| 226 TEST(ToV8Test, pairHeapVector) { |
| 227 V8TestingScope scope; |
| 228 HeapVector<std::pair<String, Member<GarbageCollectedScriptWrappable>>> |
| 229 pairHeapVector; |
| 230 pairHeapVector.push_back( |
| 231 std::make_pair("one", new GarbageCollectedScriptWrappable("foo"))); |
| 232 pairHeapVector.push_back( |
| 233 std::make_pair("two", new GarbageCollectedScriptWrappable("bar"))); |
| 234 TEST_TOV8("[object Object]", pairHeapVector); |
| 235 v8::Local<v8::Context> context = scope.getScriptState()->context(); |
| 236 v8::Local<v8::Object> result = |
| 237 ToV8(pairHeapVector, context->Global(), scope.isolate()) |
| 238 ->ToObject(context) |
| 239 .ToLocalChecked(); |
| 240 v8::Local<v8::Value> one = |
| 241 result->Get(context, v8String(scope.isolate(), "one")).ToLocalChecked(); |
| 242 EXPECT_TRUE(one->IsObject()); |
| 243 EXPECT_EQ(String("foo"), toCoreString(one->ToString())); |
| 244 v8::Local<v8::Value> two = |
| 245 result->Get(context, v8String(scope.isolate(), "two")).ToLocalChecked(); |
| 246 EXPECT_TRUE(two->IsObject()); |
| 247 EXPECT_EQ(String("bar"), toCoreString(two->ToString())); |
| 248 } |
| 249 |
| 226 TEST(ToV8Test, stringVectorVector) { | 250 TEST(ToV8Test, stringVectorVector) { |
| 227 V8TestingScope scope; | 251 V8TestingScope scope; |
| 228 | 252 |
| 229 Vector<String> stringVector1; | 253 Vector<String> stringVector1; |
| 230 stringVector1.push_back("foo"); | 254 stringVector1.push_back("foo"); |
| 231 stringVector1.push_back("bar"); | 255 stringVector1.push_back("bar"); |
| 232 Vector<String> stringVector2; | 256 Vector<String> stringVector2; |
| 233 stringVector2.push_back("quux"); | 257 stringVector2.push_back("quux"); |
| 234 | 258 |
| 235 Vector<Vector<String>> compoundVector; | 259 Vector<Vector<String>> compoundVector; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 v8::Local<v8::Value> actual = ToV8(value, scope.getScriptState()); | 294 v8::Local<v8::Value> actual = ToV8(value, scope.getScriptState()); |
| 271 EXPECT_FALSE(actual.IsEmpty()); | 295 EXPECT_FALSE(actual.IsEmpty()); |
| 272 | 296 |
| 273 double actualAsNumber = actual.As<v8::Number>()->Value(); | 297 double actualAsNumber = actual.As<v8::Number>()->Value(); |
| 274 EXPECT_EQ(1234.0, actualAsNumber); | 298 EXPECT_EQ(1234.0, actualAsNumber); |
| 275 } | 299 } |
| 276 | 300 |
| 277 } // namespace | 301 } // namespace |
| 278 | 302 |
| 279 } // namespace blink | 303 } // namespace blink |
| OLD | NEW |