Line data Source code
1 : // Copyright 2017 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 : #ifndef V8_OBJECTS_JS_COLLECTION_H_
6 : #define V8_OBJECTS_JS_COLLECTION_H_
7 :
8 : #include "src/objects.h"
9 : #include "src/objects/ordered-hash-table.h"
10 :
11 : // Has to be the last include (doesn't have include guards):
12 : #include "src/objects/object-macros.h"
13 :
14 : namespace v8 {
15 : namespace internal {
16 :
17 : class JSCollection : public JSObject {
18 : public:
19 : // [table]: the backing hash table
20 : DECL_ACCESSORS(table, Object)
21 :
22 : // Layout description.
23 : #define JS_COLLECTION_FIELDS(V) \
24 : V(kTableOffset, kTaggedSize) \
25 : /* Header size. */ \
26 : V(kSize, 0)
27 :
28 : DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, JS_COLLECTION_FIELDS)
29 : #undef JS_COLLECTION_FIELDS
30 :
31 : static const int kAddFunctionDescriptorIndex = 3;
32 :
33 : OBJECT_CONSTRUCTORS(JSCollection, JSObject);
34 : };
35 :
36 : // The JSSet describes EcmaScript Harmony sets
37 : class JSSet : public JSCollection {
38 : public:
39 : DECL_CAST(JSSet)
40 :
41 : static void Initialize(Handle<JSSet> set, Isolate* isolate);
42 : static void Clear(Isolate* isolate, Handle<JSSet> set);
43 :
44 : // Dispatched behavior.
45 : DECL_PRINTER(JSSet)
46 : DECL_VERIFIER(JSSet)
47 :
48 334742 : OBJECT_CONSTRUCTORS(JSSet, JSCollection);
49 : };
50 :
51 : class JSSetIterator
52 : : public OrderedHashTableIterator<JSSetIterator, OrderedHashSet> {
53 : public:
54 : // Dispatched behavior.
55 : DECL_PRINTER(JSSetIterator)
56 : DECL_VERIFIER(JSSetIterator)
57 :
58 : DECL_CAST(JSSetIterator)
59 :
60 : OBJECT_CONSTRUCTORS(JSSetIterator,
61 : OrderedHashTableIterator<JSSetIterator, OrderedHashSet>);
62 : };
63 :
64 : // The JSMap describes EcmaScript Harmony maps
65 : class JSMap : public JSCollection {
66 : public:
67 : DECL_CAST(JSMap)
68 :
69 : static void Initialize(Handle<JSMap> map, Isolate* isolate);
70 : static void Clear(Isolate* isolate, Handle<JSMap> map);
71 :
72 : // Dispatched behavior.
73 : DECL_PRINTER(JSMap)
74 : DECL_VERIFIER(JSMap)
75 :
76 330598 : OBJECT_CONSTRUCTORS(JSMap, JSCollection);
77 : };
78 :
79 : class JSMapIterator
80 : : public OrderedHashTableIterator<JSMapIterator, OrderedHashMap> {
81 : public:
82 : // Dispatched behavior.
83 : DECL_PRINTER(JSMapIterator)
84 : DECL_VERIFIER(JSMapIterator)
85 :
86 : DECL_CAST(JSMapIterator)
87 :
88 : // Returns the current value of the iterator. This should only be called when
89 : // |HasMore| returns true.
90 : inline Object CurrentValue();
91 :
92 : OBJECT_CONSTRUCTORS(JSMapIterator,
93 : OrderedHashTableIterator<JSMapIterator, OrderedHashMap>);
94 : };
95 :
96 : // Base class for both JSWeakMap and JSWeakSet
97 : class JSWeakCollection : public JSObject {
98 : public:
99 : DECL_CAST(JSWeakCollection)
100 :
101 : // [table]: the backing hash table mapping keys to values.
102 : DECL_ACCESSORS(table, Object)
103 :
104 : static void Initialize(Handle<JSWeakCollection> collection, Isolate* isolate);
105 : static void Set(Handle<JSWeakCollection> collection, Handle<Object> key,
106 : Handle<Object> value, int32_t hash);
107 : static bool Delete(Handle<JSWeakCollection> collection, Handle<Object> key,
108 : int32_t hash);
109 : static Handle<JSArray> GetEntries(Handle<JSWeakCollection> holder,
110 : int max_entries);
111 :
112 : // Layout description.
113 : #define JS_WEAK_COLLECTION_FIELDS(V) \
114 : V(kTableOffset, kTaggedSize) \
115 : /* Header size. */ \
116 : V(kSize, 0)
117 :
118 : DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
119 : JS_WEAK_COLLECTION_FIELDS)
120 : #undef JS_WEAK_COLLECTION_FIELDS
121 :
122 : static const int kAddFunctionDescriptorIndex = 3;
123 :
124 : // Iterates the function object according to the visiting policy.
125 : class BodyDescriptorImpl;
126 :
127 : // Visit the whole object.
128 : typedef BodyDescriptorImpl BodyDescriptor;
129 :
130 : OBJECT_CONSTRUCTORS(JSWeakCollection, JSObject);
131 : };
132 :
133 : // The JSWeakMap describes EcmaScript Harmony weak maps
134 : class JSWeakMap : public JSWeakCollection {
135 : public:
136 : DECL_CAST(JSWeakMap)
137 :
138 : // Dispatched behavior.
139 : DECL_PRINTER(JSWeakMap)
140 : DECL_VERIFIER(JSWeakMap)
141 :
142 : OBJECT_CONSTRUCTORS(JSWeakMap, JSWeakCollection);
143 : };
144 :
145 : // The JSWeakSet describes EcmaScript Harmony weak sets
146 : class JSWeakSet : public JSWeakCollection {
147 : public:
148 : DECL_CAST(JSWeakSet)
149 :
150 : // Dispatched behavior.
151 : DECL_PRINTER(JSWeakSet)
152 : DECL_VERIFIER(JSWeakSet)
153 :
154 : OBJECT_CONSTRUCTORS(JSWeakSet, JSWeakCollection);
155 : };
156 :
157 : } // namespace internal
158 : } // namespace v8
159 :
160 : #include "src/objects/object-macros-undef.h"
161 :
162 : #endif // V8_OBJECTS_JS_COLLECTION_H_
|