Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weakproperty有效的时候,可能property本身无效 #1803

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions unreal/Puerts/Source/JsEnv/Private/ContainerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void FScriptArrayWrapper::Add(const v8::FunctionCallbackInfo<v8::Value>& Info)
{
auto Self = FV8Utils::GetPointerFast<FScriptArray>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return;
Expand All @@ -69,7 +69,7 @@ void FScriptArrayWrapper::InternalGet(const v8::FunctionCallbackInfo<v8::Value>&

auto Self = FV8Utils::GetPointerFast<FScriptArray>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return;
Expand Down Expand Up @@ -110,7 +110,7 @@ void FScriptArrayWrapper::Set(const v8::FunctionCallbackInfo<v8::Value>& Info)

auto Self = FV8Utils::GetPointerFast<FScriptArray>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return;
Expand Down Expand Up @@ -151,7 +151,7 @@ void FScriptArrayWrapper::RemoveAt(const v8::FunctionCallbackInfo<v8::Value>& In

auto Self = FV8Utils::GetPointerFast<FScriptArray>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return;
Expand Down Expand Up @@ -195,7 +195,7 @@ void FScriptArrayWrapper::Empty(const v8::FunctionCallbackInfo<v8::Value>& Info)

auto Self = FV8Utils::GetPointerFast<FScriptArray>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return;
Expand Down Expand Up @@ -237,7 +237,7 @@ int32 FScriptArrayWrapper::FindIndexInner(const v8::FunctionCallbackInfo<v8::Val

auto Self = FV8Utils::GetPointerFast<FScriptArray>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return INDEX_NONE;
Expand Down Expand Up @@ -297,7 +297,7 @@ void FScriptSetWrapper::Add(const v8::FunctionCallbackInfo<v8::Value>& Info)

auto Self = FV8Utils::GetPointerFast<FScriptSet>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return;
Expand Down Expand Up @@ -331,7 +331,7 @@ void FScriptSetWrapper::InternalGet(const v8::FunctionCallbackInfo<v8::Value>& I

auto Self = FV8Utils::GetPointerFast<FScriptSet>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return;
Expand Down Expand Up @@ -390,7 +390,7 @@ void FScriptSetWrapper::RemoveAt(const v8::FunctionCallbackInfo<v8::Value>& Info

auto Self = FV8Utils::GetPointerFast<FScriptSet>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return;
Expand Down Expand Up @@ -444,7 +444,7 @@ void FScriptSetWrapper::Empty(const v8::FunctionCallbackInfo<v8::Value>& Info)

auto Self = FV8Utils::GetPointerFast<FScriptSet>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return;
Expand All @@ -461,7 +461,7 @@ int32 FScriptSetWrapper::FindIndexInner(const v8::FunctionCallbackInfo<v8::Value

auto Self = FV8Utils::GetPointerFast<FScriptSet>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return INDEX_NONE;
Expand Down Expand Up @@ -518,7 +518,7 @@ void FScriptMapWrapper::Add(const v8::FunctionCallbackInfo<v8::Value>& Info)
auto KeyProperty = KeyPropertyTranslator->Property;
auto ValuePropertyTranslator = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 2);
auto ValueProperty = ValuePropertyTranslator->Property;
if (!KeyPropertyTranslator->PropertyWeakPtr.IsValid() || !ValuePropertyTranslator->PropertyWeakPtr.IsValid())
if (!KeyPropertyTranslator->IsPropertyValid() || !ValuePropertyTranslator->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "key/value info is invalid!");
return;
Expand Down Expand Up @@ -569,7 +569,7 @@ void FScriptMapWrapper::InternalGet(const v8::FunctionCallbackInfo<v8::Value>& I
auto KeyProperty = KeyPropertyTranslator->Property;
auto ValuePropertyTranslator = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 2);
auto ValueProperty = ValuePropertyTranslator->Property;
if (!KeyPropertyTranslator->PropertyWeakPtr.IsValid() || !ValuePropertyTranslator->PropertyWeakPtr.IsValid())
if (!KeyPropertyTranslator->IsPropertyValid() || !ValuePropertyTranslator->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "key/value info is invalid!");
return;
Expand Down Expand Up @@ -626,7 +626,7 @@ void FScriptMapWrapper::Remove(const v8::FunctionCallbackInfo<v8::Value>& Info)
auto KeyProperty = KeyPropertyTranslator->Property;
auto ValuePropertyTranslator = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 2);
auto ValueProperty = ValuePropertyTranslator->Property;
if (!KeyPropertyTranslator->PropertyWeakPtr.IsValid() || !ValuePropertyTranslator->PropertyWeakPtr.IsValid())
if (!KeyPropertyTranslator->IsPropertyValid() || !ValuePropertyTranslator->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "key/value info is invalid!");
return;
Expand Down Expand Up @@ -697,7 +697,7 @@ void FScriptMapWrapper::GetKey(const v8::FunctionCallbackInfo<v8::Value>& Info)
auto KeyProperty = KeyPropertyTranslator->Property;
auto ValuePropertyTranslator = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 2);
auto ValueProperty = ValuePropertyTranslator->Property;
if (!KeyPropertyTranslator->PropertyWeakPtr.IsValid() || !ValuePropertyTranslator->PropertyWeakPtr.IsValid())
if (!KeyPropertyTranslator->IsPropertyValid() || !ValuePropertyTranslator->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "key/value info is invalid!");
return;
Expand All @@ -721,7 +721,7 @@ void FScriptMapWrapper::Empty(const v8::FunctionCallbackInfo<v8::Value>& Info)
auto KeyProperty = KeyPropertyTranslator->Property;
auto ValuePropertyTranslator = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 2);
auto ValueProperty = ValuePropertyTranslator->Property;
if (!KeyPropertyTranslator->PropertyWeakPtr.IsValid() || !ValuePropertyTranslator->PropertyWeakPtr.IsValid())
if (!KeyPropertyTranslator->IsPropertyValid() || !ValuePropertyTranslator->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "key/value info is invalid!");
return;
Expand Down Expand Up @@ -759,7 +759,7 @@ void FFixSizeArrayWrapper::Num(const v8::FunctionCallbackInfo<v8::Value>& Info)
v8::Local<v8::Context> Context = Isolate->GetCurrentContext();

auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return;
Expand All @@ -775,7 +775,7 @@ void FFixSizeArrayWrapper::InternalGet(const v8::FunctionCallbackInfo<v8::Value>

auto Self = FV8Utils::GetPointerFast<uint8>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return;
Expand Down Expand Up @@ -823,7 +823,7 @@ void FFixSizeArrayWrapper::Set(const v8::FunctionCallbackInfo<v8::Value>& Info)

auto Self = FV8Utils::GetPointerFast<uint8>(Info.Holder(), 0);
auto Inner = FV8Utils::GetPointerFast<FPropertyTranslator>(Info.Holder(), 1);
if (!Inner->PropertyWeakPtr.IsValid())
if (!Inner->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "item info is invalid!");
return;
Expand Down
6 changes: 3 additions & 3 deletions unreal/Puerts/Source/JsEnv/Private/PropertyTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void FPropertyTranslator::Getter(const v8::FunctionCallbackInfo<v8::Value>& Info
void FPropertyTranslator::Getter(
v8::Isolate* Isolate, v8::Local<v8::Context>& Context, const v8::FunctionCallbackInfo<v8::Value>& Info)
{
if (!PropertyWeakPtr.IsValid())
if (!IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "Property is invalid!");
return;
Expand Down Expand Up @@ -86,7 +86,7 @@ void FPropertyTranslator::Setter(const v8::FunctionCallbackInfo<v8::Value>& Info
void FPropertyTranslator::Setter(v8::Isolate* Isolate, v8::Local<v8::Context>& Context, v8::Local<v8::Value> Value,
const v8::FunctionCallbackInfo<v8::Value>& Info)
{
if (!PropertyWeakPtr.IsValid())
if (!IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "Property is invalid!");
return;
Expand Down Expand Up @@ -129,7 +129,7 @@ void FPropertyTranslator::DelegateGetter(const v8::FunctionCallbackInfo<v8::Valu

FPropertyTranslator* PropertyTranslator =
static_cast<FPropertyTranslator*>((v8::Local<v8::External>::Cast(Info.Data()))->Value());
if (!PropertyTranslator->PropertyWeakPtr.IsValid())
if (!PropertyTranslator->IsPropertyValid())
{
FV8Utils::ThrowException(Isolate, "Property is invalid!");
return;
Expand Down
29 changes: 23 additions & 6 deletions unreal/Puerts/Source/JsEnv/Private/PropertyTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ class FPropertyTranslator
#endif
};

#if ENGINE_MINOR_VERSION < 25 && ENGINE_MAJOR_VERSION < 5
TWeakObjectPtr<PropertyMacro> PropertyWeakPtr;
#else
TWeakFieldPtr<PropertyMacro> PropertyWeakPtr;
#endif

bool OwnerIsClass;

bool NeedLinkOuter;
Expand All @@ -181,5 +175,28 @@ class FPropertyTranslator
static void DelegateGetter(const v8::FunctionCallbackInfo<v8::Value>& Info);

void SetAccessor(v8::Isolate* Isolate, v8::Local<v8::FunctionTemplate> Template);

bool IsPropertyValid()
{
if (!PropertyWeakPtr.IsValid())
{
return false;
}
#if WITH_EDITOR
FProperty* TestP = PropertyWeakPtr.Get();
if (TestP != Property)
{
Init(TestP);
}
#endif
return true;
}

private:
#if ENGINE_MINOR_VERSION < 25 && ENGINE_MAJOR_VERSION < 5
TWeakObjectPtr<PropertyMacro> PropertyWeakPtr;
#else
TWeakFieldPtr<PropertyMacro> PropertyWeakPtr;
#endif
};
} // namespace PUERTS_NAMESPACE
Loading