Skip to content
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

Fix: Do not call callback for Map.prototype.forEach if no map entries exist #1300

Merged
merged 5 commits into from Sep 11, 2017

Conversation

JakeChampion
Copy link
Collaborator

Fixes #1299

@gaearon
Copy link

gaearon commented Sep 11, 2017

Does this work for case like

x.set(42, 'hi')
x.set(43, 'bye')
x.delete(43)

(edit: typo)

?

My intuition is it would have the same problem, calling the callback extra time at the very end because of the deleted item. size wouldn't be 0 but it would still fail.

@JakeChampion
Copy link
Collaborator Author

@gaearon That should work already but just in case I have added a test with your code.

@gaearon
Copy link

gaearon commented Sep 11, 2017

Apologies for dumb question but could you help me understand why it also works? Since the new check is for .size I would expect the same bug to manifest itself if the last item is marked with undef sentinel, but the map is not empty.

@JakeChampion JakeChampion requested a review from a team September 11, 2017 15:05
@JakeChampion JakeChampion added this to the 3.22 milestone Sep 11, 2017
@JakeChampion JakeChampion changed the title Fix: Do not call callbakc for Map.prototype.forEach if no map entries exist Fix: Do not call callback for Map.prototype.forEach if no map entries exist Sep 11, 2017
@gaearon
Copy link

gaearon commented Sep 11, 2017

I think I understand now. If it's the last one, you decrement size. If it's not, then next() will skip the missing items next time.

@JakeChampion
Copy link
Collaborator Author

@gaearon There was still a bug in there, thanks for getting me to look at it even more thoroughly 👍

@JakeChampion
Copy link
Collaborator Author

JakeChampion commented Sep 11, 2017

Screenshots of tests passing in IE 7 and IE 8:

Screenshot of tests passing in IE7

Screenshot of tests passing in IE8

@JakeChampion JakeChampion merged commit 876779e into master Sep 11, 2017
@JakeChampion JakeChampion deleted the mapfix branch September 11, 2017 16:27
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Map.prototype.forEach fires the callback for an empty Map
3 participants