Skip to content

test,doc: cover and document multi-byte offset/size in randomFill - #64834

Open
kyungrae2002 wants to merge 1 commit into
nodejs:mainfrom
kyungrae2002:my-branch
Open

test,doc: cover and document multi-byte offset/size in randomFill#64834
kyungrae2002 wants to merge 1 commit into
nodejs:mainfrom
kyungrae2002:my-branch

Conversation

@kyungrae2002

Copy link
Copy Markdown

Summary

randomFill() / randomFillSync() interpret offset and size in elements
for a TypedArray (converted to bytes internally via BYTES_PER_ELEMENT) and in
bytes for an ArrayBuffer or DataView. This PR documents contract and
adds regression tests for the previously uncovered case. No runtime behavior
changes.

Docs

The size default was documented only as buffer.length - offset, which is
meaningless for ArrayBuffer / DataView (they have no .length), and the
element-vs-byte unit distinction was undocumented. The parameter descriptions of
both randomFill() and randomFillSync() now state the unit and default per type.

Tests

Existing offset/size assertions only cover Buffer /Uint8Array
(BYTES_PER_ELEMENT === 1), so the element-to-byte conversion was never verified
for multi-byte typed arrays. The added tests fill a single element of a
Uint16Array / Uint32Array at a non-zero offset and assert the neighboring
elements are untouched, which fails if the conversion is off.

Signed-off-by: kyungrae <kyungrae2002@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants