| 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 "include/v8.h" | 8 #include "include/v8.h" |
| 9 #include "src/base/functional.h" | 9 #include "src/base/functional.h" |
| 10 #include "src/base/macros.h" | 10 #include "src/base/macros.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 this->IsDereferenceAllowed(NO_DEFERRED_CHECK)) && | 36 this->IsDereferenceAllowed(NO_DEFERRED_CHECK)) && |
| 37 (that.location_ == nullptr || | 37 (that.location_ == nullptr || |
| 38 that.IsDereferenceAllowed(NO_DEFERRED_CHECK))); | 38 that.IsDereferenceAllowed(NO_DEFERRED_CHECK))); |
| 39 if (this->location_ == that.location_) return true; | 39 if (this->location_ == that.location_) return true; |
| 40 if (this->location_ == NULL || that.location_ == NULL) return false; | 40 if (this->location_ == NULL || that.location_ == NULL) return false; |
| 41 return *this->location_ == *that.location_; | 41 return *this->location_ == *that.location_; |
| 42 } | 42 } |
| 43 | 43 |
| 44 V8_INLINE bool is_null() const { return location_ == nullptr; } | 44 V8_INLINE bool is_null() const { return location_ == nullptr; } |
| 45 | 45 |
| 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 | |
| 50 protected: | 46 protected: |
| 51 // Provides the C++ dereference operator. | 47 // Provides the C++ dereference operator. |
| 52 V8_INLINE Object* operator*() const { | 48 V8_INLINE Object* operator*() const { |
| 53 SLOW_DCHECK(IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); | 49 SLOW_DCHECK(IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); |
| 54 return *location_; | 50 return *location_; |
| 55 } | 51 } |
| 56 | 52 |
| 57 // Returns the address to where the raw pointer is stored. | 53 // Returns the address to where the raw pointer is stored. |
| 58 V8_INLINE Object** location() const { | 54 V8_INLINE Object** location() const { |
| 59 SLOW_DCHECK(location_ == nullptr || | 55 SLOW_DCHECK(location_ == nullptr || |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 return Handle<T>(reinterpret_cast<T**>(that.location_)); | 125 return Handle<T>(reinterpret_cast<T**>(that.location_)); |
| 130 } | 126 } |
| 131 | 127 |
| 132 // TODO(yangguo): Values that contain empty handles should be declared as | 128 // TODO(yangguo): Values that contain empty handles should be declared as |
| 133 // MaybeHandle to force validation before being used as handles. | 129 // MaybeHandle to force validation before being used as handles. |
| 134 static const Handle<T> null() { return Handle<T>(); } | 130 static const Handle<T> null() { return Handle<T>(); } |
| 135 | 131 |
| 136 // Provide function object for location equality comparison. | 132 // Provide function object for location equality comparison. |
| 137 struct equal_to : public std::binary_function<Handle<T>, Handle<T>, bool> { | 133 struct equal_to : public std::binary_function<Handle<T>, Handle<T>, bool> { |
| 138 V8_INLINE bool operator()(Handle<T> lhs, Handle<T> rhs) const { | 134 V8_INLINE bool operator()(Handle<T> lhs, Handle<T> rhs) const { |
| 139 return lhs.address() == rhs.address(); | 135 return lhs.location() == rhs.location(); |
| 140 } | 136 } |
| 141 }; | 137 }; |
| 142 | 138 |
| 143 // Provide function object for location hashing. | 139 // Provide function object for location hashing. |
| 144 struct hash : public std::unary_function<Handle<T>, size_t> { | 140 struct hash : public std::unary_function<Handle<T>, size_t> { |
| 145 V8_INLINE size_t operator()(Handle<T> const& handle) const { | 141 V8_INLINE size_t operator()(Handle<T> const& handle) const { |
| 146 return base::hash<void*>()(handle.address()); | 142 return base::hash<void*>()(handle.location()); |
| 147 } | 143 } |
| 148 }; | 144 }; |
| 149 | 145 |
| 150 private: | 146 private: |
| 151 // Handles of different classes are allowed to access each other's location_. | 147 // Handles of different classes are allowed to access each other's location_. |
| 152 template <typename> | 148 template <typename> |
| 153 friend class Handle; | 149 friend class Handle; |
| 154 // MaybeHandle is allowed to access location_. | 150 // MaybeHandle is allowed to access location_. |
| 155 template <typename> | 151 template <typename> |
| 156 friend class MaybeHandle; | 152 friend class MaybeHandle; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 next = limit = NULL; | 399 next = limit = NULL; |
| 404 sealed_level = level = 0; | 400 sealed_level = level = 0; |
| 405 canonical_scope = NULL; | 401 canonical_scope = NULL; |
| 406 } | 402 } |
| 407 }; | 403 }; |
| 408 | 404 |
| 409 } // namespace internal | 405 } // namespace internal |
| 410 } // namespace v8 | 406 } // namespace v8 |
| 411 | 407 |
| 412 #endif // V8_HANDLES_H_ | 408 #endif // V8_HANDLES_H_ |
| OLD | NEW |