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

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

Issue 99193002: Remove all stuff marked as V8_DEPRECATED. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased. Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-weakmaps.cc ('k') | no next file » | 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <utility>
29
28 #include "v8.h" 30 #include "v8.h"
29 31
30 #include "global-handles.h" 32 #include "global-handles.h"
31 #include "snapshot.h" 33 #include "snapshot.h"
32 #include "cctest.h" 34 #include "cctest.h"
33 35
34 using namespace v8::internal; 36 using namespace v8::internal;
35 37
36 38
37 static Isolate* GetIsolateFrom(LocalContext* context) { 39 static Isolate* GetIsolateFrom(LocalContext* context) {
(...skipping 19 matching lines...) Expand all
57 Handle<JSObject> key, 59 Handle<JSObject> key,
58 Handle<Object> value) { 60 Handle<Object> value) {
59 Handle<ObjectHashTable> table = ObjectHashTable::Put( 61 Handle<ObjectHashTable> table = ObjectHashTable::Put(
60 Handle<ObjectHashTable>(ObjectHashTable::cast(weakset->table())), 62 Handle<ObjectHashTable>(ObjectHashTable::cast(weakset->table())),
61 Handle<JSObject>(JSObject::cast(*key)), 63 Handle<JSObject>(JSObject::cast(*key)),
62 value); 64 value);
63 weakset->set_table(*table); 65 weakset->set_table(*table);
64 } 66 }
65 67
66 static int NumberOfWeakCalls = 0; 68 static int NumberOfWeakCalls = 0;
67 static void WeakPointerCallback(v8::Isolate* isolate, 69 static void WeakPointerCallback(
68 v8::Persistent<v8::Value>* handle, 70 const v8::WeakCallbackData<v8::Value, void>& data) {
69 void* id) { 71 std::pair<v8::Persistent<v8::Value>*, int>* p =
70 ASSERT(id == reinterpret_cast<void*>(1234)); 72 reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
73 data.GetParameter());
74 ASSERT_EQ(1234, p->second);
71 NumberOfWeakCalls++; 75 NumberOfWeakCalls++;
72 handle->Reset(); 76 p->first->Reset();
73 } 77 }
74 78
75 79
76 TEST(WeakSet_Weakness) { 80 TEST(WeakSet_Weakness) {
77 FLAG_incremental_marking = false; 81 FLAG_incremental_marking = false;
78 LocalContext context; 82 LocalContext context;
79 Isolate* isolate = GetIsolateFrom(&context); 83 Isolate* isolate = GetIsolateFrom(&context);
80 Factory* factory = isolate->factory(); 84 Factory* factory = isolate->factory();
81 Heap* heap = isolate->heap(); 85 Heap* heap = isolate->heap();
82 HandleScope scope(isolate); 86 HandleScope scope(isolate);
(...skipping 22 matching lines...) Expand all
105 // Force a full GC. 109 // Force a full GC.
106 heap->CollectAllGarbage(false); 110 heap->CollectAllGarbage(false);
107 CHECK_EQ(0, NumberOfWeakCalls); 111 CHECK_EQ(0, NumberOfWeakCalls);
108 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements()); 112 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements());
109 CHECK_EQ( 113 CHECK_EQ(
110 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); 114 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
111 115
112 // Make the global reference to the key weak. 116 // Make the global reference to the key weak.
113 { 117 {
114 HandleScope scope(isolate); 118 HandleScope scope(isolate);
115 global_handles->MakeWeak(key.location(), 119 std::pair<Handle<Object>*, int> handle_and_id(&key, 1234);
116 reinterpret_cast<void*>(1234), 120 GlobalHandles::MakeWeak(key.location(),
117 &WeakPointerCallback); 121 reinterpret_cast<void*>(&handle_and_id),
122 &WeakPointerCallback);
118 } 123 }
119 CHECK(global_handles->IsWeak(key.location())); 124 CHECK(global_handles->IsWeak(key.location()));
120 125
121 // Force a full GC. 126 // Force a full GC.
122 // Perform two consecutive GCs because the first one will only clear 127 // Perform two consecutive GCs because the first one will only clear
123 // weak references whereas the second one will also clear weak sets. 128 // weak references whereas the second one will also clear weak sets.
124 heap->CollectAllGarbage(false); 129 heap->CollectAllGarbage(false);
125 CHECK_EQ(1, NumberOfWeakCalls); 130 CHECK_EQ(1, NumberOfWeakCalls);
126 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements()); 131 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements());
127 CHECK_EQ( 132 CHECK_EQ(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 Handle<Smi>(Smi::FromInt(i), isolate)); 246 Handle<Smi>(Smi::FromInt(i), isolate));
242 } 247 }
243 248
244 // Force compacting garbage collection. The subsequent collections are used 249 // Force compacting garbage collection. The subsequent collections are used
245 // to verify that key references were actually updated. 250 // to verify that key references were actually updated.
246 CHECK(FLAG_always_compact); 251 CHECK(FLAG_always_compact);
247 heap->CollectAllGarbage(Heap::kNoGCFlags); 252 heap->CollectAllGarbage(Heap::kNoGCFlags);
248 heap->CollectAllGarbage(Heap::kNoGCFlags); 253 heap->CollectAllGarbage(Heap::kNoGCFlags);
249 heap->CollectAllGarbage(Heap::kNoGCFlags); 254 heap->CollectAllGarbage(Heap::kNoGCFlags);
250 } 255 }
OLDNEW
« no previous file with comments | « test/cctest/test-weakmaps.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698