ReviewOS

zig-utils/zig-js

Numeric parsing: canonicalize coerced StringData before scanning

#677
Closed chris opened this 9 days ago ·
9 days ago

Parent: #473 Related: #666, #676

Problem

The global parseFloat and parseInt builtins call toStringV and then scan the returned bytes as canonical WTF-8. With physical flat Latin-1 storage active, a non-ASCII ECMAScript whitespace code unit such as U+00A0 is exposed as one physical byte instead of its canonical encoding. skipStrWhiteSpace therefore stops before the numeric prefix and returns NaN instead of the required number.

Scope

  • Route parseFloat and parseInt input coercion through the representation-aware WTF-8 helper before whitespace and numeric scanning.
  • Preserve exactly one ToString coercion, abrupt completion, radix coercion order, sign and Infinity handling, longest-prefix scanning, numeric rounding, ASCII borrowing, OOM propagation, and all existing accepted/rejected grammar.
  • Cover primitive and object-returned non-ASCII whitespace under canonical and physical flat-Latin-1 storage.

No-workaround rules

  • No flat-storage disablement, eager global canonicalization, replacement characters, duplicate coercion, alternate host parser, hidden retry, or Test262 exclusion.
  • No stack, queue, job, Promise, Worker, or Map/Set iterator changes.

Acceptance

  • Both numeric scanners consume canonical semantic WTF-8.
  • U+00A0 and other supported ECMAScript whitespace retain exact parsing behavior.
  • Custom ToString runs exactly once and before radix coercion where required.
  • The witness passes with canonical storage and with flat_storage_active enabled, then the switch is restored and not landed.
  • Nonzero parseFloat/parseInt Test262 accounting, focused Debug/ReleaseSafe/TSan, and full units pass with exact flips reported.
9 days ago

Landed fix(number): canonicalize parser StringData (#677) on main.

parseFloat and parseInt now coerce scanner input through the representation-aware WTF-8 boundary. The canonical and physical flat Latin-1 witness proves U+00A0 handling, one input coercion, and the required parseInt input-before-radix order without changing the numeric grammar.

Evidence: focused Debug, ReleaseSafe, TSan, and physical flat-storage witnesses each 1/1; Test262 parseFloat 54/54 and parseInt 55/55 before and after, 0 flips; full units 1770 passed, 1 skipped, 0 failed, 0 leaked across 1771 tests.

Sign in to comment on this issue.