Skip to content

Commit 385499c

Browse files
jeremyromanjasnell
authored andcommitted
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<T> can point directly at the eternal reference. This makes Eternal<T>::Get trivial. Review-Url: https://codereview.chromium.org/2751263003 Cr-Commit-Position: refs/heads/master@{#43912} Ref: v8/v8@4acdb5eec2c PR-URL: #12875 Reviewed-By: James M Snell <[email protected]>
1 parent 69161b5 commit 385499c

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

deps/v8/include/v8.h

+11-12
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,18 @@ class MaybeLocal {
360360
// Eternal handles are set-once handles that live for the life of the isolate.
361361
template <class T> class Eternal {
362362
public:
363-
V8_INLINE Eternal() : index_(kInitialValue) { }
364-
template<class S>
365-
V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : index_(kInitialValue) {
363+
V8_INLINE Eternal() : val_(nullptr) {}
364+
template <class S>
365+
V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
366366
Set(isolate, handle);
367367
}
368368
// Can only be safely called if already set.
369369
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; }
371371
template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
372372

373373
private:
374-
static const int kInitialValue = -1;
375-
int index_;
374+
T* val_;
376375
};
377376

378377

@@ -7628,10 +7627,7 @@ class V8_EXPORT V8 {
76287627
WeakCallbackInfo<void>::Callback weak_callback);
76297628
static void MakeWeak(internal::Object*** location_addr);
76307629
static void* ClearWeak(internal::Object** location);
7631-
static void Eternalize(Isolate* isolate,
7632-
Value* handle,
7633-
int* index);
7634-
static Local<Value> GetEternal(Isolate* isolate, int index);
7630+
static Value* Eternalize(Isolate* isolate, Value* handle);
76357631

76367632
static void RegisterExternallyReferencedObject(internal::Object** object,
76377633
internal::Isolate* isolate);
@@ -8601,12 +8597,15 @@ template<class T>
86018597
template<class S>
86028598
void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
86038599
TYPE_CHECK(T, S);
8604-
V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle), &this->index_);
8600+
val_ = reinterpret_cast<T*>(
8601+
V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle)));
86058602
}
86068603

86078604
template <class T>
86088605
Local<T> Eternal<T>::Get(Isolate* isolate) const {
8609-
return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_)));
8606+
// The eternal handle will never go away, so as with the roots, we don't even
8607+
// need to open a handle.
8608+
return Local<T>(val_);
86108609
}
86118610

86128611

deps/v8/src/api.cc

+5-9
Original file line numberDiff line numberDiff line change
@@ -936,17 +936,13 @@ void V8::DisposeGlobal(i::Object** location) {
936936
i::GlobalHandles::Destroy(location);
937937
}
938938

939-
940-
void V8::Eternalize(Isolate* v8_isolate, Value* value, int* index) {
939+
Value* V8::Eternalize(Isolate* v8_isolate, Value* value) {
941940
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
942941
i::Object* object = *Utils::OpenHandle(value);
943-
isolate->eternal_handles()->Create(isolate, object, index);
944-
}
945-
946-
947-
Local<Value> V8::GetEternal(Isolate* v8_isolate, int index) {
948-
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
949-
return Utils::ToLocal(isolate->eternal_handles()->Get(index));
942+
int index = -1;
943+
isolate->eternal_handles()->Create(isolate, object, &index);
944+
return reinterpret_cast<Value*>(
945+
isolate->eternal_handles()->Get(index).location());
950946
}
951947

952948

0 commit comments

Comments
 (0)