mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:47:35 +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
|
@ -446,6 +446,46 @@ class ExpectationError extends Error {
|
|||
});
|
||||
}
|
||||
|
||||
toBeIteratorResultWithValue(value) {
|
||||
this.__expect(this.target !== undefined && this.target !== null);
|
||||
this.__doMatcher(() => {
|
||||
this.__expect(
|
||||
this.target.done === false,
|
||||
() =>
|
||||
`toGiveIteratorResultWithValue: expected 'done' to be _false_ got ${valueToString(
|
||||
this.target.done
|
||||
)}`
|
||||
);
|
||||
this.__expect(
|
||||
deepEquals(value, this.target.value),
|
||||
() =>
|
||||
`toGiveIteratorResultWithValue: expected 'value' to be _${valueToString(
|
||||
value
|
||||
)}_ got ${valueToString(this.target.value)}`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
toBeIteratorResultDone() {
|
||||
this.__expect(this.target !== undefined && this.target !== null);
|
||||
this.__doMatcher(() => {
|
||||
this.__expect(
|
||||
this.target.done === true,
|
||||
() =>
|
||||
`toGiveIteratorResultDone: expected 'done' to be _true_ got ${valueToString(
|
||||
this.target.done
|
||||
)}`
|
||||
);
|
||||
this.__expect(
|
||||
this.target.value === undefined,
|
||||
() =>
|
||||
`toGiveIteratorResultDone: expected 'value' to be _undefined_ got ${valueToString(
|
||||
this.target.value
|
||||
)}`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
__doMatcher(matcher) {
|
||||
if (!this.inverted) {
|
||||
matcher();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue