summaryrefslogtreecommitdiffstats
path: root/js/vendor/es6-shim/es6-shim.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/vendor/es6-shim/es6-shim.js')
-rw-r--r--js/vendor/es6-shim/es6-shim.js890
1 files changed, 624 insertions, 266 deletions
diff --git a/js/vendor/es6-shim/es6-shim.js b/js/vendor/es6-shim/es6-shim.js
index d1d052fe3..f6058ae2d 100644
--- a/js/vendor/es6-shim/es6-shim.js
+++ b/js/vendor/es6-shim/es6-shim.js
@@ -2,8 +2,8 @@
* https://github.com/paulmillr/es6-shim
* @license es6-shim Copyright 2013-2015 by Paul Miller (http://paulmillr.com)
* and contributors, MIT License
- * es6-shim: v0.33.12
- * see https://github.com/paulmillr/es6-shim/blob/0.33.12/LICENSE
+ * es6-shim: v0.34.1
+ * see https://github.com/paulmillr/es6-shim/blob/0.34.1/LICENSE
* Details and documentation:
* https://github.com/paulmillr/es6-shim/
*/
@@ -17,7 +17,7 @@
define(factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
- // only CommonJS-like enviroments that support module.exports,
+ // only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
@@ -30,6 +30,7 @@
var _apply = Function.call.bind(Function.apply);
var _call = Function.call.bind(Function.call);
var isArray = Array.isArray;
+ var keys = Object.keys;
var not = function notThunker(func) {
return function notThunk() { return !_apply(func, this, arguments); };
@@ -79,13 +80,65 @@
// Define configurable, writable and non-enumerable props
// if they don’t exist.
- var defineProperties = function (object, map) {
- _forEach(Object.keys(map), function (name) {
+ var defineProperties = function (object, map, forceOverride) {
+ _forEach(keys(map), function (name) {
var method = map[name];
- defineProperty(object, name, method, false);
+ defineProperty(object, name, method, !!forceOverride);
});
};
+ var _toString = Function.call.bind(Object.prototype.toString);
+ var isCallable = typeof /abc/ === 'function' ? function IsCallableSlow(x) {
+ // Some old browsers (IE, FF) say that typeof /abc/ === 'function'
+ return typeof x === 'function' && _toString(x) === '[object Function]';
+ } : function IsCallableFast(x) { return typeof x === 'function'; };
+
+ var Value = {
+ getter: function (object, name, getter) {
+ if (!supportsDescriptors) {
+ throw new TypeError('getters require true ES5 support');
+ }
+ Object.defineProperty(object, name, {
+ configurable: true,
+ enumerable: false,
+ get: getter
+ });
+ },
+ proxy: function (originalObject, key, targetObject) {
+ if (!supportsDescriptors) {
+ throw new TypeError('getters require true ES5 support');
+ }
+ var originalDescriptor = Object.getOwnPropertyDescriptor(originalObject, key);
+ Object.defineProperty(targetObject, key, {
+ configurable: originalDescriptor.configurable,
+ enumerable: originalDescriptor.enumerable,
+ get: function getKey() { return originalObject[key]; },
+ set: function setKey(value) { originalObject[key] = value; }
+ });
+ },
+ redefine: function (object, property, newValue) {
+ if (supportsDescriptors) {
+ var descriptor = Object.getOwnPropertyDescriptor(object, property);
+ descriptor.value = newValue;
+ Object.defineProperty(object, property, descriptor);
+ } else {
+ object[property] = newValue;
+ }
+ },
+ defineByDescriptor: function (object, property, descriptor) {
+ if (supportsDescriptors) {
+ Object.defineProperty(object, property, descriptor);
+ } else if ('value' in descriptor) {
+ object[property] = descriptor.value;
+ }
+ },
+ preserveToString: function (target, source) {
+ if (source && isCallable(source.toString)) {
+ defineProperty(target, 'toString', source.toString.bind(source), true);
+ }
+ }
+ };
+
// Simple shim for Object.create on ES3 browsers
// (unlike real shim, no attempt to support `prototype === null`)
var create = Object.create || function (prototype, properties) {
@@ -93,7 +146,7 @@
Prototype.prototype = prototype;
var object = new Prototype();
if (typeof properties !== 'undefined') {
- Object.keys(properties).forEach(function (key) {
+ keys(properties).forEach(function (key) {
Value.defineByDescriptor(object, key, properties[key]);
});
}
@@ -130,8 +183,8 @@
var globals = getGlobal();
var globalIsFinite = globals.isFinite;
var _indexOf = Function.call.bind(String.prototype.indexOf);
- var _toString = Function.call.bind(Object.prototype.toString);
var _concat = Function.call.bind(Array.prototype.concat);
+ var _sort = Function.call.bind(Array.prototype.sort);
var _strSlice = Function.call.bind(String.prototype.slice);
var _push = Function.call.bind(Array.prototype.push);
var _pushApply = Function.apply.bind(Array.prototype.push);
@@ -186,6 +239,14 @@
}
};
+ var overrideNative = function overrideNative(object, property, replacement) {
+ var original = object[property];
+ defineProperty(object, property, replacement, true);
+ Value.preserveToString(object[property], original);
+ };
+
+ var hasSymbols = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' && Type.symbol(Symbol());
+
// This is a private name in the es6 spec, equal to '[Symbol.iterator]'
// we're going to use an arbitrary _-prefixed name to make our shims
// work properly with each other, even though we don't have full Iterator
@@ -205,6 +266,8 @@
}
var Reflect = globals.Reflect;
+ var $String = String;
+
var ES = {
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-call-f-v-args
Call: function Call(F, V) {
@@ -220,24 +283,30 @@
if (x == null) {
throw new TypeError(optMessage || 'Cannot call method on ' + x);
}
+ return x;
},
+ // This might miss the "(non-standard exotic and does not implement
+ // [[Call]])" case from
+ // http://www.ecma-international.org/ecma-262/6.0/#sec-typeof-operator-runtime-semantics-evaluation
+ // but we can't find any evidence these objects exist in practice.
+ // If we find some in the future, you could test `Object(x) === x`,
+ // which is reliable according to
+ // http://www.ecma-international.org/ecma-262/6.0/#sec-toobject
+ // but is not well optimized by runtimes and creates an object
+ // whenever it returns false, and thus is very slow.
TypeIsObject: function (x) {
- /* jshint eqnull:true */
- // this is expensive when it returns false; use this function
- // when you expect it to return true in the common case.
- return x != null && Object(x) === x;
+ if (x === void 0 || x === null || x === true || x === false) {
+ return false;
+ }
+ return typeof x === 'function' || typeof x === 'object';
},
ToObject: function (o, optMessage) {
- ES.RequireObjectCoercible(o, optMessage);
- return Object(o);
+ return Object(ES.RequireObjectCoercible(o, optMessage));
},
- IsCallable: function (x) {
- // some versions of IE say that typeof /abc/ === 'function'
- return typeof x === 'function' && _toString(x) === '[object Function]';
- },
+ IsCallable: isCallable,
IsConstructor: function (x) {
// We can't tell callables from constructors in ES5
@@ -301,7 +370,7 @@
// Better diagnostics if itFn is null or undefined
throw new TypeError('value is not an iterable');
}
- var it = _call(itFn, o);
+ var it = ES.Call(itFn, o);
if (!ES.TypeIsObject(it)) {
throw new TypeError('bad iterator');
}
@@ -330,7 +399,7 @@
}
var innerResult, innerException;
try {
- innerResult = _call(returnMethod, iterator);
+ innerResult = ES.Call(returnMethod, iterator);
} catch (e) {
innerException = e;
}
@@ -362,7 +431,7 @@
Construct: function (C, args, newTarget, isES6internal) {
var target = typeof newTarget === 'undefined' ? C : newTarget;
- if (!isES6internal) {
+ if (!isES6internal && Reflect.construct) {
// Try to use Reflect.construct if available
return Reflect.construct(C, args, target);
}
@@ -400,64 +469,132 @@
},
CreateHTML: function (string, tag, attribute, value) {
- var S = String(string);
+ var S = ES.ToString(string);
var p1 = '<' + tag;
if (attribute !== '') {
- var V = String(value);
+ var V = ES.ToString(value);
var escapedV = V.replace(/"/g, '&quot;');
p1 += ' ' + attribute + '="' + escapedV + '"';
}
var p2 = p1 + '>';
var p3 = p2 + S;
return p3 + '</' + tag + '>';
+ },
+
+ IsRegExp: function IsRegExp(argument) {
+ if (!ES.TypeIsObject(argument)) {
+ return false;
+ }
+ var isRegExp = argument[Symbol.match];
+ if (typeof isRegExp !== 'undefined') {
+ return !!isRegExp;
+ }
+ return Type.regex(argument);
+ },
+
+ ToString: function ToString(string) {
+ return $String(string);
}
};
- var Value = {
- getter: function (object, name, getter) {
- if (!supportsDescriptors) {
- throw new TypeError('getters require true ES5 support');
+ // Well-known Symbol shims
+ if (supportsDescriptors && hasSymbols) {
+ var defineWellKnownSymbol = function defineWellKnownSymbol(name) {
+ if (Type.symbol(Symbol[name])) {
+ return Symbol[name];
}
- Object.defineProperty(object, name, {
- configurable: true,
+ var sym = Symbol['for']('Symbol.' + name);
+ Object.defineProperty(Symbol, name, {
+ configurable: false,
enumerable: false,
- get: getter
+ writable: false,
+ value: sym
});
- },
- proxy: function (originalObject, key, targetObject) {
- if (!supportsDescriptors) {
- throw new TypeError('getters require true ES5 support');
- }
- var originalDescriptor = Object.getOwnPropertyDescriptor(originalObject, key);
- Object.defineProperty(targetObject, key, {
- configurable: originalDescriptor.configurable,
- enumerable: originalDescriptor.enumerable,
- get: function getKey() { return originalObject[key]; },
- set: function setKey(value) { originalObject[key] = value; }
+ return sym;
+ };
+ if (!Type.symbol(Symbol.search)) {
+ var symbolSearch = defineWellKnownSymbol('search');
+ var originalSearch = String.prototype.search;
+ defineProperty(RegExp.prototype, symbolSearch, function search(string) {
+ return ES.Call(originalSearch, string, [this]);
});
- },
- redefine: function (object, property, newValue) {
- if (supportsDescriptors) {
- var descriptor = Object.getOwnPropertyDescriptor(object, property);
- descriptor.value = newValue;
- Object.defineProperty(object, property, descriptor);
- } else {
- object[property] = newValue;
- }
- },
- defineByDescriptor: function (object, property, descriptor) {
- if (supportsDescriptors) {
- Object.defineProperty(object, property, descriptor);
- } else if ('value' in descriptor) {
- object[property] = descriptor.value;
- }
- },
- preserveToString: function (target, source) {
- if (source && ES.IsCallable(source.toString)) {
- defineProperty(target, 'toString', source.toString.bind(source), true);
- }
+ var searchShim = function search(regexp) {
+ var O = ES.RequireObjectCoercible(this);
+ if (regexp !== null && typeof regexp !== 'undefined') {
+ var searcher = ES.GetMethod(regexp, symbolSearch);
+ if (typeof searcher !== 'undefined') {
+ return ES.Call(searcher, regexp, [O]);
+ }
+ }
+ return ES.Call(originalSearch, O, [ES.ToString(regexp)]);
+ };
+ overrideNative(String.prototype, 'search', searchShim);
}
- };
+ if (!Type.symbol(Symbol.replace)) {
+ var symbolReplace = defineWellKnownSymbol('replace');
+ var originalReplace = String.prototype.replace;
+ defineProperty(RegExp.prototype, symbolReplace, function replace(string, replaceValue) {
+ return ES.Call(originalReplace, string, [this, replaceValue]);
+ });
+ var replaceShim = function replace(searchValue, replaceValue) {
+ var O = ES.RequireObjectCoercible(this);
+ if (searchValue !== null && typeof searchValue !== 'undefined') {
+ var replacer = ES.GetMethod(searchValue, symbolReplace);
+ if (typeof replacer !== 'undefined') {
+ return ES.Call(replacer, searchValue, [O, replaceValue]);
+ }
+ }
+ return ES.Call(originalReplace, O, [ES.ToString(searchValue), replaceValue]);
+ };
+ overrideNative(String.prototype, 'replace', replaceShim);
+ }
+ if (!Type.symbol(Symbol.split)) {
+ var symbolSplit = defineWellKnownSymbol('split');
+ var originalSplit = String.prototype.split;
+ defineProperty(RegExp.prototype, symbolSplit, function split(string, limit) {
+ return ES.Call(originalSplit, string, [this, limit]);
+ });
+ var splitShim = function split(separator, limit) {
+ var O = ES.RequireObjectCoercible(this);
+ if (separator !== null && typeof separator !== 'undefined') {
+ var splitter = ES.GetMethod(separator, symbolSplit);
+ if (typeof splitter !== 'undefined') {
+ return ES.Call(splitter, separator, [O, limit]);
+ }
+ }
+ return ES.Call(originalSplit, O, [ES.ToString(separator), limit]);
+ };
+ overrideNative(String.prototype, 'split', splitShim);
+ }
+ var symbolMatchExists = Type.symbol(Symbol.match);
+ var stringMatchIgnoresSymbolMatch = symbolMatchExists && (function () {
+ // Firefox 41, through Nightly 45 has Symbol.match, but String#match ignores it.
+ // Firefox 40 and below have Symbol.match but String#match works fine.
+ var o = {};
+ o[Symbol.match] = function () { return 42; };
+ return 'a'.match(o) !== 42;
+ }());
+ if (!symbolMatchExists || stringMatchIgnoresSymbolMatch) {
+ var symbolMatch = defineWellKnownSymbol('match');
+
+ var originalMatch = String.prototype.match;
+ defineProperty(RegExp.prototype, symbolMatch, function match(string) {
+ return ES.Call(originalMatch, string, [this]);
+ });
+
+ var matchShim = function match(regexp) {
+ var O = ES.RequireObjectCoercible(this);
+ if (regexp !== null && typeof regexp !== 'undefined') {
+ var matcher = ES.GetMethod(regexp, symbolMatch);
+ if (typeof matcher !== 'undefined') {
+ return ES.Call(matcher, regexp, [O]);
+ }
+ }
+ return ES.Call(originalMatch, O, [ES.ToString(regexp)]);
+ };
+ overrideNative(String.prototype, 'match', matchShim);
+ }
+ }
var wrapConstructor = function wrapConstructor(original, replacement, keysToSkip) {
Value.preserveToString(replacement, original);
@@ -487,12 +624,6 @@
}
};
- var overrideNative = function overrideNative(object, property, replacement) {
- var original = object[property];
- defineProperty(object, property, replacement, true);
- Value.preserveToString(object[property], original);
- };
-
var addIterator = function (prototype, impl) {
var implementation = impl || function iterator() { return this; };
defineProperty(prototype, $iterator$, implementation);
@@ -553,7 +684,7 @@
// https://bugzilla.mozilla.org/show_bug.cgi?id=1062484
if (String.fromCodePoint && String.fromCodePoint.length !== 1) {
var originalFromCodePoint = String.fromCodePoint;
- overrideNative(String, 'fromCodePoint', function fromCodePoint(codePoints) { return _apply(originalFromCodePoint, this, arguments); });
+ overrideNative(String, 'fromCodePoint', function fromCodePoint(codePoints) { return ES.Call(originalFromCodePoint, this, arguments); });
}
var StringShims = {
@@ -590,14 +721,14 @@
var nextIndex = 0;
var nextKey, next, nextSeg, nextSub;
while (nextIndex < literalsegments) {
- nextKey = String(nextIndex);
- nextSeg = String(rawString[nextKey]);
+ nextKey = ES.ToString(nextIndex);
+ nextSeg = ES.ToString(rawString[nextKey]);
_push(stringElements, nextSeg);
if (nextIndex + 1 >= literalsegments) {
break;
}
next = nextIndex + 1 < arguments.length ? arguments[nextIndex + 1] : '';
- nextSub = String(next);
+ nextSub = ES.ToString(next);
_push(stringElements, nextSub);
nextIndex += 1;
}
@@ -622,8 +753,7 @@
var StringPrototypeShims = {
repeat: function repeat(times) {
- ES.RequireObjectCoercible(this);
- var thisStr = String(this);
+ var thisStr = ES.ToString(ES.RequireObjectCoercible(this));
var numTimes = ES.ToInteger(times);
if (numTimes < 0 || numTimes >= stringMaxLength) {
throw new RangeError('repeat count must be less than infinity and not overflow maximum string size');
@@ -632,46 +762,50 @@
},
startsWith: function startsWith(searchString) {
- ES.RequireObjectCoercible(this);
- var thisStr = String(this);
- if (Type.regex(searchString)) {
+ var S = ES.ToString(ES.RequireObjectCoercible(this));
+ if (ES.IsRegExp(searchString)) {
throw new TypeError('Cannot call method "startsWith" with a regex');
}
- var searchStr = String(searchString);
- var startArg = arguments.length > 1 ? arguments[1] : void 0;
- var start = _max(ES.ToInteger(startArg), 0);
- return _strSlice(thisStr, start, start + searchStr.length) === searchStr;
+ var searchStr = ES.ToString(searchString);
+ var position;
+ if (arguments.length > 1) {
+ position = arguments[1];
+ }
+ var start = _max(ES.ToInteger(position), 0);
+ return _strSlice(S, start, start + searchStr.length) === searchStr;
},
endsWith: function endsWith(searchString) {
- ES.RequireObjectCoercible(this);
- var thisStr = String(this);
- if (Type.regex(searchString)) {
+ var S = ES.ToString(ES.RequireObjectCoercible(this));
+ if (ES.IsRegExp(searchString)) {
throw new TypeError('Cannot call method "endsWith" with a regex');
}
- var searchStr = String(searchString);
- var thisLen = thisStr.length;
- var posArg = arguments.length > 1 ? arguments[1] : void 0;
- var pos = typeof posArg === 'undefined' ? thisLen : ES.ToInteger(posArg);
- var end = _min(_max(pos, 0), thisLen);
- return _strSlice(thisStr, end - searchStr.length, end) === searchStr;
+ var searchStr = ES.ToString(searchString);
+ var len = S.length;
+ var endPosition;
+ if (arguments.length > 1) {
+ endPosition = arguments[1];
+ }
+ var pos = typeof endPosition === 'undefined' ? len : ES.ToInteger(endPosition);
+ var end = _min(_max(pos, 0), len);
+ return _strSlice(S, end - searchStr.length, end) === searchStr;
},
includes: function includes(searchString) {
- if (Type.regex(searchString)) {
+ if (ES.IsRegExp(searchString)) {
throw new TypeError('"includes" does not accept a RegExp');
}
+ var searchStr = ES.ToString(searchString);
var position;
if (arguments.length > 1) {
position = arguments[1];
}
// Somehow this trick makes method 100% compat with the spec.
- return _indexOf(this, searchString, position) !== -1;
+ return _indexOf(this, searchStr, position) !== -1;
},
codePointAt: function codePointAt(pos) {
- ES.RequireObjectCoercible(this);
- var thisStr = String(this);
+ var thisStr = ES.ToString(ES.RequireObjectCoercible(this));
var position = ES.ToInteger(pos);
var length = thisStr.length;
if (position >= 0 && position < length) {
@@ -700,6 +834,32 @@
overrideNative(String.prototype, 'endsWith', StringPrototypeShims.endsWith);
}
}
+ if (hasSymbols) {
+ var startsWithSupportsSymbolMatch = valueOrFalseIfThrows(function () {
+ var re = /a/;
+ re[Symbol.match] = false;
+ return '/a/'.startsWith(re);
+ });
+ if (!startsWithSupportsSymbolMatch) {
+ overrideNative(String.prototype, 'startsWith', StringPrototypeShims.startsWith);
+ }
+ var endsWithSupportsSymbolMatch = valueOrFalseIfThrows(function () {
+ var re = /a/;
+ re[Symbol.match] = false;
+ return '/a/'.endsWith(re);
+ });
+ if (!endsWithSupportsSymbolMatch) {
+ overrideNative(String.prototype, 'endsWith', StringPrototypeShims.endsWith);
+ }
+ var includesSupportsSymbolMatch = valueOrFalseIfThrows(function () {
+ var re = /a/;
+ re[Symbol.match] = false;
+ return '/a/'.includes(re);
+ });
+ if (!includesSupportsSymbolMatch) {
+ overrideNative(String.prototype, 'includes', StringPrototypeShims.includes);
+ }
+ }
defineProperties(String.prototype, StringPrototypeShims);
@@ -712,10 +872,7 @@
].join('');
var trimRegexp = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g');
var trimShim = function trim() {
- if (typeof this === 'undefined' || this === null) {
- throw new TypeError("can't convert " + this + ' to object');
- }
- return String(this).replace(trimRegexp, '');
+ return ES.ToString(ES.RequireObjectCoercible(this)).replace(trimRegexp, '');
};
var nonWS = ['\u0085', '\u200b', '\ufffe'].join('');
var nonWSregex = new RegExp('[' + nonWS + ']', 'g');
@@ -726,7 +883,7 @@
// see https://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.prototype-@@iterator
var StringIterator = function (s) {
ES.RequireObjectCoercible(s);
- this._s = String(s);
+ this._s = ES.ToString(s);
this._i = 0;
};
StringIterator.prototype.next = function () {
@@ -753,15 +910,20 @@
var ArrayShims = {
from: function from(items) {
var C = this;
- var mapFn = arguments.length > 1 ? arguments[1] : void 0;
+ var mapFn;
+ if (arguments.length > 1) {
+ mapFn = arguments[1];
+ }
var mapping, T;
- if (mapFn === void 0) {
+ if (typeof mapFn === 'undefined') {
mapping = false;
} else {
if (!ES.IsCallable(mapFn)) {
throw new TypeError('Array.from: when provided, the second argument must be a function');
}
- T = arguments.length > 2 ? arguments[2] : void 0;
+ if (arguments.length > 2) {
+ T = arguments[2];
+ }
mapping = true;
}
@@ -784,7 +946,7 @@
nextValue = next.value;
try {
if (mapping) {
- nextValue = T === undefined ? mapFn(nextValue, i) : _call(mapFn, T, nextValue, i);
+ nextValue = typeof T === 'undefined' ? mapFn(nextValue, i) : _call(mapFn, T, nextValue, i);
}
result[i] = nextValue;
} catch (e) {
@@ -802,7 +964,7 @@
for (i = 0; i < length; ++i) {
value = arrayLike[i];
if (mapping) {
- value = T !== undefined ? _call(mapFn, T, value, i) : mapFn(value, i);
+ value = typeof T === 'undefined' ? mapFn(value, i) : _call(mapFn, T, value, i);
}
result[i] = value;
}
@@ -869,14 +1031,30 @@
});
addIterator(ArrayIterator.prototype);
+ var orderKeys = function orderKeys(a, b) {
+ var aNumeric = String(ES.ToInteger(a)) === a;
+ var bNumeric = String(ES.ToInteger(b)) === b;
+ if (aNumeric && bNumeric) {
+ return b - a;
+ } else if (aNumeric && !bNumeric) {
+ return -1;
+ } else if (!aNumeric && bNumeric) {
+ return 1;
+ } else {
+ return a.localeCompare(b);
+ }
+ };
var getAllKeys = function getAllKeys(object) {
+ var ownKeys = [];
var keys = [];
for (var key in object) {
- _push(keys, key);
+ _push(_hasOwnProperty(object, key) ? ownKeys : keys, key);
}
+ _sort(ownKeys, orderKeys);
+ _sort(keys, orderKeys);
- return keys;
+ return _concat(ownKeys, keys);
};
var ObjectIterator = function (object, kind) {
@@ -935,16 +1113,19 @@
var ArrayPrototypeShims = {
copyWithin: function copyWithin(target, start) {
- var end = arguments[2]; // copyWithin.length must be 2
var o = ES.ToObject(this);
var len = ES.ToLength(o.length);
var relativeTarget = ES.ToInteger(target);
var relativeStart = ES.ToInteger(start);
var to = relativeTarget < 0 ? _max(len + relativeTarget, 0) : _min(relativeTarget, len);
var from = relativeStart < 0 ? _max(len + relativeStart, 0) : _min(relativeStart, len);
- end = typeof end === 'undefined' ? len : ES.ToInteger(end);
- var fin = end < 0 ? _max(len + end, 0) : _min(end, len);
- var count = _min(fin - from, len - to);
+ var end;
+ if (arguments.length > 2) {
+ end = arguments[2];
+ }
+ var relativeEnd = typeof end === 'undefined' ? len : ES.ToInteger(end);
+ var finalItem = relativeEnd < 0 ? _max(len + relativeEnd, 0) : _min(relativeEnd, len);
+ var count = _min(finalItem - from, len - to);
var direction = 1;
if (from < to && to < (from + count)) {
direction = -1;
@@ -965,8 +1146,14 @@
},
fill: function fill(value) {
- var start = arguments.length > 1 ? arguments[1] : void 0;
- var end = arguments.length > 2 ? arguments[2] : void 0;
+ var start;
+ if (arguments.length > 1) {
+ start = arguments[1];
+ }
+ var end;
+ if (arguments.length > 2) {
+ end = arguments[2];
+ }
var O = ES.ToObject(this);
var len = ES.ToLength(O.length);
start = ES.ToInteger(typeof start === 'undefined' ? 0 : start);
@@ -1048,7 +1235,7 @@
// Chrome 40 defines Array#values with the incorrect name, although Array#{keys,entries} have the correct name
if (functionsHaveNames && Array.prototype.values && Array.prototype.values.name !== 'values') {
var originalArrayPrototypeValues = Array.prototype.values;
- overrideNative(Array.prototype, 'values', function values() { return _call(originalArrayPrototypeValues, this); });
+ overrideNative(Array.prototype, 'values', function values() { return ES.Call(originalArrayPrototypeValues, this, arguments); });
defineProperty(Array.prototype, $iterator$, Array.prototype.values, true);
}
defineProperties(Array.prototype, ArrayPrototypeShims);
@@ -1077,70 +1264,72 @@
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); });
+ return valueOrFalseIfThrows(function () { return Array.from([0], void 0); });
}());
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);
+ if (arguments.length > 1 && typeof arguments[1] !== 'undefined') {
+ return ES.Call(origArrayFrom, this, arguments);
} else {
return _call(origArrayFrom, this, items);
}
});
}
+ var int32sAsOne = -(Math.pow(2, 32) - 1);
var toLengthsCorrectly = function (method, reversed) {
- var obj = { length: -1 };
- obj[reversed ? ((-1 >>> 0) - 1) : 0] = true;
+ var obj = { length: int32sAsOne };
+ obj[reversed ? ((obj.length >>> 0) - 1) : 0] = true;
return valueOrFalseIfThrows(function () {
_call(method, obj, function () {
// note: in nonconforming browsers, this will be called
// -1 >>> 0 times, which is 4294967295, so the throw matters.
throw new RangeError('should not reach here');
}, []);
+ return true;
});
};
if (!toLengthsCorrectly(Array.prototype.forEach)) {
var originalForEach = Array.prototype.forEach;
overrideNative(Array.prototype, 'forEach', function forEach(callbackFn) {
- return _apply(originalForEach, this.length >= 0 ? this : [], arguments);
+ return ES.Call(originalForEach, this.length >= 0 ? this : [], arguments);
}, true);
}
if (!toLengthsCorrectly(Array.prototype.map)) {
var originalMap = Array.prototype.map;
overrideNative(Array.prototype, 'map', function map(callbackFn) {
- return _apply(originalMap, this.length >= 0 ? this : [], arguments);
+ return ES.Call(originalMap, this.length >= 0 ? this : [], arguments);
}, true);
}
if (!toLengthsCorrectly(Array.prototype.filter)) {
var originalFilter = Array.prototype.filter;
overrideNative(Array.prototype, 'filter', function filter(callbackFn) {
- return _apply(originalFilter, this.length >= 0 ? this : [], arguments);
+ return ES.Call(originalFilter, this.length >= 0 ? this : [], arguments);
}, true);
}
if (!toLengthsCorrectly(Array.prototype.some)) {
var originalSome = Array.prototype.some;
overrideNative(Array.prototype, 'some', function some(callbackFn) {
- return _apply(originalSome, this.length >= 0 ? this : [], arguments);
+ return ES.Call(originalSome, this.length >= 0 ? this : [], arguments);
}, true);
}
if (!toLengthsCorrectly(Array.prototype.every)) {
var originalEvery = Array.prototype.every;
overrideNative(Array.prototype, 'every', function every(callbackFn) {
- return _apply(originalEvery, this.length >= 0 ? this : [], arguments);
+ return ES.Call(originalEvery, this.length >= 0 ? this : [], arguments);
}, true);
}
if (!toLengthsCorrectly(Array.prototype.reduce)) {
var originalReduce = Array.prototype.reduce;
overrideNative(Array.prototype, 'reduce', function reduce(callbackFn) {
- return _apply(originalReduce, this.length >= 0 ? this : [], arguments);
+ return ES.Call(originalReduce, this.length >= 0 ? this : [], arguments);
}, true);
}
if (!toLengthsCorrectly(Array.prototype.reduceRight, true)) {
var originalReduceRight = Array.prototype.reduceRight;
overrideNative(Array.prototype, 'reduceRight', function reduceRight(callbackFn) {
- return _apply(originalReduceRight, this.length >= 0 ? this : [], arguments);
+ return ES.Call(originalReduceRight, this.length >= 0 ? this : [], arguments);
}, true);
}
@@ -1177,16 +1366,20 @@
var NumberShim = (function () {
// this is wrapped in an IIFE because of IE 6-8's wacky scoping issues with named function expressions.
var NumberShim = function Number(value) {
- var primValue = Type.primitive(value) ? value : toPrimitive(value, 'number');
+ var primValue;
+ if (arguments.length > 0) {
+ primValue = Type.primitive(value) ? value : toPrimitive(value, 'number');
+ } else {
+ primValue = 0;
+ }
if (typeof primValue === 'string') {
+ primValue = ES.Call(trimShim, primValue);
if (isBinary(primValue)) {
primValue = parseInt(_strSlice(primValue, 2), 2);
} else if (isOctal(primValue)) {
primValue = parseInt(_strSlice(primValue, 2), 8);
} else if (hasNonWS(primValue) || isBadHex(primValue)) {
primValue = NaN;
- } else {
- primValue = _call(trimShim, primValue);
}
}
var receiver = this;
@@ -1252,6 +1445,11 @@
/*jshint elision: false */
var isEnumerableOn = Function.bind.call(Function.bind, Object.prototype.propertyIsEnumerable);
+ var ensureEnumerable = function ensureEnumerable(obj, prop) {
+ if (supportsDescriptors && isEnumerableOn(obj, prop)) {
+ Object.defineProperty(obj, prop, { enumerable: false });
+ }
+ };
var sliceArgs = function sliceArgs() {
// per https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments
// and https://gist.github.com/WebReflection/4327762cb87a8c634a29
@@ -1271,19 +1469,19 @@
};
};
var assignReducer = function (target, source) {
- var keys = Object.keys(Object(source));
+ var sourceKeys = keys(Object(source));
var symbols;
if (ES.IsCallable(Object.getOwnPropertySymbols)) {
symbols = _filter(Object.getOwnPropertySymbols(Object(source)), isEnumerableOn(source));
}
- return _reduce(_concat(keys, symbols || []), assignTo(source), target);
+ return _reduce(_concat(sourceKeys, symbols || []), assignTo(source), target);
};
var ObjectShims = {
// 19.1.3.1
assign: function (target, source) {
var to = ES.ToObject(target, 'Cannot convert undefined or null to object');
- return _reduce(_apply(sliceArgs, 1, arguments), assignReducer, to);
+ return _reduce(ES.Call(sliceArgs, 1, arguments), assignReducer, to);
},
// Added in WebKit in https://bugs.webkit.org/show_bug.cgi?id=143865
@@ -1391,6 +1589,7 @@
overrideNative(Object, 'keys', function keys(value) {
return originalObjectKeys(ES.ToObject(value));
});
+ keys = Object.keys;
}
if (Object.getOwnPropertyNames) {
@@ -1522,20 +1721,40 @@
Value.getter(RegExp.prototype, 'flags', regExpFlagsGetter);
}
- var regExpSupportsFlagsWithRegex = valueOrFalseIfThrows(function () {
+ var regExpSupportsFlagsWithRegex = supportsDescriptors && valueOrFalseIfThrows(function () {
return String(new RegExp(/a/g, 'i')) === '/a/i';
});
+ var regExpNeedsToSupportSymbolMatch = hasSymbols && supportsDescriptors && (function () {
+ // Edge 0.12 supports flags fully, but does not support Symbol.match
+ var regex = /./;
+ regex[Symbol.match] = false;
+ return RegExp(regex) === regex;
+ }());
+
+ if (supportsDescriptors && (!regExpSupportsFlagsWithRegex || regExpNeedsToSupportSymbolMatch)) {
+ var flagsGetter = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
+ var sourceDesc = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source') || {};
+ var legacySourceGetter = function () { return this.source; }; // prior to it being a getter, it's own + nonconfigurable
+ var sourceGetter = ES.IsCallable(sourceDesc.get) ? sourceDesc.get : legacySourceGetter;
- if (!regExpSupportsFlagsWithRegex && supportsDescriptors) {
var OrigRegExp = RegExp;
var RegExpShim = (function () {
return function RegExp(pattern, flags) {
+ var patternIsRegExp = ES.IsRegExp(pattern);
var calledWithNew = this instanceof RegExp;
- if (!calledWithNew && (Type.regex(pattern) || (pattern && pattern.constructor === RegExp))) {
+ if (!calledWithNew && patternIsRegExp && typeof flags === 'undefined' && pattern.constructor === RegExp) {
return pattern;
}
- if (Type.regex(pattern) && Type.string(flags)) {
- return new RegExp(pattern.source, flags);
+
+ var P = pattern;
+ var F = flags;
+ if (Type.regex(pattern)) {
+ P = ES.Call(sourceGetter, pattern);
+ F = typeof flags === 'undefined' ? ES.Call(flagsGetter, pattern) : flags;
+ return new RegExp(P, F);
+ } else if (patternIsRegExp) {
+ P = pattern.source;
+ F = typeof flags === 'undefined' ? pattern.flags : flags;
}
return new OrigRegExp(pattern, flags);
};
@@ -1559,7 +1778,7 @@
leftContext: '$`',
rightContext: '$\''
};
- _forEach(Object.keys(regexGlobals), function (prop) {
+ _forEach(keys(regexGlobals), function (prop) {
if (prop in RegExp && !(regexGlobals[prop] in RegExp)) {
Value.getter(RegExp, regexGlobals[prop], function get() {
return RegExp[prop];
@@ -1630,7 +1849,7 @@
if (number === 0) {
return 32;
}
- return numberCLZ ? _call(numberCLZ, number) : 31 - _floor(_log(number + 0.5) * Math.LOG2E);
+ return numberCLZ ? ES.Call(numberCLZ, number) : 31 - _floor(_log(number + 0.5) * Math.LOG2E);
},
cosh: function cosh(value) {
@@ -1809,7 +2028,7 @@
// Safari 8.0.4 has