| 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 <type_traits> | 8 #include <type_traits> |
| 9 | 9 |
| 10 #include "include/v8.h" | 10 #include "include/v8.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // into a Handle requires checking that it does not point to NULL. This | 178 // into a Handle requires checking that it does not point to NULL. This |
| 179 // ensures NULL checks before use. | 179 // ensures NULL checks before use. |
| 180 // | 180 // |
| 181 // Also note that Handles do not provide default equality comparison or hashing | 181 // Also note that Handles do not provide default equality comparison or hashing |
| 182 // operators on purpose. Such operators would be misleading, because intended | 182 // operators on purpose. Such operators would be misleading, because intended |
| 183 // semantics is ambiguous between Handle location and object identity. | 183 // semantics is ambiguous between Handle location and object identity. |
| 184 template <typename T> | 184 template <typename T> |
| 185 class MaybeHandle final { | 185 class MaybeHandle final { |
| 186 public: | 186 public: |
| 187 V8_INLINE MaybeHandle() {} | 187 V8_INLINE MaybeHandle() {} |
| 188 V8_INLINE ~MaybeHandle() {} | |
| 189 | 188 |
| 190 // Constructor for handling automatic up casting from Handle. | 189 // Constructor for handling automatic up casting from Handle. |
| 191 // Ex. Handle<JSArray> can be passed when MaybeHandle<Object> is expected. | 190 // Ex. Handle<JSArray> can be passed when MaybeHandle<Object> is expected. |
| 192 template <typename S> | 191 template <typename S> |
| 193 V8_INLINE MaybeHandle(Handle<S> handle) | 192 V8_INLINE MaybeHandle(Handle<S> handle) |
| 194 : location_(reinterpret_cast<T**>(handle.location_)) { | 193 : location_(reinterpret_cast<T**>(handle.location_)) { |
| 195 T* a = nullptr; | 194 T* a = nullptr; |
| 196 S* b = nullptr; | 195 S* b = nullptr; |
| 197 a = b; // Fake assignment to enforce type checks. | 196 a = b; // Fake assignment to enforce type checks. |
| 198 USE(a); | 197 USE(a); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 next = limit = NULL; | 413 next = limit = NULL; |
| 415 sealed_level = level = 0; | 414 sealed_level = level = 0; |
| 416 canonical_scope = NULL; | 415 canonical_scope = NULL; |
| 417 } | 416 } |
| 418 }; | 417 }; |
| 419 | 418 |
| 420 } // namespace internal | 419 } // namespace internal |
| 421 } // namespace v8 | 420 } // namespace v8 |
| 422 | 421 |
| 423 #endif // V8_HANDLES_H_ | 422 #endif // V8_HANDLES_H_ |
| OLD | NEW |