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

Side by Side Diff: include/v8.h

Issue 863443005: Support old and new weak handle API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Undo cast that was not needed. Created 5 years, 11 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 class Value; 104 class Value;
105 template <class T> class Handle; 105 template <class T> class Handle;
106 template <class T> class Local; 106 template <class T> class Local;
107 template <class T> class Eternal; 107 template <class T> class Eternal;
108 template<class T> class NonCopyablePersistentTraits; 108 template<class T> class NonCopyablePersistentTraits;
109 template<class T> class PersistentBase; 109 template<class T> class PersistentBase;
110 template<class T, 110 template<class T,
111 class M = NonCopyablePersistentTraits<T> > class Persistent; 111 class M = NonCopyablePersistentTraits<T> > class Persistent;
112 template<class T> class UniquePersistent; 112 template<class T> class UniquePersistent;
113 template<class K, class V, class T> class PersistentValueMap; 113 template<class K, class V, class T> class PersistentValueMap;
114 template <class K, class V, class T>
115 class PersistentValueMapBase;
116 template <class K, class V, class T>
117 class PhantomPersistentValueMap;
114 template<class V, class T> class PersistentValueVector; 118 template<class V, class T> class PersistentValueVector;
115 template<class T, class P> class WeakCallbackObject; 119 template<class T, class P> class WeakCallbackObject;
116 class FunctionTemplate; 120 class FunctionTemplate;
117 class ObjectTemplate; 121 class ObjectTemplate;
118 class Data; 122 class Data;
119 template<typename T> class FunctionCallbackInfo; 123 template<typename T> class FunctionCallbackInfo;
120 template<typename T> class PropertyCallbackInfo; 124 template<typename T> class PropertyCallbackInfo;
121 class StackTrace; 125 class StackTrace;
122 class StackFrame; 126 class StackFrame;
123 class Isolate; 127 class Isolate;
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 template<class F> friend class Handle; 398 template<class F> friend class Handle;
395 template<class F> friend class Local; 399 template<class F> friend class Local;
396 template<class F> friend class FunctionCallbackInfo; 400 template<class F> friend class FunctionCallbackInfo;
397 template<class F> friend class PropertyCallbackInfo; 401 template<class F> friend class PropertyCallbackInfo;
398 friend class String; 402 friend class String;
399 friend class Object; 403 friend class Object;
400 friend class Context; 404 friend class Context;
401 template<class F> friend class internal::CustomArguments; 405 template<class F> friend class internal::CustomArguments;
402 friend class HandleScope; 406 friend class HandleScope;
403 friend class EscapableHandleScope; 407 friend class EscapableHandleScope;
404 template<class F1, class F2, class F3> friend class PersistentValueMap; 408 template <class F1, class F2, class F3>
409 friend class PersistentValueMapBase;
405 template<class F1, class F2> friend class PersistentValueVector; 410 template<class F1, class F2> friend class PersistentValueVector;
406 411
407 template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { } 412 template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { }
408 V8_INLINE static Local<T> New(Isolate* isolate, T* that); 413 V8_INLINE static Local<T> New(Isolate* isolate, T* that);
409 }; 414 };
410 415
411 416
412 // Eternal handles are set-once handles that live for the life of the isolate. 417 // Eternal handles are set-once handles that live for the life of the isolate.
413 template <class T> class Eternal { 418 template <class T> class Eternal {
414 public: 419 public:
415 V8_INLINE Eternal() : index_(kInitialValue) { } 420 V8_INLINE Eternal() : index_(kInitialValue) { }
416 template<class S> 421 template<class S>
417 V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : index_(kInitialValue) { 422 V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : index_(kInitialValue) {
418 Set(isolate, handle); 423 Set(isolate, handle);
419 } 424 }
420 // Can only be safely called if already set. 425 // Can only be safely called if already set.
421 V8_INLINE Local<T> Get(Isolate* isolate); 426 V8_INLINE Local<T> Get(Isolate* isolate);
422 V8_INLINE bool IsEmpty() { return index_ == kInitialValue; } 427 V8_INLINE bool IsEmpty() { return index_ == kInitialValue; }
423 template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle); 428 template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
424 429
425 private: 430 private:
426 static const int kInitialValue = -1; 431 static const int kInitialValue = -1;
427 int index_; 432 int index_;
428 }; 433 };
429 434
430 435
431 template <typename T, typename U = void, typename V = void> 436 template <typename T>
432 class PhantomCallbackData : public internal::CallbackData<T> { 437 class PhantomCallbackData : public internal::CallbackData<T> {
433 public: 438 public:
434 typedef void (*Callback)(const PhantomCallbackData<T, U, V>& data); 439 typedef void (*Callback)(const PhantomCallbackData<T>& data);
435 440
436 V8_INLINE U* GetInternalField1() const { return internal_field1_; } 441 V8_INLINE void* GetInternalField1() const { return internal_field1_; }
437 V8_INLINE V* GetInternalField2() const { return internal_field2_; } 442 V8_INLINE void* GetInternalField2() const { return internal_field2_; }
438 443
439 PhantomCallbackData(Isolate* isolate, T* parameter, U* internal_field1, 444 PhantomCallbackData(Isolate* isolate, T* parameter, void* internal_field1,
440 V* internal_field2) 445 void* internal_field2)
441 : internal::CallbackData<T>(isolate, parameter), 446 : internal::CallbackData<T>(isolate, parameter),
442 internal_field1_(internal_field1), 447 internal_field1_(internal_field1),
443 internal_field2_(internal_field2) {} 448 internal_field2_(internal_field2) {}
444 449
445 private: 450 private:
446 U* internal_field1_; 451 void* internal_field1_;
447 V* internal_field2_; 452 void* internal_field2_;
448 }; 453 };
449 454
450 455
451 template <class T, class P> 456 template <class T, class P>
452 class WeakCallbackData : public internal::CallbackData<P> { 457 class WeakCallbackData : public internal::CallbackData<P> {
453 public: 458 public:
454 typedef void (*Callback)(const WeakCallbackData<T, P>& data); 459 typedef void (*Callback)(const WeakCallbackData<T, P>& data);
455 460
456 V8_INLINE Local<T> GetValue() const { return handle_; } 461 V8_INLINE Local<T> GetValue() const { return handle_; }
457 462
458 private: 463 private:
459 friend class internal::GlobalHandles; 464 friend class internal::GlobalHandles;
460 WeakCallbackData(Isolate* isolate, P* parameter, Local<T> handle) 465 WeakCallbackData(Isolate* isolate, P* parameter, Local<T> handle)
461 : internal::CallbackData<P>(isolate, parameter), handle_(handle) {} 466 : internal::CallbackData<P>(isolate, parameter), handle_(handle) {}
462 Local<T> handle_; 467 Local<T> handle_;
463 }; 468 };
464 469
465 470
471 static const int kNoInternalFieldIndex = -1;
472
473
466 /** 474 /**
467 * An object reference that is independent of any handle scope. Where 475 * An object reference that is independent of any handle scope. Where
468 * a Local handle only lives as long as the HandleScope in which it was 476 * a Local handle only lives as long as the HandleScope in which it was
469 * allocated, a PersistentBase handle remains valid until it is explicitly 477 * allocated, a PersistentBase handle remains valid until it is explicitly
470 * disposed. 478 * disposed.
471 * 479 *
472 * A persistent handle contains a reference to a storage cell within 480 * A persistent handle contains a reference to a storage cell within
473 * the v8 engine which holds an object value and which is updated by 481 * the v8 engine which holds an object value and which is updated by
474 * the garbage collector whenever the object is moved. A new storage 482 * the garbage collector whenever the object is moved. A new storage
475 * cell can be created using the constructor or PersistentBase::Reset and 483 * cell can be created using the constructor or PersistentBase::Reset and
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 P* parameter, 551 P* parameter,
544 typename WeakCallbackData<S, P>::Callback callback); 552 typename WeakCallbackData<S, P>::Callback callback);
545 553
546 // Phantom persistents work like weak persistents, except that the pointer to 554 // Phantom persistents work like weak persistents, except that the pointer to
547 // the object being collected is not available in the finalization callback. 555 // the object being collected is not available in the finalization callback.
548 // This enables the garbage collector to collect the object and any objects 556 // This enables the garbage collector to collect the object and any objects
549 // it references transitively in one GC cycle. At the moment you can either 557 // it references transitively in one GC cycle. At the moment you can either
550 // specify a parameter for the callback or the location of two internal 558 // specify a parameter for the callback or the location of two internal
551 // fields in the dying object. 559 // fields in the dying object.
552 template <typename P> 560 template <typename P>
553 V8_INLINE void SetPhantom( 561 V8_INLINE void SetPhantom(P* parameter,
554 P* parameter, 562 typename PhantomCallbackData<P>::Callback callback,
555 typename PhantomCallbackData<P, void, void>::Callback callback); 563 int internal_field_index1 = kNoInternalFieldIndex,
556 template <typename P, typename Q> 564 int internal_field_index2 = kNoInternalFieldIndex);
557 V8_INLINE void SetPhantom(
558 P* parameter, int internal_field_index1,
559 typename PhantomCallbackData<P, Q, void>::Callback callback);
560 template <typename P, typename Q, typename R>
561 V8_INLINE void SetPhantom(
562 P* parameter, int internal_field_index1, int internal_field_index2,
563 typename PhantomCallbackData<P, Q, R>::Callback callback);
564 565
565 template<typename P> 566 template<typename P>
566 V8_INLINE P* ClearWeak(); 567 V8_INLINE P* ClearWeak();
567 568
568 // TODO(dcarney): remove this. 569 // TODO(dcarney): remove this.
569 V8_INLINE void ClearWeak() { ClearWeak<void>(); } 570 V8_INLINE void ClearWeak() { ClearWeak<void>(); }
570 571
571 /** 572 /**
572 * Marks the reference to this object independent. Garbage collector is free 573 * Marks the reference to this object independent. Garbage collector is free
573 * to ignore any object groups containing this object. Weak callback for an 574 * to ignore any object groups containing this object. Weak callback for an
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 609
609 private: 610 private:
610 friend class Isolate; 611 friend class Isolate;
611 friend class Utils; 612 friend class Utils;
612 template<class F> friend class Handle; 613 template<class F> friend class Handle;
613 template<class F> friend class Local; 614 template<class F> friend class Local;
614 template<class F1, class F2> friend class Persistent; 615 template<class F1, class F2> friend class Persistent;
615 template<class F> friend class UniquePersistent; 616 template<class F> friend class UniquePersistent;
616 template<class F> friend class PersistentBase; 617 template<class F> friend class PersistentBase;
617 template<class F> friend class ReturnValue; 618 template<class F> friend class ReturnValue;
618 template<class F1, class F2, class F3> friend class PersistentValueMap; 619 template <class F1, class F2, class F3>
620 friend class PersistentValueMapBase;
619 template<class F1, class F2> friend class PersistentValueVector; 621 template<class F1, class F2> friend class PersistentValueVector;
620 friend class Object; 622 friend class Object;
621 623
622 explicit V8_INLINE PersistentBase(T* val) : val_(val) {} 624 explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
623 PersistentBase(PersistentBase& other); // NOLINT 625 PersistentBase(PersistentBase& other); // NOLINT
624 void operator=(PersistentBase&); 626 void operator=(PersistentBase&);
625 V8_INLINE static T* New(Isolate* isolate, T* that); 627 V8_INLINE static T* New(Isolate* isolate, T* that);
626 628
627 T* val_; 629 T* val_;
628 }; 630 };
(...skipping 1880 matching lines...) Expand 10 before | Expand all | Expand 10 after
2509 Local<String> ObjectProtoToString(); 2511 Local<String> ObjectProtoToString();
2510 2512
2511 /** 2513 /**
2512 * Returns the name of the function invoked as a constructor for this object. 2514 * Returns the name of the function invoked as a constructor for this object.
2513 */ 2515 */
2514 Local<String> GetConstructorName(); 2516 Local<String> GetConstructorName();
2515 2517
2516 /** Gets the number of internal fields for this Object. */ 2518 /** Gets the number of internal fields for this Object. */
2517 int InternalFieldCount(); 2519 int InternalFieldCount();
2518 2520
2519 static const int kNoInternalFieldIndex = -1;
2520
2521 /** Same as above, but works for Persistents */ 2521 /** Same as above, but works for Persistents */
2522 V8_INLINE static int InternalFieldCount( 2522 V8_INLINE static int InternalFieldCount(
2523 const PersistentBase<Object>& object) { 2523 const PersistentBase<Object>& object) {
2524 return object.val_->InternalFieldCount(); 2524 return object.val_->InternalFieldCount();
2525 } 2525 }
2526 2526
2527 /** Gets the value from an internal field. */ 2527 /** Gets the value from an internal field. */
2528 V8_INLINE Local<Value> GetInternalField(int index); 2528 V8_INLINE Local<Value> GetInternalField(int index);
2529 2529
2530 /** Sets the value in an internal field. */ 2530 /** Sets the value in an internal field. */
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2727 V8_INLINE Isolate* GetIsolate(); 2727 V8_INLINE Isolate* GetIsolate();
2728 2728
2729 // Pointer setter: Uncompilable to prevent inadvertent misuse. 2729 // Pointer setter: Uncompilable to prevent inadvertent misuse.
2730 template <typename S> 2730 template <typename S>
2731 V8_INLINE void Set(S* whatever); 2731 V8_INLINE void Set(S* whatever);
2732 2732
2733 private: 2733 private:
2734 template<class F> friend class ReturnValue; 2734 template<class F> friend class ReturnValue;
2735 template<class F> friend class FunctionCallbackInfo; 2735 template<class F> friend class FunctionCallbackInfo;
2736 template<class F> friend class PropertyCallbackInfo; 2736 template<class F> friend class PropertyCallbackInfo;
2737 template<class F, class G, class H> friend class PersistentValueMap; 2737 template <class F, class G, class H>
2738 friend class PersistentValueMapBase;
2738 V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; } 2739 V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
2739 V8_INLINE internal::Object* GetDefaultValue(); 2740 V8_INLINE internal::Object* GetDefaultValue();
2740 V8_INLINE explicit ReturnValue(internal::Object** slot); 2741 V8_INLINE explicit ReturnValue(internal::Object** slot);
2741 internal::Object** value_; 2742 internal::Object** value_;
2742 }; 2743 };
2743 2744
2744 2745
2745 /** 2746 /**
2746 * The argument information given to function call callbacks. This 2747 * The argument information given to function call callbacks. This
2747 * class provides access to information about the context of the call, 2748 * class provides access to information about the context of the call,
(...skipping 2473 matching lines...) Expand 10 before | Expand all | Expand 10 after
5221 /** 5222 /**
5222 * Iterates through all the persistent handles in the current isolate's heap 5223 * Iterates through all the persistent handles in the current isolate's heap
5223 * that have class_ids and are candidates to be marked as partially dependent 5224 * that have class_ids and are candidates to be marked as partially dependent
5224 * handles. This will visit handles to young objects created since the last 5225 * handles. This will visit handles to young objects created since the last
5225 * garbage collection but is free to visit an arbitrary superset of these 5226 * garbage collection but is free to visit an arbitrary superset of these
5226 * objects. 5227 * objects.
5227 */ 5228 */
5228 void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor); 5229 void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
5229 5230
5230 private: 5231 private:
5231 template<class K, class V, class Traits> friend class PersistentValueMap; 5232 template <class K, class V, class Traits>
5233 friend class PersistentValueMapBase;
5232 5234
5233 Isolate(); 5235 Isolate();
5234 Isolate(const Isolate&); 5236 Isolate(const Isolate&);
5235 ~Isolate(); 5237 ~Isolate();
5236 Isolate& operator=(const Isolate&); 5238 Isolate& operator=(const Isolate&);
5237 void* operator new(size_t size); 5239 void* operator new(size_t size);
5238 void operator delete(void*, size_t); 5240 void operator delete(void*, size_t);
5239 5241
5240 void SetObjectGroupId(internal::Object** object, UniqueId id); 5242 void SetObjectGroupId(internal::Object** object, UniqueId id);
5241 void SetReferenceFromGroup(UniqueId id, internal::Object** object); 5243 void SetReferenceFromGroup(UniqueId id, internal::Object** object);
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
5573 5575
5574 enum WeakHandleType { PhantomHandle, NonphantomHandle }; 5576 enum WeakHandleType { PhantomHandle, NonphantomHandle };
5575 5577
5576 static internal::Object** GlobalizeReference(internal::Isolate* isolate, 5578 static internal::Object** GlobalizeReference(internal::Isolate* isolate,
5577 internal::Object** handle); 5579 internal::Object** handle);
5578 static internal::Object** CopyPersistent(internal::Object** handle); 5580 static internal::Object** CopyPersistent(internal::Object** handle);
5579 static void DisposeGlobal(internal::Object** global_handle); 5581 static void DisposeGlobal(internal::Object** global_handle);
5580 typedef WeakCallbackData<Value, void>::Callback WeakCallback; 5582 typedef WeakCallbackData<Value, void>::Callback WeakCallback;
5581 static void MakeWeak(internal::Object** global_handle, void* data, 5583 static void MakeWeak(internal::Object** global_handle, void* data,
5582 WeakCallback weak_callback); 5584 WeakCallback weak_callback);
5583 static void MakePhantom( 5585 static void MakePhantom(internal::Object** global_handle, void* data,
5584 internal::Object** global_handle, void* data, 5586 // Must be 0 or kNoInternalFieldIndex.
5585 // Must be 0 or kNoInternalFieldIndex. 5587 int internal_field_index1,
5586 int internal_field_index1, 5588 // Must be 1 or kNoInternalFieldIndex.
5587 // Must be 1 or kNoInternalFieldIndex. 5589 int internal_field_index2,
5588 int internal_field_index2, 5590 PhantomCallbackData<void>::Callback weak_callback);
5589 PhantomCallbackData<void, void, void>::Callback weak_callback);
5590 static void* ClearWeak(internal::Object** global_handle); 5591 static void* ClearWeak(internal::Object** global_handle);
5591 static void Eternalize(Isolate* isolate, 5592 static void Eternalize(Isolate* isolate,
5592 Value* handle, 5593 Value* handle,
5593 int* index); 5594 int* index);
5594 static Local<Value> GetEternal(Isolate* isolate, int index); 5595 static Local<Value> GetEternal(Isolate* isolate, int index);
5595 5596
5596 template <class T> friend class Handle; 5597 template <class T> friend class Handle;
5597 template <class T> friend class Local; 5598 template <class T> friend class Local;
5598 template <class T> friend class Eternal; 5599 template <class T> friend class Eternal;
5599 template <class T> friend class PersistentBase; 5600 template <class T> friend class PersistentBase;
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
6467 void PersistentBase<T>::SetWeak( 6468 void PersistentBase<T>::SetWeak(
6468 P* parameter, 6469 P* parameter,
6469 typename WeakCallbackData<T, P>::Callback callback) { 6470 typename WeakCallbackData<T, P>::Callback callback) {
6470 SetWeak<T, P>(parameter, callback); 6471 SetWeak<T, P>(parameter, callback);
6471 } 6472 }
6472 6473
6473 6474
6474 template <class T> 6475 template <class T>
6475 template <typename P> 6476 template <typename P>
6476 void PersistentBase<T>::SetPhantom( 6477 void PersistentBase<T>::SetPhantom(
6477 P* parameter, 6478 P* parameter, typename PhantomCallbackData<P>::Callback callback,
6478 typename PhantomCallbackData<P, void, void>::Callback callback) { 6479 int internal_field_index1, int internal_field_index2) {
6479 typedef typename PhantomCallbackData<void, void, void>::Callback Callback; 6480 typedef typename PhantomCallbackData<void>::Callback Callback;
6480 V8::MakePhantom(reinterpret_cast<internal::Object**>(this->val_), parameter,
6481 Object::kNoInternalFieldIndex, Object::kNoInternalFieldIndex,
6482 reinterpret_cast<Callback>(callback));
6483 }
6484
6485
6486 template <class T>
6487 template <typename P, typename Q>
6488 void PersistentBase<T>::SetPhantom(
6489 P* parameter, int internal_field_index1,
6490 typename PhantomCallbackData<P, Q, void>::Callback callback) {
6491 typedef typename PhantomCallbackData<void, void, void>::Callback Callback;
6492 V8::MakePhantom(reinterpret_cast<internal::Object**>(this->val_), parameter,
6493 internal_field_index1, Object::kNoInternalFieldIndex,
6494 reinterpret_cast<Callback>(callback));
6495 }
6496
6497
6498 template <class T>
6499 template <typename P, typename Q, typename R>
6500 void PersistentBase<T>::SetPhantom(
6501 P* parameter, int internal_field_index1, int internal_field_index2,
6502 typename PhantomCallbackData<P, Q, R>::Callback callback) {
6503 typedef typename PhantomCallbackData<void, void, void>::Callback Callback;
6504 V8::MakePhantom(reinterpret_cast<internal::Object**>(this->val_), parameter, 6481 V8::MakePhantom(reinterpret_cast<internal::Object**>(this->val_), parameter,
6505 internal_field_index1, internal_field_index2, 6482 internal_field_index1, internal_field_index2,
6506 reinterpret_cast<Callback>(callback)); 6483 reinterpret_cast<Callback>(callback));
6507 } 6484 }
6508 6485
6509 6486
6510 template <class T> 6487 template <class T>
6511 template <typename P> 6488 template <typename P>
6512 P* PersistentBase<T>::ClearWeak() { 6489 P* PersistentBase<T>::ClearWeak() {
6513 return reinterpret_cast<P*>( 6490 return reinterpret_cast<P*>(
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after
7493 */ 7470 */
7494 7471
7495 7472
7496 } // namespace v8 7473 } // namespace v8
7497 7474
7498 7475
7499 #undef TYPE_CHECK 7476 #undef TYPE_CHECK
7500 7477
7501 7478
7502 #endif // V8_H_ 7479 #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