| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 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 || !(*location_)->IsFailure()); |
| 57 reinterpret_cast<Address>(*location_) != kZapValue); | 57 if (location_ == other.location_) return true; |
| 58 if (location_ == NULL || other.location_ == NULL) return false; |
| 58 // Dereferencing deferred handles to check object equality is safe. | 59 // Dereferencing deferred handles to check object equality is safe. |
| 59 SLOW_ASSERT(IsDereferenceAllowed(true) && other.IsDereferenceAllowed(true)); | 60 SLOW_ASSERT(IsDereferenceAllowed(true) && other.IsDereferenceAllowed(true)); |
| 60 return *location_ == *other.location_; | 61 return *location_ == *other.location_; |
| 61 } | 62 } |
| 62 | 63 |
| 63 | 64 |
| 64 template <typename T> | 65 template <typename T> |
| 65 inline T* Handle<T>::operator*() const { | 66 inline T* Handle<T>::operator*() const { |
| 66 ASSERT(location_ != NULL); | 67 ASSERT(location_ != NULL && !(*location_)->IsFailure()); |
| 67 ASSERT(reinterpret_cast<Address>(*location_) != kHandleZapValue); | |
| 68 SLOW_ASSERT(IsDereferenceAllowed(false)); | 68 SLOW_ASSERT(IsDereferenceAllowed(false)); |
| 69 return *BitCast<T**>(location_); | 69 return *BitCast<T**>(location_); |
| 70 } | 70 } |
| 71 | 71 |
| 72 template <typename T> | 72 template <typename T> |
| 73 inline T** Handle<T>::location() const { | 73 inline T** Handle<T>::location() const { |
| 74 ASSERT(location_ == NULL || | 74 ASSERT(location_ == NULL || !(*location_)->IsFailure()); |
| 75 reinterpret_cast<Address>(*location_) != kZapValue); | 75 SLOW_ASSERT(location_ == NULL || IsDereferenceAllowed(false)); |
| 76 SLOW_ASSERT(IsDereferenceAllowed(false)); | |
| 77 return location_; | 76 return location_; |
| 78 } | 77 } |
| 79 | 78 |
| 80 #ifdef DEBUG | 79 #ifdef DEBUG |
| 81 template <typename T> | 80 template <typename T> |
| 82 bool Handle<T>::IsDereferenceAllowed(bool allow_deferred) const { | 81 bool Handle<T>::IsDereferenceAllowed(bool allow_deferred) const { |
| 83 if (location_ == NULL) return true; | 82 ASSERT(location_ != NULL); |
| 84 Object* object = *BitCast<T**>(location_); | 83 Object* object = *BitCast<T**>(location_); |
| 85 if (object->IsSmi()) return true; | 84 if (object->IsSmi()) return true; |
| 86 HeapObject* heap_object = HeapObject::cast(object); | 85 HeapObject* heap_object = HeapObject::cast(object); |
| 87 Isolate* isolate = heap_object->GetIsolate(); | 86 Isolate* isolate = heap_object->GetIsolate(); |
| 88 Object** handle = reinterpret_cast<Object**>(location_); | 87 Object** handle = reinterpret_cast<Object**>(location_); |
| 89 Object** roots_array_start = isolate->heap()->roots_array_start(); | 88 Object** roots_array_start = isolate->heap()->roots_array_start(); |
| 90 if (roots_array_start <= handle && | 89 if (roots_array_start <= handle && |
| 91 handle < roots_array_start + Heap::kStrongRootListLength) { | 90 handle < roots_array_start + Heap::kStrongRootListLength) { |
| 92 return true; | 91 return true; |
| 93 } | 92 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 216 |
| 218 HandleDereferenceGuard::~HandleDereferenceGuard() { | 217 HandleDereferenceGuard::~HandleDereferenceGuard() { |
| 219 isolate_->SetHandleDereferenceGuardState(old_state_); | 218 isolate_->SetHandleDereferenceGuardState(old_state_); |
| 220 } | 219 } |
| 221 | 220 |
| 222 #endif | 221 #endif |
| 223 | 222 |
| 224 } } // namespace v8::internal | 223 } } // namespace v8::internal |
| 225 | 224 |
| 226 #endif // V8_HANDLES_INL_H_ | 225 #endif // V8_HANDLES_INL_H_ |
| OLD | NEW |