| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 | 1414 |
| 1415 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapGetSize) { | 1415 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapGetSize) { |
| 1416 HandleScope scope(isolate); | 1416 HandleScope scope(isolate); |
| 1417 ASSERT(args.length() == 1); | 1417 ASSERT(args.length() == 1); |
| 1418 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); | 1418 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); |
| 1419 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); | 1419 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); |
| 1420 return Smi::FromInt(table->NumberOfElements()); | 1420 return Smi::FromInt(table->NumberOfElements()); |
| 1421 } | 1421 } |
| 1422 | 1422 |
| 1423 | 1423 |
| 1424 static JSWeakMap* WeakMapInitialize(Isolate* isolate, | 1424 static WeakCollection* WeakCollectionInitialize(Isolate* isolate, |
| 1425 Handle<JSWeakMap> weakmap) { | 1425 Handle<WeakCollection> weak_collection) { |
| 1426 ASSERT(weakmap->map()->inobject_properties() == 0); | 1426 ASSERT(weak_collection->map()->inobject_properties() == 0); |
| 1427 Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0); | 1427 Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0); |
| 1428 weakmap->set_table(*table); | 1428 weak_collection->set_table(*table); |
| 1429 weakmap->set_next(Smi::FromInt(0)); | 1429 weak_collection->set_next(Smi::FromInt(0)); |
| 1430 return *weakmap; | 1430 return *weak_collection; |
| 1431 } | 1431 } |
| 1432 | 1432 |
| 1433 | 1433 |
| 1434 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapInitialize) { | 1434 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionInitialize) { |
| 1435 HandleScope scope(isolate); | 1435 HandleScope scope(isolate); |
| 1436 ASSERT(args.length() == 1); | 1436 ASSERT(args.length() == 1); |
| 1437 CONVERT_ARG_HANDLE_CHECKED(JSWeakMap, weakmap, 0); | 1437 CONVERT_ARG_HANDLE_CHECKED(WeakCollection, weak_collection, 0); |
| 1438 return WeakMapInitialize(isolate, weakmap); | 1438 return WeakCollectionInitialize(isolate, weak_collection); |
| 1439 } | 1439 } |
| 1440 | 1440 |
| 1441 | 1441 |
| 1442 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapGet) { | 1442 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionGet) { |
| 1443 HandleScope scope(isolate); | 1443 HandleScope scope(isolate); |
| 1444 ASSERT(args.length() == 2); | 1444 ASSERT(args.length() == 2); |
| 1445 CONVERT_ARG_HANDLE_CHECKED(JSWeakMap, weakmap, 0); | 1445 CONVERT_ARG_HANDLE_CHECKED(WeakCollection, weak_collection, 0); |
| 1446 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 1446 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| 1447 Handle<ObjectHashTable> table(ObjectHashTable::cast(weakmap->table())); | 1447 Handle<ObjectHashTable> table( |
| 1448 ObjectHashTable::cast(weak_collection->table())); |
| 1448 Handle<Object> lookup(table->Lookup(*key), isolate); | 1449 Handle<Object> lookup(table->Lookup(*key), isolate); |
| 1449 return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup; | 1450 return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup; |
| 1450 } | 1451 } |
| 1451 | 1452 |
| 1452 | 1453 |
| 1453 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapHas) { | 1454 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionHas) { |
| 1454 HandleScope scope(isolate); | 1455 HandleScope scope(isolate); |
| 1455 ASSERT(args.length() == 2); | 1456 ASSERT(args.length() == 2); |
| 1456 CONVERT_ARG_HANDLE_CHECKED(JSWeakMap, weakmap, 0); | 1457 CONVERT_ARG_HANDLE_CHECKED(WeakCollection, weak_collection, 0); |
| 1457 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 1458 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| 1458 Handle<ObjectHashTable> table(ObjectHashTable::cast(weakmap->table())); | 1459 Handle<ObjectHashTable> table( |
| 1460 ObjectHashTable::cast(weak_collection->table())); |
| 1459 Handle<Object> lookup(table->Lookup(*key), isolate); | 1461 Handle<Object> lookup(table->Lookup(*key), isolate); |
| 1460 return isolate->heap()->ToBoolean(!lookup->IsTheHole()); | 1462 return isolate->heap()->ToBoolean(!lookup->IsTheHole()); |
| 1461 } | 1463 } |
| 1462 | 1464 |
| 1463 | 1465 |
| 1464 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapDelete) { | 1466 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionDelete) { |
| 1465 HandleScope scope(isolate); | 1467 HandleScope scope(isolate); |
| 1466 ASSERT(args.length() == 2); | 1468 ASSERT(args.length() == 2); |
| 1467 CONVERT_ARG_HANDLE_CHECKED(JSWeakMap, weakmap, 0); | 1469 CONVERT_ARG_HANDLE_CHECKED(WeakCollection, weak_collection, 0); |
| 1468 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 1470 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| 1469 Handle<ObjectHashTable> table(ObjectHashTable::cast(weakmap->table())); | 1471 Handle<ObjectHashTable> table(ObjectHashTable::cast( |
| 1472 weak_collection->table())); |
| 1470 Handle<Object> lookup(table->Lookup(*key), isolate); | 1473 Handle<Object> lookup(table->Lookup(*key), isolate); |
| 1471 Handle<ObjectHashTable> new_table = | 1474 Handle<ObjectHashTable> new_table = |
| 1472 PutIntoObjectHashTable(table, key, isolate->factory()->the_hole_value()); | 1475 PutIntoObjectHashTable(table, key, isolate->factory()->the_hole_value()); |
| 1473 weakmap->set_table(*new_table); | 1476 weak_collection->set_table(*new_table); |
| 1474 return isolate->heap()->ToBoolean(!lookup->IsTheHole()); | 1477 return isolate->heap()->ToBoolean(!lookup->IsTheHole()); |
| 1475 } | 1478 } |
| 1476 | 1479 |
| 1477 | 1480 |
| 1478 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapSet) { | 1481 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionSet) { |
| 1479 HandleScope scope(isolate); | 1482 HandleScope scope(isolate); |
| 1480 ASSERT(args.length() == 3); | 1483 ASSERT(args.length() == 3); |
| 1481 CONVERT_ARG_HANDLE_CHECKED(JSWeakMap, weakmap, 0); | 1484 CONVERT_ARG_HANDLE_CHECKED(WeakCollection, weak_collection, 0); |
| 1482 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 1485 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| 1483 Handle<Object> value(args[2], isolate); | 1486 Handle<Object> value(args[2], isolate); |
| 1484 Handle<ObjectHashTable> table(ObjectHashTable::cast(weakmap->table())); | 1487 Handle<ObjectHashTable> table( |
| 1488 ObjectHashTable::cast(weak_collection->table())); |
| 1485 Handle<ObjectHashTable> new_table = PutIntoObjectHashTable(table, key, value); | 1489 Handle<ObjectHashTable> new_table = PutIntoObjectHashTable(table, key, value); |
| 1486 weakmap->set_table(*new_table); | 1490 weak_collection->set_table(*new_table); |
| 1487 return isolate->heap()->undefined_value(); | 1491 return isolate->heap()->undefined_value(); |
| 1488 } | 1492 } |
| 1489 | 1493 |
| 1490 | 1494 |
| 1491 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClassOf) { | 1495 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClassOf) { |
| 1492 SealHandleScope shs(isolate); | 1496 SealHandleScope shs(isolate); |
| 1493 ASSERT(args.length() == 1); | 1497 ASSERT(args.length() == 1); |
| 1494 Object* obj = args[0]; | 1498 Object* obj = args[0]; |
| 1495 if (!obj->IsJSObject()) return isolate->heap()->null_value(); | 1499 if (!obj->IsJSObject()) return isolate->heap()->null_value(); |
| 1496 return JSObject::cast(obj)->class_name(); | 1500 return JSObject::cast(obj)->class_name(); |
| (...skipping 12283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13780 RUNTIME_FUNCTION(MaybeObject*, Runtime_ObservationWeakMapCreate) { | 13784 RUNTIME_FUNCTION(MaybeObject*, Runtime_ObservationWeakMapCreate) { |
| 13781 HandleScope scope(isolate); | 13785 HandleScope scope(isolate); |
| 13782 ASSERT(args.length() == 0); | 13786 ASSERT(args.length() == 0); |
| 13783 // TODO(adamk): Currently this runtime function is only called three times per | 13787 // TODO(adamk): Currently this runtime function is only called three times per |
| 13784 // isolate. If it's called more often, the map should be moved into the | 13788 // isolate. If it's called more often, the map should be moved into the |
| 13785 // strong root list. | 13789 // strong root list. |
| 13786 Handle<Map> map = | 13790 Handle<Map> map = |
| 13787 isolate->factory()->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); | 13791 isolate->factory()->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); |
| 13788 Handle<JSWeakMap> weakmap = | 13792 Handle<JSWeakMap> weakmap = |
| 13789 Handle<JSWeakMap>::cast(isolate->factory()->NewJSObjectFromMap(map)); | 13793 Handle<JSWeakMap>::cast(isolate->factory()->NewJSObjectFromMap(map)); |
| 13790 return WeakMapInitialize(isolate, weakmap); | 13794 return WeakCollectionInitialize(isolate, weakmap); |
| 13791 } | 13795 } |
| 13792 | 13796 |
| 13793 | 13797 |
| 13794 RUNTIME_FUNCTION(MaybeObject*, Runtime_UnwrapGlobalProxy) { | 13798 RUNTIME_FUNCTION(MaybeObject*, Runtime_UnwrapGlobalProxy) { |
| 13795 SealHandleScope shs(isolate); | 13799 SealHandleScope shs(isolate); |
| 13796 ASSERT(args.length() == 1); | 13800 ASSERT(args.length() == 1); |
| 13797 Object* object = args[0]; | 13801 Object* object = args[0]; |
| 13798 if (object->IsJSGlobalProxy()) { | 13802 if (object->IsJSGlobalProxy()) { |
| 13799 object = object->GetPrototype(isolate); | 13803 object = object->GetPrototype(isolate); |
| 13800 if (object->IsNull()) return isolate->heap()->undefined_value(); | 13804 if (object->IsNull()) return isolate->heap()->undefined_value(); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13985 // Handle last resort GC and make sure to allow future allocations | 13989 // Handle last resort GC and make sure to allow future allocations |
| 13986 // to grow the heap without causing GCs (if possible). | 13990 // to grow the heap without causing GCs (if possible). |
| 13987 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13991 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13988 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13992 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13989 "Runtime::PerformGC"); | 13993 "Runtime::PerformGC"); |
| 13990 } | 13994 } |
| 13991 } | 13995 } |
| 13992 | 13996 |
| 13993 | 13997 |
| 13994 } } // namespace v8::internal | 13998 } } // namespace v8::internal |
| OLD | NEW |