From 28e0a12c78137e98f385548d6c3bf94ef08a29e7 Mon Sep 17 00:00:00 2001 From: jbroman Date: Fri, 17 Mar 2017 10:23:34 -0700 Subject: [PATCH] deps: backport 4acdb5eec2c from upstream v8 Original commit message: Give v8::Eternal a direct reference to the handle. This makes it more similar to other handle types (like PersistentBase), by simply storing an i::Object** cast to T*. This means that it is not necessary to look up the handle in the eternal handles table to access the underlying value. Like the built-in roots (null, etc.), an eternal handle can never be destroyed, so we don't even need to allocate a separate local handle. Instead, the Local can point directly at the eternal reference. This makes Eternal::Get trivial. Review-Url: https://codereview.chromium.org/2751263003 Cr-Commit-Position: refs/heads/master@{#43912} Ref: https://github.com/v8/v8/commit/4acdb5eec2c PR-URL: https://github.com/nodejs/node/pull/12875 Reviewed-By: James M Snell --- deps/v8/include/v8.h | 23 +++++++++++------------ deps/v8/src/api.cc | 14 +++++--------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index 8de9b2af0fb4dc..5402402eb750ba 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/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 Eternal { public: - V8_INLINE Eternal() : index_(kInitialValue) { } - template - V8_INLINE Eternal(Isolate* isolate, Local handle) : index_(kInitialValue) { + V8_INLINE Eternal() : val_(nullptr) {} + template + V8_INLINE Eternal(Isolate* isolate, Local handle) : val_(nullptr) { Set(isolate, handle); } // Can only be safely called if already set. V8_INLINE Local Get(Isolate* isolate) const; - V8_INLINE bool IsEmpty() const { return index_ == kInitialValue; } + V8_INLINE bool IsEmpty() const { return val_ == nullptr; } template V8_INLINE void Set(Isolate* isolate, Local handle); private: - static const int kInitialValue = -1; - int index_; + T* val_; }; @@ -7628,10 +7627,7 @@ class V8_EXPORT V8 { WeakCallbackInfo::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 GetEternal(Isolate* isolate, int index); + static Value* Eternalize(Isolate* isolate, Value* handle); static void RegisterExternallyReferencedObject(internal::Object** object, internal::Isolate* isolate); @@ -8596,12 +8592,15 @@ template template void Eternal::Set(Isolate* isolate, Local handle) { TYPE_CHECK(T, S); - V8::Eternalize(isolate, reinterpret_cast(*handle), &this->index_); + val_ = reinterpret_cast( + V8::Eternalize(isolate, reinterpret_cast(*handle))); } template Local Eternal::Get(Isolate* isolate) const { - return Local(reinterpret_cast(*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(val_); } diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index 450f2b87a06534..0309a932b90dda 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -936,17 +936,13 @@ void V8::DisposeGlobal(i::Object** location) { i::GlobalHandles::Destroy(location); } - -void V8::Eternalize(Isolate* v8_isolate, Value* value, int* index) { +Value* V8::Eternalize(Isolate* v8_isolate, Value* value) { i::Isolate* isolate = reinterpret_cast(v8_isolate); i::Object* object = *Utils::OpenHandle(value); - isolate->eternal_handles()->Create(isolate, object, index); -} - - -Local V8::GetEternal(Isolate* v8_isolate, int index) { - i::Isolate* isolate = reinterpret_cast(v8_isolate); - return Utils::ToLocal(isolate->eternal_handles()->Get(index)); + int index = -1; + isolate->eternal_handles()->Create(isolate, object, &index); + return reinterpret_cast( + isolate->eternal_handles()->Get(index).location()); }