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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 184 |
185 /** | 185 /** |
186 * A weak reference callback function. | 186 * A weak reference callback function. |
187 * | 187 * |
188 * This callback should either explicitly invoke Dispose on |object| if | 188 * This callback should either explicitly invoke Dispose on |object| if |
189 * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. | 189 * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. |
190 * | 190 * |
191 * \param object the weak global object to be reclaimed by the garbage collector | 191 * \param object the weak global object to be reclaimed by the garbage collector |
192 * \param parameter the value passed in when making the weak global object | 192 * \param parameter the value passed in when making the weak global object |
193 */ | 193 */ |
194 typedef void (*WeakReferenceCallback)(Persistent<Value> object, | 194 template<typename T, typename P> |
195 void* parameter); | 195 class WeakReferenceCallbacks { |
| 196 public: |
| 197 typedef void (*Revivable)(Isolate* isolate, |
| 198 Persistent<T>* object, |
| 199 P* parameter); |
| 200 }; |
196 | 201 |
197 // TODO(svenpanne) Temporary definition until Chrome is in sync. | 202 // TODO(svenpanne) Temporary definition until Chrome is in sync. |
198 typedef void (*NearDeathCallback)(Isolate* isolate, | 203 typedef void (*NearDeathCallback)(Isolate* isolate, |
199 Persistent<Value> object, | 204 Persistent<Value> object, |
200 void* parameter); | 205 void* parameter); |
201 | 206 |
202 // --- Handles --- | 207 // --- Handles --- |
203 | 208 |
204 #define TYPE_CHECK(T, S) \ | 209 #define TYPE_CHECK(T, S) \ |
205 while (false) { \ | 210 while (false) { \ |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 | 596 |
592 /** | 597 /** |
593 * Releases the storage cell referenced by this persistent handle. | 598 * Releases the storage cell referenced by this persistent handle. |
594 * Does not remove the reference to the cell from any handles. | 599 * Does not remove the reference to the cell from any handles. |
595 * This handle's reference, and any other references to the storage | 600 * This handle's reference, and any other references to the storage |
596 * cell remain and IsEmpty will still return false. | 601 * cell remain and IsEmpty will still return false. |
597 */ | 602 */ |
598 // TODO(dcarney): remove before cutover | 603 // TODO(dcarney): remove before cutover |
599 V8_INLINE(void Dispose(Isolate* isolate)); | 604 V8_INLINE(void Dispose(Isolate* isolate)); |
600 | 605 |
601 V8_INLINE(void MakeWeak(void* parameters, | 606 template<typename S, typename P> |
602 WeakReferenceCallback callback)); | 607 V8_INLINE(void MakeWeak( |
| 608 Isolate* isolate, |
| 609 P* parameters, |
| 610 typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
| 611 |
| 612 template<typename P> |
| 613 V8_INLINE(void MakeWeak( |
| 614 Isolate* isolate, |
| 615 P* parameters, |
| 616 typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
603 | 617 |
604 /** | 618 /** |
605 * Make the reference to this object weak. When only weak handles | 619 * Make the reference to this object weak. When only weak handles |
606 * refer to the object, the garbage collector will perform a | 620 * refer to the object, the garbage collector will perform a |
607 * callback to the given V8::NearDeathCallback function, passing | 621 * callback to the given V8::NearDeathCallback function, passing |
608 * it the object reference and the given parameters. | 622 * it the object reference and the given parameters. |
609 */ | 623 */ |
610 // TODO(dcarney): remove before cutover | 624 // TODO(dcarney): remove before cutover |
611 V8_INLINE(void MakeWeak(Isolate* isolate, | 625 V8_INLINE(void MakeWeak(Isolate* isolate, |
612 void* parameters, | 626 void* parameters, |
(...skipping 3743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4356 */ | 4370 */ |
4357 static int ContextDisposedNotification(); | 4371 static int ContextDisposedNotification(); |
4358 | 4372 |
4359 private: | 4373 private: |
4360 V8(); | 4374 V8(); |
4361 | 4375 |
4362 static internal::Object** GlobalizeReference(internal::Isolate* isolate, | 4376 static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
4363 internal::Object** handle); | 4377 internal::Object** handle); |
4364 static void DisposeGlobal(internal::Isolate* isolate, | 4378 static void DisposeGlobal(internal::Isolate* isolate, |
4365 internal::Object** global_handle); | 4379 internal::Object** global_handle); |
| 4380 typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; |
4366 static void MakeWeak(internal::Isolate* isolate, | 4381 static void MakeWeak(internal::Isolate* isolate, |
4367 internal::Object** global_handle, | 4382 internal::Object** global_handle, |
4368 void* data, | 4383 void* data, |
4369 WeakReferenceCallback weak_reference_callback, | 4384 RevivableCallback weak_reference_callback, |
4370 NearDeathCallback near_death_callback); | 4385 NearDeathCallback near_death_callback); |
4371 static void ClearWeak(internal::Isolate* isolate, | 4386 static void ClearWeak(internal::Isolate* isolate, |
4372 internal::Object** global_handle); | 4387 internal::Object** global_handle); |
4373 | 4388 |
4374 template <class T> friend class Handle; | 4389 template <class T> friend class Handle; |
4375 template <class T> friend class Local; | 4390 template <class T> friend class Local; |
4376 template <class T> friend class Persistent; | 4391 template <class T> friend class Persistent; |
4377 friend class Context; | 4392 friend class Context; |
4378 }; | 4393 }; |
4379 | 4394 |
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5275 if (this->IsEmpty()) return; | 5290 if (this->IsEmpty()) return; |
5276 V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate), | 5291 V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate), |
5277 reinterpret_cast<internal::Object**>(this->val_)); | 5292 reinterpret_cast<internal::Object**>(this->val_)); |
5278 #ifndef V8_USE_UNSAFE_HANDLES | 5293 #ifndef V8_USE_UNSAFE_HANDLES |
5279 val_ = 0; | 5294 val_ = 0; |
5280 #endif | 5295 #endif |
5281 } | 5296 } |
5282 | 5297 |
5283 | 5298 |
5284 template <class T> | 5299 template <class T> |
5285 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) { | 5300 template <typename S, typename P> |
5286 Isolate* isolate = Isolate::GetCurrent(); | 5301 void Persistent<T>::MakeWeak( |
| 5302 Isolate* isolate, |
| 5303 P* parameters, |
| 5304 typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| 5305 TYPE_CHECK(S, T); |
| 5306 typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; |
5287 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), | 5307 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
5288 reinterpret_cast<internal::Object**>(this->val_), | 5308 reinterpret_cast<internal::Object**>(this->val_), |
5289 parameters, | 5309 parameters, |
5290 callback, | 5310 reinterpret_cast<Revivable>(callback), |
5291 NULL); | 5311 NULL); |
5292 } | 5312 } |
5293 | 5313 |
| 5314 |
| 5315 template <class T> |
| 5316 template <typename P> |
| 5317 void Persistent<T>::MakeWeak( |
| 5318 Isolate* isolate, |
| 5319 P* parameters, |
| 5320 typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
| 5321 MakeWeak<T, P>(isolate, parameters, callback); |
| 5322 } |
| 5323 |
| 5324 |
5294 template <class T> | 5325 template <class T> |
5295 void Persistent<T>::MakeWeak(Isolate* isolate, | 5326 void Persistent<T>::MakeWeak(Isolate* isolate, |
5296 void* parameters, | 5327 void* parameters, |
5297 NearDeathCallback callback) { | 5328 NearDeathCallback callback) { |
5298 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), | 5329 V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
5299 reinterpret_cast<internal::Object**>(this->val_), | 5330 reinterpret_cast<internal::Object**>(this->val_), |
5300 parameters, | 5331 parameters, |
5301 NULL, | 5332 NULL, |
5302 callback); | 5333 callback); |
5303 } | 5334 } |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5912 | 5943 |
5913 | 5944 |
5914 } // namespace v8 | 5945 } // namespace v8 |
5915 | 5946 |
5916 | 5947 |
5917 #undef V8EXPORT | 5948 #undef V8EXPORT |
5918 #undef TYPE_CHECK | 5949 #undef TYPE_CHECK |
5919 | 5950 |
5920 | 5951 |
5921 #endif // V8_H_ | 5952 #endif // V8_H_ |
OLD | NEW |