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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 Handle<JSObject> key, | 50 Handle<JSObject> key, |
51 Handle<Object> value) { | 51 Handle<Object> value) { |
52 Handle<ObjectHashTable> table = PutIntoObjectHashTable( | 52 Handle<ObjectHashTable> table = PutIntoObjectHashTable( |
53 Handle<ObjectHashTable>(ObjectHashTable::cast(weakmap->table())), | 53 Handle<ObjectHashTable>(ObjectHashTable::cast(weakmap->table())), |
54 Handle<JSObject>(JSObject::cast(*key)), | 54 Handle<JSObject>(JSObject::cast(*key)), |
55 value); | 55 value); |
56 weakmap->set_table(*table); | 56 weakmap->set_table(*table); |
57 } | 57 } |
58 | 58 |
59 static int NumberOfWeakCalls = 0; | 59 static int NumberOfWeakCalls = 0; |
60 static void WeakPointerCallback(v8::Persistent<v8::Value> handle, void* id) { | 60 static void WeakPointerCallback(v8::Isolate* isolate, |
| 61 v8::Persistent<v8::Value> handle, |
| 62 void* id) { |
61 ASSERT(id == reinterpret_cast<void*>(1234)); | 63 ASSERT(id == reinterpret_cast<void*>(1234)); |
62 NumberOfWeakCalls++; | 64 NumberOfWeakCalls++; |
63 handle.Dispose(); | 65 handle.Dispose(isolate); |
64 } | 66 } |
65 | 67 |
66 | 68 |
67 TEST(Weakness) { | 69 TEST(Weakness) { |
68 FLAG_incremental_marking = false; | 70 FLAG_incremental_marking = false; |
69 LocalContext context; | 71 LocalContext context; |
70 v8::HandleScope scope; | 72 v8::HandleScope scope; |
71 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(); | 73 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(); |
72 GlobalHandles* global_handles = Isolate::Current()->global_handles(); | 74 GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
73 | 75 |
(...skipping 21 matching lines...) Expand all Loading... |
95 CHECK_EQ(0, NumberOfWeakCalls); | 97 CHECK_EQ(0, NumberOfWeakCalls); |
96 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); | 98 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); |
97 CHECK_EQ( | 99 CHECK_EQ( |
98 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); | 100 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); |
99 | 101 |
100 // Make the global reference to the key weak. | 102 // Make the global reference to the key weak. |
101 { | 103 { |
102 v8::HandleScope scope; | 104 v8::HandleScope scope; |
103 global_handles->MakeWeak(key.location(), | 105 global_handles->MakeWeak(key.location(), |
104 reinterpret_cast<void*>(1234), | 106 reinterpret_cast<void*>(1234), |
| 107 NULL, |
105 &WeakPointerCallback); | 108 &WeakPointerCallback); |
106 } | 109 } |
107 CHECK(global_handles->IsWeak(key.location())); | 110 CHECK(global_handles->IsWeak(key.location())); |
108 | 111 |
109 // Force a full GC. | 112 // Force a full GC. |
110 // Perform two consecutive GCs because the first one will only clear | 113 // Perform two consecutive GCs because the first one will only clear |
111 // weak references whereas the second one will also clear weak maps. | 114 // weak references whereas the second one will also clear weak maps. |
112 HEAP->CollectAllGarbage(false); | 115 HEAP->CollectAllGarbage(false); |
113 CHECK_EQ(1, NumberOfWeakCalls); | 116 CHECK_EQ(1, NumberOfWeakCalls); |
114 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); | 117 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 PutIntoWeakMap(weakmap, keys[i], Handle<Smi>(Smi::FromInt(i))); | 221 PutIntoWeakMap(weakmap, keys[i], Handle<Smi>(Smi::FromInt(i))); |
219 } | 222 } |
220 | 223 |
221 // Force compacting garbage collection. The subsequent collections are used | 224 // Force compacting garbage collection. The subsequent collections are used |
222 // to verify that key references were actually updated. | 225 // to verify that key references were actually updated. |
223 CHECK(FLAG_always_compact); | 226 CHECK(FLAG_always_compact); |
224 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 227 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
225 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 228 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
226 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 229 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
227 } | 230 } |
OLD | NEW |