Skip to content

Commit

Permalink
add a workaround for prevent array iteration deoptimisation in v8, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Mar 27, 2018
1 parent 1c4bbc5 commit 4116c2d
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions packages/core-js/internals/check-correctness-of-iteration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,35 @@ var ITERATOR = require('../internals/well-known-symbol')('iterator');
var SAFE_CLOSING = false;

try {
var iteratorWithReturn = [7][ITERATOR]();
iteratorWithReturn['return'] = function () { SAFE_CLOSING = true; };
var called = 0;
var iteratorWithReturn = {
next: function () {
return { done: !!called++ };
},
'return': function () {
SAFE_CLOSING = true;
}
};
iteratorWithReturn[ITERATOR] = function () {
return this;
};
// eslint-disable-next-line no-throw-literal
Array.from(iteratorWithReturn, function () { throw 2; });
} catch (e) { /* empty */ }

module.exports = function (exec, SKIP_CLOSING) {
if (!SKIP_CLOSING && !SAFE_CLOSING) return false;
var safe = false;
var ITERATION_SUPPORT = false;
try {
var array = [7];
var iterator = array[ITERATOR]();
iterator.next = function () { return { done: safe = true }; };
array[ITERATOR] = function () { return iterator; };
exec(array);
var object = {};
object[ITERATOR] = function () {
return {
next: function () {
return { done: ITERATION_SUPPORT = true };
}
};
};
exec(object);
} catch (e) { /* empty */ }
return safe;
return ITERATION_SUPPORT;
};

0 comments on commit 4116c2d

Please sign in to comment.