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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 // | 84 // |
85 // Also note that Handles do not provide default equality comparison or hashing | 85 // Also note that Handles do not provide default equality comparison or hashing |
86 // operators on purpose. Such operators would be misleading, because intended | 86 // operators on purpose. Such operators would be misleading, because intended |
87 // semantics is ambiguous between Handle location and object identity. Instead | 87 // semantics is ambiguous between Handle location and object identity. Instead |
88 // use either {is_identical_to} or {location} explicitly. | 88 // use either {is_identical_to} or {location} explicitly. |
89 template <typename T> | 89 template <typename T> |
90 class Handle final : public HandleBase { | 90 class Handle final : public HandleBase { |
91 public: | 91 public: |
92 V8_INLINE explicit Handle(T** location = nullptr) | 92 V8_INLINE explicit Handle(T** location = nullptr) |
93 : HandleBase(reinterpret_cast<Object**>(location)) { | 93 : HandleBase(reinterpret_cast<Object**>(location)) { |
94 Object* a = nullptr; | 94 // Type check: |
95 T* b = nullptr; | 95 DCHECK(T::IsObjectSubclass()); |
Michael Starzinger
2017/01/09 11:33:07
Are we allowed to use std::is_base_of (https://chr
marja
2017/01/09 11:48:36
Done.
| |
96 a = b; // Fake assignment to enforce type checks. | |
97 USE(a); | |
98 } | 96 } |
97 | |
99 V8_INLINE explicit Handle(T* object) : Handle(object, object->GetIsolate()) {} | 98 V8_INLINE explicit Handle(T* object) : Handle(object, object->GetIsolate()) {} |
100 V8_INLINE Handle(T* object, Isolate* isolate) : HandleBase(object, isolate) {} | 99 V8_INLINE Handle(T* object, Isolate* isolate) : HandleBase(object, isolate) {} |
101 | 100 |
102 // Allocate a new handle for the object, do not canonicalize. | 101 // Allocate a new handle for the object, do not canonicalize. |
103 V8_INLINE static Handle<T> New(T* object, Isolate* isolate); | 102 V8_INLINE static Handle<T> New(T* object, Isolate* isolate); |
104 | 103 |
105 // Constructor for handling automatic up casting. | 104 // Constructor for handling automatic up casting. |
106 // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected. | 105 // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected. |
107 template <typename S> | 106 template <typename S> |
108 V8_INLINE Handle(Handle<S> handle) | 107 V8_INLINE Handle(Handle<S> handle) |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 next = limit = NULL; | 412 next = limit = NULL; |
414 sealed_level = level = 0; | 413 sealed_level = level = 0; |
415 canonical_scope = NULL; | 414 canonical_scope = NULL; |
416 } | 415 } |
417 }; | 416 }; |
418 | 417 |
419 } // namespace internal | 418 } // namespace internal |
420 } // namespace v8 | 419 } // namespace v8 |
421 | 420 |
422 #endif // V8_HANDLES_H_ | 421 #endif // V8_HANDLES_H_ |
OLD | NEW |