Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: include/v8.h

Issue 189463019: Implement PersistentValueMap, a map that stores UniquePersistent values. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix test case. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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 586
580 explicit V8_INLINE PersistentBase(T* val) : val_(val) {} 587 explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
581 PersistentBase(PersistentBase& other); // NOLINT 588 PersistentBase(PersistentBase& other); // NOLINT
582 void operator=(PersistentBase&); 589 void operator=(PersistentBase&);
583 V8_INLINE static T* New(Isolate* isolate, T* that); 590 V8_INLINE static T* New(Isolate* isolate, T* that);
584 591
585 T* val_; 592 T* val_;
586 }; 593 };
587 594
588 595
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 * Note: Persistent class hierarchy is subject to future changes. 743 * Note: Persistent class hierarchy is subject to future changes.
737 */ 744 */
738 template<class T> 745 template<class T>
739 class UniquePersistent : public PersistentBase<T> { 746 class UniquePersistent : public PersistentBase<T> {
740 struct RValue { 747 struct RValue {
741 V8_INLINE explicit RValue(UniquePersistent* obj) : object(obj) {} 748 V8_INLINE explicit RValue(UniquePersistent* obj) : object(obj) {}
742 UniquePersistent* object; 749 UniquePersistent* object;
743 }; 750 };
744 751
745 public: 752 public:
746 /** 753 /**
747 * A UniquePersistent with no storage cell. 754 * A UniquePersistent with no storage cell.
748 */ 755 */
749 V8_INLINE UniquePersistent() : PersistentBase<T>(0) { } 756 V8_INLINE UniquePersistent() : PersistentBase<T>(0) { }
750 /** 757 /**
751 * Construct a UniquePersistent from a Handle. 758 * Construct a UniquePersistent from a Handle.
752 * When the Handle is non-empty, a new storage cell is created 759 * When the Handle is non-empty, a new storage cell is created
753 * pointing to the same object, and no flags are set. 760 * pointing to the same object, and no flags are set.
754 */ 761 */
755 template <class S> 762 template <class S>
756 V8_INLINE UniquePersistent(Isolate* isolate, Handle<S> that) 763 V8_INLINE UniquePersistent(Isolate* isolate, Handle<S> that)
(...skipping 17 matching lines...) Expand all
774 : PersistentBase<T>(rvalue.object->val_) { 781 : PersistentBase<T>(rvalue.object->val_) {
775 rvalue.object->val_ = 0; 782 rvalue.object->val_ = 0;
776 } 783 }
777 V8_INLINE ~UniquePersistent() { this->Reset(); } 784 V8_INLINE ~UniquePersistent() { this->Reset(); }
778 /** 785 /**
779 * Move via assignment. 786 * Move via assignment.
780 */ 787 */
781 template<class S> 788 template<class S>
782 V8_INLINE UniquePersistent& operator=(UniquePersistent<S> rhs) { 789 V8_INLINE UniquePersistent& operator=(UniquePersistent<S> rhs) {
783 TYPE_CHECK(T, S); 790 TYPE_CHECK(T, S);
791 this->Reset();
784 this->val_ = rhs.val_; 792 this->val_ = rhs.val_;
785 rhs.val_ = 0; 793 rhs.val_ = 0;
786 return *this; 794 return *this;
787 } 795 }
788 /** 796 /**
789 * Cast operator for moves. 797 * Cast operator for moves.
790 */ 798 */
791 V8_INLINE operator RValue() { return RValue(this); } 799 V8_INLINE operator RValue() { return RValue(this); }
792 /** 800 /**
793 * Pass allows returning uniques from functions, etc. 801 * Pass allows returning uniques from functions, etc.
794 */ 802 */
795 V8_INLINE UniquePersistent Pass() { return UniquePersistent(RValue(this)); } 803 V8_INLINE UniquePersistent Pass() { return UniquePersistent(RValue(this)); }
796 804
797 private: 805 private:
798 UniquePersistent(UniquePersistent&); 806 UniquePersistent(UniquePersistent&);
799 void operator=(UniquePersistent&); 807 void operator=(UniquePersistent&);
800 }; 808 };
801 809
802 810
811 typedef uintptr_t PersistentContainerValue;
812 static const uintptr_t kPersistentContainerNotFound = 0;
813
814 /**
815 * A map wrapper that allows using UniquePersistent as a mapped value.
816 * C++11 embedders don't need this class, as they can use UniquePersistent
817 * directly in std containers.
818 *
819 * The map relies on a backing map, whose type and accessors are described
820 * by the Traits class. The backing map will handle values of type
821 * PersistentContainerValue, with all conversion into and out of V8
822 * handles being transparently handled by this class.
823 */
824 template<class K, class V, class Traits>
825 class PersistentValueMap {
826 public:
827 V8_INLINE explicit PersistentValueMap(Isolate* isolate) : isolate_(isolate) {}
828
829 V8_INLINE ~PersistentValueMap() { Clear(); }
830
831 V8_INLINE Isolate* GetIsolate() { return isolate_; }
832
833 /**
834 * Return size of the map.
835 */
836 V8_INLINE size_t Size() { return Traits::Size(&impl_); }
837
838 /**
839 * Get value stored in map.
840 */
841 V8_INLINE Local<V> Get(const K& key) {
842 return Local<V>::New(isolate_, FromVal(Traits::Get(&impl_, key)));
843 }
844
845 /**
846 * Check whether a value is contained in the map.
847 */
848 V8_INLINE bool Contains(const K& key) {
849 return Traits::Get(&impl_, key) != 0;
850 }
851
852 /**
853 * Get value stored in map and set it in returnValue.
854 * Return true if a value was found.
855 */
856 V8_INLINE bool SetReturnValue(const K& key,
857 ReturnValue<Value>& returnValue);
858
859 /**
860 * Call Isolate::SetReference with the given parent and the map value.
861 */
862 V8_INLINE void SetReference(const K& key,
863 const v8::Persistent<v8::Object>& parent) {
864 GetIsolate()->SetReference(
865 reinterpret_cast<internal::Object**>(parent.val_),
866 reinterpret_cast<internal::Object**>(FromVal(Traits::Get(&impl_, key))));
867 }
868
869 /**
870 * Put value into map. Depending on Traits::kIsWeak, the value will be held
871 * by the map strongly or weakly.
872 * Returns old value as UniquePersistent.
873 */
874 UniquePersistent<V> Set(const K& key, Local<V> value) {
875 UniquePersistent<V> persistent(isolate_, value);
876 return SetUnique(key, &persistent);
877 }
878
879 /**
880 * Put value into map, like Set(const K&, Local<V>).
881 */
882 UniquePersistent<V> Set(const K& key, UniquePersistent<V> value) {
883 return SetUnique(key, &value);
884 }
885
886 /**
887 * Return value for key and remove it from the map.
888 */
889 V8_INLINE UniquePersistent<V> Remove(const K& key) {
890 return Release(Traits::Remove(&impl_, key)).Pass();
891 }
892
893 /**
894 * Traverses the map repeatedly,
895 * in case side effects of disposal cause insertions.
896 **/
897 void Clear();
898
899 private:
900 PersistentValueMap(PersistentValueMap&);
901 void operator=(PersistentValueMap&);
902
903 /**
904 * Put the value into the map, and set the 'weak' callback when demanded
905 * by the Traits class.
906 */
907 UniquePersistent<V> SetUnique(const K& key, UniquePersistent<V>* persistent) {
908 if (Traits::kIsWeak) {
909 Local<V> value(Local<V>::New(isolate_, *persistent));
910 persistent->template SetWeak<typename Traits::WeakCallbackDataType>(
911 Traits::WeakCallbackParameter(&impl_, key, value), WeakCallback);
912 }
913 PersistentContainerValue old_value =
914 Traits::Set(&impl_, key, ClearAndLeak(persistent));
915 return Release(old_value).Pass();
916 }
917
918 static void WeakCallback(
919 const WeakCallbackData<V, typename Traits::WeakCallbackDataType>& data);
920 V8_INLINE static V* FromVal(PersistentContainerValue v) {
921 return reinterpret_cast<V*>(v);
922 }
923 V8_INLINE static PersistentContainerValue ClearAndLeak(
924 UniquePersistent<V>* persistent) {
925 V* v = persistent->val_;
926 persistent->val_ = 0;
927 return reinterpret_cast<PersistentContainerValue>(v);
928 }
929
930 /**
931 * Return a container value as UniquePersistent and make sure the weak
932 * callback is properly disposed of. All remove functionality should go
933 * through this.
934 */
935 V8_INLINE static UniquePersistent<V> Release(PersistentContainerValue v) {
936 UniquePersistent<V> p;
937 p.val_ = FromVal(v);
938 if (Traits::kIsWeak && !p.IsEmpty()) {
939 Traits::DisposeCallbackData(
940 p.template ClearWeak<typename Traits::WeakCallbackDataType>());
941 }
942 return p.Pass();
943 }
944
945 Isolate* isolate_;
946 typename Traits::Impl impl_;
947 };
948
949
803 /** 950 /**
804 * A stack-allocated class that governs a number of local handles. 951 * A stack-allocated class that governs a number of local handles.
805 * After a handle scope has been created, all local handles will be 952 * After a handle scope has been created, all local handles will be
806 * allocated within that handle scope until either the handle scope is 953 * allocated within that handle scope until either the handle scope is
807 * deleted or another handle scope is created. If there is already a 954 * deleted or another handle scope is created. If there is already a
808 * handle scope and a new one is created, all allocations will take 955 * handle scope and a new one is created, all allocations will take
809 * place in the new handle scope until it is deleted. After that, 956 * place in the new handle scope until it is deleted. After that,
810 * new handles will again be allocated in the original handle scope. 957 * new handles will again be allocated in the original handle scope.
811 * 958 *
812 * After the handle scope of a local handle has been deleted the 959 * After the handle scope of a local handle has been deleted the
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 V8_INLINE void SetNull(); 2510 V8_INLINE void SetNull();
2364 V8_INLINE void SetUndefined(); 2511 V8_INLINE void SetUndefined();
2365 V8_INLINE void SetEmptyString(); 2512 V8_INLINE void SetEmptyString();
2366 // Convenience getter for Isolate 2513 // Convenience getter for Isolate
2367 V8_INLINE Isolate* GetIsolate(); 2514 V8_INLINE Isolate* GetIsolate();
2368 2515
2369 private: 2516 private:
2370 template<class F> friend class ReturnValue; 2517 template<class F> friend class ReturnValue;
2371 template<class F> friend class FunctionCallbackInfo; 2518 template<class F> friend class FunctionCallbackInfo;
2372 template<class F> friend class PropertyCallbackInfo; 2519 template<class F> friend class PropertyCallbackInfo;
2520 template<class F, class G, class H> friend class PersistentValueMap;
2521 V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
2373 V8_INLINE internal::Object* GetDefaultValue(); 2522 V8_INLINE internal::Object* GetDefaultValue();
2374 V8_INLINE explicit ReturnValue(internal::Object** slot); 2523 V8_INLINE explicit ReturnValue(internal::Object** slot);
2375 internal::Object** value_; 2524 internal::Object** value_;
2376 }; 2525 };
2377 2526
2378 2527
2379 /** 2528 /**
2380 * The argument information given to function call callbacks. This 2529 * The argument information given to function call callbacks. This
2381 * class provides access to information about the context of the call, 2530 * class provides access to information about the context of the call,
2382 * including the receiver, the number and values of arguments, and 2531 * including the receiver, the number and values of arguments, and
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after
4166 * function if --expose_gc was specified. 4315 * function if --expose_gc was specified.
4167 * 4316 *
4168 * This should only be used for testing purposes and not to enforce a garbage 4317 * This should only be used for testing purposes and not to enforce a garbage
4169 * collection schedule. It has strong negative impact on the garbage 4318 * collection schedule. It has strong negative impact on the garbage
4170 * collection performance. Use IdleNotification() or LowMemoryNotification() 4319 * collection performance. Use IdleNotification() or LowMemoryNotification()
4171 * instead to influence the garbage collection schedule. 4320 * instead to influence the garbage collection schedule.
4172 */ 4321 */
4173 void RequestGarbageCollectionForTesting(GarbageCollectionType type); 4322 void RequestGarbageCollectionForTesting(GarbageCollectionType type);
4174 4323
4175 private: 4324 private:
4325 template<class K, class V, class Traits> friend class PersistentValueMap;
4326
4176 Isolate(); 4327 Isolate();
4177 Isolate(const Isolate&); 4328 Isolate(const Isolate&);
4178 ~Isolate(); 4329 ~Isolate();
4179 Isolate& operator=(const Isolate&); 4330 Isolate& operator=(const Isolate&);
4180 void* operator new(size_t size); 4331 void* operator new(size_t size);
4181 void operator delete(void*, size_t); 4332 void operator delete(void*, size_t);
4182 4333
4183 void SetObjectGroupId(internal::Object** object, UniqueId id); 4334 void SetObjectGroupId(internal::Object** object, UniqueId id);
4184 void SetReferenceFromGroup(UniqueId id, internal::Object** object); 4335 void SetReferenceFromGroup(UniqueId id, internal::Object** object);
4185 void SetReference(internal::Object** parent, internal::Object** child); 4336 void SetReference(internal::Object** parent, internal::Object** child);
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
4760 V8(); 4911 V8();
4761 4912
4762 static internal::Object** GlobalizeReference(internal::Isolate* isolate, 4913 static internal::Object** GlobalizeReference(internal::Isolate* isolate,
4763 internal::Object** handle); 4914 internal::Object** handle);
4764 static internal::Object** CopyPersistent(internal::Object** handle); 4915 static internal::Object** CopyPersistent(internal::Object** handle);
4765 static void DisposeGlobal(internal::Object** global_handle); 4916 static void DisposeGlobal(internal::Object** global_handle);
4766 typedef WeakCallbackData<Value, void>::Callback WeakCallback; 4917 typedef WeakCallbackData<Value, void>::Callback WeakCallback;
4767 static void MakeWeak(internal::Object** global_handle, 4918 static void MakeWeak(internal::Object** global_handle,
4768 void* data, 4919 void* data,
4769 WeakCallback weak_callback); 4920 WeakCallback weak_callback);
4770 static void ClearWeak(internal::Object** global_handle); 4921 static void* ClearWeak(internal::Object** global_handle);
4771 static void Eternalize(Isolate* isolate, 4922 static void Eternalize(Isolate* isolate,
4772 Value* handle, 4923 Value* handle,
4773 int* index); 4924 int* index);
4774 static Local<Value> GetEternal(Isolate* isolate, int index); 4925 static Local<Value> GetEternal(Isolate* isolate, int index);
4775 4926
4776 template <class T> friend class Handle; 4927 template <class T> friend class Handle;
4777 template <class T> friend class Local; 4928 template <class T> friend class Local;
4778 template <class T> friend class Eternal; 4929 template <class T> friend class Eternal;
4779 template <class T> friend class PersistentBase; 4930 template <class T> friend class PersistentBase;
4780 template <class T, class M> friend class Persistent; 4931 template <class T, class M> friend class Persistent;
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
5673 template <class T> 5824 template <class T>
5674 template <typename P> 5825 template <typename P>
5675 void PersistentBase<T>::SetWeak( 5826 void PersistentBase<T>::SetWeak(
5676 P* parameter, 5827 P* parameter,
5677 typename WeakCallbackData<T, P>::Callback callback) { 5828 typename WeakCallbackData<T, P>::Callback callback) {
5678 SetWeak<T, P>(parameter, callback); 5829 SetWeak<T, P>(parameter, callback);
5679 } 5830 }
5680 5831
5681 5832
5682 template <class T> 5833 template <class T>
5683 void PersistentBase<T>::ClearWeak() { 5834 template<typename P>
5684 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); 5835 P* PersistentBase<T>::ClearWeak() {
5836 return reinterpret_cast<P*>(
5837 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
5685 } 5838 }
5686 5839
5687 5840
5688 template <class T> 5841 template <class T>
5689 void PersistentBase<T>::MarkIndependent() { 5842 void PersistentBase<T>::MarkIndependent() {
5690 typedef internal::Internals I; 5843 typedef internal::Internals I;
5691 if (this->IsEmpty()) return; 5844 if (this->IsEmpty()) return;
5692 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), 5845 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
5693 true, 5846 true,
5694 I::kNodeIsIndependentShift); 5847 I::kNodeIsIndependentShift);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
5727 template <class T> 5880 template <class T>
5728 uint16_t PersistentBase<T>::WrapperClassId() const { 5881 uint16_t PersistentBase<T>::WrapperClassId() const {
5729 typedef internal::Internals I; 5882 typedef internal::Internals I;
5730 if (this->IsEmpty()) return 0; 5883 if (this->IsEmpty()) return 0;
5731 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); 5884 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
5732 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; 5885 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
5733 return *reinterpret_cast<uint16_t*>(addr); 5886 return *reinterpret_cast<uint16_t*>(addr);
5734 } 5887 }
5735 5888
5736 5889
5890 template <class K, class V, class Traits>
5891 bool PersistentValueMap<K, V, Traits>::SetReturnValue(const K& key,
5892 ReturnValue<Value>& returnValue) {
5893 PersistentContainerValue value = Traits::Get(&impl_, key);
5894 bool hasValue = value != 0;
5895 if (hasValue) {
5896 returnValue.SetInternal(
5897 *reinterpret_cast<internal::Object**>(FromVal(value)));
5898 }
5899 return hasValue;
5900 }
5901
5902 template <class K, class V, class Traits>
5903 void PersistentValueMap<K, V, Traits>::Clear() {
5904 typedef typename Traits::Iterator It;
5905 HandleScope handle_scope(isolate_);
5906 // TODO(dcarney): figure out if this swap and loop is necessary.
5907 while (!Traits::Empty(&impl_)) {
5908 typename Traits::Impl impl;
5909 Traits::Swap(impl_, impl);
5910 for (It i = Traits::Begin(&impl); i != Traits::End(&impl); ++i) {
5911 Traits::Dispose(isolate_, Release(Traits::Value(i)).Pass(), &impl,
5912 Traits::Key(i));
5913 }
5914 }
5915 }
5916
5917
5918 template <class K, class V, class Traits>
5919 void PersistentValueMap<K, V, Traits>::WeakCallback(
5920 const WeakCallbackData<V, typename Traits::WeakCallbackDataType>& data) {
5921 typename Traits::Impl* impl = Traits::ImplFromWeakCallbackData(data);
5922 K key = Traits::KeyFromWeakCallbackData(data);
5923 PersistentContainerValue value = Traits::Remove(impl, key);
5924 Traits::Dispose(data.GetIsolate(), Release(value).Pass(), impl, key);
5925 }
5926
5927
5737 template<typename T> 5928 template<typename T>
5738 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} 5929 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
5739 5930
5740 template<typename T> 5931 template<typename T>
5741 template<typename S> 5932 template<typename S>
5742 void ReturnValue<T>::Set(const Persistent<S>& handle) { 5933 void ReturnValue<T>::Set(const Persistent<S>& handle) {
5743 TYPE_CHECK(T, S); 5934 TYPE_CHECK(T, S);
5744 if (V8_UNLIKELY(handle.IsEmpty())) { 5935 if (V8_UNLIKELY(handle.IsEmpty())) {
5745 *value_ = GetDefaultValue(); 5936 *value_ = GetDefaultValue();
5746 } else { 5937 } else {
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
6436 */ 6627 */
6437 6628
6438 6629
6439 } // namespace v8 6630 } // namespace v8
6440 6631
6441 6632
6442 #undef TYPE_CHECK 6633 #undef TYPE_CHECK
6443 6634
6444 6635
6445 #endif // V8_H_ 6636 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698