Chromium Code Reviews| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 class Data; | 103 class Data; |
| 104 class AccessorInfo; | 104 class AccessorInfo; |
| 105 class StackTrace; | 105 class StackTrace; |
| 106 class StackFrame; | 106 class StackFrame; |
| 107 | 107 |
| 108 namespace internal { | 108 namespace internal { |
| 109 | 109 |
| 110 class Arguments; | 110 class Arguments; |
| 111 class Object; | 111 class Object; |
| 112 class Heap; | 112 class Heap; |
| 113 class HeapObject; | |
| 113 class Isolate; | 114 class Isolate; |
| 114 } | 115 } |
| 115 | 116 |
| 116 | 117 |
| 117 // --- W e a k H a n d l e s | 118 // --- W e a k H a n d l e s |
| 118 | 119 |
| 119 | 120 |
| 120 /** | 121 /** |
| 121 * A weak reference callback function. | 122 * A weak reference callback function. |
| 122 * | 123 * |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 | 431 |
| 431 /** | 432 /** |
| 432 * Counts the number of allocated handles. | 433 * Counts the number of allocated handles. |
| 433 */ | 434 */ |
| 434 static int NumberOfHandles(); | 435 static int NumberOfHandles(); |
| 435 | 436 |
| 436 /** | 437 /** |
| 437 * Creates a new handle with the given value. | 438 * Creates a new handle with the given value. |
| 438 */ | 439 */ |
| 439 static internal::Object** CreateHandle(internal::Object* value); | 440 static internal::Object** CreateHandle(internal::Object* value); |
| 441 // Faster version, uses HeapObject to obtain the current Isolate. | |
| 442 static internal::Object** CreateHandle(internal::HeapObject* value); | |
| 440 | 443 |
| 441 private: | 444 private: |
| 442 // Make it impossible to create heap-allocated or illegal handle | 445 // Make it impossible to create heap-allocated or illegal handle |
| 443 // scopes by disallowing certain operations. | 446 // scopes by disallowing certain operations. |
| 444 HandleScope(const HandleScope&); | 447 HandleScope(const HandleScope&); |
| 445 void operator=(const HandleScope&); | 448 void operator=(const HandleScope&); |
| 446 void* operator new(size_t size); | 449 void* operator new(size_t size); |
| 447 void operator delete(void*, size_t); | 450 void operator delete(void*, size_t); |
| 448 | 451 |
| 449 // This Data class is accessible internally as HandleScopeData through a | 452 // 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) { | 3479 static inline bool IsExternalTwoByteString(int instance_type) { |
| 3477 int representation = (instance_type & kFullStringRepresentationMask); | 3480 int representation = (instance_type & kFullStringRepresentationMask); |
| 3478 return representation == kExternalTwoByteRepresentationTag; | 3481 return representation == kExternalTwoByteRepresentationTag; |
| 3479 } | 3482 } |
| 3480 | 3483 |
| 3481 template <typename T> | 3484 template <typename T> |
| 3482 static inline T ReadField(Object* ptr, int offset) { | 3485 static inline T ReadField(Object* ptr, int offset) { |
| 3483 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; | 3486 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
| 3484 return *reinterpret_cast<T*>(addr); | 3487 return *reinterpret_cast<T*>(addr); |
| 3485 } | 3488 } |
| 3489 | |
| 3490 static inline bool CanCastToHeapObject(void*) { return false; } | |
| 3491 static inline bool CanCastToHeapObject(Context*) { return true; } | |
| 3492 static inline bool CanCastToHeapObject(String*) { return true; } | |
| 3493 static inline bool CanCastToHeapObject(Object*) { return true; } | |
| 3494 static inline bool CanCastToHeapObject(Message*) { return true; } | |
| 3495 static inline bool CanCastToHeapObject(StackTrace*) { return true; } | |
| 3496 static inline bool CanCastToHeapObject(StackFrame*) { return true; } | |
| 3497 | |
| 3486 }; | 3498 }; |
| 3487 | 3499 |
| 3488 } // namespace internal | 3500 } // namespace internal |
| 3489 | 3501 |
| 3490 | 3502 |
| 3491 template <class T> | 3503 template <class T> |
| 3492 Handle<T>::Handle() : val_(0) { } | 3504 Handle<T>::Handle() : val_(0) { } |
| 3493 | 3505 |
| 3494 | 3506 |
| 3495 template <class T> | 3507 template <class T> |
| 3496 Local<T>::Local() : Handle<T>() { } | 3508 Local<T>::Local() : Handle<T>() { } |
| 3497 | 3509 |
| 3498 | 3510 |
| 3499 template <class T> | 3511 template <class T> |
| 3500 Local<T> Local<T>::New(Handle<T> that) { | 3512 Local<T> Local<T>::New(Handle<T> that) { |
| 3501 if (that.IsEmpty()) return Local<T>(); | 3513 if (that.IsEmpty()) return Local<T>(); |
| 3502 internal::Object** p = reinterpret_cast<internal::Object**>(*that); | 3514 T* that_ptr = *that; |
|
Vitaly Repeshko
2010/12/07 13:35:13
Weird indentation.
| |
| 3515 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | |
| 3516 if (internal::Internals::CanCastToHeapObject(that_ptr)) { | |
| 3517 return Local<T>(reinterpret_cast<T*>( | |
| 3518 HandleScope::CreateHandle(reinterpret_cast<internal::HeapObject*>(*p)))); | |
| 3519 } | |
| 3503 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); | 3520 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 3504 } | 3521 } |
| 3505 | 3522 |
| 3506 | 3523 |
| 3507 template <class T> | 3524 template <class T> |
| 3508 Persistent<T> Persistent<T>::New(Handle<T> that) { | 3525 Persistent<T> Persistent<T>::New(Handle<T> that) { |
| 3509 if (that.IsEmpty()) return Persistent<T>(); | 3526 if (that.IsEmpty()) return Persistent<T>(); |
| 3510 internal::Object** p = reinterpret_cast<internal::Object**>(*that); | 3527 internal::Object** p = reinterpret_cast<internal::Object**>(*that); |
| 3511 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); | 3528 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); |
| 3512 } | 3529 } |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3825 | 3842 |
| 3826 | 3843 |
| 3827 } // namespace v8 | 3844 } // namespace v8 |
| 3828 | 3845 |
| 3829 | 3846 |
| 3830 #undef V8EXPORT | 3847 #undef V8EXPORT |
| 3831 #undef TYPE_CHECK | 3848 #undef TYPE_CHECK |
| 3832 | 3849 |
| 3833 | 3850 |
| 3834 #endif // V8_H_ | 3851 #endif // V8_H_ |
| OLD | NEW |