33#include " Translator.h"
44#include " JavascriptStats.h"
55#include " UObject/GCObject.h"
6+ #include " ../../Launch/Resources/Version.h"
7+ #include " v8-version.h"
68
79PRAGMA_DISABLE_SHADOW_VARIABLE_WARNINGS
810
@@ -106,29 +108,31 @@ class FJavascriptDelegate : public FGCObject, public TSharedFromThis<FJavascript
106108 auto toJSON = [](const FunctionCallbackInfo<Value>& info) {
107109 auto payload = reinterpret_cast <FJavascriptDelegate*>(Local<External>::Cast (info.Data ())->Value ());
108110
109- uint32_t Index = 0 ;
110- auto arr = Array::New (info.GetIsolate (), payload->DelegateObjects .Num ());
111+ uint32_t Index = 0 ;
112+ auto isolate_ = info.GetIsolate ();
113+ auto context_ = isolate_->GetCurrentContext ();
114+ auto arr = Array::New (isolate_, payload->DelegateObjects .Num ());
111115 const bool bIsMulticastDelegate = payload->Property ->IsA (UMulticastDelegateProperty::StaticClass ());
112116
113117 for (auto DelegateObject : payload->DelegateObjects )
114118 {
115119 auto JavascriptFunction = payload->functions .Find (DelegateObject->UniqueId );
116120 if (JavascriptFunction)
117121 {
118- auto function = Local<Function>::New (info. GetIsolate () , *JavascriptFunction);
122+ auto function = Local<Function>::New (isolate_ , *JavascriptFunction);
119123 if (!bIsMulticastDelegate)
120124 {
121125 info.GetReturnValue ().Set (function);
122126 return ;
123127 }
124128
125- arr->Set (Index++, function);
129+ arr->Set (context_, Index++, function);
126130 }
127131 }
128132
129133 if (!bIsMulticastDelegate)
130134 {
131- info.GetReturnValue ().Set (Null (info. GetIsolate () ));
135+ info.GetReturnValue ().Set (Null (isolate_ ));
132136 }
133137 else
134138 {
@@ -224,8 +228,12 @@ class FJavascriptDelegate : public FGCObject, public TSharedFromThis<FJavascript
224228 FScriptDelegate Delegate;
225229 Delegate.BindUFunction (DelegateObject, NAME_Fire);
226230
231+ #if ENGINE_MINOR_VERSION > 22
232+ p->AddDelegate (Delegate, WeakObject.Get ());
233+ #else
227234 auto Target = p->GetPropertyValuePtr_InContainer (WeakObject.Get ());
228235 Target->Add (Delegate);
236+ #endif
229237 }
230238 else if (auto p = Cast<UDelegateProperty>(Property))
231239 {
@@ -250,9 +258,12 @@ class FJavascriptDelegate : public FGCObject, public TSharedFromThis<FJavascript
250258 {
251259 FScriptDelegate Delegate;
252260 Delegate.BindUFunction (DelegateObject, NAME_Fire);
253-
261+ #if ENGINE_MINOR_VERSION > 22
262+ p->RemoveDelegate (Delegate, WeakObject.Get ());
263+ #else
254264 auto Target = p->GetPropertyValuePtr_InContainer (WeakObject.Get ());
255265 Target->Remove (Delegate);
266+ #endif
256267 }
257268 else if (auto p = Cast<UDelegateProperty>(Property))
258269 {
@@ -374,17 +385,18 @@ struct FDelegateManager : IDelegateManager
374385 virtual Local<Value> GetProxy (Local<Object> This, UObject* Object, UProperty* Property) override
375386 {
376387 auto cache_id = V8_KeywordString (isolate_, FString::Printf (TEXT (" $internal_%s" ), *(Property->GetName ())));
377- auto cached = This->Get (cache_id);
378- if (cached.IsEmpty () || cached->IsUndefined ())
388+ auto context_ = isolate_->GetCurrentContext ();
389+ auto maybe_cached = This->Get (context_, cache_id);
390+ if (maybe_cached.IsEmpty () || maybe_cached.ToLocalChecked ()->IsUndefined ())
379391 {
380392 auto created = CreateDelegate (Object, Property);
381393
382- This->Set (cache_id, created);
394+ This->Set (context_, cache_id, created);
383395 return created;
384396 }
385397 else
386398 {
387- return cached ;
399+ return maybe_cached. ToLocalChecked () ;
388400 }
389401 }
390402};
0 commit comments