V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
js-collection.h
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  private:
34  DISALLOW_IMPLICIT_CONSTRUCTORS(JSCollection);
35 };
36 
37 // The JSSet describes EcmaScript Harmony sets
38 class JSSet : public JSCollection {
39  public:
40  DECL_CAST(JSSet)
41 
42  static void Initialize(Handle<JSSet> set, Isolate* isolate);
43  static void Clear(Isolate* isolate, Handle<JSSet> set);
44 
45  // Dispatched behavior.
46  DECL_PRINTER(JSSet)
47  DECL_VERIFIER(JSSet)
48 
49  private:
50  DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet);
51 };
52 
54  : public OrderedHashTableIterator<JSSetIterator, OrderedHashSet> {
55  public:
56  // Dispatched behavior.
57  DECL_PRINTER(JSSetIterator)
58  DECL_VERIFIER(JSSetIterator)
59 
60  DECL_CAST(JSSetIterator)
61 
62  private:
63  DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator);
64 };
65 
66 // The JSMap describes EcmaScript Harmony maps
67 class JSMap : public JSCollection {
68  public:
69  DECL_CAST(JSMap)
70 
71  static void Initialize(Handle<JSMap> map, Isolate* isolate);
72  static void Clear(Isolate* isolate, Handle<JSMap> map);
73 
74  // Dispatched behavior.
75  DECL_PRINTER(JSMap)
76  DECL_VERIFIER(JSMap)
77 
78  private:
79  DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap);
80 };
81 
83  : public OrderedHashTableIterator<JSMapIterator, OrderedHashMap> {
84  public:
85  // Dispatched behavior.
86  DECL_PRINTER(JSMapIterator)
87  DECL_VERIFIER(JSMapIterator)
88 
89  DECL_CAST(JSMapIterator)
90 
91  // Returns the current value of the iterator. This should only be called when
92  // |HasMore| returns true.
93  inline Object* CurrentValue();
94 
95  private:
96  DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator);
97 };
98 
99 // Base class for both JSWeakMap and JSWeakSet
100 class JSWeakCollection : public JSObject {
101  public:
102  DECL_CAST(JSWeakCollection)
103 
104  // [table]: the backing hash table mapping keys to values.
105  DECL_ACCESSORS(table, Object)
106 
107  static void Initialize(Handle<JSWeakCollection> collection, Isolate* isolate);
108  static void Set(Handle<JSWeakCollection> collection, Handle<Object> key,
109  Handle<Object> value, int32_t hash);
110  static bool Delete(Handle<JSWeakCollection> collection, Handle<Object> key,
111  int32_t hash);
112  static Handle<JSArray> GetEntries(Handle<JSWeakCollection> holder,
113  int max_entries);
114 
115 // Layout description.
116 #define JS_WEAK_COLLECTION_FIELDS(V) \
117  V(kTableOffset, kTaggedSize) \
118  /* Header size. */ \
119  V(kSize, 0)
120 
121  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
122  JS_WEAK_COLLECTION_FIELDS)
123 #undef JS_WEAK_COLLECTION_FIELDS
124 
125  static const int kAddFunctionDescriptorIndex = 3;
126 
127  // Iterates the function object according to the visiting policy.
128  class BodyDescriptorImpl;
129 
130  // Visit the whole object.
132 
133  private:
134  DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakCollection);
135 };
136 
137 // The JSWeakMap describes EcmaScript Harmony weak maps
138 class JSWeakMap : public JSWeakCollection {
139  public:
140  DECL_CAST(JSWeakMap)
141 
142  // Dispatched behavior.
143  DECL_PRINTER(JSWeakMap)
144  DECL_VERIFIER(JSWeakMap)
145 
146  private:
147  DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap);
148 };
149 
150 // The JSWeakSet describes EcmaScript Harmony weak sets
151 class JSWeakSet : public JSWeakCollection {
152  public:
153  DECL_CAST(JSWeakSet)
154 
155  // Dispatched behavior.
156  DECL_PRINTER(JSWeakSet)
157  DECL_VERIFIER(JSWeakSet)
158 
159  private:
160  DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakSet);
161 };
162 
163 } // namespace internal
164 } // namespace v8
165 
166 #include "src/objects/object-macros-undef.h"
167 
168 #endif // V8_OBJECTS_JS_COLLECTION_H_
Definition: libplatform.h:13
Definition: v8.h:3740