OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 template<typename T> | 47 template<typename T> |
48 Handle<T>::Handle(T* obj, Isolate* isolate) { | 48 Handle<T>::Handle(T* obj, Isolate* isolate) { |
49 ASSERT(!obj->IsFailure()); | 49 ASSERT(!obj->IsFailure()); |
50 location_ = HandleScope::CreateHandle(isolate, obj); | 50 location_ = HandleScope::CreateHandle(isolate, obj); |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 template <typename T> | 54 template <typename T> |
55 inline bool Handle<T>::is_identical_to(const Handle<T> other) const { | 55 inline bool Handle<T>::is_identical_to(const Handle<T> other) const { |
56 ASSERT(location_ == NULL || | 56 ASSERT(location_ == NULL || |
57 reinterpret_cast<Address>(*location_) != kZapValue); | 57 reinterpret_cast<Address>(*location_) != kZapValue); |
Michael Starzinger
2013/05/07 11:58:37
As discussed offline: This should actually check a
rossberg
2013/05/07 12:00:25
Done (here and elsewhere).
| |
58 if (location_ == other.location_) return true; | |
59 if (location_ == NULL || other.location_ == NULL) return false; | |
58 // Dereferencing deferred handles to check object equality is safe. | 60 // Dereferencing deferred handles to check object equality is safe. |
59 SLOW_ASSERT(IsDereferenceAllowed(true) && other.IsDereferenceAllowed(true)); | 61 SLOW_ASSERT(IsDereferenceAllowed(true) && other.IsDereferenceAllowed(true)); |
60 return *location_ == *other.location_; | 62 return *location_ == *other.location_; |
61 } | 63 } |
62 | 64 |
63 | 65 |
64 template <typename T> | 66 template <typename T> |
65 inline T* Handle<T>::operator*() const { | 67 inline T* Handle<T>::operator*() const { |
66 ASSERT(location_ != NULL); | 68 ASSERT(location_ != NULL); |
67 ASSERT(reinterpret_cast<Address>(*location_) != kHandleZapValue); | 69 ASSERT(reinterpret_cast<Address>(*location_) != kHandleZapValue); |
68 SLOW_ASSERT(IsDereferenceAllowed(false)); | 70 SLOW_ASSERT(IsDereferenceAllowed(false)); |
69 return *BitCast<T**>(location_); | 71 return *BitCast<T**>(location_); |
70 } | 72 } |
71 | 73 |
72 template <typename T> | 74 template <typename T> |
73 inline T** Handle<T>::location() const { | 75 inline T** Handle<T>::location() const { |
74 ASSERT(location_ == NULL || | 76 ASSERT(location_ == NULL || |
75 reinterpret_cast<Address>(*location_) != kZapValue); | 77 reinterpret_cast<Address>(*location_) != kZapValue); |
76 SLOW_ASSERT(IsDereferenceAllowed(false)); | 78 SLOW_ASSERT(location_ == NULL || IsDereferenceAllowed(false)); |
77 return location_; | 79 return location_; |
78 } | 80 } |
79 | 81 |
80 #ifdef DEBUG | 82 #ifdef DEBUG |
81 template <typename T> | 83 template <typename T> |
82 bool Handle<T>::IsDereferenceAllowed(bool allow_deferred) const { | 84 bool Handle<T>::IsDereferenceAllowed(bool allow_deferred) const { |
83 if (location_ == NULL) return true; | 85 ASSERT(location_ != NULL); |
84 Object* object = *BitCast<T**>(location_); | 86 Object* object = *BitCast<T**>(location_); |
85 if (object->IsSmi()) return true; | 87 if (object->IsSmi()) return true; |
86 HeapObject* heap_object = HeapObject::cast(object); | 88 HeapObject* heap_object = HeapObject::cast(object); |
87 Isolate* isolate = heap_object->GetIsolate(); | 89 Isolate* isolate = heap_object->GetIsolate(); |
88 Object** handle = reinterpret_cast<Object**>(location_); | 90 Object** handle = reinterpret_cast<Object**>(location_); |
89 Object** roots_array_start = isolate->heap()->roots_array_start(); | 91 Object** roots_array_start = isolate->heap()->roots_array_start(); |
90 if (roots_array_start <= handle && | 92 if (roots_array_start <= handle && |
91 handle < roots_array_start + Heap::kStrongRootListLength) { | 93 handle < roots_array_start + Heap::kStrongRootListLength) { |
92 return true; | 94 return true; |
93 } | 95 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 | 219 |
218 HandleDereferenceGuard::~HandleDereferenceGuard() { | 220 HandleDereferenceGuard::~HandleDereferenceGuard() { |
219 isolate_->SetHandleDereferenceGuardState(old_state_); | 221 isolate_->SetHandleDereferenceGuardState(old_state_); |
220 } | 222 } |
221 | 223 |
222 #endif | 224 #endif |
223 | 225 |
224 } } // namespace v8::internal | 226 } } // namespace v8::internal |
225 | 227 |
226 #endif // V8_HANDLES_INL_H_ | 228 #endif // V8_HANDLES_INL_H_ |
OLD | NEW |