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

Side by Side Diff: include/v8.h

Issue 989153003: remove phantom naming from the api (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | include/v8-util.h » ('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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** \mainpage V8 API Reference Guide 5 /** \mainpage V8 API Reference Guide
6 * 6 *
7 * V8 is Google's open source JavaScript engine. 7 * V8 is Google's open source JavaScript engine.
8 * 8 *
9 * This set of documents provides reference material generated from the 9 * This set of documents provides reference material generated from the
10 * V8 header file, include/v8.h. 10 * V8 header file, include/v8.h.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 template<class T> class NonCopyablePersistentTraits; 114 template<class T> class NonCopyablePersistentTraits;
115 template<class T> class PersistentBase; 115 template<class T> class PersistentBase;
116 template<class T, 116 template<class T,
117 class M = NonCopyablePersistentTraits<T> > class Persistent; 117 class M = NonCopyablePersistentTraits<T> > class Persistent;
118 template <class T> 118 template <class T>
119 class Global; 119 class Global;
120 template<class K, class V, class T> class PersistentValueMap; 120 template<class K, class V, class T> class PersistentValueMap;
121 template <class K, class V, class T> 121 template <class K, class V, class T>
122 class PersistentValueMapBase; 122 class PersistentValueMapBase;
123 template <class K, class V, class T> 123 template <class K, class V, class T>
124 class PhantomPersistentValueMap; 124 class GlobalValueMap;
125 template<class V, class T> class PersistentValueVector; 125 template<class V, class T> class PersistentValueVector;
126 template<class T, class P> class WeakCallbackObject; 126 template<class T, class P> class WeakCallbackObject;
127 class FunctionTemplate; 127 class FunctionTemplate;
128 class ObjectTemplate; 128 class ObjectTemplate;
129 class Data; 129 class Data;
130 template<typename T> class FunctionCallbackInfo; 130 template<typename T> class FunctionCallbackInfo;
131 template<typename T> class PropertyCallbackInfo; 131 template<typename T> class PropertyCallbackInfo;
132 class StackTrace; 132 class StackTrace;
133 class StackFrame; 133 class StackFrame;
134 class Isolate; 134 class Isolate;
135 class CallHandlerHelper; 135 class CallHandlerHelper;
136 class EscapableHandleScope; 136 class EscapableHandleScope;
137 template<typename T> class ReturnValue; 137 template<typename T> class ReturnValue;
138 138
139 namespace internal { 139 namespace internal {
140 class Arguments; 140 class Arguments;
141 class Heap; 141 class Heap;
142 class HeapObject; 142 class HeapObject;
143 class Isolate; 143 class Isolate;
144 class Object; 144 class Object;
145 struct StreamedSource; 145 struct StreamedSource;
146 template<typename T> class CustomArguments; 146 template<typename T> class CustomArguments;
147 class PropertyCallbackArguments; 147 class PropertyCallbackArguments;
148 class FunctionCallbackArguments; 148 class FunctionCallbackArguments;
149 class GlobalHandles; 149 class GlobalHandles;
150
151 template <typename T>
152 class CallbackData {
153 public:
154 V8_INLINE v8::Isolate* GetIsolate() const { return isolate_; }
155
156 explicit CallbackData(v8::Isolate* isolate, T* parameter)
157 : isolate_(isolate), parameter_(parameter) {}
158 V8_INLINE T* GetParameter() const { return parameter_; }
159
160 private:
161 v8::Isolate* isolate_;
162 T* parameter_;
163 };
164 } 150 }
165 151
166 152
167 /** 153 /**
168 * General purpose unique identifier. 154 * General purpose unique identifier.
169 */ 155 */
170 class UniqueId { 156 class UniqueId {
171 public: 157 public:
172 explicit UniqueId(intptr_t data) 158 explicit UniqueId(intptr_t data)
173 : data_(data) {} 159 : data_(data) {}
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 V8_INLINE bool IsEmpty() { return index_ == kInitialValue; } 457 V8_INLINE bool IsEmpty() { return index_ == kInitialValue; }
472 template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle); 458 template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
473 459
474 private: 460 private:
475 static const int kInitialValue = -1; 461 static const int kInitialValue = -1;
476 int index_; 462 int index_;
477 }; 463 };
478 464
479 465
480 template <typename T> 466 template <typename T>
481 class PhantomCallbackData : public internal::CallbackData<T> { 467 class WeakCallbackInfo {
482 public: 468 public:
483 typedef void (*Callback)(const PhantomCallbackData<T>& data); 469 typedef void (*Callback)(const WeakCallbackInfo<T>& data);
484 470
471 WeakCallbackInfo(Isolate* isolate, T* parameter, void* internal_field1,
472 void* internal_field2)
473 : isolate_(isolate),
474 parameter_(parameter),
475 internal_field1_(internal_field1),
476 internal_field2_(internal_field2) {}
477
478 V8_INLINE Isolate* GetIsolate() const { return isolate_; }
479 V8_INLINE T* GetParameter() const { return parameter_; }
485 V8_INLINE void* GetInternalField1() const { return internal_field1_; } 480 V8_INLINE void* GetInternalField1() const { return internal_field1_; }
486 V8_INLINE void* GetInternalField2() const { return internal_field2_; } 481 V8_INLINE void* GetInternalField2() const { return internal_field2_; }
487 482
488 PhantomCallbackData(Isolate* isolate, T* parameter, void* internal_field1,
489 void* internal_field2)
490 : internal::CallbackData<T>(isolate, parameter),
491 internal_field1_(internal_field1),
492 internal_field2_(internal_field2) {}
493
494 private: 483 private:
484 Isolate* isolate_;
485 T* parameter_;
495 void* internal_field1_; 486 void* internal_field1_;
496 void* internal_field2_; 487 void* internal_field2_;
497 }; 488 };
498 489
499 490
500 template <class T, class P> 491 template <class T, class P>
501 class WeakCallbackData : public internal::CallbackData<P> { 492 class WeakCallbackData {
502 public: 493 public:
503 typedef void (*Callback)(const WeakCallbackData<T, P>& data); 494 typedef void (*Callback)(const WeakCallbackData<T, P>& data);
504 495
496 WeakCallbackData(Isolate* isolate, P* parameter, Local<T> handle)
497 : isolate_(isolate), parameter_(parameter), handle_(handle) {}
498
499 V8_INLINE Isolate* GetIsolate() const { return isolate_; }
500 V8_INLINE P* GetParameter() const { return parameter_; }
505 V8_INLINE Local<T> GetValue() const { return handle_; } 501 V8_INLINE Local<T> GetValue() const { return handle_; }
506 502
507 private: 503 private:
508 friend class internal::GlobalHandles; 504 Isolate* isolate_;
509 WeakCallbackData(Isolate* isolate, P* parameter, Local<T> handle) 505 P* parameter_;
510 : internal::CallbackData<P>(isolate, parameter), handle_(handle) {}
511 Local<T> handle_; 506 Local<T> handle_;
512 }; 507 };
513 508
514 509
515 static const int kNoInternalFieldIndex = -1; 510 // TODO(dcarney): delete this with WeakCallbackData
511 template <class T>
512 using PhantomCallbackData = WeakCallbackInfo<T>;
513
514
515 enum class WeakCallbackType { kParameter, kInternalFields };
516 516
517 517
518 /** 518 /**
519 * An object reference that is independent of any handle scope. Where 519 * An object reference that is independent of any handle scope. Where
520 * a Local handle only lives as long as the HandleScope in which it was 520 * a Local handle only lives as long as the HandleScope in which it was
521 * allocated, a PersistentBase handle remains valid until it is explicitly 521 * allocated, a PersistentBase handle remains valid until it is explicitly
522 * disposed. 522 * disposed.
523 * 523 *
524 * A persistent handle contains a reference to a storage cell within 524 * A persistent handle contains a reference to a storage cell within
525 * the v8 engine which holds an object value and which is updated by 525 * the v8 engine which holds an object value and which is updated by
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 return !operator==(that); 578 return !operator==(that);
579 } 579 }
580 580
581 /** 581 /**
582 * Install a finalization callback on this object. 582 * Install a finalization callback on this object.
583 * NOTE: There is no guarantee as to *when* or even *if* the callback is 583 * NOTE: There is no guarantee as to *when* or even *if* the callback is
584 * invoked. The invocation is performed solely on a best effort basis. 584 * invoked. The invocation is performed solely on a best effort basis.
585 * As always, GC-based finalization should *not* be relied upon for any 585 * As always, GC-based finalization should *not* be relied upon for any
586 * critical form of resource management! 586 * critical form of resource management!
587 */ 587 */
588 template<typename P> 588 template <typename P>
589 V8_INLINE void SetWeak( 589 V8_INLINE V8_DEPRECATE_SOON(
590 P* parameter, 590 "use WeakCallbackInfo version",
591 typename WeakCallbackData<T, P>::Callback callback); 591 void SetWeak(P* parameter,
592 typename WeakCallbackData<T, P>::Callback callback));
592 593
593 template<typename S, typename P> 594 template <typename S, typename P>
594 V8_INLINE void SetWeak( 595 V8_INLINE V8_DEPRECATE_SOON(
595 P* parameter, 596 "use WeakCallbackInfo version",
596 typename WeakCallbackData<S, P>::Callback callback); 597 void SetWeak(P* parameter,
598 typename WeakCallbackData<S, P>::Callback callback));
597 599
598 // Phantom persistents work like weak persistents, except that the pointer to 600 // Phantom persistents work like weak persistents, except that the pointer to
599 // the object being collected is not available in the finalization callback. 601 // the object being collected is not available in the finalization callback.
600 // This enables the garbage collector to collect the object and any objects 602 // This enables the garbage collector to collect the object and any objects
601 // it references transitively in one GC cycle. At the moment you can either 603 // it references transitively in one GC cycle. At the moment you can either
602 // specify a parameter for the callback or the location of two internal 604 // specify a parameter for the callback or the location of two internal
603 // fields in the dying object. 605 // fields in the dying object.
604 template <typename P> 606 template <typename P>
605 V8_INLINE void SetPhantom(P* parameter, 607 V8_INLINE V8_DEPRECATE_SOON(
606 typename PhantomCallbackData<P>::Callback callback, 608 "use SetWeak",
607 int internal_field_index1 = kNoInternalFieldIndex, 609 void SetPhantom(P* parameter,
608 int internal_field_index2 = kNoInternalFieldIndex); 610 typename WeakCallbackInfo<P>::Callback callback,
611 int internal_field_index1 = -1,
612 int internal_field_index2 = -1));
613
614 template <typename P>
615 V8_INLINE void SetWeak(P* parameter,
616 typename WeakCallbackInfo<P>::Callback callback,
617 WeakCallbackType type);
609 618
610 template<typename P> 619 template<typename P>
611 V8_INLINE P* ClearWeak(); 620 V8_INLINE P* ClearWeak();
612 621
613 // TODO(dcarney): remove this. 622 // TODO(dcarney): remove this.
614 V8_INLINE void ClearWeak() { ClearWeak<void>(); } 623 V8_INLINE void ClearWeak() { ClearWeak<void>(); }
615 624
616 /** 625 /**
617 * Marks the reference to this object independent. Garbage collector is free 626 * Marks the reference to this object independent. Garbage collector is free
618 * to ignore any object groups containing this object. Weak callback for an 627 * to ignore any object groups containing this object. Weak callback for an
(...skipping 5189 matching lines...) Expand 10 before | Expand all | Expand 10 after
5808 5817
5809 /** 5818 /**
5810 * Clears all references to the v8::Platform. This should be invoked after 5819 * Clears all references to the v8::Platform. This should be invoked after
5811 * V8 was disposed. 5820 * V8 was disposed.
5812 */ 5821 */
5813 static void ShutdownPlatform(); 5822 static void ShutdownPlatform();
5814 5823
5815 private: 5824 private:
5816 V8(); 5825 V8();
5817 5826
5818 enum WeakHandleType { PhantomHandle, NonphantomHandle };
5819
5820 static internal::Object** GlobalizeReference(internal::Isolate* isolate, 5827 static internal::Object** GlobalizeReference(internal::Isolate* isolate,
5821 internal::Object** handle); 5828 internal::Object** handle);
5822 static internal::Object** CopyPersistent(internal::Object** handle); 5829 static internal::Object** CopyPersistent(internal::Object** handle);
5823 static void DisposeGlobal(internal::Object** global_handle); 5830 static void DisposeGlobal(internal::Object** global_handle);
5824 typedef WeakCallbackData<Value, void>::Callback WeakCallback; 5831 typedef WeakCallbackData<Value, void>::Callback WeakCallback;
5825 static void MakeWeak(internal::Object** global_handle, void* data, 5832 static void MakeWeak(internal::Object** global_handle, void* data,
5826 WeakCallback weak_callback); 5833 WeakCallback weak_callback);
5827 static void MakePhantom(internal::Object** global_handle, void* data, 5834 static void MakeWeak(internal::Object** global_handle, void* data,
5828 // Must be 0 or kNoInternalFieldIndex. 5835 WeakCallbackInfo<void>::Callback weak_callback,
5829 int internal_field_index1, 5836 WeakCallbackType type);
5830 // Must be 1 or kNoInternalFieldIndex. 5837 static void MakeWeak(internal::Object** global_handle, void* data,
5831 int internal_field_index2, 5838 // Must be 0 or -1.
5832 PhantomCallbackData<void>::Callback weak_callback); 5839 int internal_field_index1,
5840 // Must be 1 or -1.
5841 int internal_field_index2,
5842 WeakCallbackInfo<void>::Callback weak_callback);
5833 static void* ClearWeak(internal::Object** global_handle); 5843 static void* ClearWeak(internal::Object** global_handle);
5834 static void Eternalize(Isolate* isolate, 5844 static void Eternalize(Isolate* isolate,
5835 Value* handle, 5845 Value* handle,
5836 int* index); 5846 int* index);
5837 static Local<Value> GetEternal(Isolate* isolate, int index); 5847 static Local<Value> GetEternal(Isolate* isolate, int index);
5838 5848
5839 static void CheckIsJust(bool is_just); 5849 static void CheckIsJust(bool is_just);
5840 5850
5841 template <class T> friend class Handle; 5851 template <class T> friend class Handle;
5842 template <class T> friend class Local; 5852 template <class T> friend class Local;
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
6769 void PersistentBase<T>::SetWeak( 6779 void PersistentBase<T>::SetWeak(
6770 P* parameter, 6780 P* parameter,
6771 typename WeakCallbackData<T, P>::Callback callback) { 6781 typename WeakCallbackData<T, P>::Callback callback) {
6772 SetWeak<T, P>(parameter, callback); 6782 SetWeak<T, P>(parameter, callback);
6773 } 6783 }
6774 6784
6775 6785
6776 template <class T> 6786 template <class T>
6777 template <typename P> 6787 template <typename P>
6778 void PersistentBase<T>::SetPhantom( 6788 void PersistentBase<T>::SetPhantom(
6779 P* parameter, typename PhantomCallbackData<P>::Callback callback, 6789 P* parameter, typename WeakCallbackInfo<P>::Callback callback,
6780 int internal_field_index1, int internal_field_index2) { 6790 int internal_field_index1, int internal_field_index2) {
6781 typedef typename PhantomCallbackData<void>::Callback Callback; 6791 typedef typename WeakCallbackInfo<void>::Callback Callback;
6782 V8::MakePhantom(reinterpret_cast<internal::Object**>(this->val_), parameter, 6792 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
6783 internal_field_index1, internal_field_index2, 6793 internal_field_index1, internal_field_index2,
6784 reinterpret_cast<Callback>(callback)); 6794 reinterpret_cast<Callback>(callback));
6785 } 6795 }
6786 6796
6787 6797
6798 template <class T>
6799 template <typename P>
6800 V8_INLINE void PersistentBase<T>::SetWeak(
6801 P* parameter, typename WeakCallbackInfo<P>::Callback callback,
6802 WeakCallbackType type) {
6803 typedef typename WeakCallbackInfo<void>::Callback Callback;
6804 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
6805 reinterpret_cast<Callback>(callback), type);
6806 }
6807
6808
6788 template <class T> 6809 template <class T>
6789 template <typename P> 6810 template <typename P>
6790 P* PersistentBase<T>::ClearWeak() { 6811 P* PersistentBase<T>::ClearWeak() {
6791 return reinterpret_cast<P*>( 6812 return reinterpret_cast<P*>(
6792 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_))); 6813 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
6793 } 6814 }
6794 6815
6795 6816
6796 template <class T> 6817 template <class T>
6797 void PersistentBase<T>::MarkIndependent() { 6818 void PersistentBase<T>::MarkIndependent() {
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after
7780 */ 7801 */
7781 7802
7782 7803
7783 } // namespace v8 7804 } // namespace v8
7784 7805
7785 7806
7786 #undef TYPE_CHECK 7807 #undef TYPE_CHECK
7787 7808
7788 7809
7789 #endif // V8_H_ 7810 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | include/v8-util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698