mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 08:18:12 +00:00
LibJS: Fix Map Iterators when elements are deleted during iteration
Before this would assume that the element found in operator++ was still valid when dereferencing it in operator*. Since any code can have been run since that increment this is not always valid. To further simplify the logic of the iterator we no longer store the index in an optional.
This commit is contained in:
parent
fdbfe85a87
commit
45646eee43
7 changed files with 302 additions and 20 deletions
|
@ -34,7 +34,7 @@ bool Map::map_remove(Value const& key)
|
|||
{
|
||||
Optional<size_t> index;
|
||||
|
||||
for (auto it = m_keys.begin(); it != m_keys.end(); ++it) {
|
||||
for (auto it = m_keys.begin(); !it.is_end(); ++it) {
|
||||
if (ValueTraits::equals(*it, key)) {
|
||||
index = it.key();
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue