UNPKG

aurelia-polyfills

Version:

The minimal set of polyfills that the Aurelia platform needs to run on ES5 browsers.

849 lines (726 loc) 24.9 kB
'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var _aureliaPal = require('aurelia-pal'); if (typeof FEATURE_NO_ES2015 === 'undefined') { (function (Object, GOPS) { 'use strict'; if (GOPS in Object) return; var setDescriptor, G = _aureliaPal.PLATFORM.global, id = 0, random = '' + Math.random(), prefix = '__\x01symbol:', prefixLength = prefix.length, internalSymbol = '__\x01symbol@@' + random, DP = 'defineProperty', DPies = 'defineProperties', GOPN = 'getOwnPropertyNames', GOPD = 'getOwnPropertyDescriptor', PIE = 'propertyIsEnumerable', gOPN = Object[GOPN], gOPD = Object[GOPD], create = Object.create, keys = Object.keys, defineProperty = Object[DP], $defineProperties = Object[DPies], descriptor = gOPD(Object, GOPN), ObjectProto = Object.prototype, hOP = ObjectProto.hasOwnProperty, pIE = ObjectProto[PIE], toString = ObjectProto.toString, indexOf = Array.prototype.indexOf || function (v) { for (var i = this.length; i-- && this[i] !== v;) {} return i; }, addInternalIfNeeded = function addInternalIfNeeded(o, uid, enumerable) { if (!hOP.call(o, internalSymbol)) { defineProperty(o, internalSymbol, { enumerable: false, configurable: false, writable: false, value: {} }); } o[internalSymbol]['@@' + uid] = enumerable; }, createWithSymbols = function createWithSymbols(proto, descriptors) { var self = create(proto); if (descriptors !== null && (typeof descriptors === 'undefined' ? 'undefined' : _typeof(descriptors)) === 'object') { gOPN(descriptors).forEach(function (key) { if (propertyIsEnumerable.call(descriptors, key)) { $defineProperty(self, key, descriptors[key]); } }); } return self; }, copyAsNonEnumerable = function copyAsNonEnumerable(descriptor) { var newDescriptor = create(descriptor); newDescriptor.enumerable = false; return newDescriptor; }, get = function get() {}, onlyNonSymbols = function onlyNonSymbols(name) { return name != internalSymbol && !hOP.call(source, name); }, onlySymbols = function onlySymbols(name) { return name != internalSymbol && hOP.call(source, name); }, propertyIsEnumerable = function propertyIsEnumerable(key) { var uid = '' + key; return onlySymbols(uid) ? hOP.call(this, uid) && this[internalSymbol] && this[internalSymbol]['@@' + uid] : pIE.call(this, key); }, setAndGetSymbol = function setAndGetSymbol(uid) { var descriptor = { enumerable: false, configurable: true, get: get, set: function set(value) { setDescriptor(this, uid, { enumerable: false, configurable: true, writable: true, value: value }); addInternalIfNeeded(this, uid, true); } }; defineProperty(ObjectProto, uid, descriptor); return source[uid] = defineProperty(Object(uid), 'constructor', sourceConstructor); }, _Symbol = function _Symbol2(description) { if (this && this !== G) { throw new TypeError('Symbol is not a constructor'); } return setAndGetSymbol(prefix.concat(description || '', random, ++id)); }, source = create(null), sourceConstructor = { value: _Symbol }, sourceMap = function sourceMap(uid) { return source[uid]; }, $defineProperty = function defineProp(o, key, descriptor) { var uid = '' + key; if (onlySymbols(uid)) { setDescriptor(o, uid, descriptor.enumerable ? copyAsNonEnumerable(descriptor) : descriptor); addInternalIfNeeded(o, uid, !!descriptor.enumerable); } else { defineProperty(o, key, descriptor); } return o; }, $getOwnPropertySymbols = function getOwnPropertySymbols(o) { var cof = toString.call(o); o = cof === '[object String]' ? o.split('') : Object(o); return gOPN(o).filter(onlySymbols).map(sourceMap); }; descriptor.value = $defineProperty; defineProperty(Object, DP, descriptor); descriptor.value = $getOwnPropertySymbols; defineProperty(Object, GOPS, descriptor); var cachedWindowNames = (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' ? Object.getOwnPropertyNames(window) : []; var originalObjectGetOwnPropertyNames = Object.getOwnPropertyNames; descriptor.value = function getOwnPropertyNames(o) { if (toString.call(o) === '[object Window]') { try { return originalObjectGetOwnPropertyNames(o); } catch (e) { return [].concat([], cachedWindowNames); } } return gOPN(o).filter(onlyNonSymbols); }; defineProperty(Object, GOPN, descriptor); descriptor.value = function defineProperties(o, descriptors) { var symbols = $getOwnPropertySymbols(descriptors); if (symbols.length) { keys(descriptors).concat(symbols).forEach(function (uid) { if (propertyIsEnumerable.call(descriptors, uid)) { $defineProperty(o, uid, descriptors[uid]); } }); } else { $defineProperties(o, descriptors); } return o; }; defineProperty(Object, DPies, descriptor); descriptor.value = propertyIsEnumerable; defineProperty(ObjectProto, PIE, descriptor); descriptor.value = _Symbol; defineProperty(G, 'Symbol', descriptor); descriptor.value = function (key) { var uid = prefix.concat(prefix, key, random); return uid in ObjectProto ? source[uid] : setAndGetSymbol(uid); }; defineProperty(_Symbol, 'for', descriptor); descriptor.value = function (symbol) { return hOP.call(source, symbol) ? symbol.slice(prefixLength * 2, -random.length) : void 0; }; defineProperty(_Symbol, 'keyFor', descriptor); descriptor.value = function getOwnPropertyDescriptor(o, key) { var descriptor = gOPD(o, key); if (descriptor && onlySymbols(key)) { descriptor.enumerable = propertyIsEnumerable.call(o, key); } return descriptor; }; defineProperty(Object, GOPD, descriptor); descriptor.value = function (proto, descriptors) { return arguments.length === 1 ? create(proto) : createWithSymbols(proto, descriptors); }; defineProperty(Object, 'create', descriptor); descriptor.value = function () { var str = toString.call(this); return str === '[object String]' && onlySymbols(this) ? '[object Symbol]' : str; }; defineProperty(ObjectProto, 'toString', descriptor); try { setDescriptor = create(defineProperty({}, prefix, { get: function get() { return defineProperty(this, prefix, { value: false })[prefix]; } }))[prefix] || defineProperty; } catch (o_O) { setDescriptor = function setDescriptor(o, key, descriptor) { var protoDescriptor = gOPD(ObjectProto, key); delete ObjectProto[key]; defineProperty(o, key, descriptor); defineProperty(ObjectProto, key, protoDescriptor); }; } })(Object, 'getOwnPropertySymbols'); (function (O, S) { var dP = O.defineProperty, ObjectProto = O.prototype, toString = ObjectProto.toString, toStringTag = 'toStringTag', descriptor; ['iterator', 'match', 'replace', 'search', 'split', 'hasInstance', 'isConcatSpreadable', 'unscopables', 'species', 'toPrimitive', toStringTag].forEach(function (name) { if (!(name in Symbol)) { dP(Symbol, name, { value: Symbol(name) }); switch (name) { case toStringTag: descriptor = O.getOwnPropertyDescriptor(ObjectProto, 'toString'); descriptor.value = function () { var str = toString.call(this), tst = typeof this === 'undefined' || this === null ? undefined : this[Symbol.toStringTag]; return typeof tst === 'undefined' ? str : '[object ' + tst + ']'; }; dP(ObjectProto, 'toString', descriptor); break; } } }); })(Object, Symbol); (function (Si, AP, SP) { function returnThis() { return this; } if (!AP[Si]) AP[Si] = function () { var i = 0, self = this, iterator = { next: function next() { var done = self.length <= i; return done ? { done: done } : { done: done, value: self[i++] }; } }; iterator[Si] = returnThis; return iterator; }; if (!SP[Si]) SP[Si] = function () { var fromCodePoint = String.fromCodePoint, self = this, i = 0, length = self.length, iterator = { next: function next() { var done = length <= i, c = done ? '' : fromCodePoint(self.codePointAt(i)); i += c.length; return done ? { done: done } : { done: done, value: c }; } }; iterator[Si] = returnThis; return iterator; }; })(Symbol.iterator, Array.prototype, String.prototype); } if (typeof FEATURE_NO_ES2015 === 'undefined') { Number.isNaN = Number.isNaN || function (value) { return value !== value; }; Number.isFinite = Number.isFinite || function (value) { return typeof value === "number" && isFinite(value); }; } if (!String.prototype.endsWith || function () { try { return !"ab".endsWith("a", 1); } catch (e) { return true; } }()) { String.prototype.endsWith = function (searchString, position) { var subjectString = this.toString(); if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) { position = subjectString.length; } position -= searchString.length; var lastIndex = subjectString.indexOf(searchString, position); return lastIndex !== -1 && lastIndex === position; }; } if (!String.prototype.startsWith || function () { try { return !"ab".startsWith("b", 1); } catch (e) { return true; } }()) { String.prototype.startsWith = function (searchString, position) { position = position || 0; return this.substr(position, searchString.length) === searchString; }; } if (typeof FEATURE_NO_ES2015 === 'undefined') { if (!Array.from) { Array.from = function () { var toInteger = function toInteger(it) { return isNaN(it = +it) ? 0 : (it > 0 ? Math.floor : Math.ceil)(it); }; var toLength = function toLength(it) { return it > 0 ? Math.min(toInteger(it), 0x1fffffffffffff) : 0; }; var iterCall = function iterCall(iter, fn, val, index) { try { return fn(val, index); } catch (E) { if (typeof iter.return == 'function') iter.return(); throw E; } }; return function from(arrayLike) { var O = Object(arrayLike), C = typeof this == 'function' ? this : Array, aLen = arguments.length, mapfn = aLen > 1 ? arguments[1] : undefined, mapping = mapfn !== undefined, index = 0, iterFn = O[Symbol.iterator], length, result, step, iterator; if (mapping) mapfn = mapfn.bind(aLen > 2 ? arguments[2] : undefined); if (iterFn != undefined && !Array.isArray(arrayLike)) { for (iterator = iterFn.call(O), result = new C(); !(step = iterator.next()).done; index++) { result[index] = mapping ? iterCall(iterator, mapfn, step.value, index) : step.value; } } else { length = toLength(O.length); for (result = new C(length); length > index; index++) { result[index] = mapping ? mapfn(O[index], index) : O[index]; } } result.length = index; return result; }; }(); } if (!Array.prototype.find) { Object.defineProperty(Array.prototype, 'find', { configurable: true, writable: true, enumerable: false, value: function value(predicate) { if (this === null) { throw new TypeError('Array.prototype.find called on null or undefined'); } if (typeof predicate !== 'function') { throw new TypeError('predicate must be a function'); } var list = Object(this); var length = list.length >>> 0; var thisArg = arguments[1]; var value; for (var i = 0; i < length; i++) { value = list[i]; if (predicate.call(thisArg, value, i, list)) { return value; } } return undefined; } }); } if (!Array.prototype.findIndex) { Object.defineProperty(Array.prototype, 'findIndex', { configurable: true, writable: true, enumerable: false, value: function value(predicate) { if (this === null) { throw new TypeError('Array.prototype.findIndex called on null or undefined'); } if (typeof predicate !== 'function') { throw new TypeError('predicate must be a function'); } var list = Object(this); var length = list.length >>> 0; var thisArg = arguments[1]; var value; for (var i = 0; i < length; i++) { value = list[i]; if (predicate.call(thisArg, value, i, list)) { return i; } } return -1; } }); } } if (typeof FEATURE_NO_ES2016 === 'undefined' && !Array.prototype.includes) { Object.defineProperty(Array.prototype, 'includes', { configurable: true, writable: true, enumerable: false, value: function value(searchElement) { var O = Object(this); var len = parseInt(O.length) || 0; if (len === 0) { return false; } var n = parseInt(arguments[1]) || 0; var k; if (n >= 0) { k = n; } else { k = len + n; if (k < 0) { k = 0; } } var currentElement; while (k < len) { currentElement = O[k]; if (searchElement === currentElement || searchElement !== searchElement && currentElement !== currentElement) { return true; } k++; } return false; } }); } if (typeof FEATURE_NO_ES2015 === 'undefined') { (function () { var needsFix = false; try { var s = Object.keys('a'); needsFix = s.length !== 1 || s[0] !== '0'; } catch (e) { needsFix = true; } if (needsFix) { Object.keys = function () { var hasOwnProperty = Object.prototype.hasOwnProperty, hasDontEnumBug = !{ toString: null }.propertyIsEnumerable('toString'), dontEnums = ['toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'constructor'], dontEnumsLength = dontEnums.length; return function (obj) { if (obj === undefined || obj === null) { throw TypeError('Cannot convert undefined or null to object'); } obj = Object(obj); var result = [], prop, i; for (prop in obj) { if (hasOwnProperty.call(obj, prop)) { result.push(prop); } } if (hasDontEnumBug) { for (i = 0; i < dontEnumsLength; i++) { if (hasOwnProperty.call(obj, dontEnums[i])) { result.push(dontEnums[i]); } } } return result; }; }(); } })(); (function (O) { if ('assign' in O) { return; } O.defineProperty(O, 'assign', { configurable: true, writable: true, value: function () { var gOPS = O.getOwnPropertySymbols, pIE = O.propertyIsEnumerable, filterOS = gOPS ? function (self) { return gOPS(self).filter(pIE, self); } : function () { return Array.prototype; }; return function assign(where) { if (gOPS && !(where instanceof O)) { console.warn('problematic Symbols', where); } function set(keyOrSymbol) { where[keyOrSymbol] = arg[keyOrSymbol]; } for (var i = 1, ii = arguments.length; i < ii; ++i) { var arg = arguments[i]; if (arg === null || arg === undefined) { continue; } O.keys(arg).concat(filterOS(arg)).forEach(set); } return where; }; }() }); })(Object); if (!Object.is) { Object.is = function (x, y) { if (x === y) { return x !== 0 || 1 / x === 1 / y; } else { return x !== x && y !== y; } }; } } if (typeof FEATURE_NO_ES2015 === 'undefined') { (function (global) { var i; var defineProperty = Object.defineProperty, is = function is(a, b) { return a === b || a !== a && b !== b; }; if (typeof WeakMap == 'undefined') { global.WeakMap = createCollection({ 'delete': sharedDelete, clear: sharedClear, get: sharedGet, has: mapHas, set: sharedSet }, true); } if (typeof Map == 'undefined' || typeof new Map().values !== 'function' || !new Map().values().next) { var _createCollection; global.Map = createCollection((_createCollection = { 'delete': sharedDelete, has: mapHas, get: sharedGet, set: sharedSet, keys: sharedKeys, values: sharedValues, entries: mapEntries, forEach: sharedForEach, clear: sharedClear }, _createCollection[Symbol.iterator] = mapEntries, _createCollection)); } if (typeof Set == 'undefined' || typeof new Set().values !== 'function' || !new Set().values().next) { var _createCollection2; global.Set = createCollection((_createCollection2 = { has: setHas, add: sharedAdd, 'delete': sharedDelete, clear: sharedClear, keys: sharedValues, values: sharedValues, entries: setEntries, forEach: sharedForEach }, _createCollection2[Symbol.iterator] = sharedValues, _createCollection2)); } if (typeof WeakSet == 'undefined') { global.WeakSet = createCollection({ 'delete': sharedDelete, add: sharedAdd, clear: sharedClear, has: setHas }, true); } function createCollection(proto, objectOnly) { function Collection(a) { if (!this || this.constructor !== Collection) return new Collection(a); this._keys = []; this._values = []; this._itp = []; this.objectOnly = objectOnly; if (a) init.call(this, a); } if (!objectOnly) { defineProperty(proto, 'size', { get: sharedSize }); } proto.constructor = Collection; Collection.prototype = proto; return Collection; } function init(a) { var i; if (this.add) a.forEach(this.add, this);else a.forEach(function (a) { this.set(a[0], a[1]); }, this); } function sharedDelete(key) { if (this.has(key)) { this._keys.splice(i, 1); this._values.splice(i, 1); this._itp.forEach(function (p) { if (i < p[0]) p[0]--; }); } return -1 < i; }; function sharedGet(key) { return this.has(key) ? this._values[i] : undefined; } function has(list, key) { if (this.objectOnly && key !== Object(key)) throw new TypeError("Invalid value used as weak collection key"); if (key != key || key === 0) for (i = list.length; i-- && !is(list[i], key);) {} else i = list.indexOf(key); return -1 < i; } function setHas(value) { return has.call(this, this._values, value); } function mapHas(value) { return has.call(this, this._keys, value); } function sharedSet(key, value) { this.has(key) ? this._values[i] = value : this._values[this._keys.push(key) - 1] = value; return this; } function sharedAdd(value) { if (!this.has(value)) this._values.push(value); return this; } function sharedClear() { (this._keys || 0).length = this._values.length = 0; } function sharedKeys() { return sharedIterator(this._itp, this._keys); } function sharedValues() { return sharedIterator(this._itp, this._values); } function mapEntries() { return sharedIterator(this._itp, this._keys, this._values); } function setEntries() { return sharedIterator(this._itp, this._values, this._values); } function sharedIterator(itp, array, array2) { var _ref; var p = [0], done = false; itp.push(p); return _ref = {}, _ref[Symbol.iterator] = function () { return this; }, _ref.next = function next() { var v, k = p[0]; if (!done && k < array.length) { v = array2 ? [array[k], array2[k]] : array[k]; p[0]++; } else { done = true; itp.splice(itp.indexOf(p), 1); } return { done: done, value: v }; }, _ref; } function sharedSize() { return this._values.length; } function sharedForEach(callback, context) { var it = this.entries(); for (;;) { var r = it.next(); if (r.done) break; callback.call(context, r.value[1], r.value[0], this); } } })(_aureliaPal.PLATFORM.global); } if (typeof FEATURE_NO_ES2015 === 'undefined') { var bind = Function.prototype.bind; if (typeof _aureliaPal.PLATFORM.global.Reflect === 'undefined') { _aureliaPal.PLATFORM.global.Reflect = {}; } if (typeof Reflect.defineProperty !== 'function') { Reflect.defineProperty = function (target, propertyKey, descriptor) { if ((typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' ? target === null : typeof target !== 'function') { throw new TypeError('Reflect.defineProperty called on non-object'); } try { Object.defineProperty(target, propertyKey, descriptor); return true; } catch (e) { return false; } }; } if (typeof Reflect.construct !== 'function') { Reflect.construct = function (Target, args) { if (args) { switch (args.length) { case 0: return new Target(); case 1: return new Target(args[0]); case 2: return new Target(args[0], args[1]); case 3: return new Target(args[0], args[1], args[2]); case 4: return new Target(args[0], args[1], args[2], args[3]); } } var a = [null]; a.push.apply(a, args); return new (bind.apply(Target, a))(); }; } if (typeof Reflect.ownKeys !== 'function') { Reflect.ownKeys = function (o) { return Object.getOwnPropertyNames(o).concat(Object.getOwnPropertySymbols(o)); }; } } if (typeof FEATURE_NO_ESNEXT === 'undefined') { var emptyMetadata = Object.freeze({}); var metadataContainerKey = '__metadata__'; if (typeof Reflect.getOwnMetadata !== 'function') { Reflect.getOwnMetadata = function (metadataKey, target, targetKey) { if (target.hasOwnProperty(metadataContainerKey)) { return (target[metadataContainerKey][targetKey] || emptyMetadata)[metadataKey]; } }; } if (typeof Reflect.defineMetadata !== 'function') { Reflect.defineMetadata = function (metadataKey, metadataValue, target, targetKey) { var metadataContainer = target.hasOwnProperty(metadataContainerKey) ? target[metadataContainerKey] : target[metadataContainerKey] = {}; var targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {}); targetContainer[metadataKey] = metadataValue; }; } if (typeof Reflect.metadata !== 'function') { Reflect.metadata = function (metadataKey, metadataValue) { return function (target, targetKey) { Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey); }; }; } }