es6-harmony
Version:
An equivalent implementation of ES6 in pure ES5 for old JavaScript engines
1 lines • 43.6 kB
JavaScript
!function(global,factory){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=factory(global):global.ES6=factory(global)}("undefined"!=typeof window?window:global,function(global){"use strict";var defineProperty=Object.defineProperty,defineProperties=Object.defineProperties,symbolHiddenCounter=0,globalSymbolRegistry=[],slice=Array.prototype.slice,stringSlice=String.prototype.slice,stringIndexOf=String.prototype.indexOf,isArray=Array.isArray,objectToString=Object.prototype.toString,push=Array.prototype.push,globalIsFinite=(String.prototype.match,isFinite),floor=Math.floor,max=Math.max,min=Math.min,create=Object.create,symbolBucket=create(null),symbolNamePattern=/^@_____$/,emptyFunction=function(){},simpleFunction=function(arg){return arg},isCallable=function(fn){return"function"==typeof fn},isConstructor=function(fn){return isCallable(fn)},Iterator=function(){},ArrayIterator=function(array,flag){this._array=array,this._flag=flag,this._nextIndex=0},StringIterator=function(string,flag){this._string=string,this._flag=flag,this._nextIndex=0},MapIterator=function(map,flag){this._map=map,this._flag=flag,this._currentEntry=null,this._done=!1},SetIterator=function(set,flag){this._set=set,this._flag=flag,this._currentEntry=null,this._done=!1},isObject=function(value){return null!==value&&("object"==typeof value||"function"==typeof value)},addToMessageQueue=function(fn,thisArg){if(!isCallable(fn))throw new TypeError(fn+" is not a function");var args=slice.call(arguments,2);setTimeout(function(){fn.apply(thisArg,args)})},setupSymbolInternals=function(symbol,desc){return defineProperties(symbol,{_description:{value:desc},_isSymbol:{value:!0},_id:{value:symbolHiddenCounter++}}),symbol},isSymbol=function(symbol){return symbol instanceof Symbol&&function(symbol){return!0===symbol._isSymbol&&"number"==typeof symbol._id&&"string"==typeof symbol._description}(symbol)},appendArray=function(array1,array2){if("number"==typeof array1.length&&array1.length>=0&&"number"==typeof array2.length&&array2.length>=0){var length1=Math.floor(array1.length),length2=Math.floor(array2.length),i=0;for(array1.length=length1+length2;i<length2;++i)array2.hasOwnProperty(i)&&(array1[length1+i]=array2[i])}},simpleInheritance=function(child,parent){if("function"!=typeof child||"function"!=typeof parent)throw new TypeError("Child and Parent must be function type");child.prototype=Object.create(parent.prototype),child.prototype.constructor=child},Symbol=function Symbol(desc){if(desc=void 0===desc?"":String(desc),this instanceof Symbol)throw new TypeError("Symbol is not a constructor");var newInstance=setupSymbolInternals(Object.create(Symbol.prototype),desc);return symbolBucket[newInstance._id]=newInstance,newInstance};defineProperties(Symbol,{for:{value:function(key){key=String(key);for(var record,registryLength=globalSymbolRegistry.length,i=0;i<registryLength;++i)if((record=globalSymbolRegistry[i]).key===key)return record.symbol;return record={key:key,symbol:Symbol(key)},globalSymbolRegistry.push(record),record.symbol},writable:!0,configurable:!0},keyFor:{value:function(symbol){if(!ES6.isSymbol(symbol))throw new TypeError(String(symbol)+" is not a symbol");for(var record,registryLength=globalSymbolRegistry.length,i=0;i<registryLength;++i)if((record=globalSymbolRegistry[i]).symbol===symbol)return record.key},writable:!0,configurable:!0},hasInstance:{value:Symbol("Symbol.hasInstance")},isConcatSpreadable:{value:Symbol("Symbol.isConcatSpreadable")},iterator:{value:Symbol("Symbol.iterator")},toStringTag:{value:Symbol("Symbol.toStringTag")}}),Symbol.prototype.toString=function(){return"@@_____"+this._id+"_____"},Symbol.prototype.valueOf=function(){return this},defineProperty(Iterator.prototype,Symbol.iterator.toString(),{value:function(){return this},writable:!0,configurable:!0}),simpleInheritance(ArrayIterator,Iterator),simpleInheritance(StringIterator,Iterator),simpleInheritance(MapIterator,Iterator),simpleInheritance(SetIterator,Iterator),defineProperty(ArrayIterator.prototype,Symbol.toStringTag.toString(),{value:"Array Iterator",configurable:!0}),defineProperty(StringIterator.prototype,Symbol.toStringTag.toString(),{value:"String Iterator",configurable:!0}),defineProperty(MapIterator.prototype,Symbol.toStringTag.toString(),{value:"Map Iterator",configurable:!0}),defineProperty(SetIterator.prototype,Symbol.toStringTag.toString(),{value:"Set Iterator",configurable:!0}),ArrayIterator.prototype.next=function(){if(!(this instanceof ArrayIterator))throw new TypeError("Method Array Iterator.prototype.next called on incompatible receiver "+String(this));var nextValue;return-1===this._nextIndex?{done:!0,value:void 0}:"number"==typeof this._array.length&&this._array.length>=0&&this._nextIndex<Math.floor(this._array.length)?(1===this._flag?nextValue=[this._nextIndex,this._array[this._nextIndex]]:2===this._flag?nextValue=this._array[this._nextIndex]:3===this._flag&&(nextValue=this._nextIndex),this._nextIndex++,{done:!1,value:nextValue}):(this._nextIndex=-1,{done:!0,value:void 0})},StringIterator.prototype.next=function(){if(!(this instanceof StringIterator))throw new TypeError("Method String Iterator.prototype.next called on incompatible receiver "+String(this));var nextValue,stringObject=new String(this._string);return-1===this._nextIndex?{done:!0,value:void 0}:this._nextIndex<stringObject.length?(nextValue=stringObject[this._nextIndex],this._nextIndex++,{done:!1,value:nextValue}):(this._nextIndex=-1,{done:!0,value:void 0})},MapIterator.prototype.next=function(){if(!(this instanceof MapIterator))throw new TypeError("Method Map Iterator.prototype.next called on incompatible receiver "+String(this));var nextValue;return this._done?{done:!0,value:void 0}:(null===this._currentEntry?this._currentEntry=this._map._head:this._currentEntry=this._currentEntry.next,null===this._currentEntry?(this._done=!0,{done:!0,value:void 0}):(1===this._flag?nextValue=[this._currentEntry.key,this._currentEntry.value]:2===this._flag?nextValue=this._currentEntry.value:3===this._flag&&(nextValue=this._currentEntry.key),{done:!1,value:nextValue}))},SetIterator.prototype.next=function(){if(!(this instanceof SetIterator))throw new TypeError("Method Set Iterator.prototype.next called on incompatible receiver "+String(this));var nextValue;return this._done?{done:!0,value:void 0}:(null===this._currentEntry?this._currentEntry=this._set._head:this._currentEntry=this._currentEntry.next,null===this._currentEntry?(this._done=!0,{done:!0,value:void 0}):(1===this._flag?nextValue=[this._currentEntry.value,this._currentEntry.value]:2===this._flag&&(nextValue=this._currentEntry.value),{done:!1,value:nextValue}))};var SpreadOperatorImpl=function(target,thisArg){this._target=target,this._values=[],this._thisArg=thisArg};SpreadOperatorImpl.prototype.spread=function(){var self=this;return slice.call(arguments).forEach(function(iterable){ES6.forOf(iterable,function(value){self._values.push(value)})}),self},SpreadOperatorImpl.prototype.add=function(){var self=this;return slice.call(arguments).forEach(function(value){self._values.push(value)}),self},SpreadOperatorImpl.prototype.call=function(thisArg){if("function"!=typeof this._target)throw new TypeError("Target is not a function");return thisArg=arguments.length<=0?this._thisArg:thisArg,this._target.apply(thisArg,this._values)},SpreadOperatorImpl.prototype.new=function(){if("function"!=typeof this._target)throw new TypeError("Target is not a constructor");var temp,returnValue;return temp=Object.create(this._target.prototype),returnValue=this._target.apply(temp,this._values),isObject(returnValue)?returnValue:temp},SpreadOperatorImpl.prototype.array=function(){if(!isArray(this._target))throw new TypeError("Target is not a array");return push.apply(this._target,this._values),this._target};var hash=function(key){var strKey=String(key);return void 0===key||null===key?"I___"+strKey:"number"==typeof key?"N___"+strKey:"string"==typeof key?"S___"+strKey:"boolean"==typeof key?"B___"+strKey:null},Map=function Map(iterable){if(!(this instanceof Map)||isMap(this))throw new TypeError("Constructor Map requires 'new'");setupMapInternals(this),null!==iterable&&void 0!==iterable&&ES6.forOf(iterable,function(entry){if(!isObject(entry))throw new TypeError("Iterator value "+entry+" is not an entry object");this.set(entry[0],entry[1])},this)};Map.prototype.set=function(key,value){if(!isMap(this))throw new TypeError("Method Map.prototype.set called on incompatible receiver "+this);var entry,keyHash=hash(key),objectHash=this._objectHash;if(null===keyHash){if("number"==typeof key[objectHash]&&this._data.objects[key[objectHash]]instanceof MapEntry)return(entry=this._data.objects[key[objectHash]]).value=value,this;entry=new MapEntry(key,value),this._data.objects.push(entry),defineProperty(key,objectHash.toString(),{value:this._data.objects.length-1,configurable:!0}),this._size++}else{if(this._data.primitives[keyHash]instanceof MapEntry)return(entry=this._data.primitives[keyHash]).value=value,this;entry=new MapEntry(key,value),this._data.primitives[keyHash]=entry,this._size++}return null===this._head&&(this._head=entry,entry.next=null,entry.prev=null),null===this._tail?this._tail=this._head:(this._tail.next=entry,entry.prev=this._tail,entry.next=null,this._tail=entry),this},Map.prototype.has=function(key){if(!isMap(this))throw new TypeError("Method Map.prototype.has called on incompatible receiver "+this);var keyHash=hash(key),objectHash=this._objectHash;return null===keyHash?"number"==typeof key[objectHash]&&this._data.objects[key[objectHash]]instanceof MapEntry:this._data.primitives[keyHash]instanceof MapEntry},Map.prototype.get=function(key){if(!isMap(this))throw new TypeError("Method Map.prototype.get called on incompatible receiver "+this);var keyHash=hash(key),objectHash=this._objectHash;if(null===keyHash){if("number"==typeof key[objectHash]&&this._data.objects[key[objectHash]]instanceof MapEntry)return this._data.objects[key[objectHash]].value}else if(this._data.primitives[keyHash]instanceof MapEntry)return this._data.primitives[keyHash].value},Map.prototype.clear=function(){if(!isMap(this))throw new TypeError("Method Map.prototype.clear called on incompatible receiver "+this);var entry;Object.getOwnPropertyNames(this._data.primitives).forEach(function(prop){this._data.primitives[prop]instanceof MapEntry&&(entry=this._data.primitives[prop],delete this._data.primitives[prop],entry.next=null,entry.prev=null)},this),Object.getOwnPropertyNames(this._data.objects).forEach(function(prop){this._data.objects[prop]instanceof MapEntry&&(entry=this._data.objects[prop],delete this._data.objects[prop],delete entry.key[this._objectHash],entry.next=null,entry.prev=null)},this),this._data.objects.length=0,this._head=null,this._tail=null,this._size=0},Map.prototype.delete=function(key){if(!isMap(this))throw new TypeError("Method Map.prototype.delete called on incompatible receiver "+this);var entry,keyHash=hash(key),objectHash=this._objectHash;if(null===keyHash){if(!("number"==typeof key[objectHash]&&this._data.objects[key[objectHash]]instanceof MapEntry))return!1;entry=this._data.objects[key[objectHash]],delete this._data.objects[key[objectHash]],delete entry.key[objectHash]}else{if(!(this._data.primitives[keyHash]instanceof MapEntry))return!1;entry=this._data.primitives[keyHash],delete this._data.primitives[keyHash]}return null!==entry.prev&&null!==entry.next?(entry.prev.next=entry.next,entry.next.prev=entry.prev,entry.next=null,entry.prev=null):null===entry.prev&&null!==entry.next&&(this._head=entry.next,entry.next.prev=null,entry.next=null),null!==entry.prev&&null===entry.next?(this._tail=entry.prev,entry.prev.next=null,entry.prev=null):(this._head=null,this._tail=null),this._size--,!0},defineProperty(Map.prototype,"size",{get:function(){if(!isMap(this))throw new TypeError("Method Map.prototype.size called on incompatible receiver "+this);return this._size},configurable:!0}),Map.prototype.entries=function(){if(!isMap(this))throw new TypeError("Method Map.prototype.entries called on incompatible receiver "+this);return new MapIterator(this,1)},Map.prototype.values=function(){if(!isMap(this))throw new TypeError("Method Map.prototype.values called on incompatible receiver "+this);return new MapIterator(this,2)},Map.prototype.keys=function(){if(!isMap(this))throw new TypeError("Method Map.prototype.keys called on incompatible receiver "+this);return new MapIterator(this,3)},Map.prototype.forEach=function(callback,thisArg){if(!isMap(this))throw new TypeError("Method Map.prototype.forEach called on incompatible receiver "+this);if(!isCallable(callback))throw new TypeError(callback+" is not a function");for(var currentEntry=this._head;null!==currentEntry;)callback.call(thisArg,currentEntry.value,currentEntry.key,this),currentEntry=currentEntry.next},Map.prototype[Symbol.iterator]=Map.prototype.entries,defineProperty(Map.prototype,Symbol.toStringTag.toString(),{value:"Map",configurable:!0});var setupMapInternals=function(map){defineProperties(map,{_isMap:{value:!0},_head:{value:null,writable:!0},_tail:{value:null,writable:!0},_objectHash:{value:Symbol("Hash(map)")},_size:{value:0,writable:!0},_data:{value:create(null,{primitives:{value:create(null)},objects:{value:[]}})}})},isMap=function(map){return map instanceof Map&&function(map){return!0===map._isMap&&(null===map._head||map._head instanceof MapEntry)&&(null===map._tail||map._tail instanceof MapEntry)&&ES6.isSymbol(map._objectHash)&&"number"==typeof map._size&&isObject(map._data)&&isObject(map._data.primitives)&&isArray(map._data.objects)}(map)},MapEntry=function(key,value){this.key=key,this.value=value,this.next=null,this.prev=null},Set=function Set(iterable){if(!(this instanceof Set)||isSet(this))throw new TypeError("Constructor Set requires 'new'");setupSetInternals(this),null!==iterable&&void 0!==iterable&&ES6.forOf(iterable,function(entry){this.add(entry)},this)};Set.prototype.add=function(value){if(!isSet(this))throw new TypeError("Method Set.prototype.add called on incompatible receiver "+this);var entry,valueHash=hash(value),objectHash=this._objectHash;if(null===valueHash){if("number"==typeof value[objectHash]&&this._data.objects[value[objectHash]]instanceof SetEntry)return this;entry=new SetEntry(value),this._data.objects.push(entry),defineProperty(value,objectHash.toString(),{value:this._data.objects.length-1,configurable:!0}),this._size++}else{if(this._data.primitives[valueHash]instanceof SetEntry)return this;entry=new SetEntry(value),this._data.primitives[valueHash]=entry,this._size++}return null===this._head&&(this._head=entry,entry.next=null,entry.prev=null),null===this._tail?this._tail=this._head:(this._tail.next=entry,entry.prev=this._tail,entry.next=null,this._tail=entry),this},Set.prototype.has=function(value){if(!isSet(this))throw new TypeError("Method Set.prototype.has called on incompatible receiver "+this);var valueHash=hash(value),objectHash=this._objectHash;return null===valueHash?"number"==typeof value[objectHash]&&this._data.objects[value[objectHash]]instanceof SetEntry:this._data.primitives[valueHash]instanceof SetEntry},Set.prototype.clear=function(){if(!isSet(this))throw new TypeError("Method Set.prototype.clear called on incompatible receiver "+this);var entry;Object.getOwnPropertyNames(this._data.primitives).forEach(function(prop){this._data.primitives[prop]instanceof SetEntry&&(entry=this._data.primitives[prop],delete this._data.primitives[prop],entry.next=null,entry.prev=null)},this),Object.getOwnPropertyNames(this._data.objects).forEach(function(prop){this._data.objects[prop]instanceof SetEntry&&(entry=this._data.objects[prop],delete this._data.objects[prop],delete entry.value[this._objectHash],entry.next=null,entry.prev=null)},this),this._data.objects.length=0,this._head=null,this._tail=null,this._size=0},Set.prototype.delete=function(value){if(!isSet(this))throw new TypeError("Method Set.prototype.delete called on incompatible receiver "+this);var entry,valueHash=hash(value),objectHash=this._objectHash;if(null===valueHash){if(!("number"==typeof value[objectHash]&&this._data.objects[value[objectHash]]instanceof SetEntry))return!1;entry=this._data.objects[value[objectHash]],delete this._data.objects[value[objectHash]],delete entry.value[objectHash]}else{if(!(this._data.primitives[valueHash]instanceof SetEntry))return!1;entry=this._data.primitives[valueHash],delete this._data.primitives[valueHash]}return null!==entry.prev&&null!==entry.next?(entry.prev.next=entry.next,entry.next.prev=entry.prev,entry.next=null,entry.prev=null):null===entry.prev&&null!==entry.next&&(this._head=entry.next,entry.next.prev=null,entry.next=null),null!==entry.prev&&null===entry.next?(this._tail=entry.prev,entry.prev.next=null,entry.prev=null):(this._head=null,this._tail=null),this._size--,!0},Set.prototype.entries=function(){if(!isSet(this))throw new TypeError("Method Set.prototype.entries called on incompatible receiver "+this);return new SetIterator(this,1)},Set.prototype.values=function(){if(!isSet(this))throw new TypeError("Method Set.prototype.values called on incompatible receiver "+this);return new SetIterator(this,2)},Set.prototype.keys=Set.prototype.values,Set.prototype[Symbol.iterator]=Set.prototype.values,defineProperty(Set.prototype,"size",{get:function(){if(!isSet(this))throw new TypeError("Method Set.prototype.size called on incompatible receiver "+this);return this._size},configurable:!0}),Set.prototype.forEach=function(callback,thisArg){if(!isSet(this))throw new TypeError("Method Set.prototype.forEach called on incompatible receiver "+this);if(!isCallable(callback))throw new TypeError(callback+" is not a function");for(var currentEntry=this._head;null!==currentEntry;)callback.call(thisArg,currentEntry.value,currentEntry.value,this),currentEntry=currentEntry.next},defineProperty(Set.prototype,Symbol.toStringTag.toString(),{value:"Set",configurable:!0});var setupSetInternals=function(set){defineProperties(set,{_isSet:{value:!0},_head:{value:null,writable:!0},_tail:{value:null,writable:!0},_objectHash:{value:Symbol("Hash(set)")},_size:{value:0,writable:!0},_data:{value:create(null,{primitives:{value:create(null)},objects:{value:[]}})}})},SetEntry=function(value){this.value=value,this.next=null,this.prev=null},isSet=function(set){return set instanceof Set&&function(set){return!0===set._isSet&&(null===set._head||set._head instanceof SetEntry)&&(null===set._tail||set._tail instanceof SetEntry)&&ES6.isSymbol(set._objectHash)&&"number"==typeof set._size&&isObject(set._data)&&isObject(set._data.primitives)&&isArray(set._data.objects)}(set)},WeakMap=function WeakMap(iterable){if(!(this instanceof WeakMap)||isWeakMap(this))throw new TypeError("Constructor WeakMap requires 'new'");setupWeakMapInternals(this),null!==iterable&&void 0!==iterable&&ES6.forOf(iterable,function(entry){if(!isObject(entry))throw new TypeError("Iterator value "+entry+" is not an entry object");this.set(entry[0],entry[1])},this)},setupWeakMapInternals=function(weakMap){defineProperties(weakMap,{_isWeakMap:{value:!0},_objectHash:{value:Symbol("Hash(weakmap)")},_values:{value:[]}})};defineProperty(WeakMap.prototype,Symbol.toStringTag.toString(),{value:"WeakMap",configurable:!0});var isWeakMap=function(weakMap){return weakMap instanceof WeakMap&&function(weakMap){return!0===weakMap._isWeakMap&&ES6.isSymbol(weakMap._objectHash)&&isArray(weakMap._values)}(weakMap)};WeakMap.prototype.set=function(key,value){if(!isWeakMap(this))throw new TypeError("Method WeakMap.prototype.set called on incompatible receiver "+this);if(!isObject(key)||ES6.isSymbol(key))throw new TypeError("Invalid value used as weak map key");var objectHash=this._objectHash;return"number"==typeof key[objectHash]&&this._values.hasOwnProperty(key[objectHash])?this._values[key[objectHash]]=value:(this._values.push(value),defineProperty(key,objectHash.toString(),{value:this._values.length-1,configurable:!0})),this},WeakMap.prototype.get=function(key){if(!isWeakMap(this))throw new TypeError("Method WeakMap.prototype.get called on incompatible receiver "+this);if(isObject(key)&&!ES6.isSymbol(key)){var objectHash=this._objectHash;return"number"==typeof key[objectHash]&&this._values.hasOwnProperty(key[objectHash])?this._values[key[objectHash]]:void 0}},WeakMap.prototype.has=function(key){if(!isWeakMap(this))throw new TypeError("Method WeakMap.prototype.has called on incompatible receiver "+this);if(!isObject(key)||ES6.isSymbol(key))return!1;var objectHash=this._objectHash;return"number"==typeof key[objectHash]&&this._values.hasOwnProperty(key[objectHash])},WeakMap.prototype.delete=function(key){if(!isWeakMap(this))throw new TypeError("Method WeakMap.prototype.delete called on incompatible receiver "+this);if(!isObject(key)||ES6.isSymbol(key))return!1;var objectHash=this._objectHash;return!("number"!=typeof key[objectHash]||!this._values.hasOwnProperty(key[objectHash]))&&(delete this._values[key[objectHash]],delete key[objectHash],!0)};var WeakSet=function WeakSet(iterable){if(!(this instanceof WeakSet)||isWeakSet(this))throw new TypeError("Constructor WeakSet requires 'new'");setupWeakSetInternals(this),null!==iterable&&void 0!==iterable&&ES6.forOf(iterable,function(entry){this.add(entry)},this)},setupWeakSetInternals=function(weakSet){defineProperties(weakSet,{_isWeakSet:{value:!0},_objectHash:{value:Symbol("Hash(weakset)")}})},isWeakSet=function(weakSet){return weakSet instanceof WeakSet&&function(weakSet){return!0===weakSet._isWeakSet&&ES6.isSymbol(weakSet._objectHash)}(weakSet)};WeakSet.prototype.add=function(value){if(!isWeakSet(this))throw new TypeError("Method WeakSet.prototype.add called on incompatible receiver "+this);if(!isObject(value)||ES6.isSymbol(value))throw new TypeError("Invalid value used in weak set");var objectHash=this._objectHash;return value[objectHash]===objectHash.toString()||defineProperty(value,objectHash.toString(),{value:objectHash.toString(),configurable:!0}),this},WeakSet.prototype.has=function(value){if(!isWeakSet(this))throw new TypeError("Method WeakSet.prototype.has called on incompatible receiver "+this);if(!isObject(value)||ES6.isSymbol(value))return!1;var objectHash=this._objectHash;return value[objectHash]===objectHash.toString()},WeakSet.prototype.delete=function(value){if(!isWeakSet(this))throw new TypeError("Method WeakSet.prototype.delete called on incompatible receiver "+this);if(!isObject(value)||ES6.isSymbol(value))return!1;var objectHash=this._objectHash;return value[objectHash]===objectHash.toString()&&(delete value[objectHash],!0)},defineProperty(WeakSet.prototype,Symbol.toStringTag.toString(),{value:"WeakSet",configurable:!0});var Promise=function Promise(executor){if(!(this instanceof Promise)||isPromise(this))throw new TypeError(String(this)+" is not a promise");if(!isCallable(executor))throw new TypeError("Promise resolver "+String(executor)+" is not a function");setupPromiseInternals(this);try{executor(function(value){this._resolve(value)}.bind(this),function(reason){this._reject(reason)}.bind(this))}catch(e){this._reject(e)}};Promise.resolve=function(value){return isPromise(value)?value:new Promise(function(resolve,reject){isThenable(value)?addToMessageQueue(function(){try{value.then(resolve,reject)}catch(e){reject(e)}}):resolve(value)})},Promise.reject=function(reason){return new Promise(function(resoolve,reject){reject(reason)})},Promise.race=function(iterable){var isSettled=!1;return new Promise(function(resolve,reject){ES6.forOf(iterable,function(promise){var temp1,temp2;isPromise(promise)?isFulfilledPromise(promise)?isSettled||(isSettled=!0,addToMessageQueue(function(){resolve(promise._value)})):isRejectedPromise(promise)?isSettled||(isSettled=!0,addToMessageQueue(function(){reject(promise._reason)})):isPendingPromise(promise)&&(temp1=promise._resolve,temp2=promise._reject,defineProperties(promise,{_resolve:{value:function(value){temp1(value),isSettled||(isSettled=!0,resolve(value))}.bind(promise)},_reject:{value:function(reason){temp2(reason),isSettled||(isSettled=!0,reject(reason))}.bind(promise)}})):isThenable(promise)?addToMessageQueue(function(){try{promise.then(function(value){isSettled||(isSettled=!0,resolve(value))},function(reason){isSettled||(isSettled=!0,reject(reason))})}catch(e){reject(e)}}):isSettled||(isSettled=!0,addToMessageQueue(function(){resolve(promise)}))})})},Promise.all=function(iterable){var promises=ES6.spreadOperator([]).spread(iterable).array(),counter=0,length=promises.length,values=new Array(length);return new Promise(function(resolve,reject){0===length?resolve(values):promises.forEach(function(promise,index){var temp1,temp2;isPromise(promise)?isFulfilledPromise(promise)?(values[index]=promise._value,++counter===length&&addToMessageQueue(function(){resolve(values)})):isRejectedPromise(promise)?addToMessageQueue(function(){reject(promise._reason)}):isPendingPromise(promise)&&(temp1=promise._resolve,temp2=promise._reject,defineProperties(promise,{_resolve:{value:function(value){temp1(value),values[index]=value,++counter===length&&resolve(values)}.bind(promise)},_reject:{value:function(reason){temp2(reason),reject(reason)}.bind(promise)}})):isThenable(promise)?addToMessageQueue(function(){try{promise.then(function(value){values[index]=value,++counter===length&&resolve(values)},function(reason){reject(reason)})}catch(e){reject(e)}}):(values[index]=promise,++counter===length&&addToMessageQueue(function(){resolve(values)}))})})},Promise.prototype.then=function(onFulfilled,onRejected){if(!isPromise(this))throw new TypeError(this+" is not a promise");onFulfilled=isCallable(onFulfilled)?onFulfilled:defaultPromiseOnFulfilled,onRejected=isCallable(onRejected)?onRejected:defaultPromiseOnRejected;var nextOnFulfilled,nextOnRejected,chainedPromise=new Promise(function(resolve,reject){});return nextOnFulfilled=function(value){var result;try{result=onFulfilled(value),processPromiseResult(result,chainedPromise)}catch(e){chainedPromise._reject(e)}},nextOnRejected=function(reason){var result;try{result=onRejected(reason),processPromiseResult(result,chainedPromise)}catch(e){chainedPromise._reject(e)}},isPendingPromise(this)?(this._onFulfilled.push(nextOnFulfilled),this._onRejected.push(nextOnRejected)):isFulfilledPromise(this)?addToMessageQueue(nextOnFulfilled,void 0,this._value):isRejectedPromise(this)&&addToMessageQueue(nextOnRejected,void 0,this._reason),chainedPromise};var processPromiseResult=function(result,chainedPromise){var temp1,temp2;isPromise(result)?isFulfilledPromise(result)?chainedPromise._resolve(result._value):isRejectedPromise(result)?chainedPromise._reject(result._reason):isPendingPromise(result)&&(temp1=result._resolve,temp2=result._reject,defineProperties(result,{_resolve:{value:function(value){temp1(value),chainedPromise._resolve(value)}.bind(result)},_reject:{value:function(reason){temp2(reason),chainedPromise._reject(reason)}.bind(result)}})):isThenable(result)?addToMessageQueue(function(){try{result.then(function(value){this._resolve(value)}.bind(chainedPromise),function(reason){this._reject(reason)}.bind(chainedPromise))}catch(e){chainedPromise._reject(e)}}):chainedPromise._resolve(result)};Promise.prototype.catch=function(onRejected){if(!isCallable(this.then))throw new TypeError("(var).then is not a function");return this.then(void 0,onRejected)},defineProperty(Promise.prototype,Symbol.toStringTag.toString(),{value:"Promise",configurable:!0}),Promise.prototype.toString=function(){if(!isPromise(this))throw new TypeError(this+" is not a promise");switch(this._state){case"pending":return"Promise { <pending> }";case"fulfilled":return"Promise { "+this._value+" }";case"rejected":return"Promise { <rejected> "+this._reason+" }"}};var isThenable=function(value){return isObject(value)&&isCallable(value.then)},defaultPromiseOnFulfilled=function(value){return Promise.resolve(value)},defaultPromiseOnRejected=function(reason){return Promise.reject(reason)},setupPromiseInternals=function(promise){defineProperties(promise,{_isPromise:{value:!0},_onFulfilled:{value:[]},_onRejected:{value:[]},_resolve:{value:function(value){isSettledPromise(this)||(defineProperties(this,{_state:{value:"fulfilled"},_value:{value:value}}),this._onFulfilled.length>0&&addToMessageQueue(function(value){this._onFulfilled.forEach(function(callback){callback(value)}),this._onFulfilled.length=0,this._onRejected.length=0},this,value))}.bind(promise),configurable:!0},_reject:{value:function(reason){isSettledPromise(this)||(defineProperties(this,{_state:{value:"rejected"},_reason:{value:reason}}),this._onRejected.length>0&&addToMessageQueue(function(reason){this._onRejected.forEach(function(callback){callback(reason)}),this._onFulfilled.length=0,this._onRejected.length=0},this,reason))}.bind(promise),configurable:!0},_state:{value:"pending",configurable:!0},_value:{value:void 0,configurable:!0},_reason:{value:void 0,configurable:!0}})},isPendingPromise=function(promise){return"pending"===promise._state},isFulfilledPromise=function(promise){return"fulfilled"===promise._state},isRejectedPromise=function(promise){return"rejected"===promise._state},isSettledPromise=function(promise){return"fulfilled"===promise._state||"rejected"===promise._state},checkPromiseInternals=function(promise){return!0===promise._isPromise&&isArray(promise._onFulfilled)&&isArray(promise._onRejected)&&isCallable(promise._resolve)&&isCallable(promise._reject)&&(state=promise._state,-1!==["pending","fulfilled","rejected"].indexOf(String(state)))&&promise.hasOwnProperty("_value")&&promise.hasOwnProperty("_reason");var state},isPromise=function(promise){return promise instanceof Promise&&checkPromiseInternals(promise)},es6NumberIsNaN=function(value){return"number"==typeof value&&value!=value},es6NumberIsFinite=function(value){return"number"==typeof value&&globalIsFinite(value)},es6NumberIsInteger=function(value){return es6NumberIsFinite(value)&&floor(value)===value},ES6={isSymbol:isSymbol,instanceOf:function(object,constructor){if(!isObject(constructor))throw new TypeError("Right-hand side of 'instanceof' is not an object");var hasInstanceSymbolProp=constructor[Symbol.hasInstance];if(void 0===hasInstanceSymbolProp)return object instanceof constructor;if("function"!=typeof hasInstanceSymbolProp)throw new TypeError(typeof hasInstanceSymbolProp+" is not a function");return hasInstanceSymbolProp.call(constructor,object)},forOf:function(iterable,callback,thisArg){if(callback="function"!=typeof callback?emptyFunction:callback,"function"!=typeof iterable[Symbol.iterator])throw new TypeError("Iterable[Symbol.iterator] is not a function");var iterationResult,iterator=iterable[Symbol.iterator]();if("function"!=typeof iterator.next)throw new TypeError(".iterator.next is not a function");for(;;){if(iterationResult=iterator.next(),!isObject(iterationResult))throw new TypeError("Iterator result "+iterationResult+" is not an object");if(iterationResult.done)break;callback.call(thisArg,iterationResult.value)}},spreadOperator:function(target,thisArg){if("function"!=typeof target&&!isArray(target))throw new TypeError("Spread operator only supports on array and function objects at this moment");return new SpreadOperatorImpl(target,thisArg)},isMap:isMap,isSet:isSet,isWeakMap:isWeakMap,isWeakSet:isWeakSet,isPromise:isPromise};return defineProperty(global,"Symbol",{value:Symbol,writable:!0,configurable:!0}),defineProperty(global,"Map",{value:Map,writable:!0,configurable:!0}),defineProperty(global,"Set",{value:Set,writable:!0,configurable:!0}),defineProperty(global,"WeakMap",{value:WeakMap,writable:!0,configurable:!0}),defineProperty(global,"WeakSet",{value:WeakSet,writable:!0,configurable:!0}),defineProperty(global,"Promise",{value:Promise,writable:!0,configurable:!0}),defineProperty(Function.prototype,Symbol.hasInstance.toString(),{value:function(instance){return"function"==typeof this&&instance instanceof this}}),defineProperty(Object,"is",{value:function(value1,value2){return"number"==typeof value1&&"number"==typeof value2?0===value1&&0===value2?1/value1==1/value2:!(!es6NumberIsNaN(value1)||!es6NumberIsNaN(value2))||value1===value2:value1===value2},writable:!0,configurable:!0}),defineProperty(Object,"setPrototypeOf",{value:function(obj,prototype){if(void 0===obj||null===obj)throw new TypeError("Object.setPrototypeOf called on null or undefined");if(null!==prototype&&!isObject(prototype))throw new TypeError("Object prototype may only be an Object or null: "+String(prototype));var protoDesc=Object.getOwnPropertyDescriptor(Object.prototype,"__proto__");if(void 0===protoDesc||!isCallable(protoDesc.set))throw new TypeError("Object.prototype.__proto__ accessor property does not exist");return protoDesc.set.call(obj,prototype),obj},writable:!0,configurable:!0}),defineProperty(Object,"assign",{value:function(target){if(null===target||void 0===target)throw new TypeError("Cannot convert undefined or null to object");var i,j,keys,nextSource;for(target=Object(target),i=1;i<arguments.length;++i)if(void 0!==(nextSource=arguments[i])&&null!==nextSource)for(nextSource=Object(nextSource),keys=Object.keys(nextSource),j=0;j<keys.length;++j)target[keys[j]]=nextSource[keys[j]];return target},writable:!0,configurable:!0}),defineProperty(Object,"getOwnPropertySymbols",{value:function(obj){if(null===obj||void 0===obj)throw new TypeError("Cannot convert undefined or null to object");obj=Object(obj);var matched,sId,foundSymbols=[];return Object.getOwnPropertyNames(obj).forEach(function(prop){null!==(matched=prop.match(symbolNamePattern))&&(sId=matched[1],isSymbol(symbolBucket[sId])&&foundSymbols.push(symbolBucket[sId]))}),foundSymbols},writable:!0,configurable:!0}),defineProperty(Object.prototype,"toString",{value:function(){return void 0===this||null===this?objectToString.call(this):"string"==typeof this[Symbol.toStringTag]?"[object "+this[Symbol.toStringTag]+"]":objectToString.call(this)},writable:!0,configurable:!0}),defineProperty(String,"fromCodePoint",{value:function(){for(var codePoint,i=0,outChars=[],length=arguments.length;i<length;++i){if(codePoint=Number(arguments[i]),!(Number.isInteger(codePoint)&&codePoint>=0&&codePoint<=1114111))throw new RangeError("Invalid code point "+codePoint);codePoint<65536?outChars.push(String.fromCharCode(codePoint)):(codePoint-=65536,outChars.push(String.fromCharCode(55296+(codePoint>>10))),outChars.push(String.fromCharCode(codePoint%1024+56320)))}return outChars.join("")},writable:!0,configurable:!0}),defineProperty(String.prototype,Symbol.iterator.toString(),{value:function(){if(void 0===this||null===this)throw new TypeError("String.prototype[Symbol.iterator] called on null or undefined");return new StringIterator(String(this),0)},writable:!0,configurable:!0}),defineProperty(String.prototype,"codePointAt",{value:function(position){if(void 0===this||null===this)throw new TypeError("String.prototype.codePointAt called on null or undefined");var first,second,self=String(this),length=self.length;if(position=Number(position),(position=((position=Number.isNaN(position)?0:position)<0?-1:1)*Math.floor(Math.abs(position)))>=0&&position<length)return(first=self.charCodeAt(position))>=55296&&first<=56319&&position+1<length&&(second=self.charCodeAt(position+1))>=56320&&second<=57343?1024*(first-55296)+second-56320+65536:first},writable:!0,configurable:!0}),defineProperty(String.prototype,"startsWith",{value:function(searchString,position){if(void 0===this||null===this)throw new TypeError("String.prototype.startsWith called on null or undefined");if("[object RegExp]"===objectToString.call(searchString))throw new TypeError("First argument to String.prototype.startsWith must not be a regular expression");var searchStringLength,startIndex,self=String(this),i=0,length=self.length;if(searchStringLength=(searchString=String(searchString)).length,position=Number(position),position=((position=Number.isNaN(position)?0:position)<0?-1:1)*Math.floor(Math.abs(position)),(startIndex=min(max(position,0),length))+searchStringLength>length)return!1;for(;i<searchStringLength;++i)if(searchString.charCodeAt(i)!==self.charCodeAt(startIndex+i))return!1;return!0},writable:!0,configurable:!0}),defineProperty(String.prototype,"endsWith",{value:function(searchString,position){if(void 0===this||null===this)throw new TypeError("String.prototype.endsWith called on null or undefined");if("[object RegExp]"===objectToString.call(searchString))throw new TypeError("First argument to String.prototype.endsWith must not be a regular expression");var endIndex,searchStringLength,self=String(this),length=self.length;return searchStringLength=(searchString=String(searchString)).length,position=void 0===position?length:position,position=Number(position),position=((position=Number.isNaN(position)?0:position)<0?-1:1)*Math.floor(Math.abs(position)),endIndex=min(max(position,0),length),stringSlice.call(self,endIndex-searchStringLength,endIndex)===searchString},writable:!0,configurable:!0}),defineProperty(String.prototype,"includes",{value:function(searchString,position){if(void 0===this||null===this)throw new TypeError("String.prototype.endsWith called on null or undefined");if("[object RegExp]"===objectToString.call(searchString))throw new TypeError("First argument to String.prototype.includes must not be a regular expression");var self=String(this);return-1!==stringIndexOf.call(self,searchString,position)},writable:!0,configurable:!0}),defineProperty(String.prototype,"repeat",{value:function(count){if(void 0===this||null===this)throw new TypeError("String.prototype.repeat called on null or undefined");var self=String(this);if(count=Number(count),(count=((count=Number.isNaN(count)?0:count)<0?-1:1)*Math.floor(Math.abs(count)))<0||count>=1/0)throw new RangeError("Invalid count value");return function repeatString(string,count){if(count<1)return"";if(count%2)return repeatString(string,count-1)+string;var half=repeatString(string,count/2);return half+half}(self,count)},writable:!0,configurable:!0}),defineProperty(Array,"from",{value:function(arrayLike,mapFn,thisArg){var constructor,length,outputs,i=0;if(constructor=isConstructor(this)?this:Array,void 0===arrayLike||null===arrayLike)throw new TypeError("Cannot convert undefined or null to object");if(arrayLike=Object(arrayLike),void 0===mapFn)mapFn=simpleFunction;else if(!isCallable(mapFn))throw new TypeError(mapFn+" is not a function");if(void 0===arrayLike[Symbol.iterator]){if(!("number"==typeof arrayLike.length&&arrayLike.length>=0))return(outputs=new constructor(0)).length=0,outputs;for(length=Math.floor(arrayLike.length),(outputs=new constructor(length)).length=length;i<length;++i)outputs[i]=mapFn.call(thisArg,arrayLike[i])}else(outputs=new constructor).length=0,ES6.forOf(arrayLike,function(value){outputs.length++,outputs[outputs.length-1]=mapFn.call(thisArg,value)});return outputs},writable:!0,configurable:!0}),defineProperty(Array,"of",{value:function(){var outputs,length,i=0;for((outputs=new(isConstructor(this)?this:Array)(length=arguments.length)).length=length;i<length;++i)outputs[i]=arguments[i];return outputs},writable:!0,configurable:!0}),defineProperty(Array.prototype,Symbol.iterator.toString(),{value:function(){if(void 0===this||null===this)throw new TypeError("Cannot convert undefined or null to object");var self=Object(this);return new ArrayIterator(self,2)},writable:!0,configurable:!0}),defineProperty(Array.prototype,"entries",{value:function(){if(void 0===this||null===this)throw new TypeError("Cannot convert undefined or null to object");var self=Object(this);return new ArrayIterator(self,1)},writable:!0,configurable:!0}),defineProperty(Array.prototype,"keys",{value:function(){if(void 0===this||null===this)throw new TypeError("Cannot convert undefined or null to object");var self=Object(this);return new ArrayIterator(self,3)},writable:!0,configurable:!0}),defineProperty(Array.prototype,"concat",{value:function(){if(void 0===this||null===this)throw new TypeError("Array.prototype.concat called on null or undefined");var self=Object(this),targets=slice.call(arguments),outputs=[];return targets.unshift(self),targets.forEach(function(target){isObject(target)?void 0!==target[Symbol.isConcatSpreadable]?target[Symbol.isConcatSpreadable]?appendArray(outputs,target):outputs.push(target):isArray(target)?appendArray(outputs,target):outputs.push(target):outputs.push(target)}),outputs},writable:!0,configurable:!0}),defineProperty(Array.prototype,"fill",{value:function(value,start,end){if(void 0===this||null===this)throw new TypeError("Array.prototype.fill called on null or undefined");var length,self=Object(this),i=0;if("number"==typeof self.length&&self.length>=0)for(length=Math.floor(self.length),start=void 0===start?0:Math.floor(Number(start)),end=void 0===end?length:Math.floor(Number(end)),start=start<0?start+length:start,end=end<0?end+length:end,start=start<0?0:start,end=end>length?length:end,i=start;i<end;++i)self[i]=value;return self},writable:!0,configurable:!0}),defineProperty(Array.prototype,"find",{value:function(callback,thisArg){if(void 0===this||null===this)throw new TypeError("Array.prototype.find called on null or undefined");if(!isCallable(callback))throw new TypeError(callback+" is not a function");var length,self=Object(this),i=0;if("number"==typeof self.length&&self.length>=0)for(length=Math.floor(self.length);i<length;++i)if(callback.call(thisArg,self[i],i,self))return self[i]},writable:!0,configurable:!0}),defineProperty(Array.prototype,"findIndex",{value:function(callback,thisArg){if(void 0===this||null===this)throw new TypeError("Array.prototype.findIndex called on null or undefined");if(!isCallable(callback))throw new TypeError(callback+" is not a function");var length,self=Object(this),i=0;if("number"==typeof self.length&&self.length>=0)for(length=Math.floor(self.length);i<length;++i)if(callback.call(thisArg,self[i],i,self))return i;return-1},writable:!0,configurable:!0}),defineProperty(Array.prototype,"copyWithin",{value:function(target,start){if(void 0==this||null===this)throw new TypeError("Array.prototype.copyWithin called on null or undefined");var self=Object(this),length=self.length>>>0,relativeTarget=target>>0,to=relativeTarget<0?max(length+relativeTarget,0):min(relativeTarget,length),relativeStart=start>>0,from=relativeStart<0?max(length+relativeStart,0):min(relativeStart,length),end=arguments[2],relativeEnd=void 0===end?length:end>>0,final=relativeEnd<0?max(length+relativeEnd,0):min(relativeEnd,length),count=min(final-from,length-to),direction=1;for(from<to&&to<from+count&&(direction=-1,from+=count-1,to+=count-1);count>0;)from in self?self[to]=self[from]:delete self[to],from+=direction,to+=direction,count--;return self},writable:!0,configurable:!0}),defineProperty(Number,"isNaN",{value:es6NumberIsNaN,writable:!0,configurable:!0}),defineProperty(Number,"isFinite",{value:es6NumberIsFinite,writable:!0,configurable:!0}),defineProperty(Number,"isInteger",{value:es6NumberIsInteger,writable:!0,configurable:!0}),defineProperty(Number,"parseInt",{value:parseInt,writable:!0,configurable:!0}),defineProperty(Number,"parseFloat",{value:parseFloat,writable:!0,configurable:!0}),defineProperty(Number,"isSafeInteger",{value:function(value){return es6NumberIsInteger(value)&&Math.abs(value)<=Number.MAX_SAFE_INTEGER},writable:!0,configurable:!0}),"number"!=typeof Number.EPSILON&&defineProperty(Number,"EPSILON",{value:2.220446049250313e-16}),"number"!=typeof Number.MAX_SAFE_INTEGER&&defineProperty(Number,"MAX_SAFE_INTEGER",{value:Math.pow(2,53)-1}),"number"!=typeof Number.MIN_SAFE_INTEGER&&defineProperty(Number,"MIN_SAFE_INTEGER",{value:-(Math.pow(2,53)-1)}),ES6});