OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 21366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21377 CHECK(map->IsObject()); | 21377 CHECK(map->IsObject()); |
21378 CHECK(map->IsMap()); | 21378 CHECK(map->IsMap()); |
21379 CHECK(map->GetPrototype()->StrictEquals(CompileRun("Map.prototype"))); | 21379 CHECK(map->GetPrototype()->StrictEquals(CompileRun("Map.prototype"))); |
21380 CHECK_EQ(0, map->Size()); | 21380 CHECK_EQ(0, map->Size()); |
21381 | 21381 |
21382 v8::Local<v8::Value> val = CompileRun("new Map([[1, 2], [3, 4]])"); | 21382 v8::Local<v8::Value> val = CompileRun("new Map([[1, 2], [3, 4]])"); |
21383 CHECK(val->IsMap()); | 21383 CHECK(val->IsMap()); |
21384 map = v8::Local<v8::Map>::Cast(val); | 21384 map = v8::Local<v8::Map>::Cast(val); |
21385 CHECK_EQ(2, map->Size()); | 21385 CHECK_EQ(2, map->Size()); |
21386 | 21386 |
21387 v8::Local<v8::Array> entries = map->AsArray(); | 21387 v8::Local<v8::Array> contents = map->AsArray(); |
21388 CHECK_EQ(2, entries->Length()); | 21388 CHECK_EQ(4, contents->Length()); |
21389 v8::Local<v8::Array> entry = entries->Get(0).As<v8::Array>(); | 21389 CHECK_EQ(1, contents->Get(0).As<v8::Int32>()->Value()); |
21390 CHECK_EQ(2, entry->Length()); | 21390 CHECK_EQ(2, contents->Get(1).As<v8::Int32>()->Value()); |
21391 CHECK_EQ(1, entry->Get(0).As<v8::Int32>()->Value()); | 21391 CHECK_EQ(3, contents->Get(2).As<v8::Int32>()->Value()); |
21392 CHECK_EQ(2, entry->Get(1).As<v8::Int32>()->Value()); | 21392 CHECK_EQ(4, contents->Get(3).As<v8::Int32>()->Value()); |
21393 entry = entries->Get(1).As<v8::Array>(); | |
21394 CHECK_EQ(2, entry->Length()); | |
21395 CHECK_EQ(3, entry->Get(0).As<v8::Int32>()->Value()); | |
21396 CHECK_EQ(4, entry->Get(1).As<v8::Int32>()->Value()); | |
21397 | 21393 |
21398 map = v8::Map::FromArray(env.local(), entries).ToLocalChecked(); | 21394 map = v8::Map::FromArray(env.local(), contents).ToLocalChecked(); |
21399 CHECK_EQ(2, map->Size()); | 21395 CHECK_EQ(2, map->Size()); |
| 21396 |
| 21397 // Odd lengths result in a null MaybeLocal. |
| 21398 contents = v8::Array::New(isolate, 41); |
| 21399 CHECK(v8::Map::FromArray(env.local(), contents).IsEmpty()); |
21400 } | 21400 } |
21401 | 21401 |
21402 | 21402 |
21403 TEST(Set) { | 21403 TEST(Set) { |
21404 v8::Isolate* isolate = CcTest::isolate(); | 21404 v8::Isolate* isolate = CcTest::isolate(); |
21405 v8::HandleScope handle_scope(isolate); | 21405 v8::HandleScope handle_scope(isolate); |
21406 LocalContext env; | 21406 LocalContext env; |
21407 | 21407 |
21408 v8::Local<v8::Set> set = v8::Set::New(isolate); | 21408 v8::Local<v8::Set> set = v8::Set::New(isolate); |
21409 CHECK(set->IsObject()); | 21409 CHECK(set->IsObject()); |
21410 CHECK(set->IsSet()); | 21410 CHECK(set->IsSet()); |
21411 CHECK(set->GetPrototype()->StrictEquals(CompileRun("Set.prototype"))); | 21411 CHECK(set->GetPrototype()->StrictEquals(CompileRun("Set.prototype"))); |
21412 CHECK_EQ(0, set->Size()); | 21412 CHECK_EQ(0, set->Size()); |
21413 | 21413 |
21414 v8::Local<v8::Value> val = CompileRun("new Set([1, 2])"); | 21414 v8::Local<v8::Value> val = CompileRun("new Set([1, 2])"); |
21415 CHECK(val->IsSet()); | 21415 CHECK(val->IsSet()); |
21416 set = v8::Local<v8::Set>::Cast(val); | 21416 set = v8::Local<v8::Set>::Cast(val); |
21417 CHECK_EQ(2, set->Size()); | 21417 CHECK_EQ(2, set->Size()); |
21418 | 21418 |
21419 v8::Local<v8::Array> keys = set->AsArray(); | 21419 v8::Local<v8::Array> keys = set->AsArray(); |
21420 CHECK_EQ(2, keys->Length()); | 21420 CHECK_EQ(2, keys->Length()); |
21421 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); | 21421 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); |
21422 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); | 21422 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); |
21423 | 21423 |
21424 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); | 21424 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); |
21425 CHECK_EQ(2, set->Size()); | 21425 CHECK_EQ(2, set->Size()); |
21426 } | 21426 } |
OLD | NEW |