@@ -44,6 +44,11 @@ struct FPrivateJavascriptFunction
4444 UniquePersistent<Function> Function;
4545};
4646
47+ struct FPrivateJavascriptRef
48+ {
49+ UniquePersistent<Object> Object;
50+ };
51+
4752template <typename CppType>
4853struct TStructReader
4954{
@@ -759,6 +764,15 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
759764 func.Handle ->Function .Reset (isolate_, jsfunc);
760765 p->Struct ->CopyScriptStruct (struct_buffer, &func);
761766 }
767+ else if (Value->IsObject () && p->Struct ->IsChildOf (FJavascriptRef::StaticStruct ()))
768+ {
769+ auto struct_buffer = p->ContainerPtrToValuePtr <uint8>(Buffer);
770+ FJavascriptRef ref;
771+ auto jsobj= Value.As <Object>();
772+ ref.Handle = MakeShareable (new FPrivateJavascriptRef);
773+ ref.Handle ->Object .Reset (isolate_, jsobj);
774+ p->Struct ->CopyScriptStruct (struct_buffer, &ref);
775+ }
762776 // If raw javascript object has been passed,
763777 else if (Value->IsObject ())
764778 {
@@ -1781,6 +1795,31 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
17811795 Template->Set (I.Keyword (" C" ), I.FunctionTemplate (fn, StructToExport));
17821796 }
17831797
1798+ void AddMemberFunction_JavascriptRef_get (Local<FunctionTemplate> Template)
1799+ {
1800+ FIsolateHelper I (isolate_);
1801+
1802+ auto fn = [](const FunctionCallbackInfo<Value>& info) {
1803+ auto isolate = info.GetIsolate ();
1804+
1805+ auto self = info.This ();
1806+ auto out = Object::New (isolate);
1807+
1808+ auto Instance = FStructMemoryInstance::FromV8 (self);
1809+
1810+ if (Instance->GetMemory ())
1811+ {
1812+ auto Ref = reinterpret_cast <FJavascriptRef*>(Instance->GetMemory ());
1813+ FPrivateJavascriptRef* Handle = Ref->Handle .Get ();
1814+ auto object = Local<Object>::New (isolate, Handle->Object );
1815+
1816+ info.GetReturnValue ().Set (object);
1817+ }
1818+ };
1819+
1820+ Template->PrototypeTemplate ()->Set (I.Keyword (" get" ), I.FunctionTemplate (fn, nullptr ));
1821+ }
1822+
17841823 void AddMemberFunction_Struct_clone (Local<FunctionTemplate> Template, UStruct* StructToExport)
17851824 {
17861825 FIsolateHelper I (isolate_);
@@ -2201,6 +2240,11 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
22012240 AddMemberFunction_Struct_toJSON<FStructPropertyAccessors>(Template, StructToExport);
22022241 AddMemberFunction_Struct_RawAccessor<FStructPropertyAccessors>(Template, StructToExport);
22032242
2243+ if (StructToExport == FJavascriptRef::StaticStruct ())
2244+ {
2245+ AddMemberFunction_JavascriptRef_get (Template);
2246+ }
2247+
22042248 Template->SetClassName (I.Keyword (StructToExport->GetName ()));
22052249
22062250 auto static_class = I.Keyword (" StaticClass" );
0 commit comments