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/js-collection-iterator.h" 9 #include "src/objects/objects.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 OrderedHashSet; 18 class OrderedHashMap; 19 20 #include "torque-generated/src/objects/js-collection-tq.inc" 21 22 class JSCollection 23 : public TorqueGeneratedJSCollection<JSCollection, JSObject> { 24 public: 25 static const int kAddFunctionDescriptorIndex = 3; 26 27 TQ_OBJECT_CONSTRUCTORS(JSCollection) 28 }; 29 30 // The JSSet describes EcmaScript Harmony sets 31 class JSSet : public TorqueGeneratedJSSet<JSSet, JSCollection> { 32 public: 33 static void Initialize(Handle<JSSet> set, Isolate* isolate); 34 static void Clear(Isolate* isolate, Handle<JSSet> set); 35 void Rehash(Isolate* isolate); 36 37 // Dispatched behavior. 38 DECL_PRINTER(JSSet) 39 DECL_VERIFIER(JSSet) 40 41 TQ_OBJECT_CONSTRUCTORS(JSSet) 42 }; 43 44 class JSSetIterator 45 : public OrderedHashTableIterator<JSSetIterator, OrderedHashSet> { 46 public: 47 // Dispatched behavior. 48 DECL_PRINTER(JSSetIterator) 49 DECL_VERIFIER(JSSetIterator) 50 51 DECL_CAST(JSSetIterator) 52 53 OBJECT_CONSTRUCTORS(JSSetIterator, 54 OrderedHashTableIterator<JSSetIterator, OrderedHashSet>); 55 }; 56 57 // The JSMap describes EcmaScript Harmony maps 58 class JSMap : public TorqueGeneratedJSMap<JSMap, JSCollection> { 59 public: 60 static void Initialize(Handle<JSMap> map, Isolate* isolate); 61 static void Clear(Isolate* isolate, Handle<JSMap> map); 62 void Rehash(Isolate* isolate); 63 64 // Dispatched behavior. 65 DECL_PRINTER(JSMap) 66 DECL_VERIFIER(JSMap) 67 68 TQ_OBJECT_CONSTRUCTORS(JSMap) 69 }; 70 71 class JSMapIterator 72 : public OrderedHashTableIterator<JSMapIterator, OrderedHashMap> { 73 public: 74 // Dispatched behavior. 75 DECL_PRINTER(JSMapIterator) 76 DECL_VERIFIER(JSMapIterator) 77 78 DECL_CAST(JSMapIterator) 79 80 // Returns the current value of the iterator. This should only be called when 81 // |HasMore| returns true. 82 inline Object CurrentValue(); 83 84 OBJECT_CONSTRUCTORS(JSMapIterator, 85 OrderedHashTableIterator<JSMapIterator, OrderedHashMap>); 86 }; 87 88 // Base class for both JSWeakMap and JSWeakSet 89 class JSWeakCollection 90 : public TorqueGeneratedJSWeakCollection<JSWeakCollection, JSObject> { 91 public: 92 static void Initialize(Handle<JSWeakCollection> collection, Isolate* isolate); 93 V8_EXPORT_PRIVATE static void Set(Handle<JSWeakCollection> collection, 94 Handle<Object> key, Handle<Object> value, 95 int32_t hash); 96 static bool Delete(Handle<JSWeakCollection> collection, Handle<Object> key, 97 int32_t hash); 98 static Handle<JSArray> GetEntries(Handle<JSWeakCollection> holder, 99 int max_entries); 100 101 static const int kAddFunctionDescriptorIndex = 3; 102 103 // Iterates the function object according to the visiting policy. 104 class BodyDescriptorImpl; 105 106 // Visit the whole object. 107 using BodyDescriptor = BodyDescriptorImpl; 108 109 static const int kHeaderSizeOfAllWeakCollections = kHeaderSize; 110 111 TQ_OBJECT_CONSTRUCTORS(JSWeakCollection) 112 }; 113 114 // The JSWeakMap describes EcmaScript Harmony weak maps 115 class JSWeakMap : public TorqueGeneratedJSWeakMap<JSWeakMap, JSWeakCollection> { 116 public: 117 // Dispatched behavior. 118 DECL_PRINTER(JSWeakMap) 119 DECL_VERIFIER(JSWeakMap) 120 121 STATIC_ASSERT(kHeaderSize == kHeaderSizeOfAllWeakCollections); 122 TQ_OBJECT_CONSTRUCTORS(JSWeakMap) 123 }; 124 125 // The JSWeakSet describes EcmaScript Harmony weak sets 126 class JSWeakSet : public TorqueGeneratedJSWeakSet<JSWeakSet, JSWeakCollection> { 127 public: 128 // Dispatched behavior. 129 DECL_PRINTER(JSWeakSet) 130 DECL_VERIFIER(JSWeakSet) 131 132 STATIC_ASSERT(kHeaderSize == kHeaderSizeOfAllWeakCollections); 133 TQ_OBJECT_CONSTRUCTORS(JSWeakSet) 134 }; 135 136 } // namespace internal 137 } // namespace v8 138 139 #include "src/objects/object-macros-undef.h" 140 141 #endif // V8_OBJECTS_JS_COLLECTION_H_ 142