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 21566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21577 v8::Local<v8::Array> contents = map->AsArray(); | 21577 v8::Local<v8::Array> contents = map->AsArray(); |
21578 CHECK_EQ(4U, contents->Length()); | 21578 CHECK_EQ(4U, contents->Length()); |
21579 CHECK_EQ(1, contents->Get(0).As<v8::Int32>()->Value()); | 21579 CHECK_EQ(1, contents->Get(0).As<v8::Int32>()->Value()); |
21580 CHECK_EQ(2, contents->Get(1).As<v8::Int32>()->Value()); | 21580 CHECK_EQ(2, contents->Get(1).As<v8::Int32>()->Value()); |
21581 CHECK_EQ(3, contents->Get(2).As<v8::Int32>()->Value()); | 21581 CHECK_EQ(3, contents->Get(2).As<v8::Int32>()->Value()); |
21582 CHECK_EQ(4, contents->Get(3).As<v8::Int32>()->Value()); | 21582 CHECK_EQ(4, contents->Get(3).As<v8::Int32>()->Value()); |
21583 | 21583 |
21584 map = v8::Map::FromArray(env.local(), contents).ToLocalChecked(); | 21584 map = v8::Map::FromArray(env.local(), contents).ToLocalChecked(); |
21585 CHECK_EQ(2U, map->Size()); | 21585 CHECK_EQ(2U, map->Size()); |
21586 | 21586 |
| 21587 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 1)).FromJust()); |
| 21588 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 3)).FromJust()); |
| 21589 |
| 21590 CHECK(!map->Has(env.local(), v8::Integer::New(isolate, 2)).FromJust()); |
| 21591 CHECK(!map->Has(env.local(), map).FromJust()); |
| 21592 |
| 21593 CHECK_EQ(2, map->Get(env.local(), v8::Integer::New(isolate, 1)) |
| 21594 .ToLocalChecked() |
| 21595 ->Int32Value()); |
| 21596 CHECK_EQ(4, map->Get(env.local(), v8::Integer::New(isolate, 3)) |
| 21597 .ToLocalChecked() |
| 21598 ->Int32Value()); |
| 21599 |
| 21600 CHECK(map->Get(env.local(), v8::Integer::New(isolate, 42)) |
| 21601 .ToLocalChecked() |
| 21602 ->IsUndefined()); |
| 21603 |
| 21604 CHECK(!map->Set(env.local(), map, map).IsEmpty()); |
| 21605 CHECK_EQ(3U, map->Size()); |
| 21606 CHECK(map->Has(env.local(), map).FromJust()); |
| 21607 |
| 21608 CHECK(map->Delete(env.local(), map).FromJust()); |
| 21609 CHECK_EQ(2U, map->Size()); |
| 21610 CHECK(!map->Has(env.local(), map).FromJust()); |
| 21611 CHECK(!map->Delete(env.local(), map).FromJust()); |
| 21612 |
| 21613 map->Clear(); |
| 21614 CHECK_EQ(0U, map->Size()); |
| 21615 } |
| 21616 |
| 21617 |
| 21618 TEST(MapFromArrayOddLength) { |
| 21619 v8::Isolate* isolate = CcTest::isolate(); |
| 21620 v8::HandleScope handle_scope(isolate); |
| 21621 LocalContext env; |
21587 // Odd lengths result in a null MaybeLocal. | 21622 // Odd lengths result in a null MaybeLocal. |
21588 contents = v8::Array::New(isolate, 41); | 21623 Local<v8::Array> contents = v8::Array::New(isolate, 41); |
21589 CHECK(v8::Map::FromArray(env.local(), contents).IsEmpty()); | 21624 CHECK(v8::Map::FromArray(env.local(), contents).IsEmpty()); |
21590 } | 21625 } |
21591 | 21626 |
21592 | 21627 |
21593 TEST(Set) { | 21628 TEST(Set) { |
21594 v8::Isolate* isolate = CcTest::isolate(); | 21629 v8::Isolate* isolate = CcTest::isolate(); |
21595 v8::HandleScope handle_scope(isolate); | 21630 v8::HandleScope handle_scope(isolate); |
21596 LocalContext env; | 21631 LocalContext env; |
21597 | 21632 |
21598 v8::Local<v8::Set> set = v8::Set::New(isolate); | 21633 v8::Local<v8::Set> set = v8::Set::New(isolate); |
21599 CHECK(set->IsObject()); | 21634 CHECK(set->IsObject()); |
21600 CHECK(set->IsSet()); | 21635 CHECK(set->IsSet()); |
21601 CHECK(set->GetPrototype()->StrictEquals(CompileRun("Set.prototype"))); | 21636 CHECK(set->GetPrototype()->StrictEquals(CompileRun("Set.prototype"))); |
21602 CHECK_EQ(0U, set->Size()); | 21637 CHECK_EQ(0U, set->Size()); |
21603 | 21638 |
21604 v8::Local<v8::Value> val = CompileRun("new Set([1, 2])"); | 21639 v8::Local<v8::Value> val = CompileRun("new Set([1, 2])"); |
21605 CHECK(val->IsSet()); | 21640 CHECK(val->IsSet()); |
21606 set = v8::Local<v8::Set>::Cast(val); | 21641 set = v8::Local<v8::Set>::Cast(val); |
21607 CHECK_EQ(2U, set->Size()); | 21642 CHECK_EQ(2U, set->Size()); |
21608 | 21643 |
21609 v8::Local<v8::Array> keys = set->AsArray(); | 21644 v8::Local<v8::Array> keys = set->AsArray(); |
21610 CHECK_EQ(2U, keys->Length()); | 21645 CHECK_EQ(2U, keys->Length()); |
21611 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); | 21646 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); |
21612 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); | 21647 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); |
21613 | 21648 |
21614 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); | 21649 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); |
21615 CHECK_EQ(2U, set->Size()); | 21650 CHECK_EQ(2U, set->Size()); |
| 21651 |
| 21652 CHECK(set->Has(env.local(), v8::Integer::New(isolate, 1)).FromJust()); |
| 21653 CHECK(set->Has(env.local(), v8::Integer::New(isolate, 2)).FromJust()); |
| 21654 |
| 21655 CHECK(!set->Has(env.local(), v8::Integer::New(isolate, 3)).FromJust()); |
| 21656 CHECK(!set->Has(env.local(), set).FromJust()); |
| 21657 |
| 21658 CHECK(!set->Add(env.local(), set).IsEmpty()); |
| 21659 CHECK_EQ(3U, set->Size()); |
| 21660 CHECK(set->Has(env.local(), set).FromJust()); |
| 21661 |
| 21662 CHECK(set->Delete(env.local(), set).FromJust()); |
| 21663 CHECK_EQ(2U, set->Size()); |
| 21664 CHECK(!set->Has(env.local(), set).FromJust()); |
| 21665 CHECK(!set->Delete(env.local(), set).FromJust()); |
| 21666 |
| 21667 set->Clear(); |
| 21668 CHECK_EQ(0U, set->Size()); |
21616 } | 21669 } |
OLD | NEW |