fix(engine): preserve map and set iterator indices after clear (#5523) - #5528
Open
MayankSharma-2812 wants to merge 1 commit into
Open
MayankSharma-2812 wants to merge 1 commit into
MayankSharma-2812 wants to merge 1 commit into
Conversation
Test262 conformance changes
Tested main commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5528 +/- ##
===========================================
+ Coverage 47.24% 62.82% +15.58%
===========================================
Files 476 536 +60
Lines 46892 60298 +13406
===========================================
+ Hits 22154 37883 +15729
+ Misses 24738 22415 -2323 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
This Pull Request fixes/closes #5523.
Background
Per ECMAScript specifications (§24.1.3.1
Map.prototype.clearand §24.2.3.2Set.prototype.clear), calling.clear()on aMaporSetdoes not reset or shift the underlying entry sequence when an iterator orforEachloop is actively traversing the collection. Instead, existing entries are marked as empty. Any entries subsequently inserted into the collection must retain index positions after the cleared entries so that in-flight iterators can observe them.Previously,
OrderedMap::clear()andOrderedSet::clear()unconditionally called.clear()on the backingIndexMap/IndexSet. When subsequent insertions were performed, they were placed at index 0. Active iterators (whosenext_index >= 1) skipped them and terminated prematurely with{ value: undefined, done: true }.Changes
OrderedMap::clear(): Whenself.lock > 0(indicating an active iterator or loop), preserve index offsets by populating existing slots withMapKey::Empty(i)tombstones instead of dropping the backing map. Ifself.lock == 0, standard.clear()is retained.OrderedSet::clear(): Mirrored the tombstone preservation pattern forOrderedSetwhenself.lock > 0.OrderedSet::is_empty(): Fixed a latent bug whereis_empty()checkedself.inner.len() == 0instead ofself.len() == 0, which caused false negatives when tombstones were present.iterator_after_clear_and_setincore/engine/src/builtins/map/tests.rs.set_iterator_after_clear_and_addincore/engine/src/builtins/set/tests.rs.Verification
cargo test -p boa_engine iterator_after_clearpasses.builtins::map::testsand all 30 tests inbuiltins::set::testspass.cargo clippy -p boa_engine -- -D warningspassed with 0 warnings.cargo fmt -- --checkpassed cleanly.