avoid explicit memcpy

This commit is contained in:
sjorsdonkers
2025-09-05 16:50:04 +02:00
committed by Muki Kiboigo
parent a5e2e8ea15
commit dc60fac90d

View File

@@ -1131,17 +1131,14 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
else => {}, else => {},
}, },
.array => |arr| { .array => |arr| {
// Retrieve fixed-size array as slice then copy it // Retrieve fixed-size array as slice
const slice_type = []arr.child; const slice_type = []arr.child;
const slice_value = try self.jsValueToZig(named_function, slice_type, js_value); const slice_value = try self.jsValueToZig(named_function, slice_type, js_value);
if (slice_value.len != arr.len) { if (slice_value.len != arr.len) {
// Exact length match, we could allow smaller arrays, but we would not be able to communicate how many were written // Exact length match, we could allow smaller arrays, but we would not be able to communicate how many were written
return error.InvalidArgument; return error.InvalidArgument;
} }
return @as(*T, @ptrCast(slice_value.ptr)).*;
var result: T = undefined;
@memcpy(&result, slice_value[0..arr.len]);
return result;
}, },
.@"struct" => { .@"struct" => {
return try (self.jsValueToStruct(named_function, T, js_value)) orelse { return try (self.jsValueToStruct(named_function, T, js_value)) orelse {