Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: test/cctest/test-weakmaps.cc

Issue 1949393006: Remove deprecated uses of WeakCallbackData from tests. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/heap/test-mark-compact.cc ('k') | test/cctest/test-weaksets.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // Do not leak handles for the hash table, it would make entries strong. 45 // Do not leak handles for the hash table, it would make entries strong.
46 { 46 {
47 HandleScope scope(isolate); 47 HandleScope scope(isolate);
48 Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 1); 48 Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 1);
49 weakmap->set_table(*table); 49 weakmap->set_table(*table);
50 } 50 }
51 return weakmap; 51 return weakmap;
52 } 52 }
53 53
54 static int NumberOfWeakCalls = 0; 54 static int NumberOfWeakCalls = 0;
55 static void WeakPointerCallback( 55 static void WeakPointerCallback(const v8::WeakCallbackInfo<void>& data) {
56 const v8::WeakCallbackData<v8::Value, void>& data) {
57 std::pair<v8::Persistent<v8::Value>*, int>* p = 56 std::pair<v8::Persistent<v8::Value>*, int>* p =
58 reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>( 57 reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
59 data.GetParameter()); 58 data.GetParameter());
60 CHECK_EQ(1234, p->second); 59 CHECK_EQ(1234, p->second);
61 NumberOfWeakCalls++; 60 NumberOfWeakCalls++;
62 p->first->Reset(); 61 p->first->Reset();
63 } 62 }
64 63
65 64
66 TEST(Weakness) { 65 TEST(Weakness) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 heap->CollectAllGarbage(false); 99 heap->CollectAllGarbage(false);
101 CHECK_EQ(0, NumberOfWeakCalls); 100 CHECK_EQ(0, NumberOfWeakCalls);
102 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 101 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
103 CHECK_EQ( 102 CHECK_EQ(
104 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 103 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
105 104
106 // Make the global reference to the key weak. 105 // Make the global reference to the key weak.
107 { 106 {
108 HandleScope scope(isolate); 107 HandleScope scope(isolate);
109 std::pair<Handle<Object>*, int> handle_and_id(&key, 1234); 108 std::pair<Handle<Object>*, int> handle_and_id(&key, 1234);
110 GlobalHandles::MakeWeak(key.location(), 109 GlobalHandles::MakeWeak(
111 reinterpret_cast<void*>(&handle_and_id), 110 key.location(), reinterpret_cast<void*>(&handle_and_id),
112 &WeakPointerCallback); 111 &WeakPointerCallback, v8::WeakCallbackType::kParameter);
113 } 112 }
114 CHECK(global_handles->IsWeak(key.location())); 113 CHECK(global_handles->IsWeak(key.location()));
115 114
116 // Force a full GC.
117 // Perform two consecutive GCs because the first one will only clear
118 // weak references whereas the second one will also clear weak maps.
119 heap->CollectAllGarbage(false);
120 CHECK_EQ(1, NumberOfWeakCalls);
121 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
122 CHECK_EQ(
123 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
124 heap->CollectAllGarbage(false); 115 heap->CollectAllGarbage(false);
125 CHECK_EQ(1, NumberOfWeakCalls); 116 CHECK_EQ(1, NumberOfWeakCalls);
126 CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 117 CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
127 CHECK_EQ(2, 118 CHECK_EQ(2,
128 ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 119 ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
129 } 120 }
130 121
131 122
132 TEST(Shrinking) { 123 TEST(Shrinking) {
133 LocalContext context; 124 LocalContext context;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 { 249 {
259 HandleScope scope(isolate); 250 HandleScope scope(isolate);
260 AllocateJSWeakMap(isolate); 251 AllocateJSWeakMap(isolate);
261 SimulateIncrementalMarking(heap); 252 SimulateIncrementalMarking(heap);
262 } 253 }
263 // The weak map is marked black here but leaving the handle scope will make 254 // The weak map is marked black here but leaving the handle scope will make
264 // the object unreachable. Aborting incremental marking will clear all the 255 // the object unreachable. Aborting incremental marking will clear all the
265 // marking bits which makes the weak map garbage. 256 // marking bits which makes the weak map garbage.
266 heap->CollectAllGarbage(); 257 heap->CollectAllGarbage();
267 } 258 }
OLDNEW
« no previous file with comments | « test/cctest/heap/test-mark-compact.cc ('k') | test/cctest/test-weaksets.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698