Skip to content
Draft
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: 9 additions & 1 deletion src/js/typed_arrays.zig
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ pub fn TypedArray(comptime Element: type, comptime array_type: TypedarrayType) t
const len_hint: ?*anyopaque = @ptrFromInt(slice.len);
const finalize_cb = comptime napi.wrapSliceFinalizeCallback(Element, externalFinalizer);
const arraybuffer = e.createExternalArrayBuffer(std.mem.sliceAsBytes(buf), finalize_cb, len_hint) catch |err| {
context.allocator().free(buf);
// These statuses are returned before N-API installs the finalizer.
switch (err) {
error.NoExternalBuffersAllowed,
error.PendingException,
error.CannotRunJS,
=> context.allocator().free(buf),
// Other failures may occur after the finalizer has taken ownership.
else => {},
}
return err;
};

Expand Down
Loading