Skip to content

Commit

Permalink
Handle a Microsoft Edge v0.11 bug with Array.from:
Browse files Browse the repository at this point in the history
http://www.ecma-international.org/ecma-262/6.0/#sec-array.from says that "if mapFn is undefined, let mapping be false", which means it doesn't matter if it's provided undefined, or not provided. Edge v0.11 only ignores it if it's not provided.
  • Loading branch information
ljharb committed Jun 21, 2015
1 parent 75c5752 commit 4bbe238
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,21 @@
if (!arrayFromSwallowsNegativeLengths || !arrayFromHandlesIterables) {
overrideNative(Array, 'from', ArrayShims.from);
}
var arrayFromHandlesUndefinedMapFunction = (function () {
// Microsoft Edge v0.11 throws if the mapFn argument is *provided* but undefined,
// but the spec doesn't care if it's provided or not - undefined doesn't throw.
return valueOrFalseIfThrows(function () { return Array.from([0], undefined); });
}());
if (!arrayFromHandlesUndefinedMapFunction) {
var origArrayFrom = Array.from;
overrideNative(Array, 'from', function from(items) {
if (arguments.length > 0 && typeof arguments[1] !== 'undefined') {
return _apply(origArrayFrom, this, arguments);
} else {
return _call(origArrayFrom, this, items);
}
});
}

var toLengthsCorrectly = function (method, reversed) {
var obj = { length: -1 };
Expand Down

0 comments on commit 4bbe238

Please sign in to comment.