OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 USE(a); | 65 USE(a); |
66 #endif | 66 #endif |
67 location_ = reinterpret_cast<T**>(maybe_handle.location_); | 67 location_ = reinterpret_cast<T**>(maybe_handle.location_); |
68 } | 68 } |
69 | 69 |
70 INLINE(Handle<T> ToHandleChecked()) { | 70 INLINE(Handle<T> ToHandleChecked()) { |
71 CHECK(location_ != NULL); | 71 CHECK(location_ != NULL); |
72 return Handle<T>(location_); | 72 return Handle<T>(location_); |
73 } | 73 } |
74 | 74 |
75 INLINE(bool ToHandle(Handle<T>* out)) { | 75 // Convert to a Handle with a type that can be upcasted to. |
| 76 template <class S> INLINE(bool ToHandle(Handle<S>* out)) { |
76 if (location_ == NULL) { | 77 if (location_ == NULL) { |
77 *out = Handle<T>::null(); | 78 *out = Handle<T>::null(); |
78 return false; | 79 return false; |
79 } else { | 80 } else { |
80 *out = Handle<T>(location_); | 81 *out = Handle<T>(location_); |
81 return true; | 82 return true; |
82 } | 83 } |
83 } | 84 } |
84 | 85 |
| 86 bool is_null() const { return location_ == NULL; } |
| 87 |
85 protected: | 88 protected: |
86 T** location_; | 89 T** location_; |
87 | 90 |
88 // MaybeHandles of different classes are allowed to access each | 91 // MaybeHandles of different classes are allowed to access each |
89 // other's location_. | 92 // other's location_. |
90 template<class S> friend class MaybeHandle; | 93 template<class S> friend class MaybeHandle; |
91 }; | 94 }; |
92 | 95 |
93 // ---------------------------------------------------------------------------- | 96 // ---------------------------------------------------------------------------- |
94 // A Handle provides a reference to an object that survives relocation by | 97 // A Handle provides a reference to an object that survives relocation by |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 382 |
380 void Initialize() { | 383 void Initialize() { |
381 next = limit = NULL; | 384 next = limit = NULL; |
382 level = 0; | 385 level = 0; |
383 } | 386 } |
384 }; | 387 }; |
385 | 388 |
386 } } // namespace v8::internal | 389 } } // namespace v8::internal |
387 | 390 |
388 #endif // V8_HANDLES_H_ | 391 #endif // V8_HANDLES_H_ |
OLD | NEW |