-
-
Notifications
You must be signed in to change notification settings - Fork 158
fix(runtime): honor exotic indices in Array shift #8761
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
Closed
Closed
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
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,118 @@ | ||
| //! Regression coverage for the Array.prototype.shift exotic-index cluster in | ||
| //! #5898. Shift must use live ordinary-property operations and observe indexed | ||
| //! getter side effects before setting the final array length. | ||
|
|
||
| use std::path::PathBuf; | ||
| use std::process::Command; | ||
|
|
||
| fn perry_bin() -> PathBuf { | ||
| PathBuf::from(env!("CARGO_BIN_EXE_perry")) | ||
| } | ||
|
|
||
| #[test] | ||
| fn shift_observes_inherited_indices_holes_and_length_side_effects() { | ||
| let dir = tempfile::tempdir().expect("tempdir"); | ||
| let entry = dir.path().join("main.ts"); | ||
| let output = dir.path().join("main_bin"); | ||
| let runtime_dir = perry_bin() | ||
| .parent() | ||
| .expect("perry binary directory") | ||
| .to_path_buf(); | ||
| std::fs::write( | ||
| &entry, | ||
| r#" | ||
| (Array.prototype as any)[1] = 1; | ||
| const inherited = [0]; | ||
| inherited.length = 2; | ||
| console.log("inherited", inherited.shift(), inherited[0], inherited[1]); | ||
| delete (Array.prototype as any)[1]; | ||
|
|
||
| const holey: any[] = []; | ||
| holey[0] = 0; | ||
| holey[3] = 3; | ||
| console.log("holey-first", holey.shift(), holey.length, holey[0], holey[2]); | ||
| holey.length = 1; | ||
| console.log("holey-second", holey.shift(), holey.length); | ||
|
|
||
| const frozen: any[] = new Array(1); | ||
| let frozenGetterCalls = 0; | ||
| Object.defineProperty(Array.prototype, "0", { | ||
| configurable: true, | ||
| get() { | ||
| Object.freeze(frozen); | ||
| frozenGetterCalls++; | ||
| } | ||
| }); | ||
| try { | ||
| frozen.shift(); | ||
| console.log("frozen no throw"); | ||
| } catch (error) { | ||
| console.log("frozen", error instanceof TypeError, frozen.length, frozenGetterCalls); | ||
| } | ||
| delete (Array.prototype as any)[0]; | ||
|
|
||
| const readonlyLength: any[] = new Array(1); | ||
| let readonlyGetterCalls = 0; | ||
| Object.defineProperty(Array.prototype, "0", { | ||
| configurable: true, | ||
| get() { | ||
| Object.defineProperty(readonlyLength, "length", { writable: false }); | ||
| readonlyGetterCalls++; | ||
| } | ||
| }); | ||
| try { | ||
| readonlyLength.shift(); | ||
| console.log("readonly no throw"); | ||
| } catch (error) { | ||
| console.log( | ||
| "readonly", | ||
| error instanceof TypeError, | ||
| readonlyLength.length, | ||
| readonlyGetterCalls | ||
| ); | ||
| } | ||
| delete (Array.prototype as any)[0]; | ||
| "#, | ||
| ) | ||
| .expect("write entry"); | ||
|
|
||
| let compile = Command::new(perry_bin()) | ||
| .current_dir(dir.path()) | ||
| .arg("compile") | ||
| .arg(&entry) | ||
| .arg("-o") | ||
| .arg(&output) | ||
| .arg("--no-cache") | ||
| .env("PERRY_LIB_DIR", &runtime_dir) | ||
| .env("PERRY_NO_AUTO_OPTIMIZE", "1") | ||
| .env("PERRY_RS4GC", "0") | ||
| .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) | ||
| ); | ||
|
|
||
| let run = Command::new(&output) | ||
| .current_dir(dir.path()) | ||
| .output() | ||
| .expect("run compiled binary"); | ||
| assert!( | ||
| run.status.success(), | ||
| "compiled binary failed\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&run.stdout), | ||
| String::from_utf8_lossy(&run.stderr) | ||
| ); | ||
| assert_eq!( | ||
| String::from_utf8_lossy(&run.stdout), | ||
| concat!( | ||
| "inherited 0 1 1\n", | ||
| "holey-first 0 3 undefined 3\n", | ||
| "holey-second undefined 0\n", | ||
| "frozen true 1 1\n", | ||
| "readonly true 1 1\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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50369
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50369
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50370
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 14337
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 49487
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 28115
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 333
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 331
Use a throwing, prototype-aware
Sethelper for shift writes.js_array_set_f64_extendchecks only own descriptors. It does not invoke inherited setters and silently returns for missing setters or non-writable own properties.shiftrequiresSet(O, key, value, true), so these failures must throw before the loop continues.🤖 Prompt for AI Agents