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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 template<typename HashMap> | 44 template<typename HashMap> |
45 static void TestHashMap(Handle<HashMap> table) { | 45 static void TestHashMap(Handle<HashMap> table) { |
46 Isolate* isolate = CcTest::i_isolate(); | 46 Isolate* isolate = CcTest::i_isolate(); |
47 Factory* factory = isolate->factory(); | 47 Factory* factory = isolate->factory(); |
48 | 48 |
49 Handle<JSObject> a = factory->NewJSArray(7); | 49 Handle<JSObject> a = factory->NewJSArray(7); |
50 Handle<JSObject> b = factory->NewJSArray(11); | 50 Handle<JSObject> b = factory->NewJSArray(11); |
51 table = HashMap::Put(table, a, b); | 51 table = HashMap::Put(table, a, b); |
52 CHECK_EQ(table->NumberOfElements(), 1); | 52 CHECK_EQ(table->NumberOfElements(), 1); |
53 CHECK_EQ(table->Lookup(a), *b); | 53 CHECK_EQ(table->Lookup(a), *b); |
| 54 // When the key does not exist in the map, Lookup returns the hole. |
54 CHECK_EQ(table->Lookup(b), CcTest::heap()->the_hole_value()); | 55 CHECK_EQ(table->Lookup(b), CcTest::heap()->the_hole_value()); |
55 | 56 |
56 // Keys still have to be valid after objects were moved. | 57 // Keys still have to be valid after objects were moved. |
57 CcTest::heap()->CollectGarbage(NEW_SPACE); | 58 CcTest::heap()->CollectGarbage(NEW_SPACE); |
58 CHECK_EQ(table->NumberOfElements(), 1); | 59 CHECK_EQ(table->NumberOfElements(), 1); |
59 CHECK_EQ(table->Lookup(a), *b); | 60 CHECK_EQ(table->Lookup(a), *b); |
60 CHECK_EQ(table->Lookup(b), CcTest::heap()->the_hole_value()); | 61 CHECK_EQ(table->Lookup(b), CcTest::heap()->the_hole_value()); |
61 | 62 |
62 // Keys that are overwritten should not change number of elements. | 63 // Keys that are overwritten should not change number of elements. |
63 table = HashMap::Put(table, a, factory->NewJSArray(13)); | 64 table = HashMap::Put(table, a, factory->NewJSArray(13)); |
64 CHECK_EQ(table->NumberOfElements(), 1); | 65 CHECK_EQ(table->NumberOfElements(), 1); |
65 CHECK_NE(table->Lookup(a), *b); | 66 CHECK_NE(table->Lookup(a), *b); |
66 | 67 |
67 // Keys mapped to the hole should be removed permanently. | 68 // Keys that have been removed are mapped to the hole. |
68 table = HashMap::Put(table, a, factory->the_hole_value()); | 69 bool was_present = false; |
| 70 table = HashMap::Remove(table, a, &was_present); |
| 71 CHECK(was_present); |
69 CHECK_EQ(table->NumberOfElements(), 0); | 72 CHECK_EQ(table->NumberOfElements(), 0); |
70 CHECK_EQ(table->Lookup(a), CcTest::heap()->the_hole_value()); | 73 CHECK_EQ(table->Lookup(a), CcTest::heap()->the_hole_value()); |
71 | 74 |
72 // Keys should map back to their respective values and also should get | 75 // Keys should map back to their respective values and also should get |
73 // an identity hash code generated. | 76 // an identity hash code generated. |
74 for (int i = 0; i < 100; i++) { | 77 for (int i = 0; i < 100; i++) { |
75 Handle<JSReceiver> key = factory->NewJSArray(7); | 78 Handle<JSReceiver> key = factory->NewJSArray(7); |
76 Handle<JSObject> value = factory->NewJSArray(11); | 79 Handle<JSObject> value = factory->NewJSArray(11); |
77 table = HashMap::Put(table, key, value); | 80 table = HashMap::Put(table, key, value); |
78 CHECK_EQ(table->NumberOfElements(), i + 1); | 81 CHECK_EQ(table->NumberOfElements(), i + 1); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 LocalContext context; | 245 LocalContext context; |
243 v8::HandleScope scope(context->GetIsolate()); | 246 v8::HandleScope scope(context->GetIsolate()); |
244 Isolate* isolate = CcTest::i_isolate(); | 247 Isolate* isolate = CcTest::i_isolate(); |
245 TestHashMapCausesGC(ObjectHashTable::New(isolate, 1)); | 248 TestHashMapCausesGC(ObjectHashTable::New(isolate, 1)); |
246 TestHashMapCausesGC(isolate->factory()->NewOrderedHashMap()); | 249 TestHashMapCausesGC(isolate->factory()->NewOrderedHashMap()); |
247 } | 250 } |
248 #endif | 251 #endif |
249 | 252 |
250 | 253 |
251 } | 254 } |
OLD | NEW |