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/macros.h" | 10 #include "src/base/macros.h" |
10 #include "src/checks.h" | 11 #include "src/checks.h" |
11 #include "src/globals.h" | 12 #include "src/globals.h" |
12 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 | 16 |
16 // Forward declarations. | 17 // Forward declarations. |
17 class DeferredHandles; | 18 class DeferredHandles; |
18 class HandleScopeImplementer; | 19 class HandleScopeImplementer; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 template <typename S> | 112 template <typename S> |
112 static const Handle<T> cast(Handle<S> that) { | 113 static const Handle<T> cast(Handle<S> that) { |
113 T::cast(*reinterpret_cast<T**>(that.location_)); | 114 T::cast(*reinterpret_cast<T**>(that.location_)); |
114 return Handle<T>(reinterpret_cast<T**>(that.location_)); | 115 return Handle<T>(reinterpret_cast<T**>(that.location_)); |
115 } | 116 } |
116 | 117 |
117 // TODO(yangguo): Values that contain empty handles should be declared as | 118 // TODO(yangguo): Values that contain empty handles should be declared as |
118 // MaybeHandle to force validation before being used as handles. | 119 // MaybeHandle to force validation before being used as handles. |
119 static const Handle<T> null() { return Handle<T>(); } | 120 static const Handle<T> null() { return Handle<T>(); } |
120 | 121 |
| 122 // Provide function object for location equality comparison. |
| 123 struct equal_to : public std::binary_function<Handle<T>, Handle<T>, bool> { |
| 124 V8_INLINE bool operator()(Handle<T> lhs, Handle<T> rhs) const { |
| 125 return lhs.location() == rhs.location(); |
| 126 } |
| 127 }; |
| 128 |
| 129 // Provide function object for location hashing. |
| 130 struct hash : public std::unary_function<Handle<T>, size_t> { |
| 131 V8_INLINE size_t operator()(Handle<T> const& handle) const { |
| 132 return base::hash<void*>()(handle.location()); |
| 133 } |
| 134 }; |
| 135 |
121 private: | 136 private: |
122 // Handles of different classes are allowed to access each other's location_. | 137 // Handles of different classes are allowed to access each other's location_. |
123 template <typename> | 138 template <typename> |
124 friend class Handle; | 139 friend class Handle; |
125 // MaybeHandle is allowed to access location_. | 140 // MaybeHandle is allowed to access location_. |
126 template <typename> | 141 template <typename> |
127 friend class MaybeHandle; | 142 friend class MaybeHandle; |
128 }; | 143 }; |
129 | 144 |
130 template <typename T> | 145 template <typename T> |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 void Initialize() { | 363 void Initialize() { |
349 next = limit = NULL; | 364 next = limit = NULL; |
350 level = 0; | 365 level = 0; |
351 } | 366 } |
352 }; | 367 }; |
353 | 368 |
354 } // namespace internal | 369 } // namespace internal |
355 } // namespace v8 | 370 } // namespace v8 |
356 | 371 |
357 #endif // V8_HANDLES_H_ | 372 #endif // V8_HANDLES_H_ |
OLD | NEW |