Skip to content

Commit

Permalink
access the .next method once, at the beginning, of the iteration pr…
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Sep 1, 2019
1 parent a241c18 commit 2dff41a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Added a workaround for iOS Safari MessageChannel + bfcache bug, [#624](https:/zloirock/core-js/issues/624)
- Added compat data for Node 12.9, FF 69 and Phantom 1.9
- Fixed unnecessary exposing on `Symbol.matchAll` in `esnext.string.match-all`, [#626](https:/zloirock/core-js/issues/626)
- Fixed missed cases [access the `.next` method once, at the beginning, of the iteration protocol](https:/tc39/ecma262/issues/976)
- Show similar `postinstall` messages only once per `npm i`, [#597](https:/zloirock/core-js/issues/597), thanks [@remy](https:/remy)

##### 3.2.1 - 2019.08.12
Expand Down
5 changes: 3 additions & 2 deletions packages/core-js/internals/array-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ module.exports = function from(arrayLike /* , mapfn = undefined, thisArg = undef
var mapping = mapfn !== undefined;
var index = 0;
var iteratorMethod = getIteratorMethod(O);
var length, result, step, iterator;
var length, result, step, iterator, next;
if (mapping) mapfn = bind(mapfn, argumentsLength > 2 ? arguments[2] : undefined, 2);
// if the target is not iterable or it's an array with the default iterator - use a simple case
if (iteratorMethod != undefined && !(C == Array && isArrayIteratorMethod(iteratorMethod))) {
iterator = iteratorMethod.call(O);
next = iterator.next;
result = new C();
for (;!(step = iterator.next()).done; index++) {
for (;!(step = next.call(iterator)).done; index++) {
createProperty(result, index, mapping
? callWithSafeIterationClosing(iterator, mapfn, [step.value, index], true)
: step.value
Expand Down
5 changes: 3 additions & 2 deletions packages/core-js/internals/typed-array-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ module.exports = function from(source /* , mapfn, thisArg */) {
var mapfn = argumentsLength > 1 ? arguments[1] : undefined;
var mapping = mapfn !== undefined;
var iteratorMethod = getIteratorMethod(O);
var i, length, result, step, iterator;
var i, length, result, step, iterator, next;
if (iteratorMethod != undefined && !isArrayIteratorMethod(iteratorMethod)) {
iterator = iteratorMethod.call(O);
next = iterator.next;
O = [];
while (!(step = iterator.next()).done) {
while (!(step = next.call(iterator)).done) {
O.push(step.value);
}
}
Expand Down
12 changes: 7 additions & 5 deletions packages/core-js/modules/web.url-search-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ var URLSearchParamsConstructor = function URLSearchParams(/* init */) {
var init = arguments.length > 0 ? arguments[0] : undefined;
var that = this;
var entries = [];
var iteratorMethod, iterator, step, entryIterator, first, second, key;
var iteratorMethod, iterator, next, step, entryIterator, entryNext, first, second, key;

setInternalState(that, {
type: URL_SEARCH_PARAMS,
Expand All @@ -135,12 +135,14 @@ var URLSearchParamsConstructor = function URLSearchParams(/* init */) {
iteratorMethod = getIteratorMethod(init);
if (typeof iteratorMethod === 'function') {
iterator = iteratorMethod.call(init);
while (!(step = iterator.next()).done) {
next = iterator.next;
while (!(step = next.call(iterator)).done) {
entryIterator = getIterator(anObject(step.value));
entryNext = entryIterator.next;
if (
(first = entryIterator.next()).done ||
(second = entryIterator.next()).done ||
!entryIterator.next().done
(first = entryNext.call(entryIterator)).done ||
(second = entryNext.call(entryIterator)).done ||
!entryNext.call(entryIterator).done
) throw TypeError('Expected sequence with length 2');
entries.push({ key: first.value + '', value: second.value + '' });
}
Expand Down

0 comments on commit 2dff41a

Please sign in to comment.