OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 370 |
371 template <class S> V8_INLINE Local<S> As() { | 371 template <class S> V8_INLINE Local<S> As() { |
372 return Local<S>::Cast(*this); | 372 return Local<S>::Cast(*this); |
373 } | 373 } |
374 | 374 |
375 /** | 375 /** |
376 * Create a local handle for the content of another handle. | 376 * Create a local handle for the content of another handle. |
377 * The referee is kept alive by the local handle even when | 377 * The referee is kept alive by the local handle even when |
378 * the original handle is destroyed/disposed. | 378 * the original handle is destroyed/disposed. |
379 */ | 379 */ |
380 V8_INLINE static Local<T> New(Handle<T> that); | |
381 V8_INLINE static Local<T> New(Isolate* isolate, Handle<T> that); | 380 V8_INLINE static Local<T> New(Isolate* isolate, Handle<T> that); |
382 template<class M> | 381 template<class M> |
383 V8_INLINE static Local<T> New(Isolate* isolate, | 382 V8_INLINE static Local<T> New(Isolate* isolate, |
384 const Persistent<T, M>& that); | 383 const Persistent<T, M>& that); |
385 | 384 |
386 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | 385 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
387 | 386 |
388 private: | 387 private: |
389 #endif | 388 #endif |
390 template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { } | 389 template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { } |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 * Closes the handle scope and returns the value as a handle in the | 776 * Closes the handle scope and returns the value as a handle in the |
778 * previous scope, which is the new current scope after the call. | 777 * previous scope, which is the new current scope after the call. |
779 */ | 778 */ |
780 template <class T> Local<T> Close(Handle<T> value); | 779 template <class T> Local<T> Close(Handle<T> value); |
781 | 780 |
782 /** | 781 /** |
783 * Counts the number of allocated handles. | 782 * Counts the number of allocated handles. |
784 */ | 783 */ |
785 static int NumberOfHandles(); | 784 static int NumberOfHandles(); |
786 | 785 |
| 786 private: |
787 /** | 787 /** |
788 * Creates a new handle with the given value. | 788 * Creates a new handle with the given value. |
789 */ | 789 */ |
790 static internal::Object** CreateHandle(internal::Object* value); | |
791 static internal::Object** CreateHandle(internal::Isolate* isolate, | 790 static internal::Object** CreateHandle(internal::Isolate* isolate, |
792 internal::Object* value); | 791 internal::Object* value); |
793 // Faster version, uses HeapObject to obtain the current Isolate. | 792 // Uses HeapObject to obtain the current Isolate. |
794 static internal::Object** CreateHandle(internal::HeapObject* value); | 793 static internal::Object** CreateHandle(internal::HeapObject* heap_object, |
| 794 internal::Object* value); |
795 | 795 |
796 private: | |
797 // Make it hard to create heap-allocated or illegal handle scopes by | 796 // Make it hard to create heap-allocated or illegal handle scopes by |
798 // disallowing certain operations. | 797 // disallowing certain operations. |
799 HandleScope(const HandleScope&); | 798 HandleScope(const HandleScope&); |
800 void operator=(const HandleScope&); | 799 void operator=(const HandleScope&); |
801 void* operator new(size_t size); | 800 void* operator new(size_t size); |
802 void operator delete(void*, size_t); | 801 void operator delete(void*, size_t); |
803 | 802 |
804 // This Data class is accessible internally as HandleScopeData through a | 803 // This Data class is accessible internally as HandleScopeData through a |
805 // typedef in the ImplementationUtilities class. | 804 // typedef in the ImplementationUtilities class. |
806 class V8_EXPORT Data { | 805 class V8_EXPORT Data { |
(...skipping 13 matching lines...) Expand all Loading... |
820 internal::Isolate* isolate_; | 819 internal::Isolate* isolate_; |
821 internal::Object** prev_next_; | 820 internal::Object** prev_next_; |
822 internal::Object** prev_limit_; | 821 internal::Object** prev_limit_; |
823 | 822 |
824 // Allow for the active closing of HandleScopes which allows to pass a handle | 823 // Allow for the active closing of HandleScopes which allows to pass a handle |
825 // from the HandleScope being closed to the next top most HandleScope. | 824 // from the HandleScope being closed to the next top most HandleScope. |
826 bool is_closed_; | 825 bool is_closed_; |
827 internal::Object** RawClose(internal::Object** value); | 826 internal::Object** RawClose(internal::Object** value); |
828 | 827 |
829 friend class ImplementationUtilities; | 828 friend class ImplementationUtilities; |
| 829 template<class F> friend class Handle; |
| 830 template<class F> friend class Local; |
| 831 friend class Object; |
| 832 friend class Context; |
830 }; | 833 }; |
831 | 834 |
832 | 835 |
833 /** | 836 /** |
834 * A simple Maybe type, representing an object which may or may not have a | 837 * A simple Maybe type, representing an object which may or may not have a |
835 * value. | 838 * value. |
836 */ | 839 */ |
837 template<class T> | 840 template<class T> |
838 struct V8_EXPORT Maybe { | 841 struct V8_EXPORT Maybe { |
839 Maybe() : has_value(false) {} | 842 Maybe() : has_value(false) {} |
(...skipping 4697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5537 }; | 5540 }; |
5538 | 5541 |
5539 } // namespace internal | 5542 } // namespace internal |
5540 | 5543 |
5541 | 5544 |
5542 template <class T> | 5545 template <class T> |
5543 Local<T>::Local() : Handle<T>() { } | 5546 Local<T>::Local() : Handle<T>() { } |
5544 | 5547 |
5545 | 5548 |
5546 template <class T> | 5549 template <class T> |
5547 Local<T> Local<T>::New(Handle<T> that) { | |
5548 if (that.IsEmpty()) return Local<T>(); | |
5549 T* that_ptr = *that; | |
5550 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | |
5551 if (internal::Internals::CanCastToHeapObject(that_ptr)) { | |
5552 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | |
5553 reinterpret_cast<internal::HeapObject*>(*p)))); | |
5554 } | |
5555 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); | |
5556 } | |
5557 | |
5558 | |
5559 template <class T> | |
5560 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { | 5550 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
5561 return New(isolate, that.val_); | 5551 return New(isolate, that.val_); |
5562 } | 5552 } |
5563 | 5553 |
5564 template <class T> | 5554 template <class T> |
5565 template <class M> | 5555 template <class M> |
5566 Local<T> Local<T>::New(Isolate* isolate, const Persistent<T, M>& that) { | 5556 Local<T> Local<T>::New(Isolate* isolate, const Persistent<T, M>& that) { |
5567 return New(isolate, that.val_); | 5557 return New(isolate, that.val_); |
5568 } | 5558 } |
5569 | 5559 |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5985 | 5975 |
5986 | 5976 |
5987 void Template::Set(const char* name, v8::Handle<Data> value) { | 5977 void Template::Set(const char* name, v8::Handle<Data> value) { |
5988 Set(v8::String::New(name), value); | 5978 Set(v8::String::New(name), value); |
5989 } | 5979 } |
5990 | 5980 |
5991 | 5981 |
5992 Local<Value> Object::GetInternalField(int index) { | 5982 Local<Value> Object::GetInternalField(int index) { |
5993 #ifndef V8_ENABLE_CHECKS | 5983 #ifndef V8_ENABLE_CHECKS |
5994 typedef internal::Object O; | 5984 typedef internal::Object O; |
| 5985 typedef internal::HeapObject HO; |
5995 typedef internal::Internals I; | 5986 typedef internal::Internals I; |
5996 O* obj = *reinterpret_cast<O**>(this); | 5987 O* obj = *reinterpret_cast<O**>(this); |
5997 // Fast path: If the object is a plain JSObject, which is the common case, we | 5988 // Fast path: If the object is a plain JSObject, which is the common case, we |
5998 // know where to find the internal fields and can return the value directly. | 5989 // know where to find the internal fields and can return the value directly. |
5999 if (I::GetInstanceType(obj) == I::kJSObjectType) { | 5990 if (I::GetInstanceType(obj) == I::kJSObjectType) { |
6000 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); | 5991 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
6001 O* value = I::ReadField<O*>(obj, offset); | 5992 O* value = I::ReadField<O*>(obj, offset); |
6002 O** result = HandleScope::CreateHandle(value); | 5993 O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value); |
6003 return Local<Value>(reinterpret_cast<Value*>(result)); | 5994 return Local<Value>(reinterpret_cast<Value*>(result)); |
6004 } | 5995 } |
6005 #endif | 5996 #endif |
6006 return SlowGetInternalField(index); | 5997 return SlowGetInternalField(index); |
6007 } | 5998 } |
6008 | 5999 |
6009 | 6000 |
6010 void* Object::GetAlignedPointerFromInternalField(int index) { | 6001 void* Object::GetAlignedPointerFromInternalField(int index) { |
6011 #ifndef V8_ENABLE_CHECKS | 6002 #ifndef V8_ENABLE_CHECKS |
6012 typedef internal::Object O; | 6003 typedef internal::Object O; |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6444 | 6435 |
6445 void* Isolate::GetData() { | 6436 void* Isolate::GetData() { |
6446 typedef internal::Internals I; | 6437 typedef internal::Internals I; |
6447 return I::GetEmbedderData(this); | 6438 return I::GetEmbedderData(this); |
6448 } | 6439 } |
6449 | 6440 |
6450 | 6441 |
6451 Local<Value> Context::GetEmbedderData(int index) { | 6442 Local<Value> Context::GetEmbedderData(int index) { |
6452 #ifndef V8_ENABLE_CHECKS | 6443 #ifndef V8_ENABLE_CHECKS |
6453 typedef internal::Object O; | 6444 typedef internal::Object O; |
| 6445 typedef internal::HeapObject HO; |
6454 typedef internal::Internals I; | 6446 typedef internal::Internals I; |
6455 O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index)); | 6447 HO* context = *reinterpret_cast<HO**>(this); |
| 6448 O** result = |
| 6449 HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index)); |
6456 return Local<Value>(reinterpret_cast<Value*>(result)); | 6450 return Local<Value>(reinterpret_cast<Value*>(result)); |
6457 #else | 6451 #else |
6458 return SlowGetEmbedderData(index); | 6452 return SlowGetEmbedderData(index); |
6459 #endif | 6453 #endif |
6460 } | 6454 } |
6461 | 6455 |
6462 | 6456 |
6463 void* Context::GetAlignedPointerFromEmbedderData(int index) { | 6457 void* Context::GetAlignedPointerFromEmbedderData(int index) { |
6464 #ifndef V8_ENABLE_CHECKS | 6458 #ifndef V8_ENABLE_CHECKS |
6465 typedef internal::Internals I; | 6459 typedef internal::Internals I; |
(...skipping 16 matching lines...) Expand all Loading... |
6482 */ | 6476 */ |
6483 | 6477 |
6484 | 6478 |
6485 } // namespace v8 | 6479 } // namespace v8 |
6486 | 6480 |
6487 | 6481 |
6488 #undef TYPE_CHECK | 6482 #undef TYPE_CHECK |
6489 | 6483 |
6490 | 6484 |
6491 #endif // V8_H_ | 6485 #endif // V8_H_ |
OLD | NEW |