| OLD | NEW |
| 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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 void SetSecondPassCallback(Callback callback) const { *callback_ = callback; } | 450 void SetSecondPassCallback(Callback callback) const { *callback_ = callback; } |
| 451 | 451 |
| 452 private: | 452 private: |
| 453 Isolate* isolate_; | 453 Isolate* isolate_; |
| 454 T* parameter_; | 454 T* parameter_; |
| 455 Callback* callback_; | 455 Callback* callback_; |
| 456 void* internal_fields_[kInternalFieldsInWeakCallback]; | 456 void* internal_fields_[kInternalFieldsInWeakCallback]; |
| 457 }; | 457 }; |
| 458 | 458 |
| 459 | 459 |
| 460 template <class T, class P> | |
| 461 class WeakCallbackData { | |
| 462 public: | |
| 463 typedef void (*Callback)(const WeakCallbackData<T, P>& data); | |
| 464 | |
| 465 WeakCallbackData(Isolate* isolate, P* parameter, Local<T> handle) | |
| 466 : isolate_(isolate), parameter_(parameter), handle_(handle) {} | |
| 467 | |
| 468 V8_INLINE Isolate* GetIsolate() const { return isolate_; } | |
| 469 V8_INLINE P* GetParameter() const { return parameter_; } | |
| 470 V8_INLINE Local<T> GetValue() const { return handle_; } | |
| 471 | |
| 472 private: | |
| 473 Isolate* isolate_; | |
| 474 P* parameter_; | |
| 475 Local<T> handle_; | |
| 476 }; | |
| 477 | |
| 478 | |
| 479 // TODO(dcarney): delete this with WeakCallbackData | |
| 480 template <class T> | |
| 481 using PhantomCallbackData = WeakCallbackInfo<T>; | |
| 482 | |
| 483 // kParameter will pass a void* parameter back to the callback, kInternalFields | 460 // kParameter will pass a void* parameter back to the callback, kInternalFields |
| 484 // will pass the first two internal fields back to the callback, kFinalizer | 461 // will pass the first two internal fields back to the callback, kFinalizer |
| 485 // will pass a void* parameter back, but is invoked before the object is | 462 // will pass a void* parameter back, but is invoked before the object is |
| 486 // actually collected, so it can be resurrected. In the last case, it is not | 463 // actually collected, so it can be resurrected. In the last case, it is not |
| 487 // possible to request a second pass callback. | 464 // possible to request a second pass callback. |
| 488 enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer }; | 465 enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer }; |
| 489 | 466 |
| 490 /** | 467 /** |
| 491 * An object reference that is independent of any handle scope. Where | 468 * An object reference that is independent of any handle scope. Where |
| 492 * a Local handle only lives as long as the HandleScope in which it was | 469 * a Local handle only lives as long as the HandleScope in which it was |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 } | 534 } |
| 558 | 535 |
| 559 /** | 536 /** |
| 560 * Install a finalization callback on this object. | 537 * Install a finalization callback on this object. |
| 561 * NOTE: There is no guarantee as to *when* or even *if* the callback is | 538 * NOTE: There is no guarantee as to *when* or even *if* the callback is |
| 562 * invoked. The invocation is performed solely on a best effort basis. | 539 * invoked. The invocation is performed solely on a best effort basis. |
| 563 * As always, GC-based finalization should *not* be relied upon for any | 540 * As always, GC-based finalization should *not* be relied upon for any |
| 564 * critical form of resource management! | 541 * critical form of resource management! |
| 565 */ | 542 */ |
| 566 template <typename P> | 543 template <typename P> |
| 567 V8_INLINE V8_DEPRECATED( | |
| 568 "use WeakCallbackInfo version", | |
| 569 void SetWeak(P* parameter, | |
| 570 typename WeakCallbackData<T, P>::Callback callback)); | |
| 571 | |
| 572 template <typename S, typename P> | |
| 573 V8_INLINE V8_DEPRECATED( | |
| 574 "use WeakCallbackInfo version", | |
| 575 void SetWeak(P* parameter, | |
| 576 typename WeakCallbackData<S, P>::Callback callback)); | |
| 577 | |
| 578 // Phantom persistents work like weak persistents, except that the pointer to | |
| 579 // the object being collected is not available in the finalization callback. | |
| 580 // This enables the garbage collector to collect the object and any objects | |
| 581 // it references transitively in one GC cycle. At the moment you can either | |
| 582 // specify a parameter for the callback or the location of two internal | |
| 583 // fields in the dying object. | |
| 584 template <typename P> | |
| 585 V8_INLINE V8_DEPRECATED( | |
| 586 "use SetWeak", | |
| 587 void SetPhantom(P* parameter, | |
| 588 typename WeakCallbackInfo<P>::Callback callback, | |
| 589 int internal_field_index1 = -1, | |
| 590 int internal_field_index2 = -1)); | |
| 591 | |
| 592 template <typename P> | |
| 593 V8_INLINE void SetWeak(P* parameter, | 544 V8_INLINE void SetWeak(P* parameter, |
| 594 typename WeakCallbackInfo<P>::Callback callback, | 545 typename WeakCallbackInfo<P>::Callback callback, |
| 595 WeakCallbackType type); | 546 WeakCallbackType type); |
| 596 | 547 |
| 597 template<typename P> | 548 template<typename P> |
| 598 V8_INLINE P* ClearWeak(); | 549 V8_INLINE P* ClearWeak(); |
| 599 | 550 |
| 600 // TODO(dcarney): remove this. | 551 // TODO(dcarney): remove this. |
| 601 V8_INLINE void ClearWeak() { ClearWeak<void>(); } | 552 V8_INLINE void ClearWeak() { ClearWeak<void>(); } |
| 602 | 553 |
| (...skipping 6067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6670 */ | 6621 */ |
| 6671 static void ShutdownPlatform(); | 6622 static void ShutdownPlatform(); |
| 6672 | 6623 |
| 6673 private: | 6624 private: |
| 6674 V8(); | 6625 V8(); |
| 6675 | 6626 |
| 6676 static internal::Object** GlobalizeReference(internal::Isolate* isolate, | 6627 static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| 6677 internal::Object** handle); | 6628 internal::Object** handle); |
| 6678 static internal::Object** CopyPersistent(internal::Object** handle); | 6629 static internal::Object** CopyPersistent(internal::Object** handle); |
| 6679 static void DisposeGlobal(internal::Object** global_handle); | 6630 static void DisposeGlobal(internal::Object** global_handle); |
| 6680 typedef WeakCallbackData<Value, void>::Callback WeakCallback; | |
| 6681 static void MakeWeak(internal::Object** global_handle, void* data, | |
| 6682 WeakCallback weak_callback); | |
| 6683 static void MakeWeak(internal::Object** global_handle, void* data, | 6631 static void MakeWeak(internal::Object** global_handle, void* data, |
| 6684 WeakCallbackInfo<void>::Callback weak_callback, | 6632 WeakCallbackInfo<void>::Callback weak_callback, |
| 6685 WeakCallbackType type); | 6633 WeakCallbackType type); |
| 6686 static void MakeWeak(internal::Object** global_handle, void* data, | 6634 static void MakeWeak(internal::Object** global_handle, void* data, |
| 6687 // Must be 0 or -1. | 6635 // Must be 0 or -1. |
| 6688 int internal_field_index1, | 6636 int internal_field_index1, |
| 6689 // Must be 1 or -1. | 6637 // Must be 1 or -1. |
| 6690 int internal_field_index2, | 6638 int internal_field_index2, |
| 6691 WeakCallbackInfo<void>::Callback weak_callback); | 6639 WeakCallbackInfo<void>::Callback weak_callback); |
| 6692 static void* ClearWeak(internal::Object** global_handle); | 6640 static void* ClearWeak(internal::Object** global_handle); |
| (...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7645 void PersistentBase<T>::Reset(Isolate* isolate, | 7593 void PersistentBase<T>::Reset(Isolate* isolate, |
| 7646 const PersistentBase<S>& other) { | 7594 const PersistentBase<S>& other) { |
| 7647 TYPE_CHECK(T, S); | 7595 TYPE_CHECK(T, S); |
| 7648 Reset(); | 7596 Reset(); |
| 7649 if (other.IsEmpty()) return; | 7597 if (other.IsEmpty()) return; |
| 7650 this->val_ = New(isolate, other.val_); | 7598 this->val_ = New(isolate, other.val_); |
| 7651 } | 7599 } |
| 7652 | 7600 |
| 7653 | 7601 |
| 7654 template <class T> | 7602 template <class T> |
| 7655 template <typename S, typename P> | |
| 7656 void PersistentBase<T>::SetWeak( | |
| 7657 P* parameter, | |
| 7658 typename WeakCallbackData<S, P>::Callback callback) { | |
| 7659 TYPE_CHECK(S, T); | |
| 7660 typedef typename WeakCallbackData<Value, void>::Callback Callback; | |
| 7661 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter, | |
| 7662 reinterpret_cast<Callback>(callback)); | |
| 7663 } | |
| 7664 | |
| 7665 | |
| 7666 template <class T> | |
| 7667 template <typename P> | |
| 7668 void PersistentBase<T>::SetWeak( | |
| 7669 P* parameter, | |
| 7670 typename WeakCallbackData<T, P>::Callback callback) { | |
| 7671 SetWeak<T, P>(parameter, callback); | |
| 7672 } | |
| 7673 | |
| 7674 | |
| 7675 template <class T> | |
| 7676 template <typename P> | |
| 7677 void PersistentBase<T>::SetPhantom( | |
| 7678 P* parameter, typename WeakCallbackInfo<P>::Callback callback, | |
| 7679 int internal_field_index1, int internal_field_index2) { | |
| 7680 typedef typename WeakCallbackInfo<void>::Callback Callback; | |
| 7681 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter, | |
| 7682 internal_field_index1, internal_field_index2, | |
| 7683 reinterpret_cast<Callback>(callback)); | |
| 7684 } | |
| 7685 | |
| 7686 | |
| 7687 template <class T> | |
| 7688 template <typename P> | 7603 template <typename P> |
| 7689 V8_INLINE void PersistentBase<T>::SetWeak( | 7604 V8_INLINE void PersistentBase<T>::SetWeak( |
| 7690 P* parameter, typename WeakCallbackInfo<P>::Callback callback, | 7605 P* parameter, typename WeakCallbackInfo<P>::Callback callback, |
| 7691 WeakCallbackType type) { | 7606 WeakCallbackType type) { |
| 7692 typedef typename WeakCallbackInfo<void>::Callback Callback; | 7607 typedef typename WeakCallbackInfo<void>::Callback Callback; |
| 7693 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter, | 7608 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter, |
| 7694 reinterpret_cast<Callback>(callback), type); | 7609 reinterpret_cast<Callback>(callback), type); |
| 7695 } | 7610 } |
| 7696 | 7611 |
| 7697 | 7612 |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8790 */ | 8705 */ |
| 8791 | 8706 |
| 8792 | 8707 |
| 8793 } // namespace v8 | 8708 } // namespace v8 |
| 8794 | 8709 |
| 8795 | 8710 |
| 8796 #undef TYPE_CHECK | 8711 #undef TYPE_CHECK |
| 8797 | 8712 |
| 8798 | 8713 |
| 8799 #endif // INCLUDE_V8_H_ | 8714 #endif // INCLUDE_V8_H_ |
| OLD | NEW |