OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/conversions-inl.h" | 8 #include "src/conversions-inl.h" |
9 #include "src/factory.h" | 9 #include "src/factory.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 | 14 |
15 RUNTIME_FUNCTION(Runtime_StringGetRawHashField) { | 15 RUNTIME_FUNCTION(Runtime_StringGetRawHashField) { |
16 HandleScope scope(isolate); | 16 HandleScope scope(isolate); |
17 DCHECK(args.length() == 1); | 17 DCHECK_EQ(1, args.length()); |
18 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); | 18 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); |
19 return *isolate->factory()->NewNumberFromUint(string->hash_field()); | 19 return *isolate->factory()->NewNumberFromUint(string->hash_field()); |
20 } | 20 } |
21 | 21 |
22 | 22 |
23 RUNTIME_FUNCTION(Runtime_TheHole) { | 23 RUNTIME_FUNCTION(Runtime_TheHole) { |
24 SealHandleScope shs(isolate); | 24 SealHandleScope shs(isolate); |
25 DCHECK(args.length() == 0); | 25 DCHECK_EQ(0, args.length()); |
26 return isolate->heap()->the_hole_value(); | 26 return isolate->heap()->the_hole_value(); |
27 } | 27 } |
28 | 28 |
29 | 29 |
30 RUNTIME_FUNCTION(Runtime_JSCollectionGetTable) { | 30 RUNTIME_FUNCTION(Runtime_JSCollectionGetTable) { |
31 SealHandleScope shs(isolate); | 31 SealHandleScope shs(isolate); |
32 DCHECK(args.length() == 1); | 32 DCHECK_EQ(1, args.length()); |
33 CONVERT_ARG_CHECKED(JSObject, object, 0); | 33 CONVERT_ARG_CHECKED(JSObject, object, 0); |
34 CHECK(object->IsJSSet() || object->IsJSMap()); | 34 CHECK(object->IsJSSet() || object->IsJSMap()); |
35 return static_cast<JSCollection*>(object)->table(); | 35 return static_cast<JSCollection*>(object)->table(); |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 RUNTIME_FUNCTION(Runtime_GenericHash) { | 39 RUNTIME_FUNCTION(Runtime_GenericHash) { |
40 HandleScope scope(isolate); | 40 HandleScope scope(isolate); |
41 DCHECK(args.length() == 1); | 41 DCHECK_EQ(1, args.length()); |
42 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 42 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
43 Smi* hash = Object::GetOrCreateHash(isolate, object); | 43 Smi* hash = Object::GetOrCreateHash(isolate, object); |
44 return hash; | 44 return hash; |
45 } | 45 } |
46 | 46 |
47 | 47 |
48 RUNTIME_FUNCTION(Runtime_SetInitialize) { | 48 RUNTIME_FUNCTION(Runtime_SetInitialize) { |
49 HandleScope scope(isolate); | 49 HandleScope scope(isolate); |
50 DCHECK(args.length() == 1); | 50 DCHECK_EQ(1, args.length()); |
51 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); | 51 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); |
52 JSSet::Initialize(holder, isolate); | 52 JSSet::Initialize(holder, isolate); |
53 return *holder; | 53 return *holder; |
54 } | 54 } |
55 | 55 |
56 | 56 |
57 RUNTIME_FUNCTION(Runtime_SetGrow) { | 57 RUNTIME_FUNCTION(Runtime_SetGrow) { |
58 HandleScope scope(isolate); | 58 HandleScope scope(isolate); |
59 DCHECK(args.length() == 1); | 59 DCHECK_EQ(1, args.length()); |
60 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); | 60 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); |
61 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table())); | 61 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table())); |
62 table = OrderedHashSet::EnsureGrowable(table); | 62 table = OrderedHashSet::EnsureGrowable(table); |
63 holder->set_table(*table); | 63 holder->set_table(*table); |
64 return isolate->heap()->undefined_value(); | 64 return isolate->heap()->undefined_value(); |
65 } | 65 } |
66 | 66 |
67 | 67 |
68 RUNTIME_FUNCTION(Runtime_SetShrink) { | 68 RUNTIME_FUNCTION(Runtime_SetShrink) { |
69 HandleScope scope(isolate); | 69 HandleScope scope(isolate); |
70 DCHECK(args.length() == 1); | 70 DCHECK_EQ(1, args.length()); |
71 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); | 71 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); |
72 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table())); | 72 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table())); |
73 table = OrderedHashSet::Shrink(table); | 73 table = OrderedHashSet::Shrink(table); |
74 holder->set_table(*table); | 74 holder->set_table(*table); |
75 return isolate->heap()->undefined_value(); | 75 return isolate->heap()->undefined_value(); |
76 } | 76 } |
77 | 77 |
78 | 78 |
79 RUNTIME_FUNCTION(Runtime_SetClear) { | 79 RUNTIME_FUNCTION(Runtime_SetClear) { |
80 HandleScope scope(isolate); | 80 HandleScope scope(isolate); |
81 DCHECK(args.length() == 1); | 81 DCHECK_EQ(1, args.length()); |
82 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); | 82 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); |
83 JSSet::Clear(holder); | 83 JSSet::Clear(holder); |
84 return isolate->heap()->undefined_value(); | 84 return isolate->heap()->undefined_value(); |
85 } | 85 } |
86 | 86 |
87 | 87 |
88 RUNTIME_FUNCTION(Runtime_SetIteratorInitialize) { | 88 RUNTIME_FUNCTION(Runtime_SetIteratorInitialize) { |
89 HandleScope scope(isolate); | 89 HandleScope scope(isolate); |
90 DCHECK(args.length() == 3); | 90 DCHECK_EQ(3, args.length()); |
91 CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0); | 91 CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0); |
92 CONVERT_ARG_HANDLE_CHECKED(JSSet, set, 1); | 92 CONVERT_ARG_HANDLE_CHECKED(JSSet, set, 1); |
93 CONVERT_SMI_ARG_CHECKED(kind, 2) | 93 CONVERT_SMI_ARG_CHECKED(kind, 2) |
94 CHECK(kind == JSSetIterator::kKindValues || | 94 CHECK(kind == JSSetIterator::kKindValues || |
95 kind == JSSetIterator::kKindEntries); | 95 kind == JSSetIterator::kKindEntries); |
96 Handle<OrderedHashSet> table(OrderedHashSet::cast(set->table())); | 96 Handle<OrderedHashSet> table(OrderedHashSet::cast(set->table())); |
97 holder->set_table(*table); | 97 holder->set_table(*table); |
98 holder->set_index(Smi::kZero); | 98 holder->set_index(Smi::kZero); |
99 holder->set_kind(Smi::FromInt(kind)); | 99 holder->set_kind(Smi::FromInt(kind)); |
100 return isolate->heap()->undefined_value(); | 100 return isolate->heap()->undefined_value(); |
101 } | 101 } |
102 | 102 |
103 | 103 |
104 RUNTIME_FUNCTION(Runtime_SetIteratorClone) { | 104 RUNTIME_FUNCTION(Runtime_SetIteratorClone) { |
105 HandleScope scope(isolate); | 105 HandleScope scope(isolate); |
106 DCHECK(args.length() == 1); | 106 DCHECK_EQ(1, args.length()); |
107 CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0); | 107 CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0); |
108 | 108 |
109 Handle<JSSetIterator> result = isolate->factory()->NewJSSetIterator(); | 109 Handle<JSSetIterator> result = isolate->factory()->NewJSSetIterator(); |
110 result->set_table(holder->table()); | 110 result->set_table(holder->table()); |
111 result->set_index(Smi::FromInt(Smi::cast(holder->index())->value())); | 111 result->set_index(Smi::FromInt(Smi::cast(holder->index())->value())); |
112 result->set_kind(Smi::FromInt(Smi::cast(holder->kind())->value())); | 112 result->set_kind(Smi::FromInt(Smi::cast(holder->kind())->value())); |
113 | 113 |
114 return *result; | 114 return *result; |
115 } | 115 } |
116 | 116 |
117 | 117 |
118 RUNTIME_FUNCTION(Runtime_SetIteratorNext) { | 118 RUNTIME_FUNCTION(Runtime_SetIteratorNext) { |
119 SealHandleScope shs(isolate); | 119 SealHandleScope shs(isolate); |
120 DCHECK(args.length() == 2); | 120 DCHECK_EQ(2, args.length()); |
121 CONVERT_ARG_CHECKED(JSSetIterator, holder, 0); | 121 CONVERT_ARG_CHECKED(JSSetIterator, holder, 0); |
122 CONVERT_ARG_CHECKED(JSArray, value_array, 1); | 122 CONVERT_ARG_CHECKED(JSArray, value_array, 1); |
123 return holder->Next(value_array); | 123 return holder->Next(value_array); |
124 } | 124 } |
125 | 125 |
126 | 126 |
127 // The array returned contains the following information: | 127 // The array returned contains the following information: |
128 // 0: HasMore flag | 128 // 0: HasMore flag |
129 // 1: Iteration index | 129 // 1: Iteration index |
130 // 2: Iteration kind | 130 // 2: Iteration kind |
131 RUNTIME_FUNCTION(Runtime_SetIteratorDetails) { | 131 RUNTIME_FUNCTION(Runtime_SetIteratorDetails) { |
132 HandleScope scope(isolate); | 132 HandleScope scope(isolate); |
133 DCHECK(args.length() == 1); | 133 DCHECK_EQ(1, args.length()); |
134 CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0); | 134 CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0); |
135 Handle<FixedArray> details = isolate->factory()->NewFixedArray(4); | 135 Handle<FixedArray> details = isolate->factory()->NewFixedArray(4); |
136 details->set(0, isolate->heap()->ToBoolean(holder->HasMore())); | 136 details->set(0, isolate->heap()->ToBoolean(holder->HasMore())); |
137 details->set(1, holder->index()); | 137 details->set(1, holder->index()); |
138 details->set(2, holder->kind()); | 138 details->set(2, holder->kind()); |
139 return *isolate->factory()->NewJSArrayWithElements(details); | 139 return *isolate->factory()->NewJSArrayWithElements(details); |
140 } | 140 } |
141 | 141 |
142 | 142 |
143 RUNTIME_FUNCTION(Runtime_MapInitialize) { | 143 RUNTIME_FUNCTION(Runtime_MapInitialize) { |
144 HandleScope scope(isolate); | 144 HandleScope scope(isolate); |
145 DCHECK(args.length() == 1); | 145 DCHECK_EQ(1, args.length()); |
146 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); | 146 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); |
147 JSMap::Initialize(holder, isolate); | 147 JSMap::Initialize(holder, isolate); |
148 return *holder; | 148 return *holder; |
149 } | 149 } |
150 | 150 |
151 | 151 |
152 RUNTIME_FUNCTION(Runtime_MapShrink) { | 152 RUNTIME_FUNCTION(Runtime_MapShrink) { |
153 HandleScope scope(isolate); | 153 HandleScope scope(isolate); |
154 DCHECK(args.length() == 1); | 154 DCHECK_EQ(1, args.length()); |
155 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); | 155 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); |
156 Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table())); | 156 Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table())); |
157 table = OrderedHashMap::Shrink(table); | 157 table = OrderedHashMap::Shrink(table); |
158 holder->set_table(*table); | 158 holder->set_table(*table); |
159 return isolate->heap()->undefined_value(); | 159 return isolate->heap()->undefined_value(); |
160 } | 160 } |
161 | 161 |
162 | 162 |
163 RUNTIME_FUNCTION(Runtime_MapClear) { | 163 RUNTIME_FUNCTION(Runtime_MapClear) { |
164 HandleScope scope(isolate); | 164 HandleScope scope(isolate); |
165 DCHECK(args.length() == 1); | 165 DCHECK_EQ(1, args.length()); |
166 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); | 166 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); |
167 JSMap::Clear(holder); | 167 JSMap::Clear(holder); |
168 return isolate->heap()->undefined_value(); | 168 return isolate->heap()->undefined_value(); |
169 } | 169 } |
170 | 170 |
171 | 171 |
172 RUNTIME_FUNCTION(Runtime_MapGrow) { | 172 RUNTIME_FUNCTION(Runtime_MapGrow) { |
173 HandleScope scope(isolate); | 173 HandleScope scope(isolate); |
174 DCHECK(args.length() == 1); | 174 DCHECK_EQ(1, args.length()); |
175 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); | 175 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); |
176 Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table())); | 176 Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table())); |
177 table = OrderedHashMap::EnsureGrowable(table); | 177 table = OrderedHashMap::EnsureGrowable(table); |
178 holder->set_table(*table); | 178 holder->set_table(*table); |
179 return isolate->heap()->undefined_value(); | 179 return isolate->heap()->undefined_value(); |
180 } | 180 } |
181 | 181 |
182 | 182 |
183 RUNTIME_FUNCTION(Runtime_MapIteratorInitialize) { | 183 RUNTIME_FUNCTION(Runtime_MapIteratorInitialize) { |
184 HandleScope scope(isolate); | 184 HandleScope scope(isolate); |
185 DCHECK(args.length() == 3); | 185 DCHECK_EQ(3, args.length()); |
186 CONVERT_ARG_HANDLE_CHECKED(JSMapIterator, holder, 0); | 186 CONVERT_ARG_HANDLE_CHECKED(JSMapIterator, holder, 0); |
187 CONVERT_ARG_HANDLE_CHECKED(JSMap, map, 1); | 187 CONVERT_ARG_HANDLE_CHECKED(JSMap, map, 1); |
188 CONVERT_SMI_ARG_CHECKED(kind, 2) | 188 CONVERT_SMI_ARG_CHECKED(kind, 2) |
189 CHECK(kind == JSMapIterator::kKindKeys || | 189 CHECK(kind == JSMapIterator::kKindKeys || |
190 kind == JSMapIterator::kKindValues || | 190 kind == JSMapIterator::kKindValues || |
191 kind == JSMapIterator::kKindEntries); | 191 kind == JSMapIterator::kKindEntries); |
192 Handle<OrderedHashMap> table(OrderedHashMap::cast(map->table())); | 192 Handle<OrderedHashMap> table(OrderedHashMap::cast(map->table())); |
193 holder->set_table(*table); | 193 holder->set_table(*table); |
194 holder->set_index(Smi::kZero); | 194 holder->set_index(Smi::kZero); |
195 holder->set_kind(Smi::FromInt(kind)); | 195 holder->set_kind(Smi::FromInt(kind)); |
196 return isolate->heap()->undefined_value(); | 196 return isolate->heap()->undefined_value(); |
197 } | 197 } |
198 | 198 |
199 | 199 |
200 RUNTIME_FUNCTION(Runtime_MapIteratorClone) { | 200 RUNTIME_FUNCTION(Runtime_MapIteratorClone) { |
201 HandleScope scope(isolate); | 201 HandleScope scope(isolate); |
202 DCHECK(args.length() == 1); | 202 DCHECK_EQ(1, args.length()); |
203 CONVERT_ARG_HANDLE_CHECKED(JSMapIterator, holder, 0); | 203 CONVERT_ARG_HANDLE_CHECKED(JSMapIterator, holder, 0); |
204 | 204 |
205 Handle<JSMapIterator> result = isolate->factory()->NewJSMapIterator(); | 205 Handle<JSMapIterator> result = isolate->factory()->NewJSMapIterator(); |
206 result->set_table(holder->table()); | 206 result->set_table(holder->table()); |
207 result->set_index(Smi::FromInt(Smi::cast(holder->index())->value())); | 207 result->set_index(Smi::FromInt(Smi::cast(holder->index())->value())); |
208 result->set_kind(Smi::FromInt(Smi::cast(holder->kind())->value())); | 208 result->set_kind(Smi::FromInt(Smi::cast(holder->kind())->value())); |
209 | 209 |
210 return *result; | 210 return *result; |
211 } | 211 } |
212 | 212 |
213 | 213 |
214 // The array returned contains the following information: | 214 // The array returned contains the following information: |
215 // 0: HasMore flag | 215 // 0: HasMore flag |
216 // 1: Iteration index | 216 // 1: Iteration index |
217 // 2: Iteration kind | 217 // 2: Iteration kind |
218 RUNTIME_FUNCTION(Runtime_MapIteratorDetails) { | 218 RUNTIME_FUNCTION(Runtime_MapIteratorDetails) { |
219 HandleScope scope(isolate); | 219 HandleScope scope(isolate); |
220 DCHECK(args.length() == 1); | 220 DCHECK_EQ(1, args.length()); |
221 CONVERT_ARG_HANDLE_CHECKED(JSMapIterator, holder, 0); | 221 CONVERT_ARG_HANDLE_CHECKED(JSMapIterator, holder, 0); |
222 Handle<FixedArray> details = isolate->factory()->NewFixedArray(4); | 222 Handle<FixedArray> details = isolate->factory()->NewFixedArray(4); |
223 details->set(0, isolate->heap()->ToBoolean(holder->HasMore())); | 223 details->set(0, isolate->heap()->ToBoolean(holder->HasMore())); |
224 details->set(1, holder->index()); | 224 details->set(1, holder->index()); |
225 details->set(2, holder->kind()); | 225 details->set(2, holder->kind()); |
226 return *isolate->factory()->NewJSArrayWithElements(details); | 226 return *isolate->factory()->NewJSArrayWithElements(details); |
227 } | 227 } |
228 | 228 |
229 | 229 |
230 RUNTIME_FUNCTION(Runtime_GetWeakMapEntries) { | 230 RUNTIME_FUNCTION(Runtime_GetWeakMapEntries) { |
231 HandleScope scope(isolate); | 231 HandleScope scope(isolate); |
232 DCHECK(args.length() == 2); | 232 DCHECK_EQ(2, args.length()); |
233 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); | 233 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); |
234 CONVERT_NUMBER_CHECKED(int, max_entries, Int32, args[1]); | 234 CONVERT_NUMBER_CHECKED(int, max_entries, Int32, args[1]); |
235 CHECK(max_entries >= 0); | 235 CHECK(max_entries >= 0); |
236 | 236 |
237 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); | 237 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); |
238 if (max_entries == 0 || max_entries > table->NumberOfElements()) { | 238 if (max_entries == 0 || max_entries > table->NumberOfElements()) { |
239 max_entries = table->NumberOfElements(); | 239 max_entries = table->NumberOfElements(); |
240 } | 240 } |
241 Handle<FixedArray> entries = | 241 Handle<FixedArray> entries = |
242 isolate->factory()->NewFixedArray(max_entries * 2); | 242 isolate->factory()->NewFixedArray(max_entries * 2); |
(...skipping 14 matching lines...) Expand all Loading... |
257 } | 257 } |
258 } | 258 } |
259 DCHECK_EQ(max_entries * 2, count); | 259 DCHECK_EQ(max_entries * 2, count); |
260 } | 260 } |
261 return *isolate->factory()->NewJSArrayWithElements(entries); | 261 return *isolate->factory()->NewJSArrayWithElements(entries); |
262 } | 262 } |
263 | 263 |
264 | 264 |
265 RUNTIME_FUNCTION(Runtime_MapIteratorNext) { | 265 RUNTIME_FUNCTION(Runtime_MapIteratorNext) { |
266 SealHandleScope shs(isolate); | 266 SealHandleScope shs(isolate); |
267 DCHECK(args.length() == 2); | 267 DCHECK_EQ(2, args.length()); |
268 CONVERT_ARG_CHECKED(JSMapIterator, holder, 0); | 268 CONVERT_ARG_CHECKED(JSMapIterator, holder, 0); |
269 CONVERT_ARG_CHECKED(JSArray, value_array, 1); | 269 CONVERT_ARG_CHECKED(JSArray, value_array, 1); |
270 return holder->Next(value_array); | 270 return holder->Next(value_array); |
271 } | 271 } |
272 | 272 |
273 | 273 |
274 RUNTIME_FUNCTION(Runtime_WeakCollectionInitialize) { | 274 RUNTIME_FUNCTION(Runtime_WeakCollectionInitialize) { |
275 HandleScope scope(isolate); | 275 HandleScope scope(isolate); |
276 DCHECK(args.length() == 1); | 276 DCHECK_EQ(1, args.length()); |
277 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); | 277 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); |
278 JSWeakCollection::Initialize(weak_collection, isolate); | 278 JSWeakCollection::Initialize(weak_collection, isolate); |
279 return *weak_collection; | 279 return *weak_collection; |
280 } | 280 } |
281 | 281 |
282 | 282 |
283 RUNTIME_FUNCTION(Runtime_WeakCollectionGet) { | 283 RUNTIME_FUNCTION(Runtime_WeakCollectionGet) { |
284 HandleScope scope(isolate); | 284 HandleScope scope(isolate); |
285 DCHECK(args.length() == 3); | 285 DCHECK_EQ(3, args.length()); |
286 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); | 286 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); |
287 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 287 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
288 CONVERT_SMI_ARG_CHECKED(hash, 2) | 288 CONVERT_SMI_ARG_CHECKED(hash, 2) |
289 CHECK(key->IsJSReceiver() || key->IsSymbol()); | 289 CHECK(key->IsJSReceiver() || key->IsSymbol()); |
290 Handle<ObjectHashTable> table( | 290 Handle<ObjectHashTable> table( |
291 ObjectHashTable::cast(weak_collection->table())); | 291 ObjectHashTable::cast(weak_collection->table())); |
292 CHECK(table->IsKey(isolate, *key)); | 292 CHECK(table->IsKey(isolate, *key)); |
293 Handle<Object> lookup(table->Lookup(key, hash), isolate); | 293 Handle<Object> lookup(table->Lookup(key, hash), isolate); |
294 return lookup->IsTheHole(isolate) ? isolate->heap()->undefined_value() | 294 return lookup->IsTheHole(isolate) ? isolate->heap()->undefined_value() |
295 : *lookup; | 295 : *lookup; |
296 } | 296 } |
297 | 297 |
298 | 298 |
299 RUNTIME_FUNCTION(Runtime_WeakCollectionHas) { | 299 RUNTIME_FUNCTION(Runtime_WeakCollectionHas) { |
300 HandleScope scope(isolate); | 300 HandleScope scope(isolate); |
301 DCHECK(args.length() == 3); | 301 DCHECK_EQ(3, args.length()); |
302 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); | 302 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); |
303 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 303 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
304 CONVERT_SMI_ARG_CHECKED(hash, 2) | 304 CONVERT_SMI_ARG_CHECKED(hash, 2) |
305 CHECK(key->IsJSReceiver() || key->IsSymbol()); | 305 CHECK(key->IsJSReceiver() || key->IsSymbol()); |
306 Handle<ObjectHashTable> table( | 306 Handle<ObjectHashTable> table( |
307 ObjectHashTable::cast(weak_collection->table())); | 307 ObjectHashTable::cast(weak_collection->table())); |
308 CHECK(table->IsKey(isolate, *key)); | 308 CHECK(table->IsKey(isolate, *key)); |
309 Handle<Object> lookup(table->Lookup(key, hash), isolate); | 309 Handle<Object> lookup(table->Lookup(key, hash), isolate); |
310 return isolate->heap()->ToBoolean(!lookup->IsTheHole(isolate)); | 310 return isolate->heap()->ToBoolean(!lookup->IsTheHole(isolate)); |
311 } | 311 } |
312 | 312 |
313 | 313 |
314 RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) { | 314 RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) { |
315 HandleScope scope(isolate); | 315 HandleScope scope(isolate); |
316 DCHECK(args.length() == 3); | 316 DCHECK_EQ(3, args.length()); |
317 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); | 317 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); |
318 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 318 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
319 CONVERT_SMI_ARG_CHECKED(hash, 2) | 319 CONVERT_SMI_ARG_CHECKED(hash, 2) |
320 CHECK(key->IsJSReceiver() || key->IsSymbol()); | 320 CHECK(key->IsJSReceiver() || key->IsSymbol()); |
321 Handle<ObjectHashTable> table( | 321 Handle<ObjectHashTable> table( |
322 ObjectHashTable::cast(weak_collection->table())); | 322 ObjectHashTable::cast(weak_collection->table())); |
323 CHECK(table->IsKey(isolate, *key)); | 323 CHECK(table->IsKey(isolate, *key)); |
324 bool was_present = JSWeakCollection::Delete(weak_collection, key, hash); | 324 bool was_present = JSWeakCollection::Delete(weak_collection, key, hash); |
325 return isolate->heap()->ToBoolean(was_present); | 325 return isolate->heap()->ToBoolean(was_present); |
326 } | 326 } |
327 | 327 |
328 | 328 |
329 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) { | 329 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) { |
330 HandleScope scope(isolate); | 330 HandleScope scope(isolate); |
331 DCHECK(args.length() == 4); | 331 DCHECK_EQ(4, args.length()); |
332 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); | 332 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); |
333 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 333 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
334 CHECK(key->IsJSReceiver() || key->IsSymbol()); | 334 CHECK(key->IsJSReceiver() || key->IsSymbol()); |
335 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 335 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
336 CONVERT_SMI_ARG_CHECKED(hash, 3) | 336 CONVERT_SMI_ARG_CHECKED(hash, 3) |
337 Handle<ObjectHashTable> table( | 337 Handle<ObjectHashTable> table( |
338 ObjectHashTable::cast(weak_collection->table())); | 338 ObjectHashTable::cast(weak_collection->table())); |
339 CHECK(table->IsKey(isolate, *key)); | 339 CHECK(table->IsKey(isolate, *key)); |
340 JSWeakCollection::Set(weak_collection, key, value, hash); | 340 JSWeakCollection::Set(weak_collection, key, value, hash); |
341 return *weak_collection; | 341 return *weak_collection; |
342 } | 342 } |
343 | 343 |
344 | 344 |
345 RUNTIME_FUNCTION(Runtime_GetWeakSetValues) { | 345 RUNTIME_FUNCTION(Runtime_GetWeakSetValues) { |
346 HandleScope scope(isolate); | 346 HandleScope scope(isolate); |
347 DCHECK(args.length() == 2); | 347 DCHECK_EQ(2, args.length()); |
348 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); | 348 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); |
349 CONVERT_NUMBER_CHECKED(int, max_values, Int32, args[1]); | 349 CONVERT_NUMBER_CHECKED(int, max_values, Int32, args[1]); |
350 CHECK(max_values >= 0); | 350 CHECK(max_values >= 0); |
351 | 351 |
352 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); | 352 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); |
353 if (max_values == 0 || max_values > table->NumberOfElements()) { | 353 if (max_values == 0 || max_values > table->NumberOfElements()) { |
354 max_values = table->NumberOfElements(); | 354 max_values = table->NumberOfElements(); |
355 } | 355 } |
356 Handle<FixedArray> values = isolate->factory()->NewFixedArray(max_values); | 356 Handle<FixedArray> values = isolate->factory()->NewFixedArray(max_values); |
357 // Recompute max_values because GC could have removed elements from the table. | 357 // Recompute max_values because GC could have removed elements from the table. |
358 if (max_values > table->NumberOfElements()) { | 358 if (max_values > table->NumberOfElements()) { |
359 max_values = table->NumberOfElements(); | 359 max_values = table->NumberOfElements(); |
360 } | 360 } |
361 { | 361 { |
362 DisallowHeapAllocation no_gc; | 362 DisallowHeapAllocation no_gc; |
363 int count = 0; | 363 int count = 0; |
364 for (int i = 0; count < max_values && i < table->Capacity(); i++) { | 364 for (int i = 0; count < max_values && i < table->Capacity(); i++) { |
365 Object* key = table->KeyAt(i); | 365 Object* key = table->KeyAt(i); |
366 if (table->IsKey(isolate, key)) values->set(count++, key); | 366 if (table->IsKey(isolate, key)) values->set(count++, key); |
367 } | 367 } |
368 DCHECK_EQ(max_values, count); | 368 DCHECK_EQ(max_values, count); |
369 } | 369 } |
370 return *isolate->factory()->NewJSArrayWithElements(values); | 370 return *isolate->factory()->NewJSArrayWithElements(values); |
371 } | 371 } |
372 } // namespace internal | 372 } // namespace internal |
373 } // namespace v8 | 373 } // namespace v8 |
OLD | NEW |