Skip to content
Open
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
23 changes: 14 additions & 9 deletions src/NodeApi.DotNetHost/JSMarshaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2893,9 +2893,9 @@ private IEnumerable<Expression> BuildFromJSToArrayExpressions(
* jsArray.CopyTo(array, 0, (item) => (T)item);
* return array;
*/
ParameterExpression jsArrayVariable = Expression.Parameter(typeof(JSArray), "jsArray");
ParameterExpression jsArrayVariable = Expression.Parameter(typeof(JSArray), "jsArray_" + FullTypeName(elementType));
ParameterExpression arrayVariable = Expression.Parameter(
elementType.MakeArrayType(), "array");
elementType.MakeArrayType(), "array_" + FullTypeName(elementType));
variables.Add(jsArrayVariable);
variables.Add(arrayVariable);

Expand All @@ -2906,10 +2906,10 @@ private IEnumerable<Expression> BuildFromJSToArrayExpressions(
Expression.Convert(valueVariable, typeof(JSArray), castMethod));

PropertyInfo jsArrayLengthProperty = typeof(JSArray).GetProperty(nameof(JSArray.Length))!;
yield return Expression.Assign(
arrayVariable,
Expression.NewArrayBounds(
elementType, Expression.Property(jsArrayVariable, jsArrayLengthProperty)));
yield return Expression.Assign(
arrayVariable,
Expression.NewArrayBounds(
elementType, Expression.Property(jsArrayVariable, jsArrayLengthProperty)));

LambdaExpression fromJSExpression = GetFromJSValueExpression(elementType);
MethodInfo arrayCopyMethod = typeof(JSArray)
Expand All @@ -2936,7 +2936,7 @@ private IEnumerable<Expression> BuildToJSFromArrayExpressions(
* jsArray.CopyFrom(value, 0, (item) => (JSValue)item);
* return jsArray;
*/
ParameterExpression jsArrayVariable = Expression.Variable(typeof(JSArray), "jsArray");
ParameterExpression jsArrayVariable = Expression.Variable(typeof(JSArray), "jsArray_" + FullTypeName(elementType));
variables.Add(jsArrayVariable);

PropertyInfo arrayLengthProperty = typeof(Array).GetProperty(nameof(Array.Length))!;
Expand Down Expand Up @@ -3700,8 +3700,13 @@ internal static string FullTypeName(Type type)
{
string? ns = type.Namespace;
string name = type.Name;

if (type.IsGenericType)
if (type.IsArray)
{
int rank = type.GetArrayRank();
string elementTypeName = FullTypeName(type.GetElementType()!);
return $"{elementTypeName}_Array{(rank > 1 ? rank.ToString() : "")}";
}
else if (type.IsGenericType)
{
int nameEnd = name.IndexOf('`');
if (nameEnd >= 0)
Expand Down
3 changes: 3 additions & 0 deletions src/NodeApi.Generator/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ member.Expression is ParameterExpression parameterExpression &&
FormatArgs(construction.Arguments, path, variables),

NewArrayExpression { NodeType: ExpressionType.NewArrayBounds } newArray =>
newArray.Type.GetElementType()!.IsArray ?
"new " + FormatType(newArray.Type.GetElementType()!.GetElementType()!) +
"[" + ToCS(newArray.Expressions.Single(), path, variables) + "][]" :
"new " + FormatType(newArray.Type.GetElementType()!) +
"[" + ToCS(newArray.Expressions.Single(), path, variables) + "]",

Expand Down