| OLD | NEW |
| 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 template <class T> Local<T> Close(Handle<T> value); | 429 template <class T> Local<T> Close(Handle<T> value); |
| 430 | 430 |
| 431 /** | 431 /** |
| 432 * Counts the number of allocated handles. | 432 * Counts the number of allocated handles. |
| 433 */ | 433 */ |
| 434 static int NumberOfHandles(); | 434 static int NumberOfHandles(); |
| 435 | 435 |
| 436 /** | 436 /** |
| 437 * Creates a new handle with the given value. | 437 * Creates a new handle with the given value. |
| 438 */ | 438 */ |
| 439 static internal::Object** CreateHandle(internal::Object* value); | 439 template <class T> |
| 440 static internal::Object** CreateHandle(T* value); |
| 440 | 441 |
| 441 private: | 442 private: |
| 442 // Make it impossible to create heap-allocated or illegal handle | 443 // Make it impossible to create heap-allocated or illegal handle |
| 443 // scopes by disallowing certain operations. | 444 // scopes by disallowing certain operations. |
| 444 HandleScope(const HandleScope&); | 445 HandleScope(const HandleScope&); |
| 445 void operator=(const HandleScope&); | 446 void operator=(const HandleScope&); |
| 446 void* operator new(size_t size); | 447 void* operator new(size_t size); |
| 447 void operator delete(void*, size_t); | 448 void operator delete(void*, size_t); |
| 448 | 449 |
| 449 // This Data class is accessible internally as HandleScopeData through a | 450 // This Data class is accessible internally as HandleScopeData through a |
| (...skipping 3042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3492 Handle<T>::Handle() : val_(0) { } | 3493 Handle<T>::Handle() : val_(0) { } |
| 3493 | 3494 |
| 3494 | 3495 |
| 3495 template <class T> | 3496 template <class T> |
| 3496 Local<T>::Local() : Handle<T>() { } | 3497 Local<T>::Local() : Handle<T>() { } |
| 3497 | 3498 |
| 3498 | 3499 |
| 3499 template <class T> | 3500 template <class T> |
| 3500 Local<T> Local<T>::New(Handle<T> that) { | 3501 Local<T> Local<T>::New(Handle<T> that) { |
| 3501 if (that.IsEmpty()) return Local<T>(); | 3502 if (that.IsEmpty()) return Local<T>(); |
| 3502 internal::Object** p = reinterpret_cast<internal::Object**>(*that); | 3503 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*that))); |
| 3503 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); | |
| 3504 } | 3504 } |
| 3505 | 3505 |
| 3506 | 3506 |
| 3507 template <class T> | 3507 template <class T> |
| 3508 Persistent<T> Persistent<T>::New(Handle<T> that) { | 3508 Persistent<T> Persistent<T>::New(Handle<T> that) { |
| 3509 if (that.IsEmpty()) return Persistent<T>(); | 3509 if (that.IsEmpty()) return Persistent<T>(); |
| 3510 internal::Object** p = reinterpret_cast<internal::Object**>(*that); | 3510 internal::Object** p = reinterpret_cast<internal::Object**>(*that); |
| 3511 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); | 3511 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); |
| 3512 } | 3512 } |
| 3513 | 3513 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3640 Local<Value> Object::UncheckedGetInternalField(int index) { | 3640 Local<Value> Object::UncheckedGetInternalField(int index) { |
| 3641 typedef internal::Object O; | 3641 typedef internal::Object O; |
| 3642 typedef internal::Internals I; | 3642 typedef internal::Internals I; |
| 3643 O* obj = *reinterpret_cast<O**>(this); | 3643 O* obj = *reinterpret_cast<O**>(this); |
| 3644 if (I::GetInstanceType(obj) == I::kJSObjectType) { | 3644 if (I::GetInstanceType(obj) == I::kJSObjectType) { |
| 3645 // If the object is a plain JSObject, which is the common case, | 3645 // If the object is a plain JSObject, which is the common case, |
| 3646 // we know where to find the internal fields and can return the | 3646 // we know where to find the internal fields and can return the |
| 3647 // value directly. | 3647 // value directly. |
| 3648 int offset = I::kJSObjectHeaderSize + (internal::kPointerSize * index); | 3648 int offset = I::kJSObjectHeaderSize + (internal::kPointerSize * index); |
| 3649 O* value = I::ReadField<O*>(obj, offset); | 3649 O* value = I::ReadField<O*>(obj, offset); |
| 3650 O** result = HandleScope::CreateHandle(value); | 3650 O** result = HandleScope::CreateHandle(reinterpret_cast<Value*>(&value)); |
| 3651 return Local<Value>(reinterpret_cast<Value*>(result)); | 3651 return Local<Value>(reinterpret_cast<Value*>(result)); |
| 3652 } else { | 3652 } else { |
| 3653 return Local<Value>(); | 3653 return Local<Value>(); |
| 3654 } | 3654 } |
| 3655 } | 3655 } |
| 3656 | 3656 |
| 3657 | 3657 |
| 3658 void* External::Unwrap(Handle<v8::Value> obj) { | 3658 void* External::Unwrap(Handle<v8::Value> obj) { |
| 3659 #ifdef V8_ENABLE_CHECKS | 3659 #ifdef V8_ENABLE_CHECKS |
| 3660 return FullUnwrap(obj); | 3660 return FullUnwrap(obj); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3825 | 3825 |
| 3826 | 3826 |
| 3827 } // namespace v8 | 3827 } // namespace v8 |
| 3828 | 3828 |
| 3829 | 3829 |
| 3830 #undef V8EXPORT | 3830 #undef V8EXPORT |
| 3831 #undef TYPE_CHECK | 3831 #undef TYPE_CHECK |
| 3832 | 3832 |
| 3833 | 3833 |
| 3834 #endif // V8_H_ | 3834 #endif // V8_H_ |
| OLD | NEW |