Skip to content

test262: Number conformance fixes (wave 15) - #77

Merged
hiett merged 1 commit into
experiment/js-frontendfrom
js262/wave15-Number
Jul 15, 2026
Merged

test262: Number conformance fixes (wave 15)#77
hiett merged 1 commit into
experiment/js-frontendfrom
js262/wave15-Number

Conversation

@hiett

@hiett hiett commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Renders Number.prototype.toString(radix) as "0".

Spec

Number.prototype is itself a Number object whose [[NumberData]] is +0 (ES2023 21.1.3). Per 21.1.3.6, Number.prototype.toString() and .toString(radix) for any radix 2-36 (or absent/undefined/10) therefore render as "0" (0 is the same digit in every base).

Bug

The receiver was the opaque builtin_prototype("Number") marker, whose ToNumber is NaN, so toString fell through to the generic object form and produced "[object Object]".

Fix

Route Number.prototype.toString(...) through the existing num_to_string_radix runtime op with a literal 0 receiver (new lower_number_proto_tostring helper in lower.gleam). No FFI/runtime change — num_to_string_radix already existed.

Result

test262 built-ins/Number: pass 55 -> 92 (RAN 100%), fail_assert 37 -> 0. Clears the whole Number/prototype/toString S15.7.4.2_A1/_A2 family (37 files), which each open with a Number.prototype.toString assertion before boxed-wrapper cases that already rendered correctly. Remaining 12 are Test262Error-class / Object.defineProperty / closure-capture-of-NaN tarpits, out of scope.

Spec-driven tests appended at EOF of js_compiler_test.gleam under // ==== Number (wave 15) ====.

Number.prototype is itself a Number object whose [[NumberData]] is +0
(ES2023 21.1.3), so Number.prototype.toString() and .toString(radix) for
any radix 2-36 must return "0" per 21.1.3.6. Previously the receiver was
the opaque builtin_prototype("Number") marker, whose ToNumber is NaN, so
toString fell through to the generic object form and produced
"[object Object]".

Route Number.prototype.toString(...) through num_to_string_radix with a
literal 0 receiver. Clears the whole test262 Number/prototype/toString
S15.7.4.2_A1/_A2 family (37 files), which each open with a
Number.prototype.toString assertion before the boxed-wrapper cases.
@hiett
hiett merged commit 27d29c8 into experiment/js-frontend Jul 15, 2026
1 check passed
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