| 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 27 matching lines...) Expand all Loading... |
| 38 namespace internal { | 38 namespace internal { |
| 39 | 39 |
| 40 inline Isolate* GetIsolateForHandle(Object* obj) { | 40 inline Isolate* GetIsolateForHandle(Object* obj) { |
| 41 return Isolate::Current(); | 41 return Isolate::Current(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 inline Isolate* GetIsolateForHandle(HeapObject* obj) { | 44 inline Isolate* GetIsolateForHandle(HeapObject* obj) { |
| 45 return obj->GetIsolate(); | 45 return obj->GetIsolate(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 template<class T> | 48 template<typename T> |
| 49 Handle<T>::Handle(T* obj) { | 49 Handle<T>::Handle(T* obj) { |
| 50 ASSERT(!obj->IsFailure()); | 50 ASSERT(!obj->IsFailure()); |
| 51 location_ = HandleScope::CreateHandle(obj, GetIsolateForHandle(obj)); | 51 location_ = HandleScope::CreateHandle(obj, GetIsolateForHandle(obj)); |
| 52 } | 52 } |
| 53 | 53 |
| 54 | 54 |
| 55 template<class T> | 55 template<typename T> |
| 56 Handle<T>::Handle(T* obj, Isolate* isolate) { | 56 Handle<T>::Handle(T* obj, Isolate* isolate) { |
| 57 ASSERT(!obj->IsFailure()); | 57 ASSERT(!obj->IsFailure()); |
| 58 location_ = HandleScope::CreateHandle(obj, isolate); | 58 location_ = HandleScope::CreateHandle(obj, isolate); |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 template <class T> | 62 template <typename T> |
| 63 inline T* Handle<T>::operator*() const { | 63 inline T* Handle<T>::operator*() const { |
| 64 ASSERT(location_ != NULL); | 64 ASSERT(location_ != NULL); |
| 65 ASSERT(reinterpret_cast<Address>(*location_) != kHandleZapValue); | 65 ASSERT(reinterpret_cast<Address>(*location_) != kHandleZapValue); |
| 66 return *BitCast<T**>(location_); | 66 return *BitCast<T**>(location_); |
| 67 } | 67 } |
| 68 | 68 |
| 69 | 69 |
| 70 HandleScope::HandleScope() { | 70 HandleScope::HandleScope() { |
| 71 Isolate* isolate = Isolate::Current(); | 71 Isolate* isolate = Isolate::Current(); |
| 72 v8::ImplementationUtilities::HandleScopeData* current = | 72 v8::ImplementationUtilities::HandleScopeData* current = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 83 v8::ImplementationUtilities::HandleScopeData* current = | 83 v8::ImplementationUtilities::HandleScopeData* current = |
| 84 isolate->handle_scope_data(); | 84 isolate->handle_scope_data(); |
| 85 isolate_ = isolate; | 85 isolate_ = isolate; |
| 86 prev_next_ = current->next; | 86 prev_next_ = current->next; |
| 87 prev_limit_ = current->limit; | 87 prev_limit_ = current->limit; |
| 88 current->level++; | 88 current->level++; |
| 89 } | 89 } |
| 90 | 90 |
| 91 | 91 |
| 92 HandleScope::~HandleScope() { | 92 HandleScope::~HandleScope() { |
| 93 CloseScope(); |
| 94 } |
| 95 |
| 96 void HandleScope::CloseScope() { |
| 93 ASSERT(isolate_ == Isolate::Current()); | 97 ASSERT(isolate_ == Isolate::Current()); |
| 94 v8::ImplementationUtilities::HandleScopeData* current = | 98 v8::ImplementationUtilities::HandleScopeData* current = |
| 95 isolate_->handle_scope_data(); | 99 isolate_->handle_scope_data(); |
| 96 current->next = prev_next_; | 100 current->next = prev_next_; |
| 97 current->level--; | 101 current->level--; |
| 98 if (current->limit != prev_limit_) { | 102 if (current->limit != prev_limit_) { |
| 99 current->limit = prev_limit_; | 103 current->limit = prev_limit_; |
| 100 DeleteExtensions(isolate_); | 104 DeleteExtensions(isolate_); |
| 101 } | 105 } |
| 102 #ifdef DEBUG | 106 #ifdef DEBUG |
| 103 ZapRange(prev_next_, prev_limit_); | 107 ZapRange(prev_next_, prev_limit_); |
| 104 #endif | 108 #endif |
| 105 } | 109 } |
| 106 | 110 |
| 107 | 111 |
| 108 template <typename T> | 112 template <typename T> |
| 113 Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) { |
| 114 T* value = *handle_value; |
| 115 // Throw away all handles in the current scope. |
| 116 CloseScope(); |
| 117 v8::ImplementationUtilities::HandleScopeData* current = |
| 118 isolate_->handle_scope_data(); |
| 119 // Allocate one handle in the parent scope. |
| 120 ASSERT(current->level > 0); |
| 121 Handle<T> result(CreateHandle<T>(value, isolate_)); |
| 122 // Reinitialize the current scope (so that it's ready |
| 123 // to be used or closed again). |
| 124 prev_next_ = current->next; |
| 125 prev_limit_ = current->limit; |
| 126 current->level++; |
| 127 return result; |
| 128 } |
| 129 |
| 130 |
| 131 template <typename T> |
| 109 T** HandleScope::CreateHandle(T* value, Isolate* isolate) { | 132 T** HandleScope::CreateHandle(T* value, Isolate* isolate) { |
| 110 ASSERT(isolate == Isolate::Current()); | 133 ASSERT(isolate == Isolate::Current()); |
| 111 v8::ImplementationUtilities::HandleScopeData* current = | 134 v8::ImplementationUtilities::HandleScopeData* current = |
| 112 isolate->handle_scope_data(); | 135 isolate->handle_scope_data(); |
| 113 | 136 |
| 114 internal::Object** cur = current->next; | 137 internal::Object** cur = current->next; |
| 115 if (cur == current->limit) cur = Extend(); | 138 if (cur == current->limit) cur = Extend(); |
| 116 // Update the current next field, set the value in the created | 139 // Update the current next field, set the value in the created |
| 117 // handle, and return the result. | 140 // handle, and return the result. |
| 118 ASSERT(cur < current->limit); | 141 ASSERT(cur < current->limit); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 145 Isolate::Current()->handle_scope_data(); | 168 Isolate::Current()->handle_scope_data(); |
| 146 ASSERT_EQ(0, data->level); | 169 ASSERT_EQ(0, data->level); |
| 147 data->level = level_; | 170 data->level = level_; |
| 148 } | 171 } |
| 149 #endif | 172 #endif |
| 150 | 173 |
| 151 | 174 |
| 152 } } // namespace v8::internal | 175 } } // namespace v8::internal |
| 153 | 176 |
| 154 #endif // V8_HANDLES_INL_H_ | 177 #endif // V8_HANDLES_INL_H_ |
| OLD | NEW |