OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/assert-scope.h" | 9 #include "src/assert-scope.h" |
10 #include "src/builtins.h" | 10 #include "src/builtins.h" |
(...skipping 4429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4440 OrderedHashMap, JSMapIterator, 2> { | 4440 OrderedHashMap, JSMapIterator, 2> { |
4441 public: | 4441 public: |
4442 DECLARE_CAST(OrderedHashMap) | 4442 DECLARE_CAST(OrderedHashMap) |
4443 | 4443 |
4444 Object* Lookup(Handle<Object> key); | 4444 Object* Lookup(Handle<Object> key); |
4445 static Handle<OrderedHashMap> Put( | 4445 static Handle<OrderedHashMap> Put( |
4446 Handle<OrderedHashMap> table, | 4446 Handle<OrderedHashMap> table, |
4447 Handle<Object> key, | 4447 Handle<Object> key, |
4448 Handle<Object> value); | 4448 Handle<Object> value); |
4449 | 4449 |
4450 private: | |
4451 Object* ValueAt(int entry) { | 4450 Object* ValueAt(int entry) { |
4452 return get(EntryToIndex(entry) + kValueOffset); | 4451 return get(EntryToIndex(entry) + kValueOffset); |
4453 } | 4452 } |
4454 | 4453 |
| 4454 private: |
4455 static const int kValueOffset = 1; | 4455 static const int kValueOffset = 1; |
4456 }; | 4456 }; |
4457 | 4457 |
4458 | 4458 |
4459 template <int entrysize> | 4459 template <int entrysize> |
4460 class WeakHashTableShape : public BaseShape<Handle<Object> > { | 4460 class WeakHashTableShape : public BaseShape<Handle<Object> > { |
4461 public: | 4461 public: |
4462 static inline bool IsMatch(Handle<Object> key, Object* other); | 4462 static inline bool IsMatch(Handle<Object> key, Object* other); |
4463 static inline uint32_t Hash(Handle<Object> key); | 4463 static inline uint32_t Hash(Handle<Object> key); |
4464 static inline uint32_t HashForObject(Handle<Object> key, Object* object); | 4464 static inline uint32_t HashForObject(Handle<Object> key, Object* object); |
(...skipping 5620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10085 static const int kIndexOffset = kTableOffset + kPointerSize; | 10085 static const int kIndexOffset = kTableOffset + kPointerSize; |
10086 static const int kKindOffset = kIndexOffset + kPointerSize; | 10086 static const int kKindOffset = kIndexOffset + kPointerSize; |
10087 static const int kSize = kKindOffset + kPointerSize; | 10087 static const int kSize = kKindOffset + kPointerSize; |
10088 | 10088 |
10089 enum Kind { | 10089 enum Kind { |
10090 kKindKeys = 1, | 10090 kKindKeys = 1, |
10091 kKindValues = 2, | 10091 kKindValues = 2, |
10092 kKindEntries = 3 | 10092 kKindEntries = 3 |
10093 }; | 10093 }; |
10094 | 10094 |
10095 // Returns an iterator result object: {value: any, done: boolean} and moves | 10095 // Whether the iterator has more elements. This needs to be called before |
10096 // the index to the next valid entry. Closes the iterator if moving past the | 10096 // calling |CurrentKey| and/or |CurrentValue|. |
10097 // end. | 10097 bool HasMore(); |
10098 static Handle<JSObject> Next(Handle<Derived> iterator); | 10098 |
| 10099 // Move the index forward one. |
| 10100 void MoveNext() { |
| 10101 set_index(Smi::FromInt(Smi::cast(index())->value() + 1)); |
| 10102 } |
| 10103 |
| 10104 // Populates the array with the next key and value and then moves the iterator |
| 10105 // forward. |
| 10106 // This returns the |kind| or 0 if the iterator is already at the end. |
| 10107 Smi* Next(JSArray* value_array); |
| 10108 |
| 10109 // Returns the current key of the iterator. This should only be called when |
| 10110 // |HasMore| returns true. |
| 10111 inline Object* CurrentKey(); |
10099 | 10112 |
10100 private: | 10113 private: |
10101 // Transitions the iterator to the non obsolote backing store. This is a NOP | 10114 // Transitions the iterator to the non obsolete backing store. This is a NOP |
10102 // if the [table] is not obsolete. | 10115 // if the [table] is not obsolete. |
10103 void Transition(); | 10116 void Transition(); |
10104 | 10117 |
10105 DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator); | 10118 DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator); |
10106 }; | 10119 }; |
10107 | 10120 |
10108 | 10121 |
10109 class JSSetIterator: public OrderedHashTableIterator<JSSetIterator, | 10122 class JSSetIterator: public OrderedHashTableIterator<JSSetIterator, |
10110 OrderedHashSet> { | 10123 OrderedHashSet> { |
10111 public: | 10124 public: |
10112 // Dispatched behavior. | 10125 // Dispatched behavior. |
10113 DECLARE_PRINTER(JSSetIterator) | 10126 DECLARE_PRINTER(JSSetIterator) |
10114 DECLARE_VERIFIER(JSSetIterator) | 10127 DECLARE_VERIFIER(JSSetIterator) |
10115 | 10128 |
10116 DECLARE_CAST(JSSetIterator) | 10129 DECLARE_CAST(JSSetIterator) |
10117 | 10130 |
10118 static Handle<Object> ValueForKind( | 10131 // Called by |Next| to populate the array. This allows the subclasses to |
10119 Handle<JSSetIterator> iterator, | 10132 // populate the array differently. |
10120 int entry_index); | 10133 inline void PopulateValueArray(FixedArray* array); |
10121 | 10134 |
10122 private: | 10135 private: |
10123 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator); | 10136 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator); |
10124 }; | 10137 }; |
10125 | 10138 |
10126 | 10139 |
10127 class JSMapIterator: public OrderedHashTableIterator<JSMapIterator, | 10140 class JSMapIterator: public OrderedHashTableIterator<JSMapIterator, |
10128 OrderedHashMap> { | 10141 OrderedHashMap> { |
10129 public: | 10142 public: |
10130 // Dispatched behavior. | 10143 // Dispatched behavior. |
10131 DECLARE_PRINTER(JSMapIterator) | 10144 DECLARE_PRINTER(JSMapIterator) |
10132 DECLARE_VERIFIER(JSMapIterator) | 10145 DECLARE_VERIFIER(JSMapIterator) |
10133 | 10146 |
10134 DECLARE_CAST(JSMapIterator) | 10147 DECLARE_CAST(JSMapIterator) |
10135 | 10148 |
10136 static Handle<Object> ValueForKind( | 10149 // Called by |Next| to populate the array. This allows the subclasses to |
10137 Handle<JSMapIterator> iterator, | 10150 // populate the array differently. |
10138 int entry_index); | 10151 inline void PopulateValueArray(FixedArray* array); |
10139 | 10152 |
10140 private: | 10153 private: |
| 10154 // Returns the current value of the iterator. This should only be called when |
| 10155 // |HasMore| returns true. |
| 10156 inline Object* CurrentValue(); |
| 10157 |
10141 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator); | 10158 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator); |
10142 }; | 10159 }; |
10143 | 10160 |
10144 | 10161 |
10145 // Base class for both JSWeakMap and JSWeakSet | 10162 // Base class for both JSWeakMap and JSWeakSet |
10146 class JSWeakCollection: public JSObject { | 10163 class JSWeakCollection: public JSObject { |
10147 public: | 10164 public: |
10148 // [table]: the backing hash table mapping keys to values. | 10165 // [table]: the backing hash table mapping keys to values. |
10149 DECL_ACCESSORS(table, Object) | 10166 DECL_ACCESSORS(table, Object) |
10150 | 10167 |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11147 } else { | 11164 } else { |
11148 value &= ~(1 << bit_position); | 11165 value &= ~(1 << bit_position); |
11149 } | 11166 } |
11150 return value; | 11167 return value; |
11151 } | 11168 } |
11152 }; | 11169 }; |
11153 | 11170 |
11154 } } // namespace v8::internal | 11171 } } // namespace v8::internal |
11155 | 11172 |
11156 #endif // V8_OBJECTS_H_ | 11173 #endif // V8_OBJECTS_H_ |
OLD | NEW |