-
-
Notifications
You must be signed in to change notification settings - Fork 155
fix(runtime): <index> in <Uint8Array> / Buffer resolves numeric indices (#6148)
#6163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
String-encoded numeric indices (
"0" in buf) incorrectly returnfalse.The buffer branch only matches string keys against the five named view slots and returns
falsefor everything else. This means"0" in new Uint8Array([1,2,3])returnsfalse, when per spec it should returntrue—ToPropertyKey("0")resolves to an in-bounds index.The typed-array branch above (lines 272–281) delegates all string keys to
typed_array_has_property, which handles string-encoded indices. The buffer branch lacks equivalent handling. The comment at lines 326–330 claims this is "the same string-key gap the registered typed-array arm above has," but the typed-array arm handles string keys comprehensively — the string-encoded index gap is unique to this buffer branch.This is not covered by the PR's stated scope limitation (which only excludes inherited prototype members like
"subarray" in u8). String-encoded numeric indices are own properties, not inherited members.🐛 Proposed fix: add `canonical_array_index` check for string-encoded indices
if key_val.is_any_string() { // Own view slots, always present. Inherited prototype MEMBERS // (`subarray`, `map`, `toString`, …) via `in` on a buffer are a // separate follow-up — the same string-key gap the registered // typed-array arm above has, tied to lazy `%TypedArray%` // prototype population. let mut sso = [0u8; crate::value::SHORT_STRING_MAX_LEN]; if let Some(name) = unsafe { crate::string::js_string_key_bytes(key_val, &mut sso) } .and_then(|b| std::str::from_utf8(b).ok()) { if matches!( name, "length" | "byteLength" | "byteOffset" | "BYTES_PER_ELEMENT" | "buffer" ) { return nanbox_true; } + // String-encoded numeric indices (e.g. `"0" in buf`). + if let Some(idx) = super::super::canonical_array_index(name) { + if (idx as i32) < len { + return nanbox_true; + } + } } return nanbox_false; }📝 Committable suggestion
🤖 Prompt for AI Agents