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