From 096c1b7aa9a9bde9b1af9a43dedeea7c2b5f2a48 Mon Sep 17 00:00:00 2001 From: Keeley Hammond Date: Tue, 27 Jan 2026 17:33:35 -0800 Subject: [PATCH] 7000847: add type tag to v8::External for gin_helper function templates The upstream gin function templates now use v8::ExternalPointerTypeTag for type safety when using v8::External. Updated Electron's forked gin_helper function template to use the same kGinInternalCallbackHolderBaseTag that Chromium's gin uses. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7000847 --- shell/common/gin_helper/function_template.cc | 6 +++++- shell/common/gin_helper/function_template.h | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/shell/common/gin_helper/function_template.cc b/shell/common/gin_helper/function_template.cc index 54019899bb..6c19caf4c5 100644 --- a/shell/common/gin_helper/function_template.cc +++ b/shell/common/gin_helper/function_template.cc @@ -5,6 +5,7 @@ #include "shell/common/gin_helper/function_template.h" #include "base/strings/strcat.h" +#include "gin/public/gin_embedders.h" namespace gin_helper { @@ -29,7 +30,10 @@ void CallbackHolderBase::DisposeObserver::OnDisposed() { } CallbackHolderBase::CallbackHolderBase(v8::Isolate* isolate) - : v8_ref_(isolate, v8::External::New(isolate, this)), + : v8_ref_(isolate, + v8::External::New(isolate, + this, + gin::kGinInternalCallbackHolderBaseTag)), dispose_observer_(gin::PerIsolateData::From(isolate), this) { v8_ref_.SetWeak(this, &CallbackHolderBase::FirstWeakCallback, v8::WeakCallbackType::kParameter); diff --git a/shell/common/gin_helper/function_template.h b/shell/common/gin_helper/function_template.h index c9d82747ce..1c4f5430b4 100644 --- a/shell/common/gin_helper/function_template.h +++ b/shell/common/gin_helper/function_template.h @@ -13,6 +13,7 @@ #include "base/memory/raw_ptr.h" #include "gin/arguments.h" #include "gin/per_isolate_data.h" +#include "gin/public/gin_embedders.h" #include "shell/common/gin_helper/destroyable.h" #include "shell/common/gin_helper/error_thrower.h" #include "v8/include/v8-context.h" @@ -289,8 +290,8 @@ struct Dispatcher { static void DispatchToCallbackImpl(gin::Arguments* args) { v8::Local v8_holder; CHECK(args->GetData(&v8_holder)); - CallbackHolderBase* holder_base = - reinterpret_cast(v8_holder->Value()); + CallbackHolderBase* holder_base = reinterpret_cast( + v8_holder->Value(gin::kGinInternalCallbackHolderBaseTag)); typedef CallbackHolder HolderT; HolderT* holder = static_cast(holder_base);