fix: crash in gin::wrappable::secondweakcallback (#45368)

This commit is contained in:
Robo 2025-01-30 03:20:37 +09:00 committed by GitHub
parent 8cf2e46c1f
commit ecd5d0a3a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 233 additions and 6 deletions

View file

@ -4,6 +4,7 @@
#include "shell/common/gin_helper/wrappable.h"
#include "gin/public/isolate_holder.h"
#include "shell/common/gin_helper/dictionary.h"
#include "v8/include/v8-function.h"
@ -60,8 +61,10 @@ void WrappableBase::InitWith(v8::Isolate* isolate,
// static
void WrappableBase::FirstWeakCallback(
const v8::WeakCallbackInfo<WrappableBase>& data) {
auto* wrappable = static_cast<WrappableBase*>(data.GetInternalField(0));
if (wrappable) {
WrappableBase* wrappable = data.GetParameter();
auto* wrappable_from_field =
static_cast<WrappableBase*>(data.GetInternalField(0));
if (wrappable && wrappable == wrappable_from_field) {
wrappable->wrapper_.Reset();
data.SetSecondPassCallback(SecondWeakCallback);
}
@ -70,6 +73,9 @@ void WrappableBase::FirstWeakCallback(
// static
void WrappableBase::SecondWeakCallback(
const v8::WeakCallbackInfo<WrappableBase>& data) {
if (gin::IsolateHolder::DestroyedMicrotasksRunner()) {
return;
}
delete static_cast<WrappableBase*>(data.GetInternalField(0));
}