OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 | 44 |
45 template<typename HashMap> | 45 template<typename HashMap> |
46 static void TestHashMap(Handle<HashMap> table) { | 46 static void TestHashMap(Handle<HashMap> table) { |
47 Isolate* isolate = CcTest::i_isolate(); | 47 Isolate* isolate = CcTest::i_isolate(); |
48 Factory* factory = isolate->factory(); | 48 Factory* factory = isolate->factory(); |
49 | 49 |
50 Handle<JSObject> a = factory->NewJSArray(7); | 50 Handle<JSObject> a = factory->NewJSArray(7); |
51 Handle<JSObject> b = factory->NewJSArray(11); | 51 Handle<JSObject> b = factory->NewJSArray(11); |
52 table = HashMap::Put(table, a, b); | 52 table = HashMap::Put(table, a, b); |
53 CHECK_EQ(table->NumberOfElements(), 1); | 53 CHECK_EQ(1, table->NumberOfElements()); |
54 CHECK_EQ(table->Lookup(a), *b); | 54 CHECK_EQ(table->Lookup(a), *b); |
55 // When the key does not exist in the map, Lookup returns the hole. | 55 // When the key does not exist in the map, Lookup returns the hole. |
56 CHECK_EQ(table->Lookup(b), CcTest::heap()->the_hole_value()); | 56 CHECK_EQ(table->Lookup(b), CcTest::heap()->the_hole_value()); |
57 | 57 |
58 // Keys still have to be valid after objects were moved. | 58 // Keys still have to be valid after objects were moved. |
59 CcTest::CollectGarbage(NEW_SPACE); | 59 CcTest::CollectGarbage(NEW_SPACE); |
60 CHECK_EQ(table->NumberOfElements(), 1); | 60 CHECK_EQ(1, table->NumberOfElements()); |
61 CHECK_EQ(table->Lookup(a), *b); | 61 CHECK_EQ(table->Lookup(a), *b); |
62 CHECK_EQ(table->Lookup(b), CcTest::heap()->the_hole_value()); | 62 CHECK_EQ(table->Lookup(b), CcTest::heap()->the_hole_value()); |
63 | 63 |
64 // Keys that are overwritten should not change number of elements. | 64 // Keys that are overwritten should not change number of elements. |
65 table = HashMap::Put(table, a, factory->NewJSArray(13)); | 65 table = HashMap::Put(table, a, factory->NewJSArray(13)); |
66 CHECK_EQ(table->NumberOfElements(), 1); | 66 CHECK_EQ(1, table->NumberOfElements()); |
67 CHECK_NE(table->Lookup(a), *b); | 67 CHECK_NE(table->Lookup(a), *b); |
68 | 68 |
69 // Keys that have been removed are mapped to the hole. | 69 // Keys that have been removed are mapped to the hole. |
70 bool was_present = false; | 70 bool was_present = false; |
71 table = HashMap::Remove(table, a, &was_present); | 71 table = HashMap::Remove(table, a, &was_present); |
72 CHECK(was_present); | 72 CHECK(was_present); |
73 CHECK_EQ(table->NumberOfElements(), 0); | 73 CHECK_EQ(0, table->NumberOfElements()); |
74 CHECK_EQ(table->Lookup(a), CcTest::heap()->the_hole_value()); | 74 CHECK_EQ(table->Lookup(a), CcTest::heap()->the_hole_value()); |
75 | 75 |
76 // Keys should map back to their respective values and also should get | 76 // Keys should map back to their respective values and also should get |
77 // an identity hash code generated. | 77 // an identity hash code generated. |
78 for (int i = 0; i < 100; i++) { | 78 for (int i = 0; i < 100; i++) { |
79 Handle<JSReceiver> key = factory->NewJSArray(7); | 79 Handle<JSReceiver> key = factory->NewJSArray(7); |
80 Handle<JSObject> value = factory->NewJSArray(11); | 80 Handle<JSObject> value = factory->NewJSArray(11); |
81 table = HashMap::Put(table, key, value); | 81 table = HashMap::Put(table, key, value); |
82 CHECK_EQ(table->NumberOfElements(), i + 1); | 82 CHECK_EQ(table->NumberOfElements(), i + 1); |
83 CHECK_NE(table->FindEntry(key), HashMap::kNotFound); | 83 CHECK_NE(table->FindEntry(key), HashMap::kNotFound); |
(...skipping 30 matching lines...) Expand all Loading... |
114 } | 114 } |
115 | 115 |
116 template <typename HashSet> | 116 template <typename HashSet> |
117 static void TestHashSet(Handle<HashSet> table) { | 117 static void TestHashSet(Handle<HashSet> table) { |
118 Isolate* isolate = CcTest::i_isolate(); | 118 Isolate* isolate = CcTest::i_isolate(); |
119 Factory* factory = isolate->factory(); | 119 Factory* factory = isolate->factory(); |
120 | 120 |
121 Handle<JSObject> a = factory->NewJSArray(7); | 121 Handle<JSObject> a = factory->NewJSArray(7); |
122 Handle<JSObject> b = factory->NewJSArray(11); | 122 Handle<JSObject> b = factory->NewJSArray(11); |
123 table = HashSet::Add(table, a); | 123 table = HashSet::Add(table, a); |
124 CHECK_EQ(table->NumberOfElements(), 1); | 124 CHECK_EQ(1, table->NumberOfElements()); |
125 CHECK(table->Has(isolate, a)); | 125 CHECK(table->Has(isolate, a)); |
126 CHECK(!table->Has(isolate, b)); | 126 CHECK(!table->Has(isolate, b)); |
127 | 127 |
128 // Keys still have to be valid after objects were moved. | 128 // Keys still have to be valid after objects were moved. |
129 CcTest::CollectGarbage(NEW_SPACE); | 129 CcTest::CollectGarbage(NEW_SPACE); |
130 CHECK_EQ(table->NumberOfElements(), 1); | 130 CHECK_EQ(1, table->NumberOfElements()); |
131 CHECK(table->Has(isolate, a)); | 131 CHECK(table->Has(isolate, a)); |
132 CHECK(!table->Has(isolate, b)); | 132 CHECK(!table->Has(isolate, b)); |
133 | 133 |
134 // Keys that are overwritten should not change number of elements. | 134 // Keys that are overwritten should not change number of elements. |
135 table = HashSet::Add(table, a); | 135 table = HashSet::Add(table, a); |
136 CHECK_EQ(table->NumberOfElements(), 1); | 136 CHECK_EQ(1, table->NumberOfElements()); |
137 CHECK(table->Has(isolate, a)); | 137 CHECK(table->Has(isolate, a)); |
138 CHECK(!table->Has(isolate, b)); | 138 CHECK(!table->Has(isolate, b)); |
139 | 139 |
140 // Keys that have been removed are mapped to the hole. | 140 // Keys that have been removed are mapped to the hole. |
141 // TODO(cbruni): not implemented yet. | 141 // TODO(cbruni): not implemented yet. |
142 // bool was_present = false; | 142 // bool was_present = false; |
143 // table = HashSet::Remove(table, a, &was_present); | 143 // table = HashSet::Remove(table, a, &was_present); |
144 // CHECK(was_present); | 144 // CHECK(was_present); |
145 // CHECK_EQ(table->NumberOfElements(), 0); | 145 // CHECK_EQ(0, table->NumberOfElements()); |
146 // CHECK(!table->Has(a)); | 146 // CHECK(!table->Has(a)); |
147 // CHECK(!table->Has(b)); | 147 // CHECK(!table->Has(b)); |
148 | 148 |
149 // Keys should map back to their respective values and also should get | 149 // Keys should map back to their respective values and also should get |
150 // an identity hash code generated. | 150 // an identity hash code generated. |
151 for (int i = 0; i < 100; i++) { | 151 for (int i = 0; i < 100; i++) { |
152 Handle<JSReceiver> key = factory->NewJSArray(7); | 152 Handle<JSReceiver> key = factory->NewJSArray(7); |
153 table = HashSet::Add(table, key); | 153 table = HashSet::Add(table, key); |
154 CHECK_EQ(table->NumberOfElements(), i + 2); | 154 CHECK_EQ(table->NumberOfElements(), i + 2); |
155 CHECK(table->Has(isolate, key)); | 155 CHECK(table->Has(isolate, key)); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 dict->SetRequiresCopyOnCapacityChange(); | 304 dict->SetRequiresCopyOnCapacityChange(); |
305 Handle<Name> key = isolate->factory()->InternalizeString( | 305 Handle<Name> key = isolate->factory()->InternalizeString( |
306 v8::Utils::OpenHandle(*v8_str("key"))); | 306 v8::Utils::OpenHandle(*v8_str("key"))); |
307 Handle<Object> value = handle(Smi::kZero, isolate); | 307 Handle<Object> value = handle(Smi::kZero, isolate); |
308 Handle<NameDictionary> new_dict = | 308 Handle<NameDictionary> new_dict = |
309 NameDictionary::Add(dict, key, value, PropertyDetails::Empty()); | 309 NameDictionary::Add(dict, key, value, PropertyDetails::Empty()); |
310 CHECK_NE(*dict, *new_dict); | 310 CHECK_NE(*dict, *new_dict); |
311 } | 311 } |
312 | 312 |
313 } // namespace | 313 } // namespace |
OLD | NEW |