| 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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 } | 353 } |
| 354 | 354 |
| 355 private: | 355 private: |
| 356 T* val_; | 356 T* val_; |
| 357 }; | 357 }; |
| 358 | 358 |
| 359 | 359 |
| 360 // Eternal handles are set-once handles that live for the life of the isolate. | 360 // Eternal handles are set-once handles that live for the life of the isolate. |
| 361 template <class T> class Eternal { | 361 template <class T> class Eternal { |
| 362 public: | 362 public: |
| 363 V8_INLINE Eternal() : index_(kInitialValue) { } | 363 V8_INLINE Eternal() : val_(nullptr) {} |
| 364 template<class S> | 364 template <class S> |
| 365 V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : index_(kInitialValue) { | 365 V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) { |
| 366 Set(isolate, handle); | 366 Set(isolate, handle); |
| 367 } | 367 } |
| 368 // Can only be safely called if already set. | 368 // Can only be safely called if already set. |
| 369 V8_INLINE Local<T> Get(Isolate* isolate) const; | 369 V8_INLINE Local<T> Get(Isolate* isolate) const; |
| 370 V8_INLINE bool IsEmpty() const { return index_ == kInitialValue; } | 370 V8_INLINE bool IsEmpty() const { return val_ == nullptr; } |
| 371 template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle); | 371 template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle); |
| 372 | 372 |
| 373 private: | 373 private: |
| 374 static const int kInitialValue = -1; | 374 T* val_; |
| 375 int index_; | |
| 376 }; | 375 }; |
| 377 | 376 |
| 378 | 377 |
| 379 static const int kInternalFieldsInWeakCallback = 2; | 378 static const int kInternalFieldsInWeakCallback = 2; |
| 380 static const int kEmbedderFieldsInWeakCallback = 2; | 379 static const int kEmbedderFieldsInWeakCallback = 2; |
| 381 | 380 |
| 382 template <typename T> | 381 template <typename T> |
| 383 class WeakCallbackInfo { | 382 class WeakCallbackInfo { |
| 384 public: | 383 public: |
| 385 typedef void (*Callback)(const WeakCallbackInfo<T>& data); | 384 typedef void (*Callback)(const WeakCallbackInfo<T>& data); |
| (...skipping 7280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7666 WeakCallbackInfo<void>::Callback weak_callback, | 7665 WeakCallbackInfo<void>::Callback weak_callback, |
| 7667 WeakCallbackType type); | 7666 WeakCallbackType type); |
| 7668 static void MakeWeak(internal::Object** location, void* data, | 7667 static void MakeWeak(internal::Object** location, void* data, |
| 7669 // Must be 0 or -1. | 7668 // Must be 0 or -1. |
| 7670 int internal_field_index1, | 7669 int internal_field_index1, |
| 7671 // Must be 1 or -1. | 7670 // Must be 1 or -1. |
| 7672 int internal_field_index2, | 7671 int internal_field_index2, |
| 7673 WeakCallbackInfo<void>::Callback weak_callback); | 7672 WeakCallbackInfo<void>::Callback weak_callback); |
| 7674 static void MakeWeak(internal::Object*** location_addr); | 7673 static void MakeWeak(internal::Object*** location_addr); |
| 7675 static void* ClearWeak(internal::Object** location); | 7674 static void* ClearWeak(internal::Object** location); |
| 7676 static void Eternalize(Isolate* isolate, | 7675 static Value* Eternalize(Isolate* isolate, Value* handle); |
| 7677 Value* handle, | |
| 7678 int* index); | |
| 7679 static Local<Value> GetEternal(Isolate* isolate, int index); | |
| 7680 | 7676 |
| 7681 static void RegisterExternallyReferencedObject(internal::Object** object, | 7677 static void RegisterExternallyReferencedObject(internal::Object** object, |
| 7682 internal::Isolate* isolate); | 7678 internal::Isolate* isolate); |
| 7683 | 7679 |
| 7684 template <class K, class V, class T> | 7680 template <class K, class V, class T> |
| 7685 friend class PersistentValueMapBase; | 7681 friend class PersistentValueMapBase; |
| 7686 | 7682 |
| 7687 static void FromJustIsNothing(); | 7683 static void FromJustIsNothing(); |
| 7688 static void ToLocalEmpty(); | 7684 static void ToLocalEmpty(); |
| 7689 static void InternalFieldOutOfBounds(int index); | 7685 static void InternalFieldOutOfBounds(int index); |
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8634 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | 8630 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 8635 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | 8631 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 8636 reinterpret_cast<internal::Isolate*>(isolate), *p))); | 8632 reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 8637 } | 8633 } |
| 8638 | 8634 |
| 8639 | 8635 |
| 8640 template<class T> | 8636 template<class T> |
| 8641 template<class S> | 8637 template<class S> |
| 8642 void Eternal<T>::Set(Isolate* isolate, Local<S> handle) { | 8638 void Eternal<T>::Set(Isolate* isolate, Local<S> handle) { |
| 8643 TYPE_CHECK(T, S); | 8639 TYPE_CHECK(T, S); |
| 8644 V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle), &this->index_); | 8640 val_ = reinterpret_cast<T*>( |
| 8641 V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle))); |
| 8645 } | 8642 } |
| 8646 | 8643 |
| 8647 template <class T> | 8644 template <class T> |
| 8648 Local<T> Eternal<T>::Get(Isolate* isolate) const { | 8645 Local<T> Eternal<T>::Get(Isolate* isolate) const { |
| 8649 return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_))); | 8646 // The eternal handle will never go away, so as with the roots, we don't even |
| 8647 // need to open a handle. |
| 8648 return Local<T>(val_); |
| 8650 } | 8649 } |
| 8651 | 8650 |
| 8652 | 8651 |
| 8653 template <class T> | 8652 template <class T> |
| 8654 Local<T> MaybeLocal<T>::ToLocalChecked() { | 8653 Local<T> MaybeLocal<T>::ToLocalChecked() { |
| 8655 if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty(); | 8654 if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty(); |
| 8656 return Local<T>(val_); | 8655 return Local<T>(val_); |
| 8657 } | 8656 } |
| 8658 | 8657 |
| 8659 | 8658 |
| (...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9837 */ | 9836 */ |
| 9838 | 9837 |
| 9839 | 9838 |
| 9840 } // namespace v8 | 9839 } // namespace v8 |
| 9841 | 9840 |
| 9842 | 9841 |
| 9843 #undef TYPE_CHECK | 9842 #undef TYPE_CHECK |
| 9844 | 9843 |
| 9845 | 9844 |
| 9846 #endif // INCLUDE_V8_H_ | 9845 #endif // INCLUDE_V8_H_ |
| OLD | NEW |