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