Index: include/v8.h |
diff --git a/include/v8.h b/include/v8.h |
index fe38d236a481af4e003809437cf3ee1689eff72a..2f3c77600745b4b20482617f32995d3b20569557 100644 |
--- a/include/v8.h |
+++ b/include/v8.h |
@@ -360,19 +360,18 @@ class MaybeLocal { |
// Eternal handles are set-once handles that live for the life of the isolate. |
template <class T> class Eternal { |
public: |
- V8_INLINE Eternal() : index_(kInitialValue) { } |
- template<class S> |
- V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : index_(kInitialValue) { |
+ V8_INLINE Eternal() : val_(nullptr) {} |
+ template <class S> |
+ V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) { |
Set(isolate, handle); |
} |
// Can only be safely called if already set. |
V8_INLINE Local<T> Get(Isolate* isolate) const; |
- V8_INLINE bool IsEmpty() const { return index_ == kInitialValue; } |
+ V8_INLINE bool IsEmpty() const { return val_ == nullptr; } |
template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle); |
private: |
- static const int kInitialValue = -1; |
- int index_; |
+ T* val_; |
}; |
@@ -7673,10 +7672,7 @@ class V8_EXPORT V8 { |
WeakCallbackInfo<void>::Callback weak_callback); |
static void MakeWeak(internal::Object*** location_addr); |
static void* ClearWeak(internal::Object** location); |
- static void Eternalize(Isolate* isolate, |
- Value* handle, |
- int* index); |
- static Local<Value> GetEternal(Isolate* isolate, int index); |
+ static Value* Eternalize(Isolate* isolate, Value* handle); |
static void RegisterExternallyReferencedObject(internal::Object** object, |
internal::Isolate* isolate); |
@@ -8641,12 +8637,15 @@ template<class T> |
template<class S> |
void Eternal<T>::Set(Isolate* isolate, Local<S> handle) { |
TYPE_CHECK(T, S); |
- V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle), &this->index_); |
+ val_ = reinterpret_cast<T*>( |
+ V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle))); |
} |
template <class T> |
Local<T> Eternal<T>::Get(Isolate* isolate) const { |
- return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_))); |
+ // The eternal handle will never go away, so as with the roots, we don't even |
+ // need to open a handle. |
+ return Local<T>(val_); |
} |