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; |
143 | 144 |
144 namespace internal { | 145 namespace internal { |
145 class Arguments; | 146 class Arguments; |
146 class Heap; | 147 class Heap; |
147 class HeapObject; | 148 class HeapObject; |
148 class Isolate; | 149 class Isolate; |
149 class Object; | 150 class Object; |
150 template<typename T> class CustomArguments; | 151 template<typename T> class CustomArguments; |
151 class PropertyCallbackArguments; | 152 class PropertyCallbackArguments; |
152 class FunctionCallbackArguments; | 153 class FunctionCallbackArguments; |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 template<class F> friend class Handle; | 406 template<class F> friend class Handle; |
406 template<class F> friend class Local; | 407 template<class F> friend class Local; |
407 template<class F> friend class FunctionCallbackInfo; | 408 template<class F> friend class FunctionCallbackInfo; |
408 template<class F> friend class PropertyCallbackInfo; | 409 template<class F> friend class PropertyCallbackInfo; |
409 friend class String; | 410 friend class String; |
410 friend class Object; | 411 friend class Object; |
411 friend class Context; | 412 friend class Context; |
412 template<class F> friend class internal::CustomArguments; | 413 template<class F> friend class internal::CustomArguments; |
413 friend class HandleScope; | 414 friend class HandleScope; |
414 friend class EscapableHandleScope; | 415 friend class EscapableHandleScope; |
| 416 template<class F1, class F2, class F3> friend class PersistentValueMap; |
415 | 417 |
416 V8_INLINE static Local<T> New(Isolate* isolate, T* that); | 418 V8_INLINE static Local<T> New(Isolate* isolate, T* that); |
417 }; | 419 }; |
418 | 420 |
419 | 421 |
420 // Eternal handles are set-once handles that live for the life of the isolate. | 422 // Eternal handles are set-once handles that live for the life of the isolate. |
421 template <class T> class Eternal { | 423 template <class T> class Eternal { |
422 public: | 424 public: |
423 V8_INLINE Eternal() : index_(kInitialValue) { } | 425 V8_INLINE Eternal() : index_(kInitialValue) { } |
424 template<class S> | 426 template<class S> |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 template<typename P> | 522 template<typename P> |
521 V8_INLINE void SetWeak( | 523 V8_INLINE void SetWeak( |
522 P* parameter, | 524 P* parameter, |
523 typename WeakCallbackData<T, P>::Callback callback); | 525 typename WeakCallbackData<T, P>::Callback callback); |
524 | 526 |
525 template<typename S, typename P> | 527 template<typename S, typename P> |
526 V8_INLINE void SetWeak( | 528 V8_INLINE void SetWeak( |
527 P* parameter, | 529 P* parameter, |
528 typename WeakCallbackData<S, P>::Callback callback); | 530 typename WeakCallbackData<S, P>::Callback callback); |
529 | 531 |
530 V8_INLINE void ClearWeak(); | 532 template<typename P> |
| 533 V8_INLINE P* ClearWeak(); |
| 534 |
| 535 // TODO(dcarney): remove this. |
| 536 V8_INLINE void ClearWeak() { ClearWeak<void>(); } |
531 | 537 |
532 /** | 538 /** |
533 * Marks the reference to this object independent. Garbage collector is free | 539 * Marks the reference to this object independent. Garbage collector is free |
534 * to ignore any object groups containing this object. Weak callback for an | 540 * to ignore any object groups containing this object. Weak callback for an |
535 * independent handle should not assume that it will be preceded by a global | 541 * independent handle should not assume that it will be preceded by a global |
536 * GC prologue callback or followed by a global GC epilogue callback. | 542 * GC prologue callback or followed by a global GC epilogue callback. |
537 */ | 543 */ |
538 V8_INLINE void MarkIndependent(); | 544 V8_INLINE void MarkIndependent(); |
539 | 545 |
540 /** | 546 /** |
(...skipping 28 matching lines...) Expand all Loading... |
569 | 575 |
570 private: | 576 private: |
571 friend class Isolate; | 577 friend class Isolate; |
572 friend class Utils; | 578 friend class Utils; |
573 template<class F> friend class Handle; | 579 template<class F> friend class Handle; |
574 template<class F> friend class Local; | 580 template<class F> friend class Local; |
575 template<class F1, class F2> friend class Persistent; | 581 template<class F1, class F2> friend class Persistent; |
576 template<class F> friend class UniquePersistent; | 582 template<class F> friend class UniquePersistent; |
577 template<class F> friend class PersistentBase; | 583 template<class F> friend class PersistentBase; |
578 template<class F> friend class ReturnValue; | 584 template<class F> friend class ReturnValue; |
| 585 template<class F1, class F2, class F3> friend class PersistentValueMap; |
579 friend class Object; | 586 friend class Object; |
580 | 587 |
581 explicit V8_INLINE PersistentBase(T* val) : val_(val) {} | 588 explicit V8_INLINE PersistentBase(T* val) : val_(val) {} |
582 PersistentBase(PersistentBase& other); // NOLINT | 589 PersistentBase(PersistentBase& other); // NOLINT |
583 void operator=(PersistentBase&); | 590 void operator=(PersistentBase&); |
584 V8_INLINE static T* New(Isolate* isolate, T* that); | 591 V8_INLINE static T* New(Isolate* isolate, T* that); |
585 | 592 |
586 T* val_; | 593 T* val_; |
587 }; | 594 }; |
588 | 595 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 * Note: Persistent class hierarchy is subject to future changes. | 744 * Note: Persistent class hierarchy is subject to future changes. |
738 */ | 745 */ |
739 template<class T> | 746 template<class T> |
740 class UniquePersistent : public PersistentBase<T> { | 747 class UniquePersistent : public PersistentBase<T> { |
741 struct RValue { | 748 struct RValue { |
742 V8_INLINE explicit RValue(UniquePersistent* obj) : object(obj) {} | 749 V8_INLINE explicit RValue(UniquePersistent* obj) : object(obj) {} |
743 UniquePersistent* object; | 750 UniquePersistent* object; |
744 }; | 751 }; |
745 | 752 |
746 public: | 753 public: |
747 /** | 754 /** |
748 * A UniquePersistent with no storage cell. | 755 * A UniquePersistent with no storage cell. |
749 */ | 756 */ |
750 V8_INLINE UniquePersistent() : PersistentBase<T>(0) { } | 757 V8_INLINE UniquePersistent() : PersistentBase<T>(0) { } |
751 /** | 758 /** |
752 * Construct a UniquePersistent from a Handle. | 759 * Construct a UniquePersistent from a Handle. |
753 * When the Handle is non-empty, a new storage cell is created | 760 * When the Handle is non-empty, a new storage cell is created |
754 * pointing to the same object, and no flags are set. | 761 * pointing to the same object, and no flags are set. |
755 */ | 762 */ |
756 template <class S> | 763 template <class S> |
757 V8_INLINE UniquePersistent(Isolate* isolate, Handle<S> that) | 764 V8_INLINE UniquePersistent(Isolate* isolate, Handle<S> that) |
(...skipping 17 matching lines...) Expand all Loading... |
775 : PersistentBase<T>(rvalue.object->val_) { | 782 : PersistentBase<T>(rvalue.object->val_) { |
776 rvalue.object->val_ = 0; | 783 rvalue.object->val_ = 0; |
777 } | 784 } |
778 V8_INLINE ~UniquePersistent() { this->Reset(); } | 785 V8_INLINE ~UniquePersistent() { this->Reset(); } |
779 /** | 786 /** |
780 * Move via assignment. | 787 * Move via assignment. |
781 */ | 788 */ |
782 template<class S> | 789 template<class S> |
783 V8_INLINE UniquePersistent& operator=(UniquePersistent<S> rhs) { | 790 V8_INLINE UniquePersistent& operator=(UniquePersistent<S> rhs) { |
784 TYPE_CHECK(T, S); | 791 TYPE_CHECK(T, S); |
| 792 this->Reset(); |
785 this->val_ = rhs.val_; | 793 this->val_ = rhs.val_; |
786 rhs.val_ = 0; | 794 rhs.val_ = 0; |
787 return *this; | 795 return *this; |
788 } | 796 } |
789 /** | 797 /** |
790 * Cast operator for moves. | 798 * Cast operator for moves. |
791 */ | 799 */ |
792 V8_INLINE operator RValue() { return RValue(this); } | 800 V8_INLINE operator RValue() { return RValue(this); } |
793 /** | 801 /** |
794 * Pass allows returning uniques from functions, etc. | 802 * Pass allows returning uniques from functions, etc. |
795 */ | 803 */ |
796 V8_INLINE UniquePersistent Pass() { return UniquePersistent(RValue(this)); } | 804 V8_INLINE UniquePersistent Pass() { return UniquePersistent(RValue(this)); } |
797 | 805 |
798 private: | 806 private: |
799 UniquePersistent(UniquePersistent&); | 807 UniquePersistent(UniquePersistent&); |
800 void operator=(UniquePersistent&); | 808 void operator=(UniquePersistent&); |
801 }; | 809 }; |
802 | 810 |
803 | 811 |
| 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 |
804 /** | 951 /** |
805 * A stack-allocated class that governs a number of local handles. | 952 * A stack-allocated class that governs a number of local handles. |
806 * After a handle scope has been created, all local handles will be | 953 * After a handle scope has been created, all local handles will be |
807 * allocated within that handle scope until either the handle scope is | 954 * allocated within that handle scope until either the handle scope is |
808 * deleted or another handle scope is created. If there is already a | 955 * deleted or another handle scope is created. If there is already a |
809 * handle scope and a new one is created, all allocations will take | 956 * handle scope and a new one is created, all allocations will take |
810 * place in the new handle scope until it is deleted. After that, | 957 * place in the new handle scope until it is deleted. After that, |
811 * new handles will again be allocated in the original handle scope. | 958 * new handles will again be allocated in the original handle scope. |
812 * | 959 * |
813 * After the handle scope of a local handle has been deleted the | 960 * 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... |
2381 V8_INLINE void SetNull(); | 2528 V8_INLINE void SetNull(); |
2382 V8_INLINE void SetUndefined(); | 2529 V8_INLINE void SetUndefined(); |
2383 V8_INLINE void SetEmptyString(); | 2530 V8_INLINE void SetEmptyString(); |
2384 // Convenience getter for Isolate | 2531 // Convenience getter for Isolate |
2385 V8_INLINE Isolate* GetIsolate(); | 2532 V8_INLINE Isolate* GetIsolate(); |
2386 | 2533 |
2387 private: | 2534 private: |
2388 template<class F> friend class ReturnValue; | 2535 template<class F> friend class ReturnValue; |
2389 template<class F> friend class FunctionCallbackInfo; | 2536 template<class F> friend class FunctionCallbackInfo; |
2390 template<class F> friend class PropertyCallbackInfo; | 2537 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; } |
2391 V8_INLINE internal::Object* GetDefaultValue(); | 2540 V8_INLINE internal::Object* GetDefaultValue(); |
2392 V8_INLINE explicit ReturnValue(internal::Object** slot); | 2541 V8_INLINE explicit ReturnValue(internal::Object** slot); |
2393 internal::Object** value_; | 2542 internal::Object** value_; |
2394 }; | 2543 }; |
2395 | 2544 |
2396 | 2545 |
2397 /** | 2546 /** |
2398 * The argument information given to function call callbacks. This | 2547 * The argument information given to function call callbacks. This |
2399 * class provides access to information about the context of the call, | 2548 * class provides access to information about the context of the call, |
2400 * including the receiver, the number and values of arguments, and | 2549 * including the receiver, the number and values of arguments, and |
(...skipping 1827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4228 * instead to influence the garbage collection schedule. | 4377 * instead to influence the garbage collection schedule. |
4229 */ | 4378 */ |
4230 void RequestGarbageCollectionForTesting(GarbageCollectionType type); | 4379 void RequestGarbageCollectionForTesting(GarbageCollectionType type); |
4231 | 4380 |
4232 /** | 4381 /** |
4233 * Set the callback to invoke for logging event. | 4382 * Set the callback to invoke for logging event. |
4234 */ | 4383 */ |
4235 void SetEventLogger(LogEventCallback that); | 4384 void SetEventLogger(LogEventCallback that); |
4236 | 4385 |
4237 private: | 4386 private: |
| 4387 template<class K, class V, class Traits> friend class PersistentValueMap; |
| 4388 |
4238 Isolate(); | 4389 Isolate(); |
4239 Isolate(const Isolate&); | 4390 Isolate(const Isolate&); |
4240 ~Isolate(); | 4391 ~Isolate(); |
4241 Isolate& operator=(const Isolate&); | 4392 Isolate& operator=(const Isolate&); |
4242 void* operator new(size_t size); | 4393 void* operator new(size_t size); |
4243 void operator delete(void*, size_t); | 4394 void operator delete(void*, size_t); |
4244 | 4395 |
4245 void SetObjectGroupId(internal::Object** object, UniqueId id); | 4396 void SetObjectGroupId(internal::Object** object, UniqueId id); |
4246 void SetReferenceFromGroup(UniqueId id, internal::Object** object); | 4397 void SetReferenceFromGroup(UniqueId id, internal::Object** object); |
4247 void SetReference(internal::Object** parent, internal::Object** child); | 4398 void SetReference(internal::Object** parent, internal::Object** child); |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4822 V8(); | 4973 V8(); |
4823 | 4974 |
4824 static internal::Object** GlobalizeReference(internal::Isolate* isolate, | 4975 static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
4825 internal::Object** handle); | 4976 internal::Object** handle); |
4826 static internal::Object** CopyPersistent(internal::Object** handle); | 4977 static internal::Object** CopyPersistent(internal::Object** handle); |
4827 static void DisposeGlobal(internal::Object** global_handle); | 4978 static void DisposeGlobal(internal::Object** global_handle); |
4828 typedef WeakCallbackData<Value, void>::Callback WeakCallback; | 4979 typedef WeakCallbackData<Value, void>::Callback WeakCallback; |
4829 static void MakeWeak(internal::Object** global_handle, | 4980 static void MakeWeak(internal::Object** global_handle, |
4830 void* data, | 4981 void* data, |
4831 WeakCallback weak_callback); | 4982 WeakCallback weak_callback); |
4832 static void ClearWeak(internal::Object** global_handle); | 4983 static void* ClearWeak(internal::Object** global_handle); |
4833 static void Eternalize(Isolate* isolate, | 4984 static void Eternalize(Isolate* isolate, |
4834 Value* handle, | 4985 Value* handle, |
4835 int* index); | 4986 int* index); |
4836 static Local<Value> GetEternal(Isolate* isolate, int index); | 4987 static Local<Value> GetEternal(Isolate* isolate, int index); |
4837 | 4988 |
4838 template <class T> friend class Handle; | 4989 template <class T> friend class Handle; |
4839 template <class T> friend class Local; | 4990 template <class T> friend class Local; |
4840 template <class T> friend class Eternal; | 4991 template <class T> friend class Eternal; |
4841 template <class T> friend class PersistentBase; | 4992 template <class T> friend class PersistentBase; |
4842 template <class T, class M> friend class Persistent; | 4993 template <class T, class M> friend class Persistent; |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5735 template <class T> | 5886 template <class T> |
5736 template <typename P> | 5887 template <typename P> |
5737 void PersistentBase<T>::SetWeak( | 5888 void PersistentBase<T>::SetWeak( |
5738 P* parameter, | 5889 P* parameter, |
5739 typename WeakCallbackData<T, P>::Callback callback) { | 5890 typename WeakCallbackData<T, P>::Callback callback) { |
5740 SetWeak<T, P>(parameter, callback); | 5891 SetWeak<T, P>(parameter, callback); |
5741 } | 5892 } |
5742 | 5893 |
5743 | 5894 |
5744 template <class T> | 5895 template <class T> |
5745 void PersistentBase<T>::ClearWeak() { | 5896 template<typename P> |
5746 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); | 5897 P* PersistentBase<T>::ClearWeak() { |
| 5898 return reinterpret_cast<P*>( |
| 5899 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_))); |
5747 } | 5900 } |
5748 | 5901 |
5749 | 5902 |
5750 template <class T> | 5903 template <class T> |
5751 void PersistentBase<T>::MarkIndependent() { | 5904 void PersistentBase<T>::MarkIndependent() { |
5752 typedef internal::Internals I; | 5905 typedef internal::Internals I; |
5753 if (this->IsEmpty()) return; | 5906 if (this->IsEmpty()) return; |
5754 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | 5907 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
5755 true, | 5908 true, |
5756 I::kNodeIsIndependentShift); | 5909 I::kNodeIsIndependentShift); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5789 template <class T> | 5942 template <class T> |
5790 uint16_t PersistentBase<T>::WrapperClassId() const { | 5943 uint16_t PersistentBase<T>::WrapperClassId() const { |
5791 typedef internal::Internals I; | 5944 typedef internal::Internals I; |
5792 if (this->IsEmpty()) return 0; | 5945 if (this->IsEmpty()) return 0; |
5793 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); | 5946 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
5794 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | 5947 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
5795 return *reinterpret_cast<uint16_t*>(addr); | 5948 return *reinterpret_cast<uint16_t*>(addr); |
5796 } | 5949 } |
5797 | 5950 |
5798 | 5951 |
| 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 |
5799 template<typename T> | 5990 template<typename T> |
5800 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} | 5991 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} |
5801 | 5992 |
5802 template<typename T> | 5993 template<typename T> |
5803 template<typename S> | 5994 template<typename S> |
5804 void ReturnValue<T>::Set(const Persistent<S>& handle) { | 5995 void ReturnValue<T>::Set(const Persistent<S>& handle) { |
5805 TYPE_CHECK(T, S); | 5996 TYPE_CHECK(T, S); |
5806 if (V8_UNLIKELY(handle.IsEmpty())) { | 5997 if (V8_UNLIKELY(handle.IsEmpty())) { |
5807 *value_ = GetDefaultValue(); | 5998 *value_ = GetDefaultValue(); |
5808 } else { | 5999 } else { |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6506 */ | 6697 */ |
6507 | 6698 |
6508 | 6699 |
6509 } // namespace v8 | 6700 } // namespace v8 |
6510 | 6701 |
6511 | 6702 |
6512 #undef TYPE_CHECK | 6703 #undef TYPE_CHECK |
6513 | 6704 |
6514 | 6705 |
6515 #endif // V8_H_ | 6706 #endif // V8_H_ |
OLD | NEW |