js-on-sx: parseInt digit-walker, parseFloat prefix, Number('abc')→NaN, encodeURIComponent
Four coercion fixes that together unblock many test262 cases:
1. js-to-number(undefined) now returns NaN (was 0). Fixes Number(undefined),
isNaN(undefined), Math ops on undefined.
2. js-string-to-number returns NaN for non-numeric strings (via new
js-is-numeric-string?). Previously returned 0 for 'abc'.
3. parseInt('123abc', 10) → 123 (walks digits until first invalid char),
supports radix 2..36.
4. parseFloat('3.14xyz') → 3.14 (walks float prefix).
5. encodeURIComponent / decodeURIComponent / encodeURI / decodeURI —
new URI-helper implementations.
8 new unit tests, 514/516 total.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1213,6 +1213,28 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 3709)
|
||||
(eval "(js-eval \"var a=[1,2,3]; a.keys().join(',')\")")
|
||||
|
||||
;; ── Phase 11.coerce2: Number coercion edge cases ────────────
|
||||
(epoch 4000)
|
||||
(eval "(js-eval \"Number('abc')\")")
|
||||
(epoch 4001)
|
||||
(eval "(js-eval \"isNaN(Number('abc'))\")")
|
||||
(epoch 4002)
|
||||
(eval "(js-eval \"parseInt('123abc')\")")
|
||||
(epoch 4003)
|
||||
(eval "(js-eval \"parseFloat('3.14xyz')\")")
|
||||
(epoch 4004)
|
||||
(eval "(js-eval \"parseInt('0xff', 16)\")")
|
||||
(epoch 4005)
|
||||
(eval "(js-eval \"parseInt('1010', 2)\")")
|
||||
(epoch 4006)
|
||||
(eval "(js-eval \"Number(' 42 ')\")")
|
||||
(epoch 4007)
|
||||
(eval "(js-eval \"Number('')\")")
|
||||
(epoch 4008)
|
||||
(eval "(js-eval \"encodeURIComponent('a b')\")")
|
||||
(epoch 4009)
|
||||
(eval "(js-eval \"encodeURIComponent('a+b?c')\")")
|
||||
|
||||
;; ── Phase 11.objglobal: Object.getPrototypeOf, .create, .is, .hasOwn etc. ──
|
||||
(epoch 3900)
|
||||
(eval "(js-eval \"var o = Object.create(null); o.x=5; o.x\")")
|
||||
@@ -1947,6 +1969,16 @@ check 3707 "arr.toReversed" '"2,1,3"'
|
||||
check 3708 "arr.toSorted" '"1,1,3,4,5"'
|
||||
check 3709 "arr.keys" '"0,1,2"'
|
||||
|
||||
# ── Phase 11.coerce2: Number coercion edge cases ─────────────
|
||||
check 4001 "isNaN(Number('abc'))" 'true'
|
||||
check 4002 "parseInt leading digits" '123'
|
||||
check 4003 "parseFloat leading" '3.14'
|
||||
check 4005 "parseInt radix 2" '10'
|
||||
check 4006 "Number with spaces" '42'
|
||||
check 4007 "Number('')" '0'
|
||||
check 4008 "encodeURIComponent space" '"a%20b"'
|
||||
check 4009 "encodeURIComponent +?" '"a%2Bb%3Fc"'
|
||||
|
||||
# ── Phase 11.objglobal: Object.getPrototypeOf, .create, .is, .hasOwn ──
|
||||
check 3900 "Object.create(null)" '5'
|
||||
check 3901 "Object.is(NaN,NaN)" 'true'
|
||||
|
||||
Reference in New Issue
Block a user