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
This commit is contained in:
Keeley Hammond
2026-01-27 17:33:35 -08:00
parent f9baafbebc
commit 096c1b7aa9
2 changed files with 8 additions and 3 deletions

View File

@@ -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);

View File

@@ -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<ReturnType(ArgTypes...)> {
static void DispatchToCallbackImpl(gin::Arguments* args) {
v8::Local<v8::External> v8_holder;
CHECK(args->GetData(&v8_holder));
CallbackHolderBase* holder_base =
reinterpret_cast<CallbackHolderBase*>(v8_holder->Value());
CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>(
v8_holder->Value(gin::kGinInternalCallbackHolderBaseTag));
typedef CallbackHolder<ReturnType(ArgTypes...)> HolderT;
HolderT* holder = static_cast<HolderT*>(holder_base);