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 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 * was previously assigned. | 688 * was previously assigned. |
689 */ | 689 */ |
690 // TODO(dcarney): remove before cutover | 690 // TODO(dcarney): remove before cutover |
691 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); | 691 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); |
692 | 692 |
693 /** | 693 /** |
694 * Disposes the current contents of the handle and replaces it. | 694 * Disposes the current contents of the handle and replaces it. |
695 */ | 695 */ |
696 V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); | 696 V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); |
697 | 697 |
| 698 /** |
| 699 * Returns the underlying raw pointer and clears the handle. The caller is |
| 700 * responsible of eventually destroying the underlying object (by creating a |
| 701 * Persistent handle which points to it and Disposing it). In the future, |
| 702 * destructing a Persistent will also Dispose it. With this function, the |
| 703 * embedder can let the Persistent go out of scope without it getting |
| 704 * disposed. |
| 705 */ |
| 706 V8_INLINE(T* ClearAndLeak()); |
| 707 |
698 #ifndef V8_USE_UNSAFE_HANDLES | 708 #ifndef V8_USE_UNSAFE_HANDLES |
699 | 709 |
700 #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT | 710 #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
701 | 711 |
702 private: | 712 private: |
703 #endif | 713 #endif |
704 // TODO(dcarney): make unlinkable before cutover | 714 // TODO(dcarney): make unlinkable before cutover |
705 V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} | 715 V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} |
706 // TODO(dcarney): make unlinkable before cutover | 716 // TODO(dcarney): make unlinkable before cutover |
707 V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT | 717 V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT |
(...skipping 4669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5377 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | 5387 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
5378 true, | 5388 true, |
5379 I::kNodeIsPartiallyDependentShift); | 5389 I::kNodeIsPartiallyDependentShift); |
5380 } | 5390 } |
5381 | 5391 |
5382 template <class T> | 5392 template <class T> |
5383 void Persistent<T>::SetWrapperClassId(uint16_t class_id) { | 5393 void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
5384 SetWrapperClassId(Isolate::GetCurrent(), class_id); | 5394 SetWrapperClassId(Isolate::GetCurrent(), class_id); |
5385 } | 5395 } |
5386 | 5396 |
| 5397 |
5387 template <class T> | 5398 template <class T> |
5388 void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) { | 5399 void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) { |
5389 Dispose(isolate); | 5400 Dispose(isolate); |
5390 #ifdef V8_USE_UNSAFE_HANDLES | 5401 #ifdef V8_USE_UNSAFE_HANDLES |
5391 *this = *New(isolate, other); | 5402 *this = *New(isolate, other); |
5392 #else | 5403 #else |
5393 if (other.IsEmpty()) { | 5404 if (other.IsEmpty()) { |
5394 this->val_ = NULL; | 5405 this->val_ = NULL; |
5395 return; | 5406 return; |
5396 } | 5407 } |
5397 internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); | 5408 internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
5398 this->val_ = reinterpret_cast<T*>( | 5409 this->val_ = reinterpret_cast<T*>( |
5399 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); | 5410 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
5400 #endif | 5411 #endif |
5401 } | 5412 } |
5402 | 5413 |
| 5414 |
| 5415 template <class T> |
| 5416 T* Persistent<T>::ClearAndLeak() { |
| 5417 T* old; |
| 5418 #ifdef V8_USE_UNSAFE_HANDLES |
| 5419 old = **this; |
| 5420 *this = Persistent<T>(); |
| 5421 #else |
| 5422 old = val_; |
| 5423 val_ = NULL; |
| 5424 #endif |
| 5425 return old; |
| 5426 } |
| 5427 |
| 5428 |
5403 template <class T> | 5429 template <class T> |
5404 void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { | 5430 void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { |
5405 typedef internal::Internals I; | 5431 typedef internal::Internals I; |
5406 if (this->IsEmpty()) return; | 5432 if (this->IsEmpty()) return; |
5407 if (!I::IsInitialized(isolate)) return; | 5433 if (!I::IsInitialized(isolate)) return; |
5408 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); | 5434 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
5409 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | 5435 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
5410 *reinterpret_cast<uint16_t*>(addr) = class_id; | 5436 *reinterpret_cast<uint16_t*>(addr) = class_id; |
5411 } | 5437 } |
5412 | 5438 |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5964 | 5990 |
5965 | 5991 |
5966 } // namespace v8 | 5992 } // namespace v8 |
5967 | 5993 |
5968 | 5994 |
5969 #undef V8EXPORT | 5995 #undef V8EXPORT |
5970 #undef TYPE_CHECK | 5996 #undef TYPE_CHECK |
5971 | 5997 |
5972 | 5998 |
5973 #endif // V8_H_ | 5999 #endif // V8_H_ |
OLD | NEW |