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

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

Issue 2655533004: [tests] Fix use-after-scope errors related to weak refs (Closed)
Patch Set: typo Created 3 years, 10 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/test-api.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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 104 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
105 105
106 // Force a full GC. 106 // Force a full GC.
107 CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 107 CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
108 CHECK_EQ(0, NumberOfWeakCalls); 108 CHECK_EQ(0, NumberOfWeakCalls);
109 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 109 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
110 CHECK_EQ( 110 CHECK_EQ(
111 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 111 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
112 112
113 // Make the global reference to the key weak. 113 // Make the global reference to the key weak.
114 { 114 std::pair<Handle<Object>*, int> handle_and_id(&key, 1234);
115 HandleScope scope(isolate); 115 GlobalHandles::MakeWeak(
116 std::pair<Handle<Object>*, int> handle_and_id(&key, 1234); 116 key.location(), reinterpret_cast<void*>(&handle_and_id),
117 GlobalHandles::MakeWeak( 117 &WeakPointerCallback, v8::WeakCallbackType::kParameter);
118 key.location(), reinterpret_cast<void*>(&handle_and_id),
119 &WeakPointerCallback, v8::WeakCallbackType::kParameter);
120 }
121 CHECK(global_handles->IsWeak(key.location())); 118 CHECK(global_handles->IsWeak(key.location()));
122 119
123 CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 120 CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
124 CHECK_EQ(1, NumberOfWeakCalls); 121 CHECK_EQ(1, NumberOfWeakCalls);
125 CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 122 CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
126 CHECK_EQ(2, 123 CHECK_EQ(2,
127 ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 124 ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
128 } 125 }
129 126
130 127
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 { 254 {
258 HandleScope scope(isolate); 255 HandleScope scope(isolate);
259 AllocateJSWeakMap(isolate); 256 AllocateJSWeakMap(isolate);
260 heap::SimulateIncrementalMarking(heap); 257 heap::SimulateIncrementalMarking(heap);
261 } 258 }
262 // The weak map is marked black here but leaving the handle scope will make 259 // The weak map is marked black here but leaving the handle scope will make
263 // the object unreachable. Aborting incremental marking will clear all the 260 // the object unreachable. Aborting incremental marking will clear all the
264 // marking bits which makes the weak map garbage. 261 // marking bits which makes the weak map garbage.
265 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask); 262 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask);
266 } 263 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-weaksets.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698