5 #include "src/arguments-inl.h" 6 #include "src/conversions-inl.h" 7 #include "src/counters.h" 8 #include "src/heap/factory.h" 9 #include "src/objects/hash-table-inl.h" 10 #include "src/objects/js-collection-inl.h" 11 #include "src/runtime/runtime-utils.h" 16 RUNTIME_FUNCTION(Runtime_TheHole) {
17 SealHandleScope shs(isolate);
18 DCHECK_EQ(0, args.length());
19 return ReadOnlyRoots(isolate).the_hole_value();
22 RUNTIME_FUNCTION(Runtime_SetGrow) {
23 HandleScope scope(isolate);
24 DCHECK_EQ(1, args.length());
25 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
26 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()), isolate);
27 table = OrderedHashSet::EnsureGrowable(isolate, table);
28 holder->set_table(*table);
29 return ReadOnlyRoots(isolate).undefined_value();
33 RUNTIME_FUNCTION(Runtime_SetShrink) {
34 HandleScope scope(isolate);
35 DCHECK_EQ(1, args.length());
36 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
37 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()), isolate);
38 table = OrderedHashSet::Shrink(isolate, table);
39 holder->set_table(*table);
40 return ReadOnlyRoots(isolate).undefined_value();
43 RUNTIME_FUNCTION(Runtime_MapShrink) {
44 HandleScope scope(isolate);
45 DCHECK_EQ(1, args.length());
46 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
47 Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()), isolate);
48 table = OrderedHashMap::Shrink(isolate, table);
49 holder->set_table(*table);
50 return ReadOnlyRoots(isolate).undefined_value();
53 RUNTIME_FUNCTION(Runtime_MapGrow) {
54 HandleScope scope(isolate);
55 DCHECK_EQ(1, args.length());
56 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
57 Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()), isolate);
58 table = OrderedHashMap::EnsureGrowable(isolate, table);
59 holder->set_table(*table);
60 return ReadOnlyRoots(isolate).undefined_value();
63 RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
64 HandleScope scope(isolate);
65 DCHECK_EQ(3, args.length());
66 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
67 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
68 CONVERT_SMI_ARG_CHECKED(hash, 2)
71 DCHECK(key->IsJSReceiver());
72 DCHECK(EphemeronHashTableShape::IsLive(ReadOnlyRoots(isolate), *key));
73 Handle<EphemeronHashTable> table(
74 EphemeronHashTable::cast(weak_collection->table()), isolate);
77 DCHECK(table->NumberOfElements() - 1 <= (table->Capacity() >> 2) &&
78 table->NumberOfElements() - 1 >= 16);
81 bool was_present = JSWeakCollection::Delete(weak_collection, key, hash);
82 return isolate->heap()->ToBoolean(was_present);
85 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
86 HandleScope scope(isolate);
87 DCHECK_EQ(4, args.length());
88 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
89 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
90 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
91 CONVERT_SMI_ARG_CHECKED(hash, 3)
94 DCHECK(key->IsJSReceiver());
95 DCHECK(EphemeronHashTableShape::IsLive(ReadOnlyRoots(isolate), *key));
96 Handle<EphemeronHashTable> table(
97 EphemeronHashTable::cast(weak_collection->table()), isolate);
100 DCHECK((table->NumberOfDeletedElements() << 1) > table->NumberOfElements() ||
101 !table->HasSufficientCapacityToAdd(1));
104 JSWeakCollection::Set(weak_collection, key, value, hash);
105 return *weak_collection;