Map.prototype.forEach fires the callback for an empty Map
See original GitHub issueThis bug in the polyfill impacts React 16 users, and we are shipping React 16 very soon.
Specifically, Map.prototype.forEach
attempts to skip deleted items but then always calls the callback. The problem is that it may be the case that all items were deleted, in which case it should have skipped the callback. In other words, this check should be done just before calling the callback as well.
Specific reproducing case:
var x = new Map();
x.set(42, 'hi');
x.delete(42);
x.forEach(function() {
throw new Error('Should never get here!');
});
This breaks with the provided Map
polyfill but works with the native implementation.
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Map.prototype.forEach() - JavaScript - MDN Web Docs - Mozilla
The forEach method executes the provided callback once for each key of the map which actually exist. It is not invoked for keys...
Read more >Why when apply Map.prototype.forEach will return undefined?
It means the function forEach will execute the provided function f and nothing ... If the callback returns a value, this will be...
Read more >Deep Dive into JavaScript's Array Map Method - Robin Wieruch
While forEach does iterate through the entire array and it does execute its callback function once for every item in the array, there's...
Read more >Creating a .map() Method for Objects, Strings, Sets, and Maps
First, let's add an empty .map() method to the Object prototype. ... argument: the callback method we'd like to fire on each of...
Read more >Map.prototype.forEach() - JavaScript - UDN Web Docs: MDN Backup
The forEach method executes the provided callback once for each key of the map which actually exist. It is not invoked for keys...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@green-arrow 3.22 was shipped with the fix
Yeah, I didn’t meant to be pushing 😃. Just letting you know.