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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 static internal::Object** CreateHandle(internal::Object* value); |
| 440 static internal::Object** CreateHandleFromHeapObject(internal::Object* 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 3026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3476 static inline bool IsExternalTwoByteString(int instance_type) { | 3477 static inline bool IsExternalTwoByteString(int instance_type) { |
3477 int representation = (instance_type & kFullStringRepresentationMask); | 3478 int representation = (instance_type & kFullStringRepresentationMask); |
3478 return representation == kExternalTwoByteRepresentationTag; | 3479 return representation == kExternalTwoByteRepresentationTag; |
3479 } | 3480 } |
3480 | 3481 |
3481 template <typename T> | 3482 template <typename T> |
3482 static inline T ReadField(Object* ptr, int offset) { | 3483 static inline T ReadField(Object* ptr, int offset) { |
3483 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; | 3484 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
3484 return *reinterpret_cast<T*>(addr); | 3485 return *reinterpret_cast<T*>(addr); |
3485 } | 3486 } |
| 3487 |
| 3488 static inline bool IsHeapObject(void*) { return false; } |
| 3489 static inline bool IsHeapObject(Date*) { return true; } |
3486 }; | 3490 }; |
3487 | 3491 |
3488 } // namespace internal | 3492 } // namespace internal |
3489 | 3493 |
3490 | 3494 |
3491 template <class T> | 3495 template <class T> |
3492 Handle<T>::Handle() : val_(0) { } | 3496 Handle<T>::Handle() : val_(0) { } |
3493 | 3497 |
3494 | 3498 |
3495 template <class T> | 3499 template <class T> |
3496 Local<T>::Local() : Handle<T>() { } | 3500 Local<T>::Local() : Handle<T>() { } |
3497 | 3501 |
3498 | 3502 |
3499 template <class T> | 3503 template <class T> |
3500 Local<T> Local<T>::New(Handle<T> that) { | 3504 Local<T> Local<T>::New(Handle<T> that) { |
3501 if (that.IsEmpty()) return Local<T>(); | 3505 if (that.IsEmpty()) return Local<T>(); |
3502 internal::Object** p = reinterpret_cast<internal::Object**>(*that); | 3506 T* that_ptr = *that; |
| 3507 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 3508 if (internal::Internals::IsHeapObject(that_ptr)) { |
| 3509 return Local<T>( |
| 3510 reinterpret_cast<T*>(HandleScope::CreateHandleFromHeapObject(*p))); |
| 3511 } |
3503 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); | 3512 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
3504 } | 3513 } |
3505 | 3514 |
3506 | 3515 |
3507 template <class T> | 3516 template <class T> |
3508 Persistent<T> Persistent<T>::New(Handle<T> that) { | 3517 Persistent<T> Persistent<T>::New(Handle<T> that) { |
3509 if (that.IsEmpty()) return Persistent<T>(); | 3518 if (that.IsEmpty()) return Persistent<T>(); |
3510 internal::Object** p = reinterpret_cast<internal::Object**>(*that); | 3519 internal::Object** p = reinterpret_cast<internal::Object**>(*that); |
3511 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); | 3520 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); |
3512 } | 3521 } |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3825 | 3834 |
3826 | 3835 |
3827 } // namespace v8 | 3836 } // namespace v8 |
3828 | 3837 |
3829 | 3838 |
3830 #undef V8EXPORT | 3839 #undef V8EXPORT |
3831 #undef TYPE_CHECK | 3840 #undef TYPE_CHECK |
3832 | 3841 |
3833 | 3842 |
3834 #endif // V8_H_ | 3843 #endif // V8_H_ |
OLD | NEW |