Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_HANDLES_H_ |
| 6 | #define V8_HANDLES_H_ |
| 7 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8 | #include "include/v8.h" |
| 9 | #include "src/base/functional.h" |
| 10 | #include "src/base/macros.h" |
| 11 | #include "src/checks.h" |
| 12 | #include "src/globals.h" |
| 13 | #include "src/zone.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 14 | |
| 15 | namespace v8 { |
| 16 | namespace internal { |
| 17 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 18 | // Forward declarations. |
| 19 | class DeferredHandles; |
| 20 | class HandleScopeImplementer; |
| 21 | class Isolate; |
| 22 | class Object; |
| 23 | |
| 24 | |
| 25 | // ---------------------------------------------------------------------------- |
| 26 | // Base class for Handle instantiations. Don't use directly. |
| 27 | class HandleBase { |
| 28 | public: |
| 29 | V8_INLINE explicit HandleBase(Object** location) : location_(location) {} |
| 30 | V8_INLINE explicit HandleBase(Object* object, Isolate* isolate); |
| 31 | |
| 32 | // Check if this handle refers to the exact same object as the other handle. |
| 33 | V8_INLINE bool is_identical_to(const HandleBase that) const { |
| 34 | // Dereferencing deferred handles to check object equality is safe. |
| 35 | SLOW_DCHECK((this->location_ == nullptr || |
| 36 | this->IsDereferenceAllowed(NO_DEFERRED_CHECK)) && |
| 37 | (that.location_ == nullptr || |
| 38 | that.IsDereferenceAllowed(NO_DEFERRED_CHECK))); |
| 39 | if (this->location_ == that.location_) return true; |
| 40 | if (this->location_ == NULL || that.location_ == NULL) return false; |
| 41 | return *this->location_ == *that.location_; |
| 42 | } |
| 43 | |
| 44 | V8_INLINE bool is_null() const { return location_ == nullptr; } |
| 45 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 46 | // Returns the raw address where this handle is stored. This should only be |
| 47 | // used for hashing handles; do not ever try to dereference it. |
| 48 | V8_INLINE Address address() const { return bit_cast<Address>(location_); } |
| 49 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 50 | protected: |
| 51 | // Provides the C++ dereference operator. |
| 52 | V8_INLINE Object* operator*() const { |
| 53 | SLOW_DCHECK(IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); |
| 54 | return *location_; |
| 55 | } |
| 56 | |
| 57 | // Returns the address to where the raw pointer is stored. |
| 58 | V8_INLINE Object** location() const { |
| 59 | SLOW_DCHECK(location_ == nullptr || |
| 60 | IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); |
| 61 | return location_; |
| 62 | } |
| 63 | |
| 64 | enum DereferenceCheckMode { INCLUDE_DEFERRED_CHECK, NO_DEFERRED_CHECK }; |
| 65 | #ifdef DEBUG |
| 66 | bool IsDereferenceAllowed(DereferenceCheckMode mode) const; |
| 67 | #else |
| 68 | V8_INLINE |
| 69 | bool IsDereferenceAllowed(DereferenceCheckMode mode) const { return true; } |
| 70 | #endif // DEBUG |
| 71 | |
| 72 | Object** location_; |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | // ---------------------------------------------------------------------------- |
| 77 | // A Handle provides a reference to an object that survives relocation by |
| 78 | // the garbage collector. |
| 79 | // |
| 80 | // Handles are only valid within a HandleScope. When a handle is created |
| 81 | // for an object a cell is allocated in the current HandleScope. |
| 82 | // |
| 83 | // Also note that Handles do not provide default equality comparison or hashing |
| 84 | // operators on purpose. Such operators would be misleading, because intended |
| 85 | // semantics is ambiguous between Handle location and object identity. Instead |
| 86 | // use either {is_identical_to} or {location} explicitly. |
| 87 | template <typename T> |
| 88 | class Handle final : public HandleBase { |
| 89 | public: |
| 90 | V8_INLINE explicit Handle(T** location = nullptr) |
| 91 | : HandleBase(reinterpret_cast<Object**>(location)) { |
| 92 | Object* a = nullptr; |
| 93 | T* b = nullptr; |
| 94 | a = b; // Fake assignment to enforce type checks. |
| 95 | USE(a); |
| 96 | } |
| 97 | V8_INLINE explicit Handle(T* object) : Handle(object, object->GetIsolate()) {} |
| 98 | V8_INLINE Handle(T* object, Isolate* isolate) : HandleBase(object, isolate) {} |
| 99 | |
| 100 | // Allocate a new handle for the object, do not canonicalize. |
| 101 | V8_INLINE static Handle<T> New(T* object, Isolate* isolate); |
| 102 | |
| 103 | // Constructor for handling automatic up casting. |
| 104 | // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected. |
| 105 | template <typename S> |
| 106 | V8_INLINE Handle(Handle<S> handle) |
| 107 | : HandleBase(handle) { |
| 108 | T* a = nullptr; |
| 109 | S* b = nullptr; |
| 110 | a = b; // Fake assignment to enforce type checks. |
| 111 | USE(a); |
| 112 | } |
| 113 | |
| 114 | V8_INLINE T* operator->() const { return operator*(); } |
| 115 | |
| 116 | // Provides the C++ dereference operator. |
| 117 | V8_INLINE T* operator*() const { |
| 118 | return reinterpret_cast<T*>(HandleBase::operator*()); |
| 119 | } |
| 120 | |
| 121 | // Returns the address to where the raw pointer is stored. |
| 122 | V8_INLINE T** location() const { |
| 123 | return reinterpret_cast<T**>(HandleBase::location()); |
| 124 | } |
| 125 | |
| 126 | template <typename S> |
| 127 | static const Handle<T> cast(Handle<S> that) { |
| 128 | T::cast(*reinterpret_cast<T**>(that.location_)); |
| 129 | return Handle<T>(reinterpret_cast<T**>(that.location_)); |
| 130 | } |
| 131 | |
| 132 | // TODO(yangguo): Values that contain empty handles should be declared as |
| 133 | // MaybeHandle to force validation before being used as handles. |
| 134 | static const Handle<T> null() { return Handle<T>(); } |
| 135 | |
| 136 | // Provide function object for location equality comparison. |
| 137 | struct equal_to : public std::binary_function<Handle<T>, Handle<T>, bool> { |
| 138 | V8_INLINE bool operator()(Handle<T> lhs, Handle<T> rhs) const { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 139 | return lhs.address() == rhs.address(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 140 | } |
| 141 | }; |
| 142 | |
| 143 | // Provide function object for location hashing. |
| 144 | struct hash : public std::unary_function<Handle<T>, size_t> { |
| 145 | V8_INLINE size_t operator()(Handle<T> const& handle) const { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 146 | return base::hash<void*>()(handle.address()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 147 | } |
| 148 | }; |
| 149 | |
| 150 | private: |
| 151 | // Handles of different classes are allowed to access each other's location_. |
| 152 | template <typename> |
| 153 | friend class Handle; |
| 154 | // MaybeHandle is allowed to access location_. |
| 155 | template <typename> |
| 156 | friend class MaybeHandle; |
| 157 | }; |
| 158 | |
| 159 | template <typename T> |
| 160 | inline std::ostream& operator<<(std::ostream& os, Handle<T> handle); |
| 161 | |
| 162 | template <typename T> |
| 163 | V8_INLINE Handle<T> handle(T* object, Isolate* isolate) { |
| 164 | return Handle<T>(object, isolate); |
| 165 | } |
| 166 | |
| 167 | template <typename T> |
| 168 | V8_INLINE Handle<T> handle(T* object) { |
| 169 | return Handle<T>(object); |
| 170 | } |
| 171 | |
| 172 | |
| 173 | // ---------------------------------------------------------------------------- |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 174 | // A Handle can be converted into a MaybeHandle. Converting a MaybeHandle |
| 175 | // into a Handle requires checking that it does not point to NULL. This |
| 176 | // ensures NULL checks before use. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 177 | // |
| 178 | // Also note that Handles do not provide default equality comparison or hashing |
| 179 | // operators on purpose. Such operators would be misleading, because intended |
| 180 | // semantics is ambiguous between Handle location and object identity. |
| 181 | template <typename T> |
| 182 | class MaybeHandle final { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 183 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 184 | V8_INLINE MaybeHandle() {} |
| 185 | V8_INLINE ~MaybeHandle() {} |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 186 | |
| 187 | // Constructor for handling automatic up casting from Handle. |
| 188 | // Ex. Handle<JSArray> can be passed when MaybeHandle<Object> is expected. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 189 | template <typename S> |
| 190 | V8_INLINE MaybeHandle(Handle<S> handle) |
| 191 | : location_(reinterpret_cast<T**>(handle.location_)) { |
| 192 | T* a = nullptr; |
| 193 | S* b = nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 194 | a = b; // Fake assignment to enforce type checks. |
| 195 | USE(a); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | // Constructor for handling automatic up casting. |
| 199 | // Ex. MaybeHandle<JSArray> can be passed when Handle<Object> is expected. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 200 | template <typename S> |
| 201 | V8_INLINE MaybeHandle(MaybeHandle<S> maybe_handle) |
| 202 | : location_(reinterpret_cast<T**>(maybe_handle.location_)) { |
| 203 | T* a = nullptr; |
| 204 | S* b = nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 205 | a = b; // Fake assignment to enforce type checks. |
| 206 | USE(a); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 209 | V8_INLINE void Assert() const { DCHECK_NOT_NULL(location_); } |
| 210 | V8_INLINE void Check() const { CHECK_NOT_NULL(location_); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 211 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 212 | V8_INLINE Handle<T> ToHandleChecked() const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 213 | Check(); |
| 214 | return Handle<T>(location_); |
| 215 | } |
| 216 | |
| 217 | // Convert to a Handle with a type that can be upcasted to. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 218 | template <typename S> |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 219 | V8_INLINE bool ToHandle(Handle<S>* out) const { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 220 | if (location_ == nullptr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 221 | *out = Handle<T>::null(); |
| 222 | return false; |
| 223 | } else { |
| 224 | *out = Handle<T>(location_); |
| 225 | return true; |
| 226 | } |
| 227 | } |
| 228 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 229 | bool is_null() const { return location_ == nullptr; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 230 | |
| 231 | protected: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 232 | T** location_ = nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 233 | |
| 234 | // MaybeHandles of different classes are allowed to access each |
| 235 | // other's location_. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 236 | template <typename> |
| 237 | friend class MaybeHandle; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 238 | }; |
| 239 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 240 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 241 | // ---------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 242 | // A stack-allocated class that governs a number of local handles. |
| 243 | // After a handle scope has been created, all local handles will be |
| 244 | // allocated within that handle scope until either the handle scope is |
| 245 | // deleted or another handle scope is created. If there is already a |
| 246 | // handle scope and a new one is created, all allocations will take |
| 247 | // place in the new handle scope until it is deleted. After that, |
| 248 | // new handles will again be allocated in the original handle scope. |
| 249 | // |
| 250 | // After the handle scope of a local handle has been deleted the |
| 251 | // garbage collector will no longer track the object stored in the |
| 252 | // handle and may deallocate it. The behavior of accessing a handle |
| 253 | // for which the handle scope has been deleted is undefined. |
| 254 | class HandleScope { |
| 255 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 256 | explicit inline HandleScope(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 257 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 258 | inline ~HandleScope(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 259 | |
| 260 | // Counts the number of allocated handles. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 261 | static int NumberOfHandles(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 262 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 263 | // Create a new handle or lookup a canonical handle. |
| 264 | V8_INLINE static Object** GetHandle(Isolate* isolate, Object* value); |
| 265 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 266 | // Creates a new handle with the given value. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 267 | V8_INLINE static Object** CreateHandle(Isolate* isolate, Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 268 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 269 | // Deallocates any extensions used by the current scope. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 270 | static void DeleteExtensions(Isolate* isolate); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 271 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 272 | static Address current_next_address(Isolate* isolate); |
| 273 | static Address current_limit_address(Isolate* isolate); |
| 274 | static Address current_level_address(Isolate* isolate); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 275 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 276 | // Closes the HandleScope (invalidating all handles |
| 277 | // created in the scope of the HandleScope) and returns |
| 278 | // a Handle backed by the parent scope holding the |
| 279 | // value of the argument handle. |
| 280 | template <typename T> |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 281 | Handle<T> CloseAndEscape(Handle<T> handle_value); |
| 282 | |
| 283 | Isolate* isolate() { return isolate_; } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 284 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 285 | // Limit for number of handles with --check-handle-count. This is |
| 286 | // large enough to compile natives and pass unit tests with some |
| 287 | // slack for future changes to natives. |
| 288 | static const int kCheckHandleThreshold = 30 * 1024; |
| 289 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 290 | private: |
| 291 | // Prevent heap allocation or illegal handle scopes. |
| 292 | HandleScope(const HandleScope&); |
| 293 | void operator=(const HandleScope&); |
| 294 | void* operator new(size_t size); |
| 295 | void operator delete(void* size_t); |
| 296 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 297 | Isolate* isolate_; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 298 | Object** prev_next_; |
| 299 | Object** prev_limit_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 300 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 301 | // Close the handle scope resetting limits to a previous state. |
| 302 | static inline void CloseScope(Isolate* isolate, |
| 303 | Object** prev_next, |
| 304 | Object** prev_limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 305 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 306 | // Extend the handle scope making room for more handles. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 307 | static Object** Extend(Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 308 | |
| 309 | #ifdef ENABLE_HANDLE_ZAPPING |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 310 | // Zaps the handles in the half-open interval [start, end). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 311 | static void ZapRange(Object** start, Object** end); |
| 312 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | |
| 314 | friend class v8::HandleScope; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 315 | friend class DeferredHandles; |
| 316 | friend class DeferredHandleScope; |
| 317 | friend class HandleScopeImplementer; |
| 318 | friend class Isolate; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 319 | }; |
| 320 | |
| 321 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 322 | // Forward declarations for CanonicalHandleScope. |
| 323 | template <typename V> |
| 324 | class IdentityMap; |
| 325 | class RootIndexMap; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 326 | |
| 327 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 328 | // A CanonicalHandleScope does not open a new HandleScope. It changes the |
| 329 | // existing HandleScope so that Handles created within are canonicalized. |
| 330 | // This does not apply to nested inner HandleScopes unless a nested |
| 331 | // CanonicalHandleScope is introduced. Handles are only canonicalized within |
| 332 | // the same CanonicalHandleScope, but not across nested ones. |
| 333 | class CanonicalHandleScope final { |
| 334 | public: |
| 335 | explicit CanonicalHandleScope(Isolate* isolate); |
| 336 | ~CanonicalHandleScope(); |
| 337 | |
| 338 | private: |
| 339 | Object** Lookup(Object* object); |
| 340 | |
| 341 | Isolate* isolate_; |
| 342 | Zone zone_; |
| 343 | RootIndexMap* root_index_map_; |
| 344 | IdentityMap<Object**>* identity_map_; |
| 345 | // Ordinary nested handle scopes within the current one are not canonical. |
| 346 | int canonical_level_; |
| 347 | // We may have nested canonical scopes. Handles are canonical within each one. |
| 348 | CanonicalHandleScope* prev_canonical_scope_; |
| 349 | |
| 350 | friend class HandleScope; |
| 351 | }; |
| 352 | |
| 353 | |
| 354 | class DeferredHandleScope final { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 355 | public: |
| 356 | explicit DeferredHandleScope(Isolate* isolate); |
| 357 | // The DeferredHandles object returned stores the Handles created |
| 358 | // since the creation of this DeferredHandleScope. The Handles are |
| 359 | // alive as long as the DeferredHandles object is alive. |
| 360 | DeferredHandles* Detach(); |
| 361 | ~DeferredHandleScope(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 362 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 363 | private: |
| 364 | Object** prev_limit_; |
| 365 | Object** prev_next_; |
| 366 | HandleScopeImplementer* impl_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 367 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 368 | #ifdef DEBUG |
| 369 | bool handles_detached_; |
| 370 | int prev_level_; |
| 371 | #endif |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 372 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 373 | friend class HandleScopeImplementer; |
| 374 | }; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 375 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 376 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 377 | // Seal off the current HandleScope so that new handles can only be created |
| 378 | // if a new HandleScope is entered. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 379 | class SealHandleScope final { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 380 | public: |
| 381 | #ifndef DEBUG |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 382 | explicit SealHandleScope(Isolate* isolate) {} |
| 383 | ~SealHandleScope() {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 384 | #else |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 385 | explicit inline SealHandleScope(Isolate* isolate); |
| 386 | inline ~SealHandleScope(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 387 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 388 | Isolate* isolate_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 389 | Object** prev_limit_; |
| 390 | int prev_sealed_level_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 391 | #endif |
| 392 | }; |
| 393 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 394 | |
| 395 | struct HandleScopeData final { |
| 396 | Object** next; |
| 397 | Object** limit; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 398 | int level; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 399 | int sealed_level; |
| 400 | CanonicalHandleScope* canonical_scope; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 401 | |
| 402 | void Initialize() { |
| 403 | next = limit = NULL; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 404 | sealed_level = level = 0; |
| 405 | canonical_scope = NULL; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 406 | } |
| 407 | }; |
| 408 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 409 | } // namespace internal |
| 410 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 411 | |
| 412 | #endif // V8_HANDLES_H_ |