| OLD | NEW |
| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 * \param parameter the value passed in when making the weak global object | 207 * \param parameter the value passed in when making the weak global object |
| 208 */ | 208 */ |
| 209 template<typename T, typename P> | 209 template<typename T, typename P> |
| 210 class WeakReferenceCallbacks { | 210 class WeakReferenceCallbacks { |
| 211 public: | 211 public: |
| 212 typedef void (*Revivable)(Isolate* isolate, | 212 typedef void (*Revivable)(Isolate* isolate, |
| 213 Persistent<T>* object, | 213 Persistent<T>* object, |
| 214 P* parameter); | 214 P* parameter); |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 // TODO(svenpanne) Temporary definition until Chrome is in sync. | |
| 218 typedef void (*NearDeathCallback)(Isolate* isolate, | |
| 219 Persistent<Value> object, | |
| 220 void* parameter); | |
| 221 | |
| 222 // --- Handles --- | 217 // --- Handles --- |
| 223 | 218 |
| 224 #define TYPE_CHECK(T, S) \ | 219 #define TYPE_CHECK(T, S) \ |
| 225 while (false) { \ | 220 while (false) { \ |
| 226 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ | 221 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
| 227 } | 222 } |
| 228 | 223 |
| 229 | 224 |
| 230 #define V8_USE_UNSAFE_HANDLES | 225 #define V8_USE_UNSAFE_HANDLES |
| 231 #define V8_USE_OLD_STYLE_PERSISTENT_HANDLE_VISITORS | 226 #define V8_USE_OLD_STYLE_PERSISTENT_HANDLE_VISITORS |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 664 |
| 670 // TODO(dcarney): deprecate | 665 // TODO(dcarney): deprecate |
| 671 template<typename P> | 666 template<typename P> |
| 672 V8_INLINE(void MakeWeak( | 667 V8_INLINE(void MakeWeak( |
| 673 Isolate* isolate, | 668 Isolate* isolate, |
| 674 P* parameters, | 669 P* parameters, |
| 675 typename WeakReferenceCallbacks<T, P>::Revivable callback)) { | 670 typename WeakReferenceCallbacks<T, P>::Revivable callback)) { |
| 676 MakeWeak<P>(parameters, callback); | 671 MakeWeak<P>(parameters, callback); |
| 677 } | 672 } |
| 678 | 673 |
| 679 // TODO(dcarney): remove before cutover | |
| 680 V8_INLINE(void MakeWeak(Isolate* isolate, | |
| 681 void* parameters, | |
| 682 NearDeathCallback callback)); | |
| 683 | |
| 684 V8_INLINE(void ClearWeak()); | 674 V8_INLINE(void ClearWeak()); |
| 685 | 675 |
| 686 // TODO(dcarney): deprecate | 676 // TODO(dcarney): deprecate |
| 687 V8_INLINE(void ClearWeak(Isolate* isolate)) { ClearWeak(); } | 677 V8_INLINE(void ClearWeak(Isolate* isolate)) { ClearWeak(); } |
| 688 | 678 |
| 689 /** | 679 /** |
| 690 * Marks the reference to this object independent. Garbage collector is free | 680 * Marks the reference to this object independent. Garbage collector is free |
| 691 * to ignore any object groups containing this object. Weak callback for an | 681 * to ignore any object groups containing this object. Weak callback for an |
| 692 * independent handle should not assume that it will be preceded by a global | 682 * independent handle should not assume that it will be preceded by a global |
| 693 * GC prologue callback or followed by a global GC epilogue callback. | 683 * GC prologue callback or followed by a global GC epilogue callback. |
| (...skipping 3904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4598 | 4588 |
| 4599 private: | 4589 private: |
| 4600 V8(); | 4590 V8(); |
| 4601 | 4591 |
| 4602 static internal::Object** GlobalizeReference(internal::Isolate* isolate, | 4592 static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| 4603 internal::Object** handle); | 4593 internal::Object** handle); |
| 4604 static void DisposeGlobal(internal::Object** global_handle); | 4594 static void DisposeGlobal(internal::Object** global_handle); |
| 4605 typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; | 4595 typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; |
| 4606 static void MakeWeak(internal::Object** global_handle, | 4596 static void MakeWeak(internal::Object** global_handle, |
| 4607 void* data, | 4597 void* data, |
| 4608 RevivableCallback weak_reference_callback, | 4598 RevivableCallback weak_reference_callback); |
| 4609 NearDeathCallback near_death_callback); | |
| 4610 static void ClearWeak(internal::Object** global_handle); | 4599 static void ClearWeak(internal::Object** global_handle); |
| 4611 | 4600 |
| 4612 template <class T> friend class Handle; | 4601 template <class T> friend class Handle; |
| 4613 template <class T> friend class Local; | 4602 template <class T> friend class Local; |
| 4614 template <class T> friend class Persistent; | 4603 template <class T> friend class Persistent; |
| 4615 friend class Context; | 4604 friend class Context; |
| 4616 }; | 4605 }; |
| 4617 | 4606 |
| 4618 | 4607 |
| 4619 /** | 4608 /** |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5533 | 5522 |
| 5534 template <class T> | 5523 template <class T> |
| 5535 template <typename S, typename P> | 5524 template <typename S, typename P> |
| 5536 void Persistent<T>::MakeWeak( | 5525 void Persistent<T>::MakeWeak( |
| 5537 P* parameters, | 5526 P* parameters, |
| 5538 typename WeakReferenceCallbacks<S, P>::Revivable callback) { | 5527 typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| 5539 TYPE_CHECK(S, T); | 5528 TYPE_CHECK(S, T); |
| 5540 typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; | 5529 typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; |
| 5541 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), | 5530 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), |
| 5542 parameters, | 5531 parameters, |
| 5543 reinterpret_cast<Revivable>(callback), | 5532 reinterpret_cast<Revivable>(callback)); |
| 5544 NULL); | |
| 5545 } | 5533 } |
| 5546 | 5534 |
| 5547 | 5535 |
| 5548 template <class T> | 5536 template <class T> |
| 5549 template <typename P> | 5537 template <typename P> |
| 5550 void Persistent<T>::MakeWeak( | 5538 void Persistent<T>::MakeWeak( |
| 5551 P* parameters, | 5539 P* parameters, |
| 5552 typename WeakReferenceCallbacks<T, P>::Revivable callback) { | 5540 typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
| 5553 MakeWeak<T, P>(parameters, callback); | 5541 MakeWeak<T, P>(parameters, callback); |
| 5554 } | 5542 } |
| 5555 | 5543 |
| 5556 | 5544 |
| 5557 template <class T> | 5545 template <class T> |
| 5558 void Persistent<T>::MakeWeak(Isolate* isolate, | |
| 5559 void* parameters, | |
| 5560 NearDeathCallback callback) { | |
| 5561 V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), | |
| 5562 parameters, | |
| 5563 NULL, | |
| 5564 callback); | |
| 5565 } | |
| 5566 | |
| 5567 | |
| 5568 template <class T> | |
| 5569 void Persistent<T>::ClearWeak() { | 5546 void Persistent<T>::ClearWeak() { |
| 5570 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); | 5547 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); |
| 5571 } | 5548 } |
| 5572 | 5549 |
| 5573 | 5550 |
| 5574 template <class T> | 5551 template <class T> |
| 5575 void Persistent<T>::MarkIndependent() { | 5552 void Persistent<T>::MarkIndependent() { |
| 5576 typedef internal::Internals I; | 5553 typedef internal::Internals I; |
| 5577 if (this->IsEmpty()) return; | 5554 if (this->IsEmpty()) return; |
| 5578 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | 5555 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6302 | 6279 |
| 6303 | 6280 |
| 6304 } // namespace v8 | 6281 } // namespace v8 |
| 6305 | 6282 |
| 6306 | 6283 |
| 6307 #undef V8EXPORT | 6284 #undef V8EXPORT |
| 6308 #undef TYPE_CHECK | 6285 #undef TYPE_CHECK |
| 6309 | 6286 |
| 6310 | 6287 |
| 6311 #endif // V8_H_ | 6288 #endif // V8_H_ |
| OLD | NEW |