From b7eca3a9407c1f3f65442a3bcd7f2d3513e0861d Mon Sep 17 00:00:00 2001 From: Ryan Sampras Date: Thu, 14 Dec 2023 11:26:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=BD=93extension=20methods?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=8F=82=E6=95=B0=E6=9C=89=E4=BC=A0=E5=8F=82?= =?UTF-8?q?=E6=97=B6=EF=BC=8Cindex=E8=AF=BB=E5=8F=96=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Resources/puerts/templates/cppwrapper.tpl.mjs | 8 ++++---- unity/native_src_il2cpp/Src/Puerts.cpp | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/unity/Assets/core/upm/Editor/Resources/puerts/templates/cppwrapper.tpl.mjs b/unity/Assets/core/upm/Editor/Resources/puerts/templates/cppwrapper.tpl.mjs index 284fa58935..8710cca639 100644 --- a/unity/Assets/core/upm/Editor/Resources/puerts/templates/cppwrapper.tpl.mjs +++ b/unity/Assets/core/upm/Editor/Resources/puerts/templates/cppwrapper.tpl.mjs @@ -326,19 +326,19 @@ ${CODE_SNIPPETS.JSValToCSVal(signature, 'MaybeRet.ToLocalChecked()', 'ret')} const start = parseInt(JSName.match(/info\[(\d+)\]/)[1]); if (si in PrimitiveSignatureCppTypeMap) { return ` // JSValToCSVal primitive with default - ${PrimitiveSignatureCppTypeMap[si]} ${CSName} = OptionalParameter<${PrimitiveSignatureCppTypeMap[si]}>::GetPrimitive(context, info, method, wrapData->IsExtensionMethod ? ${start + 1} : ${start}); + ${PrimitiveSignatureCppTypeMap[si]} ${CSName} = OptionalParameter<${PrimitiveSignatureCppTypeMap[si]}>::GetPrimitive(context, info, method, wrapData, ${start}); ` } else if (si == 's') { return ` // JSValToCSVal string with default - void* ${CSName} = OptionalParameter::GetString(context, info, method, wrapData->IsExtensionMethod ? ${start + 1} : ${start}); + void* ${CSName} = OptionalParameter::GetString(context, info, method, wrapData, ${start}); ` } else if (si == 'o' || si == 'O' || si == 'a') { return ` // JSValToCSVal ref with default - void* ${CSName} = OptionalParameter::GetRefType(context, info, method, wrapData->IsExtensionMethod ? ${start + 1} : ${start}, TI${CSName}); + void* ${CSName} = OptionalParameter::GetRefType(context, info, method, wrapData, ${start}, TI${CSName}); ` } else if ((si.startsWith(sigs.StructPrefix) || si.startsWith(sigs.NullableStructPrefix)) && si.endsWith('_')) { return ` // JSValToCSVal valuetype with default - ${si} ${CSName} = OptionalParameter<${si}>::GetValueType(context, info, method, wrapData->IsExtensionMethod ? ${start + 1} : ${start}); + ${si} ${CSName} = OptionalParameter<${si}>::GetValueType(context, info, method, wrapData, ${start}); ` } else { return ` // JSValToCSVal unknow type with default diff --git a/unity/native_src_il2cpp/Src/Puerts.cpp b/unity/native_src_il2cpp/Src/Puerts.cpp index 53401e33d0..c8f905fc98 100644 --- a/unity/native_src_il2cpp/Src/Puerts.cpp +++ b/unity/native_src_il2cpp/Src/Puerts.cpp @@ -569,7 +569,7 @@ struct RestArguments template struct OptionalParameter { - static T GetPrimitive(v8::Local context, const v8::FunctionCallbackInfo& info, const void* methodInfo, int index) + static T GetPrimitive(v8::Local context, const v8::FunctionCallbackInfo& info, const void* methodInfo, puerts::WrapData* wrapData, int index) { if (index < info.Length()) { @@ -577,6 +577,7 @@ struct OptionalParameter } else { + if (wrapData->IsExtensionMethod) ++index; auto pret = (T*)GetDefaultValuePtr(methodInfo, index); if (pret) { @@ -586,7 +587,7 @@ struct OptionalParameter } } - static T GetValueType(v8::Local context, const v8::FunctionCallbackInfo& info, const void* methodInfo, int index) + static T GetValueType(v8::Local context, const v8::FunctionCallbackInfo& info, const void* methodInfo, puerts::WrapData* wrapData, int index) { if (index < info.Length()) { @@ -594,6 +595,7 @@ struct OptionalParameter } else { + if (wrapData->IsExtensionMethod) ++index; auto pret = (T*)GetDefaultValuePtr(methodInfo, index); if (pret) { @@ -605,7 +607,7 @@ struct OptionalParameter } } - static void* GetString(v8::Local context, const v8::FunctionCallbackInfo& info, const void* methodInfo, int index) + static void* GetString(v8::Local context, const v8::FunctionCallbackInfo& info, const void* methodInfo, puerts::WrapData* wrapData, int index) { if (index < info.Length()) { @@ -614,11 +616,12 @@ struct OptionalParameter } else { + if (wrapData->IsExtensionMethod) ++index; return GetDefaultValuePtr(methodInfo, index); } } - static void* GetRefType(v8::Local context, const v8::FunctionCallbackInfo& info, const void* methodInfo, int index, const void* typeId) + static void* GetRefType(v8::Local context, const v8::FunctionCallbackInfo& info, const void* methodInfo, puerts::WrapData* wrapData, int index, const void* typeId) { if (index < info.Length()) { @@ -626,6 +629,7 @@ struct OptionalParameter } else { + if (wrapData->IsExtensionMethod) ++index; return GetDefaultValuePtr(methodInfo, index); } }