eaglercraft-1.8/sources/setup/workspace_template/javascript/ES6ShimScript.txt

41 lines
21 KiB
Plaintext
Raw Normal View History

(function(_jsGlobal){try {(function(){var namedFunction=function(name,body){if(typeof body==="function"){try {Object.defineProperty(body,"name",{configurable:true,enumerable:false,writable:false,value:name});}catch(ex){}}return body;};var enabledShims=[];var collectionsShimImpl=function(){var i;var createCollection=function(proto,objectOnly){var Collection=namedFunction("Collection",function(a){if(!this||this.constructor!==Collection)return new Collection(a);Object.defineProperty(this,
"_keys",{value:[]});Object.defineProperty(this,"_values",{value:[]});Object.defineProperty(this,"_itp",{value:[]});Object.defineProperty(this,"objectOnly",{value:objectOnly});if(a)init.call(this,a);});if(!objectOnly){Object.defineProperty(proto,"size",{get:sharedSize});}proto.constructor=Collection;for(var k in proto){Object.defineProperty(Collection.prototype,k,{value:proto[k]});}return Collection;};var init=function(a){if(this.add)a.forEach(this.add,this);else a.forEach(function(a){this.set(a[0],a[1]);},this);};var sharedDelete
=function(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;};var sharedGet=namedFunction("get",function(key){return this.has(key)?this._values[i]:$rt_globals.undefined;});var has=namedFunction("has",function(list,key){if(this.objectOnly&&key!==Object(key))throw new $rt_globals.TypeError("Invalid value used as weak collection key");if(key!=key||key===0)for(i=list.length;i--&&!$rt_globals.is(list[i],key);){}else i=list.indexOf(key);return -1
<i;});var setHas=namedFunction("has",function(value){return has.call(this,this._values,value);});var mapHas=namedFunction("has",function(value){return has.call(this,this._keys,value);});var sharedSet=namedFunction("set",function(key,value){this.has(key)?(this._values[i]=value):(this._values[this._keys.push(key) -1]=value);return this;});var sharedAdd=namedFunction("add",function(value){if(!this.has(value))this._values.push(value);return this;});var sharedClear=namedFunction("clear",function(){(this._keys||0).length
=this._values.length=0;});var sharedKeys=namedFunction("keys",function(){return sharedIterator(this._itp,this._keys);});var sharedValues=namedFunction("values",function(){return sharedIterator(this._itp,this._values);});var mapEntries=namedFunction("entries",function(){return sharedIterator(this._itp,this._keys,this._values);});var setEntries=namedFunction("entries",function(){return sharedIterator(this._itp,this._values,this._values);});var sharedIterator=function(itp,array,array2){var p=[0],done=false;itp.push(p);return {
next:function(){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};}};};var sharedSize=namedFunction("size",function(){return this._values.length;});var sharedForEach=namedFunction("forEach",function(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);}});return {createCollection:createCollection,init:init,sharedDelete:sharedDelete,
sharedGet:sharedGet,has:has,setHas:setHas,mapHas:mapHas,sharedSet:sharedSet,sharedAdd:sharedAdd,sharedClear:sharedClear,sharedKeys:sharedKeys,sharedValues:sharedValues,mapEntries:mapEntries,setEntries:setEntries,sharedIterator:sharedIterator,sharedSize:sharedSize,sharedForEach:sharedForEach};}();var shim_Map=function(){if(typeof $rt_globals.Map==="undefined"||typeof (new $rt_globals.Map()).values!=="function"||!((new $rt_globals.Map()).values()).next){Object.defineProperty(_jsGlobal,"Map",{value:namedFunction("Map",
collectionsShimImpl.createCollection({'delete':collectionsShimImpl.sharedDelete,has:collectionsShimImpl.mapHas,get:collectionsShimImpl.sharedGet,set:collectionsShimImpl.sharedSet,keys:collectionsShimImpl.sharedKeys,values:collectionsShimImpl.sharedValues,entries:collectionsShimImpl.mapEntries,forEach:collectionsShimImpl.sharedForEach,clear:collectionsShimImpl.sharedClear}))});return true;}else {return false;}};var shim_WeakMap=function(){if(typeof $rt_globals.WeakMap==="undefined"){Object.defineProperty(_jsGlobal,
"WeakMap",{value:namedFunction("WeakMap",collectionsShimImpl.createCollection({'delete':collectionsShimImpl.sharedDelete,clear:collectionsShimImpl.sharedClear,get:collectionsShimImpl.sharedGet,has:collectionsShimImpl.mapHas,set:collectionsShimImpl.sharedSet}))});return true;}else {return false;}};var shim_Set=function(){if(typeof $rt_globals.Set==="undefined"||typeof (new $rt_globals.Set()).values!=="function"||!((new $rt_globals.Set()).values()).next){Object.defineProperty(_jsGlobal,"Set",{value:namedFunction("Set",
collectionsShimImpl.createCollection({has:collectionsShimImpl.setHas,add:collectionsShimImpl.sharedAdd,'delete':collectionsShimImpl.sharedDelete,clear:collectionsShimImpl.sharedClear,keys:collectionsShimImpl.sharedValues,values:collectionsShimImpl.sharedValues,entries:collectionsShimImpl.setEntries,forEach:collectionsShimImpl.sharedForEach}))});return true;}else {return false;}};var shim_WeakSet=function(){if(typeof $rt_globals.WeakSet==="undefined"){Object.defineProperty(_jsGlobal,"WeakSet",{value:namedFunction("WeakSet",
collectionsShimImpl.createCollection({'delete':collectionsShimImpl.sharedDelete,add:collectionsShimImpl.sharedAdd,clear:collectionsShimImpl.sharedClear,has:collectionsShimImpl.setHas}))});return true;}else {return false;}};var createPromiseShim=function(){var PROMISE_ID="[["+(($rt_globals.Math.random()).toString(36)).substring(2)+"]]";var PENDING=void 0;var FULFILLED=1;var REJECTED=2;var _qlen=0;var msgChannel=null;var useLegacyFlush=false;var isFlushTest=false;var queue=new $rt_globals.Array(1000);var _noop
=function(){};var _initMessageChannelFlush=function(flushFunc){if(typeof $rt_globals.MessageChannel==="undefined"){useLegacyFlush=true;$rt_globals.setTimeout(flushFunc,0);return;}isFlushTest=true;try {msgChannel=new $rt_globals.MessageChannel();var testVal=false;var _flushTest=function(){testVal=true;};msgChannel.port1.addEventListener("message",_flushTest);msgChannel.port1.start();msgChannel.port2.start();msgChannel.port2.postMessage("");if(testVal){msgChannel=null;useLegacyFlush=true;isFlushTest=false;$rt_globals.setTimeout(flushFunc,
0);return;}$rt_globals.setTimeout(function(){msgChannel.port1.removeEventListener("message",_flushTest);if(!testVal){msgChannel=null;useLegacyFlush=true;}else {msgChannel.port1.addEventListener("message",flushFunc);}isFlushTest=false;flushFunc();},10);}catch(ex){msgChannel=null;useLegacyFlush=true;isFlushTest=false;$rt_globals.setTimeout(flushFunc,0);return;}};var _scheduleFlush=function(){if(useLegacyFlush||isFlushTest){$rt_globals.setTimeout(_flush,0);}else {if(msgChannel===null){_initMessageChannelFlush(_flush);return;}msgChannel.port2.postMessage("");}};var _flush
=function(){for(var i=0;i<_qlen;i+=2){var callback=queue[i];var arg=queue[i+1];callback(arg);queue[i]=$rt_globals.undefined;queue[i+1]=$rt_globals.undefined;}_qlen=0;};var _asap=function(callback,arg){queue[_qlen]=callback;queue[_qlen+1]=arg;_qlen+=2;if(_qlen===2){_scheduleFlush();}};var _handleForeignThenable=function(promise,thenable,then$$1){_asap(function(promise){var sealed=false;var error=_tryThen(then$$1,thenable,function(value){if(sealed){return;}sealed=true;if(thenable!==value){__resolve(promise,value);}
else {_fulfill(promise,value);}},function(reason){if(sealed){return;}sealed=true;_reject(promise,reason);},"Settle: "+(promise._label||" unknown promise"));if(!sealed&&error){sealed=true;_reject(promise,error);}},promise);};var _tryThen=function(then$$1,value,fulfillmentHandler,rejectionHandler){try {then$$1.call(value,fulfillmentHandler,rejectionHandler);}catch(e){return e;}};var _handleOwnThenable=function(promise,thenable){if(thenable._state===FULFILLED){_fulfill(promise,thenable._result);}else if(thenable._state
===REJECTED){_reject(promise,thenable._result);}else {_subscribe(thenable,$rt_globals.undefined,function(value){return __resolve(promise,value);},function(reason){return _reject(promise,reason);});}};var _handleMaybeThenable=function(promise,maybeThenable,then$$1){if(maybeThenable.constructor===promise.constructor&&then$$1===_then&&maybeThenable.constructor.resolve===_resolve){_handleOwnThenable(promise,maybeThenable);}else {if(then$$1===$rt_globals.undefined){_fulfill(promise,maybeThenable);}else if(typeof then$$1
==="function"){_handleForeignThenable(promise,maybeThenable,then$$1);}else {_fulfill(promise,maybeThenable);}}};var __resolve=function(promise,value){if(promise===value){_reject(promise,new $rt_globals.TypeError("You cannot resolve a promise with itself"));}else if(typeof value==="object"||typeof value==="function"){var then$$1=void 0;try {then$$1=value.then;}catch(error){_reject(promise,error);return;}_handleMaybeThenable(promise,value,then$$1);}else {_fulfill(promise,value);}};var _reject=function(promise,
reason){if(promise._state!==PENDING){return;}promise._state=REJECTED;promise._result=reason;_asap(_publishRejection,promise);};var _subscribe=function(parent,child,onFulfillment,onRejection){var _subscribers=parent._subscribers;var length=_subscribers.length;parent._onerror=null;_subscribers[length]=child;_subscribers[length+FULFILLED]=onFulfillment;_subscribers[length+REJECTED]=onRejection;if(length===0&&parent._state){_asap(_publish,parent);}};var _publish=function(promise){var subscribers=promise._subscribers;var settled
=promise._state;if(subscribers.length===0){return;}var child=void 0,callback=void 0,detail=promise._result;for(var i=0;i<subscribers.length;i+=3){child=subscribers[i];callback=subscribers[i+settled];if(child){_invokeCallback(settled,child,callback,detail);}else {callback(detail);}}promise._subscribers.length=0;};var _publishRejection=function(promise){if(promise._onerror){promise._onerror(promise._result);}_publish(promise);};var _fulfill=function(promise,value){if(promise._state!==PENDING){return;}promise._result
=value;promise._state=FULFILLED;if(promise._subscribers.length!==0){_asap(_publish,promise);}};var _invokeCallback=function(settled,promise,callback,detail){var hasCallback=typeof callback==="function",value=void 0,error=void 0,succeeded=true;if(hasCallback){try {value=callback(detail);}catch(e){succeeded=false;error=e;}if(promise===value){_reject(promise,new $rt_globals.TypeError("A promises callback cannot return that same promise."));return;}}else {value=detail;}if(promise._state!==PENDING){}else if(hasCallback
&&succeeded){__resolve(promise,value);}else if(succeeded===false){_reject(promise,error);}else if(settled===FULFILLED){_fulfill(promise,value);}else if(settled===REJECTED){_reject(promise,value);}};var _initializePromise=function(promise,resolver){try {resolver(function(value){__resolve(promise,value);},function(reason){_reject(promise,reason);});}catch(e){_reject(promise,e);}};var id=0;var _nextId=function(){return id++;};var _makePromise=function(promise){promise[PROMISE_ID]=id++;promise._state=$rt_globals.undefined;promise._result
=$rt_globals.undefined;promise._subscribers=[];};var Promise;Promise=namedFunction("Promise",function(resolver){this[PROMISE_ID]=_nextId();this._result=this._state=$rt_globals.undefined;this._subscribers=[];if(_noop!==resolver){typeof resolver!=='function'&&$rt_globals._needsResolver();this instanceof Promise?_initializePromise(this,resolver):$rt_globals._needsNew();}});var _then=namedFunction("then",function(onFulfillment,onRejection){var parent=this;var child=new this.constructor(_noop);if(child[PROMISE_ID]
===$rt_globals.undefined){_makePromise(child);}var _state=parent._state;if(_state){var callback=arguments[_state -1];_asap(function(){return _invokeCallback(_state,child,callback,parent._result);});}else {_subscribe(parent,child,onFulfillment,onRejection);}return child;});Promise.prototype.then=_then;Promise.prototype.catch=namedFunction("catch",function(onRejection){return this.then(null,onRejection);});Promise.prototype.finally=namedFunction("finally",function(callback){var promise=this;var constructor=promise.constructor;if
(typeof callback==="function"){return promise.then(function(value){return (constructor.resolve(callback())).then(function(){return value;});},function(reason){return (constructor.resolve(callback())).then(function(){throw reason;});});}return promise.then(callback,callback);});Promise.all=namedFunction("all",function(entries){throw new $rt_globals.Error("Promise.all is not included in the ES6 compatibility shim!");});Promise.race=namedFunction("race",function(entries){var Constructor=this;if(!$rt_globals.Array.isArray(entries))
{return new Constructor(function(_,reject){return reject(new $rt_globals.TypeError("You must pass an array to race."));});}else {return new Constructor(function(resolve,reject){var length=entries.length;for(var i=0;i<length;i++){(Constructor.resolve(entries[i])).then(resolve,reject);}});}});var _resolve=namedFunction("resolve",function(object){var Constructor=this;if(object&&typeof object==="object"&&object.constructor===Constructor){return object;}var promise=new Constructor(_noop);__resolve(promise,object);return promise;});Promise.resolve
=_resolve;Promise.reject=namedFunction("reject",function(reason){var Constructor=this;var promise=new Constructor(_noop);_reject(promise,reason);return promise;});return Promise;};var shim_Promise=function(){if(typeof Promise==="undefined"){Object.defineProperty(_jsGlobal,"Promise",{value:createPromiseShim()});return true;}else {return false;}};var shim_String_fromCodePoint=function(){if(typeof $rt_globals.String.fromCodePoint==="undefined"){Object.defineProperty($rt_globals.String,"fromCodePoint",{value:namedFunction("fromCodePoint",
function(codePoints){var result=[];var next;for(var i=0,length=arguments.length;i<length;i++){next=$rt_globals.Number(arguments[i]);if(next!==(next|0)||next<0||next>0x10FFFF){throw new $rt_globals.RangeError("Invalid code point "+next);}if(next<0x10000){result.push($rt_globals.String.fromCharCode(next));}else {next -=0x10000;result.push($rt_globals.String.fromCharCode((next>>10)+0xD800));result.push($rt_globals.String.fromCharCode(next%0x400+0xDC00));}}return result.join("");})});return true;}else {return false;}};var shim_String_proto_codePointAt
=function(){if(typeof $rt_globals.String.prototype.codePointAt==="undefined"){Object.defineProperty($rt_globals.String.prototype,"codePointAt",{value:namedFunction("codePointAt",function(pos){pos=pos|0;var leng=this.length;if(pos>=0&&pos<leng){var first=this.charCodeAt(pos);var isEnd=pos+1===leng;if(first<0xD800||first>0xDBFF||isEnd){return first;}var second=this.charCodeAt(pos+1);if(second<0xDC00||second>0xDFFF){return first;}return (first -0xD800)*1024+second -0xDC00+0x10000;}})});return true;}else {return false;}};var shim_String_proto_startsWith
=function(){if(typeof $rt_globals.String.prototype.startsWith==="undefined"){Object.defineProperty($rt_globals.String.prototype,"startsWith",{value:namedFunction("startsWith",function(str){var position=0;if(arguments.length>1){position=arguments[1];}var start=$rt_globals.Math.max(position,0)|0;return this.slice(start,start+str.length)===str;})});return true;}else {return false;}};var shim_String_proto_endsWith=function(){if(typeof $rt_globals.String.prototype.endsWith==="undefined"){Object.defineProperty($rt_globals.String.prototype,
"endsWith",{value:namedFunction("endsWith",function(str){var len=this.length;var endPosition;if(arguments.length>1){endPosition=arguments[1];}var pos=typeof endPosition==="undefined"?len:endPosition|0;var end=$rt_globals.Math.min($rt_globals.Math.max(pos,0)|0,len);return this.slice(end -str.length,end)===str;})});return true;}else {return false;}};var shim_String_proto_includes=function(){if(typeof $rt_globals.String.prototype.includes==="undefined"){Object.defineProperty($rt_globals.String.prototype,"includes",
{value:namedFunction("includes",function(str){var position;if(arguments.length>1){position=arguments[1];}return this.indexOf(str,position)!== -1;})});return true;}else {return false;}};var stringRepeatHelper;stringRepeatHelper=function(s,times){if(times<1){return '';}if(times%2){return stringRepeatHelper(s,times -1)+s;}var half=stringRepeatHelper(s,times/2);return half+half;};var shim_String_proto_repeat=function(){if(typeof $rt_globals.String.prototype.repeat==="undefined"){Object.defineProperty($rt_globals.String.prototype,
"repeat",{value:namedFunction("repeat",function(numTimes){if(numTimes>=$rt_globals.Infinity||(numTimes|=0)<0){throw new $rt_globals.RangeError("repeat count must be less than infinity and not overflow maximum string size");}return stringRepeatHelper(this,numTimes);})});return true;}else {return false;}};var shim_Object_is=function(){if(typeof Object.is==="undefined"){Object.defineProperty(Object,"is",{value:namedFunction("is",function(a,b){return a===b||a!==a&&b!==b;})});return true;}else {return false;}};var shim_Object_setPrototypeOf
=function(){if(typeof Object.setPrototypeOf==="undefined"){var theShim=function(Object,magic){var set;var checkArgs=function(O,proto){if(typeof O!=="object"||O===null){throw new $rt_globals.TypeError("can not set prototype on a non-object");}if(typeof proto!=="object"&&proto!==null){throw new $rt_globals.TypeError("can only set prototype to an object or null");}};var setPrototypeOf=function(O,proto){checkArgs(O,proto);set.call(O,proto);return O;};try {set=(Object.getOwnPropertyDescriptor(Object.prototype,magic)).set;set.call({
},null);}catch(o_O){if(Object.prototype!=={}[magic]||{__proto__:null}.__proto__===void 0){$rt_globals.console.error("ES6Shims: Can not shim Object.setPrototypeOf on this browser! Ignoring for now");return false;}set=function(proto){this[magic]=proto;};}return setPrototypeOf;}(Object,"__proto__");if(theShim){Object.defineProperty(Object,"setPrototypeOf",{value:namedFunction("setPrototypeOf",theShim)});return true;}else {return false;}}else {return false;}};var shim_Function_proto_name=function(){if($rt_globals.Math.max.name
!=="max"){Object.defineProperty($rt_globals.Function.prototype,"name",{configurable:true,enumerable:false,get:function(){if(this===$rt_globals.Function.prototype){return "";}var str=$rt_globals.Function.prototype.toString.call(this);var match=str.match(/\s*function\s+([^(\s]*)\s*/);var name=match&&match[1];Object.defineProperty(this,"name",{configurable:true,enumerable:false,writable:false,value:name});return name;}});return true;}else {return false;}};var shim_Math_sign=function(){if(typeof $rt_globals.Math.sign
==="undefined"){Object.defineProperty($rt_globals.Math,"sign",{value:namedFunction("sign",function(val){var number=$rt_globals.Number(val);if(number===0){return number;}if($rt_globals.isNaN(number)){return number;}return number<0? -1:1;})});return true;}else {return false;}};var shim_Symbol=function(){if(typeof $rt_globals.Symbol==="undefined"){Object.defineProperty(_jsGlobal,"Symbol",{value:function(){var symRet=namedFunction("Symbol",function(){return "[[ShimbolR_"+(($rt_globals.Math.random()).toString(36)).substring(2)
+"]]";});symRet.for=namedFunction("for",function(symName){if(!(typeof symName==="string"))return $rt_globals.undefined;return "[[ShimbolN_"+symName+"]]";});symRet.keyFor=namedFunction("keyFor",function(sym){return typeof sym==="string"&&sym.startsWith("[[ShimbolN_")&&sym.endsWith("]]")?sym.substring(11,sym.length -2):$rt_globals.undefined;});return symRet;}()});return true;}else {return false;}};var hasErrors=false;var shim_install=function(str,cb){try {return cb();}catch(_exx_){hasErrors=true;$rt_globals.console.error("ES6Shims: Failed to detect and enable shim \""
+str+"\" for this browser! (Continuing anyway)");$rt_globals.console.error(_exx_);return false;}};if(shim_install("Map",shim_Map))enabledShims.push(0);if(shim_install("WeakMap",shim_WeakMap))enabledShims.push(1);if(shim_install("Set",shim_Set))enabledShims.push(2);if(shim_install("WeakSet",shim_WeakSet))enabledShims.push(3);if(shim_install("Promise",shim_Promise))enabledShims.push(4);if(shim_install("String_fromCodePoint",shim_String_fromCodePoint))enabledShims.push(5);if(shim_install("String_proto_codePointAt",
shim_String_proto_codePointAt))enabledShims.push(6);if(shim_install("String_proto_startsWith",shim_String_proto_startsWith))enabledShims.push(7);if(shim_install("String_proto_endsWith",shim_String_proto_endsWith))enabledShims.push(8);if(shim_install("String_proto_includes",shim_String_proto_includes))enabledShims.push(9);if(shim_install("String_proto_repeat",shim_String_proto_repeat))enabledShims.push(10);if(shim_install("Object_is",shim_Object_is))enabledShims.push(12);if(shim_install("Object_setPrototypeOf",
shim_Object_setPrototypeOf))enabledShims.push(13);if(shim_install("Function_proto_name",shim_Function_proto_name))enabledShims.push(14);if(shim_install("Math_sign",shim_Math_sign))enabledShims.push(15);if(shim_install("Symbol",shim_Symbol))enabledShims.push(16);var enCnt=enabledShims.length;_jsGlobal.__eaglercraftXES6ShimStatus={getShimInitStatus:function(){return (enCnt>0?1:0)|(hasErrors?2:0);},getEnabledShimCount:function(){return enCnt;},getEnabledShimID:function(idxIn){return enabledShims[idxIn];}};})();}
catch(_ex_){$rt_globals.console.error("ES6Shims: Failed to detect and enable shims for this browser! (Continuing anyway)");$rt_globals.console.error(_ex_);_jsGlobal.__eaglercraftXES6ShimStatus={getShimInitStatus:function(){return -1;},getEnabledShimCount:function(){return 0;},getEnabledShimID:function(idxIn){return $rt_globals.undefined;}};}})($rt_globals);