Skip to content

Commit

Permalink
Merge pull request #1616 from dunadain/CSharpExtensionBug
Browse files Browse the repository at this point in the history
解决当extension methods默认参数有传参时,index读取不正确bug
  • Loading branch information
zombieyang authored Dec 18, 2023
2 parents 6d76c14 + b7eca3a commit 1957d4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<void*>::GetString(context, info, method, wrapData->IsExtensionMethod ? ${start + 1} : ${start});
void* ${CSName} = OptionalParameter<void*>::GetString(context, info, method, wrapData, ${start});
`
} else if (si == 'o' || si == 'O' || si == 'a') {
return ` // JSValToCSVal ref with default
void* ${CSName} = OptionalParameter<void*>::GetRefType(context, info, method, wrapData->IsExtensionMethod ? ${start + 1} : ${start}, TI${CSName});
void* ${CSName} = OptionalParameter<void*>::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
Expand Down
12 changes: 8 additions & 4 deletions unity/native_src_il2cpp/Src/Puerts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,15 @@ struct RestArguments
template <typename T>
struct OptionalParameter
{
static T GetPrimitive(v8::Local<v8::Context> context, const v8::FunctionCallbackInfo<v8::Value>& info, const void* methodInfo, int index)
static T GetPrimitive(v8::Local<v8::Context> context, const v8::FunctionCallbackInfo<v8::Value>& info, const void* methodInfo, puerts::WrapData* wrapData, int index)
{
if (index < info.Length())
{
return converter::Converter<T>::toCpp(context, info[index]);
}
else
{
if (wrapData->IsExtensionMethod) ++index;
auto pret = (T*)GetDefaultValuePtr(methodInfo, index);
if (pret)
{
Expand All @@ -586,14 +587,15 @@ struct OptionalParameter
}
}

static T GetValueType(v8::Local<v8::Context> context, const v8::FunctionCallbackInfo<v8::Value>& info, const void* methodInfo, int index)
static T GetValueType(v8::Local<v8::Context> context, const v8::FunctionCallbackInfo<v8::Value>& info, const void* methodInfo, puerts::WrapData* wrapData, int index)
{
if (index < info.Length())
{
return (*DataTransfer::GetPointer<T>(context, info[index]));
}
else
{
if (wrapData->IsExtensionMethod) ++index;
auto pret = (T*)GetDefaultValuePtr(methodInfo, index);
if (pret)
{
Expand All @@ -605,7 +607,7 @@ struct OptionalParameter
}
}

static void* GetString(v8::Local<v8::Context> context, const v8::FunctionCallbackInfo<v8::Value>& info, const void* methodInfo, int index)
static void* GetString(v8::Local<v8::Context> context, const v8::FunctionCallbackInfo<v8::Value>& info, const void* methodInfo, puerts::WrapData* wrapData, int index)
{
if (index < info.Length())
{
Expand All @@ -614,18 +616,20 @@ struct OptionalParameter
}
else
{
if (wrapData->IsExtensionMethod) ++index;
return GetDefaultValuePtr(methodInfo, index);
}
}

static void* GetRefType(v8::Local<v8::Context> context, const v8::FunctionCallbackInfo<v8::Value>& info, const void* methodInfo, int index, const void* typeId)
static void* GetRefType(v8::Local<v8::Context> context, const v8::FunctionCallbackInfo<v8::Value>& info, const void* methodInfo, puerts::WrapData* wrapData, int index, const void* typeId)
{
if (index < info.Length())
{
return JsValueToCSRef(context, info[index], typeId);
}
else
{
if (wrapData->IsExtensionMethod) ++index;
return GetDefaultValuePtr(methodInfo, index);
}
}
Expand Down

0 comments on commit 1957d4c

Please sign in to comment.