Skip to content

feat: allow v8 alloc for typed-array#21

Merged
nazarhussain merged 1 commit into
mainfrom
nh/js-array-memory
Apr 28, 2026
Merged

feat: allow v8 alloc for typed-array#21
nazarhussain merged 1 commit into
mainfrom
nh/js-array-memory

Conversation

@nazarhussain
Copy link
Copy Markdown
Contributor

@nazarhussain nazarhussain commented Apr 22, 2026

Summary

Example

var arr = try js.Uint8Array.alloc(size);
_ = try view.serializeIntoBytes(try arr.toSlice());
return arr;

@nazarhussain nazarhussain changed the title feat: add memory alloc feature for typed-array feat: allow v8 alloc for typed-array Apr 22, 2026
@nazarhussain nazarhussain merged commit 56e6812 into main Apr 28, 2026
7 checks passed
@nazarhussain nazarhussain deleted the nh/js-array-memory branch April 28, 2026 11:16
Comment thread src/js/typed_arrays.zig
///
/// Consumers should generally use the concrete aliases provided (e.g., `js.Uint8Array`)
/// rather than instantiating this factory directly.
pub fn TypedArray(comptime Element: type, comptime array_type: TypedarrayType) type {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we consider add comptime type check since it looks like only support several array_types

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use this struct for shared behavior of the typed arrays, so the new functions added here can be used as js.Uint8Array.alloc() or js.Uint16Array.alloc(). Do not understand what do you mean by further comptime checks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If needed we can add anytime as a patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ergonomic DSL helpers for constructing JS TypedArrays without raw env.createArrayBuffer/createTypedarray boilerplate

2 participants