-
-
Notifications
You must be signed in to change notification settings - Fork 158
fix(runtime): inherit Array-subclass fill #8987
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ### Fixed | ||
|
|
||
| - Array-subclass enumeration now matches Node: `Object.keys` and `for...in` | ||
| report only enumerable indices, while `Object.getOwnPropertyNames` also | ||
| reports `length`; inherited `Array.prototype.fill` no longer leaks as an own key. |
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
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
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
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
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
84 changes: 84 additions & 0 deletions
84
crates/perry/tests/issue_8953_array_subclass_enumeration.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| //! #8953: Array-subclass instances use an elements store for indices and | ||
| //! `length`, while inherited Array methods stay off the instance shape. | ||
| use std::path::PathBuf; | ||
| use std::process::{Command, Output}; | ||
|
|
||
| fn perry_bin() -> PathBuf { | ||
| PathBuf::from(env!("CARGO_BIN_EXE_perry")) | ||
| } | ||
|
|
||
| fn compile_and_run(source: &str) -> Output { | ||
| let dir = tempfile::tempdir().expect("tempdir"); | ||
| let entry = dir.path().join("main.js"); | ||
| let output = dir.path().join("main_bin"); | ||
| std::fs::write(&entry, source).expect("write entry"); | ||
| let compile = Command::new(perry_bin()) | ||
| .current_dir(dir.path()) | ||
| .arg("compile") | ||
| .arg(&entry) | ||
| .arg("-o") | ||
| .arg(&output) | ||
| .arg("--no-auto-optimize") | ||
| .output() | ||
| .expect("run perry compile"); | ||
| assert!( | ||
| compile.status.success(), | ||
| "perry compile failed\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&compile.stdout), | ||
| String::from_utf8_lossy(&compile.stderr) | ||
| ); | ||
| Command::new(&output).output().expect("run compiled binary") | ||
| } | ||
|
|
||
| #[test] | ||
| fn array_subclass_enumeration_matches_node_and_fill_is_inherited() { | ||
| let run = compile_and_run( | ||
| r#" | ||
| class A extends Array {} | ||
|
|
||
| const empty = new A(); | ||
| console.log("empty keys:", Object.keys(empty).join(",")); | ||
| let emptyForIn = []; | ||
| for (const key in empty) emptyForIn.push(key); | ||
| console.log("empty for-in:", emptyForIn.join(",")); | ||
| console.log("empty names:", Object.getOwnPropertyNames(empty).join(",")); | ||
| console.log("fill:", Object.hasOwn(empty, "fill"), typeof empty.fill); | ||
|
|
||
| const a = new A(); | ||
| a.push(1, 2, 3); | ||
| console.log("keys:", Object.keys(a).join(",")); | ||
| let keys = []; | ||
| for (const key in a) keys.push(key); | ||
| console.log("for-in:", keys.join(",")); | ||
| console.log("names:", Object.getOwnPropertyNames(a).join(",")); | ||
| a.fill(7, 1); | ||
| console.log("filled:", a.join(",")); | ||
| const inheritedFill = a.fill; | ||
| inheritedFill.call(a, 9, 2); | ||
| console.log("extracted fill:", a.join(",")); | ||
|
|
||
| class B extends Array { fill(value) { return "override:" + value; } } | ||
| const b = new B(); | ||
| console.log("override:", Object.hasOwn(b, "fill"), b.fill(5)); | ||
| "#, | ||
| ); | ||
| assert!( | ||
| run.status.success(), | ||
| "the #8953 fixture must not crash\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&run.stdout), | ||
| String::from_utf8_lossy(&run.stderr) | ||
| ); | ||
| assert_eq!( | ||
| String::from_utf8_lossy(&run.stdout), | ||
| "empty keys: \n\ | ||
| empty for-in: \n\ | ||
| empty names: length\n\ | ||
| fill: false function\n\ | ||
| keys: 0,1,2\n\ | ||
| for-in: 0,1,2\n\ | ||
| names: 0,1,2,length\n\ | ||
| filled: 1,7,7\n\ | ||
| extracted fill: 1,7,9\n\ | ||
| override: false override:5\n" | ||
| ); | ||
| } |
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.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Refresh the receiver and arguments across allocation points.
objis a raw pointer snapshot from before the allocation at Line 2102. A moving collection can invalidate it beforearray_prototype_property_valuereceivesobj as usize. That helper can then root or dereference the old address.The lookup and
clone_closure_rebind_thiscan also allocate before Lines 2149-2153 pass the originalargs_ptr. Refresh the receiver fromobject_handlebefore each fallback boundary, and passrefreshed_args()after rebinding the method.Proposed fix
🤖 Prompt for AI Agents