| 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 "src/objects.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 *out = Handle<T>::null(); | 59 *out = Handle<T>::null(); |
| 60 return false; | 60 return false; |
| 61 } else { | 61 } else { |
| 62 *out = Handle<T>(location_); | 62 *out = Handle<T>(location_); |
| 63 return true; | 63 return true; |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool is_null() const { return location_ == NULL; } | 67 bool is_null() const { return location_ == NULL; } |
| 68 | 68 |
| 69 template <typename S> |
| 70 bool operator==(MaybeHandle<S> that) const { |
| 71 return this->location_ == that.location_; |
| 72 } |
| 73 template <typename S> |
| 74 bool operator!=(MaybeHandle<S> that) const { |
| 75 return !(*this == that); |
| 76 } |
| 77 |
| 78 |
| 69 protected: | 79 protected: |
| 70 T** location_; | 80 T** location_; |
| 71 | 81 |
| 72 // MaybeHandles of different classes are allowed to access each | 82 // MaybeHandles of different classes are allowed to access each |
| 73 // other's location_. | 83 // other's location_. |
| 74 template<class S> friend class MaybeHandle; | 84 template<class S> friend class MaybeHandle; |
| 85 template <typename S> |
| 86 friend size_t hash_value(MaybeHandle<S>); |
| 75 }; | 87 }; |
| 76 | 88 |
| 89 template <typename S> |
| 90 inline size_t hash_value(MaybeHandle<S> maybe_handle) { |
| 91 return bit_cast<size_t>(maybe_handle.location_); |
| 92 } |
| 93 |
| 94 |
| 77 // ---------------------------------------------------------------------------- | 95 // ---------------------------------------------------------------------------- |
| 78 // A Handle provides a reference to an object that survives relocation by | 96 // A Handle provides a reference to an object that survives relocation by |
| 79 // the garbage collector. | 97 // the garbage collector. |
| 80 // Handles are only valid within a HandleScope. | 98 // Handles are only valid within a HandleScope. |
| 81 // When a handle is created for an object a cell is allocated in the heap. | 99 // When a handle is created for an object a cell is allocated in the heap. |
| 82 | 100 |
| 83 template<typename T> | 101 template<typename T> |
| 84 class Handle { | 102 class Handle { |
| 85 public: | 103 public: |
| 86 INLINE(explicit Handle(T** location)) { location_ = location; } | 104 INLINE(explicit Handle(T** location)) { location_ = location; } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 307 |
| 290 void Initialize() { | 308 void Initialize() { |
| 291 next = limit = NULL; | 309 next = limit = NULL; |
| 292 level = 0; | 310 level = 0; |
| 293 } | 311 } |
| 294 }; | 312 }; |
| 295 | 313 |
| 296 } } // namespace v8::internal | 314 } } // namespace v8::internal |
| 297 | 315 |
| 298 #endif // V8_HANDLES_H_ | 316 #endif // V8_HANDLES_H_ |
| OLD | NEW |