Skip to content

fix(runtime): stringify BigInt elements in Array.prototype.join#4426

Merged
proggeramlug merged 1 commit into
mainfrom
fix-array-join-bigint
Jun 4, 2026
Merged

fix(runtime): stringify BigInt elements in Array.prototype.join#4426
proggeramlug merged 1 commit into
mainfrom
fix-array-join-bigint

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

What

Array.prototype.join now stringifies BigInt elements correctly. A BigInt is
NaN-boxed with BIGINT_TAG (not POINTER_TAG), so it bypassed the pointer arm in
js_array_join and fell through to the "[object Object]" catch-all. Added an
is_bigint() arm that emits ToString(BigInt) — the plain decimal digits, no n
suffix.

This also fixes Array.prototype.toString, String(array), and template-literal
interpolation of arrays, which all route through join.

Why

[10n].join() returned "[object Object]" instead of "10". Surfaced while
fixing BigInt.asUintN/asIntN ToBigInt coercion (sibling PR): test262
built-ins/BigInt/{asIntN,asUintN}/bigint-tobigint.js feeds [10n]/["10"]
through ToBigInt (→ array.toString() → BigInt parse), which silently corrupted.

Verification

Byte-identical to node --experimental-strip-types, in both PERRY_NO_AUTO_OPTIMIZE=1
and the default (codegen js_array_join_value) build:

[1n,2n,3n].join("-")  => "1-2-3"
[1n,2n,3n].toString() => "1,2,3"
String([100n, -5n])   => "100,-5"
`${[7n,8n]}`          => "7,8"
[1, 2n, "x"].join(",")=> "1,2,x"
  • cargo test --release -p perry-runtime --lib green.
  • Purely additive: only the previously-"[object Object]" BigInt-element path
    changes; non-BigInt arrays are untouched.

@proggeramlug proggeramlug force-pushed the fix-array-join-bigint branch from 8271159 to 77411a0 Compare June 4, 2026 17:19
@proggeramlug proggeramlug merged commit 214a871 into main Jun 4, 2026
13 checks passed
@proggeramlug proggeramlug deleted the fix-array-join-bigint branch June 4, 2026 17:52
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