Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use iteration count for final size in map. Fixes #3155.
When the block passed to map makes modifications to the array under iteration, we may prematurely finish the map loop due to the size changing. However our logic for creating the mapped array assumed the new array's size would always be the same as the original array's size, leading to an array with null elements. This fix uses the iteration count as the final size, so we at least know how many elements in the new array were populated. Note that this behavior is officially undefined; modifying the array while performing internal iteration can cause peculiar effects across runtimes and potentially across the different versions of the same runtime. We add a regression spec here to at least make sure we don't produce an invalid array.