Skip to content

Commit

Permalink
Merge branch 'Tencent:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnoChenFx authored Feb 2, 2024
2 parents 8220729 + 3500dff commit b0b6c64
Showing 1 changed file with 66 additions and 18 deletions.
84 changes: 66 additions & 18 deletions unreal/Puerts/Source/JsEnv/Private/JsEnvImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2353,39 +2353,87 @@ bool FJsEnvImpl::AddToDelegate(

auto JsCallbacks = Iter->second.JsCallbacks.Get(Isolate);

bool bSingleDelegate = Iter->second.DelegateProperty != nullptr;
(void) (JsCallbacks->Set(Context, bSingleDelegate ? 0 : JsCallbacks->Length(), JsFunction)); // push

UDynamicDelegateProxy* DelegateProxy = nullptr;
bool InitApplyFunc = false;
if (Iter->second.Proxy.IsValid())
{
return true;
DelegateProxy = Iter->second.Proxy.Get();
if (Iter->second.DelegateProperty)
{
if (!static_cast<FScriptDelegate*>(DelegatePtr)->IsBoundToObject(DelegateProxy))
{
InitApplyFunc = true;
}
}
else if (Iter->second.MulticastDelegateProperty)
{
#if ENGINE_MINOR_VERSION >= 23 || ENGINE_MAJOR_VERSION > 4
if (Iter->second.MulticastDelegateProperty->IsA<MulticastSparseDelegatePropertyMacro>())
{
if (!FSparseDelegateStorage::Contains(
Iter->second.Owner.Get(), Iter->second.MulticastDelegateProperty->GetFName(), DelegateProxy, NAME_Fire))
{
InitApplyFunc = true;
}
}
else
{
#endif
if (!static_cast<FMulticastScriptDelegate*>(DelegatePtr)->Contains(DelegateProxy, NAME_Fire))
{
InitApplyFunc = true;
}
}
}
if (InitApplyFunc)
{
if (JsCallbacks->Length() > 0)
{
JsCallbacks = v8::Array::New(Isolate);
Iter->second.JsCallbacks.Reset(Isolate, JsCallbacks);
}
else
{
InitApplyFunc = false;
}
}
}

UDynamicDelegateProxy* DelegateProxy = NewObject<UDynamicDelegateProxy>();
else
{
DelegateProxy = NewObject<UDynamicDelegateProxy>();

#ifdef THREAD_SAFE
DelegateProxy->Isolate = Isolate;
DelegateProxy->Isolate = Isolate;
#endif
DelegateProxy->Owner = Iter->second.Owner;
DelegateProxy->SignatureFunction = Iter->second.SignatureFunction;
DelegateProxy->DynamicInvoker = DynamicInvoker;
DelegateProxy->Owner = Iter->second.Owner;
DelegateProxy->SignatureFunction = Iter->second.SignatureFunction;
DelegateProxy->DynamicInvoker = DynamicInvoker;

InitApplyFunc = true;

v8::Local<v8::Value> Args[] = {JsCallbacks};
SysObjectRetainer.Retain(DelegateProxy);
Iter->second.Proxy = DelegateProxy;
}

v8::Local<v8::Value> Apply;
if (!GenListApply.Get(Isolate)->Call(Context, v8::Undefined(Isolate), 1, Args).ToLocal(&Apply) || !Apply->IsFunction())
if (InitApplyFunc)
{
Logger->Error("gen callback apply fail!");
return false;
v8::Local<v8::Value> Args[] = {JsCallbacks};

v8::Local<v8::Value> Apply;
if (!GenListApply.Get(Isolate)->Call(Context, v8::Undefined(Isolate), 1, Args).ToLocal(&Apply) || !Apply->IsFunction())
{
Logger->Error("gen callback apply fail!");
return false;
}
DelegateProxy->JsFunction = v8::UniquePersistent<v8::Function>(Isolate, v8::Local<v8::Function>::Cast(Apply));
}
DelegateProxy->JsFunction = v8::UniquePersistent<v8::Function>(Isolate, v8::Local<v8::Function>::Cast(Apply));

SysObjectRetainer.Retain(DelegateProxy);
bool bSingleDelegate = Iter->second.DelegateProperty != nullptr;
(void) (JsCallbacks->Set(Context, bSingleDelegate ? 0 : JsCallbacks->Length(), JsFunction)); // push

FScriptDelegate Delegate;
Delegate.BindUFunction(DelegateProxy, NAME_Fire);

Iter->second.Proxy = DelegateProxy;
if (Iter->second.DelegateProperty)
{
// UE_LOG(LogTemp, Warning, TEXT("bind to delegate"));
Expand Down

0 comments on commit b0b6c64

Please sign in to comment.