• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INL_H_
6 #define V8_OBJECTS_JS_COLLECTION_INL_H_
7 
8 #include "src/heap/heap-write-barrier-inl.h"
9 #include "src/objects/heap-object-inl.h"
10 #include "src/objects/js-collection-iterator-inl.h"
11 #include "src/objects/js-collection.h"
12 #include "src/objects/objects-inl.h"
13 #include "src/objects/ordered-hash-table-inl.h"
14 #include "src/roots/roots-inl.h"
15 
16 // Has to be the last include (doesn't have include guards):
17 #include "src/objects/object-macros.h"
18 
19 namespace v8 {
20 namespace internal {
21 
22 #include "torque-generated/src/objects/js-collection-tq-inl.inc"
23 
24 TQ_OBJECT_CONSTRUCTORS_IMPL(JSCollection)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSMap)25 TQ_OBJECT_CONSTRUCTORS_IMPL(JSMap)
26 TQ_OBJECT_CONSTRUCTORS_IMPL(JSSet)
27 TQ_OBJECT_CONSTRUCTORS_IMPL(JSWeakCollection)
28 TQ_OBJECT_CONSTRUCTORS_IMPL(JSWeakMap)
29 TQ_OBJECT_CONSTRUCTORS_IMPL(JSWeakSet)
30 
31 template <class Derived, class TableType>
32 OrderedHashTableIterator<Derived, TableType>::OrderedHashTableIterator(
33     Address ptr)
34     : JSCollectionIterator(ptr) {}
35 
JSMapIterator(Address ptr)36 JSMapIterator::JSMapIterator(Address ptr)
37     : OrderedHashTableIterator<JSMapIterator, OrderedHashMap>(ptr) {
38   SLOW_DCHECK(IsJSMapIterator());
39 }
40 
JSSetIterator(Address ptr)41 JSSetIterator::JSSetIterator(Address ptr)
42     : OrderedHashTableIterator<JSSetIterator, OrderedHashSet>(ptr) {
43   SLOW_DCHECK(IsJSSetIterator());
44 }
45 
46 CAST_ACCESSOR(JSSetIterator)
CAST_ACCESSOR(JSMapIterator)47 CAST_ACCESSOR(JSMapIterator)
48 
49 Object JSMapIterator::CurrentValue() {
50   OrderedHashMap table = OrderedHashMap::cast(this->table());
51   int index = Smi::ToInt(this->index());
52   DCHECK_GE(index, 0);
53   InternalIndex entry(index);
54   Object value = table.ValueAt(entry);
55   DCHECK(!value.IsTheHole());
56   return value;
57 }
58 
59 }  // namespace internal
60 }  // namespace v8
61 
62 #include "src/objects/object-macros-undef.h"
63 
64 #endif  // V8_OBJECTS_JS_COLLECTION_INL_H_
65