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.js1521
1 files changed, 951 insertions, 570 deletions
diff --git a/js/vendor/es6-shim/es6-shim.js b/js/vendor/es6-shim/es6-shim.js
index 14229dd21..f16d48573 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.27.1
- * see https://github.com/paulmillr/es6-shim/blob/0.27.1/LICENSE
+ * es6-shim: v0.33.3
+ * see https://github.com/paulmillr/es6-shim/blob/0.33.3/LICENSE
* Details and documentation:
* https://github.com/paulmillr/es6-shim/
*/
@@ -27,8 +27,11 @@
}(this, function () {
'use strict';
+ var _apply = Function.call.bind(Function.apply);
+ var _call = Function.call.bind(Function.call);
+
var not = function notThunker(func) {
- return function notThunk() { return !func.apply(this, arguments); };
+ return function notThunk() { return !_apply(func, this, arguments); };
};
var throwsError = function (func) {
try {
@@ -52,12 +55,31 @@
return !throwsError(function () { Object.defineProperty({}, 'x', {}); });
};
var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported();
+ var functionsHaveNames = (function foo() {}).name === 'foo';
var _forEach = Function.call.bind(Array.prototype.forEach);
- var _map = Function.call.bind(Array.prototype.map);
var _reduce = Function.call.bind(Array.prototype.reduce);
var _filter = Function.call.bind(Array.prototype.filter);
+ var _every = Function.call.bind(Array.prototype.every);
+ var createDataProperty = function createDataProperty(object, name, value) {
+ if (supportsDescriptors) {
+ Object.defineProperty(object, name, {
+ configurable: true,
+ enumerable: true,
+ writable: true,
+ value: value
+ });
+ } else {
+ object[name] = value;
+ }
+ };
+ var createDataPropertyOrThrow = function createDataPropertyOrThrow(object, name, value) {
+ createDataProperty(object, name, value);
+ if (!ES.SameValue(object[name], value)) {
+ throw new TypeError('property is nonconfigurable');
+ }
+ };
var defineProperty = function (object, name, value, force) {
if (!force && name in object) { return; }
if (supportsDescriptors) {
@@ -84,11 +106,13 @@
// Simple shim for Object.create on ES3 browsers
// (unlike real shim, no attempt to support `prototype === null`)
var create = Object.create || function (prototype, properties) {
- function Prototype() {}
+ var Prototype = function Prototype() {};
Prototype.prototype = prototype;
var object = new Prototype();
if (typeof properties !== 'undefined') {
- defineProperties(object, properties);
+ Object.keys(properties).forEach(function (key) {
+ Value.defineByDescriptor(object, key, properties[key]);
+ });
}
return object;
};
@@ -101,8 +125,9 @@
Object.setPrototypeOf(o, Subclass.prototype);
return o;
};
+ Object.setPrototypeOf(Sub, C);
Sub.prototype = create(C.prototype, {
- constructor: { value: C }
+ constructor: { value: Sub }
});
return f(Sub);
});
@@ -118,9 +143,15 @@
return String.prototype.startsWith && 'abc'.startsWith('a', Infinity) === false;
}());
- /*jshint evil: true */
- var getGlobal = new Function('return this;');
- /*jshint evil: false */
+ var getGlobal = function () {
+ // the only reliable means to get the global object is
+ // `Function('return this')()`
+ // However, this causes CSP violations in Chrome apps.
+ if (typeof self !== 'undefined') { return self; }
+ if (typeof window !== 'undefined') { return window; }
+ if (typeof global !== 'undefined') { return global; }
+ throw new Error('unable to locate global object');
+ };
var globals = getGlobal();
var globalIsFinite = globals.isFinite;
@@ -128,32 +159,23 @@
var startsWithIsCompliant = startsWithRejectsRegex() && startsWithHandlesInfinity;
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 _strSlice = Function.call.bind(String.prototype.slice);
+ var _push = Function.call.bind(Array.prototype.push);
+ var _pushApply = Function.apply.bind(Array.prototype.push);
+ var _shift = Function.call.bind(Array.prototype.shift);
+ var _max = Math.max;
+ var _min = Math.min;
+ var _floor = Math.floor;
+ var _abs = Math.abs;
+ var _log = Math.log;
+ var _sqrt = Math.sqrt;
var _hasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);
var ArrayIterator; // make our implementation private
var noop = function () {};
var Symbol = globals.Symbol || {};
var symbolSpecies = Symbol.species || '@@species';
- var Type = {
- object: function (x) { return x !== null && typeof x === 'object'; },
- string: function (x) { return _toString(x) === '[object String]'; },
- regex: function (x) { return _toString(x) === '[object RegExp]'; },
- symbol: function (x) {
- return typeof globals.Symbol === 'function' && typeof x === 'symbol';
- }
- };
-
- var numberIsNaN = Number.isNaN || function isNaN(value) {
- // NaN !== NaN, but they are identical.
- // NaNs are the only non-reflexive value, i.e., if x !== x,
- // then x is NaN.
- // isNaN is broken: it converts its argument to number, so
- // isNaN('foo') => true
- return value !== value;
- };
- var numberIsFinite = Number.isFinite || function isFinite(value) {
- return typeof value === 'number' && globalIsFinite(value);
- };
var Value = {
getter: function (object, name, getter) {
@@ -187,11 +209,60 @@
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) {
defineProperty(target, 'toString', source.toString.bind(source), true);
}
};
+ var wrapConstructor = function wrapConstructor(original, replacement, keysToSkip) {
+ Value.preserveToString(replacement, original);
+ if (Object.setPrototypeOf) {
+ // sets up proper prototype chain where possible
+ Object.setPrototypeOf(original, replacement);
+ }
+ _forEach(Object.getOwnPropertyNames(original), function (key) {
+ if (key in noop || keysToSkip[key]) { return; }
+ Value.proxy(original, key, replacement);
+ });
+ replacement.prototype = original.prototype;
+ Value.redefine(original.prototype, 'constructor', replacement);
+ };
+
+ var defaultSpeciesGetter = function () { return this; };
+ var addDefaultSpecies = function (C) {
+ if (supportsDescriptors && !_hasOwnProperty(C, symbolSpecies)) {
+ Value.getter(C, symbolSpecies, defaultSpeciesGetter);
+ }
+ };
+ var Type = {
+ primitive: function (x) { return x === null || (typeof x !== 'function' && typeof x !== 'object'); },
+ object: function (x) { return x !== null && typeof x === 'object'; },
+ string: function (x) { return _toString(x) === '[object String]'; },
+ regex: function (x) { return _toString(x) === '[object RegExp]'; },
+ symbol: function (x) {
+ return typeof globals.Symbol === 'function' && typeof x === 'symbol';
+ }
+ };
+
+ var numberIsNaN = Number.isNaN || function isNaN(value) {
+ // NaN !== NaN, but they are identical.
+ // NaNs are the only non-reflexive value, i.e., if x !== x,
+ // then x is NaN.
+ // isNaN is broken: it converts its argument to number, so
+ // isNaN('foo') => true
+ return value !== value;
+ };
+ var numberIsFinite = Number.isFinite || function isFinite(value) {
+ return typeof value === 'number' && globalIsFinite(value);
+ };
+
var overrideNative = function overrideNative(object, property, replacement) {
var original = object[property];
defineProperty(object, property, replacement, true);
@@ -212,9 +283,7 @@
}
var addIterator = function (prototype, impl) {
var implementation = impl || function iterator() { return this; };
- var o = {};
- o[$iterator$] = implementation;
- defineProperties(prototype, o);
+ defineProperty(prototype, $iterator$, implementation);
if (!prototype[$iterator$] && Type.symbol($iterator$)) {
// implementations are buggy when $iterator$ is a Symbol
prototype[$iterator$] = implementation;
@@ -237,8 +306,6 @@
return result;
};
- var safeApply = Function.call.bind(Function.apply);
-
var ES = {
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-call-f-v-args
Call: function Call(F, V) {
@@ -246,7 +313,7 @@
if (!ES.IsCallable(F)) {
throw new TypeError(F + ' is not a function');
}
- return safeApply(F, V, args);
+ return _apply(F, V, args);
},
RequireObjectCoercible: function (x, optMessage) {
@@ -273,6 +340,11 @@
return typeof x === 'function' && _toString(x) === '[object Function]';
},
+ IsConstructor: function (x) {
+ // We can't tell callables from constructors in ES5
+ return ES.IsCallable(x);
+ },
+
ToInt32: function (x) {
return ES.ToNumber(x) >> 0;
},
@@ -292,7 +364,7 @@
var number = ES.ToNumber(value);
if (numberIsNaN(number)) { return 0; }
if (number === 0 || !numberIsFinite(number)) { return number; }
- return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
+ return (number > 0 ? 1 : -1) * _floor(_abs(number));
},
ToLength: function (value) {
@@ -325,17 +397,55 @@
// special case support for `arguments`
return new ArrayIterator(o, 'value');
}
- var itFn = o[$iterator$];
+ var itFn = ES.GetMethod(o, $iterator$);
if (!ES.IsCallable(itFn)) {
+ // Better diagnostics if itFn is null or undefined
throw new TypeError('value is not an iterable');
}
- var it = itFn.call(o);
+ var it = _call(itFn, o);
if (!ES.TypeIsObject(it)) {
throw new TypeError('bad iterator');
}
return it;
},
+ GetMethod: function (o, p) {
+ var func = ES.ToObject(o)[p];
+ if (func === void 0 || func === null) {
+ return void 0;
+ }
+ if (!ES.IsCallable(func)) {
+ throw new TypeError('Method not callable: ' + p);
+ }
+ return func;
+ },
+
+ IteratorComplete: function (iterResult) {
+ return !!(iterResult.done);
+ },
+
+ IteratorClose: function (iterator, completionIsThrow) {
+ var returnMethod = ES.GetMethod(iterator, 'return');
+ if (returnMethod === void 0) {
+ return;
+ }
+ var innerResult, innerException;
+ try {
+ innerResult = _call(returnMethod, iterator);
+ } catch (e) {
+ innerException = e;
+ }
+ if (completionIsThrow) {
+ return;
+ }
+ if (innerException) {
+ throw innerException;
+ }
+ if (!ES.TypeIsObject(innerResult)) {
+ throw new TypeError("Iterator's return method returned a non-object.");
+ }
+ },
+
IteratorNext: function (it) {
var result = arguments.length > 1 ? it.next(arguments[1]) : it.next();
if (!ES.TypeIsObject(result)) {
@@ -344,23 +454,53 @@
return result;
},
- Construct: function (C, args) {
- // CreateFromConstructor
- var obj;
- if (ES.IsCallable(C[symbolSpecies])) {
- obj = C[symbolSpecies]();
- } else {
- // OrdinaryCreateFromConstructor
- obj = create(C.prototype || null);
+ IteratorStep: function (it) {
+ var result = ES.IteratorNext(it);
+ var done = ES.IteratorComplete(result);
+ return done ? false : result;
+ },
+
+ Construct: function (C, args, newTarget, isES6internal) {
+ if (newTarget === void 0) {
+ newTarget = C;
+ }
+ if (!isES6internal) {
+ // Try to use Reflect.construct if available
+ return Reflect.construct(C, args, newTarget);
}
- // Mark that we've used the es6 construct path
- // (see emulateES6construct)
- defineProperties(obj, { _es6construct: true });
+ // OK, we have to fake it. This will only work if the
+ // C.[[ConstructorKind]] == "base" -- but that's the only
+ // kind we can make in ES5 code anyway.
+
+ // OrdinaryCreateFromConstructor(newTarget, "%ObjectPrototype%")
+ var proto = newTarget.prototype;
+ if (!ES.TypeIsObject(proto)) {
+ proto = Object.prototype;
+ }
+ var obj = create(proto);
// Call the constructor.
var result = ES.Call(C, obj, args);
return ES.TypeIsObject(result) ? result : obj;
},
+ SpeciesConstructor: function (O, defaultConstructor) {
+ var C = O.constructor;
+ if (C === void 0) {
+ return defaultConstructor;
+ }
+ if (!ES.TypeIsObject(C)) {
+ throw new TypeError('Bad constructor');
+ }
+ var S = C[symbolSpecies];
+ if (S === void 0 || S === null) {
+ return defaultConstructor;
+ }
+ if (!ES.IsConstructor(S)) {
+ throw new TypeError('Bad @@species');
+ }
+ return S;
+ },
+
CreateHTML: function (string, tag, attribute, value) {
var S = String(string);
var p1 = '<' + tag;
@@ -375,27 +515,39 @@
}
};
- var emulateES6construct = function (o) {
- if (!ES.TypeIsObject(o)) { throw new TypeError('bad object'); }
- var object = o;
- // es5 approximation to es6 subclass semantics: in es6, 'new Foo'
- // would invoke Foo.@@species to allocation/initialize the new object.
- // In es5 we just get the plain object. So if we detect an
- // uninitialized object, invoke o.constructor.@@species
- if (!object._es6construct) {
- if (object.constructor && ES.IsCallable(object.constructor[symbolSpecies])) {
- object = object.constructor[symbolSpecies](object);
- }
- defineProperties(object, { _es6construct: true });
+ var emulateES6construct = function (o, defaultNewTarget, defaultProto, slots) {
+ // This is an es5 approximation to es6 construct semantics. in es6,
+ // 'new Foo' invokes Foo.[[Construct]] which (for almost all objects)
+ // just sets the internal variable NewTarget (in es6 syntax `new.target`)
+ // to Foo and then returns Foo().
+
+ // Many ES6 object then have constructors of the form:
+ // 1. If NewTarget is undefined, throw a TypeError exception
+ // 2. Let xxx by OrdinaryCreateFromConstructor(NewTarget, yyy, zzz)
+
+ // So we're going to emulate those first two steps.
+ if (!ES.TypeIsObject(o)) {
+ throw new TypeError('Constructor requires `new`: ' + defaultNewTarget.name);
}
- return object;
+ var proto = defaultNewTarget.prototype;
+ if (!ES.TypeIsObject(proto)) {
+ proto = defaultProto;
+ }
+ o = create(proto);
+ for (var name in slots) {
+ if (_hasOwnProperty(slots, name)) {
+ var value = slots[name];
+ defineProperty(o, name, value, true);
+ }
+ }
+ return o;
};
// Firefox 31 reports this function's length as 0
// https://bugzilla.mozilla.org/show_bug.cgi?id=1062484
if (String.fromCodePoint && String.fromCodePoint.length !== 1) {
- var originalFromCodePoint = Function.apply.bind(String.fromCodePoint);
- overrideNative(String, 'fromCodePoint', function fromCodePoint(codePoints) { return originalFromCodePoint(this, arguments); });
+ var originalFromCodePoint = String.fromCodePoint;
+ overrideNative(String, 'fromCodePoint', function fromCodePoint(codePoints) { return _apply(originalFromCodePoint, this, arguments); });
}
var StringShims = {
@@ -409,11 +561,11 @@
}
if (next < 0x10000) {
- result.push(String.fromCharCode(next));
+ _push(result, String.fromCharCode(next));
} else {
next -= 0x10000;
- result.push(String.fromCharCode((next >> 10) + 0xD800));
- result.push(String.fromCharCode((next % 0x400) + 0xDC00));
+ _push(result, String.fromCharCode((next >> 10) + 0xD800));
+ _push(result, String.fromCharCode((next % 0x400) + 0xDC00));
}
}
return result.join('');
@@ -434,13 +586,13 @@
while (nextIndex < literalsegments) {
nextKey = String(nextIndex);
nextSeg = String(rawString[nextKey]);
- stringElements.push(nextSeg);
+ _push(stringElements, nextSeg);
if (nextIndex + 1 >= literalsegments) {
break;
}
next = nextIndex + 1 < arguments.length ? arguments[nextIndex + 1] : '';
nextSub = String(next);
- stringElements.push(nextSub);
+ _push(stringElements, nextSub);
nextIndex++;
}
return stringElements.join('');
@@ -481,8 +633,8 @@
}
var searchStr = String(searchString);
var startArg = arguments.length > 1 ? arguments[1] : void 0;
- var start = Math.max(ES.ToInteger(startArg), 0);
- return thisStr.slice(start, start + searchStr.length) === searchStr;
+ var start = _max(ES.ToInteger(startArg), 0);
+ return _strSlice(thisStr, start, start + searchStr.length) === searchStr;
},
endsWith: function endsWith(searchString) {
@@ -495,12 +647,18 @@
var thisLen = thisStr.length;
var posArg = arguments.length > 1 ? arguments[1] : void 0;
var pos = typeof posArg === 'undefined' ? thisLen : ES.ToInteger(posArg);
- var end = Math.min(Math.max(pos, 0), thisLen);
- return thisStr.slice(end - searchStr.length, end) === searchStr;
+ var end = _min(_max(pos, 0), thisLen);
+ return _strSlice(thisStr, end - searchStr.length, end) === searchStr;
},
includes: function includes(searchString) {
- var position = arguments.length > 1 ? arguments[1] : void 0;
+ if (Type.regex(searchString)) {
+ throw new TypeError('"includes" does not accept a RegExp');
+ }
+ 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;
},
@@ -581,53 +739,60 @@
}
var ArrayShims = {
- from: function from(iterable) {
+ from: function from(items) {
+ var C = this;
var mapFn = arguments.length > 1 ? arguments[1] : void 0;
-
- var list = ES.ToObject(iterable, 'bad iterable');
- if (typeof mapFn !== 'undefined' && !ES.IsCallable(mapFn)) {
- throw new TypeError('Array.from: when provided, the second argument must be a function');
+ var mapping, T;
+ if (mapFn === void 0) {
+ 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;
+ mapping = true;
}
- var hasThisArg = arguments.length > 2;
- var thisArg = hasThisArg ? arguments[2] : void 0;
-
- var usingIterator = ES.IsIterable(list);
- // does the spec really mean that Arrays should use ArrayIterator?
+ // Note that that Arrays will use ArrayIterator:
// https://bugs.ecmascript.org/show_bug.cgi?id=2416
- //if (Array.isArray(list)) { usingIterator=false; }
+ var usingIterator = isArguments(items) || ES.GetMethod(items, $iterator$);
+
+ var length, result, i;
+ if (usingIterator !== void 0) {
+ result = ES.IsConstructor(C) ? Object(new C()) : [];
+ var iterator = ES.GetIterator(items);
+ var next, nextValue;
- var length;
- var result, i, value;
- if (usingIterator) {
i = 0;
- result = ES.IsCallable(this) ? Object(new this()) : [];
- var it = usingIterator ? ES.GetIterator(list) : null;
- var iterationValue;
-
- do {
- iterationValue = ES.IteratorNext(it);
- if (!iterationValue.done) {
- value = iterationValue.value;
- if (mapFn) {
- result[i] = hasThisArg ? mapFn.call(thisArg, value, i) : mapFn(value, i);
- } else {
- result[i] = value;
+ while (true) {
+ next = ES.IteratorStep(iterator);
+ if (next === false) {
+ break;
+ }
+ nextValue = next.value;
+ try {
+ if (mapping) {
+ nextValue = T !== undefined ? _call(mapFn, T, nextValue, i) : mapFn(nextValue, i);
}
- i += 1;
+ result[i] = nextValue;
+ } catch (e) {
+ ES.IteratorClose(iterator, true);
+ throw e;
}
- } while (!iterationValue.done);
+ i += 1;
+ }
length = i;
} else {
- length = ES.ToLength(list.length);
- result = ES.IsCallable(this) ? Object(new this(length)) : new Array(length);
+ var arrayLike = ES.ToObject(items);
+ length = ES.ToLength(arrayLike.length);
+ result = ES.IsConstructor(C) ? Object(new C(length)) : new Array(length);
+ var value;
for (i = 0; i < length; ++i) {
- value = list[i];
- if (mapFn) {
- result[i] = hasThisArg ? mapFn.call(thisArg, value, i) : mapFn(value, i);
- } else {
- result[i] = value;
+ value = arrayLike[i];
+ if (mapping) {
+ value = T !== undefined ? _call(mapFn, T, value, i) : mapFn(value, i);
}
+ result[i] = value;
}
}
@@ -636,10 +801,18 @@
},
of: function of() {
- return Array.from.call(this, arguments);
+ var len = arguments.length;
+ var C = this;
+ var A = Array.isArray(C) || !ES.IsCallable(C) ? new Array(len) : ES.Construct(C, [len]);
+ for (var k = 0; k < len; ++k) {
+ createDataPropertyOrThrow(A, k, arguments[k]);
+ }
+ A.length = len;
+ return A;
}
};
defineProperties(Array, ArrayShims);
+ addDefaultSpecies(Array);
// Given an argument x, it will return an IteratorResult object,
// with value set to x and done to false.
@@ -685,38 +858,35 @@
addIterator(ArrayIterator.prototype);
var ObjectIterator = function (object, kind) {
- this.object = object;
- // Don't generate keys yet.
- this.array = null;
- this.kind = kind;
+ defineProperties(this, {
+ object: object,
+ array: getAllKeys(object),
+ kind: kind
+ });
};
- function getAllKeys(object) {
+ var getAllKeys = function getAllKeys(object) {
var keys = [];
for (var key in object) {
- keys.push(key);
+ _push(keys, key);
}
return keys;
- }
+ };
defineProperties(ObjectIterator.prototype, {
- next: function () {
- var key, array = this.array;
+ next: function next() {
+ var key;
+ var array = this.array;
if (!(this instanceof ObjectIterator)) {
throw new TypeError('Not an ObjectIterator');
}
- // Keys not generated
- if (array === null) {
- array = this.array = getAllKeys(this.object);
- }
-
// Find next key in the object
- while (ES.ToLength(array.length) > 0) {
- key = array.shift();
+ while (array.length > 0) {
+ key = _shift(array);
// The candidate key isn't defined on object.
// Must have been deleted, or object[[Prototype]]
@@ -740,7 +910,7 @@
addIterator(ObjectIterator.prototype);
// note: this is positioned here because it depends on ArrayIterator
- var arrayOfSupportsSubclassing = (function () {
+ var arrayOfSupportsSubclassing = Array.of === ArrayShims.of || (function () {
// Detects a bug in Webkit nightly r181886
var Foo = function Foo(len) { this.length = len; };
Foo.prototype = [];
@@ -758,11 +928,11 @@
var len = ES.ToLength(o.length);
var relativeTarget = ES.ToInteger(target);
var relativeStart = ES.ToInteger(start);
- var to = relativeTarget < 0 ? Math.max(len + relativeTarget, 0) : Math.min(relativeTarget, len);
- var from = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
+ 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 ? Math.max(len + end, 0) : Math.min(end, len);
- var count = Math.min(fin - from, len - to);
+ var fin = end < 0 ? _max(len + end, 0) : _min(end, len);
+ var count = _min(fin - from, len - to);
var direction = 1;
if (from < to && to < (from + count)) {
direction = -1;
@@ -790,7 +960,7 @@
start = ES.ToInteger(typeof start === 'undefined' ? 0 : start);
end = ES.ToInteger(typeof end === 'undefined' ? len : end);
- var relativeStart = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
+ var relativeStart = start < 0 ? _max(len + start, 0) : _min(start, len);
var relativeEnd = end < 0 ? len + end : end;
for (var i = relativeStart; i < len && i < relativeEnd; ++i) {
@@ -809,7 +979,7 @@
for (var i = 0, value; i < length; i++) {
value = list[i];
if (thisArg) {
- if (predicate.call(thisArg, value, i, list)) { return value; }
+ if (_call(predicate, thisArg, value, i, list)) { return value; }
} else if (predicate(value, i, list)) {
return value;
}
@@ -825,7 +995,7 @@
var thisArg = arguments.length > 1 ? arguments[1] : null;
for (var i = 0; i < length; i++) {
if (thisArg) {
- if (predicate.call(thisArg, list[i], i, list)) { return i; }
+ if (_call(predicate, thisArg, list[i], i, list)) { return i; }
} else if (predicate(list[i], i, list)) {
return i;
}
@@ -864,9 +1034,9 @@
}
}
// Chrome 40 defines Array#values with the incorrect name, although Array#{keys,entries} have the correct name
- if (Array.prototype.values && Array.prototype.values.name !== 'values') {
+ if (functionsHaveNames && Array.prototype.values && Array.prototype.values.name !== 'values') {
var originalArrayPrototypeValues = Array.prototype.values;
- overrideNative(Array.prototype, 'values', function values() { return originalArrayPrototypeValues.call(this); });
+ overrideNative(Array.prototype, 'values', function values() { return _call(originalArrayPrototypeValues, this); });
defineProperty(Array.prototype, $iterator$, Array.prototype.values, true);
}
defineProperties(Array.prototype, ArrayPrototypeShims);
@@ -887,17 +1057,32 @@
var arrayFromHandlesIterables = (function () {
// Detects a bug in Webkit nightly r181886
var arr = Array.from([0].entries());
- return arr.length === 1 && arr[0][0] === 0 && arr[0][1] === 1;
+ return arr.length === 1 && Array.isArray(arr[0]) && arr[0][0] === 0 && arr[0][1] === 0;
}());
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 };
obj[reversed ? ((-1 >>> 0) - 1) : 0] = true;
return valueOrFalseIfThrows(function () {
- method.call(obj, 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');
@@ -907,46 +1092,89 @@
if (!toLengthsCorrectly(Array.prototype.forEach)) {
var originalForEach = Array.prototype.forEach;
overrideNative(Array.prototype, 'forEach', function forEach(callbackFn) {
- return originalForEach.apply(this.length >= 0 ? this : [], arguments);
+ return _apply(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 originalMap.apply(this.length >= 0 ? this : [], arguments);
+ return _apply(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 originalFilter.apply(this.length >= 0 ? this : [], arguments);
+ return _apply(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 originalSome.apply(this.length >= 0 ? this : [], arguments);
+ return _apply(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 originalEvery.apply(this.length >= 0 ? this : [], arguments);
+ return _apply(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 originalReduce.apply(this.length >= 0 ? this : [], arguments);
+ return _apply(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 originalReduceRight.apply(this.length >= 0 ? this : [], arguments);
+ return _apply(originalReduceRight, this.length >= 0 ? this : [], arguments);
}, true);
}
+ if (Number('0o10') !== 8 || Number('0b10') !== 2) {
+ var OrigNumber = Number;
+ var isBinary = Function.bind.call(Function.call, RegExp.prototype.test, /^0b/i);
+ var isOctal = Function.bind.call(Function.call, RegExp.prototype.test, /^0o/i);
+ var toPrimitive = function (O) { // need to replace this with `es-to-primitive/es6`
+ var result;
+ if (typeof O.valueOf === 'function') {
+ result = O.valueOf();
+ if (Type.primitive(result)) {
+ return result;
+ }
+ }
+ if (typeof O.toString === 'function') {
+ result = O.toString();
+ if (Type.primitive(result)) {
+ return result;
+ }
+ }
+ throw new TypeError('No default value');
+ };
+ var NumberShim = function Number(value) {
+ var primValue = Type.primitive(value) ? value : toPrimitive(value, 'number');
+ if (typeof primValue === 'string') {
+ if (isBinary(primValue)) {
+ primValue = parseInt(_strSlice(primValue, 2), 2);
+ } else if (isOctal(primValue)) {
+ primValue = parseInt(_strSlice(primValue, 2), 8);
+ }
+ }
+ if (this instanceof Number) {
+ return new OrigNumber(primValue);
+ }
+ /* jshint newcap: false */
+ return OrigNumber(primValue);
+ /* jshint newcap: true */
+ };
+ wrapConstructor(OrigNumber, NumberShim, {});
+ /*globals Number: true */
+ Number = NumberShim;
+ Value.redefine(globals, 'Number', NumberShim);
+ /*globals Number: false */
+ }
+
var maxSafeInteger = Math.pow(2, 53) - 1;
defineProperties(Number, {
MAX_SAFE_INTEGER: maxSafeInteger,
@@ -963,7 +1191,7 @@
},
isSafeInteger: function isSafeInteger(value) {
- return Number.isInteger(value) && Math.abs(value) <= Number.MAX_SAFE_INTEGER;
+ return Number.isInteger(value) && _abs(value) <= Number.MAX_SAFE_INTEGER;
},
isNaN: numberIsNaN
@@ -1009,16 +1237,14 @@
if (ES.IsCallable(Object.getOwnPropertySymbols)) {
symbols = _filter(Object.getOwnPropertySymbols(Object(source)), isEnumerableOn(source));
}
- return _reduce(keys.concat(symbols || []), assignTo(source), target);
+ return _reduce(_concat(keys, symbols || []), assignTo(source), target);
};
var ObjectShims = {
// 19.1.3.1
assign: function (target, source) {
- if (!ES.TypeIsObject(target)) {
- throw new TypeError('target must be an object');
- }
- return _reduce(sliceArgs.apply(0, arguments), assignReducer);
+ var to = ES.ToObject(target, 'Cannot convert undefined or null to object');
+ return _reduce(_apply(sliceArgs, 1, arguments), assignReducer, to);
},
// Added in WebKit in https://bugs.webkit.org/show_bug.cgi?id=143865
@@ -1059,14 +1285,14 @@
var setPrototypeOf = function (O, proto) {
checkArgs(O, proto);
- set.call(O, proto);
+ _call(set, O, proto);
return O;
};
try {
// this works already in Firefox and Safari
set = Object.getOwnPropertyDescriptor(Object.prototype, magic).set;
- set.call({}, null);
+ _call(set, {}, null);
} catch (e) {
if (Object.prototype !== {}[magic]) {
// IE < 11 cannot be shimmed
@@ -1131,9 +1357,19 @@
if (Object.getOwnPropertyNames) {
var objectGOPNAcceptsPrimitives = !throwsError(function () { Object.getOwnPropertyNames('foo'); });
if (!objectGOPNAcceptsPrimitives) {
+ var cachedWindowNames = typeof window === 'object' ? Object.getOwnPropertyNames(window) : [];
var originalObjectGetOwnPropertyNames = Object.getOwnPropertyNames;
overrideNative(Object, 'getOwnPropertyNames', function getOwnPropertyNames(value) {
- return