Hi, 

I'm updating v8 from v10.2.154.26 to v 12.4.254.
I found out kFinalizer is deprecated in the newer version so I have to 
rework the weakcall back part in my implementation.
When I simply change the kFinalizer in to kParameter in my SetWeak call, 
the program crashes when I calles SetAlignedPointerInInternalField in the 
destructor of my class under certain circumstance.
I'm wondering what's the correct way to use internal field, and the reason 
why it's crashing if I change WeakCallbackType from kFinalizer to 
kParameter.

The following is some code segment of my implementation.

class A {
    v8::Persistent<v8::Object> mObject;
}

A::~A ()
{
    if ( !mObject.IsEmpty() )
        mObject.ClearWeak();
    mObject.Reset();
}

void
A::Wrap (v8::Local<v8::Object> const &object)
{
    object->SetAlignedPointerInInternalField(0, this);
    mObject.Reset(v8::Isolate::GetCurrent(), object);
}

B::B() :A() {}

B::~B()
{
    if (!mObject.IsEmpty() && GetRuntime()->IsValid())
    {
        v8::Local<v8::Object> obj = 
v8::Local<v8::Object>::New(v8::Isolate::GetCurrent(), mObject);
        obj->SetAlignedPointerInInternalField(0, NULL); // Crashes here, 
seems obj is already collected, Is this needed to prevent dangling pointer?
    }
}

C::C()
    :B()
{
    v8::Local<v8::Object> target =
    Initialize()->GetFunction(ctx).ToLocalChecked()
                ->NewInstance(ctx).ToLocalChecked();
    
    Wrap(target);
    mObject.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter); 
// Was kFinalizer in previous version, no crash.
}

C::~C()
{
    mObject.ClearWeak();
}

void
B::WeakCallback(const v8::WeakCallbackInfo<C>& data)
{
    C* self = data.GetParameter();
    self->EarlyComplete();
    delete self;
}

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/v8-users/77f84ccf-b1ba-4967-81ab-89a312be8af3n%40googlegroups.com.

Reply via email to