diff --git a/unity/native_src/Inc/DataTransfer.h b/unity/native_src/Inc/DataTransfer.h index 344ca88069..a69e4d36f4 100644 --- a/unity/native_src/Inc/DataTransfer.h +++ b/unity/native_src/Inc/DataTransfer.h @@ -185,6 +185,24 @@ struct TScriptStructTraits } }; +template <> +struct TScriptStructTraits +{ + static UScriptStruct* Get() + { + return GetScriptStructInCoreUObject(TEXT("Matrix")); + } +}; + +template <> +struct TScriptStructTraits +{ + static UScriptStruct* Get() + { + return GetScriptStructInCoreUObject(TEXT("IntVector4")); + } +}; + template using ToVoid = void; @@ -319,7 +337,7 @@ class JSENV_API DataTransfer static v8::Local FindOrAddCData( v8::Isolate* Isolate, v8::Local Context, const void* TypeId, const void* Ptr, bool PassByPointer); - static bool IsInstanceOf(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject); + static bool IsInstanceOf(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject); static v8::Local UnRef(v8::Isolate* Isolate, const v8::Local& Value); @@ -347,12 +365,12 @@ class JSENV_API DataTransfer v8::Isolate* Isolate, v8::Local Context, UScriptStruct* ScriptStruct, void* Ptr, bool PassByPointer); template - static bool IsInstanceOf(v8::Isolate* Isolate, v8::Local JsObject) + static bool IsInstanceOf(v8::Isolate* Isolate, v8::Local JsObject) { return IsInstanceOf(Isolate, TScriptStructTraits::Get(), JsObject); } - static bool IsInstanceOf(v8::Isolate* Isolate, UStruct* Struct, v8::Local JsObject); + static bool IsInstanceOf(v8::Isolate* Isolate, UStruct* Struct, v8::Local JsObject); static FString ToFString(v8::Isolate* Isolate, v8::Local Value); diff --git a/unity/native_src/Src/DataTransfer.cpp b/unity/native_src/Src/DataTransfer.cpp index b16f15c821..4ab17c98fe 100644 --- a/unity/native_src/Src/DataTransfer.cpp +++ b/unity/native_src/Src/DataTransfer.cpp @@ -21,9 +21,9 @@ v8::Local DataTransfer::FindOrAddCData( Isolate, Context, TypeId, const_cast(Ptr), PassByPointer); } -bool DataTransfer::IsInstanceOf(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject) +bool DataTransfer::IsInstanceOf(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject) { - return IsolateData(Isolate)->IsInstanceOfCppObject(Isolate, TypeId, JsObject); + return JsObject->IsObject() && IsolateData(Isolate)->IsInstanceOfCppObject(Isolate, TypeId, JsObject.As()); } v8::Local DataTransfer::UnRef(v8::Isolate* Isolate, const v8::Local& Value) @@ -64,9 +64,9 @@ v8::Local DataTransfer::FindOrAddStruct( return FV8Utils::IsolateData(Isolate)->FindOrAddStruct(Isolate, Context, ScriptStruct, Ptr, PassByPointer); } -bool DataTransfer::IsInstanceOf(v8::Isolate* Isolate, UStruct* Struct, v8::Local JsObject) +bool DataTransfer::IsInstanceOf(v8::Isolate* Isolate, UStruct* Struct, v8::Local JsObject) { - return FV8Utils::IsolateData(Isolate)->IsInstanceOf(Struct, JsObject); + return JsObject->IsObject() && FV8Utils::IsolateData(Isolate)->IsInstanceOf(Struct, JsObject.As()); } void DataTransfer::ThrowException(v8::Isolate* Isolate, const char* Message) diff --git a/unreal/Puerts/Source/JsEnv/Private/DataTransfer.cpp b/unreal/Puerts/Source/JsEnv/Private/DataTransfer.cpp index b16f15c821..0e69c89095 100644 --- a/unreal/Puerts/Source/JsEnv/Private/DataTransfer.cpp +++ b/unreal/Puerts/Source/JsEnv/Private/DataTransfer.cpp @@ -21,9 +21,10 @@ v8::Local DataTransfer::FindOrAddCData( Isolate, Context, TypeId, const_cast(Ptr), PassByPointer); } -bool DataTransfer::IsInstanceOf(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject) +bool DataTransfer::IsInstanceOf(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject) { - return IsolateData(Isolate)->IsInstanceOfCppObject(Isolate, TypeId, JsObject); + return JsObject->IsObject() && + IsolateData(Isolate)->IsInstanceOfCppObject(Isolate, TypeId, JsObject.As()); } v8::Local DataTransfer::UnRef(v8::Isolate* Isolate, const v8::Local& Value) @@ -64,9 +65,9 @@ v8::Local DataTransfer::FindOrAddStruct( return FV8Utils::IsolateData(Isolate)->FindOrAddStruct(Isolate, Context, ScriptStruct, Ptr, PassByPointer); } -bool DataTransfer::IsInstanceOf(v8::Isolate* Isolate, UStruct* Struct, v8::Local JsObject) +bool DataTransfer::IsInstanceOf(v8::Isolate* Isolate, UStruct* Struct, v8::Local JsObject) { - return FV8Utils::IsolateData(Isolate)->IsInstanceOf(Struct, JsObject); + return JsObject->IsObject() && FV8Utils::IsolateData(Isolate)->IsInstanceOf(Struct, JsObject.As()); } void DataTransfer::ThrowException(v8::Isolate* Isolate, const char* Message) diff --git a/unreal/Puerts/Source/JsEnv/Public/DataTransfer.h b/unreal/Puerts/Source/JsEnv/Public/DataTransfer.h index 2921d64de9..9ebe6fc23a 100644 --- a/unreal/Puerts/Source/JsEnv/Public/DataTransfer.h +++ b/unreal/Puerts/Source/JsEnv/Public/DataTransfer.h @@ -303,7 +303,7 @@ class JSENV_API DataTransfer static v8::Local FindOrAddCData( v8::Isolate* Isolate, v8::Local Context, const void* TypeId, const void* Ptr, bool PassByPointer); - static bool IsInstanceOf(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject); + static bool IsInstanceOf(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject); static v8::Local UnRef(v8::Isolate* Isolate, const v8::Local& Value); @@ -331,12 +331,12 @@ class JSENV_API DataTransfer v8::Isolate* Isolate, v8::Local Context, UScriptStruct* ScriptStruct, void* Ptr, bool PassByPointer); template - static bool IsInstanceOf(v8::Isolate* Isolate, v8::Local JsObject) + static bool IsInstanceOf(v8::Isolate* Isolate, v8::Local JsObject) { return IsInstanceOf(Isolate, TScriptStructTraits::Get(), JsObject); } - static bool IsInstanceOf(v8::Isolate* Isolate, UStruct* Struct, v8::Local JsObject); + static bool IsInstanceOf(v8::Isolate* Isolate, UStruct* Struct, v8::Local JsObject); static FString ToFString(v8::Isolate* Isolate, v8::Local Value); diff --git a/unreal/Puerts/Source/JsEnv/Public/V8Backend.hpp b/unreal/Puerts/Source/JsEnv/Public/V8Backend.hpp index 0adcb822df..d73fbec816 100644 --- a/unreal/Puerts/Source/JsEnv/Public/V8Backend.hpp +++ b/unreal/Puerts/Source/JsEnv/Public/V8Backend.hpp @@ -23,56 +23,54 @@ }; \ } -#define __DefCDataPointerConverter_v8_impl(CLS) \ - namespace PUERTS_NAMESPACE \ - { \ - namespace v8_impl \ - { \ - template <> \ - struct Converter \ - { \ - static v8::Local toScript(v8::Local context, CLS* value) \ - { \ - return ::PUERTS_NAMESPACE::DataTransfer::FindOrAddCData( \ - context->GetIsolate(), context, DynamicTypeId::get(value), value, true); \ - } \ - static CLS* toCpp(v8::Local context, const v8::Local& value) \ - { \ - return ::PUERTS_NAMESPACE::DataTransfer::GetPointerFast(value.As()); \ - } \ - static bool accept(v8::Local context, const v8::Local& value) \ - { \ - return ::PUERTS_NAMESPACE::DataTransfer::IsInstanceOf( \ - context->GetIsolate(), StaticTypeId::get(), value.As()); \ - } \ - }; \ - } \ - } - -#define __DefCDataConverter_v8_impl(CLS) \ - namespace PUERTS_NAMESPACE \ - { \ - namespace v8_impl \ - { \ - template <> \ - struct Converter \ - { \ - static v8::Local toScript(v8::Local context, CLS value) \ - { \ - return ::PUERTS_NAMESPACE::DataTransfer::FindOrAddCData( \ - context->GetIsolate(), context, DynamicTypeId::get(&value), new CLS(value), false); \ - } \ - static CLS toCpp(v8::Local context, const v8::Local& value) \ - { \ - return *::PUERTS_NAMESPACE::DataTransfer::GetPointerFast(value.As()); \ - } \ - static bool accept(v8::Local context, const v8::Local& value) \ - { \ - return ::PUERTS_NAMESPACE::DataTransfer::IsInstanceOf( \ - context->GetIsolate(), StaticTypeId::get(), value.As()); \ - } \ - }; \ - } \ +#define __DefCDataPointerConverter_v8_impl(CLS) \ + namespace PUERTS_NAMESPACE \ + { \ + namespace v8_impl \ + { \ + template <> \ + struct Converter \ + { \ + static v8::Local toScript(v8::Local context, CLS* value) \ + { \ + return ::PUERTS_NAMESPACE::DataTransfer::FindOrAddCData( \ + context->GetIsolate(), context, DynamicTypeId::get(value), value, true); \ + } \ + static CLS* toCpp(v8::Local context, const v8::Local& value) \ + { \ + return ::PUERTS_NAMESPACE::DataTransfer::GetPointerFast(value.As()); \ + } \ + static bool accept(v8::Local context, const v8::Local& value) \ + { \ + return ::PUERTS_NAMESPACE::DataTransfer::IsInstanceOf(context->GetIsolate(), StaticTypeId::get(), value); \ + } \ + }; \ + } \ + } + +#define __DefCDataConverter_v8_impl(CLS) \ + namespace PUERTS_NAMESPACE \ + { \ + namespace v8_impl \ + { \ + template <> \ + struct Converter \ + { \ + static v8::Local toScript(v8::Local context, CLS value) \ + { \ + return ::PUERTS_NAMESPACE::DataTransfer::FindOrAddCData( \ + context->GetIsolate(), context, DynamicTypeId::get(&value), new CLS(value), false); \ + } \ + static CLS toCpp(v8::Local context, const v8::Local& value) \ + { \ + return *::PUERTS_NAMESPACE::DataTransfer::GetPointerFast(value.As()); \ + } \ + static bool accept(v8::Local context, const v8::Local& value) \ + { \ + return ::PUERTS_NAMESPACE::DataTransfer::IsInstanceOf(context->GetIsolate(), StaticTypeId::get(), value); \ + } \ + }; \ + } \ } namespace PUERTS_NAMESPACE @@ -642,7 +640,7 @@ struct Converter::value } static bool accept(v8::Local context, const v8::Local& value) { - return DataTransfer::IsInstanceOf(context->GetIsolate(), StaticTypeId::get(), value.As()); + return DataTransfer::IsInstanceOf(context->GetIsolate(), StaticTypeId::get(), value); } };