Skip to content

fix Set iterator not reflecting mutations after creation#1691

Open
RealColdFry wants to merge 1 commit intoTypeScriptToLua:masterfrom
RealColdFry:fix/set-iterator-mutation
Open

fix Set iterator not reflecting mutations after creation#1691
RealColdFry wants to merge 1 commit intoTypeScriptToLua:masterfrom
RealColdFry:fix/set-iterator-mutation

Conversation

@RealColdFry
Copy link

Fixes #1671

Set.values(), keys(), and entries() eagerly captured firstKey at iterator creation time. If the Set was mutated (e.g. via delete) before the iterator was consumed, the iterator still saw the stale firstKey. Read firstKey lazily on the first next() call instead.

…oLua#1671)

Set.values(), keys(), and entries() eagerly captured firstKey at
iterator creation time. If the Set was mutated (e.g. via delete)
before the iterator was consumed, the iterator still saw the stale
firstKey. Read firstKey lazily on the first next() call instead.
const nextKey = this.nextKey;
let key: T = this.firstKey!;
let key: T | undefined;
let started = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add another bool instead of simply checking if key is undefined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set.prototype.values() should change if origin Set changes.

2 participants