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

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: Address 2nd round of feedback. 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 template<class K, class V, class Traits>
dcarney 2014/03/11 15:12:05 need to add some small comments to the functions t
vogelheim 2014/03/11 16:11:59 Done. Please let me know if they're helpful.
820 class PersistentValueMap {
821 public:
822 V8_INLINE explicit PersistentValueMap(Isolate* isolate) : isolate_(isolate) {}
823
824 V8_INLINE ~PersistentValueMap() { Clear(); }
825
826 V8_INLINE Isolate* GetIsolate() { return isolate_; }
827
828 V8_INLINE size_t Size() { return Traits::Size(&impl_); }
829
830 V8_INLINE Local<V> Get(const K& key) {
831 return Local<V>::New(isolate_, FromVal(Traits::Get(&impl_, key)));
832 }
833
834 V8_INLINE bool Contains(const K& key) {
835 return Traits::Get(&impl_, key) != 0;
836 }
837
838 V8_INLINE bool SetReturnValue(const K& key,
839 ReturnValue<Value>& returnValue);
840
841 V8_INLINE void SetReference(const K& key,
842 const v8::Persistent<v8::Object>& parent) {
843 GetIsolate()->SetReference(
844 reinterpret_cast<internal::Object**>(parent.val_),
845 reinterpret_cast<internal::Object**>(FromVal(Traits::Get(&impl_, key))));
846 }
847
848 UniquePersistent<V> Set(const K& key, Local<V> value) {
849 UniquePersistent<V> persistent(isolate_, value);
850 return SetUnique(key, &persistent);
851 }
852
853 UniquePersistent<V> Set(const K& key, UniquePersistent<V> value) {
854 return SetUnique(key, &value);
855 }
856
857 V8_INLINE UniquePersistent<V> Remove(const K& key) {
858 return Release(Traits::Remove(&impl_, key)).Pass();
859 }
860
861 /**
862 * Traverses the map repeatedly,
863 * in case side effects of disposal cause insertions.
864 **/
865 void Clear();
866
867 private:
868 PersistentValueMap(PersistentValueMap&);
869 void operator=(PersistentValueMap&);
870
871 UniquePersistent<V> SetUnique(const K& key, UniquePersistent<V>* persistent) {
872 if (Traits::kIsWeak) {
873 Local<V> value(Local<V>::New(isolate_, *persistent));
874 persistent->template SetWeak<typename Traits::WeakCallbackDataType>(
875 Traits::WeakCallbackParameter(&impl_, key, value), WeakCallback);
876 }
877 PersistentContainerValue old_value =
878 Traits::Set(&impl_, key, ClearAndLeak(persistent));
879 return Release(old_value).Pass();
880 }
881
882 static void WeakCallback(
883 const WeakCallbackData<V, typename Traits::WeakCallbackDataType>& data);
884 V8_INLINE static V* FromVal(PersistentContainerValue v) {
885 return reinterpret_cast<V*>(v);
886 }
887 V8_INLINE static PersistentContainerValue ClearAndLeak(
888 UniquePersistent<V>* persistent) {
889 V* v = persistent->val_;
890 persistent->val_ = 0;
891 return reinterpret_cast<PersistentContainerValue>(v);
892 }
893 V8_INLINE static UniquePersistent<V> Release(PersistentContainerValue v) {
894 UniquePersistent<V> p;
895 p.val_ = FromVal(v);
896 if (Traits::kIsWeak && !p.IsEmpty()) {
897 Traits::DisposeCallbackData(
898 p.template ClearWeak<typename Traits::WeakCallbackDataType>());
899 }
900 return p.Pass();
901 }
902
903 Isolate* isolate_;
904 typename Traits::Impl impl_;
905 };
906
907
803 /** 908 /**
804 * A stack-allocated class that governs a number of local handles. 909 * A stack-allocated class that governs a number of local handles.
805 * After a handle scope has been created, all local handles will be 910 * After a handle scope has been created, all local handles will be
806 * allocated within that handle scope until either the handle scope is 911 * allocated within that handle scope until either the handle scope is
807 * deleted or another handle scope is created. If there is already a 912 * 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 913 * 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, 914 * place in the new handle scope until it is deleted. After that,
810 * new handles will again be allocated in the original handle scope. 915 * new handles will again be allocated in the original handle scope.
811 * 916 *
812 * After the handle scope of a local handle has been deleted the 917 * After the handle scope of a local handle has been deleted the
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 public: 1109 public:
1005 /** 1110 /**
1006 * Compiles the specified script (context-independent). 1111 * Compiles the specified script (context-independent).
1007 * 1112 *
1008 * \param source Script source code. 1113 * \param source Script source code.
1009 * \param origin Script origin, owned by caller, no references are kept 1114 * \param origin Script origin, owned by caller, no references are kept
1010 * when New() returns 1115 * when New() returns
1011 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() 1116 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
1012 * using pre_data speeds compilation if it's done multiple times. 1117 * using pre_data speeds compilation if it's done multiple times.
1013 * Owned by caller, no references are kept when New() returns. 1118 * Owned by caller, no references are kept when New() returns.
1119 * \param script_data Arbitrary data associated with script. Using
1120 * this has same effect as calling SetData(), but allows data to be
1121 * available to compile event handlers.
1014 * \return Compiled script object (context independent; when run it 1122 * \return Compiled script object (context independent; when run it
1015 * will use the currently entered context). 1123 * will use the currently entered context).
1016 */ 1124 */
1017 static Local<Script> New(Handle<String> source, 1125 static Local<Script> New(Handle<String> source,
1018 ScriptOrigin* origin = NULL, 1126 ScriptOrigin* origin = NULL,
1019 ScriptData* pre_data = NULL); 1127 ScriptData* pre_data = NULL,
1128 Handle<String> script_data = Handle<String>());
1020 1129
1021 /** 1130 /**
1022 * Compiles the specified script using the specified file name 1131 * Compiles the specified script using the specified file name
1023 * object (typically a string) as the script's origin. 1132 * object (typically a string) as the script's origin.
1024 * 1133 *
1025 * \param source Script source code. 1134 * \param source Script source code.
1026 * \param file_name file name object (typically a string) to be used 1135 * \param file_name file name object (typically a string) to be used
1027 * as the script's origin. 1136 * as the script's origin.
1028 * \return Compiled script object (context independent; when run it 1137 * \return Compiled script object (context independent; when run it
1029 * will use the currently entered context). 1138 * will use the currently entered context).
1030 */ 1139 */
1031 static Local<Script> New(Handle<String> source, 1140 static Local<Script> New(Handle<String> source,
1032 Handle<Value> file_name); 1141 Handle<Value> file_name);
1033 1142
1034 /** 1143 /**
1035 * Compiles the specified script (bound to current context). 1144 * Compiles the specified script (bound to current context).
1036 * 1145 *
1037 * \param source Script source code. 1146 * \param source Script source code.
1038 * \param origin Script origin, owned by caller, no references are kept 1147 * \param origin Script origin, owned by caller, no references are kept
1039 * when Compile() returns 1148 * when Compile() returns
1040 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() 1149 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
1041 * using pre_data speeds compilation if it's done multiple times. 1150 * using pre_data speeds compilation if it's done multiple times.
1042 * Owned by caller, no references are kept when Compile() returns. 1151 * Owned by caller, no references are kept when Compile() returns.
1152 * \param script_data Arbitrary data associated with script. Using
1153 * this has same effect as calling SetData(), but makes data available
1154 * earlier (i.e. to compile event handlers).
1043 * \return Compiled script object, bound to the context that was active 1155 * \return Compiled script object, bound to the context that was active
1044 * when this function was called. When run it will always use this 1156 * when this function was called. When run it will always use this
1045 * context. 1157 * context.
1046 */ 1158 */
1047 static Local<Script> Compile(Handle<String> source, 1159 static Local<Script> Compile(Handle<String> source,
1048 ScriptOrigin* origin = NULL, 1160 ScriptOrigin* origin = NULL,
1049 ScriptData* pre_data = NULL); 1161 ScriptData* pre_data = NULL,
1162 Handle<String> script_data = Handle<String>());
1050 1163
1051 /** 1164 /**
1052 * Compiles the specified script using the specified file name 1165 * Compiles the specified script using the specified file name
1053 * object (typically a string) as the script's origin. 1166 * object (typically a string) as the script's origin.
1054 * 1167 *
1055 * \param source Script source code. 1168 * \param source Script source code.
1056 * \param file_name File name to use as script's origin 1169 * \param file_name File name to use as script's origin
1170 * \param script_data Arbitrary data associated with script. Using
1171 * this has same effect as calling SetData(), but makes data available
1172 * earlier (i.e. to compile event handlers).
1057 * \return Compiled script object, bound to the context that was active 1173 * \return Compiled script object, bound to the context that was active
1058 * when this function was called. When run it will always use this 1174 * when this function was called. When run it will always use this
1059 * context. 1175 * context.
1060 */ 1176 */
1061 static Local<Script> Compile(Handle<String> source, 1177 static Local<Script> Compile(Handle<String> source,
1062 Handle<Value> file_name); 1178 Handle<Value> file_name,
1179 Handle<String> script_data = Handle<String>());
1063 1180
1064 /** 1181 /**
1065 * Runs the script returning the resulting value. If the script is 1182 * Runs the script returning the resulting value. If the script is
1066 * context independent (created using ::New) it will be run in the 1183 * context independent (created using ::New) it will be run in the
1067 * currently entered context. If it is context specific (created 1184 * currently entered context. If it is context specific (created
1068 * using ::Compile) it will be run in the context in which it was 1185 * using ::Compile) it will be run in the context in which it was
1069 * compiled. 1186 * compiled.
1070 */ 1187 */
1071 Local<Value> Run(); 1188 Local<Value> Run();
1072 1189
1073 /** 1190 /**
1074 * Returns the script id. 1191 * Returns the script id.
1075 */ 1192 */
1076 int GetId(); 1193 int GetId();
1077 1194
1078 /** 1195 /**
1196 * Associate an additional data object with the script. This is mainly used
1197 * with the debugger as this data object is only available through the
1198 * debugger API.
1199 */
1200 void SetData(Handle<String> data);
1201
1202 /**
1079 * Returns the name value of one Script. 1203 * Returns the name value of one Script.
1080 */ 1204 */
1081 Handle<Value> GetScriptName(); 1205 Handle<Value> GetScriptName();
1082 1206
1083 /** 1207 /**
1084 * Returns zero based line number of the code_pos location in the script. 1208 * Returns zero based line number of the code_pos location in the script.
1085 * -1 will be returned if no information available. 1209 * -1 will be returned if no information available.
1086 */ 1210 */
1087 int GetLineNumber(int code_pos); 1211 int GetLineNumber(int code_pos);
1088 1212
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 V8_INLINE void SetNull(); 2487 V8_INLINE void SetNull();
2364 V8_INLINE void SetUndefined(); 2488 V8_INLINE void SetUndefined();
2365 V8_INLINE void SetEmptyString(); 2489 V8_INLINE void SetEmptyString();
2366 // Convenience getter for Isolate 2490 // Convenience getter for Isolate
2367 V8_INLINE Isolate* GetIsolate(); 2491 V8_INLINE Isolate* GetIsolate();
2368 2492
2369 private: 2493 private:
2370 template<class F> friend class ReturnValue; 2494 template<class F> friend class ReturnValue;
2371 template<class F> friend class FunctionCallbackInfo; 2495 template<class F> friend class FunctionCallbackInfo;
2372 template<class F> friend class PropertyCallbackInfo; 2496 template<class F> friend class PropertyCallbackInfo;
2497 template<class F, class G, class H> friend class PersistentValueMap;
2498 V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
2373 V8_INLINE internal::Object* GetDefaultValue(); 2499 V8_INLINE internal::Object* GetDefaultValue();
2374 V8_INLINE explicit ReturnValue(internal::Object** slot); 2500 V8_INLINE explicit ReturnValue(internal::Object** slot);
2375 internal::Object** value_; 2501 internal::Object** value_;
2376 }; 2502 };
2377 2503
2378 2504
2379 /** 2505 /**
2380 * The argument information given to function call callbacks. This 2506 * The argument information given to function call callbacks. This
2381 * class provides access to information about the context of the call, 2507 * class provides access to information about the context of the call,
2382 * including the receiver, the number and values of arguments, and 2508 * 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. 4292 * function if --expose_gc was specified.
4167 * 4293 *
4168 * This should only be used for testing purposes and not to enforce a garbage 4294 * 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 4295 * collection schedule. It has strong negative impact on the garbage
4170 * collection performance. Use IdleNotification() or LowMemoryNotification() 4296 * collection performance. Use IdleNotification() or LowMemoryNotification()
4171 * instead to influence the garbage collection schedule. 4297 * instead to influence the garbage collection schedule.
4172 */ 4298 */
4173 void RequestGarbageCollectionForTesting(GarbageCollectionType type); 4299 void RequestGarbageCollectionForTesting(GarbageCollectionType type);
4174 4300
4175 private: 4301 private:
4302 template<class K, class V, class Traits> friend class PersistentValueMap;
4303
4176 Isolate(); 4304 Isolate();
4177 Isolate(const Isolate&); 4305 Isolate(const Isolate&);
4178 ~Isolate(); 4306 ~Isolate();
4179 Isolate& operator=(const Isolate&); 4307 Isolate& operator=(const Isolate&);
4180 void* operator new(size_t size); 4308 void* operator new(size_t size);
4181 void operator delete(void*, size_t); 4309 void operator delete(void*, size_t);
4182 4310
4183 void SetObjectGroupId(internal::Object** object, UniqueId id); 4311 void SetObjectGroupId(internal::Object** object, UniqueId id);
4184 void SetReferenceFromGroup(UniqueId id, internal::Object** object); 4312 void SetReferenceFromGroup(UniqueId id, internal::Object** object);
4185 void SetReference(internal::Object** parent, internal::Object** child); 4313 void SetReference(internal::Object** parent, internal::Object** child);
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
4760 V8(); 4888 V8();
4761 4889
4762 static internal::Object** GlobalizeReference(internal::Isolate* isolate, 4890 static internal::Object** GlobalizeReference(internal::Isolate* isolate,
4763 internal::Object** handle); 4891 internal::Object** handle);
4764 static internal::Object** CopyPersistent(internal::Object** handle); 4892 static internal::Object** CopyPersistent(internal::Object** handle);
4765 static void DisposeGlobal(internal::Object** global_handle); 4893 static void DisposeGlobal(internal::Object** global_handle);
4766 typedef WeakCallbackData<Value, void>::Callback WeakCallback; 4894 typedef WeakCallbackData<Value, void>::Callback WeakCallback;
4767 static void MakeWeak(internal::Object** global_handle, 4895 static void MakeWeak(internal::Object** global_handle,
4768 void* data, 4896 void* data,
4769 WeakCallback weak_callback); 4897 WeakCallback weak_callback);
4770 static void ClearWeak(internal::Object** global_handle); 4898 static void* ClearWeak(internal::Object** global_handle);
4771 static void Eternalize(Isolate* isolate, 4899 static void Eternalize(Isolate* isolate,
4772 Value* handle, 4900 Value* handle,
4773 int* index); 4901 int* index);
4774 static Local<Value> GetEternal(Isolate* isolate, int index); 4902 static Local<Value> GetEternal(Isolate* isolate, int index);
4775 4903
4776 template <class T> friend class Handle; 4904 template <class T> friend class Handle;
4777 template <class T> friend class Local; 4905 template <class T> friend class Local;
4778 template <class T> friend class Eternal; 4906 template <class T> friend class Eternal;
4779 template <class T> friend class PersistentBase; 4907 template <class T> friend class PersistentBase;
4780 template <class T, class M> friend class Persistent; 4908 template <class T, class M> friend class Persistent;
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
5388 static const int kStringEncodingMask = 0x4; 5516 static const int kStringEncodingMask = 0x4;
5389 static const int kExternalTwoByteRepresentationTag = 0x02; 5517 static const int kExternalTwoByteRepresentationTag = 0x02;
5390 static const int kExternalAsciiRepresentationTag = 0x06; 5518 static const int kExternalAsciiRepresentationTag = 0x06;
5391 5519
5392 static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize; 5520 static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
5393 static const int kIsolateRootsOffset = 5 * kApiPointerSize; 5521 static const int kIsolateRootsOffset = 5 * kApiPointerSize;
5394 static const int kUndefinedValueRootIndex = 5; 5522 static const int kUndefinedValueRootIndex = 5;
5395 static const int kNullValueRootIndex = 7; 5523 static const int kNullValueRootIndex = 7;
5396 static const int kTrueValueRootIndex = 8; 5524 static const int kTrueValueRootIndex = 8;
5397 static const int kFalseValueRootIndex = 9; 5525 static const int kFalseValueRootIndex = 9;
5398 static const int kEmptyStringRootIndex = 144; 5526 static const int kEmptyStringRootIndex = 142;
5399 5527
5400 static const int kNodeClassIdOffset = 1 * kApiPointerSize; 5528 static const int kNodeClassIdOffset = 1 * kApiPointerSize;
5401 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; 5529 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
5402 static const int kNodeStateMask = 0xf; 5530 static const int kNodeStateMask = 0xf;
5403 static const int kNodeStateIsWeakValue = 2; 5531 static const int kNodeStateIsWeakValue = 2;
5404 static const int kNodeStateIsPendingValue = 3; 5532 static const int kNodeStateIsPendingValue = 3;
5405 static const int kNodeStateIsNearDeathValue = 4; 5533 static const int kNodeStateIsNearDeathValue = 4;
5406 static const int kNodeIsIndependentShift = 4; 5534 static const int kNodeIsIndependentShift = 4;
5407 static const int kNodeIsPartiallyDependentShift = 5; 5535 static const int kNodeIsPartiallyDependentShift = 5;
5408 5536
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
5673 template <class T> 5801 template <class T>
5674 template <typename P> 5802 template <typename P>
5675 void PersistentBase<T>::SetWeak( 5803 void PersistentBase<T>::SetWeak(
5676 P* parameter, 5804 P* parameter,
5677 typename WeakCallbackData<T, P>::Callback callback) { 5805 typename WeakCallbackData<T, P>::Callback callback) {
5678 SetWeak<T, P>(parameter, callback); 5806 SetWeak<T, P>(parameter, callback);
5679 } 5807 }
5680 5808
5681 5809
5682 template <class T> 5810 template <class T>
5683 void PersistentBase<T>::ClearWeak() { 5811 template<typename P>
5684 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); 5812 P* PersistentBase<T>::ClearWeak() {
5813 return reinterpret_cast<P*>(
5814 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
5685 } 5815 }
5686 5816
5687 5817
5688 template <class T> 5818 template <class T>
5689 void PersistentBase<T>::MarkIndependent() { 5819 void PersistentBase<T>::MarkIndependent() {
5690 typedef internal::Internals I; 5820 typedef internal::Internals I;
5691 if (this->IsEmpty()) return; 5821 if (this->IsEmpty()) return;
5692 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), 5822 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
5693 true, 5823 true,
5694 I::kNodeIsIndependentShift); 5824 I::kNodeIsIndependentShift);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
5727 template <class T> 5857 template <class T>
5728 uint16_t PersistentBase<T>::WrapperClassId() const { 5858 uint16_t PersistentBase<T>::WrapperClassId() const {
5729 typedef internal::Internals I; 5859 typedef internal::Internals I;
5730 if (this->IsEmpty()) return 0; 5860 if (this->IsEmpty()) return 0;
5731 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); 5861 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
5732 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; 5862 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
5733 return *reinterpret_cast<uint16_t*>(addr); 5863 return *reinterpret_cast<uint16_t*>(addr);
5734 } 5864 }
5735 5865
5736 5866
5867 template <class K, class V, class Traits>
5868 bool PersistentValueMap<K, V, Traits>::SetReturnValue(const K& key,
5869 ReturnValue<Value>& returnValue) {
5870 PersistentContainerValue value = Traits::Get(&impl_, key);
5871 bool hasValue = value != 0;
5872 if (hasValue) {
5873 returnValue.SetInternal(
5874 *reinterpret_cast<internal::Object**>(FromVal(value)));
5875 }
5876 return hasValue;
5877 }
5878
5879 template <class K, class V, class Traits>
5880 void PersistentValueMap<K, V, Traits>::Clear() {
5881 typedef typename Traits::Iterator It;
5882 HandleScope handle_scope(isolate_);
5883 // TODO(dcarney): figure out if this swap and loop is necessary.
5884 while (!Traits::Empty(&impl_)) {
5885 typename Traits::Impl impl;
5886 Traits::Swap(impl_, impl);
5887 for (It i = Traits::Begin(&impl); i != Traits::End(&impl); ++i) {
5888 Traits::Dispose(Release(Traits::Value(i)).Pass(), isolate_, &impl,
5889 Traits::Key(i));
5890 }
5891 }
5892 }
5893
5894
5895 template <class K, class V, class Traits>
5896 void PersistentValueMap<K, V, Traits>::WeakCallback(
5897 const WeakCallbackData<V, typename Traits::WeakCallbackDataType>& data) {
5898 typename Traits::Impl* impl = Traits::ImplFromWeakCallbackData(data);
5899 K key = Traits::KeyFromWeakCallbackData(data);
5900 PersistentContainerValue value = Traits::Remove(impl, key);
5901 Traits::Dispose(Release(value).Pass(), data.GetIsolate(), impl, key);
dcarney 2014/03/11 15:12:05 all function which take an isolate parameter have
vogelheim 2014/03/11 16:11:59 Done.
5902 }
5903
5904
5737 template<typename T> 5905 template<typename T>
5738 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} 5906 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
5739 5907
5740 template<typename T> 5908 template<typename T>
5741 template<typename S> 5909 template<typename S>
5742 void ReturnValue<T>::Set(const Persistent<S>& handle) { 5910 void ReturnValue<T>::Set(const Persistent<S>& handle) {
5743 TYPE_CHECK(T, S); 5911 TYPE_CHECK(T, S);
5744 if (V8_UNLIKELY(handle.IsEmpty())) { 5912 if (V8_UNLIKELY(handle.IsEmpty())) {
5745 *value_ = GetDefaultValue(); 5913 SetInternal(GetDefaultValue());
dcarney 2014/03/11 15:12:05 not much point in changing this if there's no if(V
vogelheim 2014/03/11 16:11:59 Done.
5746 } else { 5914 } else {
5747 *value_ = *reinterpret_cast<internal::Object**>(*handle); 5915 SetInternal(*reinterpret_cast<internal::Object**>(*handle));
5748 } 5916 }
5749 } 5917 }
5750 5918
5751 template<typename T> 5919 template<typename T>
5752 template<typename S> 5920 template<typename S>
5753 void ReturnValue<T>::Set(const Handle<S> handle) { 5921 void ReturnValue<T>::Set(const Handle<S> handle) {
5754 TYPE_CHECK(T, S); 5922 TYPE_CHECK(T, S);
5755 if (V8_UNLIKELY(handle.IsEmpty())) { 5923 if (V8_UNLIKELY(handle.IsEmpty())) {
5756 *value_ = GetDefaultValue(); 5924 SetInternal(GetDefaultValue());
5757 } else { 5925 } else {
5758 *value_ = *reinterpret_cast<internal::Object**>(*handle); 5926 SetInternal(*reinterpret_cast<internal::Object**>(*handle));
5759 } 5927 }
5760 } 5928 }
5761 5929
5762 template<typename T> 5930 template<typename T>
5763 void ReturnValue<T>::Set(double i) { 5931 void ReturnValue<T>::Set(double i) {
5764 TYPE_CHECK(T, Number); 5932 TYPE_CHECK(T, Number);
5765 Set(Number::New(GetIsolate(), i)); 5933 Set(Number::New(GetIsolate(), i));
5766 } 5934 }
5767 5935
5768 template<typename T> 5936 template<typename T>
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
6436 */ 6604 */
6437 6605
6438 6606
6439 } // namespace v8 6607 } // namespace v8
6440 6608
6441 6609
6442 #undef TYPE_CHECK 6610 #undef TYPE_CHECK
6443 6611
6444 6612
6445 #endif // V8_H_ 6613 #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