From 77256a9d91efcbb5be06657cbbbde4e895ba02f0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 13 Mar 2018 23:25:35 +0900 Subject: [PATCH 1/5] prelude: Bug fix: specifying out of range index must panic Fixes #732 --- compiler/prelude/prelude.go | 16 ++++++++-------- tests/misc_test.go | 12 ++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/compiler/prelude/prelude.go b/compiler/prelude/prelude.go index 82fbbc934..2dbbb8880 100644 --- a/compiler/prelude/prelude.go +++ b/compiler/prelude/prelude.go @@ -99,19 +99,19 @@ var $ifaceMethodExpr = function(name) { }; var $subslice = function(slice, low, high, max) { + if (high === undefined) { + high = slice.$length; + } + if (max === undefined) { + max = slice.$capacity + } if (low < 0 || high < low || max < high || high > slice.$capacity || max > slice.$capacity) { $throwRuntimeError("slice bounds out of range"); } var s = new slice.constructor(slice.$array); s.$offset = slice.$offset + low; - s.$length = slice.$length - low; - s.$capacity = slice.$capacity - low; - if (high !== undefined) { - s.$length = high - low; - } - if (max !== undefined) { - s.$capacity = max - low; - } + s.$length = high - low; + s.$capacity = max - low; return s; }; diff --git a/tests/misc_test.go b/tests/misc_test.go index edbc890ce..648bbc3e1 100644 --- a/tests/misc_test.go +++ b/tests/misc_test.go @@ -623,3 +623,15 @@ func TestTypeConversion(t *testing.T) { t.Fail() } } + +func TestSliceOutOfRange(t *testing.T) { + defer func() { + if err := recover(); err == nil || !strings.Contains(err.(error).Error(), "slice bounds out of range") { + t.Fail() + } + }() + + a := make([]byte, 4096) + b := a[8192:] + _ = b +} From b227c39f6380dc64f875c8218229a29c49eca39d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 14 Mar 2018 11:40:09 +0900 Subject: [PATCH 2/5] Update minified prelude --- compiler/prelude/prelude.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/prelude/prelude.go b/compiler/prelude/prelude.go index 2dbbb8880..29315bd7a 100644 --- a/compiler/prelude/prelude.go +++ b/compiler/prelude/prelude.go @@ -4,7 +4,7 @@ const Prelude = prelude + numeric + types + goroutines + jsmapping // Minified is Prelude ran through UglifyJS 3 via https://skalman.github.io/UglifyJS-online/ // with default options. -const Minified = `var $global,$module;if(Error.stackTraceLimit=1/0,"undefined"!=typeof window?$global=window:"undefined"!=typeof self?$global=self:"undefined"!=typeof global?($global=global).require=require:$global=this,void 0===$global||void 0===$global.Array)throw new Error("no global object found");"undefined"!=typeof module&&($module=module);var $throwRuntimeError,$packages={},$idCounter=0,$keys=function(e){return e?Object.keys(e):[]},$flushConsole=function(){},$throwNilPointerError=function(){$throwRuntimeError("invalid memory address or nil pointer dereference")},$call=function(e,n,r){return e.apply(n,r)},$makeFunc=function(e){return function(){return $externalize(e(this,new($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments,[]))),$emptyInterface)}},$unused=function(e){},$mapArray=function(e,n){for(var r=new e.constructor(e.length),t=0;te.$capacity||t>e.$capacity)&&$throwRuntimeError("slice bounds out of range");var i=new e.constructor(e.$array);return i.$offset=e.$offset+n,i.$length=e.$length-n,i.$capacity=e.$capacity-n,void 0!==r&&(i.$length=r-n),void 0!==t&&(i.$capacity=t-n),i},$substring=function(e,n,r){return(n<0||re.length)&&$throwRuntimeError("slice bounds out of range"),e.substring(n,r)},$sliceToArray=function(e){return e.$array.constructor!==Array?e.$array.subarray(e.$offset,e.$offset+e.$length):e.$array.slice(e.$offset,e.$offset+e.$length)},$decodeRune=function(e,n){var r=e.charCodeAt(n);if(r<128)return[r,1];if(r!=r||r<192)return[65533,1];var t=e.charCodeAt(n+1);if(t!=t||t<128||192<=t)return[65533,1];if(r<224)return(a=(31&r)<<6|63&t)<=127?[65533,1]:[a,2];var i=e.charCodeAt(n+2);if(i!=i||i<128||192<=i)return[65533,1];if(r<240)return(a=(15&r)<<12|(63&t)<<6|63&i)<=2047?[65533,1]:55296<=a&&a<=57343?[65533,1]:[a,3];var a,o=e.charCodeAt(n+3);return o!=o||o<128||192<=o?[65533,1]:r<248?(a=(7&r)<<18|(63&t)<<12|(63&i)<<6|63&o)<=65535||11141111114111||55296<=e&&e<=57343)&&(e=65533),e<=127?String.fromCharCode(e):e<=2047?String.fromCharCode(192|e>>6,128|63&e):e<=65535?String.fromCharCode(224|e>>12,128|e>>6&63,128|63&e):String.fromCharCode(240|e>>18,128|e>>12&63,128|e>>6&63,128|63&e)},$stringToBytes=function(e){for(var n=new Uint8Array(e.length),r=0;rt){for(var o=i-1;o>=0;o--)a.copy(e[r+o],n[t+o]);return}for(o=0;ot)for(o=i-1;o>=0;o--)e[r+o]=n[t+o];else for(o=0;o$)if(a=0,$=Math.max(o,e.$capacity<1024?2*e.$capacity:Math.floor(5*e.$capacity/4)),e.$array.constructor===Array){(i=e.$array.slice(e.$offset,e.$offset+e.$length)).length=$;for(var c=e.constructor.elem.zero,u=e.$length;u<$;u++)i[u]=c()}else(i=new e.$array.constructor($)).set(e.$array.subarray(e.$offset,e.$offset+e.$length));$copyArray(i,n,a+e.$length,r,t,e.constructor.elem);var l=new e.constructor(i);return l.$offset=a,l.$length=o,l.$capacity=$,l},$equal=function(e,n,r){if(r===$jsObjectPtr)return e===n;switch(r.kind){case $kindComplex64:case $kindComplex128:return e.$real===n.$real&&e.$imag===n.$imag;case $kindInt64:case $kindUint64:return e.$high===n.$high&&e.$low===n.$low;case $kindArray:if(e.length!==n.length)return!1;for(var t=0;t>>16&65535)*t+r*(n>>>16&65535)<<16>>>0)>>0},$floatKey=function(e){return e!=e?"NaN$"+ ++$idCounter:String(e)},$flatten64=function(e){return 4294967296*e.$high+e.$low},$shiftLeft64=function(e,n){return 0===n?e:n<32?new e.constructor(e.$high<>>32-n,e.$low<>>0):n<64?new e.constructor(e.$low<>n,(e.$low>>>n|e.$high<<32-n)>>>0):n<64?new e.constructor(e.$high>>31,e.$high>>n-32>>>0):e.$high<0?new e.constructor(-1,4294967295):new e.constructor(0,0)},$shiftRightUint64=function(e,n){return 0===n?e:n<32?new e.constructor(e.$high>>>n,(e.$low>>>n|e.$high<<32-n)>>>0):n<64?new e.constructor(0,e.$high>>>n-32):new e.constructor(0,0)},$mul64=function(e,n){var r=0,t=0;0!=(1&n.$low)&&(r=e.$high,t=e.$low);for(var i=1;i<32;i++)0!=(n.$low&1<>>32-i,t+=e.$low<>>0);for(i=0;i<32;i++)0!=(n.$high&1<$||a===$&&o>c);)$=($<<1|c>>>31)>>>0,c=c<<1>>>0,s++;for(var f=0;f<=s;f++)u=u<<1|l>>>31,l=l<<1>>>0,(a>$||a===$&&o>=c)&&(a-=$,(o-=c)<0&&(a--,o+=4294967296),4294967296===++l&&(u++,l=0)),c=(c>>>1|$<<31)>>>0,$>>>=1;return r?new e.constructor(a*i,o*i):new e.constructor(u*t,l*t)},$divComplex=function(e,n){var r=e.$real===1/0||e.$real===-1/0||e.$imag===1/0||e.$imag===-1/0,t=n.$real===1/0||n.$real===-1/0||n.$imag===1/0||n.$imag===-1/0,i=!r&&(e.$real!=e.$real||e.$imag!=e.$imag),a=!t&&(n.$real!=n.$real||n.$imag!=n.$imag);if(i||a)return new e.constructor(NaN,NaN);if(r&&!t)return new e.constructor(1/0,1/0);if(!r&&t)return new e.constructor(0,0);if(0===n.$real&&0===n.$imag)return 0===e.$real&&0===e.$imag?new e.constructor(NaN,NaN):new e.constructor(1/0,1/0);if(Math.abs(n.$real)<=Math.abs(n.$imag)){var o=n.$real/n.$imag,$=n.$real*o+n.$imag;return new e.constructor((e.$real*o+e.$imag)/$,(e.$imag*o-e.$real)/$)}o=n.$imag/n.$real,$=n.$imag*o+n.$real;return new e.constructor((e.$imag*o+e.$real)/$,(e.$imag-e.$real*o)/$)},$kindBool=1,$kindInt=2,$kindInt8=3,$kindInt16=4,$kindInt32=5,$kindInt64=6,$kindUint=7,$kindUint8=8,$kindUint16=9,$kindUint32=10,$kindUint64=11,$kindUintptr=12,$kindFloat32=13,$kindFloat64=14,$kindComplex64=15,$kindComplex128=16,$kindArray=17,$kindChan=18,$kindFunc=19,$kindInterface=20,$kindMap=21,$kindPtr=22,$kindSlice=23,$kindString=24,$kindStruct=25,$kindUnsafePointer=26,$methodSynthesizers=[],$addMethodSynthesizer=function(e){null!==$methodSynthesizers?$methodSynthesizers.push(e):e()},$synthesizeMethods=function(){$methodSynthesizers.forEach(function(e){e()}),$methodSynthesizers=null},$ifaceKeyFor=function(e){if(e===$ifaceNil)return"nil";var n=e.constructor;return n.string+"$"+n.keyFor(e.$val)},$identity=function(e){return e},$typeIDCounter=0,$idKey=function(e){return void 0===e.$id&&($idCounter++,e.$id=$idCounter),String(e.$id)},$newType=function(e,n,r,t,i,a,o){var $;switch(n){case $kindBool:case $kindInt:case $kindInt8:case $kindInt16:case $kindInt32:case $kindUint:case $kindUint8:case $kindUint16:case $kindUint32:case $kindUintptr:case $kindUnsafePointer:($=function(e){this.$val=e}).wrapped=!0,$.keyFor=$identity;break;case $kindString:($=function(e){this.$val=e}).wrapped=!0,$.keyFor=function(e){return"$"+e};break;case $kindFloat32:case $kindFloat64:($=function(e){this.$val=e}).wrapped=!0,$.keyFor=function(e){return $floatKey(e)};break;case $kindInt64:($=function(e,n){this.$high=e+Math.floor(Math.ceil(n)/4294967296)>>0,this.$low=n>>>0,this.$val=this}).keyFor=function(e){return e.$high+"$"+e.$low};break;case $kindUint64:($=function(e,n){this.$high=e+Math.floor(Math.ceil(n)/4294967296)>>>0,this.$low=n>>>0,this.$val=this}).keyFor=function(e){return e.$high+"$"+e.$low};break;case $kindComplex64:($=function(e,n){this.$real=$fround(e),this.$imag=$fround(n),this.$val=this}).keyFor=function(e){return e.$real+"$"+e.$imag};break;case $kindComplex128:($=function(e,n){this.$real=e,this.$imag=n,this.$val=this}).keyFor=function(e){return e.$real+"$"+e.$imag};break;case $kindArray:($=function(e){this.$val=e}).wrapped=!0,$.ptr=$newType(4,$kindPtr,"*"+r,!1,"",!1,function(e){this.$get=function(){return e},this.$set=function(e){$.copy(this,e)},this.$val=e}),$.init=function(e,n){$.elem=e,$.len=n,$.comparable=e.comparable,$.keyFor=function(n){return Array.prototype.join.call($mapArray(n,function(n){return String(e.keyFor(n)).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}),"$")},$.copy=function(n,r){$copyArray(n,r,0,0,r.length,e)},$.ptr.init($),Object.defineProperty($.ptr.nil,"nilCheck",{get:$throwNilPointerError})};break;case $kindChan:($=function(e){this.$val=e}).wrapped=!0,$.keyFor=$idKey,$.init=function(e,n,r){$.elem=e,$.sendOnly=n,$.recvOnly=r};break;case $kindFunc:($=function(e){this.$val=e}).wrapped=!0,$.init=function(e,n,r){$.params=e,$.results=n,$.variadic=r,$.comparable=!1};break;case $kindInterface:($={implementedBy:{},missingMethodFor:{}}).keyFor=$ifaceKeyFor,$.init=function(e){$.methods=e,e.forEach(function(e){$ifaceNil[e.prop]=$throwNilPointerError})};break;case $kindMap:($=function(e){this.$val=e}).wrapped=!0,$.init=function(e,n){$.key=e,$.elem=n,$.comparable=!1};break;case $kindPtr:($=o||function(e,n,r){this.$get=e,this.$set=n,this.$target=r,this.$val=this}).keyFor=$idKey,$.init=function(e){$.elem=e,$.wrapped=e.kind===$kindArray,$.nil=new $($throwNilPointerError,$throwNilPointerError)};break;case $kindSlice:($=function(e){e.constructor!==$.nativeArray&&(e=new $.nativeArray(e)),this.$array=e,this.$offset=0,this.$length=e.length,this.$capacity=e.length,this.$val=this}).init=function(e){$.elem=e,$.comparable=!1,$.nativeArray=$nativeArray(e.kind),$.nil=new $([])};break;case $kindStruct:($=function(e){this.$val=e}).wrapped=!0,$.ptr=$newType(4,$kindPtr,"*"+r,!1,i,a,o),$.ptr.elem=$,$.ptr.prototype.$get=function(){return this},$.ptr.prototype.$set=function(e){$.copy(this,e)},$.init=function(e,n){$.pkgPath=e,$.fields=n,n.forEach(function(e){e.typ.comparable||($.comparable=!1)}),$.keyFor=function(e){var r=e.$val;return $mapArray(n,function(e){return String(e.typ.keyFor(r[e.prop])).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}).join("$")},$.copy=function(e,r){for(var t=0;t0;){var a=[],o=[];t.forEach(function(e){if(!i[e.typ.string])switch(i[e.typ.string]=!0,e.typ.named&&(o=o.concat(e.typ.methods),e.indirect&&(o=o.concat($ptrType(e.typ).methods))),e.typ.kind){case $kindStruct:e.typ.fields.forEach(function(n){if(n.anonymous){var r=n.typ,t=r.kind===$kindPtr;a.push({typ:t?r.elem:r,indirect:e.indirect||t})}});break;case $kindInterface:o=o.concat(e.typ.methods)}}),o.forEach(function(e){void 0===n[e.name]&&(n[e.name]=e)}),t=a}return e.methodSetCache=[],Object.keys(n).sort().forEach(function(r){e.methodSetCache.push(n[r])}),e.methodSetCache},$Bool=$newType(1,$kindBool,"bool",!0,"",!1,null),$Int=$newType(4,$kindInt,"int",!0,"",!1,null),$Int8=$newType(1,$kindInt8,"int8",!0,"",!1,null),$Int16=$newType(2,$kindInt16,"int16",!0,"",!1,null),$Int32=$newType(4,$kindInt32,"int32",!0,"",!1,null),$Int64=$newType(8,$kindInt64,"int64",!0,"",!1,null),$Uint=$newType(4,$kindUint,"uint",!0,"",!1,null),$Uint8=$newType(1,$kindUint8,"uint8",!0,"",!1,null),$Uint16=$newType(2,$kindUint16,"uint16",!0,"",!1,null),$Uint32=$newType(4,$kindUint32,"uint32",!0,"",!1,null),$Uint64=$newType(8,$kindUint64,"uint64",!0,"",!1,null),$Uintptr=$newType(4,$kindUintptr,"uintptr",!0,"",!1,null),$Float32=$newType(4,$kindFloat32,"float32",!0,"",!1,null),$Float64=$newType(8,$kindFloat64,"float64",!0,"",!1,null),$Complex64=$newType(8,$kindComplex64,"complex64",!0,"",!1,null),$Complex128=$newType(16,$kindComplex128,"complex128",!0,"",!1,null),$String=$newType(8,$kindString,"string",!0,"",!1,null),$UnsafePointer=$newType(4,$kindUnsafePointer,"unsafe.Pointer",!0,"",!1,null),$nativeArray=function(e){switch(e){case $kindInt:return Int32Array;case $kindInt8:return Int8Array;case $kindInt16:return Int16Array;case $kindInt32:return Int32Array;case $kindUint:return Uint32Array;case $kindUint8:return Uint8Array;case $kindUint16:return Uint16Array;case $kindUint32:case $kindUintptr:return Uint32Array;case $kindFloat32:return Float32Array;case $kindFloat64:return Float64Array;default:return Array}},$toNativeArray=function(e,n){var r=$nativeArray(e);return r===Array?n:new r(n)},$arrayTypes={},$arrayType=function(e,n){var r=e.id+"$"+n,t=$arrayTypes[r];return void 0===t&&(t=$newType(12,$kindArray,"["+n+"]"+e.string,!1,"",!1,null),$arrayTypes[r]=t,t.init(e,n)),t},$chanType=function(e,n,r){var t=(r?"<-":"")+"chan"+(n?"<- ":" ")+e.string,i=n?"SendChan":r?"RecvChan":"Chan",a=e[i];return void 0===a&&(a=$newType(4,$kindChan,t,!1,"",!1,null),e[i]=a,a.init(e,n,r)),a},$Chan=function(e,n){(n<0||n>2147483647)&&$throwRuntimeError("makechan: size out of range"),this.$elem=e,this.$capacity=n,this.$buffer=[],this.$sendQueue=[],this.$recvQueue=[],this.$closed=!1},$chanNil=new $Chan(null,0);$chanNil.$sendQueue=$chanNil.$recvQueue={length:0,push:function(){},shift:function(){},indexOf:function(){return-1}};var $funcTypes={},$funcType=function(e,n,r){var t=$mapArray(e,function(e){return e.id}).join(",")+"$"+$mapArray(n,function(e){return e.id}).join(",")+"$"+r,i=$funcTypes[t];if(void 0===i){var a=$mapArray(e,function(e){return e.string});r&&(a[a.length-1]="..."+a[a.length-1].substr(2));var o="func("+a.join(", ")+")";1===n.length?o+=" "+n[0].string:n.length>1&&(o+=" ("+$mapArray(n,function(e){return e.string}).join(", ")+")"),i=$newType(4,$kindFunc,o,!1,"",!1,null),$funcTypes[t]=i,i.init(e,n,r)}return i},$interfaceTypes={},$interfaceType=function(e){var n=$mapArray(e,function(e){return e.pkg+","+e.name+","+e.typ.id}).join("$"),r=$interfaceTypes[n];if(void 0===r){var t="interface {}";0!==e.length&&(t="interface { "+$mapArray(e,function(e){return(""!==e.pkg?e.pkg+".":"")+e.name+e.typ.string.substr(4)}).join("; ")+" }"),r=$newType(8,$kindInterface,t,!1,"",!1,null),$interfaceTypes[n]=r,r.init(e)}return r},$emptyInterface=$interfaceType([]),$ifaceNil={},$error=$newType(8,$kindInterface,"error",!0,"",!1,null);$error.init([{prop:"Error",name:"Error",pkg:"",typ:$funcType([],[$String],!1)}]);var $panicValue,$jsObjectPtr,$jsErrorPtr,$mapTypes={},$mapType=function(e,n){var r=e.id+"$"+n.id,t=$mapTypes[r];return void 0===t&&(t=$newType(4,$kindMap,"map["+e.string+"]"+n.string,!1,"",!1,null),$mapTypes[r]=t,t.init(e,n)),t},$makeMap=function(e,n){for(var r={},t=0;t2147483647)&&$throwRuntimeError("makeslice: len out of range"),(r<0||r2147483647)&&$throwRuntimeError("makeslice: cap out of range");var t=new e.nativeArray(r);if(e.nativeArray===Array)for(var i=0;i=$curGoroutine.deferStack.length)throw n;if(null!==n){var t=null;try{$curGoroutine.deferStack.push(e),$panic(new $jsErrorPtr(n))}catch(e){t=e}return $curGoroutine.deferStack.pop(),void $callDeferred(e,t)}if(!$curGoroutine.asleep){$stackDepthOffset--;var i=$panicStackDepth,a=$panicValue,o=$curGoroutine.panicStack.pop();void 0!==o&&($panicStackDepth=$getStackDepth(),$panicValue=o);try{for(;;){if(null===e&&void 0===(e=$curGoroutine.deferStack[$curGoroutine.deferStack.length-1])){if($panicStackDepth=null,o.Object instanceof Error)throw o.Object;var $;throw $=o.constructor===$String?o.$val:void 0!==o.Error?o.Error():void 0!==o.String?o.String():o,new Error($)}var c=e.pop();if(void 0===c){if($curGoroutine.deferStack.pop(),void 0!==o){e=null;continue}return}var u=c[0].apply(c[2],c[1]);if(u&&void 0!==u.$blk){if(e.push([u.$blk,[],u]),r)throw null;return}if(void 0!==o&&null===$panicStackDepth)throw null}}finally{void 0!==o&&(null!==$panicStackDepth&&$curGoroutine.panicStack.push(o),$panicStackDepth=i,$panicValue=a),$stackDepthOffset++}}},$panic=function(e){$curGoroutine.panicStack.push(e),$callDeferred(null,null,!0)},$recover=function(){return null===$panicStackDepth||void 0!==$panicStackDepth&&$panicStackDepth!==$getStackDepth()-2?$ifaceNil:($panicStackDepth=null,$panicValue)},$throw=function(e){throw e},$noGoroutine={asleep:!1,exit:!1,deferStack:[],panicStack:[]},$curGoroutine=$noGoroutine,$totalGoroutines=0,$awakeGoroutines=0,$checkForDeadlock=!0,$mainFinished=!1,$go=function(e,n){$totalGoroutines++,$awakeGoroutines++;var r=function(){try{$curGoroutine=r;var t=e.apply(void 0,n);if(t&&void 0!==t.$blk)return e=function(){return t.$blk()},void(n=[]);r.exit=!0}catch(e){if(!r.exit)throw e}finally{$curGoroutine=$noGoroutine,r.exit&&($totalGoroutines--,r.asleep=!0),r.asleep&&($awakeGoroutines--,!$mainFinished&&0===$awakeGoroutines&&$checkForDeadlock&&(console.error("fatal error: all goroutines are asleep - deadlock!"),void 0!==$global.process&&$global.process.exit(2)))}};r.asleep=!1,r.exit=!1,r.deferStack=[],r.panicStack=[],$schedule(r)},$scheduled=[],$runScheduled=function(){try{for(var e;void 0!==(e=$scheduled.shift());)e()}finally{$scheduled.length>0&&setTimeout($runScheduled,0)}},$schedule=function(e){e.asleep&&(e.asleep=!1,$awakeGoroutines++),$scheduled.push(e),$curGoroutine===$noGoroutine&&$runScheduled()},$setTimeout=function(e,n){return $awakeGoroutines++,setTimeout(function(){$awakeGoroutines--,e()},n)},$block=function(){$curGoroutine===$noGoroutine&&$throwRuntimeError("cannot block in JavaScript callback, fix by wrapping code in goroutine"),$curGoroutine.asleep=!0},$send=function(e,n){e.$closed&&$throwRuntimeError("send on closed channel");var r=e.$recvQueue.shift();if(void 0===r){if(!(e.$buffer.length65535){var u=Math.floor((c-65536)/1024)+55296,l=(c-65536)%1024+56320;$+=String.fromCharCode(u,l)}else $+=String.fromCharCode(c)}return $;case $kindStruct:var s=$packages.time;if(void 0!==s&&e.constructor===s.Time.ptr){var f=$div64(e.UnixNano(),new $Int64(0,1e6));return new Date($flatten64(f))}var d={},p=function(e,n){if(n===$jsObjectPtr)return e;switch(n.kind){case $kindPtr:return e===n.nil?d:p(e.$get(),n.elem);case $kindStruct:var r=n.fields[0];return p(e[r.prop],r.typ);case $kindInterface:return p(e.$val,e.constructor);default:return d}},h=p(e,n);if(h!==d)return h;h={};for(i=0;i>24;case $kindInt16:return parseInt(e)<<16>>16;case $kindInt32:return parseInt(e)>>0;case $kindUint:return parseInt(e);case $kindUint8:return parseInt(e)<<24>>>24;case $kindUint16:return parseInt(e)<<16>>>16;case $kindUint32:case $kindUintptr:return parseInt(e)>>>0;case $kindInt64:case $kindUint64:return new n(0,e);case $kindFloat32:case $kindFloat64:return parseFloat(e);case $kindArray:return e.length!==n.len&&$throwRuntimeError("got array with wrong size from JavaScript native"),$mapArray(e,function(e){return $internalize(e,n.elem)});case $kindFunc:return function(){for(var t=[],i=0;i=128)return!1;return!0};` +const Minified = `var $global,$module;if(Error.stackTraceLimit=1/0,"undefined"!=typeof window?$global=window:"undefined"!=typeof self?$global=self:"undefined"!=typeof global?($global=global).require=require:$global=this,void 0===$global||void 0===$global.Array)throw new Error("no global object found");"undefined"!=typeof module&&($module=module);var $throwRuntimeError,$packages={},$idCounter=0,$keys=function(r){return r?Object.keys(r):[]},$flushConsole=function(){},$throwNilPointerError=function(){$throwRuntimeError("invalid memory address or nil pointer dereference")},$call=function(r,e,t){return r.apply(e,t)},$makeFunc=function(r){return function(){return $externalize(r(this,new($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments,[]))),$emptyInterface)}},$unused=function(r){},$mapArray=function(r,e){for(var t=new r.constructor(r.length),n=0;nr.$capacity||n>r.$capacity)&&$throwRuntimeError("slice bounds out of range");var o=new r.constructor(r.$array);return o.$offset=r.$offset+e,o.$length=t-e,o.$capacity=n-e,o},$substring=function(r,e,t){return(e<0||tr.length)&&$throwRuntimeError("slice bounds out of range"),r.substring(e,t)},$sliceToArray=function(r){return r.$array.constructor!==Array?r.$array.subarray(r.$offset,r.$offset+r.$length):r.$array.slice(r.$offset,r.$offset+r.$length)},$decodeRune=function(r,e){var t=r.charCodeAt(e);if(t<128)return[t,1];if(t!=t||t<192)return[65533,1];var n=r.charCodeAt(e+1);if(n!=n||n<128||192<=n)return[65533,1];if(t<224)return(a=(31&t)<<6|63&n)<=127?[65533,1]:[a,2];var o=r.charCodeAt(e+2);if(o!=o||o<128||192<=o)return[65533,1];if(t<240)return(a=(15&t)<<12|(63&n)<<6|63&o)<=2047?[65533,1]:55296<=a&&a<=57343?[65533,1]:[a,3];var a,i=r.charCodeAt(e+3);return i!=i||i<128||192<=i?[65533,1]:t<248?(a=(7&t)<<18|(63&n)<<12|(63&o)<<6|63&i)<=65535||11141111114111||55296<=r&&r<=57343)&&(r=65533),r<=127?String.fromCharCode(r):r<=2047?String.fromCharCode(192|r>>6,128|63&r):r<=65535?String.fromCharCode(224|r>>12,128|r>>6&63,128|63&r):String.fromCharCode(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r)},$stringToBytes=function(r){for(var e=new Uint8Array(r.length),t=0;tn){for(var i=o-1;i>=0;i--)a.copy(r[t+i],e[n+i]);return}for(i=0;in)for(i=o-1;i>=0;i--)r[t+i]=e[n+i];else for(i=0;i$)if(a=0,$=Math.max(i,r.$capacity<1024?2*r.$capacity:Math.floor(5*r.$capacity/4)),r.$array.constructor===Array){(o=r.$array.slice(r.$offset,r.$offset+r.$length)).length=$;for(var c=r.constructor.elem.zero,f=r.$length;f<$;f++)o[f]=c()}else(o=new r.$array.constructor($)).set(r.$array.subarray(r.$offset,r.$offset+r.$length));$copyArray(o,e,a+r.$length,t,n,r.constructor.elem);var u=new r.constructor(o);return u.$offset=a,u.$length=i,u.$capacity=$,u},$equal=function(r,e,t){if(t===$jsObjectPtr)return r===e;switch(t.kind){case $kindComplex64:case $kindComplex128:return r.$real===e.$real&&r.$imag===e.$imag;case $kindInt64:case $kindUint64:return r.$high===e.$high&&r.$low===e.$low;case $kindArray:if(r.length!==e.length)return!1;for(var n=0;n Date: Wed, 14 Mar 2018 11:49:57 +0900 Subject: [PATCH 3/5] Retry minifying prelude --- compiler/prelude/prelude.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/prelude/prelude.go b/compiler/prelude/prelude.go index 29315bd7a..e52cef4e6 100644 --- a/compiler/prelude/prelude.go +++ b/compiler/prelude/prelude.go @@ -4,7 +4,7 @@ const Prelude = prelude + numeric + types + goroutines + jsmapping // Minified is Prelude ran through UglifyJS 3 via https://skalman.github.io/UglifyJS-online/ // with default options. -const Minified = `var $global,$module;if(Error.stackTraceLimit=1/0,"undefined"!=typeof window?$global=window:"undefined"!=typeof self?$global=self:"undefined"!=typeof global?($global=global).require=require:$global=this,void 0===$global||void 0===$global.Array)throw new Error("no global object found");"undefined"!=typeof module&&($module=module);var $throwRuntimeError,$packages={},$idCounter=0,$keys=function(r){return r?Object.keys(r):[]},$flushConsole=function(){},$throwNilPointerError=function(){$throwRuntimeError("invalid memory address or nil pointer dereference")},$call=function(r,e,t){return r.apply(e,t)},$makeFunc=function(r){return function(){return $externalize(r(this,new($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments,[]))),$emptyInterface)}},$unused=function(r){},$mapArray=function(r,e){for(var t=new r.constructor(r.length),n=0;nr.$capacity||n>r.$capacity)&&$throwRuntimeError("slice bounds out of range");var o=new r.constructor(r.$array);return o.$offset=r.$offset+e,o.$length=t-e,o.$capacity=n-e,o},$substring=function(r,e,t){return(e<0||tr.length)&&$throwRuntimeError("slice bounds out of range"),r.substring(e,t)},$sliceToArray=function(r){return r.$array.constructor!==Array?r.$array.subarray(r.$offset,r.$offset+r.$length):r.$array.slice(r.$offset,r.$offset+r.$length)},$decodeRune=function(r,e){var t=r.charCodeAt(e);if(t<128)return[t,1];if(t!=t||t<192)return[65533,1];var n=r.charCodeAt(e+1);if(n!=n||n<128||192<=n)return[65533,1];if(t<224)return(a=(31&t)<<6|63&n)<=127?[65533,1]:[a,2];var o=r.charCodeAt(e+2);if(o!=o||o<128||192<=o)return[65533,1];if(t<240)return(a=(15&t)<<12|(63&n)<<6|63&o)<=2047?[65533,1]:55296<=a&&a<=57343?[65533,1]:[a,3];var a,i=r.charCodeAt(e+3);return i!=i||i<128||192<=i?[65533,1]:t<248?(a=(7&t)<<18|(63&n)<<12|(63&o)<<6|63&i)<=65535||11141111114111||55296<=r&&r<=57343)&&(r=65533),r<=127?String.fromCharCode(r):r<=2047?String.fromCharCode(192|r>>6,128|63&r):r<=65535?String.fromCharCode(224|r>>12,128|r>>6&63,128|63&r):String.fromCharCode(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r)},$stringToBytes=function(r){for(var e=new Uint8Array(r.length),t=0;tn){for(var i=o-1;i>=0;i--)a.copy(r[t+i],e[n+i]);return}for(i=0;in)for(i=o-1;i>=0;i--)r[t+i]=e[n+i];else for(i=0;i$)if(a=0,$=Math.max(i,r.$capacity<1024?2*r.$capacity:Math.floor(5*r.$capacity/4)),r.$array.constructor===Array){(o=r.$array.slice(r.$offset,r.$offset+r.$length)).length=$;for(var c=r.constructor.elem.zero,f=r.$length;f<$;f++)o[f]=c()}else(o=new r.$array.constructor($)).set(r.$array.subarray(r.$offset,r.$offset+r.$length));$copyArray(o,e,a+r.$length,t,n,r.constructor.elem);var u=new r.constructor(o);return u.$offset=a,u.$length=i,u.$capacity=$,u},$equal=function(r,e,t){if(t===$jsObjectPtr)return r===e;switch(t.kind){case $kindComplex64:case $kindComplex128:return r.$real===e.$real&&r.$imag===e.$imag;case $kindInt64:case $kindUint64:return r.$high===e.$high&&r.$low===e.$low;case $kindArray:if(r.length!==e.length)return!1;for(var n=0;nslice.$capacity||max>slice.$capacity){$throwRuntimeError("slice bounds out of range")}var s=new slice.constructor(slice.$array);s.$offset=slice.$offset+low;s.$length=high-low;s.$capacity=max-low;return s};var $substring=function(str,low,high){if(low<0||highstr.length){$throwRuntimeError("slice bounds out of range")}return str.substring(low,high)};var $sliceToArray=function(slice){if(slice.$array.constructor!==Array){return slice.$array.subarray(slice.$offset,slice.$offset+slice.$length)}return slice.$array.slice(slice.$offset,slice.$offset+slice.$length)};var $decodeRune=function(str,pos){var c0=str.charCodeAt(pos);if(c0<128){return[c0,1]}if(c0!==c0||c0<192){return[65533,1]}var c1=str.charCodeAt(pos+1);if(c1!==c1||c1<128||192<=c1){return[65533,1]}if(c0<224){var r=(c0&31)<<6|c1&63;if(r<=127){return[65533,1]}return[r,2]}var c2=str.charCodeAt(pos+2);if(c2!==c2||c2<128||192<=c2){return[65533,1]}if(c0<240){var r=(c0&15)<<12|(c1&63)<<6|c2&63;if(r<=2047){return[65533,1]}if(55296<=r&&r<=57343){return[65533,1]}return[r,3]}var c3=str.charCodeAt(pos+3);if(c3!==c3||c3<128||192<=c3){return[65533,1]}if(c0<248){var r=(c0&7)<<18|(c1&63)<<12|(c2&63)<<6|c3&63;if(r<=65535||11141111114111||55296<=r&&r<=57343){r=65533}if(r<=127){return String.fromCharCode(r)}if(r<=2047){return String.fromCharCode(192|r>>6,128|r&63)}if(r<=65535){return String.fromCharCode(224|r>>12,128|r>>6&63,128|r&63)}return String.fromCharCode(240|r>>18,128|r>>12&63,128|r>>6&63,128|r&63)};var $stringToBytes=function(str){var array=new Uint8Array(str.length);for(var i=0;isrcOffset){for(var i=n-1;i>=0;i--){elem.copy(dst[dstOffset+i],src[srcOffset+i])}return}for(var i=0;isrcOffset){for(var i=n-1;i>=0;i--){dst[dstOffset+i]=src[srcOffset+i]}return}for(var i=0;inewCapacity){newOffset=0;newCapacity=Math.max(newLength,slice.$capacity<1024?slice.$capacity*2:Math.floor(slice.$capacity*5/4));if(slice.$array.constructor===Array){newArray=slice.$array.slice(slice.$offset,slice.$offset+slice.$length);newArray.length=newCapacity;var zero=slice.constructor.elem.zero;for(var i=slice.$length;i>>16&65535;var al=a&65535;var bh=b>>>16&65535;var bl=b&65535;return al*bl+(ah*bl+al*bh<<16>>>0)>>0};var $floatKey=function(f){if(f!==f){$idCounter++;return"NaN$"+$idCounter}return String(f)};var $flatten64=function(x){return x.$high*4294967296+x.$low};var $shiftLeft64=function(x,y){if(y===0){return x}if(y<32){return new x.constructor(x.$high<>>32-y,x.$low<>>0)}if(y<64){return new x.constructor(x.$low<>y,(x.$low>>>y|x.$high<<32-y)>>>0)}if(y<64){return new x.constructor(x.$high>>31,x.$high>>y-32>>>0)}if(x.$high<0){return new x.constructor(-1,4294967295)}return new x.constructor(0,0)};var $shiftRightUint64=function(x,y){if(y===0){return x}if(y<32){return new x.constructor(x.$high>>>y,(x.$low>>>y|x.$high<<32-y)>>>0)}if(y<64){return new x.constructor(0,x.$high>>>y-32)}return new x.constructor(0,0)};var $mul64=function(x,y){var high=0,low=0;if((y.$low&1)!==0){high=x.$high;low=x.$low}for(var i=1;i<32;i++){if((y.$low&1<>>32-i;low+=x.$low<>>0}}for(var i=0;i<32;i++){if((y.$high&1<yHigh||xHigh===yHigh&&xLow>yLow)){yHigh=(yHigh<<1|yLow>>>31)>>>0;yLow=yLow<<1>>>0;n++}for(var i=0;i<=n;i++){high=high<<1|low>>>31;low=low<<1>>>0;if(xHigh>yHigh||xHigh===yHigh&&xLow>=yLow){xHigh=xHigh-yHigh;xLow=xLow-yLow;if(xLow<0){xHigh--;xLow+=4294967296}low++;if(low===4294967296){high++;low=0}}yLow=(yLow>>>1|yHigh<<32-1)>>>0;yHigh=yHigh>>>1}if(returnRemainder){return new x.constructor(xHigh*rs,xLow*rs)}return new x.constructor(high*s,low*s)};var $divComplex=function(n,d){var ninf=n.$real===Infinity||n.$real===-Infinity||n.$imag===Infinity||n.$imag===-Infinity;var dinf=d.$real===Infinity||d.$real===-Infinity||d.$imag===Infinity||d.$imag===-Infinity;var nnan=!ninf&&(n.$real!==n.$real||n.$imag!==n.$imag);var dnan=!dinf&&(d.$real!==d.$real||d.$imag!==d.$imag);if(nnan||dnan){return new n.constructor(NaN,NaN)}if(ninf&&!dinf){return new n.constructor(Infinity,Infinity)}if(!ninf&&dinf){return new n.constructor(0,0)}if(d.$real===0&&d.$imag===0){if(n.$real===0&&n.$imag===0){return new n.constructor(NaN,NaN)}return new n.constructor(Infinity,Infinity)}var a=Math.abs(d.$real);var b=Math.abs(d.$imag);if(a<=b){var ratio=d.$real/d.$imag;var denom=d.$real*ratio+d.$imag;return new n.constructor((n.$real*ratio+n.$imag)/denom,(n.$imag*ratio-n.$real)/denom)}var ratio=d.$imag/d.$real;var denom=d.$imag*ratio+d.$real;return new n.constructor((n.$imag*ratio+n.$real)/denom,(n.$imag-n.$real*ratio)/denom)};var $kindBool=1;var $kindInt=2;var $kindInt8=3;var $kindInt16=4;var $kindInt32=5;var $kindInt64=6;var $kindUint=7;var $kindUint8=8;var $kindUint16=9;var $kindUint32=10;var $kindUint64=11;var $kindUintptr=12;var $kindFloat32=13;var $kindFloat64=14;var $kindComplex64=15;var $kindComplex128=16;var $kindArray=17;var $kindChan=18;var $kindFunc=19;var $kindInterface=20;var $kindMap=21;var $kindPtr=22;var $kindSlice=23;var $kindString=24;var $kindStruct=25;var $kindUnsafePointer=26;var $methodSynthesizers=[];var $addMethodSynthesizer=function(f){if($methodSynthesizers===null){f();return}$methodSynthesizers.push(f)};var $synthesizeMethods=function(){$methodSynthesizers.forEach(function(f){f()});$methodSynthesizers=null};var $ifaceKeyFor=function(x){if(x===$ifaceNil){return"nil"}var c=x.constructor;return c.string+"$"+c.keyFor(x.$val)};var $identity=function(x){return x};var $typeIDCounter=0;var $idKey=function(x){if(x.$id===undefined){$idCounter++;x.$id=$idCounter}return String(x.$id)};var $newType=function(size,kind,string,named,pkg,exported,constructor){var typ;switch(kind){case $kindBool:case $kindInt:case $kindInt8:case $kindInt16:case $kindInt32:case $kindUint:case $kindUint8:case $kindUint16:case $kindUint32:case $kindUintptr:case $kindUnsafePointer:typ=function(v){this.$val=v};typ.wrapped=true;typ.keyFor=$identity;break;case $kindString:typ=function(v){this.$val=v};typ.wrapped=true;typ.keyFor=function(x){return"$"+x};break;case $kindFloat32:case $kindFloat64:typ=function(v){this.$val=v};typ.wrapped=true;typ.keyFor=function(x){return $floatKey(x)};break;case $kindInt64:typ=function(high,low){this.$high=high+Math.floor(Math.ceil(low)/4294967296)>>0;this.$low=low>>>0;this.$val=this};typ.keyFor=function(x){return x.$high+"$"+x.$low};break;case $kindUint64:typ=function(high,low){this.$high=high+Math.floor(Math.ceil(low)/4294967296)>>>0;this.$low=low>>>0;this.$val=this};typ.keyFor=function(x){return x.$high+"$"+x.$low};break;case $kindComplex64:typ=function(real,imag){this.$real=$fround(real);this.$imag=$fround(imag);this.$val=this};typ.keyFor=function(x){return x.$real+"$"+x.$imag};break;case $kindComplex128:typ=function(real,imag){this.$real=real;this.$imag=imag;this.$val=this};typ.keyFor=function(x){return x.$real+"$"+x.$imag};break;case $kindArray:typ=function(v){this.$val=v};typ.wrapped=true;typ.ptr=$newType(4,$kindPtr,"*"+string,false,"",false,function(array){this.$get=function(){return array};this.$set=function(v){typ.copy(this,v)};this.$val=array});typ.init=function(elem,len){typ.elem=elem;typ.len=len;typ.comparable=elem.comparable;typ.keyFor=function(x){return Array.prototype.join.call($mapArray(x,function(e){return String(elem.keyFor(e)).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}),"$")};typ.copy=function(dst,src){$copyArray(dst,src,0,0,src.length,elem)};typ.ptr.init(typ);Object.defineProperty(typ.ptr.nil,"nilCheck",{get:$throwNilPointerError})};break;case $kindChan:typ=function(v){this.$val=v};typ.wrapped=true;typ.keyFor=$idKey;typ.init=function(elem,sendOnly,recvOnly){typ.elem=elem;typ.sendOnly=sendOnly;typ.recvOnly=recvOnly};break;case $kindFunc:typ=function(v){this.$val=v};typ.wrapped=true;typ.init=function(params,results,variadic){typ.params=params;typ.results=results;typ.variadic=variadic;typ.comparable=false};break;case $kindInterface:typ={implementedBy:{},missingMethodFor:{}};typ.keyFor=$ifaceKeyFor;typ.init=function(methods){typ.methods=methods;methods.forEach(function(m){$ifaceNil[m.prop]=$throwNilPointerError})};break;case $kindMap:typ=function(v){this.$val=v};typ.wrapped=true;typ.init=function(key,elem){typ.key=key;typ.elem=elem;typ.comparable=false};break;case $kindPtr:typ=constructor||function(getter,setter,target){this.$get=getter;this.$set=setter;this.$target=target;this.$val=this};typ.keyFor=$idKey;typ.init=function(elem){typ.elem=elem;typ.wrapped=elem.kind===$kindArray;typ.nil=new typ($throwNilPointerError,$throwNilPointerError)};break;case $kindSlice:typ=function(array){if(array.constructor!==typ.nativeArray){array=new typ.nativeArray(array)}this.$array=array;this.$offset=0;this.$length=array.length;this.$capacity=array.length;this.$val=this};typ.init=function(elem){typ.elem=elem;typ.comparable=false;typ.nativeArray=$nativeArray(elem.kind);typ.nil=new typ([])};break;case $kindStruct:typ=function(v){this.$val=v};typ.wrapped=true;typ.ptr=$newType(4,$kindPtr,"*"+string,false,pkg,exported,constructor);typ.ptr.elem=typ;typ.ptr.prototype.$get=function(){return this};typ.ptr.prototype.$set=function(v){typ.copy(this,v)};typ.init=function(pkgPath,fields){typ.pkgPath=pkgPath;typ.fields=fields;fields.forEach(function(f){if(!f.typ.comparable){typ.comparable=false}});typ.keyFor=function(x){var val=x.$val;return $mapArray(fields,function(f){return String(f.typ.keyFor(val[f.prop])).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}).join("$")};typ.copy=function(dst,src){for(var i=0;i0){var next=[];var mset=[];current.forEach(function(e){if(seen[e.typ.string]){return}seen[e.typ.string]=true;if(e.typ.named){mset=mset.concat(e.typ.methods);if(e.indirect){mset=mset.concat($ptrType(e.typ).methods)}}switch(e.typ.kind){case $kindStruct:e.typ.fields.forEach(function(f){if(f.anonymous){var fTyp=f.typ;var fIsPtr=fTyp.kind===$kindPtr;next.push({typ:fIsPtr?fTyp.elem:fTyp,indirect:e.indirect||fIsPtr})}});break;case $kindInterface:mset=mset.concat(e.typ.methods);break}});mset.forEach(function(m){if(base[m.name]===undefined){base[m.name]=m}});current=next}typ.methodSetCache=[];Object.keys(base).sort().forEach(function(name){typ.methodSetCache.push(base[name])});return typ.methodSetCache};var $Bool=$newType(1,$kindBool,"bool",true,"",false,null);var $Int=$newType(4,$kindInt,"int",true,"",false,null);var $Int8=$newType(1,$kindInt8,"int8",true,"",false,null);var $Int16=$newType(2,$kindInt16,"int16",true,"",false,null);var $Int32=$newType(4,$kindInt32,"int32",true,"",false,null);var $Int64=$newType(8,$kindInt64,"int64",true,"",false,null);var $Uint=$newType(4,$kindUint,"uint",true,"",false,null);var $Uint8=$newType(1,$kindUint8,"uint8",true,"",false,null);var $Uint16=$newType(2,$kindUint16,"uint16",true,"",false,null);var $Uint32=$newType(4,$kindUint32,"uint32",true,"",false,null);var $Uint64=$newType(8,$kindUint64,"uint64",true,"",false,null);var $Uintptr=$newType(4,$kindUintptr,"uintptr",true,"",false,null);var $Float32=$newType(4,$kindFloat32,"float32",true,"",false,null);var $Float64=$newType(8,$kindFloat64,"float64",true,"",false,null);var $Complex64=$newType(8,$kindComplex64,"complex64",true,"",false,null);var $Complex128=$newType(16,$kindComplex128,"complex128",true,"",false,null);var $String=$newType(8,$kindString,"string",true,"",false,null);var $UnsafePointer=$newType(4,$kindUnsafePointer,"unsafe.Pointer",true,"",false,null);var $nativeArray=function(elemKind){switch(elemKind){case $kindInt:return Int32Array;case $kindInt8:return Int8Array;case $kindInt16:return Int16Array;case $kindInt32:return Int32Array;case $kindUint:return Uint32Array;case $kindUint8:return Uint8Array;case $kindUint16:return Uint16Array;case $kindUint32:return Uint32Array;case $kindUintptr:return Uint32Array;case $kindFloat32:return Float32Array;case $kindFloat64:return Float64Array;default:return Array}};var $toNativeArray=function(elemKind,array){var nativeArray=$nativeArray(elemKind);if(nativeArray===Array){return array}return new nativeArray(array)};var $arrayTypes={};var $arrayType=function(elem,len){var typeKey=elem.id+"$"+len;var typ=$arrayTypes[typeKey];if(typ===undefined){typ=$newType(12,$kindArray,"["+len+"]"+elem.string,false,"",false,null);$arrayTypes[typeKey]=typ;typ.init(elem,len)}return typ};var $chanType=function(elem,sendOnly,recvOnly){var string=(recvOnly?"<-":"")+"chan"+(sendOnly?"<- ":" ")+elem.string;var field=sendOnly?"SendChan":recvOnly?"RecvChan":"Chan";var typ=elem[field];if(typ===undefined){typ=$newType(4,$kindChan,string,false,"",false,null);elem[field]=typ;typ.init(elem,sendOnly,recvOnly)}return typ};var $Chan=function(elem,capacity){if(capacity<0||capacity>2147483647){$throwRuntimeError("makechan: size out of range")}this.$elem=elem;this.$capacity=capacity;this.$buffer=[];this.$sendQueue=[];this.$recvQueue=[];this.$closed=false};var $chanNil=new $Chan(null,0);$chanNil.$sendQueue=$chanNil.$recvQueue={length:0,push:function(){},shift:function(){return undefined},indexOf:function(){return-1}};var $funcTypes={};var $funcType=function(params,results,variadic){var typeKey=$mapArray(params,function(p){return p.id}).join(",")+"$"+$mapArray(results,function(r){return r.id}).join(",")+"$"+variadic;var typ=$funcTypes[typeKey];if(typ===undefined){var paramTypes=$mapArray(params,function(p){return p.string});if(variadic){paramTypes[paramTypes.length-1]="..."+paramTypes[paramTypes.length-1].substr(2)}var string="func("+paramTypes.join(", ")+")";if(results.length===1){string+=" "+results[0].string}else if(results.length>1){string+=" ("+$mapArray(results,function(r){return r.string}).join(", ")+")"}typ=$newType(4,$kindFunc,string,false,"",false,null);$funcTypes[typeKey]=typ;typ.init(params,results,variadic)}return typ};var $interfaceTypes={};var $interfaceType=function(methods){var typeKey=$mapArray(methods,function(m){return m.pkg+","+m.name+","+m.typ.id}).join("$");var typ=$interfaceTypes[typeKey];if(typ===undefined){var string="interface {}";if(methods.length!==0){string="interface { "+$mapArray(methods,function(m){return(m.pkg!==""?m.pkg+".":"")+m.name+m.typ.string.substr(4)}).join("; ")+" }"}typ=$newType(8,$kindInterface,string,false,"",false,null);$interfaceTypes[typeKey]=typ;typ.init(methods)}return typ};var $emptyInterface=$interfaceType([]);var $ifaceNil={};var $error=$newType(8,$kindInterface,"error",true,"",false,null);$error.init([{prop:"Error",name:"Error",pkg:"",typ:$funcType([],[$String],false)}]);var $mapTypes={};var $mapType=function(key,elem){var typeKey=key.id+"$"+elem.id;var typ=$mapTypes[typeKey];if(typ===undefined){typ=$newType(4,$kindMap,"map["+key.string+"]"+elem.string,false,"",false,null);$mapTypes[typeKey]=typ;typ.init(key,elem)}return typ};var $makeMap=function(keyForFunc,entries){var m={};for(var i=0;i2147483647){$throwRuntimeError("makeslice: len out of range")}if(capacity<0||capacity2147483647){$throwRuntimeError("makeslice: cap out of range")}var array=new typ.nativeArray(capacity);if(typ.nativeArray===Array){for(var i=0;i=$curGoroutine.deferStack.length){throw jsErr}if(jsErr!==null){var newErr=null;try{$curGoroutine.deferStack.push(deferred);$panic(new $jsErrorPtr(jsErr))}catch(err){newErr=err}$curGoroutine.deferStack.pop();$callDeferred(deferred,newErr);return}if($curGoroutine.asleep){return}$stackDepthOffset--;var outerPanicStackDepth=$panicStackDepth;var outerPanicValue=$panicValue;var localPanicValue=$curGoroutine.panicStack.pop();if(localPanicValue!==undefined){$panicStackDepth=$getStackDepth();$panicValue=localPanicValue}try{while(true){if(deferred===null){deferred=$curGoroutine.deferStack[$curGoroutine.deferStack.length-1];if(deferred===undefined){$panicStackDepth=null;if(localPanicValue.Object instanceof Error){throw localPanicValue.Object}var msg;if(localPanicValue.constructor===$String){msg=localPanicValue.$val}else if(localPanicValue.Error!==undefined){msg=localPanicValue.Error()}else if(localPanicValue.String!==undefined){msg=localPanicValue.String()}else{msg=localPanicValue}throw new Error(msg)}}var call=deferred.pop();if(call===undefined){$curGoroutine.deferStack.pop();if(localPanicValue!==undefined){deferred=null;continue}return}var r=call[0].apply(call[2],call[1]);if(r&&r.$blk!==undefined){deferred.push([r.$blk,[],r]);if(fromPanic){throw null}return}if(localPanicValue!==undefined&&$panicStackDepth===null){throw null}}}finally{if(localPanicValue!==undefined){if($panicStackDepth!==null){$curGoroutine.panicStack.push(localPanicValue)}$panicStackDepth=outerPanicStackDepth;$panicValue=outerPanicValue}$stackDepthOffset++}};var $panic=function(value){$curGoroutine.panicStack.push(value);$callDeferred(null,null,true)};var $recover=function(){if($panicStackDepth===null||$panicStackDepth!==undefined&&$panicStackDepth!==$getStackDepth()-2){return $ifaceNil}$panicStackDepth=null;return $panicValue};var $throw=function(err){throw err};var $noGoroutine={asleep:false,exit:false,deferStack:[],panicStack:[]};var $curGoroutine=$noGoroutine,$totalGoroutines=0,$awakeGoroutines=0,$checkForDeadlock=true;var $mainFinished=false;var $go=function(fun,args){$totalGoroutines++;$awakeGoroutines++;var $goroutine=function(){try{$curGoroutine=$goroutine;var r=fun.apply(undefined,args);if(r&&r.$blk!==undefined){fun=function(){return r.$blk()};args=[];return}$goroutine.exit=true}catch(err){if(!$goroutine.exit){throw err}}finally{$curGoroutine=$noGoroutine;if($goroutine.exit){$totalGoroutines--;$goroutine.asleep=true}if($goroutine.asleep){$awakeGoroutines--;if(!$mainFinished&&$awakeGoroutines===0&&$checkForDeadlock){console.error("fatal error: all goroutines are asleep - deadlock!");if($global.process!==undefined){$global.process.exit(2)}}}}};$goroutine.asleep=false;$goroutine.exit=false;$goroutine.deferStack=[];$goroutine.panicStack=[];$schedule($goroutine)};var $scheduled=[];var $runScheduled=function(){try{var r;while((r=$scheduled.shift())!==undefined){r()}}finally{if($scheduled.length>0){setTimeout($runScheduled,0)}}};var $schedule=function(goroutine){if(goroutine.asleep){goroutine.asleep=false;$awakeGoroutines++}$scheduled.push(goroutine);if($curGoroutine===$noGoroutine){$runScheduled()}};var $setTimeout=function(f,t){$awakeGoroutines++;return setTimeout(function(){$awakeGoroutines--;f()},t)};var $block=function(){if($curGoroutine===$noGoroutine){$throwRuntimeError("cannot block in JavaScript callback, fix by wrapping code in goroutine")}$curGoroutine.asleep=true};var $send=function(chan,value){if(chan.$closed){$throwRuntimeError("send on closed channel")}var queuedRecv=chan.$recvQueue.shift();if(queuedRecv!==undefined){queuedRecv([value,true]);return}if(chan.$buffer.length65535){var h=Math.floor((c-65536)/1024)+55296;var l=(c-65536)%1024+56320;s+=String.fromCharCode(h,l);continue}s+=String.fromCharCode(c)}return s;case $kindStruct:var timePkg=$packages["time"];if(timePkg!==undefined&&v.constructor===timePkg.Time.ptr){var milli=$div64(v.UnixNano(),new $Int64(0,1e6));return new Date($flatten64(milli))}var noJsObject={};var searchJsObject=function(v,t){if(t===$jsObjectPtr){return v}switch(t.kind){case $kindPtr:if(v===t.nil){return noJsObject}return searchJsObject(v.$get(),t.elem);case $kindStruct:var f=t.fields[0];return searchJsObject(v[f.prop],f.typ);case $kindInterface:return searchJsObject(v.$val,v.constructor);default:return noJsObject}};var o=searchJsObject(v,t);if(o!==noJsObject){return o}o={};for(var i=0;i>24;case $kindInt16:return parseInt(v)<<16>>16;case $kindInt32:return parseInt(v)>>0;case $kindUint:return parseInt(v);case $kindUint8:return parseInt(v)<<24>>>24;case $kindUint16:return parseInt(v)<<16>>>16;case $kindUint32:case $kindUintptr:return parseInt(v)>>>0;case $kindInt64:case $kindUint64:return new t(0,v);case $kindFloat32:case $kindFloat64:return parseFloat(v);case $kindArray:if(v.length!==t.len){$throwRuntimeError("got array with wrong size from JavaScript native")}return $mapArray(v,function(e){return $internalize(e,t.elem)});case $kindFunc:return function(){var args=[];for(var i=0;i=128){return false}}return true};` const prelude = `Error.stackTraceLimit = Infinity; From 08b8e29c1838cabe12b54132c002c5eee2693ee8 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 15 Mar 2018 11:15:16 +0900 Subject: [PATCH 4/5] Re-retry minifying prelude Tried https://skalman.github.io/UglifyJS-online/ --- compiler/prelude/prelude.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/prelude/prelude.go b/compiler/prelude/prelude.go index e52cef4e6..8757cb913 100644 --- a/compiler/prelude/prelude.go +++ b/compiler/prelude/prelude.go @@ -4,7 +4,7 @@ const Prelude = prelude + numeric + types + goroutines + jsmapping // Minified is Prelude ran through UglifyJS 3 via https://skalman.github.io/UglifyJS-online/ // with default options. -const Minified = `Error.stackTraceLimit=Infinity;var $global,$module;if(typeof window!=="undefined"){$global=window}else if(typeof self!=="undefined"){$global=self}else if(typeof global!=="undefined"){$global=global;$global.require=require}else{$global=this}if($global===undefined||$global.Array===undefined){throw new Error("no global object found")}if(typeof module!=="undefined"){$module=module}var $packages={},$idCounter=0;var $keys=function(m){return m?Object.keys(m):[]};var $flushConsole=function(){};var $throwRuntimeError;var $throwNilPointerError=function(){$throwRuntimeError("invalid memory address or nil pointer dereference")};var $call=function(fn,rcvr,args){return fn.apply(rcvr,args)};var $makeFunc=function(fn){return function(){return $externalize(fn(this,new($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments,[]))),$emptyInterface)}};var $unused=function(v){};var $mapArray=function(array,f){var newArray=new array.constructor(array.length);for(var i=0;islice.$capacity||max>slice.$capacity){$throwRuntimeError("slice bounds out of range")}var s=new slice.constructor(slice.$array);s.$offset=slice.$offset+low;s.$length=high-low;s.$capacity=max-low;return s};var $substring=function(str,low,high){if(low<0||highstr.length){$throwRuntimeError("slice bounds out of range")}return str.substring(low,high)};var $sliceToArray=function(slice){if(slice.$array.constructor!==Array){return slice.$array.subarray(slice.$offset,slice.$offset+slice.$length)}return slice.$array.slice(slice.$offset,slice.$offset+slice.$length)};var $decodeRune=function(str,pos){var c0=str.charCodeAt(pos);if(c0<128){return[c0,1]}if(c0!==c0||c0<192){return[65533,1]}var c1=str.charCodeAt(pos+1);if(c1!==c1||c1<128||192<=c1){return[65533,1]}if(c0<224){var r=(c0&31)<<6|c1&63;if(r<=127){return[65533,1]}return[r,2]}var c2=str.charCodeAt(pos+2);if(c2!==c2||c2<128||192<=c2){return[65533,1]}if(c0<240){var r=(c0&15)<<12|(c1&63)<<6|c2&63;if(r<=2047){return[65533,1]}if(55296<=r&&r<=57343){return[65533,1]}return[r,3]}var c3=str.charCodeAt(pos+3);if(c3!==c3||c3<128||192<=c3){return[65533,1]}if(c0<248){var r=(c0&7)<<18|(c1&63)<<12|(c2&63)<<6|c3&63;if(r<=65535||11141111114111||55296<=r&&r<=57343){r=65533}if(r<=127){return String.fromCharCode(r)}if(r<=2047){return String.fromCharCode(192|r>>6,128|r&63)}if(r<=65535){return String.fromCharCode(224|r>>12,128|r>>6&63,128|r&63)}return String.fromCharCode(240|r>>18,128|r>>12&63,128|r>>6&63,128|r&63)};var $stringToBytes=function(str){var array=new Uint8Array(str.length);for(var i=0;isrcOffset){for(var i=n-1;i>=0;i--){elem.copy(dst[dstOffset+i],src[srcOffset+i])}return}for(var i=0;isrcOffset){for(var i=n-1;i>=0;i--){dst[dstOffset+i]=src[srcOffset+i]}return}for(var i=0;inewCapacity){newOffset=0;newCapacity=Math.max(newLength,slice.$capacity<1024?slice.$capacity*2:Math.floor(slice.$capacity*5/4));if(slice.$array.constructor===Array){newArray=slice.$array.slice(slice.$offset,slice.$offset+slice.$length);newArray.length=newCapacity;var zero=slice.constructor.elem.zero;for(var i=slice.$length;i>>16&65535;var al=a&65535;var bh=b>>>16&65535;var bl=b&65535;return al*bl+(ah*bl+al*bh<<16>>>0)>>0};var $floatKey=function(f){if(f!==f){$idCounter++;return"NaN$"+$idCounter}return String(f)};var $flatten64=function(x){return x.$high*4294967296+x.$low};var $shiftLeft64=function(x,y){if(y===0){return x}if(y<32){return new x.constructor(x.$high<>>32-y,x.$low<>>0)}if(y<64){return new x.constructor(x.$low<>y,(x.$low>>>y|x.$high<<32-y)>>>0)}if(y<64){return new x.constructor(x.$high>>31,x.$high>>y-32>>>0)}if(x.$high<0){return new x.constructor(-1,4294967295)}return new x.constructor(0,0)};var $shiftRightUint64=function(x,y){if(y===0){return x}if(y<32){return new x.constructor(x.$high>>>y,(x.$low>>>y|x.$high<<32-y)>>>0)}if(y<64){return new x.constructor(0,x.$high>>>y-32)}return new x.constructor(0,0)};var $mul64=function(x,y){var high=0,low=0;if((y.$low&1)!==0){high=x.$high;low=x.$low}for(var i=1;i<32;i++){if((y.$low&1<>>32-i;low+=x.$low<>>0}}for(var i=0;i<32;i++){if((y.$high&1<yHigh||xHigh===yHigh&&xLow>yLow)){yHigh=(yHigh<<1|yLow>>>31)>>>0;yLow=yLow<<1>>>0;n++}for(var i=0;i<=n;i++){high=high<<1|low>>>31;low=low<<1>>>0;if(xHigh>yHigh||xHigh===yHigh&&xLow>=yLow){xHigh=xHigh-yHigh;xLow=xLow-yLow;if(xLow<0){xHigh--;xLow+=4294967296}low++;if(low===4294967296){high++;low=0}}yLow=(yLow>>>1|yHigh<<32-1)>>>0;yHigh=yHigh>>>1}if(returnRemainder){return new x.constructor(xHigh*rs,xLow*rs)}return new x.constructor(high*s,low*s)};var $divComplex=function(n,d){var ninf=n.$real===Infinity||n.$real===-Infinity||n.$imag===Infinity||n.$imag===-Infinity;var dinf=d.$real===Infinity||d.$real===-Infinity||d.$imag===Infinity||d.$imag===-Infinity;var nnan=!ninf&&(n.$real!==n.$real||n.$imag!==n.$imag);var dnan=!dinf&&(d.$real!==d.$real||d.$imag!==d.$imag);if(nnan||dnan){return new n.constructor(NaN,NaN)}if(ninf&&!dinf){return new n.constructor(Infinity,Infinity)}if(!ninf&&dinf){return new n.constructor(0,0)}if(d.$real===0&&d.$imag===0){if(n.$real===0&&n.$imag===0){return new n.constructor(NaN,NaN)}return new n.constructor(Infinity,Infinity)}var a=Math.abs(d.$real);var b=Math.abs(d.$imag);if(a<=b){var ratio=d.$real/d.$imag;var denom=d.$real*ratio+d.$imag;return new n.constructor((n.$real*ratio+n.$imag)/denom,(n.$imag*ratio-n.$real)/denom)}var ratio=d.$imag/d.$real;var denom=d.$imag*ratio+d.$real;return new n.constructor((n.$imag*ratio+n.$real)/denom,(n.$imag-n.$real*ratio)/denom)};var $kindBool=1;var $kindInt=2;var $kindInt8=3;var $kindInt16=4;var $kindInt32=5;var $kindInt64=6;var $kindUint=7;var $kindUint8=8;var $kindUint16=9;var $kindUint32=10;var $kindUint64=11;var $kindUintptr=12;var $kindFloat32=13;var $kindFloat64=14;var $kindComplex64=15;var $kindComplex128=16;var $kindArray=17;var $kindChan=18;var $kindFunc=19;var $kindInterface=20;var $kindMap=21;var $kindPtr=22;var $kindSlice=23;var $kindString=24;var $kindStruct=25;var $kindUnsafePointer=26;var $methodSynthesizers=[];var $addMethodSynthesizer=function(f){if($methodSynthesizers===null){f();return}$methodSynthesizers.push(f)};var $synthesizeMethods=function(){$methodSynthesizers.forEach(function(f){f()});$methodSynthesizers=null};var $ifaceKeyFor=function(x){if(x===$ifaceNil){return"nil"}var c=x.constructor;return c.string+"$"+c.keyFor(x.$val)};var $identity=function(x){return x};var $typeIDCounter=0;var $idKey=function(x){if(x.$id===undefined){$idCounter++;x.$id=$idCounter}return String(x.$id)};var $newType=function(size,kind,string,named,pkg,exported,constructor){var typ;switch(kind){case $kindBool:case $kindInt:case $kindInt8:case $kindInt16:case $kindInt32:case $kindUint:case $kindUint8:case $kindUint16:case $kindUint32:case $kindUintptr:case $kindUnsafePointer:typ=function(v){this.$val=v};typ.wrapped=true;typ.keyFor=$identity;break;case $kindString:typ=function(v){this.$val=v};typ.wrapped=true;typ.keyFor=function(x){return"$"+x};break;case $kindFloat32:case $kindFloat64:typ=function(v){this.$val=v};typ.wrapped=true;typ.keyFor=function(x){return $floatKey(x)};break;case $kindInt64:typ=function(high,low){this.$high=high+Math.floor(Math.ceil(low)/4294967296)>>0;this.$low=low>>>0;this.$val=this};typ.keyFor=function(x){return x.$high+"$"+x.$low};break;case $kindUint64:typ=function(high,low){this.$high=high+Math.floor(Math.ceil(low)/4294967296)>>>0;this.$low=low>>>0;this.$val=this};typ.keyFor=function(x){return x.$high+"$"+x.$low};break;case $kindComplex64:typ=function(real,imag){this.$real=$fround(real);this.$imag=$fround(imag);this.$val=this};typ.keyFor=function(x){return x.$real+"$"+x.$imag};break;case $kindComplex128:typ=function(real,imag){this.$real=real;this.$imag=imag;this.$val=this};typ.keyFor=function(x){return x.$real+"$"+x.$imag};break;case $kindArray:typ=function(v){this.$val=v};typ.wrapped=true;typ.ptr=$newType(4,$kindPtr,"*"+string,false,"",false,function(array){this.$get=function(){return array};this.$set=function(v){typ.copy(this,v)};this.$val=array});typ.init=function(elem,len){typ.elem=elem;typ.len=len;typ.comparable=elem.comparable;typ.keyFor=function(x){return Array.prototype.join.call($mapArray(x,function(e){return String(elem.keyFor(e)).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}),"$")};typ.copy=function(dst,src){$copyArray(dst,src,0,0,src.length,elem)};typ.ptr.init(typ);Object.defineProperty(typ.ptr.nil,"nilCheck",{get:$throwNilPointerError})};break;case $kindChan:typ=function(v){this.$val=v};typ.wrapped=true;typ.keyFor=$idKey;typ.init=function(elem,sendOnly,recvOnly){typ.elem=elem;typ.sendOnly=sendOnly;typ.recvOnly=recvOnly};break;case $kindFunc:typ=function(v){this.$val=v};typ.wrapped=true;typ.init=function(params,results,variadic){typ.params=params;typ.results=results;typ.variadic=variadic;typ.comparable=false};break;case $kindInterface:typ={implementedBy:{},missingMethodFor:{}};typ.keyFor=$ifaceKeyFor;typ.init=function(methods){typ.methods=methods;methods.forEach(function(m){$ifaceNil[m.prop]=$throwNilPointerError})};break;case $kindMap:typ=function(v){this.$val=v};typ.wrapped=true;typ.init=function(key,elem){typ.key=key;typ.elem=elem;typ.comparable=false};break;case $kindPtr:typ=constructor||function(getter,setter,target){this.$get=getter;this.$set=setter;this.$target=target;this.$val=this};typ.keyFor=$idKey;typ.init=function(elem){typ.elem=elem;typ.wrapped=elem.kind===$kindArray;typ.nil=new typ($throwNilPointerError,$throwNilPointerError)};break;case $kindSlice:typ=function(array){if(array.constructor!==typ.nativeArray){array=new typ.nativeArray(array)}this.$array=array;this.$offset=0;this.$length=array.length;this.$capacity=array.length;this.$val=this};typ.init=function(elem){typ.elem=elem;typ.comparable=false;typ.nativeArray=$nativeArray(elem.kind);typ.nil=new typ([])};break;case $kindStruct:typ=function(v){this.$val=v};typ.wrapped=true;typ.ptr=$newType(4,$kindPtr,"*"+string,false,pkg,exported,constructor);typ.ptr.elem=typ;typ.ptr.prototype.$get=function(){return this};typ.ptr.prototype.$set=function(v){typ.copy(this,v)};typ.init=function(pkgPath,fields){typ.pkgPath=pkgPath;typ.fields=fields;fields.forEach(function(f){if(!f.typ.comparable){typ.comparable=false}});typ.keyFor=function(x){var val=x.$val;return $mapArray(fields,function(f){return String(f.typ.keyFor(val[f.prop])).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}).join("$")};typ.copy=function(dst,src){for(var i=0;i0){var next=[];var mset=[];current.forEach(function(e){if(seen[e.typ.string]){return}seen[e.typ.string]=true;if(e.typ.named){mset=mset.concat(e.typ.methods);if(e.indirect){mset=mset.concat($ptrType(e.typ).methods)}}switch(e.typ.kind){case $kindStruct:e.typ.fields.forEach(function(f){if(f.anonymous){var fTyp=f.typ;var fIsPtr=fTyp.kind===$kindPtr;next.push({typ:fIsPtr?fTyp.elem:fTyp,indirect:e.indirect||fIsPtr})}});break;case $kindInterface:mset=mset.concat(e.typ.methods);break}});mset.forEach(function(m){if(base[m.name]===undefined){base[m.name]=m}});current=next}typ.methodSetCache=[];Object.keys(base).sort().forEach(function(name){typ.methodSetCache.push(base[name])});return typ.methodSetCache};var $Bool=$newType(1,$kindBool,"bool",true,"",false,null);var $Int=$newType(4,$kindInt,"int",true,"",false,null);var $Int8=$newType(1,$kindInt8,"int8",true,"",false,null);var $Int16=$newType(2,$kindInt16,"int16",true,"",false,null);var $Int32=$newType(4,$kindInt32,"int32",true,"",false,null);var $Int64=$newType(8,$kindInt64,"int64",true,"",false,null);var $Uint=$newType(4,$kindUint,"uint",true,"",false,null);var $Uint8=$newType(1,$kindUint8,"uint8",true,"",false,null);var $Uint16=$newType(2,$kindUint16,"uint16",true,"",false,null);var $Uint32=$newType(4,$kindUint32,"uint32",true,"",false,null);var $Uint64=$newType(8,$kindUint64,"uint64",true,"",false,null);var $Uintptr=$newType(4,$kindUintptr,"uintptr",true,"",false,null);var $Float32=$newType(4,$kindFloat32,"float32",true,"",false,null);var $Float64=$newType(8,$kindFloat64,"float64",true,"",false,null);var $Complex64=$newType(8,$kindComplex64,"complex64",true,"",false,null);var $Complex128=$newType(16,$kindComplex128,"complex128",true,"",false,null);var $String=$newType(8,$kindString,"string",true,"",false,null);var $UnsafePointer=$newType(4,$kindUnsafePointer,"unsafe.Pointer",true,"",false,null);var $nativeArray=function(elemKind){switch(elemKind){case $kindInt:return Int32Array;case $kindInt8:return Int8Array;case $kindInt16:return Int16Array;case $kindInt32:return Int32Array;case $kindUint:return Uint32Array;case $kindUint8:return Uint8Array;case $kindUint16:return Uint16Array;case $kindUint32:return Uint32Array;case $kindUintptr:return Uint32Array;case $kindFloat32:return Float32Array;case $kindFloat64:return Float64Array;default:return Array}};var $toNativeArray=function(elemKind,array){var nativeArray=$nativeArray(elemKind);if(nativeArray===Array){return array}return new nativeArray(array)};var $arrayTypes={};var $arrayType=function(elem,len){var typeKey=elem.id+"$"+len;var typ=$arrayTypes[typeKey];if(typ===undefined){typ=$newType(12,$kindArray,"["+len+"]"+elem.string,false,"",false,null);$arrayTypes[typeKey]=typ;typ.init(elem,len)}return typ};var $chanType=function(elem,sendOnly,recvOnly){var string=(recvOnly?"<-":"")+"chan"+(sendOnly?"<- ":" ")+elem.string;var field=sendOnly?"SendChan":recvOnly?"RecvChan":"Chan";var typ=elem[field];if(typ===undefined){typ=$newType(4,$kindChan,string,false,"",false,null);elem[field]=typ;typ.init(elem,sendOnly,recvOnly)}return typ};var $Chan=function(elem,capacity){if(capacity<0||capacity>2147483647){$throwRuntimeError("makechan: size out of range")}this.$elem=elem;this.$capacity=capacity;this.$buffer=[];this.$sendQueue=[];this.$recvQueue=[];this.$closed=false};var $chanNil=new $Chan(null,0);$chanNil.$sendQueue=$chanNil.$recvQueue={length:0,push:function(){},shift:function(){return undefined},indexOf:function(){return-1}};var $funcTypes={};var $funcType=function(params,results,variadic){var typeKey=$mapArray(params,function(p){return p.id}).join(",")+"$"+$mapArray(results,function(r){return r.id}).join(",")+"$"+variadic;var typ=$funcTypes[typeKey];if(typ===undefined){var paramTypes=$mapArray(params,function(p){return p.string});if(variadic){paramTypes[paramTypes.length-1]="..."+paramTypes[paramTypes.length-1].substr(2)}var string="func("+paramTypes.join(", ")+")";if(results.length===1){string+=" "+results[0].string}else if(results.length>1){string+=" ("+$mapArray(results,function(r){return r.string}).join(", ")+")"}typ=$newType(4,$kindFunc,string,false,"",false,null);$funcTypes[typeKey]=typ;typ.init(params,results,variadic)}return typ};var $interfaceTypes={};var $interfaceType=function(methods){var typeKey=$mapArray(methods,function(m){return m.pkg+","+m.name+","+m.typ.id}).join("$");var typ=$interfaceTypes[typeKey];if(typ===undefined){var string="interface {}";if(methods.length!==0){string="interface { "+$mapArray(methods,function(m){return(m.pkg!==""?m.pkg+".":"")+m.name+m.typ.string.substr(4)}).join("; ")+" }"}typ=$newType(8,$kindInterface,string,false,"",false,null);$interfaceTypes[typeKey]=typ;typ.init(methods)}return typ};var $emptyInterface=$interfaceType([]);var $ifaceNil={};var $error=$newType(8,$kindInterface,"error",true,"",false,null);$error.init([{prop:"Error",name:"Error",pkg:"",typ:$funcType([],[$String],false)}]);var $mapTypes={};var $mapType=function(key,elem){var typeKey=key.id+"$"+elem.id;var typ=$mapTypes[typeKey];if(typ===undefined){typ=$newType(4,$kindMap,"map["+key.string+"]"+elem.string,false,"",false,null);$mapTypes[typeKey]=typ;typ.init(key,elem)}return typ};var $makeMap=function(keyForFunc,entries){var m={};for(var i=0;i2147483647){$throwRuntimeError("makeslice: len out of range")}if(capacity<0||capacity2147483647){$throwRuntimeError("makeslice: cap out of range")}var array=new typ.nativeArray(capacity);if(typ.nativeArray===Array){for(var i=0;i=$curGoroutine.deferStack.length){throw jsErr}if(jsErr!==null){var newErr=null;try{$curGoroutine.deferStack.push(deferred);$panic(new $jsErrorPtr(jsErr))}catch(err){newErr=err}$curGoroutine.deferStack.pop();$callDeferred(deferred,newErr);return}if($curGoroutine.asleep){return}$stackDepthOffset--;var outerPanicStackDepth=$panicStackDepth;var outerPanicValue=$panicValue;var localPanicValue=$curGoroutine.panicStack.pop();if(localPanicValue!==undefined){$panicStackDepth=$getStackDepth();$panicValue=localPanicValue}try{while(true){if(deferred===null){deferred=$curGoroutine.deferStack[$curGoroutine.deferStack.length-1];if(deferred===undefined){$panicStackDepth=null;if(localPanicValue.Object instanceof Error){throw localPanicValue.Object}var msg;if(localPanicValue.constructor===$String){msg=localPanicValue.$val}else if(localPanicValue.Error!==undefined){msg=localPanicValue.Error()}else if(localPanicValue.String!==undefined){msg=localPanicValue.String()}else{msg=localPanicValue}throw new Error(msg)}}var call=deferred.pop();if(call===undefined){$curGoroutine.deferStack.pop();if(localPanicValue!==undefined){deferred=null;continue}return}var r=call[0].apply(call[2],call[1]);if(r&&r.$blk!==undefined){deferred.push([r.$blk,[],r]);if(fromPanic){throw null}return}if(localPanicValue!==undefined&&$panicStackDepth===null){throw null}}}finally{if(localPanicValue!==undefined){if($panicStackDepth!==null){$curGoroutine.panicStack.push(localPanicValue)}$panicStackDepth=outerPanicStackDepth;$panicValue=outerPanicValue}$stackDepthOffset++}};var $panic=function(value){$curGoroutine.panicStack.push(value);$callDeferred(null,null,true)};var $recover=function(){if($panicStackDepth===null||$panicStackDepth!==undefined&&$panicStackDepth!==$getStackDepth()-2){return $ifaceNil}$panicStackDepth=null;return $panicValue};var $throw=function(err){throw err};var $noGoroutine={asleep:false,exit:false,deferStack:[],panicStack:[]};var $curGoroutine=$noGoroutine,$totalGoroutines=0,$awakeGoroutines=0,$checkForDeadlock=true;var $mainFinished=false;var $go=function(fun,args){$totalGoroutines++;$awakeGoroutines++;var $goroutine=function(){try{$curGoroutine=$goroutine;var r=fun.apply(undefined,args);if(r&&r.$blk!==undefined){fun=function(){return r.$blk()};args=[];return}$goroutine.exit=true}catch(err){if(!$goroutine.exit){throw err}}finally{$curGoroutine=$noGoroutine;if($goroutine.exit){$totalGoroutines--;$goroutine.asleep=true}if($goroutine.asleep){$awakeGoroutines--;if(!$mainFinished&&$awakeGoroutines===0&&$checkForDeadlock){console.error("fatal error: all goroutines are asleep - deadlock!");if($global.process!==undefined){$global.process.exit(2)}}}}};$goroutine.asleep=false;$goroutine.exit=false;$goroutine.deferStack=[];$goroutine.panicStack=[];$schedule($goroutine)};var $scheduled=[];var $runScheduled=function(){try{var r;while((r=$scheduled.shift())!==undefined){r()}}finally{if($scheduled.length>0){setTimeout($runScheduled,0)}}};var $schedule=function(goroutine){if(goroutine.asleep){goroutine.asleep=false;$awakeGoroutines++}$scheduled.push(goroutine);if($curGoroutine===$noGoroutine){$runScheduled()}};var $setTimeout=function(f,t){$awakeGoroutines++;return setTimeout(function(){$awakeGoroutines--;f()},t)};var $block=function(){if($curGoroutine===$noGoroutine){$throwRuntimeError("cannot block in JavaScript callback, fix by wrapping code in goroutine")}$curGoroutine.asleep=true};var $send=function(chan,value){if(chan.$closed){$throwRuntimeError("send on closed channel")}var queuedRecv=chan.$recvQueue.shift();if(queuedRecv!==undefined){queuedRecv([value,true]);return}if(chan.$buffer.length65535){var h=Math.floor((c-65536)/1024)+55296;var l=(c-65536)%1024+56320;s+=String.fromCharCode(h,l);continue}s+=String.fromCharCode(c)}return s;case $kindStruct:var timePkg=$packages["time"];if(timePkg!==undefined&&v.constructor===timePkg.Time.ptr){var milli=$div64(v.UnixNano(),new $Int64(0,1e6));return new Date($flatten64(milli))}var noJsObject={};var searchJsObject=function(v,t){if(t===$jsObjectPtr){return v}switch(t.kind){case $kindPtr:if(v===t.nil){return noJsObject}return searchJsObject(v.$get(),t.elem);case $kindStruct:var f=t.fields[0];return searchJsObject(v[f.prop],f.typ);case $kindInterface:return searchJsObject(v.$val,v.constructor);default:return noJsObject}};var o=searchJsObject(v,t);if(o!==noJsObject){return o}o={};for(var i=0;i>24;case $kindInt16:return parseInt(v)<<16>>16;case $kindInt32:return parseInt(v)>>0;case $kindUint:return parseInt(v);case $kindUint8:return parseInt(v)<<24>>>24;case $kindUint16:return parseInt(v)<<16>>>16;case $kindUint32:case $kindUintptr:return parseInt(v)>>>0;case $kindInt64:case $kindUint64:return new t(0,v);case $kindFloat32:case $kindFloat64:return parseFloat(v);case $kindArray:if(v.length!==t.len){$throwRuntimeError("got array with wrong size from JavaScript native")}return $mapArray(v,function(e){return $internalize(e,t.elem)});case $kindFunc:return function(){var args=[];for(var i=0;i=128){return false}}return true};` +const Minified = `var $global,$module;if(Error.stackTraceLimit=1/0,"undefined"!=typeof window?$global=window:"undefined"!=typeof self?$global=self:"undefined"!=typeof global?($global=global).require=require:$global=this,void 0===$global||void 0===$global.Array)throw new Error("no global object found");"undefined"!=typeof module&&($module=module);var $throwRuntimeError,$packages={},$idCounter=0,$keys=function(e){return e?Object.keys(e):[]},$flushConsole=function(){},$throwNilPointerError=function(){$throwRuntimeError("invalid memory address or nil pointer dereference")},$call=function(e,n,r){return e.apply(n,r)},$makeFunc=function(e){return function(){return $externalize(e(this,new($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments,[]))),$emptyInterface)}},$unused=function(e){},$mapArray=function(e,n){for(var r=new e.constructor(e.length),t=0;te.$capacity||t>e.$capacity)&&$throwRuntimeError("slice bounds out of range");var i=new e.constructor(e.$array);return i.$offset=e.$offset+n,i.$length=r-n,i.$capacity=t-n,i},$substring=function(e,n,r){return(n<0||re.length)&&$throwRuntimeError("slice bounds out of range"),e.substring(n,r)},$sliceToArray=function(e){return e.$array.constructor!==Array?e.$array.subarray(e.$offset,e.$offset+e.$length):e.$array.slice(e.$offset,e.$offset+e.$length)},$decodeRune=function(e,n){var r=e.charCodeAt(n);if(r<128)return[r,1];if(r!=r||r<192)return[65533,1];var t=e.charCodeAt(n+1);if(t!=t||t<128||192<=t)return[65533,1];if(r<224)return(a=(31&r)<<6|63&t)<=127?[65533,1]:[a,2];var i=e.charCodeAt(n+2);if(i!=i||i<128||192<=i)return[65533,1];if(r<240)return(a=(15&r)<<12|(63&t)<<6|63&i)<=2047?[65533,1]:55296<=a&&a<=57343?[65533,1]:[a,3];var a,o=e.charCodeAt(n+3);return o!=o||o<128||192<=o?[65533,1]:r<248?(a=(7&r)<<18|(63&t)<<12|(63&i)<<6|63&o)<=65535||11141111114111||55296<=e&&e<=57343)&&(e=65533),e<=127?String.fromCharCode(e):e<=2047?String.fromCharCode(192|e>>6,128|63&e):e<=65535?String.fromCharCode(224|e>>12,128|e>>6&63,128|63&e):String.fromCharCode(240|e>>18,128|e>>12&63,128|e>>6&63,128|63&e)},$stringToBytes=function(e){for(var n=new Uint8Array(e.length),r=0;rt){for(var o=i-1;o>=0;o--)a.copy(e[r+o],n[t+o]);return}for(o=0;ot)for(o=i-1;o>=0;o--)e[r+o]=n[t+o];else for(o=0;o$)if(a=0,$=Math.max(o,e.$capacity<1024?2*e.$capacity:Math.floor(5*e.$capacity/4)),e.$array.constructor===Array){(i=e.$array.slice(e.$offset,e.$offset+e.$length)).length=$;for(var c=e.constructor.elem.zero,u=e.$length;u<$;u++)i[u]=c()}else(i=new e.$array.constructor($)).set(e.$array.subarray(e.$offset,e.$offset+e.$length));$copyArray(i,n,a+e.$length,r,t,e.constructor.elem);var l=new e.constructor(i);return l.$offset=a,l.$length=o,l.$capacity=$,l},$equal=function(e,n,r){if(r===$jsObjectPtr)return e===n;switch(r.kind){case $kindComplex64:case $kindComplex128:return e.$real===n.$real&&e.$imag===n.$imag;case $kindInt64:case $kindUint64:return e.$high===n.$high&&e.$low===n.$low;case $kindArray:if(e.length!==n.length)return!1;for(var t=0;t>>16&65535)*t+r*(n>>>16&65535)<<16>>>0)>>0},$floatKey=function(e){return e!=e?"NaN$"+ ++$idCounter:String(e)},$flatten64=function(e){return 4294967296*e.$high+e.$low},$shiftLeft64=function(e,n){return 0===n?e:n<32?new e.constructor(e.$high<>>32-n,e.$low<>>0):n<64?new e.constructor(e.$low<>n,(e.$low>>>n|e.$high<<32-n)>>>0):n<64?new e.constructor(e.$high>>31,e.$high>>n-32>>>0):e.$high<0?new e.constructor(-1,4294967295):new e.constructor(0,0)},$shiftRightUint64=function(e,n){return 0===n?e:n<32?new e.constructor(e.$high>>>n,(e.$low>>>n|e.$high<<32-n)>>>0):n<64?new e.constructor(0,e.$high>>>n-32):new e.constructor(0,0)},$mul64=function(e,n){var r=0,t=0;0!=(1&n.$low)&&(r=e.$high,t=e.$low);for(var i=1;i<32;i++)0!=(n.$low&1<>>32-i,t+=e.$low<>>0);for(i=0;i<32;i++)0!=(n.$high&1<$||a===$&&o>c);)$=($<<1|c>>>31)>>>0,c=c<<1>>>0,s++;for(var f=0;f<=s;f++)u=u<<1|l>>>31,l=l<<1>>>0,(a>$||a===$&&o>=c)&&(a-=$,(o-=c)<0&&(a--,o+=4294967296),4294967296===++l&&(u++,l=0)),c=(c>>>1|$<<31)>>>0,$>>>=1;return r?new e.constructor(a*i,o*i):new e.constructor(u*t,l*t)},$divComplex=function(e,n){var r=e.$real===1/0||e.$real===-1/0||e.$imag===1/0||e.$imag===-1/0,t=n.$real===1/0||n.$real===-1/0||n.$imag===1/0||n.$imag===-1/0,i=!r&&(e.$real!=e.$real||e.$imag!=e.$imag),a=!t&&(n.$real!=n.$real||n.$imag!=n.$imag);if(i||a)return new e.constructor(NaN,NaN);if(r&&!t)return new e.constructor(1/0,1/0);if(!r&&t)return new e.constructor(0,0);if(0===n.$real&&0===n.$imag)return 0===e.$real&&0===e.$imag?new e.constructor(NaN,NaN):new e.constructor(1/0,1/0);if(Math.abs(n.$real)<=Math.abs(n.$imag)){var o=n.$real/n.$imag,$=n.$real*o+n.$imag;return new e.constructor((e.$real*o+e.$imag)/$,(e.$imag*o-e.$real)/$)}o=n.$imag/n.$real,$=n.$imag*o+n.$real;return new e.constructor((e.$imag*o+e.$real)/$,(e.$imag-e.$real*o)/$)},$kindBool=1,$kindInt=2,$kindInt8=3,$kindInt16=4,$kindInt32=5,$kindInt64=6,$kindUint=7,$kindUint8=8,$kindUint16=9,$kindUint32=10,$kindUint64=11,$kindUintptr=12,$kindFloat32=13,$kindFloat64=14,$kindComplex64=15,$kindComplex128=16,$kindArray=17,$kindChan=18,$kindFunc=19,$kindInterface=20,$kindMap=21,$kindPtr=22,$kindSlice=23,$kindString=24,$kindStruct=25,$kindUnsafePointer=26,$methodSynthesizers=[],$addMethodSynthesizer=function(e){null!==$methodSynthesizers?$methodSynthesizers.push(e):e()},$synthesizeMethods=function(){$methodSynthesizers.forEach(function(e){e()}),$methodSynthesizers=null},$ifaceKeyFor=function(e){if(e===$ifaceNil)return"nil";var n=e.constructor;return n.string+"$"+n.keyFor(e.$val)},$identity=function(e){return e},$typeIDCounter=0,$idKey=function(e){return void 0===e.$id&&($idCounter++,e.$id=$idCounter),String(e.$id)},$newType=function(e,n,r,t,i,a,o){var $;switch(n){case $kindBool:case $kindInt:case $kindInt8:case $kindInt16:case $kindInt32:case $kindUint:case $kindUint8:case $kindUint16:case $kindUint32:case $kindUintptr:case $kindUnsafePointer:($=function(e){this.$val=e}).wrapped=!0,$.keyFor=$identity;break;case $kindString:($=function(e){this.$val=e}).wrapped=!0,$.keyFor=function(e){return"$"+e};break;case $kindFloat32:case $kindFloat64:($=function(e){this.$val=e}).wrapped=!0,$.keyFor=function(e){return $floatKey(e)};break;case $kindInt64:($=function(e,n){this.$high=e+Math.floor(Math.ceil(n)/4294967296)>>0,this.$low=n>>>0,this.$val=this}).keyFor=function(e){return e.$high+"$"+e.$low};break;case $kindUint64:($=function(e,n){this.$high=e+Math.floor(Math.ceil(n)/4294967296)>>>0,this.$low=n>>>0,this.$val=this}).keyFor=function(e){return e.$high+"$"+e.$low};break;case $kindComplex64:($=function(e,n){this.$real=$fround(e),this.$imag=$fround(n),this.$val=this}).keyFor=function(e){return e.$real+"$"+e.$imag};break;case $kindComplex128:($=function(e,n){this.$real=e,this.$imag=n,this.$val=this}).keyFor=function(e){return e.$real+"$"+e.$imag};break;case $kindArray:($=function(e){this.$val=e}).wrapped=!0,$.ptr=$newType(4,$kindPtr,"*"+r,!1,"",!1,function(e){this.$get=function(){return e},this.$set=function(e){$.copy(this,e)},this.$val=e}),$.init=function(e,n){$.elem=e,$.len=n,$.comparable=e.comparable,$.keyFor=function(n){return Array.prototype.join.call($mapArray(n,function(n){return String(e.keyFor(n)).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}),"$")},$.copy=function(n,r){$copyArray(n,r,0,0,r.length,e)},$.ptr.init($),Object.defineProperty($.ptr.nil,"nilCheck",{get:$throwNilPointerError})};break;case $kindChan:($=function(e){this.$val=e}).wrapped=!0,$.keyFor=$idKey,$.init=function(e,n,r){$.elem=e,$.sendOnly=n,$.recvOnly=r};break;case $kindFunc:($=function(e){this.$val=e}).wrapped=!0,$.init=function(e,n,r){$.params=e,$.results=n,$.variadic=r,$.comparable=!1};break;case $kindInterface:($={implementedBy:{},missingMethodFor:{}}).keyFor=$ifaceKeyFor,$.init=function(e){$.methods=e,e.forEach(function(e){$ifaceNil[e.prop]=$throwNilPointerError})};break;case $kindMap:($=function(e){this.$val=e}).wrapped=!0,$.init=function(e,n){$.key=e,$.elem=n,$.comparable=!1};break;case $kindPtr:($=o||function(e,n,r){this.$get=e,this.$set=n,this.$target=r,this.$val=this}).keyFor=$idKey,$.init=function(e){$.elem=e,$.wrapped=e.kind===$kindArray,$.nil=new $($throwNilPointerError,$throwNilPointerError)};break;case $kindSlice:($=function(e){e.constructor!==$.nativeArray&&(e=new $.nativeArray(e)),this.$array=e,this.$offset=0,this.$length=e.length,this.$capacity=e.length,this.$val=this}).init=function(e){$.elem=e,$.comparable=!1,$.nativeArray=$nativeArray(e.kind),$.nil=new $([])};break;case $kindStruct:($=function(e){this.$val=e}).wrapped=!0,$.ptr=$newType(4,$kindPtr,"*"+r,!1,i,a,o),$.ptr.elem=$,$.ptr.prototype.$get=function(){return this},$.ptr.prototype.$set=function(e){$.copy(this,e)},$.init=function(e,n){$.pkgPath=e,$.fields=n,n.forEach(function(e){e.typ.comparable||($.comparable=!1)}),$.keyFor=function(e){var r=e.$val;return $mapArray(n,function(e){return String(e.typ.keyFor(r[e.prop])).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}).join("$")},$.copy=function(e,r){for(var t=0;t0;){var a=[],o=[];t.forEach(function(e){if(!i[e.typ.string])switch(i[e.typ.string]=!0,e.typ.named&&(o=o.concat(e.typ.methods),e.indirect&&(o=o.concat($ptrType(e.typ).methods))),e.typ.kind){case $kindStruct:e.typ.fields.forEach(function(n){if(n.anonymous){var r=n.typ,t=r.kind===$kindPtr;a.push({typ:t?r.elem:r,indirect:e.indirect||t})}});break;case $kindInterface:o=o.concat(e.typ.methods)}}),o.forEach(function(e){void 0===n[e.name]&&(n[e.name]=e)}),t=a}return e.methodSetCache=[],Object.keys(n).sort().forEach(function(r){e.methodSetCache.push(n[r])}),e.methodSetCache},$Bool=$newType(1,$kindBool,"bool",!0,"",!1,null),$Int=$newType(4,$kindInt,"int",!0,"",!1,null),$Int8=$newType(1,$kindInt8,"int8",!0,"",!1,null),$Int16=$newType(2,$kindInt16,"int16",!0,"",!1,null),$Int32=$newType(4,$kindInt32,"int32",!0,"",!1,null),$Int64=$newType(8,$kindInt64,"int64",!0,"",!1,null),$Uint=$newType(4,$kindUint,"uint",!0,"",!1,null),$Uint8=$newType(1,$kindUint8,"uint8",!0,"",!1,null),$Uint16=$newType(2,$kindUint16,"uint16",!0,"",!1,null),$Uint32=$newType(4,$kindUint32,"uint32",!0,"",!1,null),$Uint64=$newType(8,$kindUint64,"uint64",!0,"",!1,null),$Uintptr=$newType(4,$kindUintptr,"uintptr",!0,"",!1,null),$Float32=$newType(4,$kindFloat32,"float32",!0,"",!1,null),$Float64=$newType(8,$kindFloat64,"float64",!0,"",!1,null),$Complex64=$newType(8,$kindComplex64,"complex64",!0,"",!1,null),$Complex128=$newType(16,$kindComplex128,"complex128",!0,"",!1,null),$String=$newType(8,$kindString,"string",!0,"",!1,null),$UnsafePointer=$newType(4,$kindUnsafePointer,"unsafe.Pointer",!0,"",!1,null),$nativeArray=function(e){switch(e){case $kindInt:return Int32Array;case $kindInt8:return Int8Array;case $kindInt16:return Int16Array;case $kindInt32:return Int32Array;case $kindUint:return Uint32Array;case $kindUint8:return Uint8Array;case $kindUint16:return Uint16Array;case $kindUint32:case $kindUintptr:return Uint32Array;case $kindFloat32:return Float32Array;case $kindFloat64:return Float64Array;default:return Array}},$toNativeArray=function(e,n){var r=$nativeArray(e);return r===Array?n:new r(n)},$arrayTypes={},$arrayType=function(e,n){var r=e.id+"$"+n,t=$arrayTypes[r];return void 0===t&&(t=$newType(12,$kindArray,"["+n+"]"+e.string,!1,"",!1,null),$arrayTypes[r]=t,t.init(e,n)),t},$chanType=function(e,n,r){var t=(r?"<-":"")+"chan"+(n?"<- ":" ")+e.string,i=n?"SendChan":r?"RecvChan":"Chan",a=e[i];return void 0===a&&(a=$newType(4,$kindChan,t,!1,"",!1,null),e[i]=a,a.init(e,n,r)),a},$Chan=function(e,n){(n<0||n>2147483647)&&$throwRuntimeError("makechan: size out of range"),this.$elem=e,this.$capacity=n,this.$buffer=[],this.$sendQueue=[],this.$recvQueue=[],this.$closed=!1},$chanNil=new $Chan(null,0);$chanNil.$sendQueue=$chanNil.$recvQueue={length:0,push:function(){},shift:function(){},indexOf:function(){return-1}};var $funcTypes={},$funcType=function(e,n,r){var t=$mapArray(e,function(e){return e.id}).join(",")+"$"+$mapArray(n,function(e){return e.id}).join(",")+"$"+r,i=$funcTypes[t];if(void 0===i){var a=$mapArray(e,function(e){return e.string});r&&(a[a.length-1]="..."+a[a.length-1].substr(2));var o="func("+a.join(", ")+")";1===n.length?o+=" "+n[0].string:n.length>1&&(o+=" ("+$mapArray(n,function(e){return e.string}).join(", ")+")"),i=$newType(4,$kindFunc,o,!1,"",!1,null),$funcTypes[t]=i,i.init(e,n,r)}return i},$interfaceTypes={},$interfaceType=function(e){var n=$mapArray(e,function(e){return e.pkg+","+e.name+","+e.typ.id}).join("$"),r=$interfaceTypes[n];if(void 0===r){var t="interface {}";0!==e.length&&(t="interface { "+$mapArray(e,function(e){return(""!==e.pkg?e.pkg+".":"")+e.name+e.typ.string.substr(4)}).join("; ")+" }"),r=$newType(8,$kindInterface,t,!1,"",!1,null),$interfaceTypes[n]=r,r.init(e)}return r},$emptyInterface=$interfaceType([]),$ifaceNil={},$error=$newType(8,$kindInterface,"error",!0,"",!1,null);$error.init([{prop:"Error",name:"Error",pkg:"",typ:$funcType([],[$String],!1)}]);var $panicValue,$jsObjectPtr,$jsErrorPtr,$mapTypes={},$mapType=function(e,n){var r=e.id+"$"+n.id,t=$mapTypes[r];return void 0===t&&(t=$newType(4,$kindMap,"map["+e.string+"]"+n.string,!1,"",!1,null),$mapTypes[r]=t,t.init(e,n)),t},$makeMap=function(e,n){for(var r={},t=0;t2147483647)&&$throwRuntimeError("makeslice: len out of range"),(r<0||r2147483647)&&$throwRuntimeError("makeslice: cap out of range");var t=new e.nativeArray(r);if(e.nativeArray===Array)for(var i=0;i=$curGoroutine.deferStack.length)throw n;if(null!==n){var t=null;try{$curGoroutine.deferStack.push(e),$panic(new $jsErrorPtr(n))}catch(e){t=e}return $curGoroutine.deferStack.pop(),void $callDeferred(e,t)}if(!$curGoroutine.asleep){$stackDepthOffset--;var i=$panicStackDepth,a=$panicValue,o=$curGoroutine.panicStack.pop();void 0!==o&&($panicStackDepth=$getStackDepth(),$panicValue=o);try{for(;;){if(null===e&&void 0===(e=$curGoroutine.deferStack[$curGoroutine.deferStack.length-1])){if($panicStackDepth=null,o.Object instanceof Error)throw o.Object;var $;throw $=o.constructor===$String?o.$val:void 0!==o.Error?o.Error():void 0!==o.String?o.String():o,new Error($)}var c=e.pop();if(void 0===c){if($curGoroutine.deferStack.pop(),void 0!==o){e=null;continue}return}var u=c[0].apply(c[2],c[1]);if(u&&void 0!==u.$blk){if(e.push([u.$blk,[],u]),r)throw null;return}if(void 0!==o&&null===$panicStackDepth)throw null}}finally{void 0!==o&&(null!==$panicStackDepth&&$curGoroutine.panicStack.push(o),$panicStackDepth=i,$panicValue=a),$stackDepthOffset++}}},$panic=function(e){$curGoroutine.panicStack.push(e),$callDeferred(null,null,!0)},$recover=function(){return null===$panicStackDepth||void 0!==$panicStackDepth&&$panicStackDepth!==$getStackDepth()-2?$ifaceNil:($panicStackDepth=null,$panicValue)},$throw=function(e){throw e},$noGoroutine={asleep:!1,exit:!1,deferStack:[],panicStack:[]},$curGoroutine=$noGoroutine,$totalGoroutines=0,$awakeGoroutines=0,$checkForDeadlock=!0,$mainFinished=!1,$go=function(e,n){$totalGoroutines++,$awakeGoroutines++;var r=function(){try{$curGoroutine=r;var t=e.apply(void 0,n);if(t&&void 0!==t.$blk)return e=function(){return t.$blk()},void(n=[]);r.exit=!0}catch(e){if(!r.exit)throw e}finally{$curGoroutine=$noGoroutine,r.exit&&($totalGoroutines--,r.asleep=!0),r.asleep&&($awakeGoroutines--,!$mainFinished&&0===$awakeGoroutines&&$checkForDeadlock&&(console.error("fatal error: all goroutines are asleep - deadlock!"),void 0!==$global.process&&$global.process.exit(2)))}};r.asleep=!1,r.exit=!1,r.deferStack=[],r.panicStack=[],$schedule(r)},$scheduled=[],$runScheduled=function(){try{for(var e;void 0!==(e=$scheduled.shift());)e()}finally{$scheduled.length>0&&setTimeout($runScheduled,0)}},$schedule=function(e){e.asleep&&(e.asleep=!1,$awakeGoroutines++),$scheduled.push(e),$curGoroutine===$noGoroutine&&$runScheduled()},$setTimeout=function(e,n){return $awakeGoroutines++,setTimeout(function(){$awakeGoroutines--,e()},n)},$block=function(){$curGoroutine===$noGoroutine&&$throwRuntimeError("cannot block in JavaScript callback, fix by wrapping code in goroutine"),$curGoroutine.asleep=!0},$send=function(e,n){e.$closed&&$throwRuntimeError("send on closed channel");var r=e.$recvQueue.shift();if(void 0===r){if(!(e.$buffer.length65535){var u=Math.floor((c-65536)/1024)+55296,l=(c-65536)%1024+56320;$+=String.fromCharCode(u,l)}else $+=String.fromCharCode(c)}return $;case $kindStruct:var s=$packages.time;if(void 0!==s&&e.constructor===s.Time.ptr){var f=$div64(e.UnixNano(),new $Int64(0,1e6));return new Date($flatten64(f))}var d={},p=function(e,n){if(n===$jsObjectPtr)return e;switch(n.kind){case $kindPtr:return e===n.nil?d:p(e.$get(),n.elem);case $kindStruct:var r=n.fields[0];return p(e[r.prop],r.typ);case $kindInterface:return p(e.$val,e.constructor);default:return d}},h=p(e,n);if(h!==d)return h;h={};for(i=0;i>24;case $kindInt16:return parseInt(e)<<16>>16;case $kindInt32:return parseInt(e)>>0;case $kindUint:return parseInt(e);case $kindUint8:return parseInt(e)<<24>>>24;case $kindUint16:return parseInt(e)<<16>>>16;case $kindUint32:case $kindUintptr:return parseInt(e)>>>0;case $kindInt64:case $kindUint64:return new n(0,e);case $kindFloat32:case $kindFloat64:return parseFloat(e);case $kindArray:return e.length!==n.len&&$throwRuntimeError("got array with wrong size from JavaScript native"),$mapArray(e,function(e){return $internalize(e,n.elem)});case $kindFunc:return function(){for(var t=[],i=0;i=128)return!1;return!0};` const prelude = `Error.stackTraceLimit = Infinity; From a0346cc37383b13c29a69bf5f4586499418c2eb5 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 15 Mar 2018 22:44:09 +0900 Subject: [PATCH 5/5] Address on reviews --- compiler/prelude/prelude.go | 2 +- tests/misc_test.go | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/compiler/prelude/prelude.go b/compiler/prelude/prelude.go index 8757cb913..0cae7d702 100644 --- a/compiler/prelude/prelude.go +++ b/compiler/prelude/prelude.go @@ -103,7 +103,7 @@ var $subslice = function(slice, low, high, max) { high = slice.$length; } if (max === undefined) { - max = slice.$capacity + max = slice.$capacity; } if (low < 0 || high < low || max < high || high > slice.$capacity || max > slice.$capacity) { $throwRuntimeError("slice bounds out of range"); diff --git a/tests/misc_test.go b/tests/misc_test.go index 648bbc3e1..d8b8885e1 100644 --- a/tests/misc_test.go +++ b/tests/misc_test.go @@ -597,6 +597,18 @@ func TestSliceOfString(t *testing.T) { print(str[0:10]) } +func TestSliceOutOfRange(t *testing.T) { + defer func() { + if err := recover(); err == nil || !strings.Contains(err.(error).Error(), "slice bounds out of range") { + t.Fail() + } + }() + + a := make([]byte, 4) + b := a[8:] + _ = b +} + type R struct{ v int } func (r R) Val() int { @@ -623,15 +635,3 @@ func TestTypeConversion(t *testing.T) { t.Fail() } } - -func TestSliceOutOfRange(t *testing.T) { - defer func() { - if err := recover(); err == nil || !strings.Contains(err.(error).Error(), "slice bounds out of range") { - t.Fail() - } - }() - - a := make([]byte, 4096) - b := a[8192:] - _ = b -}