Skip to content
Merged
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
10 changes: 10 additions & 0 deletions Jint/Native/JsTypedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,18 @@ internal bool IsValidIntegerIndex(int index)
return true;
}


internal T[] ToNativeArray<T>()
{
if (_byteOffset == 0 && typeof(T) == typeof(byte) && _arrayElementType == TypedArrayElementType.Uint8)
{
var result = _viewedArrayBuffer._arrayBufferData.AsSpan().Slice(0, (int) GetLength()).ToArray() as T[];
if (result != null)
{
return result;
Comment thread
StringEpsilon marked this conversation as resolved.
}
}

var conversionType = typeof(T);
var elementSize = _arrayElementType.GetElementSize();
var byteOffset = _byteOffset;
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/TypedArray/TypedArrayConstructor.Uint8Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void Initialize()
public JsTypedArray Construct(ReadOnlySpan<byte> values)
{
var array = (JsTypedArray) base.Construct([values.Length], this);
FillTypedArrayInstance(array, values);
values.CopyTo(array._viewedArrayBuffer._arrayBufferData.AsSpan());
return array;
Comment thread
StringEpsilon marked this conversation as resolved.
}

Expand Down
9 changes: 6 additions & 3 deletions Jint/Runtime/Interop/MethodInfoFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ static JsCallArguments ArgumentProvider(MethodDescriptor method, MethodResolverS
var methodParameter = methodParameters[i];
var parameterType = methodParameter.ParameterType;
var argument = arguments.Length > i ? arguments[i] : null;
object? argumentObject = null;

if (typeof(JsValue).IsAssignableFrom(parameterType))
Comment thread
StringEpsilon marked this conversation as resolved.
{
Expand All @@ -195,9 +196,11 @@ static JsCallArguments ArgumentProvider(MethodDescriptor method, MethodResolverS
// optional
parameters[i] = System.Type.Missing;
}
else if (IsGenericParameter(argument.ToObject(), parameterType)) // don't think we need the condition preface of (argument == null) because of earlier condition
else if (IsGenericParameter(argumentObject = argument.ToObject(), parameterType)) // don't think we need the condition preface of (argument == null) because of earlier condition
{
parameters[i] = argument.ToObject();
// ^ this is the best way I could think of to only eval argument.ToObject() when needed.
// But it's very cursed, I'm sorry.
parameters[i] = argumentObject;
}
else if (parameterType == typeof(JsValue[]) && argument.IsArray())
{
Expand All @@ -215,7 +218,7 @@ static JsCallArguments ArgumentProvider(MethodDescriptor method, MethodResolverS
else
{
if (!ReflectionExtensions.TryConvertViaTypeCoercion(parameterType, _engine.Options.Interop.ValueCoercion, argument, out parameters[i])
&& !converter.TryConvert(argument.ToObject(), parameterType, CultureInfo.InvariantCulture, out parameters[i]))
&& !converter.TryConvert(argumentObject, parameterType, CultureInfo.InvariantCulture, out parameters[i]))
{
argumentsMatch = false;
break;
Expand Down