| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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_HANDLES_H_ | 5 #ifndef V8_HANDLES_H_ |
| 6 #define V8_HANDLES_H_ | 6 #define V8_HANDLES_H_ |
| 7 | 7 |
| 8 #include "src/objects.h" | 8 #include "include/v8.h" |
| 9 #include "src/base/macros.h" |
| 10 #include "src/checks.h" |
| 11 #include "src/globals.h" |
| 9 | 12 |
| 10 namespace v8 { | 13 namespace v8 { |
| 11 namespace internal { | 14 namespace internal { |
| 12 | 15 |
| 13 // Forward declarations. | 16 // Forward declarations. |
| 14 class DeferredHandles; | 17 class DeferredHandles; |
| 15 class HandleScopeImplementer; | 18 class HandleScopeImplementer; |
| 19 class Isolate; |
| 20 class Object; |
| 16 | 21 |
| 17 | 22 |
| 18 // ---------------------------------------------------------------------------- | 23 // ---------------------------------------------------------------------------- |
| 19 // Base class for Handle instantiations. Don't use directly. | 24 // Base class for Handle instantiations. Don't use directly. |
| 20 class HandleBase { | 25 class HandleBase { |
| 21 public: | 26 public: |
| 22 V8_INLINE explicit HandleBase(Object** location) : location_(location) {} | 27 V8_INLINE explicit HandleBase(Object** location) : location_(location) {} |
| 23 V8_INLINE explicit HandleBase(Object* object, Isolate* isolate); | 28 V8_INLINE explicit HandleBase(Object* object, Isolate* isolate); |
| 24 | 29 |
| 25 // Check if this handle refers to the exact same object as the other handle. | 30 // Check if this handle refers to the exact same object as the other handle. |
| 26 V8_INLINE bool is_identical_to(const HandleBase that) const { | 31 V8_INLINE bool is_identical_to(const HandleBase that) const { |
| 27 // Dereferencing deferred handles to check object equality is safe. | 32 // Dereferencing deferred handles to check object equality is safe. |
| 28 SLOW_DCHECK((this->location_ == NULL || | 33 SLOW_DCHECK((this->location_ == nullptr || |
| 29 this->IsDereferenceAllowed(NO_DEFERRED_CHECK)) && | 34 this->IsDereferenceAllowed(NO_DEFERRED_CHECK)) && |
| 30 (that.location_ == NULL || | 35 (that.location_ == nullptr || |
| 31 that.IsDereferenceAllowed(NO_DEFERRED_CHECK))); | 36 that.IsDereferenceAllowed(NO_DEFERRED_CHECK))); |
| 32 if (this->location_ == that.location_) return true; | 37 if (this->location_ == that.location_) return true; |
| 33 if (this->location_ == NULL || that.location_ == NULL) return false; | 38 if (this->location_ == NULL || that.location_ == NULL) return false; |
| 34 return *this->location_ == *that.location_; | 39 return *this->location_ == *that.location_; |
| 35 } | 40 } |
| 36 | 41 |
| 37 V8_INLINE bool is_null() const { return location_ == nullptr; } | 42 V8_INLINE bool is_null() const { return location_ == nullptr; } |
| 38 | 43 |
| 39 protected: | 44 protected: |
| 40 // Provides the C++ dereference operator. | 45 // Provides the C++ dereference operator. |
| 41 V8_INLINE Object* operator*() const { | 46 V8_INLINE Object* operator*() const { |
| 42 SLOW_DCHECK(IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); | 47 SLOW_DCHECK(IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); |
| 43 return *location_; | 48 return *location_; |
| 44 } | 49 } |
| 45 | 50 |
| 46 // Returns the address to where the raw pointer is stored. | 51 // Returns the address to where the raw pointer is stored. |
| 47 V8_INLINE Object** location() const { | 52 V8_INLINE Object** location() const { |
| 48 SLOW_DCHECK(location_ == NULL || | 53 SLOW_DCHECK(location_ == nullptr || |
| 49 IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); | 54 IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); |
| 50 return location_; | 55 return location_; |
| 51 } | 56 } |
| 52 | 57 |
| 53 enum DereferenceCheckMode { INCLUDE_DEFERRED_CHECK, NO_DEFERRED_CHECK }; | 58 enum DereferenceCheckMode { INCLUDE_DEFERRED_CHECK, NO_DEFERRED_CHECK }; |
| 54 #ifdef DEBUG | 59 #ifdef DEBUG |
| 55 bool IsDereferenceAllowed(DereferenceCheckMode mode) const; | 60 bool IsDereferenceAllowed(DereferenceCheckMode mode) const; |
| 56 #else | 61 #else |
| 57 V8_INLINE | 62 V8_INLINE |
| 58 bool IsDereferenceAllowed(DereferenceCheckMode mode) const { return true; } | 63 bool IsDereferenceAllowed(DereferenceCheckMode mode) const { return true; } |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 void Initialize() { | 348 void Initialize() { |
| 344 next = limit = NULL; | 349 next = limit = NULL; |
| 345 level = 0; | 350 level = 0; |
| 346 } | 351 } |
| 347 }; | 352 }; |
| 348 | 353 |
| 349 } // namespace internal | 354 } // namespace internal |
| 350 } // namespace v8 | 355 } // namespace v8 |
| 351 | 356 |
| 352 #endif // V8_HANDLES_H_ | 357 #endif // V8_HANDLES_H_ |
| OLD | NEW |