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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 | 363 |
364 private: | 364 private: |
365 #endif | 365 #endif |
366 /** | 366 /** |
367 * Creates a new handle for the specified value. | 367 * Creates a new handle for the specified value. |
368 */ | 368 */ |
369 V8_INLINE(explicit Handle(T* val)) : val_(val) {} | 369 V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
370 #endif | 370 #endif |
371 | 371 |
372 private: | 372 private: |
373 template<class F> | 373 template<class F> friend class Persistent; |
374 friend class Persistent; | 374 template<class F> friend class Local; |
375 template<class F> | |
376 friend class Local; | |
377 friend class Arguments; | 375 friend class Arguments; |
| 376 template<class F> friend class FunctionCallbackInfo; |
| 377 template<class F> friend class PropertyCallbackInfo; |
378 friend class String; | 378 friend class String; |
379 friend class Object; | 379 friend class Object; |
380 friend class AccessorInfo; | 380 friend class AccessorInfo; |
381 friend Handle<Primitive> Undefined(Isolate* isolate); | 381 friend Handle<Primitive> Undefined(Isolate* isolate); |
382 friend Handle<Primitive> Null(Isolate* isolate); | 382 friend Handle<Primitive> Null(Isolate* isolate); |
383 friend Handle<Boolean> True(Isolate* isolate); | 383 friend Handle<Boolean> True(Isolate* isolate); |
384 friend Handle<Boolean> False(Isolate* isolate); | 384 friend Handle<Boolean> False(Isolate* isolate); |
385 friend class Context; | 385 friend class Context; |
386 friend class InternalHandleHelper; | 386 friend class InternalHandleHelper; |
387 friend class LocalContext; | 387 friend class LocalContext; |
| 388 friend class HandleScope; |
388 | 389 |
389 #ifndef V8_USE_UNSAFE_HANDLES | 390 #ifndef V8_USE_UNSAFE_HANDLES |
390 V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); | 391 V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); |
391 #endif | 392 #endif |
392 | 393 |
393 T* val_; | 394 T* val_; |
394 }; | 395 }; |
395 | 396 |
396 | 397 |
397 /** | 398 /** |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); | 452 V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); |
452 | 453 |
453 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | 454 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
454 | 455 |
455 private: | 456 private: |
456 #endif | 457 #endif |
457 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } | 458 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
458 #endif | 459 #endif |
459 | 460 |
460 private: | 461 private: |
461 template<class F> | 462 template<class F> friend class Persistent; |
462 friend class Persistent; | 463 template<class F> friend class Handle; |
463 template<class F> | |
464 friend class Handle; | |
465 friend class Arguments; | 464 friend class Arguments; |
| 465 template<class F> friend class FunctionCallbackInfo; |
| 466 template<class F> friend class PropertyCallbackInfo; |
466 friend class String; | 467 friend class String; |
467 friend class Object; | 468 friend class Object; |
468 friend class AccessorInfo; | 469 friend class AccessorInfo; |
469 friend class Context; | 470 friend class Context; |
470 friend class InternalHandleHelper; | 471 friend class InternalHandleHelper; |
471 friend class LocalContext; | 472 friend class LocalContext; |
| 473 friend class HandleScope; |
472 | 474 |
473 V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); | 475 V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); |
474 }; | 476 }; |
475 | 477 |
476 /** | 478 /** |
477 * An object reference that is independent of any handle scope. Where | 479 * An object reference that is independent of any handle scope. Where |
478 * a Local handle only lives as long as the HandleScope in which it was | 480 * a Local handle only lives as long as the HandleScope in which it was |
479 * allocated, a Persistent handle remains valid until it is explicitly | 481 * allocated, a Persistent handle remains valid until it is explicitly |
480 * disposed. | 482 * disposed. |
481 * | 483 * |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 // TODO(dcarney): deprecate | 746 // TODO(dcarney): deprecate |
745 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const) { | 747 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const) { |
746 return WrapperClassId(); | 748 return WrapperClassId(); |
747 } | 749 } |
748 | 750 |
749 /** | 751 /** |
750 * Disposes the current contents of the handle and replaces it. | 752 * Disposes the current contents of the handle and replaces it. |
751 */ | 753 */ |
752 V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); | 754 V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); |
753 | 755 |
| 756 #ifndef V8_USE_UNSAFE_HANDLES |
| 757 V8_INLINE(void Reset(Isolate* isolate, const Persistent<T>& other)); |
| 758 #endif |
| 759 |
754 /** | 760 /** |
755 * Returns the underlying raw pointer and clears the handle. The caller is | 761 * Returns the underlying raw pointer and clears the handle. The caller is |
756 * responsible of eventually destroying the underlying object (by creating a | 762 * responsible of eventually destroying the underlying object (by creating a |
757 * Persistent handle which points to it and Disposing it). In the future, | 763 * Persistent handle which points to it and Disposing it). In the future, |
758 * destructing a Persistent will also Dispose it. With this function, the | 764 * destructing a Persistent will also Dispose it. With this function, the |
759 * embedder can let the Persistent go out of scope without it getting | 765 * embedder can let the Persistent go out of scope without it getting |
760 * disposed. | 766 * disposed. |
761 */ | 767 */ |
762 V8_INLINE(T* ClearAndLeak()); | 768 V8_INLINE(T* ClearAndLeak()); |
763 | 769 |
(...skipping 29 matching lines...) Expand all Loading... |
793 #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW | 799 #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW |
794 | 800 |
795 private: | 801 private: |
796 #endif | 802 #endif |
797 // TODO(dcarney): remove before cutover | 803 // TODO(dcarney): remove before cutover |
798 V8_INLINE(T* operator->() const) { return val_; } | 804 V8_INLINE(T* operator->() const) { return val_; } |
799 public: | 805 public: |
800 #endif | 806 #endif |
801 | 807 |
802 private: | 808 private: |
803 template<class F> | 809 template<class F> friend class Handle; |
804 friend class Handle; | 810 template<class F> friend class Local; |
805 template<class F> | |
806 friend class Local; | |
807 friend class ImplementationUtilities; | 811 friend class ImplementationUtilities; |
808 friend class ObjectTemplate; | 812 friend class ObjectTemplate; |
809 friend class Context; | 813 friend class Context; |
810 friend class InternalHandleHelper; | 814 friend class InternalHandleHelper; |
811 friend class LocalContext; | 815 friend class LocalContext; |
812 | 816 |
813 V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); | 817 V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); |
814 | 818 |
815 #ifndef V8_USE_UNSAFE_HANDLES | 819 #ifndef V8_USE_UNSAFE_HANDLES |
816 T* val_; | 820 T* val_; |
(...skipping 4805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5622 this->val_ = NULL; | 5626 this->val_ = NULL; |
5623 return; | 5627 return; |
5624 } | 5628 } |
5625 internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); | 5629 internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
5626 this->val_ = reinterpret_cast<T*>( | 5630 this->val_ = reinterpret_cast<T*>( |
5627 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); | 5631 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
5628 #endif | 5632 #endif |
5629 } | 5633 } |
5630 | 5634 |
5631 | 5635 |
| 5636 #ifndef V8_USE_UNSAFE_HANDLES |
| 5637 template <class T> |
| 5638 void Persistent<T>::Reset(Isolate* isolate, const Persistent<T>& other) { |
| 5639 Dispose(isolate); |
| 5640 if (other.IsEmpty()) { |
| 5641 this->val_ = NULL; |
| 5642 return; |
| 5643 } |
| 5644 internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
| 5645 this->val_ = reinterpret_cast<T*>( |
| 5646 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
| 5647 } |
| 5648 #endif |
| 5649 |
| 5650 |
5632 template <class T> | 5651 template <class T> |
5633 T* Persistent<T>::ClearAndLeak() { | 5652 T* Persistent<T>::ClearAndLeak() { |
5634 T* old; | 5653 T* old; |
5635 #ifdef V8_USE_UNSAFE_HANDLES | 5654 #ifdef V8_USE_UNSAFE_HANDLES |
5636 old = **this; | 5655 old = **this; |
5637 *this = Persistent<T>(); | 5656 *this = Persistent<T>(); |
5638 #else | 5657 #else |
5639 old = val_; | 5658 old = val_; |
5640 val_ = NULL; | 5659 val_ = NULL; |
5641 #endif | 5660 #endif |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6308 | 6327 |
6309 | 6328 |
6310 } // namespace v8 | 6329 } // namespace v8 |
6311 | 6330 |
6312 | 6331 |
6313 #undef V8EXPORT | 6332 #undef V8EXPORT |
6314 #undef TYPE_CHECK | 6333 #undef TYPE_CHECK |
6315 | 6334 |
6316 | 6335 |
6317 #endif // V8_H_ | 6336 #endif // V8_H_ |
OLD | NEW |