Skip to content

Commit

Permalink
[Robustness] Cache Array.isArray internally.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Sep 6, 2015
1 parent 8159480 commit b0647f6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

var _apply = Function.call.bind(Function.apply);
var _call = Function.call.bind(Function.call);
var isArray = Array.isArray;

var not = function notThunker(func) {
return function notThunk() { return !_apply(func, this, arguments); };
Expand Down Expand Up @@ -802,7 +803,7 @@
of: function of() {
var len = arguments.length;
var C = this;
var A = Array.isArray(C) || !ES.IsCallable(C) ? new Array(len) : ES.Construct(C, [len]);
var A = isArray(C) || !ES.IsCallable(C) ? new Array(len) : ES.Construct(C, [len]);
for (var k = 0; k < len; ++k) {
createDataPropertyOrThrow(A, k, arguments[k]);
}
Expand Down Expand Up @@ -1056,7 +1057,7 @@
var arrayFromHandlesIterables = (function () {
// Detects a bug in Webkit nightly r181886
var arr = Array.from([0].entries());
return arr.length === 1 && Array.isArray(arr[0]) && arr[0][0] === 0 && arr[0][1] === 0;
return arr.length === 1 && isArray(arr[0]) && arr[0][0] === 0 && arr[0][1] === 0;
}());
if (!arrayFromSwallowsNegativeLengths || !arrayFromHandlesIterables) {
overrideNative(Array, 'from', ArrayShims.from);
Expand Down Expand Up @@ -2247,7 +2248,7 @@
};

var addIterableToMap = function addIterableToMap(MapConstructor, map, iterable) {
if (Array.isArray(iterable) || Type.string(iterable)) {
if (isArray(iterable) || Type.string(iterable)) {
_forEach(iterable, function (entry) {
map.set(entry[0], entry[1]);
});
Expand Down Expand Up @@ -2281,7 +2282,7 @@
}
};
var addIterableToSet = function addIterableToSet(SetConstructor, set, iterable) {
if (Array.isArray(iterable) || Type.string(iterable)) {
if (isArray(iterable) || Type.string(iterable)) {
_forEach(iterable, function (value) {
set.add(value);
});
Expand Down

0 comments on commit b0647f6

Please sign in to comment.