Skip to content

fix(node:diagnostics_channel): forward runStores callback arguments (#3082)#3182

Merged
proggeramlug merged 1 commit into
mainfrom
fix/dc-runstores-forward-args-3082
May 30, 2026
Merged

fix(node:diagnostics_channel): forward runStores callback arguments (#3082)#3182
proggeramlug merged 1 commit into
mainfrom
fix/dc-runstores-forward-args-3082

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

What

Extends Node argument-validation parity (#2013) to the global Buffer factory methods, following the fs slice landed in #2035 / #2328. These functions previously coerced bad input silently, so assert.throws-style tests reported "Missing expected exception".

API Bad input Now throws
Buffer.alloc / allocUnsafe / allocUnsafeSlow non-number size TypeError [ERR_INVALID_ARG_TYPE]
NaN / Infinity / negative / > kMaxLength RangeError [ERR_OUT_OF_RANGE]
Buffer.concat non-Array list TypeError [ERR_INVALID_ARG_TYPE]
non-Buffer/Uint8Array element TypeError [ERR_INVALID_ARG_TYPE] (list[i])
non-integer / negative totalLength ERR_INVALID_ARG_TYPE / ERR_OUT_OF_RANGE
Buffer.byteLength non string/Buffer/ArrayBuffer/TypedArray TypeError [ERR_INVALID_ARG_TYPE]

Non-integer sizes still truncate toward zero (Buffer.alloc(2.5).length === 2), matching Node.

How

  • Reuses the fs::validate primitives (describe_received, throw_type_error_with_code, throw_range_error_with_code, validate_int32) — the issue explicitly names this the shared validation home. describe_received gains string/bigint rendering (Node's determineSpecificType shape) — purely additive; fs never reaches those branches.
  • New buffer/validate.rs with js_buffer_validate_size, js_buffer_validate_concat_list, validate_concat_length, validate_byte_length_arg.
  • The size/list values reach validation as raw NaN-boxed values: the Buffer factory codegen (env_clones.rs, array_methods.rs) now calls the validators before coercing to i32 / treating as an ArrayHeader (the latter also closes a latent UB where Buffer.concat('x') cast a string pointer to an array header). byteLength / concat(totalLength) validate inside the runtime entry points.
  • Buffer.alloc() / allocUnsafe() with no argument now default to undefined so they surface ERR_INVALID_ARG_TYPE like Node, instead of silently allocating empty.

Testing

Verified byte-identical to Node v25 across the full buffer node-suite (120 cases, including 3 new arg-validation tests under allocation/, concat/, byte-length/) — 0 diffs, 0 regressions. cargo fmt --all --check clean.

Scope

#2013 is a cross-cutting umbrella (~85 tests across fs/buffer/net/http/crypto/zlib/process/url). fs landed earlier; this is the buffer slice. Buffer.compare is deferred (it lowers to an instance a.compare(b) dispatch — a separate path); remaining APIs remain follow-ups.

@proggeramlug proggeramlug merged commit 98c36e0 into main May 30, 2026
8 of 11 checks passed
@proggeramlug proggeramlug deleted the fix/dc-runstores-forward-args-3082 branch May 30, 2026 09:06
proggeramlug added a commit that referenced this pull request May 30, 2026
…_channel) (#3266)

* Revert "fix(node:console): validate Console stream write methods (#3080) (#3201)"

This reverts commit c9f5894.

* Revert "fix(node:diagnostics_channel): forward runStores callback arguments (#3082) (#3182)"

This reverts commit 98c36e0.

---------

Co-authored-by: Ralph Küpper <ralph@skelpo.com>
proggeramlug added a commit that referenced this pull request May 30, 2026
…l) + #3201 (console) re-merges (#3275)

* Revert "fix(node:diagnostics_channel): forward runStores callback arguments (#3082) (#3182)"

This reverts commit 98c36e0.

* Revert "fix(node:console): validate Console stream write methods (#3080) (#3201)"

This reverts commit c9f5894.

---------

Co-authored-by: Ralph Küpper <ralph@skelpo.com>
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.

1 participant