Fixed a bug where core-js was modifying native collection iterator prototypes #261
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First off, thanks for all the hard work that has gone into
core-js
!I ran into a fairly obscure bug in
core-js
's handling of collection iterator prototype chains while running compat-table tests on various platforms. I found thatcore-js
was causing collection iterator prototype chain tests to fail on platforms that already had native collection iterator support. The tests that were failing are for iterators on Set, Map, Array, and String, and they all look basically like this:As this test shows, the iterator should not have a
Symbol.iterator
own property, and neither should the iterator's prototype. The iterator's prototype's prototype, however, should have aSymbol.iterator
property, and that method should return the iterator. These tests pass in all modern browsers without any shims (Chrome, Firefox, Safari). They also pass whencore-js
is used in a browser that has no iterator support. These tests fail, however, when used in modern browsers in concert withcore-js
.It looks to me like there is a method in
_iter-define.js
that attempts to patch the iterator prototype chain for native iterator implementations only, but the implementation puts aSymbol.iterator
method on the iterator's prototype rather than the iterator's prototype's prototype. This is what causes the test failures.This PR attempts to fix this by patching the native iterator's prototype's prototype instead. I added tests for Set, Map, Array, and String, although those tests didn't fail with the pre-existing code. I think this because
npm run test
runs the test suite in Phantom, which doesn't have native iterator support. As I said above, this bug only shows up in browsers that have native iterator support.Apologies for any breaches of code style and such; I've never used LiveScript before and did not feel super confident about my changes there. Feedback is welcome, and thanks again for your work!