| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 class Data; | 133 class Data; |
| 134 template<typename T> class PropertyCallbackInfo; | 134 template<typename T> class PropertyCallbackInfo; |
| 135 class StackTrace; | 135 class StackTrace; |
| 136 class StackFrame; | 136 class StackFrame; |
| 137 class Isolate; | 137 class Isolate; |
| 138 class DeclaredAccessorDescriptor; | 138 class DeclaredAccessorDescriptor; |
| 139 class ObjectOperationDescriptor; | 139 class ObjectOperationDescriptor; |
| 140 class RawOperationDescriptor; | 140 class RawOperationDescriptor; |
| 141 class CallHandlerHelper; | 141 class CallHandlerHelper; |
| 142 class EscapableHandleScope; | 142 class EscapableHandleScope; |
| 143 template<typename T> class ReturnValue; | |
| 144 | 143 |
| 145 namespace internal { | 144 namespace internal { |
| 146 class Arguments; | 145 class Arguments; |
| 147 class Heap; | 146 class Heap; |
| 148 class HeapObject; | 147 class HeapObject; |
| 149 class Isolate; | 148 class Isolate; |
| 150 class Object; | 149 class Object; |
| 151 template<typename T> class CustomArguments; | 150 template<typename T> class CustomArguments; |
| 152 class PropertyCallbackArguments; | 151 class PropertyCallbackArguments; |
| 153 class FunctionCallbackArguments; | 152 class FunctionCallbackArguments; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 template<class F> friend class Handle; | 405 template<class F> friend class Handle; |
| 407 template<class F> friend class Local; | 406 template<class F> friend class Local; |
| 408 template<class F> friend class FunctionCallbackInfo; | 407 template<class F> friend class FunctionCallbackInfo; |
| 409 template<class F> friend class PropertyCallbackInfo; | 408 template<class F> friend class PropertyCallbackInfo; |
| 410 friend class String; | 409 friend class String; |
| 411 friend class Object; | 410 friend class Object; |
| 412 friend class Context; | 411 friend class Context; |
| 413 template<class F> friend class internal::CustomArguments; | 412 template<class F> friend class internal::CustomArguments; |
| 414 friend class HandleScope; | 413 friend class HandleScope; |
| 415 friend class EscapableHandleScope; | 414 friend class EscapableHandleScope; |
| 416 template<class F1, class F2, class F3> friend class PersistentValueMap; | |
| 417 | 415 |
| 418 V8_INLINE static Local<T> New(Isolate* isolate, T* that); | 416 V8_INLINE static Local<T> New(Isolate* isolate, T* that); |
| 419 }; | 417 }; |
| 420 | 418 |
| 421 | 419 |
| 422 // Eternal handles are set-once handles that live for the life of the isolate. | 420 // Eternal handles are set-once handles that live for the life of the isolate. |
| 423 template <class T> class Eternal { | 421 template <class T> class Eternal { |
| 424 public: | 422 public: |
| 425 V8_INLINE Eternal() : index_(kInitialValue) { } | 423 V8_INLINE Eternal() : index_(kInitialValue) { } |
| 426 template<class S> | 424 template<class S> |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 template<typename P> | 520 template<typename P> |
| 523 V8_INLINE void SetWeak( | 521 V8_INLINE void SetWeak( |
| 524 P* parameter, | 522 P* parameter, |
| 525 typename WeakCallbackData<T, P>::Callback callback); | 523 typename WeakCallbackData<T, P>::Callback callback); |
| 526 | 524 |
| 527 template<typename S, typename P> | 525 template<typename S, typename P> |
| 528 V8_INLINE void SetWeak( | 526 V8_INLINE void SetWeak( |
| 529 P* parameter, | 527 P* parameter, |
| 530 typename WeakCallbackData<S, P>::Callback callback); | 528 typename WeakCallbackData<S, P>::Callback callback); |
| 531 | 529 |
| 532 template<typename P> | 530 V8_INLINE void ClearWeak(); |
| 533 V8_INLINE P* ClearWeak(); | |
| 534 | |
| 535 // TODO(dcarney): remove this. | |
| 536 V8_INLINE void ClearWeak() { ClearWeak<void>(); } | |
| 537 | 531 |
| 538 /** | 532 /** |
| 539 * Marks the reference to this object independent. Garbage collector is free | 533 * Marks the reference to this object independent. Garbage collector is free |
| 540 * to ignore any object groups containing this object. Weak callback for an | 534 * to ignore any object groups containing this object. Weak callback for an |
| 541 * independent handle should not assume that it will be preceded by a global | 535 * independent handle should not assume that it will be preceded by a global |
| 542 * GC prologue callback or followed by a global GC epilogue callback. | 536 * GC prologue callback or followed by a global GC epilogue callback. |
| 543 */ | 537 */ |
| 544 V8_INLINE void MarkIndependent(); | 538 V8_INLINE void MarkIndependent(); |
| 545 | 539 |
| 546 /** | 540 /** |
| (...skipping 28 matching lines...) Expand all Loading... |
| 575 | 569 |
| 576 private: | 570 private: |
| 577 friend class Isolate; | 571 friend class Isolate; |
| 578 friend class Utils; | 572 friend class Utils; |
| 579 template<class F> friend class Handle; | 573 template<class F> friend class Handle; |
| 580 template<class F> friend class Local; | 574 template<class F> friend class Local; |
| 581 template<class F1, class F2> friend class Persistent; | 575 template<class F1, class F2> friend class Persistent; |
| 582 template<class F> friend class UniquePersistent; | 576 template<class F> friend class UniquePersistent; |
| 583 template<class F> friend class PersistentBase; | 577 template<class F> friend class PersistentBase; |
| 584 template<class F> friend class ReturnValue; | 578 template<class F> friend class ReturnValue; |
| 585 template<class F1, class F2, class F3> friend class PersistentValueMap; | |
| 586 friend class Object; | 579 friend class Object; |
| 587 | 580 |
| 588 explicit V8_INLINE PersistentBase(T* val) : val_(val) {} | 581 explicit V8_INLINE PersistentBase(T* val) : val_(val) {} |
| 589 PersistentBase(PersistentBase& other); // NOLINT | 582 PersistentBase(PersistentBase& other); // NOLINT |
| 590 void operator=(PersistentBase&); | 583 void operator=(PersistentBase&); |
| 591 V8_INLINE static T* New(Isolate* isolate, T* that); | 584 V8_INLINE static T* New(Isolate* isolate, T* that); |
| 592 | 585 |
| 593 T* val_; | 586 T* val_; |
| 594 }; | 587 }; |
| 595 | 588 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 * Note: Persistent class hierarchy is subject to future changes. | 737 * Note: Persistent class hierarchy is subject to future changes. |
| 745 */ | 738 */ |
| 746 template<class T> | 739 template<class T> |
| 747 class UniquePersistent : public PersistentBase<T> { | 740 class UniquePersistent : public PersistentBase<T> { |
| 748 struct RValue { | 741 struct RValue { |
| 749 V8_INLINE explicit RValue(UniquePersistent* obj) : object(obj) {} | 742 V8_INLINE explicit RValue(UniquePersistent* obj) : object(obj) {} |
| 750 UniquePersistent* object; | 743 UniquePersistent* object; |
| 751 }; | 744 }; |
| 752 | 745 |
| 753 public: | 746 public: |
| 754 /** | 747 /** |
| 755 * A UniquePersistent with no storage cell. | 748 * A UniquePersistent with no storage cell. |
| 756 */ | 749 */ |
| 757 V8_INLINE UniquePersistent() : PersistentBase<T>(0) { } | 750 V8_INLINE UniquePersistent() : PersistentBase<T>(0) { } |
| 758 /** | 751 /** |
| 759 * Construct a UniquePersistent from a Handle. | 752 * Construct a UniquePersistent from a Handle. |
| 760 * When the Handle is non-empty, a new storage cell is created | 753 * When the Handle is non-empty, a new storage cell is created |
| 761 * pointing to the same object, and no flags are set. | 754 * pointing to the same object, and no flags are set. |
| 762 */ | 755 */ |
| 763 template <class S> | 756 template <class S> |
| 764 V8_INLINE UniquePersistent(Isolate* isolate, Handle<S> that) | 757 V8_INLINE UniquePersistent(Isolate* isolate, Handle<S> that) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 782 : PersistentBase<T>(rvalue.object->val_) { | 775 : PersistentBase<T>(rvalue.object->val_) { |
| 783 rvalue.object->val_ = 0; | 776 rvalue.object->val_ = 0; |
| 784 } | 777 } |
| 785 V8_INLINE ~UniquePersistent() { this->Reset(); } | 778 V8_INLINE ~UniquePersistent() { this->Reset(); } |
| 786 /** | 779 /** |
| 787 * Move via assignment. | 780 * Move via assignment. |
| 788 */ | 781 */ |
| 789 template<class S> | 782 template<class S> |
| 790 V8_INLINE UniquePersistent& operator=(UniquePersistent<S> rhs) { | 783 V8_INLINE UniquePersistent& operator=(UniquePersistent<S> rhs) { |
| 791 TYPE_CHECK(T, S); | 784 TYPE_CHECK(T, S); |
| 792 this->Reset(); | |
| 793 this->val_ = rhs.val_; | 785 this->val_ = rhs.val_; |
| 794 rhs.val_ = 0; | 786 rhs.val_ = 0; |
| 795 return *this; | 787 return *this; |
| 796 } | 788 } |
| 797 /** | 789 /** |
| 798 * Cast operator for moves. | 790 * Cast operator for moves. |
| 799 */ | 791 */ |
| 800 V8_INLINE operator RValue() { return RValue(this); } | 792 V8_INLINE operator RValue() { return RValue(this); } |
| 801 /** | 793 /** |
| 802 * Pass allows returning uniques from functions, etc. | 794 * Pass allows returning uniques from functions, etc. |
| 803 */ | 795 */ |
| 804 V8_INLINE UniquePersistent Pass() { return UniquePersistent(RValue(this)); } | 796 V8_INLINE UniquePersistent Pass() { return UniquePersistent(RValue(this)); } |
| 805 | 797 |
| 806 private: | 798 private: |
| 807 UniquePersistent(UniquePersistent&); | 799 UniquePersistent(UniquePersistent&); |
| 808 void operator=(UniquePersistent&); | 800 void operator=(UniquePersistent&); |
| 809 }; | 801 }; |
| 810 | 802 |
| 811 | 803 |
| 812 typedef uintptr_t PersistentContainerValue; | |
| 813 static const uintptr_t kPersistentContainerNotFound = 0; | |
| 814 | |
| 815 /** | |
| 816 * A map wrapper that allows using UniquePersistent as a mapped value. | |
| 817 * C++11 embedders don't need this class, as they can use UniquePersistent | |
| 818 * directly in std containers. | |
| 819 * | |
| 820 * The map relies on a backing map, whose type and accessors are described | |
| 821 * by the Traits class. The backing map will handle values of type | |
| 822 * PersistentContainerValue, with all conversion into and out of V8 | |
| 823 * handles being transparently handled by this class. | |
| 824 */ | |
| 825 template<class K, class V, class Traits> | |
| 826 class PersistentValueMap { | |
| 827 public: | |
| 828 V8_INLINE explicit PersistentValueMap(Isolate* isolate) : isolate_(isolate) {} | |
| 829 | |
| 830 V8_INLINE ~PersistentValueMap() { Clear(); } | |
| 831 | |
| 832 V8_INLINE Isolate* GetIsolate() { return isolate_; } | |
| 833 | |
| 834 /** | |
| 835 * Return size of the map. | |
| 836 */ | |
| 837 V8_INLINE size_t Size() { return Traits::Size(&impl_); } | |
| 838 | |
| 839 /** | |
| 840 * Get value stored in map. | |
| 841 */ | |
| 842 V8_INLINE Local<V> Get(const K& key) { | |
| 843 return Local<V>::New(isolate_, FromVal(Traits::Get(&impl_, key))); | |
| 844 } | |
| 845 | |
| 846 /** | |
| 847 * Check whether a value is contained in the map. | |
| 848 */ | |
| 849 V8_INLINE bool Contains(const K& key) { | |
| 850 return Traits::Get(&impl_, key) != 0; | |
| 851 } | |
| 852 | |
| 853 /** | |
| 854 * Get value stored in map and set it in returnValue. | |
| 855 * Return true if a value was found. | |
| 856 */ | |
| 857 V8_INLINE bool SetReturnValue(const K& key, | |
| 858 ReturnValue<Value>& returnValue); | |
| 859 | |
| 860 /** | |
| 861 * Call Isolate::SetReference with the given parent and the map value. | |
| 862 */ | |
| 863 V8_INLINE void SetReference(const K& key, | |
| 864 const v8::Persistent<v8::Object>& parent) { | |
| 865 GetIsolate()->SetReference( | |
| 866 reinterpret_cast<internal::Object**>(parent.val_), | |
| 867 reinterpret_cast<internal::Object**>(FromVal(Traits::Get(&impl_, key)))); | |
| 868 } | |
| 869 | |
| 870 /** | |
| 871 * Put value into map. Depending on Traits::kIsWeak, the value will be held | |
| 872 * by the map strongly or weakly. | |
| 873 * Returns old value as UniquePersistent. | |
| 874 */ | |
| 875 UniquePersistent<V> Set(const K& key, Local<V> value) { | |
| 876 UniquePersistent<V> persistent(isolate_, value); | |
| 877 return SetUnique(key, &persistent); | |
| 878 } | |
| 879 | |
| 880 /** | |
| 881 * Put value into map, like Set(const K&, Local<V>). | |
| 882 */ | |
| 883 UniquePersistent<V> Set(const K& key, UniquePersistent<V> value) { | |
| 884 return SetUnique(key, &value); | |
| 885 } | |
| 886 | |
| 887 /** | |
| 888 * Return value for key and remove it from the map. | |
| 889 */ | |
| 890 V8_INLINE UniquePersistent<V> Remove(const K& key) { | |
| 891 return Release(Traits::Remove(&impl_, key)).Pass(); | |
| 892 } | |
| 893 | |
| 894 /** | |
| 895 * Traverses the map repeatedly, | |
| 896 * in case side effects of disposal cause insertions. | |
| 897 **/ | |
| 898 void Clear(); | |
| 899 | |
| 900 private: | |
| 901 PersistentValueMap(PersistentValueMap&); | |
| 902 void operator=(PersistentValueMap&); | |
| 903 | |
| 904 /** | |
| 905 * Put the value into the map, and set the 'weak' callback when demanded | |
| 906 * by the Traits class. | |
| 907 */ | |
| 908 UniquePersistent<V> SetUnique(const K& key, UniquePersistent<V>* persistent) { | |
| 909 if (Traits::kIsWeak) { | |
| 910 Local<V> value(Local<V>::New(isolate_, *persistent)); | |
| 911 persistent->template SetWeak<typename Traits::WeakCallbackDataType>( | |
| 912 Traits::WeakCallbackParameter(&impl_, key, value), WeakCallback); | |
| 913 } | |
| 914 PersistentContainerValue old_value = | |
| 915 Traits::Set(&impl_, key, ClearAndLeak(persistent)); | |
| 916 return Release(old_value).Pass(); | |
| 917 } | |
| 918 | |
| 919 static void WeakCallback( | |
| 920 const WeakCallbackData<V, typename Traits::WeakCallbackDataType>& data); | |
| 921 V8_INLINE static V* FromVal(PersistentContainerValue v) { | |
| 922 return reinterpret_cast<V*>(v); | |
| 923 } | |
| 924 V8_INLINE static PersistentContainerValue ClearAndLeak( | |
| 925 UniquePersistent<V>* persistent) { | |
| 926 V* v = persistent->val_; | |
| 927 persistent->val_ = 0; | |
| 928 return reinterpret_cast<PersistentContainerValue>(v); | |
| 929 } | |
| 930 | |
| 931 /** | |
| 932 * Return a container value as UniquePersistent and make sure the weak | |
| 933 * callback is properly disposed of. All remove functionality should go | |
| 934 * through this. | |
| 935 */ | |
| 936 V8_INLINE static UniquePersistent<V> Release(PersistentContainerValue v) { | |
| 937 UniquePersistent<V> p; | |
| 938 p.val_ = FromVal(v); | |
| 939 if (Traits::kIsWeak && !p.IsEmpty()) { | |
| 940 Traits::DisposeCallbackData( | |
| 941 p.template ClearWeak<typename Traits::WeakCallbackDataType>()); | |
| 942 } | |
| 943 return p.Pass(); | |
| 944 } | |
| 945 | |
| 946 Isolate* isolate_; | |
| 947 typename Traits::Impl impl_; | |
| 948 }; | |
| 949 | |
| 950 | |
| 951 /** | 804 /** |
| 952 * A stack-allocated class that governs a number of local handles. | 805 * A stack-allocated class that governs a number of local handles. |
| 953 * After a handle scope has been created, all local handles will be | 806 * After a handle scope has been created, all local handles will be |
| 954 * allocated within that handle scope until either the handle scope is | 807 * allocated within that handle scope until either the handle scope is |
| 955 * deleted or another handle scope is created. If there is already a | 808 * deleted or another handle scope is created. If there is already a |
| 956 * handle scope and a new one is created, all allocations will take | 809 * handle scope and a new one is created, all allocations will take |
| 957 * place in the new handle scope until it is deleted. After that, | 810 * place in the new handle scope until it is deleted. After that, |
| 958 * new handles will again be allocated in the original handle scope. | 811 * new handles will again be allocated in the original handle scope. |
| 959 * | 812 * |
| 960 * After the handle scope of a local handle has been deleted the | 813 * After the handle scope of a local handle has been deleted the |
| (...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2528 V8_INLINE void SetNull(); | 2381 V8_INLINE void SetNull(); |
| 2529 V8_INLINE void SetUndefined(); | 2382 V8_INLINE void SetUndefined(); |
| 2530 V8_INLINE void SetEmptyString(); | 2383 V8_INLINE void SetEmptyString(); |
| 2531 // Convenience getter for Isolate | 2384 // Convenience getter for Isolate |
| 2532 V8_INLINE Isolate* GetIsolate(); | 2385 V8_INLINE Isolate* GetIsolate(); |
| 2533 | 2386 |
| 2534 private: | 2387 private: |
| 2535 template<class F> friend class ReturnValue; | 2388 template<class F> friend class ReturnValue; |
| 2536 template<class F> friend class FunctionCallbackInfo; | 2389 template<class F> friend class FunctionCallbackInfo; |
| 2537 template<class F> friend class PropertyCallbackInfo; | 2390 template<class F> friend class PropertyCallbackInfo; |
| 2538 template<class F, class G, class H> friend class PersistentValueMap; | |
| 2539 V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; } | |
| 2540 V8_INLINE internal::Object* GetDefaultValue(); | 2391 V8_INLINE internal::Object* GetDefaultValue(); |
| 2541 V8_INLINE explicit ReturnValue(internal::Object** slot); | 2392 V8_INLINE explicit ReturnValue(internal::Object** slot); |
| 2542 internal::Object** value_; | 2393 internal::Object** value_; |
| 2543 }; | 2394 }; |
| 2544 | 2395 |
| 2545 | 2396 |
| 2546 /** | 2397 /** |
| 2547 * The argument information given to function call callbacks. This | 2398 * The argument information given to function call callbacks. This |
| 2548 * class provides access to information about the context of the call, | 2399 * class provides access to information about the context of the call, |
| 2549 * including the receiver, the number and values of arguments, and | 2400 * including the receiver, the number and values of arguments, and |
| (...skipping 1827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4377 * instead to influence the garbage collection schedule. | 4228 * instead to influence the garbage collection schedule. |
| 4378 */ | 4229 */ |
| 4379 void RequestGarbageCollectionForTesting(GarbageCollectionType type); | 4230 void RequestGarbageCollectionForTesting(GarbageCollectionType type); |
| 4380 | 4231 |
| 4381 /** | 4232 /** |
| 4382 * Set the callback to invoke for logging event. | 4233 * Set the callback to invoke for logging event. |
| 4383 */ | 4234 */ |
| 4384 void SetEventLogger(LogEventCallback that); | 4235 void SetEventLogger(LogEventCallback that); |
| 4385 | 4236 |
| 4386 private: | 4237 private: |
| 4387 template<class K, class V, class Traits> friend class PersistentValueMap; | |
| 4388 | |
| 4389 Isolate(); | 4238 Isolate(); |
| 4390 Isolate(const Isolate&); | 4239 Isolate(const Isolate&); |
| 4391 ~Isolate(); | 4240 ~Isolate(); |
| 4392 Isolate& operator=(const Isolate&); | 4241 Isolate& operator=(const Isolate&); |
| 4393 void* operator new(size_t size); | 4242 void* operator new(size_t size); |
| 4394 void operator delete(void*, size_t); | 4243 void operator delete(void*, size_t); |
| 4395 | 4244 |
| 4396 void SetObjectGroupId(internal::Object** object, UniqueId id); | 4245 void SetObjectGroupId(internal::Object** object, UniqueId id); |
| 4397 void SetReferenceFromGroup(UniqueId id, internal::Object** object); | 4246 void SetReferenceFromGroup(UniqueId id, internal::Object** object); |
| 4398 void SetReference(internal::Object** parent, internal::Object** child); | 4247 void SetReference(internal::Object** parent, internal::Object** child); |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4973 V8(); | 4822 V8(); |
| 4974 | 4823 |
| 4975 static internal::Object** GlobalizeReference(internal::Isolate* isolate, | 4824 static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| 4976 internal::Object** handle); | 4825 internal::Object** handle); |
| 4977 static internal::Object** CopyPersistent(internal::Object** handle); | 4826 static internal::Object** CopyPersistent(internal::Object** handle); |
| 4978 static void DisposeGlobal(internal::Object** global_handle); | 4827 static void DisposeGlobal(internal::Object** global_handle); |
| 4979 typedef WeakCallbackData<Value, void>::Callback WeakCallback; | 4828 typedef WeakCallbackData<Value, void>::Callback WeakCallback; |
| 4980 static void MakeWeak(internal::Object** global_handle, | 4829 static void MakeWeak(internal::Object** global_handle, |
| 4981 void* data, | 4830 void* data, |
| 4982 WeakCallback weak_callback); | 4831 WeakCallback weak_callback); |
| 4983 static void* ClearWeak(internal::Object** global_handle); | 4832 static void ClearWeak(internal::Object** global_handle); |
| 4984 static void Eternalize(Isolate* isolate, | 4833 static void Eternalize(Isolate* isolate, |
| 4985 Value* handle, | 4834 Value* handle, |
| 4986 int* index); | 4835 int* index); |
| 4987 static Local<Value> GetEternal(Isolate* isolate, int index); | 4836 static Local<Value> GetEternal(Isolate* isolate, int index); |
| 4988 | 4837 |
| 4989 template <class T> friend class Handle; | 4838 template <class T> friend class Handle; |
| 4990 template <class T> friend class Local; | 4839 template <class T> friend class Local; |
| 4991 template <class T> friend class Eternal; | 4840 template <class T> friend class Eternal; |
| 4992 template <class T> friend class PersistentBase; | 4841 template <class T> friend class PersistentBase; |
| 4993 template <class T, class M> friend class Persistent; | 4842 template <class T, class M> friend class Persistent; |
| (...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5886 template <class T> | 5735 template <class T> |
| 5887 template <typename P> | 5736 template <typename P> |
| 5888 void PersistentBase<T>::SetWeak( | 5737 void PersistentBase<T>::SetWeak( |
| 5889 P* parameter, | 5738 P* parameter, |
| 5890 typename WeakCallbackData<T, P>::Callback callback) { | 5739 typename WeakCallbackData<T, P>::Callback callback) { |
| 5891 SetWeak<T, P>(parameter, callback); | 5740 SetWeak<T, P>(parameter, callback); |
| 5892 } | 5741 } |
| 5893 | 5742 |
| 5894 | 5743 |
| 5895 template <class T> | 5744 template <class T> |
| 5896 template<typename P> | 5745 void PersistentBase<T>::ClearWeak() { |
| 5897 P* PersistentBase<T>::ClearWeak() { | 5746 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); |
| 5898 return reinterpret_cast<P*>( | |
| 5899 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_))); | |
| 5900 } | 5747 } |
| 5901 | 5748 |
| 5902 | 5749 |
| 5903 template <class T> | 5750 template <class T> |
| 5904 void PersistentBase<T>::MarkIndependent() { | 5751 void PersistentBase<T>::MarkIndependent() { |
| 5905 typedef internal::Internals I; | 5752 typedef internal::Internals I; |
| 5906 if (this->IsEmpty()) return; | 5753 if (this->IsEmpty()) return; |
| 5907 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | 5754 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| 5908 true, | 5755 true, |
| 5909 I::kNodeIsIndependentShift); | 5756 I::kNodeIsIndependentShift); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5942 template <class T> | 5789 template <class T> |
| 5943 uint16_t PersistentBase<T>::WrapperClassId() const { | 5790 uint16_t PersistentBase<T>::WrapperClassId() const { |
| 5944 typedef internal::Internals I; | 5791 typedef internal::Internals I; |
| 5945 if (this->IsEmpty()) return 0; | 5792 if (this->IsEmpty()) return 0; |
| 5946 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); | 5793 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
| 5947 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | 5794 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5948 return *reinterpret_cast<uint16_t*>(addr); | 5795 return *reinterpret_cast<uint16_t*>(addr); |
| 5949 } | 5796 } |
| 5950 | 5797 |
| 5951 | 5798 |
| 5952 template <class K, class V, class Traits> | |
| 5953 bool PersistentValueMap<K, V, Traits>::SetReturnValue(const K& key, | |
| 5954 ReturnValue<Value>& returnValue) { | |
| 5955 PersistentContainerValue value = Traits::Get(&impl_, key); | |
| 5956 bool hasValue = value != 0; | |
| 5957 if (hasValue) { | |
| 5958 returnValue.SetInternal( | |
| 5959 *reinterpret_cast<internal::Object**>(FromVal(value))); | |
| 5960 } | |
| 5961 return hasValue; | |
| 5962 } | |
| 5963 | |
| 5964 template <class K, class V, class Traits> | |
| 5965 void PersistentValueMap<K, V, Traits>::Clear() { | |
| 5966 typedef typename Traits::Iterator It; | |
| 5967 HandleScope handle_scope(isolate_); | |
| 5968 // TODO(dcarney): figure out if this swap and loop is necessary. | |
| 5969 while (!Traits::Empty(&impl_)) { | |
| 5970 typename Traits::Impl impl; | |
| 5971 Traits::Swap(impl_, impl); | |
| 5972 for (It i = Traits::Begin(&impl); i != Traits::End(&impl); ++i) { | |
| 5973 Traits::Dispose(isolate_, Release(Traits::Value(i)).Pass(), &impl, | |
| 5974 Traits::Key(i)); | |
| 5975 } | |
| 5976 } | |
| 5977 } | |
| 5978 | |
| 5979 | |
| 5980 template <class K, class V, class Traits> | |
| 5981 void PersistentValueMap<K, V, Traits>::WeakCallback( | |
| 5982 const WeakCallbackData<V, typename Traits::WeakCallbackDataType>& data) { | |
| 5983 typename Traits::Impl* impl = Traits::ImplFromWeakCallbackData(data); | |
| 5984 K key = Traits::KeyFromWeakCallbackData(data); | |
| 5985 PersistentContainerValue value = Traits::Remove(impl, key); | |
| 5986 Traits::Dispose(data.GetIsolate(), Release(value).Pass(), impl, key); | |
| 5987 } | |
| 5988 | |
| 5989 | |
| 5990 template<typename T> | 5799 template<typename T> |
| 5991 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} | 5800 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} |
| 5992 | 5801 |
| 5993 template<typename T> | 5802 template<typename T> |
| 5994 template<typename S> | 5803 template<typename S> |
| 5995 void ReturnValue<T>::Set(const Persistent<S>& handle) { | 5804 void ReturnValue<T>::Set(const Persistent<S>& handle) { |
| 5996 TYPE_CHECK(T, S); | 5805 TYPE_CHECK(T, S); |
| 5997 if (V8_UNLIKELY(handle.IsEmpty())) { | 5806 if (V8_UNLIKELY(handle.IsEmpty())) { |
| 5998 *value_ = GetDefaultValue(); | 5807 *value_ = GetDefaultValue(); |
| 5999 } else { | 5808 } else { |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6697 */ | 6506 */ |
| 6698 | 6507 |
| 6699 | 6508 |
| 6700 } // namespace v8 | 6509 } // namespace v8 |
| 6701 | 6510 |
| 6702 | 6511 |
| 6703 #undef TYPE_CHECK | 6512 #undef TYPE_CHECK |
| 6704 | 6513 |
| 6705 | 6514 |
| 6706 #endif // V8_H_ | 6515 #endif // V8_H_ |
| OLD | NEW |