Skip to content

Commit

Permalink
[unreal]反射new,Class.Load, Class.Find, Class.StaticClass加上关联的UStruct是否…
Browse files Browse the repository at this point in the history
…无效的检查
  • Loading branch information
chexiongsheng committed Jul 8, 2024
1 parent e90454f commit be37ef8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions unreal/Puerts/Source/JsEnv/Private/StructWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ void FStructWrapper::StaticClass(const v8::FunctionCallbackInfo<v8::Value>& Info

FStructWrapper* This = reinterpret_cast<FStructWrapper*>((v8::Local<v8::External>::Cast(Info.Data()))->Value());

if (!This->Struct.IsValid())
{
FV8Utils::ThrowException(Isolate, "Associated UStruct had been GC");
return;
}

auto Result =
FV8Utils::IsolateData<IObjectMapper>(Isolate)->FindOrAdd(Isolate, Context, This->Struct->GetClass(), This->Struct.Get());
Info.GetReturnValue().Set(Result);
Expand All @@ -441,6 +447,12 @@ void FStructWrapper::Find(const v8::FunctionCallbackInfo<v8::Value>& Info)

FStructWrapper* This = reinterpret_cast<FStructWrapper*>((v8::Local<v8::External>::Cast(Info.Data()))->Value());

if (!This->Struct.IsValid())
{
FV8Utils::ThrowException(Isolate, "Associated UStruct had been GC");
return;
}

UClass* Class = Cast<UClass>(This->Struct);

if (Class && Info.Length() >= 1 && Info[0]->IsString())
Expand Down Expand Up @@ -486,6 +498,12 @@ void FStructWrapper::Load(const v8::FunctionCallbackInfo<v8::Value>& Info)

FStructWrapper* This = reinterpret_cast<FStructWrapper*>((v8::Local<v8::External>::Cast(Info.Data()))->Value());

if (!This->Struct.IsValid())
{
FV8Utils::ThrowException(Isolate, "Associated UStruct had been GC");
return;
}

UClass* Class = Cast<UClass>(This->Struct);

if (Class && Info.Length() > 0 && Info[0]->IsString())
Expand Down Expand Up @@ -523,6 +541,11 @@ void FScriptStructWrapper::New(const v8::FunctionCallbackInfo<v8::Value>& Info)
v8::Context::Scope ContextScope(Context);

FScriptStructWrapper* This = reinterpret_cast<FScriptStructWrapper*>((v8::Local<v8::External>::Cast(Info.Data()))->Value());
if (!This->Struct.IsValid())
{
FV8Utils::ThrowException(Isolate, "Associated UStruct had been GC");
return;
}
This->New(Isolate, Context, Info);
}

Expand Down Expand Up @@ -612,6 +635,11 @@ void FClassWrapper::New(const v8::FunctionCallbackInfo<v8::Value>& Info)
v8::Context::Scope ContextScope(Context);

FClassWrapper* This = reinterpret_cast<FClassWrapper*>((v8::Local<v8::External>::Cast(Info.Data()))->Value());
if (!This->Struct.IsValid())
{
FV8Utils::ThrowException(Isolate, "Associated UStruct had been GC");
return;
}
This->New(Isolate, Context, Info);
}

Expand Down

0 comments on commit be37ef8

Please sign in to comment.