10 #include "include/v8.h" 11 #include "src/base/functional.h" 12 #include "src/base/macros.h" 13 #include "src/checks.h" 14 #include "src/globals.h" 19 #include "src/objects.h" 20 #include "src/objects/heap-object.h" 21 #include "src/zone/zone.h" 27 class DeferredHandles;
28 class HandleScopeImplementer;
35 class OrderedNameDictionary;
36 class SmallOrderedHashMap;
37 class SmallOrderedHashSet;
38 class SmallOrderedNameDictionary;
48 V8_INLINE
bool is_identical_to(
const HandleBase that)
const {
50 SLOW_DCHECK((this->location_ ==
nullptr ||
51 this->IsDereferenceAllowed(NO_DEFERRED_CHECK)) &&
52 (that.location_ ==
nullptr ||
53 that.IsDereferenceAllowed(NO_DEFERRED_CHECK)));
54 if (this->location_ == that.location_)
return true;
55 if (this->location_ ==
nullptr || that.location_ ==
nullptr)
return false;
56 return *this->location_ == *that.location_;
59 V8_INLINE
bool is_null()
const {
return location_ ==
nullptr; }
63 V8_INLINE
Address address()
const {
return bit_cast<
Address>(location_); }
67 V8_INLINE
Address operator*()
const {
68 SLOW_DCHECK(IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK));
73 V8_INLINE
Address* location()
const {
74 SLOW_DCHECK(location_ ==
nullptr ||
75 IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK));
79 enum DereferenceCheckMode { INCLUDE_DEFERRED_CHECK, NO_DEFERRED_CHECK };
81 bool V8_EXPORT_PRIVATE IsDereferenceAllowed(DereferenceCheckMode mode)
const;
84 bool V8_EXPORT_PRIVATE IsDereferenceAllowed(DereferenceCheckMode mode)
const {
107 template <
typename T>
110 V8_INLINE
explicit Handle(
T** location)
111 :
HandleBase(reinterpret_cast<Address*>(location)) {
113 static_assert(std::is_convertible<T*, Object*>::value,
114 "static type violation");
116 V8_INLINE
explicit Handle(Address* location =
nullptr)
117 : HandleBase(location) {
119 static_assert(std::is_convertible<T*, Object*>::value ||
120 std::is_convertible<T, ObjectPtr>::value,
121 "static type violation");
129 template <
typename T1 = T,
typename =
typename std::enable_if<
130 std::is_base_of<Object, T1>::value>::type>
131 V8_INLINE Handle(T*
object, Isolate* isolate);
132 template <
typename T1 = T,
typename =
typename std::enable_if<
133 std::is_base_of<ObjectPtr, T1>::value>::type>
134 V8_INLINE Handle(T
object, Isolate* isolate);
137 template <
typename T1 = T,
typename =
typename std::enable_if<
138 std::is_base_of<Object, T1>::value>::type>
139 V8_INLINE
static Handle<T> New(T*
object, Isolate* isolate);
140 template <
typename T1 = T,
typename =
typename std::enable_if<
141 std::is_base_of<ObjectPtr, T1>::value>::type>
142 V8_INLINE
static Handle<T> New(T
object, Isolate* isolate);
149 typename =
typename std::enable_if<
150 std::is_convertible<S*, T*>::value ||
151 std::is_same<T, Object>::value ||
152 (std::is_same<T, HeapObject>::value &&
153 (std::is_same<S, ByteArray>::value || std::is_same<S, Code>::value ||
154 std::is_same<S, Context>::value ||
155 std::is_same<S, FixedArray>::value ||
156 std::is_same<S, FixedArrayBase>::value ||
157 std::is_same<S, FixedDoubleArray>::value ||
158 std::is_same<S, Map>::value || std::is_same<S, Name>::value ||
159 std::is_same<S, NumberDictionary>::value ||
160 std::is_same<S, ObjectBoilerplateDescription>::value ||
161 std::is_same<S, OrderedHashMap>::value ||
162 std::is_same<S, OrderedHashSet>::value ||
163 std::is_same<S, OrderedNameDictionary>::value ||
164 std::is_same<S, ScriptContextTable>::value ||
165 std::is_same<S, ScopeInfo>::value ||
166 std::is_same<S, SmallOrderedHashMap>::value ||
167 std::is_same<S, SmallOrderedHashSet>::value ||
168 std::is_same<S, SmallOrderedNameDictionary>::value ||
169 std::is_same<S, String>::value ||
170 std::is_same<S, Symbol>::value))>::type>
171 V8_INLINE Handle(Handle<S> handle) : HandleBase(handle) {}
175 template <
typename T1 = T,
176 typename =
typename std::enable_if<
177 std::is_base_of<Object, T1>::value ||
178 std::is_base_of<NeverReadOnlySpaceObject, T1>::value>::type>
179 V8_INLINE T* operator->()
const {
182 template <
typename T1 = T,
typename =
typename std::enable_if<
183 std::is_base_of<ObjectPtr, T1>::value>::type>
184 V8_INLINE T operator->()
const {
189 template <
typename T1 = T,
190 typename =
typename std::enable_if<
191 std::is_base_of<Object, T1>::value ||
192 std::is_base_of<NeverReadOnlySpaceObject, T1>::value>::type>
193 V8_INLINE T* operator*()
const {
194 return reinterpret_cast<T*
>(HandleBase::operator*());
196 template <
typename T1 = T,
typename =
typename std::enable_if<
197 std::is_base_of<ObjectPtr, T1>::value>::type>
198 V8_INLINE T operator*()
const {
201 return T::unchecked_cast(ObjectPtr(HandleBase::operator*()));
205 V8_INLINE Address* location()
const {
return HandleBase::location(); }
207 template <
typename S>
208 inline static const Handle<T> cast(Handle<S> that);
212 static const Handle<T> null() {
return Handle<T>(); }
215 bool equals(Handle<T> other)
const {
return address() == other.address(); }
220 return lhs.equals(rhs);
226 V8_INLINE
size_t operator()(
Handle<T> const& handle)
const {
240 template <
typename T>
241 inline std::ostream& operator<<(std::ostream& os, Handle<T> handle);
263 V8_EXPORT_PRIVATE
static int NumberOfHandles(
Isolate* isolate);
272 V8_EXPORT_PRIVATE
static void DeleteExtensions(
Isolate* isolate);
282 template <
typename T>
285 Isolate* isolate() {
return isolate_; }
290 static const int kCheckHandleThreshold = 30 * 1024;
294 void*
operator new(
size_t size);
295 void operator delete(
void*
size_t);
302 static inline void CloseScope(
Isolate* isolate,
Address* prev_next,
308 #ifdef ENABLE_HANDLE_ZAPPING 310 V8_EXPORT_PRIVATE
static void ZapRange(
Address* start,
Address* end);
324 template <
typename V,
class AllocationPolicy>
347 int canonical_level_;
389 bool handles_detached_ =
false;
410 int prev_sealed_level_;
423 next = limit =
nullptr;
424 sealed_level = level = 0;
425 canonical_scope =
nullptr;
432 #endif // V8_HANDLES_H_