Line data Source code
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
3 : // found in the LICENSE file.
4 :
5 : #include "src/runtime/runtime-utils.h"
6 :
7 : #include "src/arguments.h"
8 : #include "src/conversions-inl.h"
9 : #include "src/factory.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 :
14 24 : RUNTIME_FUNCTION(Runtime_TheHole) {
15 : SealHandleScope shs(isolate);
16 : DCHECK_EQ(0, args.length());
17 12 : return isolate->heap()->the_hole_value();
18 : }
19 :
20 1692 : RUNTIME_FUNCTION(Runtime_GetExistingHash) {
21 : SealHandleScope shs(isolate);
22 : DCHECK_EQ(1, args.length());
23 846 : CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
24 846 : return object->GetHash();
25 : }
26 :
27 2822 : RUNTIME_FUNCTION(Runtime_GenericHash) {
28 1411 : HandleScope scope(isolate);
29 : DCHECK_EQ(1, args.length());
30 1411 : CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
31 1411 : return object->GetOrCreateHash(isolate);
32 : }
33 :
34 17906 : RUNTIME_FUNCTION(Runtime_SetGrow) {
35 8953 : HandleScope scope(isolate);
36 : DCHECK_EQ(1, args.length());
37 17906 : CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
38 8953 : Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()));
39 8953 : table = OrderedHashSet::EnsureGrowable(table);
40 8953 : holder->set_table(*table);
41 8953 : return isolate->heap()->undefined_value();
42 : }
43 :
44 :
45 1604 : RUNTIME_FUNCTION(Runtime_SetShrink) {
46 802 : HandleScope scope(isolate);
47 : DCHECK_EQ(1, args.length());
48 1604 : CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
49 802 : Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()));
50 802 : table = OrderedHashSet::Shrink(table);
51 802 : holder->set_table(*table);
52 802 : return isolate->heap()->undefined_value();
53 : }
54 :
55 0 : RUNTIME_FUNCTION(Runtime_SetIteratorClone) {
56 0 : HandleScope scope(isolate);
57 : DCHECK_EQ(1, args.length());
58 0 : CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0);
59 : return *isolate->factory()->NewJSSetIterator(
60 : handle(holder->map(), isolate),
61 : handle(OrderedHashSet::cast(holder->table()), isolate),
62 0 : Smi::ToInt(holder->index()));
63 : }
64 :
65 268626 : RUNTIME_FUNCTION(Runtime_MapShrink) {
66 134313 : HandleScope scope(isolate);
67 : DCHECK_EQ(1, args.length());
68 268626 : CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
69 134313 : Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()));
70 134313 : table = OrderedHashMap::Shrink(table);
71 134313 : holder->set_table(*table);
72 134313 : return isolate->heap()->undefined_value();
73 : }
74 :
75 5222 : RUNTIME_FUNCTION(Runtime_MapGrow) {
76 2611 : HandleScope scope(isolate);
77 : DCHECK_EQ(1, args.length());
78 5222 : CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
79 2611 : Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()));
80 2611 : table = OrderedHashMap::EnsureGrowable(table);
81 2611 : holder->set_table(*table);
82 2611 : return isolate->heap()->undefined_value();
83 : }
84 :
85 0 : RUNTIME_FUNCTION(Runtime_MapIteratorClone) {
86 0 : HandleScope scope(isolate);
87 : DCHECK_EQ(1, args.length());
88 0 : CONVERT_ARG_HANDLE_CHECKED(JSMapIterator, holder, 0);
89 : return *isolate->factory()->NewJSMapIterator(
90 : handle(holder->map(), isolate),
91 : handle(OrderedHashMap::cast(holder->table()), isolate),
92 0 : Smi::ToInt(holder->index()));
93 : }
94 :
95 0 : RUNTIME_FUNCTION(Runtime_GetWeakMapEntries) {
96 0 : HandleScope scope(isolate);
97 : DCHECK_EQ(2, args.length());
98 0 : CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0);
99 0 : CONVERT_NUMBER_CHECKED(int, max_entries, Int32, args[1]);
100 0 : CHECK_GE(max_entries, 0);
101 0 : return *JSWeakCollection::GetEntries(holder, max_entries);
102 : }
103 :
104 166328 : RUNTIME_FUNCTION(Runtime_WeakCollectionInitialize) {
105 83164 : HandleScope scope(isolate);
106 : DCHECK_EQ(1, args.length());
107 166328 : CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
108 83164 : JSWeakCollection::Initialize(weak_collection, isolate);
109 83164 : return *weak_collection;
110 : }
111 :
112 :
113 144 : RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
114 72 : HandleScope scope(isolate);
115 : DCHECK_EQ(3, args.length());
116 144 : CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
117 72 : CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
118 144 : CONVERT_SMI_ARG_CHECKED(hash, 2)
119 72 : CHECK(key->IsJSReceiver() || key->IsSymbol());
120 : Handle<ObjectHashTable> table(
121 72 : ObjectHashTable::cast(weak_collection->table()));
122 72 : CHECK(table->IsKey(isolate, *key));
123 72 : bool was_present = JSWeakCollection::Delete(weak_collection, key, hash);
124 72 : return isolate->heap()->ToBoolean(was_present);
125 : }
126 :
127 :
128 2822 : RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
129 1411 : HandleScope scope(isolate);
130 : DCHECK_EQ(4, args.length());
131 2822 : CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
132 1411 : CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
133 1411 : CHECK(key->IsJSReceiver() || key->IsSymbol());
134 1411 : CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
135 2822 : CONVERT_SMI_ARG_CHECKED(hash, 3)
136 : Handle<ObjectHashTable> table(
137 1411 : ObjectHashTable::cast(weak_collection->table()));
138 1411 : CHECK(table->IsKey(isolate, *key));
139 1411 : JSWeakCollection::Set(weak_collection, key, value, hash);
140 1411 : return *weak_collection;
141 : }
142 :
143 :
144 0 : RUNTIME_FUNCTION(Runtime_GetWeakSetValues) {
145 0 : HandleScope scope(isolate);
146 : DCHECK_EQ(2, args.length());
147 0 : CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0);
148 0 : CONVERT_NUMBER_CHECKED(int, max_values, Int32, args[1]);
149 0 : CHECK_GE(max_values, 0);
150 0 : return *JSWeakCollection::GetEntries(holder, max_values);
151 : }
152 :
153 0 : RUNTIME_FUNCTION(Runtime_IsJSMap) {
154 : SealHandleScope shs(isolate);
155 : DCHECK_EQ(1, args.length());
156 0 : CONVERT_ARG_CHECKED(Object, obj, 0);
157 0 : return isolate->heap()->ToBoolean(obj->IsJSMap());
158 : }
159 :
160 0 : RUNTIME_FUNCTION(Runtime_IsJSSet) {
161 : SealHandleScope shs(isolate);
162 : DCHECK_EQ(1, args.length());
163 0 : CONVERT_ARG_CHECKED(Object, obj, 0);
164 0 : return isolate->heap()->ToBoolean(obj->IsJSSet());
165 : }
166 :
167 0 : RUNTIME_FUNCTION(Runtime_IsJSWeakMap) {
168 : SealHandleScope shs(isolate);
169 : DCHECK_EQ(1, args.length());
170 0 : CONVERT_ARG_CHECKED(Object, obj, 0);
171 0 : return isolate->heap()->ToBoolean(obj->IsJSWeakMap());
172 : }
173 :
174 0 : RUNTIME_FUNCTION(Runtime_IsJSWeakSet) {
175 : SealHandleScope shs(isolate);
176 : DCHECK_EQ(1, args.length());
177 0 : CONVERT_ARG_CHECKED(Object, obj, 0);
178 0 : return isolate->heap()->ToBoolean(obj->IsJSWeakSet());
179 : }
180 :
181 : } // namespace internal
182 : } // namespace v8
|