v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
scope-info-inl.h
Go to the documentation of this file.
1// Copyright 2020 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_SCOPE_INFO_INL_H_
6#define V8_OBJECTS_SCOPE_INFO_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
13#include "src/objects/string.h"
14#include "src/roots/roots-inl.h"
17
18// Has to be the last include (doesn't have include guards):
20
21namespace v8 {
22namespace internal {
23
24#include "torque-generated/src/objects/scope-info-tq-inl.inc"
25
27
28bool ScopeInfo::IsAsmModule() const { return IsAsmModuleBit::decode(Flags()); }
29
31 return HasSimpleParametersBit::decode(Flags());
32}
33
34uint32_t ScopeInfo::Flags() const { return flags(kRelaxedLoad); }
36int ScopeInfo::ContextLocalCount() const { return context_local_count(); }
37
39 return Cast<DependentCode>(TorqueGeneratedScopeInfo::dependent_code());
40}
41
43
47
48template <typename ScopeInfoPtr>
50 public:
51 class Iterator {
52 public:
54 : range_(range), index_(index) {
55 DCHECK_NOT_NULL(range);
56 if (!range_->inlined()) advance_hashtable_index();
57 }
58
60 DCHECK_LT(index_, range_->max_index());
61 ++index_;
62 if (range_->inlined()) return *this;
64 return *this;
65 }
66
67 friend bool operator==(const Iterator& a, const Iterator& b) {
68 return a.range_ == b.range_ && a.index_ == b.index_;
69 }
70
71 friend bool operator!=(const Iterator& a, const Iterator& b) {
72 return !(a == b);
73 }
74
76 DCHECK_LT(index_, range_->max_index());
77 if (range_->inlined()) {
78 return scope_info()->ContextInlinedLocalName(cage_base,
79 index_.as_int());
80 }
81 return Cast<String>(table()->KeyAt(cage_base, index_));
82 }
83
86 return name(cage_base);
87 }
88
89 const Iterator* operator*() const { return this; }
90
91 int index() const {
92 if (range_->inlined()) return index_.as_int();
93 return table()->IndexAt(index_);
94 }
95
96 private:
99
100 ScopeInfoPtr scope_info() const { return range_->scope_info_; }
101
103 return scope_info()->context_local_names_hashtable();
104 }
105
109 InternalIndex max = range_->max_index();
110 // Increment until iterator points to a valid key or max.
111 while (index_ < max) {
112 Tagged<Object> key = table()->KeyAt(index_);
113 if (table()->IsKey(roots, key)) break;
114 ++index_;
115 }
116 }
117
118 friend class LocalNamesRange;
119 };
120
121 bool inlined() const { return scope_info_->HasInlinedLocalNames(); }
122
124 int max = inlined()
125 ? scope_info_->ContextLocalCount()
126 : scope_info_->context_local_names_hashtable()->Capacity();
127 return InternalIndex(max);
128 }
129
130 explicit LocalNamesRange(ScopeInfoPtr scope_info) : scope_info_(scope_info) {}
131
132 inline Iterator begin() const { return Iterator(this, InternalIndex(0)); }
133
134 inline Iterator end() const { return Iterator(this, max_index()); }
135
136 private:
137 ScopeInfoPtr scope_info_;
138};
139
140// static
145
146// static
152
153} // namespace internal
154} // namespace v8
155
157
158#endif // V8_OBJECTS_SCOPE_INFO_INL_H_
int16_t parameter_count
Definition builtins.cc:67
constexpr int as_int() const
friend bool operator!=(const Iterator &a, const Iterator &b)
Tagged< NameToIndexHashTable > table() const
Tagged< String > name(PtrComprCageBase cage_base) const
Iterator(const LocalNamesRange *range, InternalIndex index)
friend bool operator==(const Iterator &a, const Iterator &b)
bool HasSimpleParameters() const
uint32_t Flags() const
Tagged< DependentCode > dependent_code() const
static constexpr int OffsetOfElementAt(int index)
Definition scope-info.h:342
bool HasInlinedLocalNames() const
static LocalNamesRange< DirectHandle< ScopeInfo > > IterateLocalNames(DirectHandle< ScopeInfo > scope_info)
V8_EXPORT_PRIVATE base::Vector< Flag > Flags()
Definition flags.cc:300
ReadOnlyRoots GetReadOnlyRoots()
Definition roots-inl.h:86
constexpr int kScopeInfoMaxInlinedLocalNamesSize
Definition globals.h:1891
Flag flags[]
Definition flags.cc:3797
V8_INLINE PtrComprCageBase GetPtrComprCageBase()
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
static constexpr RelaxedLoadTag kRelaxedLoad
Definition globals.h:2909
#define TQ_OBJECT_CONSTRUCTORS_IMPL(Type)
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define USE(...)
Definition macros.h:293