Repository navigation
fix(codemode): honor Uint8Array.from mappers, compare byte searches without coercion, skip flatMap holes, and truncate fractional radixes - #57285
Merged
Conversation
…ithout coercion, skip flatMap holes, and truncate fractional radixes Closes #57244, #56924, #56925, #51807. Co-authored-by: r266-tech <r266-tech@users.noreply.github.com> Co-authored-by: sdivyanshu90 <divyanshu74.80@gmail.com> Co-authored-by: icearia0219 <133481415+icearia0219@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Looks good. I ran the #57244 reproduction (extended with the byte-search, flatMap and radix cases) through CodeMode.execute on the base and on this branch. All four problems show up on the base and are gone here:
- the mapper and
thisArgare applied, and a non-callable mapper throws a TypeError - the
atobdecode gives[104, 105] includes('1'),indexOf(true)andlastIndexOf(null)no longer match[1].flatMap(() => [, 2])gives[2](35).toString(36.9)gives"z"
Invalid radixes still throw a RangeError that code can catch, and numeric start indexes are still converted to numbers. The mapper is checked before the source is read and runs only after it is fully read, which matches TypedArray.from. In packages/codemode, the codemode tests (1411 pass) and the type check pass.
Public API: unchanged. Only Code Mode's internal built-ins change.
No concerns.
3 tasks done
This was referenced Oct 20, 2026
3 tasks done
3 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Four reproduced Code Mode issues where a built-in silently returned a different value from JavaScript. The worst case: the usual browser base64 decode,
Uint8Array.from(atob(b64), (c) => c.charCodeAt(0)), returned all zeros, becauseUint8Array.fromignored its mapper.Closes #57244, #56924, #56925, #51807.
Change
Uint8Array.from(atob("aGk="), (c) => c.charCodeAt(0)) -[0, 0] mapper and thisArg ignored; a non-callable mapper accepted +[104, 105] mapper sees the original values after the source is consumed, as TypedArray.from does new Uint8Array([0, 1, 2]).includes("1") // also indexOf(true), lastIndexOf(null) -true search value coerced to a number +false non-numbers never match a byte; start indexes still coerce [1].flatMap(() => [, 2]) -[undefined, 2] spread turned holes into elements +[2] holes skipped; explicit undefined kept (35).toString(36.9) -RangeError range checked before the radix was truncated +"z" our check removed; the host truncates, then throws RangeError for 0, 37, NaN, ...Credit: the byte-search,
flatMap, and radix fixes are #56926 (@sdivyanshu90), #56927 (@sdivyanshu90), and #51808 (@icearia0219), unchanged except a comment. TheUint8Array.fromfix follows #57257 (@r266-tech) and its tests, but reusescollectBytesinstead of a second iteration loop (8 source lines instead of 30). All three are co-authors on the commit; those PRs can close once this merges.Out of scope
Uint8Array.fromstill rejects array-likes ({ length: 2, 0: 7 }), as before.Verification
bun test(packages/codemode)devdev; 0 new failuresbun typecheckbun run check