| 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 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 SealHandleScope shs(isolate); | 24 SealHandleScope shs(isolate); |
| 25 DCHECK(args.length() == 0); | 25 DCHECK(args.length() == 0); |
| 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(args.length() == 1); |
| 33 CONVERT_ARG_CHECKED(JSObject, object, 0); | 33 CONVERT_ARG_CHECKED(JSObject, object, 0); |
| 34 RUNTIME_ASSERT(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(args.length() == 1); |
| 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; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(args.length() == 3); |
| 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 RUNTIME_ASSERT(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::FromInt(0)); | 98 holder->set_index(Smi::FromInt(0)); |
| 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); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(args.length() == 3); |
| 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 RUNTIME_ASSERT(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::FromInt(0)); | 194 holder->set_index(Smi::FromInt(0)); |
| 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); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 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(args.length() == 2); |
| 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 RUNTIME_ASSERT(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); |
| 243 // Allocation can cause GC can delete weak elements. Reload. | 243 // Allocation can cause GC can delete weak elements. Reload. |
| 244 if (max_entries > table->NumberOfElements()) { | 244 if (max_entries > table->NumberOfElements()) { |
| 245 max_entries = table->NumberOfElements(); | 245 max_entries = table->NumberOfElements(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(args.length() == 3); |
| 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 RUNTIME_ASSERT(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 RUNTIME_ASSERT(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(args.length() == 3); |
| 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 RUNTIME_ASSERT(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 RUNTIME_ASSERT(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(args.length() == 3); |
| 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 RUNTIME_ASSERT(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 RUNTIME_ASSERT(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(args.length() == 4); |
| 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 RUNTIME_ASSERT(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 RUNTIME_ASSERT(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(args.length() == 2); |
| 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 RUNTIME_ASSERT(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 |