| 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 11 matching lines...) Expand all Loading... |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 // | 27 // |
| 28 | 28 |
| 29 #ifndef V8_HANDLES_INL_H_ | 29 #ifndef V8_HANDLES_INL_H_ |
| 30 #define V8_HANDLES_INL_H_ | 30 #define V8_HANDLES_INL_H_ |
| 31 | 31 |
| 32 #include "api.h" |
| 32 #include "apiutils.h" | 33 #include "apiutils.h" |
| 33 #include "handles.h" | 34 #include "handles.h" |
| 34 #include "api.h" | 35 #include "isolate.h" |
| 35 | 36 |
| 36 namespace v8 { | 37 namespace v8 { |
| 37 namespace internal { | 38 namespace internal { |
| 38 | 39 |
| 39 template<class T> | 40 template<class T> |
| 40 Handle<T>::Handle(T* obj) { | 41 Handle<T>::Handle(T* obj) { |
| 41 ASSERT(!obj->IsFailure()); | 42 ASSERT(!obj->IsFailure()); |
| 42 location_ = HandleScope::CreateHandle(obj); | 43 location_ = HandleScope::CreateHandle(obj); |
| 43 } | 44 } |
| 44 | 45 |
| 45 | 46 |
| 46 template <class T> | 47 template <class T> |
| 47 inline T* Handle<T>::operator*() const { | 48 inline T* Handle<T>::operator*() const { |
| 48 ASSERT(location_ != NULL); | 49 ASSERT(location_ != NULL); |
| 49 ASSERT(reinterpret_cast<Address>(*location_) != kHandleZapValue); | 50 ASSERT(reinterpret_cast<Address>(*location_) != kHandleZapValue); |
| 50 return *location_; | 51 return *location_; |
| 51 } | 52 } |
| 52 | 53 |
| 53 | 54 |
| 55 HandleScope::HandleScope() |
| 56 : previous_(*Isolate::Current()->handle_scope_data()) { |
| 57 Isolate::Current()->handle_scope_data()->extensions = 0; |
| 58 } |
| 59 |
| 60 |
| 61 template <typename T> |
| 62 T** HandleScope::CreateHandle(T* value) { |
| 63 v8::ImplementationUtilities::HandleScopeData* current = |
| 64 Isolate::Current()->handle_scope_data(); |
| 65 |
| 66 internal::Object** cur = current->next; |
| 67 if (cur == current->limit) cur = Extend(); |
| 68 // Update the current next field, set the value in the created |
| 69 // handle, and return the result. |
| 70 ASSERT(cur < current->limit); |
| 71 current->next = cur + 1; |
| 72 |
| 73 T** result = reinterpret_cast<T**>(cur); |
| 74 *result = value; |
| 75 return result; |
| 76 } |
| 77 |
| 78 |
| 79 void HandleScope::Enter( |
| 80 v8::ImplementationUtilities::HandleScopeData* previous) { |
| 81 v8::ImplementationUtilities::HandleScopeData* current = |
| 82 Isolate::Current()->handle_scope_data(); |
| 83 *previous = *current; |
| 84 current->extensions = 0; |
| 85 } |
| 86 |
| 87 |
| 88 void HandleScope::Leave( |
| 89 const v8::ImplementationUtilities::HandleScopeData* previous) { |
| 90 Isolate* isolate = Isolate::Current(); |
| 91 v8::ImplementationUtilities::HandleScopeData* current = |
| 92 isolate->handle_scope_data(); |
| 93 if (current->extensions > 0) { |
| 94 DeleteExtensions(isolate); |
| 95 } |
| 96 *current = *previous; |
| 97 #ifdef DEBUG |
| 98 ZapRange(current->next, current->limit); |
| 99 #endif |
| 100 } |
| 101 |
| 102 |
| 54 #ifdef DEBUG | 103 #ifdef DEBUG |
| 55 inline NoHandleAllocation::NoHandleAllocation() { | 104 inline NoHandleAllocation::NoHandleAllocation() { |
| 56 v8::ImplementationUtilities::HandleScopeData* current = | 105 v8::ImplementationUtilities::HandleScopeData* current = |
| 57 Isolate::Current()->handle_scope_data(); | 106 Isolate::Current()->handle_scope_data(); |
| 58 extensions_ = current->extensions; | 107 extensions_ = current->extensions; |
| 59 // Shrink the current handle scope to make it impossible to do | 108 // Shrink the current handle scope to make it impossible to do |
| 60 // handle allocations without an explicit handle scope. | 109 // handle allocations without an explicit handle scope. |
| 61 current->limit = current->next; | 110 current->limit = current->next; |
| 62 current->extensions = -1; | 111 current->extensions = -1; |
| 63 } | 112 } |
| 64 | 113 |
| 65 | 114 |
| 66 inline NoHandleAllocation::~NoHandleAllocation() { | 115 inline NoHandleAllocation::~NoHandleAllocation() { |
| 67 // Restore state in current handle scope to re-enable handle | 116 // Restore state in current handle scope to re-enable handle |
| 68 // allocations. | 117 // allocations. |
| 69 Isolate::Current()->handle_scope_data()->extensions = extensions_; | 118 Isolate::Current()->handle_scope_data()->extensions = extensions_; |
| 70 } | 119 } |
| 71 #endif | 120 #endif |
| 72 | 121 |
| 73 | 122 |
| 74 } } // namespace v8::internal | 123 } } // namespace v8::internal |
| 75 | 124 |
| 76 #endif // V8_HANDLES_INL_H_ | 125 #endif // V8_HANDLES_INL_H_ |
| OLD | NEW |