dry.c.js 298 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497
  1. /*
  2. ==============================================================================
  3. LLVM Release License
  4. ==============================================================================
  5. University of Illinois/NCSA
  6. Open Source License
  7. Copyright (c) 2003, 2004, 2005 University of Illinois at Urbana-Champaign.
  8. All rights reserved.
  9. Developed by:
  10. LLVM Team
  11. University of Illinois at Urbana-Champaign
  12. http://llvm.org/
  13. Permission is hereby granted, free of charge, to any person obtaining a copy of
  14. this software and associated documentation files (the "Software"), to deal with
  15. the Software without restriction, including without limitation the rights to
  16. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  17. of the Software, and to permit persons to whom the Software is furnished to do
  18. so, subject to the following conditions:
  19. * Redistributions of source code must retain the above copyright notice,
  20. this list of conditions and the following disclaimers.
  21. * Redistributions in binary form must reproduce the above copyright notice,
  22. this list of conditions and the following disclaimers in the
  23. documentation and/or other materials provided with the distribution.
  24. * Neither the names of the LLVM Team, University of Illinois at
  25. Urbana-Champaign, nor the names of its contributors may be used to
  26. endorse or promote products derived from this Software without specific
  27. prior written permission.
  28. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  29. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  30. FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  31. CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  32. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  33. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
  34. SOFTWARE.
  35. Copyright (C) 2014 Apple Inc. All rights reserved.
  36. Redistribution and use in source and binary forms, with or without
  37. modification, are permitted provided that the following conditions
  38. are met:
  39. 1. Redistributions of source code must retain the above copyright
  40. notice, this list of conditions and the following disclaimer.
  41. 2. Redistributions in binary form must reproduce the above copyright
  42. notice, this list of conditions and the following disclaimer in the
  43. documentation and/or other materials provided with the distribution.
  44. THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  45. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  46. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  47. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  48. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  49. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  50. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  51. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  52. OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  53. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  54. //OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  55. */
  56. var referenceScore = 1699;
  57. if (typeof (WScript) === "undefined") {
  58. var WScript = {
  59. Echo: print
  60. }
  61. }
  62. var print = function () {};
  63. var performance = performance || {};
  64. performance.now = (function () {
  65. return performance.now ||
  66. performance.mozNow ||
  67. performance.msNow ||
  68. performance.oNow ||
  69. performance.webkitNow ||
  70. Date.now;
  71. })();
  72. function reportResult(score) {
  73. WScript.Echo("### SCORE: " + (100 * referenceScore / score));
  74. }
  75. var top = {};
  76. top.JetStream = {
  77. goodTime: performance.now,
  78. reportResult: reportResult
  79. };
  80. var __time_before = top.JetStream.goodTime();
  81. ////////////////////////////////////////////////////////////////////////////////
  82. // Test
  83. ////////////////////////////////////////////////////////////////////////////////
  84. // The Module object: Our interface to the outside world. We import
  85. // and export values on it, and do the work to get that through
  86. // closure compiler if necessary. There are various ways Module can be used:
  87. // 1. Not defined. We create it here
  88. // 2. A function parameter, function(Module) { ..generated code.. }
  89. // 3. pre-run appended it, var Module = {}; ..generated code..
  90. // 4. External script tag defines var Module.
  91. // We need to do an eval in order to handle the closure compiler
  92. // case, where this code here is minified but Module was defined
  93. // elsewhere (e.g. case 4 above). We also need to check if Module
  94. // already exists (e.g. case 3 above).
  95. // Note that if you want to run closure, and also to use Module
  96. // after the generated code, you will need to define var Module = {};
  97. // before the code. Then that object will be used in the code, and you
  98. // can continue to use Module afterwards as well.
  99. var Module;
  100. if (!Module) Module = eval('(function() { try { return Module || {} } catch(e) { return {} } })()');
  101. // Sometimes an existing Module object exists with properties
  102. // meant to overwrite the default module functionality. Here
  103. // we collect those properties and reapply _after_ we configure
  104. // the current environment's defaults to avoid having to be so
  105. // defensive during initialization.
  106. var moduleOverrides = {};
  107. for (var key in Module) {
  108. if (Module.hasOwnProperty(key)) {
  109. moduleOverrides[key] = Module[key];
  110. }
  111. }
  112. // The environment setup code below is customized to use Module.
  113. // *** Environment setup code ***
  114. var ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof require === 'function';
  115. var ENVIRONMENT_IS_WEB = typeof window === 'object';
  116. var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
  117. var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
  118. if (ENVIRONMENT_IS_NODE) {
  119. // Expose functionality in the same simple way that the shells work
  120. // Note that we pollute the global namespace here, otherwise we break in node
  121. if (!Module['print']) Module['print'] = function print(x) {
  122. process['stdout'].write(x + '\n');
  123. };
  124. if (!Module['printErr']) Module['printErr'] = function printErr(x) {
  125. process['stderr'].write(x + '\n');
  126. };
  127. var nodeFS = require('fs');
  128. var nodePath = require('path');
  129. Module['read'] = function read(filename, binary) {
  130. filename = nodePath['normalize'](filename);
  131. var ret = nodeFS['readFileSync'](filename);
  132. // The path is absolute if the normalized version is the same as the resolved.
  133. if (!ret && filename != nodePath['resolve'](filename)) {
  134. filename = path.join(__dirname, '..', 'src', filename);
  135. ret = nodeFS['readFileSync'](filename);
  136. }
  137. if (ret && !binary) ret = ret.toString();
  138. return ret;
  139. };
  140. Module['readBinary'] = function readBinary(filename) {
  141. return Module['read'](filename, true)
  142. };
  143. Module['load'] = function load(f) {
  144. globalEval(read(f));
  145. };
  146. Module['arguments'] = process['argv'].slice(2);
  147. module['exports'] = Module;
  148. } else if (ENVIRONMENT_IS_SHELL) {
  149. if (!Module['print']) Module['print'] = print;
  150. if (typeof printErr != 'undefined') Module['printErr'] = printErr; // not present in v8 or older sm
  151. if (typeof read != 'undefined') {
  152. Module['read'] = read;
  153. } else {
  154. Module['read'] = function read() {
  155. throw 'no read() available (jsc?)'
  156. };
  157. }
  158. Module['readBinary'] = function readBinary(f) {
  159. return read(f, 'binary');
  160. };
  161. if (typeof scriptArgs != 'undefined') {
  162. Module['arguments'] = scriptArgs;
  163. } else if (typeof arguments != 'undefined') {
  164. Module['arguments'] = arguments;
  165. }
  166. this['Module'] = Module;
  167. eval("if (typeof gc === 'function' && gc.toString().indexOf('[native code]') > 0) var gc = undefined"); // wipe out the SpiderMonkey shell 'gc' function, which can confuse closure (uses it as a minified name, and it is then initted to a non-falsey value unexpectedly)
  168. } else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
  169. Module['read'] = function read(url) {
  170. var xhr = new XMLHttpRequest();
  171. xhr.open('GET', url, false);
  172. xhr.send(null);
  173. return xhr.responseText;
  174. };
  175. if (typeof arguments != 'undefined') {
  176. Module['arguments'] = arguments;
  177. }
  178. if (typeof console !== 'undefined') {
  179. if (!Module['print']) Module['print'] = function print(x) {
  180. console.log(x);
  181. };
  182. if (!Module['printErr']) Module['printErr'] = function printErr(x) {
  183. console.log(x);
  184. };
  185. } else {
  186. // Probably a worker, and without console.log. We can do very little here...
  187. var TRY_USE_DUMP = false;
  188. if (!Module['print']) Module['print'] = (TRY_USE_DUMP && (typeof (dump) !== "undefined") ? (function (x) {
  189. dump(x);
  190. }) : (function (x) {
  191. // self.postMessage(x); // enable this if you want stdout to be sent as messages
  192. }));
  193. }
  194. if (ENVIRONMENT_IS_WEB) {
  195. this['Module'] = Module;
  196. } else {
  197. Module['load'] = importScripts;
  198. }
  199. } else {
  200. // Unreachable because SHELL is dependant on the others
  201. throw 'Unknown runtime environment. Where are we?';
  202. }
  203. function globalEval(x) {
  204. eval.call(null, x);
  205. }
  206. if (!Module['load'] == 'undefined' && Module['read']) {
  207. Module['load'] = function load(f) {
  208. globalEval(Module['read'](f));
  209. };
  210. }
  211. if (!Module['print']) {
  212. Module['print'] = function () {};
  213. }
  214. if (!Module['printErr']) {
  215. Module['printErr'] = Module['print'];
  216. }
  217. if (!Module['arguments']) {
  218. Module['arguments'] = [];
  219. }
  220. // *** Environment setup code ***
  221. // Closure helpers
  222. Module.print = Module['print'];
  223. Module.printErr = Module['printErr'];
  224. // Callbacks
  225. Module['preRun'] = [];
  226. Module['postRun'] = [];
  227. // Merge back in the overrides
  228. for (var key in moduleOverrides) {
  229. if (moduleOverrides.hasOwnProperty(key)) {
  230. Module[key] = moduleOverrides[key];
  231. }
  232. }
  233. // === Auto-generated preamble library stuff ===
  234. //========================================
  235. // Runtime code shared with compiler
  236. //========================================
  237. var Runtime = {
  238. stackSave: function () {
  239. return STACKTOP;
  240. },
  241. stackRestore: function (stackTop) {
  242. STACKTOP = stackTop;
  243. },
  244. forceAlign: function (target, quantum) {
  245. quantum = quantum || 4;
  246. if (quantum == 1) return target;
  247. if (isNumber(target) && isNumber(quantum)) {
  248. return Math.ceil(target / quantum) * quantum;
  249. } else if (isNumber(quantum) && isPowerOfTwo(quantum)) {
  250. return '(((' + target + ')+' + (quantum - 1) + ')&' + -quantum + ')';
  251. }
  252. return 'Math.ceil((' + target + ')/' + quantum + ')*' + quantum;
  253. },
  254. isNumberType: function (type) {
  255. return type in Runtime.INT_TYPES || type in Runtime.FLOAT_TYPES;
  256. },
  257. isPointerType: function isPointerType(type) {
  258. return type[type.length - 1] == '*';
  259. },
  260. isStructType: function isStructType(type) {
  261. if (isPointerType(type)) return false;
  262. if (isArrayType(type)) return true;
  263. if (/<?\{ ?[^}]* ?\}>?/.test(type)) return true; // { i32, i8 } etc. - anonymous struct types
  264. // See comment in isStructPointerType()
  265. return type[0] == '%';
  266. },
  267. INT_TYPES: {
  268. "i1": 0,
  269. "i8": 0,
  270. "i16": 0,
  271. "i32": 0,
  272. "i64": 0
  273. },
  274. FLOAT_TYPES: {
  275. "float": 0,
  276. "double": 0
  277. },
  278. or64: function (x, y) {
  279. var l = (x | 0) | (y | 0);
  280. var h = (Math.round(x / 4294967296) | Math.round(y / 4294967296)) * 4294967296;
  281. return l + h;
  282. },
  283. and64: function (x, y) {
  284. var l = (x | 0) & (y | 0);
  285. var h = (Math.round(x / 4294967296) & Math.round(y / 4294967296)) * 4294967296;
  286. return l + h;
  287. },
  288. xor64: function (x, y) {
  289. var l = (x | 0) ^ (y | 0);
  290. var h = (Math.round(x / 4294967296) ^ Math.round(y / 4294967296)) * 4294967296;
  291. return l + h;
  292. },
  293. getNativeTypeSize: function (type) {
  294. switch (type) {
  295. case 'i1':
  296. case 'i8':
  297. return 1;
  298. case 'i16':
  299. return 2;
  300. case 'i32':
  301. return 4;
  302. case 'i64':
  303. return 8;
  304. case 'float':
  305. return 4;
  306. case 'double':
  307. return 8;
  308. default:
  309. {
  310. if (type[type.length - 1] === '*') {
  311. return Runtime.QUANTUM_SIZE; // A pointer
  312. } else if (type[0] === 'i') {
  313. var bits = parseInt(type.substr(1));
  314. assert(bits % 8 === 0);
  315. return bits / 8;
  316. } else {
  317. return 0;
  318. }
  319. }
  320. }
  321. },
  322. getNativeFieldSize: function (type) {
  323. return Math.max(Runtime.getNativeTypeSize(type), Runtime.QUANTUM_SIZE);
  324. },
  325. dedup: function dedup(items, ident) {
  326. var seen = {};
  327. if (ident) {
  328. return items.filter(function (item) {
  329. if (seen[item[ident]]) return false;
  330. seen[item[ident]] = true;
  331. return true;
  332. });
  333. } else {
  334. return items.filter(function (item) {
  335. if (seen[item]) return false;
  336. seen[item] = true;
  337. return true;
  338. });
  339. }
  340. },
  341. set: function set() {
  342. var args = typeof arguments[0] === 'object' ? arguments[0] : arguments;
  343. var ret = {};
  344. for (var i = 0; i < args.length; i++) {
  345. ret[args[i]] = 0;
  346. }
  347. return ret;
  348. },
  349. STACK_ALIGN: 8,
  350. getAlignSize: function (type, size, vararg) {
  351. // we align i64s and doubles on 64-bit boundaries, unlike x86
  352. if (!vararg && (type == 'i64' || type == 'double')) return 8;
  353. if (!type) return Math.min(size, 8); // align structures internally to 64 bits
  354. return Math.min(size || (type ? Runtime.getNativeFieldSize(type) : 0), Runtime.QUANTUM_SIZE);
  355. },
  356. calculateStructAlignment: function calculateStructAlignment(type) {
  357. type.flatSize = 0;
  358. type.alignSize = 0;
  359. var diffs = [];
  360. var prev = -1;
  361. var index = 0;
  362. type.flatIndexes = type.fields.map(function (field) {
  363. index++;
  364. var size, alignSize;
  365. if (Runtime.isNumberType(field) || Runtime.isPointerType(field)) {
  366. size = Runtime.getNativeTypeSize(field); // pack char; char; in structs, also char[X]s.
  367. alignSize = Runtime.getAlignSize(field, size);
  368. } else if (Runtime.isStructType(field)) {
  369. if (field[1] === '0') {
  370. // this is [0 x something]. When inside another structure like here, it must be at the end,
  371. // and it adds no size
  372. // XXX this happens in java-nbody for example... assert(index === type.fields.length, 'zero-length in the middle!');
  373. size = 0;
  374. if (Types.types[field]) {
  375. alignSize = Runtime.getAlignSize(null, Types.types[field].alignSize);
  376. } else {
  377. alignSize = type.alignSize || QUANTUM_SIZE;
  378. }
  379. } else {
  380. size = Types.types[field].flatSize;
  381. alignSize = Runtime.getAlignSize(null, Types.types[field].alignSize);
  382. }
  383. } else if (field[0] == 'b') {
  384. // bN, large number field, like a [N x i8]
  385. size = field.substr(1) | 0;
  386. alignSize = 1;
  387. } else if (field[0] === '<') {
  388. // vector type
  389. size = alignSize = Types.types[field].flatSize; // fully aligned
  390. } else if (field[0] === 'i') {
  391. // illegal integer field, that could not be legalized because it is an internal structure field
  392. // it is ok to have such fields, if we just use them as markers of field size and nothing more complex
  393. size = alignSize = parseInt(field.substr(1)) / 8;
  394. assert(size % 1 === 0, 'cannot handle non-byte-size field ' + field);
  395. } else {
  396. assert(false, 'invalid type for calculateStructAlignment');
  397. }
  398. if (type.packed) alignSize = 1;
  399. type.alignSize = Math.max(type.alignSize, alignSize);
  400. var curr = Runtime.alignMemory(type.flatSize, alignSize); // if necessary, place this on aligned memory
  401. type.flatSize = curr + size;
  402. if (prev >= 0) {
  403. diffs.push(curr - prev);
  404. }
  405. prev = curr;
  406. return curr;
  407. });
  408. if (type.name_ && type.name_[0] === '[') {
  409. // arrays have 2 elements, so we get the proper difference. then we scale here. that way we avoid
  410. // allocating a potentially huge array for [999999 x i8] etc.
  411. type.flatSize = parseInt(type.name_.substr(1)) * type.flatSize / 2;
  412. }
  413. type.flatSize = Runtime.alignMemory(type.flatSize, type.alignSize);
  414. if (diffs.length == 0) {
  415. type.flatFactor = type.flatSize;
  416. } else if (Runtime.dedup(diffs).length == 1) {
  417. type.flatFactor = diffs[0];
  418. }
  419. type.needsFlattening = (type.flatFactor != 1);
  420. return type.flatIndexes;
  421. },
  422. generateStructInfo: function (struct, typeName, offset) {
  423. var type, alignment;
  424. if (typeName) {
  425. offset = offset || 0;
  426. type = (typeof Types === 'undefined' ? Runtime.typeInfo : Types.types)[typeName];
  427. if (!type) return null;
  428. if (type.fields.length != struct.length) {
  429. printErr('Number of named fields must match the type for ' + typeName + ': possibly duplicate struct names. Cannot return structInfo');
  430. return null;
  431. }
  432. alignment = type.flatIndexes;
  433. } else {
  434. var type = {
  435. fields: struct.map(function (item) {
  436. return item[0]
  437. })
  438. };
  439. alignment = Runtime.calculateStructAlignment(type);
  440. }
  441. var ret = {
  442. __size__: type.flatSize
  443. };
  444. if (typeName) {
  445. struct.forEach(function (item, i) {
  446. if (typeof item === 'string') {
  447. ret[item] = alignment[i] + offset;
  448. } else {
  449. // embedded struct
  450. var key;
  451. for (var k in item) key = k;
  452. ret[key] = Runtime.generateStructInfo(item[key], type.fields[i], alignment[i]);
  453. }
  454. });
  455. } else {
  456. struct.forEach(function (item, i) {
  457. ret[item[1]] = alignment[i];
  458. });
  459. }
  460. return ret;
  461. },
  462. dynCall: function (sig, ptr, args) {
  463. if (args && args.length) {
  464. if (!args.splice) args = Array.prototype.slice.call(args);
  465. args.splice(0, 0, ptr);
  466. return Module['dynCall_' + sig].apply(null, args);
  467. } else {
  468. return Module['dynCall_' + sig].call(null, ptr);
  469. }
  470. },
  471. functionPointers: [],
  472. addFunction: function (func) {
  473. for (var i = 0; i < Runtime.functionPointers.length; i++) {
  474. if (!Runtime.functionPointers[i]) {
  475. Runtime.functionPointers[i] = func;
  476. return 2 * (1 + i);
  477. }
  478. }
  479. throw 'Finished up all reserved function pointers. Use a higher value for RESERVED_FUNCTION_POINTERS.';
  480. },
  481. removeFunction: function (index) {
  482. Runtime.functionPointers[(index - 2) / 2] = null;
  483. },
  484. getAsmConst: function (code, numArgs) {
  485. // code is a constant string on the heap, so we can cache these
  486. if (!Runtime.asmConstCache) Runtime.asmConstCache = {};
  487. var func = Runtime.asmConstCache[code];
  488. if (func) return func;
  489. var args = [];
  490. for (var i = 0; i < numArgs; i++) {
  491. args.push(String.fromCharCode(36) + i); // $0, $1 etc
  492. }
  493. code = Pointer_stringify(code);
  494. if (code[0] === '"') {
  495. // tolerate EM_ASM("..code..") even though EM_ASM(..code..) is correct
  496. if (code.indexOf('"', 1) === code.length - 1) {
  497. code = code.substr(1, code.length - 2);
  498. } else {
  499. // something invalid happened, e.g. EM_ASM("..code($0)..", input)
  500. abort('invalid EM_ASM input |' + code + '|. Please use EM_ASM(..code..) (no quotes) or EM_ASM({ ..code($0).. }, input) (to input values)');
  501. }
  502. }
  503. return Runtime.asmConstCache[code] = eval('(function(' + args.join(',') + '){ ' + code + ' })'); // new Function does not allow upvars in node
  504. },
  505. warnOnce: function (text) {
  506. if (!Runtime.warnOnce.shown) Runtime.warnOnce.shown = {};
  507. if (!Runtime.warnOnce.shown[text]) {
  508. Runtime.warnOnce.shown[text] = 1;
  509. Module.printErr(text);
  510. }
  511. },
  512. funcWrappers: {},
  513. getFuncWrapper: function (func, sig) {
  514. assert(sig);
  515. if (!Runtime.funcWrappers[func]) {
  516. Runtime.funcWrappers[func] = function dynCall_wrapper() {
  517. return Runtime.dynCall(sig, func, arguments);
  518. };
  519. }
  520. return Runtime.funcWrappers[func];
  521. },
  522. UTF8Processor: function () {
  523. var buffer = [];
  524. var needed = 0;
  525. this.processCChar = function (code) {
  526. code = code & 0xFF;
  527. if (buffer.length == 0) {
  528. if ((code & 0x80) == 0x00) { // 0xxxxxxx
  529. return String.fromCharCode(code);
  530. }
  531. buffer.push(code);
  532. if ((code & 0xE0) == 0xC0) { // 110xxxxx
  533. needed = 1;
  534. } else if ((code & 0xF0) == 0xE0) { // 1110xxxx
  535. needed = 2;
  536. } else { // 11110xxx
  537. needed = 3;
  538. }
  539. return '';
  540. }
  541. if (needed) {
  542. buffer.push(code);
  543. needed--;
  544. if (needed > 0) return '';
  545. }
  546. var c1 = buffer[0];
  547. var c2 = buffer[1];
  548. var c3 = buffer[2];
  549. var c4 = buffer[3];
  550. var ret;
  551. if (buffer.length == 2) {
  552. ret = String.fromCharCode(((c1 & 0x1F) << 6) | (c2 & 0x3F));
  553. } else if (buffer.length == 3) {
  554. ret = String.fromCharCode(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
  555. } else {
  556. // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  557. var codePoint = ((c1 & 0x07) << 18) | ((c2 & 0x3F) << 12) |
  558. ((c3 & 0x3F) << 6) | (c4 & 0x3F);
  559. ret = String.fromCharCode(
  560. Math.floor((codePoint - 0x10000) / 0x400) + 0xD800, (codePoint - 0x10000) % 0x400 + 0xDC00);
  561. }
  562. buffer.length = 0;
  563. return ret;
  564. }
  565. this.processJSString = function processJSString(string) {
  566. string = unescape(encodeURIComponent(string));
  567. var ret = [];
  568. for (var i = 0; i < string.length; i++) {
  569. ret.push(string.charCodeAt(i));
  570. }
  571. return ret;
  572. }
  573. },
  574. getCompilerSetting: function (name) {
  575. throw 'You must build with -s RETAIN_COMPILER_SETTINGS=1 for Runtime.getCompilerSetting or emscripten_get_compiler_setting to work';
  576. },
  577. stackAlloc: function (size) {
  578. var ret = STACKTOP;
  579. STACKTOP = (STACKTOP + size) | 0;
  580. STACKTOP = (((STACKTOP) + 7) & -8);
  581. return ret;
  582. },
  583. staticAlloc: function (size) {
  584. var ret = STATICTOP;
  585. STATICTOP = (STATICTOP + size) | 0;
  586. STATICTOP = (((STATICTOP) + 7) & -8);
  587. return ret;
  588. },
  589. dynamicAlloc: function (size) {
  590. var ret = DYNAMICTOP;
  591. DYNAMICTOP = (DYNAMICTOP + size) | 0;
  592. DYNAMICTOP = (((DYNAMICTOP) + 7) & -8);
  593. if (DYNAMICTOP >= TOTAL_MEMORY) enlargeMemory();;
  594. return ret;
  595. },
  596. alignMemory: function (size, quantum) {
  597. var ret = size = Math.ceil((size) / (quantum ? quantum : 8)) * (quantum ? quantum : 8);
  598. return ret;
  599. },
  600. makeBigInt: function (low, high, unsigned) {
  601. var ret = (unsigned ? ((+((low >>> 0))) + ((+((high >>> 0))) * (+4294967296))) : ((+((low >>> 0))) + ((+((high | 0))) * (+4294967296))));
  602. return ret;
  603. },
  604. GLOBAL_BASE: 8,
  605. QUANTUM_SIZE: 4,
  606. __dummy__: 0
  607. }
  608. Module['Runtime'] = Runtime;
  609. //========================================
  610. // Runtime essentials
  611. //========================================
  612. var __THREW__ = 0; // Used in checking for thrown exceptions.
  613. var ABORT = false; // whether we are quitting the application. no code should run after this. set in exit() and abort()
  614. var EXITSTATUS = 0;
  615. var undef = 0;
  616. // tempInt is used for 32-bit signed values or smaller. tempBigInt is used
  617. // for 32-bit unsigned values or more than 32 bits. TODO: audit all uses of tempInt
  618. var tempValue, tempInt, tempBigInt, tempInt2, tempBigInt2, tempPair, tempBigIntI, tempBigIntR, tempBigIntS, tempBigIntP, tempBigIntD, tempDouble, tempFloat;
  619. var tempI64, tempI64b;
  620. var tempRet0, tempRet1, tempRet2, tempRet3, tempRet4, tempRet5, tempRet6, tempRet7, tempRet8, tempRet9;
  621. function assert(condition, text) {
  622. if (!condition) {
  623. abort('Assertion failed: ' + text);
  624. }
  625. }
  626. var globalScope = this;
  627. // C calling interface. A convenient way to call C functions (in C files, or
  628. // defined with extern "C").
  629. //
  630. // Note: LLVM optimizations can inline and remove functions, after which you will not be
  631. // able to call them. Closure can also do so. To avoid that, add your function to
  632. // the exports using something like
  633. //
  634. // -s EXPORTED_FUNCTIONS='["_main", "_myfunc"]'
  635. //
  636. // @param ident The name of the C function (note that C++ functions will be name-mangled - use extern "C")
  637. // @param returnType The return type of the function, one of the JS types 'number', 'string' or 'array' (use 'number' for any C pointer, and
  638. // 'array' for JavaScript arrays and typed arrays; note that arrays are 8-bit).
  639. // @param argTypes An array of the types of arguments for the function (if there are no arguments, this can be ommitted). Types are as in returnType,
  640. // except that 'array' is not possible (there is no way for us to know the length of the array)
  641. // @param args An array of the arguments to the function, as native JS values (as in returnType)
  642. // Note that string arguments will be stored on the stack (the JS string will become a C string on the stack).
  643. // @return The return value, as a native JS value (as in returnType)
  644. function ccall(ident, returnType, argTypes, args) {
  645. return ccallFunc(getCFunc(ident), returnType, argTypes, args);
  646. }
  647. Module["ccall"] = ccall;
  648. // Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
  649. function getCFunc(ident) {
  650. try {
  651. var func = Module['_' + ident]; // closure exported function
  652. if (!func) func = eval('_' + ident); // explicit lookup
  653. } catch (e) {}
  654. assert(func, 'Cannot call unknown function ' + ident + ' (perhaps LLVM optimizations or closure removed it?)');
  655. return func;
  656. }
  657. // Internal function that does a C call using a function, not an identifier
  658. function ccallFunc(func, returnType, argTypes, args) {
  659. var stack = 0;
  660. function toC(value, type) {
  661. if (type == 'string') {
  662. if (value === null || value === undefined || value === 0) return 0; // null string
  663. value = intArrayFromString(value);
  664. type = 'array';
  665. }
  666. if (type == 'array') {
  667. if (!stack) stack = Runtime.stackSave();
  668. var ret = Runtime.stackAlloc(value.length);
  669. writeArrayToMemory(value, ret);
  670. return ret;
  671. }
  672. return value;
  673. }
  674. function fromC(value, type) {
  675. if (type == 'string') {
  676. return Pointer_stringify(value);
  677. }
  678. assert(type != 'array');
  679. return value;
  680. }
  681. var i = 0;
  682. var cArgs = args ? args.map(function (arg) {
  683. return toC(arg, argTypes[i++]);
  684. }) : [];
  685. var ret = fromC(func.apply(null, cArgs), returnType);
  686. if (stack) Runtime.stackRestore(stack);
  687. return ret;
  688. }
  689. // Returns a native JS wrapper for a C function. This is similar to ccall, but
  690. // returns a function you can call repeatedly in a normal way. For example:
  691. //
  692. // var my_function = cwrap('my_c_function', 'number', ['number', 'number']);
  693. // alert(my_function(5, 22));
  694. // alert(my_function(99, 12));
  695. //
  696. function cwrap(ident, returnType, argTypes) {
  697. var func = getCFunc(ident);
  698. return function () {
  699. return ccallFunc(func, returnType, argTypes, Array.prototype.slice.call(arguments));
  700. }
  701. }
  702. Module["cwrap"] = cwrap;
  703. // Sets a value in memory in a dynamic way at run-time. Uses the
  704. // type data. This is the same as makeSetValue, except that
  705. // makeSetValue is done at compile-time and generates the needed
  706. // code then, whereas this function picks the right code at
  707. // run-time.
  708. // Note that setValue and getValue only do *aligned* writes and reads!
  709. // Note that ccall uses JS types as for defining types, while setValue and
  710. // getValue need LLVM types ('i8', 'i32') - this is a lower-level operation
  711. function setValue(ptr, value, type, noSafe) {
  712. type = type || 'i8';
  713. if (type.charAt(type.length - 1) === '*') type = 'i32'; // pointers are 32-bit
  714. switch (type) {
  715. case 'i1':
  716. HEAP8[(ptr)] = value;
  717. break;
  718. case 'i8':
  719. HEAP8[(ptr)] = value;
  720. break;
  721. case 'i16':
  722. HEAP16[((ptr) >> 1)] = value;
  723. break;
  724. case 'i32':
  725. HEAP32[((ptr) >> 2)] = value;
  726. break;
  727. case 'i64':
  728. (tempI64 = [value >>> 0, (tempDouble = value, (+(Math_abs(tempDouble))) >= (+1) ? (tempDouble > (+0) ? ((Math_min((+(Math_floor((tempDouble) / (+4294967296)))), (+4294967295))) | 0) >>> 0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / (+4294967296)))))) >>> 0) : 0)], HEAP32[((ptr) >> 2)] = tempI64[0], HEAP32[(((ptr) + (4)) >> 2)] = tempI64[1]);
  729. break;
  730. case 'float':
  731. HEAPF32[((ptr) >> 2)] = value;
  732. break;
  733. case 'double':
  734. HEAPF64[((ptr) >> 3)] = value;
  735. break;
  736. default:
  737. abort('invalid type for setValue: ' + type);
  738. }
  739. }
  740. Module['setValue'] = setValue;
  741. // Parallel to setValue.
  742. function getValue(ptr, type, noSafe) {
  743. type = type || 'i8';
  744. if (type.charAt(type.length - 1) === '*') type = 'i32'; // pointers are 32-bit
  745. switch (type) {
  746. case 'i1':
  747. return HEAP8[(ptr)];
  748. case 'i8':
  749. return HEAP8[(ptr)];
  750. case 'i16':
  751. return HEAP16[((ptr) >> 1)];
  752. case 'i32':
  753. return HEAP32[((ptr) >> 2)];
  754. case 'i64':
  755. return HEAP32[((ptr) >> 2)];
  756. case 'float':
  757. return HEAPF32[((ptr) >> 2)];
  758. case 'double':
  759. return HEAPF64[((ptr) >> 3)];
  760. default:
  761. abort('invalid type for setValue: ' + type);
  762. }
  763. return null;
  764. }
  765. Module['getValue'] = getValue;
  766. var ALLOC_NORMAL = 0; // Tries to use _malloc()
  767. var ALLOC_STACK = 1; // Lives for the duration of the current function call
  768. var ALLOC_STATIC = 2; // Cannot be freed
  769. var ALLOC_DYNAMIC = 3; // Cannot be freed except through sbrk
  770. var ALLOC_NONE = 4; // Do not allocate
  771. Module['ALLOC_NORMAL'] = ALLOC_NORMAL;
  772. Module['ALLOC_STACK'] = ALLOC_STACK;
  773. Module['ALLOC_STATIC'] = ALLOC_STATIC;
  774. Module['ALLOC_DYNAMIC'] = ALLOC_DYNAMIC;
  775. Module['ALLOC_NONE'] = ALLOC_NONE;
  776. // allocate(): This is for internal use. You can use it yourself as well, but the interface
  777. // is a little tricky (see docs right below). The reason is that it is optimized
  778. // for multiple syntaxes to save space in generated code. So you should
  779. // normally not use allocate(), and instead allocate memory using _malloc(),
  780. // initialize it with setValue(), and so forth.
  781. // @slab: An array of data, or a number. If a number, then the size of the block to allocate,
  782. // in *bytes* (note that this is sometimes confusing: the next parameter does not
  783. // affect this!)
  784. // @types: Either an array of types, one for each byte (or 0 if no type at that position),
  785. // or a single type which is used for the entire block. This only matters if there
  786. // is initial data - if @slab is a number, then this does not matter at all and is
  787. // ignored.
  788. // @allocator: How to allocate memory, see ALLOC_*
  789. function allocate(slab, types, allocator, ptr) {
  790. var zeroinit, size;
  791. if (typeof slab === 'number') {
  792. zeroinit = true;
  793. size = slab;
  794. } else {
  795. zeroinit = false;
  796. size = slab.length;
  797. }
  798. var singleType = typeof types === 'string' ? types : null;
  799. var ret;
  800. if (allocator == ALLOC_NONE) {
  801. ret = ptr;
  802. } else {
  803. ret = [_malloc, Runtime.stackAlloc, Runtime.staticAlloc, Runtime.dynamicAlloc][allocator === undefined ? ALLOC_STATIC : allocator](Math.max(size, singleType ? 1 : types.length));
  804. }
  805. if (zeroinit) {
  806. var ptr = ret,
  807. stop;
  808. assert((ret & 3) == 0);
  809. stop = ret + (size & ~3);
  810. for (; ptr < stop; ptr += 4) {
  811. HEAP32[((ptr) >> 2)] = 0;
  812. }
  813. stop = ret + size;
  814. while (ptr < stop) {
  815. HEAP8[((ptr++) | 0)] = 0;
  816. }
  817. return ret;
  818. }
  819. if (singleType === 'i8') {
  820. if (slab.subarray || slab.slice) {
  821. HEAPU8.set(slab, ret);
  822. } else {
  823. HEAPU8.set(new Uint8Array(slab), ret);
  824. }
  825. return ret;
  826. }
  827. var i = 0,
  828. type, typeSize, previousType;
  829. while (i < size) {
  830. var curr = slab[i];
  831. if (typeof curr === 'function') {
  832. curr = Runtime.getFunctionIndex(curr);
  833. }
  834. type = singleType || types[i];
  835. if (type === 0) {
  836. i++;
  837. continue;
  838. }
  839. if (type == 'i64') type = 'i32'; // special case: we have one i32 here, and one i32 later
  840. setValue(ret + i, curr, type);
  841. // no need to look up size unless type changes, so cache it
  842. if (previousType !== type) {
  843. typeSize = Runtime.getNativeTypeSize(type);
  844. previousType = type;
  845. }
  846. i += typeSize;
  847. }
  848. return ret;
  849. }
  850. Module['allocate'] = allocate;
  851. function Pointer_stringify(ptr, /* optional */ length) {
  852. // TODO: use TextDecoder
  853. // Find the length, and check for UTF while doing so
  854. var hasUtf = false;
  855. var t;
  856. var i = 0;
  857. while (1) {
  858. t = HEAPU8[(((ptr) + (i)) | 0)];
  859. if (t >= 128) hasUtf = true;
  860. else if (t == 0 && !length) break;
  861. i++;
  862. if (length && i == length) break;
  863. }
  864. if (!length) length = i;
  865. var ret = '';
  866. if (!hasUtf) {
  867. var MAX_CHUNK = 1024; // split up into chunks, because .apply on a huge string can overflow the stack
  868. var curr;
  869. while (length > 0) {
  870. curr = String.fromCharCode.apply(String, HEAPU8.subarray(ptr, ptr + Math.min(length, MAX_CHUNK)));
  871. ret = ret ? ret + curr : curr;
  872. ptr += MAX_CHUNK;
  873. length -= MAX_CHUNK;
  874. }
  875. return ret;
  876. }
  877. var utf8 = new Runtime.UTF8Processor();
  878. for (i = 0; i < length; i++) {
  879. t = HEAPU8[(((ptr) + (i)) | 0)];
  880. ret += utf8.processCChar(t);
  881. }
  882. return ret;
  883. }
  884. Module['Pointer_stringify'] = Pointer_stringify;
  885. // Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns
  886. // a copy of that string as a Javascript String object.
  887. function UTF16ToString(ptr) {
  888. var i = 0;
  889. var str = '';
  890. while (1) {
  891. var codeUnit = HEAP16[(((ptr) + (i * 2)) >> 1)];
  892. if (codeUnit == 0)
  893. return str;
  894. ++i;
  895. // fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through.
  896. str += String.fromCharCode(codeUnit);
  897. }
  898. }
  899. Module['UTF16ToString'] = UTF16ToString;
  900. // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
  901. // null-terminated and encoded in UTF16LE form. The copy will require at most (str.length*2+1)*2 bytes of space in the HEAP.
  902. function stringToUTF16(str, outPtr) {
  903. for (var i = 0; i < str.length; ++i) {
  904. // charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP.
  905. var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
  906. HEAP16[(((outPtr) + (i * 2)) >> 1)] = codeUnit;
  907. }
  908. // Null-terminate the pointer to the HEAP.
  909. HEAP16[(((outPtr) + (str.length * 2)) >> 1)] = 0;
  910. }
  911. Module['stringToUTF16'] = stringToUTF16;
  912. // Given a pointer 'ptr' to a null-terminated UTF32LE-encoded string in the emscripten HEAP, returns
  913. // a copy of that string as a Javascript String object.
  914. function UTF32ToString(ptr) {
  915. var i = 0;
  916. var str = '';
  917. while (1) {
  918. var utf32 = HEAP32[(((ptr) + (i * 4)) >> 2)];
  919. if (utf32 == 0)
  920. return str;
  921. ++i;
  922. // Gotcha: fromCharCode constructs a character from a UTF-16 encoded code (pair), not from a Unicode code point! So encode the code point to UTF-16 for constructing.
  923. if (utf32 >= 0x10000) {
  924. var ch = utf32 - 0x10000;
  925. str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
  926. } else {
  927. str += String.fromCharCode(utf32);
  928. }
  929. }
  930. }
  931. Module['UTF32ToString'] = UTF32ToString;
  932. // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
  933. // null-terminated and encoded in UTF32LE form. The copy will require at most (str.length+1)*4 bytes of space in the HEAP,
  934. // but can use less, since str.length does not return the number of characters in the string, but the number of UTF-16 code units in the string.
  935. function stringToUTF32(str, outPtr) {
  936. var iChar = 0;
  937. for (var iCodeUnit = 0; iCodeUnit < str.length; ++iCodeUnit) {
  938. // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap.
  939. var codeUnit = str.charCodeAt(iCodeUnit); // possibly a lead surrogate
  940. if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) {
  941. var trailSurrogate = str.charCodeAt(++iCodeUnit);
  942. codeUnit = 0x10000 + ((codeUnit & 0x3FF) << 10) | (trailSurrogate & 0x3FF);
  943. }
  944. HEAP32[(((outPtr) + (iChar * 4)) >> 2)] = codeUnit;
  945. ++iChar;
  946. }
  947. // Null-terminate the pointer to the HEAP.
  948. HEAP32[(((outPtr) + (iChar * 4)) >> 2)] = 0;
  949. }
  950. Module['stringToUTF32'] = stringToUTF32;
  951. function demangle(func) {
  952. var i = 3;
  953. // params, etc.
  954. var basicTypes = {
  955. 'v': 'void',
  956. 'b': 'bool',
  957. 'c': 'char',
  958. 's': 'short',
  959. 'i': 'int',
  960. 'l': 'long',
  961. 'f': 'float',
  962. 'd': 'double',
  963. 'w': 'wchar_t',
  964. 'a': 'signed char',
  965. 'h': 'unsigned char',
  966. 't': 'unsigned short',
  967. 'j': 'unsigned int',
  968. 'm': 'unsigned long',
  969. 'x': 'long long',
  970. 'y': 'unsigned long long',
  971. 'z': '...'
  972. };
  973. var subs = [];
  974. var first = true;
  975. function dump(x) {
  976. //return;
  977. if (x) Module.print(x);
  978. Module.print(func);
  979. var pre = '';
  980. for (var a = 0; a < i; a++) pre += ' ';
  981. Module.print(pre + '^');
  982. }
  983. function parseNested() {
  984. i++;
  985. if (func[i] === 'K') i++; // ignore const
  986. var parts = [];
  987. while (func[i] !== 'E') {
  988. if (func[i] === 'S') { // substitution
  989. i++;
  990. var next = func.indexOf('_', i);
  991. var num = func.substring(i, next) || 0;
  992. parts.push(subs[num] || '?');
  993. i = next + 1;
  994. continue;
  995. }
  996. if (func[i] === 'C') { // constructor
  997. parts.push(parts[parts.length - 1]);
  998. i += 2;
  999. continue;
  1000. }
  1001. var size = parseInt(func.substr(i));
  1002. var pre = size.toString().length;
  1003. if (!size || !pre) {
  1004. i--;
  1005. break;
  1006. } // counter i++ below us
  1007. var curr = func.substr(i + pre, size);
  1008. parts.push(curr);
  1009. subs.push(curr);
  1010. i += pre + size;
  1011. }
  1012. i++; // skip E
  1013. return parts;
  1014. }
  1015. function parse(rawList, limit, allowVoid) { // main parser
  1016. limit = limit || Infinity;
  1017. var ret = '',
  1018. list = [];
  1019. function flushList() {
  1020. return '(' + list.join(', ') + ')';
  1021. }
  1022. var name;
  1023. if (func[i] === 'N') {
  1024. // namespaced N-E
  1025. name = parseNested().join('::');
  1026. limit--;
  1027. if (limit === 0) return rawList ? [name] : name;
  1028. } else {
  1029. // not namespaced
  1030. if (func[i] === 'K' || (first && func[i] === 'L')) i++; // ignore const and first 'L'
  1031. var size = parseInt(func.substr(i));
  1032. if (size) {
  1033. var pre = size.toString().length;
  1034. name = func.substr(i + pre, size);
  1035. i += pre + size;
  1036. }
  1037. }
  1038. first = false;
  1039. if (func[i] === 'I') {
  1040. i++;
  1041. var iList = parse(true);
  1042. var iRet = parse(true, 1, true);
  1043. ret += iRet[0] + ' ' + name + '<' + iList.join(', ') + '>';
  1044. } else {
  1045. ret = name;
  1046. }
  1047. paramLoop: while (i < func.length && limit-- > 0) {
  1048. //dump('paramLoop');
  1049. var c = func[i++];
  1050. if (c in basicTypes) {
  1051. list.push(basicTypes[c]);
  1052. } else {
  1053. switch (c) {
  1054. case 'P':
  1055. list.push(parse(true, 1, true)[0] + '*');
  1056. break; // pointer
  1057. case 'R':
  1058. list.push(parse(true, 1, true)[0] + '&');
  1059. break; // reference
  1060. case 'L':
  1061. { // literal
  1062. i++; // skip basic type
  1063. var end = func.indexOf('E', i);
  1064. var size = end - i;
  1065. list.push(func.substr(i, size));
  1066. i += size + 2; // size + 'EE'
  1067. break;
  1068. }
  1069. case 'A':
  1070. { // array
  1071. var size = parseInt(func.substr(i));
  1072. i += size.toString().length;
  1073. if (func[i] !== '_') throw '?';
  1074. i++; // skip _
  1075. list.push(parse(true, 1, true)[0] + ' [' + size + ']');
  1076. break;
  1077. }
  1078. case 'E':
  1079. break paramLoop;
  1080. default:
  1081. ret += '?' + c;
  1082. break paramLoop;
  1083. }
  1084. }
  1085. }
  1086. if (!allowVoid && list.length === 1 && list[0] === 'void') list = []; // avoid (void)
  1087. return rawList ? list : ret + flushList();
  1088. }
  1089. try {
  1090. // Special-case the entry point, since its name differs from other name mangling.
  1091. if (func == 'Object._main' || func == '_main') {
  1092. return 'main()';
  1093. }
  1094. if (typeof func === 'number') func = Pointer_stringify(func);
  1095. if (func[0] !== '_') return func;
  1096. if (func[1] !== '_') return func; // C function
  1097. if (func[2] !== 'Z') return func;
  1098. switch (func[3]) {
  1099. case 'n':
  1100. return 'operator new()';
  1101. case 'd':
  1102. return 'operator delete()';
  1103. }
  1104. return parse();
  1105. } catch (e) {
  1106. return func;
  1107. }
  1108. }
  1109. function demangleAll(text) {
  1110. return text.replace(/__Z[\w\d_]+/g, function (x) {
  1111. var y = demangle(x);
  1112. return x === y ? x : (x + ' [' + y + ']')
  1113. });
  1114. }
  1115. function stackTrace() {
  1116. var stack = new Error().stack;
  1117. return stack ? demangleAll(stack) : '(no stack trace available)'; // Stack trace is not available at least on IE10 and Safari 6.
  1118. }
  1119. // Memory management
  1120. var PAGE_SIZE = 4096;
  1121. function alignMemoryPage(x) {
  1122. return (x + 4095) & -4096;
  1123. }
  1124. var HEAP;
  1125. var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
  1126. var STATIC_BASE = 0,
  1127. STATICTOP = 0,
  1128. staticSealed = false; // static area
  1129. var STACK_BASE = 0,
  1130. STACKTOP = 0,
  1131. STACK_MAX = 0; // stack area
  1132. var DYNAMIC_BASE = 0,
  1133. DYNAMICTOP = 0; // dynamic area handled by sbrk
  1134. function enlargeMemory() {
  1135. abort('Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value ' + TOTAL_MEMORY + ', (2) compile with ALLOW_MEMORY_GROWTH which adjusts the size at runtime but prevents some optimizations, or (3) set Module.TOTAL_MEMORY before the program runs.');
  1136. }
  1137. var TOTAL_STACK = Module['TOTAL_STACK'] || 5242880;
  1138. var TOTAL_MEMORY = Module['TOTAL_MEMORY'] || 16777216;
  1139. var FAST_MEMORY = Module['FAST_MEMORY'] || 2097152;
  1140. var totalMemory = 4096;
  1141. while (totalMemory < TOTAL_MEMORY || totalMemory < 2 * TOTAL_STACK) {
  1142. if (totalMemory < 16 * 1024 * 1024) {
  1143. totalMemory *= 2;
  1144. } else {
  1145. totalMemory += 16 * 1024 * 1024
  1146. }
  1147. }
  1148. if (totalMemory !== TOTAL_MEMORY) {
  1149. Module.printErr('increasing TOTAL_MEMORY to ' + totalMemory + ' to be more reasonable');
  1150. TOTAL_MEMORY = totalMemory;
  1151. }
  1152. // Initialize the runtime's memory
  1153. // check for full engine support (use string 'subarray' to avoid closure compiler confusion)
  1154. assert(typeof Int32Array !== 'undefined' && typeof Float64Array !== 'undefined' && !!(new Int32Array(1)['subarray']) && !!(new Int32Array(1)['set']),
  1155. 'JS engine does not provide full typed array support');
  1156. var buffer = new ArrayBuffer(TOTAL_MEMORY);
  1157. HEAP8 = new Int8Array(buffer);
  1158. HEAP16 = new Int16Array(buffer);
  1159. HEAP32 = new Int32Array(buffer);
  1160. HEAPU8 = new Uint8Array(buffer);
  1161. HEAPU16 = new Uint16Array(buffer);
  1162. HEAPU32 = new Uint32Array(buffer);
  1163. HEAPF32 = new Float32Array(buffer);
  1164. HEAPF64 = new Float64Array(buffer);
  1165. // Endianness check (note: assumes compiler arch was little-endian)
  1166. HEAP32[0] = 255;
  1167. assert(HEAPU8[0] === 255 && HEAPU8[3] === 0, 'Typed arrays 2 must be run on a little-endian system');
  1168. Module['HEAP'] = HEAP;
  1169. Module['HEAP8'] = HEAP8;
  1170. Module['HEAP16'] = HEAP16;
  1171. Module['HEAP32'] = HEAP32;
  1172. Module['HEAPU8'] = HEAPU8;
  1173. Module['HEAPU16'] = HEAPU16;
  1174. Module['HEAPU32'] = HEAPU32;
  1175. Module['HEAPF32'] = HEAPF32;
  1176. Module['HEAPF64'] = HEAPF64;
  1177. function callRuntimeCallbacks(callbacks) {
  1178. while (callbacks.length > 0) {
  1179. var callback = callbacks.shift();
  1180. if (typeof callback == 'function') {
  1181. callback();
  1182. continue;
  1183. }
  1184. var func = callback.func;
  1185. if (typeof func === 'number') {
  1186. if (callback.arg === undefined) {
  1187. Runtime.dynCall('v', func);
  1188. } else {
  1189. Runtime.dynCall('vi', func, [callback.arg]);
  1190. }
  1191. } else {
  1192. func(callback.arg === undefined ? null : callback.arg);
  1193. }
  1194. }
  1195. }
  1196. var __ATPRERUN__ = []; // functions called before the runtime is initialized
  1197. var __ATINIT__ = []; // functions called during startup
  1198. var __ATMAIN__ = []; // functions called when main() is to be run
  1199. var __ATEXIT__ = []; // functions called during shutdown
  1200. var __ATPOSTRUN__ = []; // functions called after the runtime has exited
  1201. var runtimeInitialized = false;
  1202. function preRun() {
  1203. // compatibility - merge in anything from Module['preRun'] at this time
  1204. if (Module['preRun']) {
  1205. if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
  1206. while (Module['preRun'].length) {
  1207. addOnPreRun(Module['preRun'].shift());
  1208. }
  1209. }
  1210. callRuntimeCallbacks(__ATPRERUN__);
  1211. }
  1212. function ensureInitRuntime() {
  1213. if (runtimeInitialized) return;
  1214. runtimeInitialized = true;
  1215. callRuntimeCallbacks(__ATINIT__);
  1216. }
  1217. function preMain() {
  1218. callRuntimeCallbacks(__ATMAIN__);
  1219. }
  1220. function exitRuntime() {
  1221. callRuntimeCallbacks(__ATEXIT__);
  1222. }
  1223. function postRun() {
  1224. // compatibility - merge in anything from Module['postRun'] at this time
  1225. if (Module['postRun']) {
  1226. if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
  1227. while (Module['postRun'].length) {
  1228. addOnPostRun(Module['postRun'].shift());
  1229. }
  1230. }
  1231. callRuntimeCallbacks(__ATPOSTRUN__);
  1232. }
  1233. function addOnPreRun(cb) {
  1234. __ATPRERUN__.unshift(cb);
  1235. }
  1236. Module['addOnPreRun'] = Module.addOnPreRun = addOnPreRun;
  1237. function addOnInit(cb) {
  1238. __ATINIT__.unshift(cb);
  1239. }
  1240. Module['addOnInit'] = Module.addOnInit = addOnInit;
  1241. function addOnPreMain(cb) {
  1242. __ATMAIN__.unshift(cb);
  1243. }
  1244. Module['addOnPreMain'] = Module.addOnPreMain = addOnPreMain;
  1245. function addOnExit(cb) {
  1246. __ATEXIT__.unshift(cb);
  1247. }
  1248. Module['addOnExit'] = Module.addOnExit = addOnExit;
  1249. function addOnPostRun(cb) {
  1250. __ATPOSTRUN__.unshift(cb);
  1251. }
  1252. Module['addOnPostRun'] = Module.addOnPostRun = addOnPostRun;
  1253. // Tools
  1254. // This processes a JS string into a C-line array of numbers, 0-terminated.
  1255. // For LLVM-originating strings, see parser.js:parseLLVMString function
  1256. function intArrayFromString(stringy, dontAddNull, length /* optional */ ) {
  1257. var ret = (new Runtime.UTF8Processor()).processJSString(stringy);
  1258. if (length) {
  1259. ret.length = length;
  1260. }
  1261. if (!dontAddNull) {
  1262. ret.push(0);
  1263. }
  1264. return ret;
  1265. }
  1266. Module['intArrayFromString'] = intArrayFromString;
  1267. function intArrayToString(array) {
  1268. var ret = [];
  1269. for (var i = 0; i < array.length; i++) {
  1270. var chr = array[i];
  1271. if (chr > 0xFF) {
  1272. chr &= 0xFF;
  1273. }
  1274. ret.push(String.fromCharCode(chr));
  1275. }
  1276. return ret.join('');
  1277. }
  1278. Module['intArrayToString'] = intArrayToString;
  1279. // Write a Javascript array to somewhere in the heap
  1280. function writeStringToMemory(string, buffer, dontAddNull) {
  1281. var array = intArrayFromString(string, dontAddNull);
  1282. var i = 0;
  1283. while (i < array.length) {
  1284. var chr = array[i];
  1285. HEAP8[(((buffer) + (i)) | 0)] = chr;
  1286. i = i + 1;
  1287. }
  1288. }
  1289. Module['writeStringToMemory'] = writeStringToMemory;
  1290. function writeArrayToMemory(array, buffer) {
  1291. for (var i = 0; i < array.length; i++) {
  1292. HEAP8[(((buffer) + (i)) | 0)] = array[i];
  1293. }
  1294. }
  1295. Module['writeArrayToMemory'] = writeArrayToMemory;
  1296. function writeAsciiToMemory(str, buffer, dontAddNull) {
  1297. for (var i = 0; i < str.length; i++) {
  1298. HEAP8[(((buffer) + (i)) | 0)] = str.charCodeAt(i);
  1299. }
  1300. if (!dontAddNull) HEAP8[(((buffer) + (str.length)) | 0)] = 0;
  1301. }
  1302. Module['writeAsciiToMemory'] = writeAsciiToMemory;
  1303. function unSign(value, bits, ignore) {
  1304. if (value >= 0) {
  1305. return value;
  1306. }
  1307. return bits <= 32 ? 2 * Math.abs(1 << (bits - 1)) + value // Need some trickery, since if bits == 32, we are right at the limit of the bits JS uses in bitshifts
  1308. : Math.pow(2, bits) + value;
  1309. }
  1310. function reSign(value, bits, ignore) {
  1311. if (value <= 0) {
  1312. return value;
  1313. }
  1314. var half = bits <= 32 ? Math.abs(1 << (bits - 1)) // abs is needed if bits == 32
  1315. : Math.pow(2, bits - 1);
  1316. if (value >= half && (bits <= 32 || value > half)) { // for huge values, we can hit the precision limit and always get true here. so don't do that
  1317. // but, in general there is no perfect solution here. With 64-bit ints, we get rounding and errors
  1318. // TODO: In i64 mode 1, resign the two parts separately and safely
  1319. value = -2 * half + value; // Cannot bitshift half, as it may be at the limit of the bits JS uses in bitshifts
  1320. }
  1321. return value;
  1322. }
  1323. // check for imul support, and also for correctness ( https://bugs.webkit.org/show_bug.cgi?id=126345 )
  1324. if (!Math['imul'] || Math['imul'](0xffffffff, 5) !== -5) Math['imul'] = function imul(a, b) {
  1325. var ah = a >>> 16;
  1326. var al = a & 0xffff;
  1327. var bh = b >>> 16;
  1328. var bl = b & 0xffff;
  1329. return (al * bl + ((ah * bl + al * bh) << 16)) | 0;
  1330. };
  1331. Math.imul = Math['imul'];
  1332. var Math_abs = Math.abs;
  1333. var Math_cos = Math.cos;
  1334. var Math_sin = Math.sin;
  1335. var Math_tan = Math.tan;
  1336. var Math_acos = Math.acos;
  1337. var Math_asin = Math.asin;
  1338. var Math_atan = Math.atan;
  1339. var Math_atan2 = Math.atan2;
  1340. var Math_exp = Math.exp;
  1341. var Math_log = Math.log;
  1342. var Math_sqrt = Math.sqrt;
  1343. var Math_ceil = Math.ceil;
  1344. var Math_floor = Math.floor;
  1345. var Math_pow = Math.pow;
  1346. var Math_imul = Math.imul;
  1347. var Math_fround = Math.fround;
  1348. var Math_min = Math.min;
  1349. // A counter of dependencies for calling run(). If we need to
  1350. // do asynchronous work before running, increment this and
  1351. // decrement it. Incrementing must happen in a place like
  1352. // PRE_RUN_ADDITIONS (used by emcc to add file preloading).
  1353. // Note that you can add dependencies in preRun, even though
  1354. // it happens right before run - run will be postponed until
  1355. // the dependencies are met.
  1356. var runDependencies = 0;
  1357. var runDependencyWatcher = null;
  1358. var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
  1359. function addRunDependency(id) {
  1360. runDependencies++;
  1361. if (Module['monitorRunDependencies']) {
  1362. Module['monitorRunDependencies'](runDependencies);
  1363. }
  1364. }
  1365. Module['addRunDependency'] = addRunDependency;
  1366. function removeRunDependency(id) {
  1367. runDependencies--;
  1368. if (Module['monitorRunDependencies']) {
  1369. Module['monitorRunDependencies'](runDependencies);
  1370. }
  1371. if (runDependencies == 0) {
  1372. if (runDependencyWatcher !== null) {
  1373. clearInterval(runDependencyWatcher);
  1374. runDependencyWatcher = null;
  1375. }
  1376. if (dependenciesFulfilled) {
  1377. var callback = dependenciesFulfilled;
  1378. dependenciesFulfilled = null;
  1379. callback(); // can add another dependenciesFulfilled
  1380. }
  1381. }
  1382. }
  1383. Module['removeRunDependency'] = removeRunDependency;
  1384. Module["preloadedImages"] = {}; // maps url to image data
  1385. Module["preloadedAudios"] = {}; // maps url to audio data
  1386. var memoryInitializer = null;
  1387. // === Body ===
  1388. STATIC_BASE = 8;
  1389. STATICTOP = STATIC_BASE + Runtime.alignMemory(11195);
  1390. /* global initializers */
  1391. __ATINIT__.push();
  1392. /* memory initializer */
  1393. allocate([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 68, 72, 82, 89, 83, 84, 79, 78, 69, 32, 80, 82, 79, 71, 82, 65, 77, 44, 32, 83, 79, 77, 69, 32, 83, 84, 82, 73, 78, 71], "i8", ALLOC_NONE, Runtime.GLOBAL_BASE);
  1394. var tempDoublePtr = Runtime.alignMemory(allocate(12, "i8", ALLOC_STATIC), 8);
  1395. assert(tempDoublePtr % 8 == 0);
  1396. function copyTempFloat(ptr) { // functions, because inlining this code increases code size too much
  1397. HEAP8[tempDoublePtr] = HEAP8[ptr];
  1398. HEAP8[tempDoublePtr + 1] = HEAP8[ptr + 1];
  1399. HEAP8[tempDoublePtr + 2] = HEAP8[ptr + 2];
  1400. HEAP8[tempDoublePtr + 3] = HEAP8[ptr + 3];
  1401. }
  1402. function copyTempDouble(ptr) {
  1403. HEAP8[tempDoublePtr] = HEAP8[ptr];
  1404. HEAP8[tempDoublePtr + 1] = HEAP8[ptr + 1];
  1405. HEAP8[tempDoublePtr + 2] = HEAP8[ptr + 2];
  1406. HEAP8[tempDoublePtr + 3] = HEAP8[ptr + 3];
  1407. HEAP8[tempDoublePtr + 4] = HEAP8[ptr + 4];
  1408. HEAP8[tempDoublePtr + 5] = HEAP8[ptr + 5];
  1409. HEAP8[tempDoublePtr + 6] = HEAP8[ptr + 6];
  1410. HEAP8[tempDoublePtr + 7] = HEAP8[ptr + 7];
  1411. }
  1412. function _emscripten_memcpy_big(dest, src, num) {
  1413. HEAPU8.set(HEAPU8.subarray(src, src + num), dest);
  1414. return dest;
  1415. }
  1416. Module["_memcpy"] = _memcpy;
  1417. var _llvm_memcpy_p0i8_p0i8_i32 = _memcpy;
  1418. function _sbrk(bytes) {
  1419. // Implement a Linux-like 'memory area' for our 'process'.
  1420. // Changes the size of the memory area by |bytes|; returns the
  1421. // address of the previous top ('break') of the memory area
  1422. // We control the "dynamic" memory - DYNAMIC_BASE to DYNAMICTOP
  1423. var self = _sbrk;
  1424. if (!self.called) {
  1425. DYNAMICTOP = alignMemoryPage(DYNAMICTOP); // make sure we start out aligned
  1426. self.called = true;
  1427. assert(Runtime.dynamicAlloc);
  1428. self.alloc = Runtime.dynamicAlloc;
  1429. Runtime.dynamicAlloc = function () {
  1430. abort('cannot dynamically allocate, sbrk now has control')
  1431. };
  1432. }
  1433. var ret = DYNAMICTOP;
  1434. if (bytes != 0) self.alloc(bytes);
  1435. return ret; // Previous break location.
  1436. }
  1437. var ___errno_state = 0;
  1438. function ___setErrNo(value) {
  1439. // For convenient setting and returning of errno.
  1440. HEAP32[((___errno_state) >> 2)] = value;
  1441. return value;
  1442. }
  1443. var ERRNO_CODES = {
  1444. EPERM: 1,
  1445. ENOENT: 2,
  1446. ESRCH: 3,
  1447. EINTR: 4,
  1448. EIO: 5,
  1449. ENXIO: 6,
  1450. E2BIG: 7,
  1451. ENOEXEC: 8,
  1452. EBADF: 9,
  1453. ECHILD: 10,
  1454. EAGAIN: 11,
  1455. EWOULDBLOCK: 11,
  1456. ENOMEM: 12,
  1457. EACCES: 13,
  1458. EFAULT: 14,
  1459. ENOTBLK: 15,
  1460. EBUSY: 16,
  1461. EEXIST: 17,
  1462. EXDEV: 18,
  1463. ENODEV: 19,
  1464. ENOTDIR: 20,
  1465. EISDIR: 21,
  1466. EINVAL: 22,
  1467. ENFILE: 23,
  1468. EMFILE: 24,
  1469. ENOTTY: 25,
  1470. ETXTBSY: 26,
  1471. EFBIG: 27,
  1472. ENOSPC: 28,
  1473. ESPIPE: 29,
  1474. EROFS: 30,
  1475. EMLINK: 31,
  1476. EPIPE: 32,
  1477. EDOM: 33,
  1478. ERANGE: 34,
  1479. ENOMSG: 42,
  1480. EIDRM: 43,
  1481. ECHRNG: 44,
  1482. EL2NSYNC: 45,
  1483. EL3HLT: 46,
  1484. EL3RST: 47,
  1485. ELNRNG: 48,
  1486. EUNATCH: 49,
  1487. ENOCSI: 50,
  1488. EL2HLT: 51,
  1489. EDEADLK: 35,
  1490. ENOLCK: 37,
  1491. EBADE: 52,
  1492. EBADR: 53,
  1493. EXFULL: 54,
  1494. ENOANO: 55,
  1495. EBADRQC: 56,
  1496. EBADSLT: 57,
  1497. EDEADLOCK: 35,
  1498. EBFONT: 59,
  1499. ENOSTR: 60,
  1500. ENODATA: 61,
  1501. ETIME: 62,
  1502. ENOSR: 63,
  1503. ENONET: 64,
  1504. ENOPKG: 65,
  1505. EREMOTE: 66,
  1506. ENOLINK: 67,
  1507. EADV: 68,
  1508. ESRMNT: 69,
  1509. ECOMM: 70,
  1510. EPROTO: 71,
  1511. EMULTIHOP: 72,
  1512. EDOTDOT: 73,
  1513. EBADMSG: 74,
  1514. ENOTUNIQ: 76,
  1515. EBADFD: 77,
  1516. EREMCHG: 78,
  1517. ELIBACC: 79,
  1518. ELIBBAD: 80,
  1519. ELIBSCN: 81,
  1520. ELIBMAX: 82,
  1521. ELIBEXEC: 83,
  1522. ENOSYS: 38,
  1523. ENOTEMPTY: 39,
  1524. ENAMETOOLONG: 36,
  1525. ELOOP: 40,
  1526. EOPNOTSUPP: 95,
  1527. EPFNOSUPPORT: 96,
  1528. ECONNRESET: 104,
  1529. ENOBUFS: 105,
  1530. EAFNOSUPPORT: 97,
  1531. EPROTOTYPE: 91,
  1532. ENOTSOCK: 88,
  1533. ENOPROTOOPT: 92,
  1534. ESHUTDOWN: 108,
  1535. ECONNREFUSED: 111,
  1536. EADDRINUSE: 98,
  1537. ECONNABORTED: 103,
  1538. ENETUNREACH: 101,
  1539. ENETDOWN: 100,
  1540. ETIMEDOUT: 110,
  1541. EHOSTDOWN: 112,
  1542. EHOSTUNREACH: 113,
  1543. EINPROGRESS: 115,
  1544. EALREADY: 114,
  1545. EDESTADDRREQ: 89,
  1546. EMSGSIZE: 90,
  1547. EPROTONOSUPPORT: 93,
  1548. ESOCKTNOSUPPORT: 94,
  1549. EADDRNOTAVAIL: 99,
  1550. ENETRESET: 102,
  1551. EISCONN: 106,
  1552. ENOTCONN: 107,
  1553. ETOOMANYREFS: 109,
  1554. EUSERS: 87,
  1555. EDQUOT: 122,
  1556. ESTALE: 116,
  1557. ENOTSUP: 95,
  1558. ENOMEDIUM: 123,
  1559. EILSEQ: 84,
  1560. EOVERFLOW: 75,
  1561. ECANCELED: 125,
  1562. ENOTRECOVERABLE: 131,
  1563. EOWNERDEAD: 130,
  1564. ESTRPIPE: 86
  1565. };
  1566. function _sysconf(name) {
  1567. // long sysconf(int name);
  1568. // http://pubs.opengroup.org/onlinepubs/009695399/functions/sysconf.html
  1569. switch (name) {
  1570. case 30:
  1571. return PAGE_SIZE;
  1572. case 132:
  1573. case 133:
  1574. case 12:
  1575. case 137:
  1576. case 138:
  1577. case 15:
  1578. case 235:
  1579. case 16:
  1580. case 17:
  1581. case 18:
  1582. case 19:
  1583. case 20:
  1584. case 149:
  1585. case 13:
  1586. case 10:
  1587. case 236:
  1588. case 153:
  1589. case 9:
  1590. case 21:
  1591. case 22:
  1592. case 159:
  1593. case 154:
  1594. case 14:
  1595. case 77:
  1596. case 78:
  1597. case 139:
  1598. case 80:
  1599. case 81:
  1600. case 79:
  1601. case 82:
  1602. case 68:
  1603. case 67:
  1604. case 164:
  1605. case 11:
  1606. case 29:
  1607. case 47:
  1608. case 48:
  1609. case 95:
  1610. case 52:
  1611. case 51:
  1612. case 46:
  1613. return 200809;
  1614. case 27:
  1615. case 246:
  1616. case 127:
  1617. case 128:
  1618. case 23:
  1619. case 24:
  1620. case 160:
  1621. case 161:
  1622. case 181:
  1623. case 182:
  1624. case 242:
  1625. case 183:
  1626. case 184:
  1627. case 243:
  1628. case 244:
  1629. case 245:
  1630. case 165:
  1631. case 178:
  1632. case 179:
  1633. case 49:
  1634. case 50:
  1635. case 168:
  1636. case 169:
  1637. case 175:
  1638. case 170:
  1639. case 171:
  1640. case 172:
  1641. case 97:
  1642. case 76:
  1643. case 32:
  1644. case 173:
  1645. case 35:
  1646. return -1;
  1647. case 176:
  1648. case 177:
  1649. case 7:
  1650. case 155:
  1651. case 8:
  1652. case 157:
  1653. case 125:
  1654. case 126:
  1655. case 92:
  1656. case 93:
  1657. case 129:
  1658. case 130:
  1659. case 131:
  1660. case 94:
  1661. case 91:
  1662. return 1;
  1663. case 74:
  1664. case 60:
  1665. case 69:
  1666. case 70:
  1667. case 4:
  1668. return 1024;
  1669. case 31:
  1670. case 42:
  1671. case 72:
  1672. return 32;
  1673. case 87:
  1674. case 26:
  1675. case 33:
  1676. return 2147483647;
  1677. case 34:
  1678. case 1:
  1679. return 47839;
  1680. case 38:
  1681. case 36:
  1682. return 99;
  1683. case 43:
  1684. case 37:
  1685. return 2048;
  1686. case 0:
  1687. return 2097152;
  1688. case 3:
  1689. return 65536;
  1690. case 28:
  1691. return 32768;
  1692. case 44:
  1693. return 32767;
  1694. case 75:
  1695. return 16384;
  1696. case 39:
  1697. return 1000;
  1698. case 89:
  1699. return 700;
  1700. case 71:
  1701. return 256;
  1702. case 40:
  1703. return 255;
  1704. case 2:
  1705. return 100;
  1706. case 180:
  1707. return 64;
  1708. case 25:
  1709. return 20;
  1710. case 5:
  1711. return 16;
  1712. case 6:
  1713. return 6;
  1714. case 73:
  1715. return 4;
  1716. case 84:
  1717. return 1;
  1718. }
  1719. ___setErrNo(ERRNO_CODES.EINVAL);
  1720. return -1;
  1721. }
  1722. function _clock() {
  1723. if (_clock.start === undefined) _clock.start = Date.now();
  1724. return Math.floor((Date.now() - _clock.start) * (1000000 / 1000));
  1725. }
  1726. Module["_memset"] = _memset;
  1727. function ___errno_location() {
  1728. return ___errno_state;
  1729. }
  1730. function _abort() {
  1731. Module['abort']();
  1732. }
  1733. var ERRNO_MESSAGES = {
  1734. 0: "Success",
  1735. 1: "Not super-user",
  1736. 2: "No such file or directory",
  1737. 3: "No such process",
  1738. 4: "Interrupted system call",
  1739. 5: "I/O error",
  1740. 6: "No such device or address",
  1741. 7: "Arg list too long",
  1742. 8: "Exec format error",
  1743. 9: "Bad file number",
  1744. 10: "No children",
  1745. 11: "No more processes",
  1746. 12: "Not enough core",
  1747. 13: "Permission denied",
  1748. 14: "Bad address",
  1749. 15: "Block device required",
  1750. 16: "Mount device busy",
  1751. 17: "File exists",
  1752. 18: "Cross-device link",
  1753. 19: "No such device",
  1754. 20: "Not a directory",
  1755. 21: "Is a directory",
  1756. 22: "Invalid argument",
  1757. 23: "Too many open files in system",
  1758. 24: "Too many open files",
  1759. 25: "Not a typewriter",
  1760. 26: "Text file busy",
  1761. 27: "File too large",
  1762. 28: "No space left on device",
  1763. 29: "Illegal seek",
  1764. 30: "Read only file system",
  1765. 31: "Too many links",
  1766. 32: "Broken pipe",
  1767. 33: "Math arg out of domain of func",
  1768. 34: "Math result not representable",
  1769. 35: "File locking deadlock error",
  1770. 36: "File or path name too long",
  1771. 37: "No record locks available",
  1772. 38: "Function not implemented",
  1773. 39: "Directory not empty",
  1774. 40: "Too many symbolic links",
  1775. 42: "No message of desired type",
  1776. 43: "Identifier removed",
  1777. 44: "Channel number out of range",
  1778. 45: "Level 2 not synchronized",
  1779. 46: "Level 3 halted",
  1780. 47: "Level 3 reset",
  1781. 48: "Link number out of range",
  1782. 49: "Protocol driver not attached",
  1783. 50: "No CSI structure available",
  1784. 51: "Level 2 halted",
  1785. 52: "Invalid exchange",
  1786. 53: "Invalid request descriptor",
  1787. 54: "Exchange full",
  1788. 55: "No anode",
  1789. 56: "Invalid request code",
  1790. 57: "Invalid slot",
  1791. 59: "Bad font file fmt",
  1792. 60: "Device not a stream",
  1793. 61: "No data (for no delay io)",
  1794. 62: "Timer expired",
  1795. 63: "Out of streams resources",
  1796. 64: "Machine is not on the network",
  1797. 65: "Package not installed",
  1798. 66: "The object is remote",
  1799. 67: "The link has been severed",
  1800. 68: "Advertise error",
  1801. 69: "Srmount error",
  1802. 70: "Communication error on send",
  1803. 71: "Protocol error",
  1804. 72: "Multihop attempted",
  1805. 73: "Cross mount point (not really error)",
  1806. 74: "Trying to read unreadable message",
  1807. 75: "Value too large for defined data type",
  1808. 76: "Given log. name not unique",
  1809. 77: "f.d. invalid for this operation",
  1810. 78: "Remote address changed",
  1811. 79: "Can access a needed shared lib",
  1812. 80: "Accessing a corrupted shared lib",
  1813. 81: ".lib section in a.out corrupted",
  1814. 82: "Attempting to link in too many libs",
  1815. 83: "Attempting to exec a shared library",
  1816. 84: "Illegal byte sequence",
  1817. 86: "Streams pipe error",
  1818. 87: "Too many users",
  1819. 88: "Socket operation on non-socket",
  1820. 89: "Destination address required",
  1821. 90: "Message too long",
  1822. 91: "Protocol wrong type for socket",
  1823. 92: "Protocol not available",
  1824. 93: "Unknown protocol",
  1825. 94: "Socket type not supported",
  1826. 95: "Not supported",
  1827. 96: "Protocol family not supported",
  1828. 97: "Address family not supported by protocol family",
  1829. 98: "Address already in use",
  1830. 99: "Address not available",
  1831. 100: "Network interface is not configured",
  1832. 101: "Network is unreachable",
  1833. 102: "Connection reset by network",
  1834. 103: "Connection aborted",
  1835. 104: "Connection reset by peer",
  1836. 105: "No buffer space available",
  1837. 106: "Socket is already connected",
  1838. 107: "Socket is not connected",
  1839. 108: "Can't send after socket shutdown",
  1840. 109: "Too many references",
  1841. 110: "Connection timed out",
  1842. 111: "Connection refused",
  1843. 112: "Host is down",
  1844. 113: "Host is unreachable",
  1845. 114: "Socket already connected",
  1846. 115: "Connection already in progress",
  1847. 116: "Stale file handle",
  1848. 122: "Quota exceeded",
  1849. 123: "No medium (in tape drive)",
  1850. 125: "Operation canceled",
  1851. 130: "Previous owner died",
  1852. 131: "State not recoverable"
  1853. };
  1854. var TTY = {
  1855. ttys: [],
  1856. init: function () {
  1857. // https://github.com/kripken/emscripten/pull/1555
  1858. // if (ENVIRONMENT_IS_NODE) {
  1859. // // currently, FS.init does not distinguish if process.stdin is a file or TTY
  1860. // // device, it always assumes it's a TTY device. because of this, we're forcing
  1861. // // process.stdin to UTF8 encoding to at least make stdin reading compatible
  1862. // // with text files until FS.init can be refactored.
  1863. // process['stdin']['setEncoding']('utf8');
  1864. // }
  1865. },
  1866. shutdown: function () {
  1867. // https://github.com/kripken/emscripten/pull/1555
  1868. // if (ENVIRONMENT_IS_NODE) {
  1869. // // inolen: any idea as to why node -e 'process.stdin.read()' wouldn't exit immediately (with process.stdin being a tty)?
  1870. // // isaacs: because now it's reading from the stream, you've expressed interest in it, so that read() kicks off a _read() which creates a ReadReq operation
  1871. // // inolen: I thought read() in that case was a synchronous operation that just grabbed some amount of buffered data if it exists?
  1872. // // isaacs: it is. but it also triggers a _read() call, which calls readStart() on the handle
  1873. // // isaacs: do process.stdin.pause() and i'd think it'd probably close the pending call
  1874. // process['stdin']['pause']();
  1875. // }
  1876. },
  1877. register: function (dev, ops) {
  1878. TTY.ttys[dev] = {
  1879. input: [],
  1880. output: [],
  1881. ops: ops
  1882. };
  1883. FS.registerDevice(dev, TTY.stream_ops);
  1884. },
  1885. stream_ops: {
  1886. open: function (stream) {
  1887. var tty = TTY.ttys[stream.node.rdev];
  1888. if (!tty) {
  1889. throw new FS.ErrnoError(ERRNO_CODES.ENODEV);
  1890. }
  1891. stream.tty = tty;
  1892. stream.seekable = false;
  1893. },
  1894. close: function (stream) {
  1895. // flush any pending line data
  1896. if (stream.tty.output.length) {
  1897. stream.tty.ops.put_char(stream.tty, 10);
  1898. }
  1899. },
  1900. read: function (stream, buffer, offset, length, pos /* ignored */ ) {
  1901. if (!stream.tty || !stream.tty.ops.get_char) {
  1902. throw new FS.ErrnoError(ERRNO_CODES.ENXIO);
  1903. }
  1904. var bytesRead = 0;
  1905. for (var i = 0; i < length; i++) {
  1906. var result;
  1907. try {
  1908. result = stream.tty.ops.get_char(stream.tty);
  1909. } catch (e) {
  1910. throw new FS.ErrnoError(ERRNO_CODES.EIO);
  1911. }
  1912. if (result === undefined && bytesRead === 0) {
  1913. throw new FS.ErrnoError(ERRNO_CODES.EAGAIN);
  1914. }
  1915. if (result === null || result === undefined) break;
  1916. bytesRead++;
  1917. buffer[offset + i] = result;
  1918. }
  1919. if (bytesRead) {
  1920. stream.node.timestamp = Date.now();
  1921. }
  1922. return bytesRead;
  1923. },
  1924. write: function (stream, buffer, offset, length, pos) {
  1925. if (!stream.tty || !stream.tty.ops.put_char) {
  1926. throw new FS.ErrnoError(ERRNO_CODES.ENXIO);
  1927. }
  1928. for (var i = 0; i < length; i++) {
  1929. try {
  1930. stream.tty.ops.put_char(stream.tty, buffer[offset + i]);
  1931. } catch (e) {
  1932. throw new FS.ErrnoError(ERRNO_CODES.EIO);
  1933. }
  1934. }
  1935. if (length) {
  1936. stream.node.timestamp = Date.now();
  1937. }
  1938. return i;
  1939. }
  1940. },
  1941. default_tty_ops: {
  1942. get_char: function (tty) {
  1943. if (!tty.input.length) {
  1944. var result = null;
  1945. if (ENVIRONMENT_IS_NODE) {
  1946. result = process['stdin']['read']();
  1947. if (!result) {
  1948. if (process['stdin']['_readableState'] && process['stdin']['_readableState']['ended']) {
  1949. return null; // EOF
  1950. }
  1951. return undefined; // no data available
  1952. }
  1953. } else if (typeof window != 'undefined' &&
  1954. typeof window.prompt == 'function') {
  1955. // Browser.
  1956. result = window.prompt('Input: '); // returns null on cancel
  1957. if (result !== null) {
  1958. result += '\n';
  1959. }
  1960. } else if (typeof readline == 'function') {
  1961. // Command line.
  1962. result = readline();
  1963. if (result !== null) {
  1964. result += '\n';
  1965. }
  1966. }
  1967. if (!result) {
  1968. return null;
  1969. }
  1970. tty.input = intArrayFromString(result, true);
  1971. }
  1972. return tty.input.shift();
  1973. },
  1974. put_char: function (tty, val) {
  1975. if (val === null || val === 10) {
  1976. Module['print'](tty.output.join(''));
  1977. tty.output = [];
  1978. } else {
  1979. tty.output.push(TTY.utf8.processCChar(val));
  1980. }
  1981. }
  1982. },
  1983. default_tty1_ops: {
  1984. put_char: function (tty, val) {
  1985. if (val === null || val === 10) {
  1986. Module['printErr'](tty.output.join(''));
  1987. tty.output = [];
  1988. } else {
  1989. tty.output.push(TTY.utf8.processCChar(val));
  1990. }
  1991. }
  1992. }
  1993. };
  1994. var MEMFS = {
  1995. ops_table: null,
  1996. CONTENT_OWNING: 1,
  1997. CONTENT_FLEXIBLE: 2,
  1998. CONTENT_FIXED: 3,
  1999. mount: function (mount) {
  2000. return MEMFS.createNode(null, '/', 16384 | 511 /* 0777 */ , 0);
  2001. },
  2002. createNode: function (parent, name, mode, dev) {
  2003. if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
  2004. // no supported
  2005. throw new FS.ErrnoError(ERRNO_CODES.EPERM);
  2006. }
  2007. if (!MEMFS.ops_table) {
  2008. MEMFS.ops_table = {
  2009. dir: {
  2010. node: {
  2011. getattr: MEMFS.node_ops.getattr,
  2012. setattr: MEMFS.node_ops.setattr,
  2013. lookup: MEMFS.node_ops.lookup,
  2014. mknod: MEMFS.node_ops.mknod,
  2015. rename: MEMFS.node_ops.rename,
  2016. unlink: MEMFS.node_ops.unlink,
  2017. rmdir: MEMFS.node_ops.rmdir,
  2018. readdir: MEMFS.node_ops.readdir,
  2019. symlink: MEMFS.node_ops.symlink
  2020. },
  2021. stream: {
  2022. llseek: MEMFS.stream_ops.llseek
  2023. }
  2024. },
  2025. file: {
  2026. node: {
  2027. getattr: MEMFS.node_ops.getattr,
  2028. setattr: MEMFS.node_ops.setattr
  2029. },
  2030. stream: {
  2031. llseek: MEMFS.stream_ops.llseek,
  2032. read: MEMFS.stream_ops.read,
  2033. write: MEMFS.stream_ops.write,
  2034. allocate: MEMFS.stream_ops.allocate,
  2035. mmap: MEMFS.stream_ops.mmap
  2036. }
  2037. },
  2038. link: {
  2039. node: {
  2040. getattr: MEMFS.node_ops.getattr,
  2041. setattr: MEMFS.node_ops.setattr,
  2042. readlink: MEMFS.node_ops.readlink
  2043. },
  2044. stream: {}
  2045. },
  2046. chrdev: {
  2047. node: {
  2048. getattr: MEMFS.node_ops.getattr,
  2049. setattr: MEMFS.node_ops.setattr
  2050. },
  2051. stream: FS.chrdev_stream_ops
  2052. },
  2053. };
  2054. }
  2055. var node = FS.createNode(parent, name, mode, dev);
  2056. if (FS.isDir(node.mode)) {
  2057. node.node_ops = MEMFS.ops_table.dir.node;
  2058. node.stream_ops = MEMFS.ops_table.dir.stream;
  2059. node.contents = {};
  2060. } else if (FS.isFile(node.mode)) {
  2061. node.node_ops = MEMFS.ops_table.file.node;
  2062. node.stream_ops = MEMFS.ops_table.file.stream;
  2063. node.contents = [];
  2064. node.contentMode = MEMFS.CONTENT_FLEXIBLE;
  2065. } else if (FS.isLink(node.mode)) {
  2066. node.node_ops = MEMFS.ops_table.link.node;
  2067. node.stream_ops = MEMFS.ops_table.link.stream;
  2068. } else if (FS.isChrdev(node.mode)) {
  2069. node.node_ops = MEMFS.ops_table.chrdev.node;
  2070. node.stream_ops = MEMFS.ops_table.chrdev.stream;
  2071. }
  2072. node.timestamp = Date.now();
  2073. // add the new node to the parent
  2074. if (parent) {
  2075. parent.contents[name] = node;
  2076. }
  2077. return node;
  2078. },
  2079. ensureFlexible: function (node) {
  2080. if (node.contentMode !== MEMFS.CONTENT_FLEXIBLE) {
  2081. var contents = node.contents;
  2082. node.contents = Array.prototype.slice.call(contents);
  2083. node.contentMode = MEMFS.CONTENT_FLEXIBLE;
  2084. }
  2085. },
  2086. node_ops: {
  2087. getattr: function (node) {
  2088. var attr = {};
  2089. // device numbers reuse inode numbers.
  2090. attr.dev = FS.isChrdev(node.mode) ? node.id : 1;
  2091. attr.ino = node.id;
  2092. attr.mode = node.mode;
  2093. attr.nlink = 1;
  2094. attr.uid = 0;
  2095. attr.gid = 0;
  2096. attr.rdev = node.rdev;
  2097. if (FS.isDir(node.mode)) {
  2098. attr.size = 4096;
  2099. } else if (FS.isFile(node.mode)) {
  2100. attr.size = node.contents.length;
  2101. } else if (FS.isLink(node.mode)) {
  2102. attr.size = node.link.length;
  2103. } else {
  2104. attr.size = 0;
  2105. }
  2106. attr.atime = new Date(node.timestamp);
  2107. attr.mtime = new Date(node.timestamp);
  2108. attr.ctime = new Date(node.timestamp);
  2109. // NOTE: In our implementation, st_blocks = Math.ceil(st_size/st_blksize),
  2110. // but this is not required by the standard.
  2111. attr.blksize = 4096;
  2112. attr.blocks = Math.ceil(attr.size / attr.blksize);
  2113. return attr;
  2114. },
  2115. setattr: function (node, attr) {
  2116. if (attr.mode !== undefined) {
  2117. node.mode = attr.mode;
  2118. }
  2119. if (attr.timestamp !== undefined) {
  2120. node.timestamp = attr.timestamp;
  2121. }
  2122. if (attr.size !== undefined) {
  2123. MEMFS.ensureFlexible(node);
  2124. var contents = node.contents;
  2125. if (attr.size < contents.length) contents.length = attr.size;
  2126. else
  2127. while (attr.size > contents.length) contents.push(0);
  2128. }
  2129. },
  2130. lookup: function (parent, name) {
  2131. throw FS.genericErrors[ERRNO_CODES.ENOENT];
  2132. },
  2133. mknod: function (parent, name, mode, dev) {
  2134. return MEMFS.createNode(parent, name, mode, dev);
  2135. },
  2136. rename: function (old_node, new_dir, new_name) {
  2137. // if we're overwriting a directory at new_name, make sure it's empty.
  2138. if (FS.isDir(old_node.mode)) {
  2139. var new_node;
  2140. try {
  2141. new_node = FS.lookupNode(new_dir, new_name);
  2142. } catch (e) {}
  2143. if (new_node) {
  2144. for (var i in new_node.contents) {
  2145. throw new FS.ErrnoError(ERRNO_CODES.ENOTEMPTY);
  2146. }
  2147. }
  2148. }
  2149. // do the internal rewiring
  2150. delete old_node.parent.contents[old_node.name];
  2151. old_node.name = new_name;
  2152. new_dir.contents[new_name] = old_node;
  2153. old_node.parent = new_dir;
  2154. },
  2155. unlink: function (parent, name) {
  2156. delete parent.contents[name];
  2157. },
  2158. rmdir: function (parent, name) {
  2159. var node = FS.lookupNode(parent, name);
  2160. for (var i in node.contents) {
  2161. throw new FS.ErrnoError(ERRNO_CODES.ENOTEMPTY);
  2162. }
  2163. delete parent.contents[name];
  2164. },
  2165. readdir: function (node) {
  2166. var entries = ['.', '..']
  2167. for (var key in node.contents) {
  2168. if (!node.contents.hasOwnProperty(key)) {
  2169. continue;
  2170. }
  2171. entries.push(key);
  2172. }
  2173. return entries;
  2174. },
  2175. symlink: function (parent, newname, oldpath) {
  2176. var node = MEMFS.createNode(parent, newname, 511 /* 0777 */ | 40960, 0);
  2177. node.link = oldpath;
  2178. return node;
  2179. },
  2180. readlink: function (node) {
  2181. if (!FS.isLink(node.mode)) {
  2182. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  2183. }
  2184. return node.link;
  2185. }
  2186. },
  2187. stream_ops: {
  2188. read: function (stream, buffer, offset, length, position) {
  2189. var contents = stream.node.contents;
  2190. if (position >= contents.length)
  2191. return 0;
  2192. var size = Math.min(contents.length - position, length);
  2193. assert(size >= 0);
  2194. if (size > 8 && contents.subarray) { // non-trivial, and typed array
  2195. buffer.set(contents.subarray(position, position + size), offset);
  2196. } else {
  2197. for (var i = 0; i < size; i++) {
  2198. buffer[offset + i] = contents[position + i];
  2199. }
  2200. }
  2201. return size;
  2202. },
  2203. write: function (stream, buffer, offset, length, position, canOwn) {
  2204. var node = stream.node;
  2205. node.timestamp = Date.now();
  2206. var contents = node.contents;
  2207. if (length && contents.length === 0 && position === 0 && buffer.subarray) {
  2208. // just replace it with the new data
  2209. if (canOwn && offset === 0) {
  2210. node.contents = buffer; // this could be a subarray of Emscripten HEAP, or allocated from some other source.
  2211. node.contentMode = (buffer.buffer === HEAP8.buffer) ? MEMFS.CONTENT_OWNING : MEMFS.CONTENT_FIXED;
  2212. } else {
  2213. node.contents = new Uint8Array(buffer.subarray(offset, offset + length));
  2214. node.contentMode = MEMFS.CONTENT_FIXED;
  2215. }
  2216. return length;
  2217. }
  2218. MEMFS.ensureFlexible(node);
  2219. var contents = node.contents;
  2220. while (contents.length < position) contents.push(0);
  2221. for (var i = 0; i < length; i++) {
  2222. contents[position + i] = buffer[offset + i];
  2223. }
  2224. return length;
  2225. },
  2226. llseek: function (stream, offset, whence) {
  2227. var position = offset;
  2228. if (whence === 1) { // SEEK_CUR.
  2229. position += stream.position;
  2230. } else if (whence === 2) { // SEEK_END.
  2231. if (FS.isFile(stream.node.mode)) {
  2232. position += stream.node.contents.length;
  2233. }
  2234. }
  2235. if (position < 0) {
  2236. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  2237. }
  2238. stream.ungotten = [];
  2239. stream.position = position;
  2240. return position;
  2241. },
  2242. allocate: function (stream, offset, length) {
  2243. MEMFS.ensureFlexible(stream.node);
  2244. var contents = stream.node.contents;
  2245. var limit = offset + length;
  2246. while (limit > contents.length) contents.push(0);
  2247. },
  2248. mmap: function (stream, buffer, offset, length, position, prot, flags) {
  2249. if (!FS.isFile(stream.node.mode)) {
  2250. throw new FS.ErrnoError(ERRNO_CODES.ENODEV);
  2251. }
  2252. var ptr;
  2253. var allocated;
  2254. var contents = stream.node.contents;
  2255. // Only make a new copy when MAP_PRIVATE is specified.
  2256. if (!(flags & 2) &&
  2257. (contents.buffer === buffer || contents.buffer === buffer.buffer)) {
  2258. // We can't emulate MAP_SHARED when the file is not backed by the buffer
  2259. // we're mapping to (e.g. the HEAP buffer).
  2260. allocated = false;
  2261. ptr = contents.byteOffset;
  2262. } else {
  2263. // Try to avoid unnecessary slices.
  2264. if (position > 0 || position + length < contents.length) {
  2265. if (contents.subarray) {
  2266. contents = contents.subarray(position, position + length);
  2267. } else {
  2268. contents = Array.prototype.slice.call(contents, position, position + length);
  2269. }
  2270. }
  2271. allocated = true;
  2272. ptr = _malloc(length);
  2273. if (!ptr) {
  2274. throw new FS.ErrnoError(ERRNO_CODES.ENOMEM);
  2275. }
  2276. buffer.set(contents, ptr);
  2277. }
  2278. return {
  2279. ptr: ptr,
  2280. allocated: allocated
  2281. };
  2282. }
  2283. }
  2284. };
  2285. var IDBFS = {
  2286. dbs: {},
  2287. indexedDB: function () {
  2288. return window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
  2289. },
  2290. DB_VERSION: 21,
  2291. DB_STORE_NAME: "FILE_DATA",
  2292. mount: function (mount) {
  2293. // reuse all of the core MEMFS functionality
  2294. return MEMFS.mount.apply(null, arguments);
  2295. },
  2296. syncfs: function (mount, populate, callback) {
  2297. IDBFS.getLocalSet(mount, function (err, local) {
  2298. if (err) return callback(err);
  2299. IDBFS.getRemoteSet(mount, function (err, remote) {
  2300. if (err) return callback(err);
  2301. var src = populate ? remote : local;
  2302. var dst = populate ? local : remote;
  2303. IDBFS.reconcile(src, dst, callback);
  2304. });
  2305. });
  2306. },
  2307. getDB: function (name, callback) {
  2308. // check the cache first
  2309. var db = IDBFS.dbs[name];
  2310. if (db) {
  2311. return callback(null, db);
  2312. }
  2313. var req;
  2314. try {
  2315. req = IDBFS.indexedDB().open(name, IDBFS.DB_VERSION);
  2316. } catch (e) {
  2317. return callback(e);
  2318. }
  2319. req.onupgradeneeded = function (e) {
  2320. var db = e.target.result;
  2321. var transaction = e.target.transaction;
  2322. var fileStore;
  2323. if (db.objectStoreNames.contains(IDBFS.DB_STORE_NAME)) {
  2324. fileStore = transaction.objectStore(IDBFS.DB_STORE_NAME);
  2325. } else {
  2326. fileStore = db.createObjectStore(IDBFS.DB_STORE_NAME);
  2327. }
  2328. fileStore.createIndex('timestamp', 'timestamp', {
  2329. unique: false
  2330. });
  2331. };
  2332. req.onsuccess = function () {
  2333. db = req.result;
  2334. // add to the cache
  2335. IDBFS.dbs[name] = db;
  2336. callback(null, db);
  2337. };
  2338. req.onerror = function () {
  2339. callback(this.error);
  2340. };
  2341. },
  2342. getLocalSet: function (mount, callback) {
  2343. var entries = {};
  2344. function isRealDir(p) {
  2345. return p !== '.' && p !== '..';
  2346. };
  2347. function toAbsolute(root) {
  2348. return function (p) {
  2349. return PATH.join2(root, p);
  2350. }
  2351. };
  2352. var check = FS.readdir(mount.mountpoint).filter(isRealDir).map(toAbsolute(mount.mountpoint));
  2353. while (check.length) {
  2354. var path = check.pop();
  2355. var stat;
  2356. try {
  2357. stat = FS.stat(path);
  2358. } catch (e) {
  2359. return callback(e);
  2360. }
  2361. if (FS.isDir(stat.mode)) {
  2362. check.push.apply(check, FS.readdir(path).filter(isRealDir).map(toAbsolute(path)));
  2363. }
  2364. entries[path] = {
  2365. timestamp: stat.mtime
  2366. };
  2367. }
  2368. return callback(null, {
  2369. type: 'local',
  2370. entries: entries
  2371. });
  2372. },
  2373. getRemoteSet: function (mount, callback) {
  2374. var entries = {};
  2375. IDBFS.getDB(mount.mountpoint, function (err, db) {
  2376. if (err) return callback(err);
  2377. var transaction = db.transaction([IDBFS.DB_STORE_NAME], 'readonly');
  2378. transaction.onerror = function () {
  2379. callback(this.error);
  2380. };
  2381. var store = transaction.objectStore(IDBFS.DB_STORE_NAME);
  2382. var index = store.index('timestamp');
  2383. index.openKeyCursor().onsuccess = function (event) {
  2384. var cursor = event.target.result;
  2385. if (!cursor) {
  2386. return callback(null, {
  2387. type: 'remote',
  2388. db: db,
  2389. entries: entries
  2390. });
  2391. }
  2392. entries[cursor.primaryKey] = {
  2393. timestamp: cursor.key
  2394. };
  2395. cursor.continue();
  2396. };
  2397. });
  2398. },
  2399. loadLocalEntry: function (path, callback) {
  2400. var stat, node;
  2401. try {
  2402. var lookup = FS.lookupPath(path);
  2403. node = lookup.node;
  2404. stat = FS.stat(path);
  2405. } catch (e) {
  2406. return callback(e);
  2407. }
  2408. if (FS.isDir(stat.mode)) {
  2409. return callback(null, {
  2410. timestamp: stat.mtime,
  2411. mode: stat.mode
  2412. });
  2413. } else if (FS.isFile(stat.mode)) {
  2414. return callback(null, {
  2415. timestamp: stat.mtime,
  2416. mode: stat.mode,
  2417. contents: node.contents
  2418. });
  2419. } else {
  2420. return callback(new Error('node type not supported'));
  2421. }
  2422. },
  2423. storeLocalEntry: function (path, entry, callback) {
  2424. try {
  2425. if (FS.isDir(entry.mode)) {
  2426. FS.mkdir(path, entry.mode);
  2427. } else if (FS.isFile(entry.mode)) {
  2428. FS.writeFile(path, entry.contents, {
  2429. encoding: 'binary',
  2430. canOwn: true
  2431. });
  2432. } else {
  2433. return callback(new Error('node type not supported'));
  2434. }
  2435. FS.utime(path, entry.timestamp, entry.timestamp);
  2436. } catch (e) {
  2437. return callback(e);
  2438. }
  2439. callback(null);
  2440. },
  2441. removeLocalEntry: function (path, callback) {
  2442. try {
  2443. var lookup = FS.lookupPath(path);
  2444. var stat = FS.stat(path);
  2445. if (FS.isDir(stat.mode)) {
  2446. FS.rmdir(path);
  2447. } else if (FS.isFile(stat.mode)) {
  2448. FS.unlink(path);
  2449. }
  2450. } catch (e) {
  2451. return callback(e);
  2452. }
  2453. callback(null);
  2454. },
  2455. loadRemoteEntry: function (store, path, callback) {
  2456. var req = store.get(path);
  2457. req.onsuccess = function (event) {
  2458. callback(null, event.target.result);
  2459. };
  2460. req.onerror = function () {
  2461. callback(this.error);
  2462. };
  2463. },
  2464. storeRemoteEntry: function (store, path, entry, callback) {
  2465. var req = store.put(entry, path);
  2466. req.onsuccess = function () {
  2467. callback(null);
  2468. };
  2469. req.onerror = function () {
  2470. callback(this.error);
  2471. };
  2472. },
  2473. removeRemoteEntry: function (store, path, callback) {
  2474. var req = store.delete(path);
  2475. req.onsuccess = function () {
  2476. callback(null);
  2477. };
  2478. req.onerror = function () {
  2479. callback(this.error);
  2480. };
  2481. },
  2482. reconcile: function (src, dst, callback) {
  2483. var total = 0;
  2484. var create = [];
  2485. Object.keys(src.entries).forEach(function (key) {
  2486. var e = src.entries[key];
  2487. var e2 = dst.entries[key];
  2488. if (!e2 || e.timestamp > e2.timestamp) {
  2489. create.push(key);
  2490. total++;
  2491. }
  2492. });
  2493. var remove = [];
  2494. Object.keys(dst.entries).forEach(function (key) {
  2495. var e = dst.entries[key];
  2496. var e2 = src.entries[key];
  2497. if (!e2) {
  2498. remove.push(key);
  2499. total++;
  2500. }
  2501. });
  2502. if (!total) {
  2503. return callback(null);
  2504. }
  2505. var errored = false;
  2506. var completed = 0;
  2507. var db = src.type === 'remote' ? src.db : dst.db;
  2508. var transaction = db.transaction([IDBFS.DB_STORE_NAME], 'readwrite');
  2509. var store = transaction.objectStore(IDBFS.DB_STORE_NAME);
  2510. function done(err) {
  2511. if (err) {
  2512. if (!done.errored) {
  2513. done.errored = true;
  2514. return callback(err);
  2515. }
  2516. return;
  2517. }
  2518. if (++completed >= total) {
  2519. return callback(null);
  2520. }
  2521. };
  2522. transaction.onerror = function () {
  2523. done(this.error);
  2524. };
  2525. // sort paths in ascending order so directory entries are created
  2526. // before the files inside them
  2527. create.sort().forEach(function (path) {
  2528. if (dst.type === 'local') {
  2529. IDBFS.loadRemoteEntry(store, path, function (err, entry) {
  2530. if (err) return done(err);
  2531. IDBFS.storeLocalEntry(path, entry, done);
  2532. });
  2533. } else {
  2534. IDBFS.loadLocalEntry(path, function (err, entry) {
  2535. if (err) return done(err);
  2536. IDBFS.storeRemoteEntry(store, path, entry, done);
  2537. });
  2538. }
  2539. });
  2540. // sort paths in descending order so files are deleted before their
  2541. // parent directories
  2542. remove.sort().reverse().forEach(function (path) {
  2543. if (dst.type === 'local') {
  2544. IDBFS.removeLocalEntry(path, done);
  2545. } else {
  2546. IDBFS.removeRemoteEntry(store, path, done);
  2547. }
  2548. });
  2549. }
  2550. };
  2551. var NODEFS = {
  2552. isWindows: false,
  2553. staticInit: function () {
  2554. NODEFS.isWindows = !!process.platform.match(/^win/);
  2555. },
  2556. mount: function (mount) {
  2557. assert(ENVIRONMENT_IS_NODE);
  2558. return NODEFS.createNode(null, '/', NODEFS.getMode(mount.opts.root), 0);
  2559. },
  2560. createNode: function (parent, name, mode, dev) {
  2561. if (!FS.isDir(mode) && !FS.isFile(mode) && !FS.isLink(mode)) {
  2562. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  2563. }
  2564. var node = FS.createNode(parent, name, mode);
  2565. node.node_ops = NODEFS.node_ops;
  2566. node.stream_ops = NODEFS.stream_ops;
  2567. return node;
  2568. },
  2569. getMode: function (path) {
  2570. var stat;
  2571. try {
  2572. stat = fs.lstatSync(path);
  2573. if (NODEFS.isWindows) {
  2574. // On Windows, directories return permission bits 'rw-rw-rw-', even though they have 'rwxrwxrwx', so
  2575. // propagate write bits to execute bits.
  2576. stat.mode = stat.mode | ((stat.mode & 146) >> 1);
  2577. }
  2578. } catch (e) {
  2579. if (!e.code) throw e;
  2580. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2581. }
  2582. return stat.mode;
  2583. },
  2584. realPath: function (node) {
  2585. var parts = [];
  2586. while (node.parent !== node) {
  2587. parts.push(node.name);
  2588. node = node.parent;
  2589. }
  2590. parts.push(node.mount.opts.root);
  2591. parts.reverse();
  2592. return PATH.join.apply(null, parts);
  2593. },
  2594. flagsToPermissionStringMap: {
  2595. 0: "r",
  2596. 1: "r+",
  2597. 2: "r+",
  2598. 64: "r",
  2599. 65: "r+",
  2600. 66: "r+",
  2601. 129: "rx+",
  2602. 193: "rx+",
  2603. 514: "w+",
  2604. 577: "w",
  2605. 578: "w+",
  2606. 705: "wx",
  2607. 706: "wx+",
  2608. 1024: "a",
  2609. 1025: "a",
  2610. 1026: "a+",
  2611. 1089: "a",
  2612. 1090: "a+",
  2613. 1153: "ax",
  2614. 1154: "ax+",
  2615. 1217: "ax",
  2616. 1218: "ax+",
  2617. 4096: "rs",
  2618. 4098: "rs+"
  2619. },
  2620. flagsToPermissionString: function (flags) {
  2621. if (flags in NODEFS.flagsToPermissionStringMap) {
  2622. return NODEFS.flagsToPermissionStringMap[flags];
  2623. } else {
  2624. return flags;
  2625. }
  2626. },
  2627. node_ops: {
  2628. getattr: function (node) {
  2629. var path = NODEFS.realPath(node);
  2630. var stat;
  2631. try {
  2632. stat = fs.lstatSync(path);
  2633. } catch (e) {
  2634. if (!e.code) throw e;
  2635. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2636. }
  2637. // node.js v0.10.20 doesn't report blksize and blocks on Windows. Fake them with default blksize of 4096.
  2638. // See http://support.microsoft.com/kb/140365
  2639. if (NODEFS.isWindows && !stat.blksize) {
  2640. stat.blksize = 4096;
  2641. }
  2642. if (NODEFS.isWindows && !stat.blocks) {
  2643. stat.blocks = (stat.size + stat.blksize - 1) / stat.blksize | 0;
  2644. }
  2645. return {
  2646. dev: stat.dev,
  2647. ino: stat.ino,
  2648. mode: stat.mode,
  2649. nlink: stat.nlink,
  2650. uid: stat.uid,
  2651. gid: stat.gid,
  2652. rdev: stat.rdev,
  2653. size: stat.size,
  2654. atime: stat.atime,
  2655. mtime: stat.mtime,
  2656. ctime: stat.ctime,
  2657. blksize: stat.blksize,
  2658. blocks: stat.blocks
  2659. };
  2660. },
  2661. setattr: function (node, attr) {
  2662. var path = NODEFS.realPath(node);
  2663. try {
  2664. if (attr.mode !== undefined) {
  2665. fs.chmodSync(path, attr.mode);
  2666. // update the common node structure mode as well
  2667. node.mode = attr.mode;
  2668. }
  2669. if (attr.timestamp !== undefined) {
  2670. var date = new Date(attr.timestamp);
  2671. fs.utimesSync(path, date, date);
  2672. }
  2673. if (attr.size !== undefined) {
  2674. fs.truncateSync(path, attr.size);
  2675. }
  2676. } catch (e) {
  2677. if (!e.code) throw e;
  2678. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2679. }
  2680. },
  2681. lookup: function (parent, name) {
  2682. var path = PATH.join2(NODEFS.realPath(parent), name);
  2683. var mode = NODEFS.getMode(path);
  2684. return NODEFS.createNode(parent, name, mode);
  2685. },
  2686. mknod: function (parent, name, mode, dev) {
  2687. var node = NODEFS.createNode(parent, name, mode, dev);
  2688. // create the backing node for this in the fs root as well
  2689. var path = NODEFS.realPath(node);
  2690. try {
  2691. if (FS.isDir(node.mode)) {
  2692. fs.mkdirSync(path, node.mode);
  2693. } else {
  2694. fs.writeFileSync(path, '', {
  2695. mode: node.mode
  2696. });
  2697. }
  2698. } catch (e) {
  2699. if (!e.code) throw e;
  2700. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2701. }
  2702. return node;
  2703. },
  2704. rename: function (oldNode, newDir, newName) {
  2705. var oldPath = NODEFS.realPath(oldNode);
  2706. var newPath = PATH.join2(NODEFS.realPath(newDir), newName);
  2707. try {
  2708. fs.renameSync(oldPath, newPath);
  2709. } catch (e) {
  2710. if (!e.code) throw e;
  2711. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2712. }
  2713. },
  2714. unlink: function (parent, name) {
  2715. var path = PATH.join2(NODEFS.realPath(parent), name);
  2716. try {
  2717. fs.unlinkSync(path);
  2718. } catch (e) {
  2719. if (!e.code) throw e;
  2720. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2721. }
  2722. },
  2723. rmdir: function (parent, name) {
  2724. var path = PATH.join2(NODEFS.realPath(parent), name);
  2725. try {
  2726. fs.rmdirSync(path);
  2727. } catch (e) {
  2728. if (!e.code) throw e;
  2729. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2730. }
  2731. },
  2732. readdir: function (node) {
  2733. var path = NODEFS.realPath(node);
  2734. try {
  2735. return fs.readdirSync(path);
  2736. } catch (e) {
  2737. if (!e.code) throw e;
  2738. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2739. }
  2740. },
  2741. symlink: function (parent, newName, oldPath) {
  2742. var newPath = PATH.join2(NODEFS.realPath(parent), newName);
  2743. try {
  2744. fs.symlinkSync(oldPath, newPath);
  2745. } catch (e) {
  2746. if (!e.code) throw e;
  2747. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2748. }
  2749. },
  2750. readlink: function (node) {
  2751. var path = NODEFS.realPath(node);
  2752. try {
  2753. return fs.readlinkSync(path);
  2754. } catch (e) {
  2755. if (!e.code) throw e;
  2756. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2757. }
  2758. }
  2759. },
  2760. stream_ops: {
  2761. open: function (stream) {
  2762. var path = NODEFS.realPath(stream.node);
  2763. try {
  2764. if (FS.isFile(stream.node.mode)) {
  2765. stream.nfd = fs.openSync(path, NODEFS.flagsToPermissionString(stream.flags));
  2766. }
  2767. } catch (e) {
  2768. if (!e.code) throw e;
  2769. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2770. }
  2771. },
  2772. close: function (stream) {
  2773. try {
  2774. if (FS.isFile(stream.node.mode) && stream.nfd) {
  2775. fs.closeSync(stream.nfd);
  2776. }
  2777. } catch (e) {
  2778. if (!e.code) throw e;
  2779. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2780. }
  2781. },
  2782. read: function (stream, buffer, offset, length, position) {
  2783. // FIXME this is terrible.
  2784. var nbuffer = new Buffer(length);
  2785. var res;
  2786. try {
  2787. res = fs.readSync(stream.nfd, nbuffer, 0, length, position);
  2788. } catch (e) {
  2789. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2790. }
  2791. if (res > 0) {
  2792. for (var i = 0; i < res; i++) {
  2793. buffer[offset + i] = nbuffer[i];
  2794. }
  2795. }
  2796. return res;
  2797. },
  2798. write: function (stream, buffer, offset, length, position) {
  2799. // FIXME this is terrible.
  2800. var nbuffer = new Buffer(buffer.subarray(offset, offset + length));
  2801. var res;
  2802. try {
  2803. res = fs.writeSync(stream.nfd, nbuffer, 0, length, position);
  2804. } catch (e) {
  2805. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2806. }
  2807. return res;
  2808. },
  2809. llseek: function (stream, offset, whence) {
  2810. var position = offset;
  2811. if (whence === 1) { // SEEK_CUR.
  2812. position += stream.position;
  2813. } else if (whence === 2) { // SEEK_END.
  2814. if (FS.isFile(stream.node.mode)) {
  2815. try {
  2816. var stat = fs.fstatSync(stream.nfd);
  2817. position += stat.size;
  2818. } catch (e) {
  2819. throw new FS.ErrnoError(ERRNO_CODES[e.code]);
  2820. }
  2821. }
  2822. }
  2823. if (position < 0) {
  2824. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  2825. }
  2826. stream.position = position;
  2827. return position;
  2828. }
  2829. }
  2830. };
  2831. var _stdin = allocate(1, "i32*", ALLOC_STATIC);
  2832. var _stdout = allocate(1, "i32*", ALLOC_STATIC);
  2833. var _stderr = allocate(1, "i32*", ALLOC_STATIC);
  2834. function _fflush(stream) {
  2835. // int fflush(FILE *stream);
  2836. // http://pubs.opengroup.org/onlinepubs/000095399/functions/fflush.html
  2837. // we don't currently perform any user-space buffering of data
  2838. }
  2839. var FS = {
  2840. root: null,
  2841. mounts: [],
  2842. devices: [null],
  2843. streams: [],
  2844. nextInode: 1,
  2845. nameTable: null,
  2846. currentPath: "/",
  2847. initialized: false,
  2848. ignorePermissions: true,
  2849. ErrnoError: null,
  2850. genericErrors: {},
  2851. handleFSError: function (e) {
  2852. if (!(e instanceof FS.ErrnoError)) throw e + ' : ' + stackTrace();
  2853. return ___setErrNo(e.errno);
  2854. },
  2855. lookupPath: function (path, opts) {
  2856. path = PATH.resolve(FS.cwd(), path);
  2857. opts = opts || {};
  2858. var defaults = {
  2859. follow_mount: true,
  2860. recurse_count: 0
  2861. };
  2862. for (var key in defaults) {
  2863. if (opts[key] === undefined) {
  2864. opts[key] = defaults[key];
  2865. }
  2866. }
  2867. if (opts.recurse_count > 8) { // max recursive lookup of 8
  2868. throw new FS.ErrnoError(ERRNO_CODES.ELOOP);
  2869. }
  2870. // split the path
  2871. var parts = PATH.normalizeArray(path.split('/').filter(function (p) {
  2872. return !!p;
  2873. }), false);
  2874. // start at the root
  2875. var current = FS.root;
  2876. var current_path = '/';
  2877. for (var i = 0; i < parts.length; i++) {
  2878. var islast = (i === parts.length - 1);
  2879. if (islast && opts.parent) {
  2880. // stop resolving
  2881. break;
  2882. }
  2883. current = FS.lookupNode(current, parts[i]);
  2884. current_path = PATH.join2(current_path, parts[i]);
  2885. // jump to the mount's root node if this is a mountpoint
  2886. if (FS.isMountpoint(current)) {
  2887. if (!islast || (islast && opts.follow_mount)) {
  2888. current = current.mounted.root;
  2889. }
  2890. }
  2891. // by default, lookupPath will not follow a symlink if it is the final path component.
  2892. // setting opts.follow = true will override this behavior.
  2893. if (!islast || opts.follow) {
  2894. var count = 0;
  2895. while (FS.isLink(current.mode)) {
  2896. var link = FS.readlink(current_path);
  2897. current_path = PATH.resolve(PATH.dirname(current_path), link);
  2898. var lookup = FS.lookupPath(current_path, {
  2899. recurse_count: opts.recurse_count
  2900. });
  2901. current = lookup.node;
  2902. if (count++ > 40) { // limit max consecutive symlinks to 40 (SYMLOOP_MAX).
  2903. throw new FS.ErrnoError(ERRNO_CODES.ELOOP);
  2904. }
  2905. }
  2906. }
  2907. }
  2908. return {
  2909. path: current_path,
  2910. node: current
  2911. };
  2912. },
  2913. getPath: function (node) {
  2914. var path;
  2915. while (true) {
  2916. if (FS.isRoot(node)) {
  2917. var mount = node.mount.mountpoint;
  2918. if (!path) return mount;
  2919. return mount[mount.length - 1] !== '/' ? mount + '/' + path : mount + path;
  2920. }
  2921. path = path ? node.name + '/' + path : node.name;
  2922. node = node.parent;
  2923. }
  2924. },
  2925. hashName: function (parentid, name) {
  2926. var hash = 0;
  2927. for (var i = 0; i < name.length; i++) {
  2928. hash = ((hash << 5) - hash + name.charCodeAt(i)) | 0;
  2929. }
  2930. return ((parentid + hash) >>> 0) % FS.nameTable.length;
  2931. },
  2932. hashAddNode: function (node) {
  2933. var hash = FS.hashName(node.parent.id, node.name);
  2934. node.name_next = FS.nameTable[hash];
  2935. FS.nameTable[hash] = node;
  2936. },
  2937. hashRemoveNode: function (node) {
  2938. var hash = FS.hashName(node.parent.id, node.name);
  2939. if (FS.nameTable[hash] === node) {
  2940. FS.nameTable[hash] = node.name_next;
  2941. } else {
  2942. var current = FS.nameTable[hash];
  2943. while (current) {
  2944. if (current.name_next === node) {
  2945. current.name_next = node.name_next;
  2946. break;
  2947. }
  2948. current = current.name_next;
  2949. }
  2950. }
  2951. },
  2952. lookupNode: function (parent, name) {
  2953. var err = FS.mayLookup(parent);
  2954. if (err) {
  2955. throw new FS.ErrnoError(err);
  2956. }
  2957. var hash = FS.hashName(parent.id, name);
  2958. for (var node = FS.nameTable[hash]; node; node = node.name_next) {
  2959. var nodeName = node.name;
  2960. if (node.parent.id === parent.id && nodeName === name) {
  2961. return node;
  2962. }
  2963. }
  2964. // if we failed to find it in the cache, call into the VFS
  2965. return FS.lookup(parent, name);
  2966. },
  2967. createNode: function (parent, name, mode, rdev) {
  2968. if (!FS.FSNode) {
  2969. FS.FSNode = function (parent, name, mode, rdev) {
  2970. if (!parent) {
  2971. parent = this; // root node sets parent to itself
  2972. }
  2973. this.parent = parent;
  2974. this.mount = parent.mount;
  2975. this.mounted = null;
  2976. this.id = FS.nextInode++;
  2977. this.name = name;
  2978. this.mode = mode;
  2979. this.node_ops = {};
  2980. this.stream_ops = {};
  2981. this.rdev = rdev;
  2982. };
  2983. FS.FSNode.prototype = {};
  2984. // compatibility
  2985. var readMode = 292 | 73;
  2986. var writeMode = 146;
  2987. // NOTE we must use Object.defineProperties instead of individual calls to
  2988. // Object.defineProperty in order to make closure compiler happy
  2989. Object.defineProperties(FS.FSNode.prototype, {
  2990. read: {
  2991. get: function () {
  2992. return (this.mode & readMode) === readMode;
  2993. },
  2994. set: function (val) {
  2995. val ? this.mode |= readMode : this.mode &= ~readMode;
  2996. }
  2997. },
  2998. write: {
  2999. get: function () {
  3000. return (this.mode & writeMode) === writeMode;
  3001. },
  3002. set: function (val) {
  3003. val ? this.mode |= writeMode : this.mode &= ~writeMode;
  3004. }
  3005. },
  3006. isFolder: {
  3007. get: function () {
  3008. return FS.isDir(this.mode);
  3009. },
  3010. },
  3011. isDevice: {
  3012. get: function () {
  3013. return FS.isChrdev(this.mode);
  3014. },
  3015. },
  3016. });
  3017. }
  3018. var node = new FS.FSNode(parent, name, mode, rdev);
  3019. FS.hashAddNode(node);
  3020. return node;
  3021. },
  3022. destroyNode: function (node) {
  3023. FS.hashRemoveNode(node);
  3024. },
  3025. isRoot: function (node) {
  3026. return node === node.parent;
  3027. },
  3028. isMountpoint: function (node) {
  3029. return !!node.mounted;
  3030. },
  3031. isFile: function (mode) {
  3032. return (mode & 61440) === 32768;
  3033. },
  3034. isDir: function (mode) {
  3035. return (mode & 61440) === 16384;
  3036. },
  3037. isLink: function (mode) {
  3038. return (mode & 61440) === 40960;
  3039. },
  3040. isChrdev: function (mode) {
  3041. return (mode & 61440) === 8192;
  3042. },
  3043. isBlkdev: function (mode) {
  3044. return (mode & 61440) === 24576;
  3045. },
  3046. isFIFO: function (mode) {
  3047. return (mode & 61440) === 4096;
  3048. },
  3049. isSocket: function (mode) {
  3050. return (mode & 49152) === 49152;
  3051. },
  3052. flagModes: {
  3053. "r": 0,
  3054. "rs": 1052672,
  3055. "r+": 2,
  3056. "w": 577,
  3057. "wx": 705,
  3058. "xw": 705,
  3059. "w+": 578,
  3060. "wx+": 706,
  3061. "xw+": 706,
  3062. "a": 1089,
  3063. "ax": 1217,
  3064. "xa": 1217,
  3065. "a+": 1090,
  3066. "ax+": 1218,
  3067. "xa+": 1218
  3068. },
  3069. modeStringToFlags: function (str) {
  3070. var flags = FS.flagModes[str];
  3071. if (typeof flags === 'undefined') {
  3072. throw new Error('Unknown file open mode: ' + str);
  3073. }
  3074. return flags;
  3075. },
  3076. flagsToPermissionString: function (flag) {
  3077. var accmode = flag & 2097155;
  3078. var perms = ['r', 'w', 'rw'][accmode];
  3079. if ((flag & 512)) {
  3080. perms += 'w';
  3081. }
  3082. return perms;
  3083. },
  3084. nodePermissions: function (node, perms) {
  3085. if (FS.ignorePermissions) {
  3086. return 0;
  3087. }
  3088. // return 0 if any user, group or owner bits are set.
  3089. if (perms.indexOf('r') !== -1 && !(node.mode & 292)) {
  3090. return ERRNO_CODES.EACCES;
  3091. } else if (perms.indexOf('w') !== -1 && !(node.mode & 146)) {
  3092. return ERRNO_CODES.EACCES;
  3093. } else if (perms.indexOf('x') !== -1 && !(node.mode & 73)) {
  3094. return ERRNO_CODES.EACCES;
  3095. }
  3096. return 0;
  3097. },
  3098. mayLookup: function (dir) {
  3099. return FS.nodePermissions(dir, 'x');
  3100. },
  3101. mayCreate: function (dir, name) {
  3102. try {
  3103. var node = FS.lookupNode(dir, name);
  3104. return ERRNO_CODES.EEXIST;
  3105. } catch (e) {}
  3106. return FS.nodePermissions(dir, 'wx');
  3107. },
  3108. mayDelete: function (dir, name, isdir) {
  3109. var node;
  3110. try {
  3111. node = FS.lookupNode(dir, name);
  3112. } catch (e) {
  3113. return e.errno;
  3114. }
  3115. var err = FS.nodePermissions(dir, 'wx');
  3116. if (err) {
  3117. return err;
  3118. }
  3119. if (isdir) {
  3120. if (!FS.isDir(node.mode)) {
  3121. return ERRNO_CODES.ENOTDIR;
  3122. }
  3123. if (FS.isRoot(node) || FS.getPath(node) === FS.cwd()) {
  3124. return ERRNO_CODES.EBUSY;
  3125. }
  3126. } else {
  3127. if (FS.isDir(node.mode)) {
  3128. return ERRNO_CODES.EISDIR;
  3129. }
  3130. }
  3131. return 0;
  3132. },
  3133. mayOpen: function (node, flags) {
  3134. if (!node) {
  3135. return ERRNO_CODES.ENOENT;
  3136. }
  3137. if (FS.isLink(node.mode)) {
  3138. return ERRNO_CODES.ELOOP;
  3139. } else if (FS.isDir(node.mode)) {
  3140. if ((flags & 2097155) !== 0 || // opening for write
  3141. (flags & 512)) {
  3142. return ERRNO_CODES.EISDIR;
  3143. }
  3144. }
  3145. return FS.nodePermissions(node, FS.flagsToPermissionString(flags));
  3146. },
  3147. MAX_OPEN_FDS: 4096,
  3148. nextfd: function (fd_start, fd_end) {
  3149. fd_start = fd_start || 0;
  3150. fd_end = fd_end || FS.MAX_OPEN_FDS;
  3151. for (var fd = fd_start; fd <= fd_end; fd++) {
  3152. if (!FS.streams[fd]) {
  3153. return fd;
  3154. }
  3155. }
  3156. throw new FS.ErrnoError(ERRNO_CODES.EMFILE);
  3157. },
  3158. getStream: function (fd) {
  3159. return FS.streams[fd];
  3160. },
  3161. createStream: function (stream, fd_start, fd_end) {
  3162. if (!FS.FSStream) {
  3163. FS.FSStream = function () {};
  3164. FS.FSStream.prototype = {};
  3165. // compatibility
  3166. Object.defineProperties(FS.FSStream.prototype, {
  3167. object: {
  3168. get: function () {
  3169. return this.node;
  3170. },
  3171. set: function (val) {
  3172. this.node = val;
  3173. }
  3174. },
  3175. isRead: {
  3176. get: function () {
  3177. return (this.flags & 2097155) !== 1;
  3178. }
  3179. },
  3180. isWrite: {
  3181. get: function () {
  3182. return (this.flags & 2097155) !== 0;
  3183. }
  3184. },
  3185. isAppend: {
  3186. get: function () {
  3187. return (this.flags & 1024);
  3188. }
  3189. }
  3190. });
  3191. }
  3192. if (stream.__proto__) {
  3193. // reuse the object
  3194. stream.__proto__ = FS.FSStream.prototype;
  3195. } else {
  3196. var newStream = new FS.FSStream();
  3197. for (var p in stream) {
  3198. newStream[p] = stream[p];
  3199. }
  3200. stream = newStream;
  3201. }
  3202. var fd = FS.nextfd(fd_start, fd_end);
  3203. stream.fd = fd;
  3204. FS.streams[fd] = stream;
  3205. return stream;
  3206. },
  3207. closeStream: function (fd) {
  3208. FS.streams[fd] = null;
  3209. },
  3210. getStreamFromPtr: function (ptr) {
  3211. return FS.streams[ptr - 1];
  3212. },
  3213. getPtrForStream: function (stream) {
  3214. return stream ? stream.fd + 1 : 0;
  3215. },
  3216. chrdev_stream_ops: {
  3217. open: function (stream) {
  3218. var device = FS.getDevice(stream.node.rdev);
  3219. // override node's stream ops with the device's
  3220. stream.stream_ops = device.stream_ops;
  3221. // forward the open call
  3222. if (stream.stream_ops.open) {
  3223. stream.stream_ops.open(stream);
  3224. }
  3225. },
  3226. llseek: function () {
  3227. throw new FS.ErrnoError(ERRNO_CODES.ESPIPE);
  3228. }
  3229. },
  3230. major: function (dev) {
  3231. return ((dev) >> 8);
  3232. },
  3233. minor: function (dev) {
  3234. return ((dev) & 0xff);
  3235. },
  3236. makedev: function (ma, mi) {
  3237. return ((ma) << 8 | (mi));
  3238. },
  3239. registerDevice: function (dev, ops) {
  3240. FS.devices[dev] = {
  3241. stream_ops: ops
  3242. };
  3243. },
  3244. getDevice: function (dev) {
  3245. return FS.devices[dev];
  3246. },
  3247. getMounts: function (mount) {
  3248. var mounts = [];
  3249. var check = [mount];
  3250. while (check.length) {
  3251. var m = check.pop();
  3252. mounts.push(m);
  3253. check.push.apply(check, m.mounts);
  3254. }
  3255. return mounts;
  3256. },
  3257. syncfs: function (populate, callback) {
  3258. if (typeof (populate) === 'function') {
  3259. callback = populate;
  3260. populate = false;
  3261. }
  3262. var mounts = FS.getMounts(FS.root.mount);
  3263. var completed = 0;
  3264. function done(err) {
  3265. if (err) {
  3266. if (!done.errored) {
  3267. done.errored = true;
  3268. return callback(err);
  3269. }
  3270. return;
  3271. }
  3272. if (++completed >= mounts.length) {
  3273. callback(null);
  3274. }
  3275. };
  3276. // sync all mounts
  3277. mounts.forEach(function (mount) {
  3278. if (!mount.type.syncfs) {
  3279. return done(null);
  3280. }
  3281. mount.type.syncfs(mount, populate, done);
  3282. });
  3283. },
  3284. mount: function (type, opts, mountpoint) {
  3285. var root = mountpoint === '/';
  3286. var pseudo = !mountpoint;
  3287. var node;
  3288. if (root && FS.root) {
  3289. throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
  3290. } else if (!root && !pseudo) {
  3291. var lookup = FS.lookupPath(mountpoint, {
  3292. follow_mount: false
  3293. });
  3294. mountpoint = lookup.path; // use the absolute path
  3295. node = lookup.node;
  3296. if (FS.isMountpoint(node)) {
  3297. throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
  3298. }
  3299. if (!FS.isDir(node.mode)) {
  3300. throw new FS.ErrnoError(ERRNO_CODES.ENOTDIR);
  3301. }
  3302. }
  3303. var mount = {
  3304. type: type,
  3305. opts: opts,
  3306. mountpoint: mountpoint,
  3307. mounts: []
  3308. };
  3309. // create a root node for the fs
  3310. var mountRoot = type.mount(mount);
  3311. mountRoot.mount = mount;
  3312. mount.root = mountRoot;
  3313. if (root) {
  3314. FS.root = mountRoot;
  3315. } else if (node) {
  3316. // set as a mountpoint
  3317. node.mounted = mount;
  3318. // add the new mount to the current mount's children
  3319. if (node.mount) {
  3320. node.mount.mounts.push(mount);
  3321. }
  3322. }
  3323. return mountRoot;
  3324. },
  3325. unmount: function (mountpoint) {
  3326. var lookup = FS.lookupPath(mountpoint, {
  3327. follow_mount: false
  3328. });
  3329. if (!FS.isMountpoint(lookup.node)) {
  3330. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  3331. }
  3332. // destroy the nodes for this mount, and all its child mounts
  3333. var node = lookup.node;
  3334. var mount = node.mounted;
  3335. var mounts = FS.getMounts(mount);
  3336. Object.keys(FS.nameTable).forEach(function (hash) {
  3337. var current = FS.nameTable[hash];
  3338. while (current) {
  3339. var next = current.name_next;
  3340. if (mounts.indexOf(current.mount) !== -1) {
  3341. FS.destroyNode(current);
  3342. }
  3343. current = next;
  3344. }
  3345. });
  3346. // no longer a mountpoint
  3347. node.mounted = null;
  3348. // remove this mount from the child mounts
  3349. var idx = node.mount.mounts.indexOf(mount);
  3350. assert(idx !== -1);
  3351. node.mount.mounts.splice(idx, 1);
  3352. },
  3353. lookup: function (parent, name) {
  3354. return parent.node_ops.lookup(parent, name);
  3355. },
  3356. mknod: function (path, mode, dev) {
  3357. var lookup = FS.lookupPath(path, {
  3358. parent: true
  3359. });
  3360. var parent = lookup.node;
  3361. var name = PATH.basename(path);
  3362. var err = FS.mayCreate(parent, name);
  3363. if (err) {
  3364. throw new FS.ErrnoError(err);
  3365. }
  3366. if (!parent.node_ops.mknod) {
  3367. throw new FS.ErrnoError(ERRNO_CODES.EPERM);
  3368. }
  3369. return parent.node_ops.mknod(parent, name, mode, dev);
  3370. },
  3371. create: function (path, mode) {
  3372. mode = mode !== undefined ? mode : 438 /* 0666 */ ;
  3373. mode &= 4095;
  3374. mode |= 32768;
  3375. return FS.mknod(path, mode, 0);
  3376. },
  3377. mkdir: function (path, mode) {
  3378. mode = mode !== undefined ? mode : 511 /* 0777 */ ;
  3379. mode &= 511 | 512;
  3380. mode |= 16384;
  3381. return FS.mknod(path, mode, 0);
  3382. },
  3383. mkdev: function (path, mode, dev) {
  3384. if (typeof (dev) === 'undefined') {
  3385. dev = mode;
  3386. mode = 438 /* 0666 */ ;
  3387. }
  3388. mode |= 8192;
  3389. return FS.mknod(path, mode, dev);
  3390. },
  3391. symlink: function (oldpath, newpath) {
  3392. var lookup = FS.lookupPath(newpath, {
  3393. parent: true
  3394. });
  3395. var parent = lookup.node;
  3396. var newname = PATH.basename(newpath);
  3397. var err = FS.mayCreate(parent, newname);
  3398. if (err) {
  3399. throw new FS.ErrnoError(err);
  3400. }
  3401. if (!parent.node_ops.symlink) {
  3402. throw new FS.ErrnoError(ERRNO_CODES.EPERM);
  3403. }
  3404. return parent.node_ops.symlink(parent, newname, oldpath);
  3405. },
  3406. rename: function (old_path, new_path) {
  3407. var old_dirname = PATH.dirname(old_path);
  3408. var new_dirname = PATH.dirname(new_path);
  3409. var old_name = PATH.basename(old_path);
  3410. var new_name = PATH.basename(new_path);
  3411. // parents must exist
  3412. var lookup, old_dir, new_dir;
  3413. try {
  3414. lookup = FS.lookupPath(old_path, {
  3415. parent: true
  3416. });
  3417. old_dir = lookup.node;
  3418. lookup = FS.lookupPath(new_path, {
  3419. parent: true
  3420. });
  3421. new_dir = lookup.node;
  3422. } catch (e) {
  3423. throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
  3424. }
  3425. // need to be part of the same mount
  3426. if (old_dir.mount !== new_dir.mount) {
  3427. throw new FS.ErrnoError(ERRNO_CODES.EXDEV);
  3428. }
  3429. // source must exist
  3430. var old_node = FS.lookupNode(old_dir, old_name);
  3431. // old path should not be an ancestor of the new path
  3432. var relative = PATH.relative(old_path, new_dirname);
  3433. if (relative.charAt(0) !== '.') {
  3434. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  3435. }
  3436. // new path should not be an ancestor of the old path
  3437. relative = PATH.relative(new_path, old_dirname);
  3438. if (relative.charAt(0) !== '.') {
  3439. throw new FS.ErrnoError(ERRNO_CODES.ENOTEMPTY);
  3440. }
  3441. // see if the new path already exists
  3442. var new_node;
  3443. try {
  3444. new_node = FS.lookupNode(new_dir, new_name);
  3445. } catch (e) {
  3446. // not fatal
  3447. }
  3448. // early out if nothing needs to change
  3449. if (old_node === new_node) {
  3450. return;
  3451. }
  3452. // we'll need to delete the old entry
  3453. var isdir = FS.isDir(old_node.mode);
  3454. var err = FS.mayDelete(old_dir, old_name, isdir);
  3455. if (err) {
  3456. throw new FS.ErrnoError(err);
  3457. }
  3458. // need delete permissions if we'll be overwriting.
  3459. // need create permissions if new doesn't already exist.
  3460. err = new_node ?
  3461. FS.mayDelete(new_dir, new_name, isdir) :
  3462. FS.mayCreate(new_dir, new_name);
  3463. if (err) {
  3464. throw new FS.ErrnoError(err);
  3465. }
  3466. if (!old_dir.node_ops.rename) {
  3467. throw new FS.ErrnoError(ERRNO_CODES.EPERM);
  3468. }
  3469. if (FS.isMountpoint(old_node) || (new_node && FS.isMountpoint(new_node))) {
  3470. throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
  3471. }
  3472. // if we are going to change the parent, check write permissions
  3473. if (new_dir !== old_dir) {
  3474. err = FS.nodePermissions(old_dir, 'w');
  3475. if (err) {
  3476. throw new FS.ErrnoError(err);
  3477. }
  3478. }
  3479. // remove the node from the lookup hash
  3480. FS.hashRemoveNode(old_node);
  3481. // do the underlying fs rename
  3482. try {
  3483. old_dir.node_ops.rename(old_node, new_dir, new_name);
  3484. } catch (e) {
  3485. throw e;
  3486. } finally {
  3487. // add the node back to the hash (in case node_ops.rename
  3488. // changed its name)
  3489. FS.hashAddNode(old_node);
  3490. }
  3491. },
  3492. rmdir: function (path) {
  3493. var lookup = FS.lookupPath(path, {
  3494. parent: true
  3495. });
  3496. var parent = lookup.node;
  3497. var name = PATH.basename(path);
  3498. var node = FS.lookupNode(parent, name);
  3499. var err = FS.mayDelete(parent, name, true);
  3500. if (err) {
  3501. throw new FS.ErrnoError(err);
  3502. }
  3503. if (!parent.node_ops.rmdir) {
  3504. throw new FS.ErrnoError(ERRNO_CODES.EPERM);
  3505. }
  3506. if (FS.isMountpoint(node)) {
  3507. throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
  3508. }
  3509. parent.node_ops.rmdir(parent, name);
  3510. FS.destroyNode(node);
  3511. },
  3512. readdir: function (path) {
  3513. var lookup = FS.lookupPath(path, {
  3514. follow: true
  3515. });
  3516. var node = lookup.node;
  3517. if (!node.node_ops.readdir) {
  3518. throw new FS.ErrnoError(ERRNO_CODES.ENOTDIR);
  3519. }
  3520. return node.node_ops.readdir(node);
  3521. },
  3522. unlink: function (path) {
  3523. var lookup = FS.lookupPath(path, {
  3524. parent: true
  3525. });
  3526. var parent = lookup.node;
  3527. var name = PATH.basename(path);
  3528. var node = FS.lookupNode(parent, name);
  3529. var err = FS.mayDelete(parent, name, false);
  3530. if (err) {
  3531. // POSIX says unlink should set EPERM, not EISDIR
  3532. if (err === ERRNO_CODES.EISDIR) err = ERRNO_CODES.EPERM;
  3533. throw new FS.ErrnoError(err);
  3534. }
  3535. if (!parent.node_ops.unlink) {
  3536. throw new FS.ErrnoError(ERRNO_CODES.EPERM);
  3537. }
  3538. if (FS.isMountpoint(node)) {
  3539. throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
  3540. }
  3541. parent.node_ops.unlink(parent, name);
  3542. FS.destroyNode(node);
  3543. },
  3544. readlink: function (path) {
  3545. var lookup = FS.lookupPath(path);
  3546. var link = lookup.node;
  3547. if (!link.node_ops.readlink) {
  3548. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  3549. }
  3550. return link.node_ops.readlink(link);
  3551. },
  3552. stat: function (path, dontFollow) {
  3553. var lookup = FS.lookupPath(path, {
  3554. follow: !dontFollow
  3555. });
  3556. var node = lookup.node;
  3557. if (!node.node_ops.getattr) {
  3558. throw new FS.ErrnoError(ERRNO_CODES.EPERM);
  3559. }
  3560. return node.node_ops.getattr(node);
  3561. },
  3562. lstat: function (path) {
  3563. return FS.stat(path, true);
  3564. },
  3565. chmod: function (path, mode, dontFollow) {
  3566. var node;
  3567. if (typeof path === 'string') {
  3568. var lookup = FS.lookupPath(path, {
  3569. follow: !dontFollow
  3570. });
  3571. node = lookup.node;
  3572. } else {
  3573. node = path;
  3574. }
  3575. if (!node.node_ops.setattr) {
  3576. throw new FS.ErrnoError(ERRNO_CODES.EPERM);
  3577. }
  3578. node.node_ops.setattr(node, {
  3579. mode: (mode & 4095) | (node.mode & ~4095),
  3580. timestamp: Date.now()
  3581. });
  3582. },
  3583. lchmod: function (path, mode) {
  3584. FS.chmod(path, mode, true);
  3585. },
  3586. fchmod: function (fd, mode) {
  3587. var stream = FS.getStream(fd);
  3588. if (!stream) {
  3589. throw new FS.ErrnoError(ERRNO_CODES.EBADF);
  3590. }
  3591. FS.chmod(stream.node, mode);
  3592. },
  3593. chown: function (path, uid, gid, dontFollow) {
  3594. var node;
  3595. if (typeof path === 'string') {
  3596. var lookup = FS.lookupPath(path, {
  3597. follow: !dontFollow
  3598. });
  3599. node = lookup.node;
  3600. } else {
  3601. node = path;
  3602. }
  3603. if (!node.node_ops.setattr) {
  3604. throw new FS.ErrnoError(ERRNO_CODES.EPERM);
  3605. }
  3606. node.node_ops.setattr(node, {
  3607. timestamp: Date.now()
  3608. // we ignore the uid / gid for now
  3609. });
  3610. },
  3611. lchown: function (path, uid, gid) {
  3612. FS.chown(path, uid, gid, true);
  3613. },
  3614. fchown: function (fd, uid, gid) {
  3615. var stream = FS.getStream(fd);
  3616. if (!stream) {
  3617. throw new FS.ErrnoError(ERRNO_CODES.EBADF);
  3618. }
  3619. FS.chown(stream.node, uid, gid);
  3620. },
  3621. truncate: function (path, len) {
  3622. if (len < 0) {
  3623. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  3624. }
  3625. var node;
  3626. if (typeof path === 'string') {
  3627. var lookup = FS.lookupPath(path, {
  3628. follow: true
  3629. });
  3630. node = lookup.node;
  3631. } else {
  3632. node = path;
  3633. }
  3634. if (!node.node_ops.setattr) {
  3635. throw new FS.ErrnoError(ERRNO_CODES.EPERM);
  3636. }
  3637. if (FS.isDir(node.mode)) {
  3638. throw new FS.ErrnoError(ERRNO_CODES.EISDIR);
  3639. }
  3640. if (!FS.isFile(node.mode)) {
  3641. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  3642. }
  3643. var err = FS.nodePermissions(node, 'w');
  3644. if (err) {
  3645. throw new FS.ErrnoError(err);
  3646. }
  3647. node.node_ops.setattr(node, {
  3648. size: len,
  3649. timestamp: Date.now()
  3650. });
  3651. },
  3652. ftruncate: function (fd, len) {
  3653. var stream = FS.getStream(fd);
  3654. if (!stream) {
  3655. throw new FS.ErrnoError(ERRNO_CODES.EBADF);
  3656. }
  3657. if ((stream.flags & 2097155) === 0) {
  3658. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  3659. }
  3660. FS.truncate(stream.node, len);
  3661. },
  3662. utime: function (path, atime, mtime) {
  3663. var lookup = FS.lookupPath(path, {
  3664. follow: true
  3665. });
  3666. var node = lookup.node;
  3667. node.node_ops.setattr(node, {
  3668. timestamp: Math.max(atime, mtime)
  3669. });
  3670. },
  3671. open: function (path, flags, mode, fd_start, fd_end) {
  3672. flags = typeof flags === 'string' ? FS.modeStringToFlags(flags) : flags;
  3673. mode = typeof mode === 'undefined' ? 438 /* 0666 */ : mode;
  3674. if ((flags & 64)) {
  3675. mode = (mode & 4095) | 32768;
  3676. } else {
  3677. mode = 0;
  3678. }
  3679. var node;
  3680. if (typeof path === 'object') {
  3681. node = path;
  3682. } else {
  3683. path = PATH.normalize(path);
  3684. try {
  3685. var lookup = FS.lookupPath(path, {
  3686. follow: !(flags & 131072)
  3687. });
  3688. node = lookup.node;
  3689. } catch (e) {
  3690. // ignore
  3691. }
  3692. }
  3693. // perhaps we need to create the node
  3694. if ((flags & 64)) {
  3695. if (node) {
  3696. // if O_CREAT and O_EXCL are set, error out if the node already exists
  3697. if ((flags & 128)) {
  3698. throw new FS.ErrnoError(ERRNO_CODES.EEXIST);
  3699. }
  3700. } else {
  3701. // node doesn't exist, try to create it
  3702. node = FS.mknod(path, mode, 0);
  3703. }
  3704. }
  3705. if (!node) {
  3706. throw new FS.ErrnoError(ERRNO_CODES.ENOENT);
  3707. }
  3708. // can't truncate a device
  3709. if (FS.isChrdev(node.mode)) {
  3710. flags &= ~512;
  3711. }
  3712. // check permissions
  3713. var err = FS.mayOpen(node, flags);
  3714. if (err) {
  3715. throw new FS.ErrnoError(err);
  3716. }
  3717. // do truncation if necessary
  3718. if ((flags & 512)) {
  3719. FS.truncate(node, 0);
  3720. }
  3721. // we've already handled these, don't pass down to the underlying vfs
  3722. flags &= ~(128 | 512);
  3723. // register the stream with the filesystem
  3724. var stream = FS.createStream({
  3725. node: node,
  3726. path: FS.getPath(node), // we want the absolute path to the node
  3727. flags: flags,
  3728. seekable: true,
  3729. position: 0,
  3730. stream_ops: node.stream_ops,
  3731. // used by the file family libc calls (fopen, fwrite, ferror, etc.)
  3732. ungotten: [],
  3733. error: false
  3734. }, fd_start, fd_end);
  3735. // call the new stream's open function
  3736. if (stream.stream_ops.open) {
  3737. stream.stream_ops.open(stream);
  3738. }
  3739. if (Module['logReadFiles'] && !(flags & 1)) {
  3740. if (!FS.readFiles) FS.readFiles = {};
  3741. if (!(path in FS.readFiles)) {
  3742. FS.readFiles[path] = 1;
  3743. Module['printErr']('read file: ' + path);
  3744. }
  3745. }
  3746. return stream;
  3747. },
  3748. close: function (stream) {
  3749. try {
  3750. if (stream.stream_ops.close) {
  3751. stream.stream_ops.close(stream);
  3752. }
  3753. } catch (e) {
  3754. throw e;
  3755. } finally {
  3756. FS.closeStream(stream.fd);
  3757. }
  3758. },
  3759. llseek: function (stream, offset, whence) {
  3760. if (!stream.seekable || !stream.stream_ops.llseek) {
  3761. throw new FS.ErrnoError(ERRNO_CODES.ESPIPE);
  3762. }
  3763. return stream.stream_ops.llseek(stream, offset, whence);
  3764. },
  3765. read: function (stream, buffer, offset, length, position) {
  3766. if (length < 0 || position < 0) {
  3767. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  3768. }
  3769. if ((stream.flags & 2097155) === 1) {
  3770. throw new FS.ErrnoError(ERRNO_CODES.EBADF);
  3771. }
  3772. if (FS.isDir(stream.node.mode)) {
  3773. throw new FS.ErrnoError(ERRNO_CODES.EISDIR);
  3774. }
  3775. if (!stream.stream_ops.read) {
  3776. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  3777. }
  3778. var seeking = true;
  3779. if (typeof position === 'undefined') {
  3780. position = stream.position;
  3781. seeking = false;
  3782. } else if (!stream.seekable) {
  3783. throw new FS.ErrnoError(ERRNO_CODES.ESPIPE);
  3784. }
  3785. var bytesRead = stream.stream_ops.read(stream, buffer, offset, length, position);
  3786. if (!seeking) stream.position += bytesRead;
  3787. return bytesRead;
  3788. },
  3789. write: function (stream, buffer, offset, length, position, canOwn) {
  3790. if (length < 0 || position < 0) {
  3791. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  3792. }
  3793. if ((stream.flags & 2097155) === 0) {
  3794. throw new FS.ErrnoError(ERRNO_CODES.EBADF);
  3795. }
  3796. if (FS.isDir(stream.node.mode)) {
  3797. throw new FS.ErrnoError(ERRNO_CODES.EISDIR);
  3798. }
  3799. if (!stream.stream_ops.write) {
  3800. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  3801. }
  3802. var seeking = true;
  3803. if (typeof position === 'undefined') {
  3804. position = stream.position;
  3805. seeking = false;
  3806. } else if (!stream.seekable) {
  3807. throw new FS.ErrnoError(ERRNO_CODES.ESPIPE);
  3808. }
  3809. if (stream.flags & 1024) {
  3810. // seek to the end before writing in append mode
  3811. FS.llseek(stream, 0, 2);
  3812. }
  3813. var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
  3814. if (!seeking) stream.position += bytesWritten;
  3815. return bytesWritten;
  3816. },
  3817. allocate: function (stream, offset, length) {
  3818. if (offset < 0 || length <= 0) {
  3819. throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
  3820. }
  3821. if ((stream.flags & 2097155) === 0) {
  3822. throw new FS.ErrnoError(ERRNO_CODES.EBADF);
  3823. }
  3824. if (!FS.isFile(stream.node.mode) && !FS.isDir(node.mode)) {
  3825. throw new FS.ErrnoError(ERRNO_CODES.ENODEV);
  3826. }
  3827. if (!stream.stream_ops.allocate) {
  3828. throw new FS.ErrnoError(ERRNO_CODES.EOPNOTSUPP);
  3829. }
  3830. stream.stream_ops.allocate(stream, offset, length);
  3831. },
  3832. mmap: function (stream, buffer, offset, length, position, prot, flags) {
  3833. // TODO if PROT is PROT_WRITE, make sure we have write access
  3834. if ((stream.flags & 2097155) === 1) {
  3835. throw new FS.ErrnoError(ERRNO_CODES.EACCES);
  3836. }
  3837. if (!stream.stream_ops.mmap) {
  3838. throw new FS.ErrnoError(ERRNO_CODES.ENODEV);
  3839. }
  3840. return stream.stream_ops.mmap(stream, buffer, offset, length, position, prot, flags);
  3841. },
  3842. ioctl: function (stream, cmd, arg) {
  3843. if (!stream.stream_ops.ioctl) {
  3844. throw new FS.ErrnoError(ERRNO_CODES.ENOTTY);
  3845. }
  3846. return stream.stream_ops.ioctl(stream, cmd, arg);
  3847. },
  3848. readFile: function (path, opts) {
  3849. opts = opts || {};
  3850. opts.flags = opts.flags || 'r';
  3851. opts.encoding = opts.encoding || 'binary';
  3852. if (opts.encoding !== 'utf8' && opts.encoding !== 'binary') {
  3853. throw new Error('Invalid encoding type "' + opts.encoding + '"');
  3854. }
  3855. var ret;
  3856. var stream = FS.open(path, opts.flags);
  3857. var stat = FS.stat(path);
  3858. var length = stat.size;
  3859. var buf = new Uint8Array(length);
  3860. FS.read(stream, buf, 0, length, 0);
  3861. if (opts.encoding === 'utf8') {
  3862. ret = '';
  3863. var utf8 = new Runtime.UTF8Processor();
  3864. for (var i = 0; i < length; i++) {
  3865. ret += utf8.processCChar(buf[i]);
  3866. }
  3867. } else if (opts.encoding === 'binary') {
  3868. ret = buf;
  3869. }
  3870. FS.close(stream);
  3871. return ret;
  3872. },
  3873. writeFile: function (path, data, opts) {
  3874. opts = opts || {};
  3875. opts.flags = opts.flags || 'w';
  3876. opts.encoding = opts.encoding || 'utf8';
  3877. if (opts.encoding !== 'utf8' && opts.encoding !== 'binary') {
  3878. throw new Error('Invalid encoding type "' + opts.encoding + '"');
  3879. }
  3880. var stream = FS.open(path, opts.flags, opts.mode);
  3881. if (opts.encoding === 'utf8') {
  3882. var utf8 = new Runtime.UTF8Processor();
  3883. var buf = new Uint8Array(utf8.processJSString(data));
  3884. FS.write(stream, buf, 0, buf.length, 0, opts.canOwn);
  3885. } else if (opts.encoding === 'binary') {
  3886. FS.write(stream, data, 0, data.length, 0, opts.canOwn);
  3887. }
  3888. FS.close(stream);
  3889. },
  3890. cwd: function () {
  3891. return FS.currentPath;
  3892. },
  3893. chdir: function (path) {
  3894. var lookup = FS.lookupPath(path, {
  3895. follow: true
  3896. });
  3897. if (!FS.isDir(lookup.node.mode)) {
  3898. throw new FS.ErrnoError(ERRNO_CODES.ENOTDIR);
  3899. }
  3900. var err = FS.nodePermissions(lookup.node, 'x');
  3901. if (err) {
  3902. throw new FS.ErrnoError(err);
  3903. }
  3904. FS.currentPath = lookup.path;
  3905. },
  3906. createDefaultDirectories: function () {
  3907. FS.mkdir('/tmp');
  3908. },
  3909. createDefaultDevices: function () {
  3910. // create /dev
  3911. FS.mkdir('/dev');
  3912. // setup /dev/null
  3913. FS.registerDevice(FS.makedev(1, 3), {
  3914. read: function () {
  3915. return 0;
  3916. },
  3917. write: function () {
  3918. return 0;
  3919. }
  3920. });
  3921. FS.mkdev('/dev/null', FS.makedev(1, 3));
  3922. // setup /dev/tty and /dev/tty1
  3923. // stderr needs to print output using Module['printErr']
  3924. // so we register a second tty just for it.
  3925. TTY.register(FS.makedev(5, 0), TTY.default_tty_ops);
  3926. TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops);
  3927. FS.mkdev('/dev/tty', FS.makedev(5, 0));
  3928. FS.mkdev('/dev/tty1', FS.makedev(6, 0));
  3929. // we're not going to emulate the actual shm device,
  3930. // just create the tmp dirs that reside in it commonly
  3931. FS.mkdir('/dev/shm');
  3932. FS.mkdir('/dev/shm/tmp');
  3933. },
  3934. createStandardStreams: function () {
  3935. // TODO deprecate the old functionality of a single
  3936. // input / output callback and that utilizes FS.createDevice
  3937. // and instead require a unique set of stream ops
  3938. // by default, we symlink the standard streams to the
  3939. // default tty devices. however, if the standard streams
  3940. // have been overwritten we create a unique device for
  3941. // them instead.
  3942. if (Module['stdin']) {
  3943. FS.createDevice('/dev', 'stdin', Module['stdin']);
  3944. } else {
  3945. FS.symlink('/dev/tty', '/dev/stdin');
  3946. }
  3947. if (Module['stdout']) {
  3948. FS.createDevice('/dev', 'stdout', null, Module['stdout']);
  3949. } else {
  3950. FS.symlink('/dev/tty', '/dev/stdout');
  3951. }
  3952. if (Module['stderr']) {
  3953. FS.createDevice('/dev', 'stderr', null, Module['stderr']);
  3954. } else {
  3955. FS.symlink('/dev/tty1', '/dev/stderr');
  3956. }
  3957. // open default streams for the stdin, stdout and stderr devices
  3958. var stdin = FS.open('/dev/stdin', 'r');
  3959. HEAP32[((_stdin) >> 2)] = FS.getPtrForStream(stdin);
  3960. assert(stdin.fd === 0, 'invalid handle for stdin (' + stdin.fd + ')');
  3961. var stdout = FS.open('/dev/stdout', 'w');
  3962. HEAP32[((_stdout) >> 2)] = FS.getPtrForStream(stdout);
  3963. assert(stdout.fd === 1, 'invalid handle for stdout (' + stdout.fd + ')');
  3964. var stderr = FS.open('/dev/stderr', 'w');
  3965. HEAP32[((_stderr) >> 2)] = FS.getPtrForStream(stderr);
  3966. assert(stderr.fd === 2, 'invalid handle for stderr (' + stderr.fd + ')');
  3967. },
  3968. ensureErrnoError: function () {
  3969. if (FS.ErrnoError) return;
  3970. FS.ErrnoError = function ErrnoError(errno) {
  3971. this.errno = errno;
  3972. for (var key in ERRNO_CODES) {
  3973. if (ERRNO_CODES[key] === errno) {
  3974. this.code = key;
  3975. break;
  3976. }
  3977. }
  3978. this.message = ERRNO_MESSAGES[errno];
  3979. };
  3980. FS.ErrnoError.prototype = new Error();
  3981. FS.ErrnoError.prototype.constructor = FS.ErrnoError;
  3982. // Some errors may happen quite a bit, to avoid overhead we reuse them (and suffer a lack of stack info)
  3983. [ERRNO_CODES.ENOENT].forEach(function (code) {
  3984. FS.genericErrors[code] = new FS.ErrnoError(code);
  3985. FS.genericErrors[code].stack = '<generic error, no stack>';
  3986. });
  3987. },
  3988. staticInit: function () {
  3989. FS.ensureErrnoError();
  3990. FS.nameTable = new Array(4096);
  3991. FS.mount(MEMFS, {}, '/');
  3992. FS.createDefaultDirectories();
  3993. FS.createDefaultDevices();
  3994. },
  3995. init: function (input, output, error) {
  3996. assert(!FS.init.initialized, 'FS.init was previously called. If you want to initialize later with custom parameters, remove any earlier calls (note that one is automatically added to the generated code)');
  3997. FS.init.initialized = true;
  3998. FS.ensureErrnoError();
  3999. // Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
  4000. Module['stdin'] = input || Module['stdin'];
  4001. Module['stdout'] = output || Module['stdout'];
  4002. Module['stderr'] = error || Module['stderr'];
  4003. FS.createStandardStreams();
  4004. },
  4005. quit: function () {
  4006. FS.init.initialized = false;
  4007. for (var i = 0; i < FS.streams.length; i++) {
  4008. var stream = FS.streams[i];
  4009. if (!stream) {
  4010. continue;
  4011. }
  4012. FS.close(stream);
  4013. }
  4014. },
  4015. getMode: function (canRead, canWrite) {
  4016. var mode = 0;
  4017. if (canRead) mode |= 292 | 73;
  4018. if (canWrite) mode |= 146;
  4019. return mode;
  4020. },
  4021. joinPath: function (parts, forceRelative) {
  4022. var path = PATH.join.apply(null, parts);
  4023. if (forceRelative && path[0] == '/') path = path.substr(1);
  4024. return path;
  4025. },
  4026. absolutePath: function (relative, base) {
  4027. return PATH.resolve(base, relative);
  4028. },
  4029. standardizePath: function (path) {
  4030. return PATH.normalize(path);
  4031. },
  4032. findObject: function (path, dontResolveLastLink) {
  4033. var ret = FS.analyzePath(path, dontResolveLastLink);
  4034. if (ret.exists) {
  4035. return ret.object;
  4036. } else {
  4037. ___setErrNo(ret.error);
  4038. return null;
  4039. }
  4040. },
  4041. analyzePath: function (path, dontResolveLastLink) {
  4042. // operate from within the context of the symlink's target
  4043. try {
  4044. var lookup = FS.lookupPath(path, {
  4045. follow: !dontResolveLastLink
  4046. });
  4047. path = lookup.path;
  4048. } catch (e) {}
  4049. var ret = {
  4050. isRoot: false,
  4051. exists: false,
  4052. error: 0,
  4053. name: null,
  4054. path: null,
  4055. object: null,
  4056. parentExists: false,
  4057. parentPath: null,
  4058. parentObject: null
  4059. };
  4060. try {
  4061. var lookup = FS.lookupPath(path, {
  4062. parent: true
  4063. });
  4064. ret.parentExists = true;
  4065. ret.parentPath = lookup.path;
  4066. ret.parentObject = lookup.node;
  4067. ret.name = PATH.basename(path);
  4068. lookup = FS.lookupPath(path, {
  4069. follow: !dontResolveLastLink
  4070. });
  4071. ret.exists = true;
  4072. ret.path = lookup.path;
  4073. ret.object = lookup.node;
  4074. ret.name = lookup.node.name;
  4075. ret.isRoot = lookup.path === '/';
  4076. } catch (e) {
  4077. ret.error = e.errno;
  4078. };
  4079. return ret;
  4080. },
  4081. createFolder: function (parent, name, canRead, canWrite) {
  4082. var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
  4083. var mode = FS.getMode(canRead, canWrite);
  4084. return FS.mkdir(path, mode);
  4085. },
  4086. createPath: function (parent, path, canRead, canWrite) {
  4087. parent = typeof parent === 'string' ? parent : FS.getPath(parent);
  4088. var parts = path.split('/').reverse();
  4089. while (parts.length) {
  4090. var part = parts.pop();
  4091. if (!part) continue;
  4092. var current = PATH.join2(parent, part);
  4093. try {
  4094. FS.mkdir(current);
  4095. } catch (e) {
  4096. // ignore EEXIST
  4097. }
  4098. parent = current;
  4099. }
  4100. return current;
  4101. },
  4102. createFile: function (parent, name, properties, canRead, canWrite) {
  4103. var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
  4104. var mode = FS.getMode(canRead, canWrite);
  4105. return FS.create(path, mode);
  4106. },
  4107. createDataFile: function (parent, name, data, canRead, canWrite, canOwn) {
  4108. var path = name ? PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name) : parent;
  4109. var mode = FS.getMode(canRead, canWrite);
  4110. var node = FS.create(path, mode);
  4111. if (data) {
  4112. if (typeof data === 'string') {
  4113. var arr = new Array(data.length);
  4114. for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
  4115. data = arr;
  4116. }
  4117. // make sure we can write to the file
  4118. FS.chmod(node, mode | 146);
  4119. var stream = FS.open(node, 'w');
  4120. FS.write(stream, data, 0, data.length, 0, canOwn);
  4121. FS.close(stream);
  4122. FS.chmod(node, mode);
  4123. }
  4124. return node;
  4125. },
  4126. createDevice: function (parent, name, input, output) {
  4127. var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
  4128. var mode = FS.getMode(!!input, !!output);
  4129. if (!FS.createDevice.major) FS.createDevice.major = 64;
  4130. var dev = FS.makedev(FS.createDevice.major++, 0);
  4131. // Create a fake device that a set of stream ops to emulate
  4132. // the old behavior.
  4133. FS.registerDevice(dev, {
  4134. open: function (stream) {
  4135. stream.seekable = false;
  4136. },
  4137. close: function (stream) {
  4138. // flush any pending line data
  4139. if (output && output.buffer && output.buffer.length) {
  4140. output(10);
  4141. }
  4142. },
  4143. read: function (stream, buffer, offset, length, pos /* ignored */ ) {
  4144. var bytesRead = 0;
  4145. for (var i = 0; i < length; i++) {
  4146. var result;
  4147. try {
  4148. result = input();
  4149. } catch (e) {
  4150. throw new FS.ErrnoError(ERRNO_CODES.EIO);
  4151. }
  4152. if (result === undefined && bytesRead === 0) {
  4153. throw new FS.ErrnoError(ERRNO_CODES.EAGAIN);
  4154. }
  4155. if (result === null || result === undefined) break;
  4156. bytesRead++;
  4157. buffer[offset + i] = result;
  4158. }
  4159. if (bytesRead) {
  4160. stream.node.timestamp = Date.now();
  4161. }
  4162. return bytesRead;
  4163. },
  4164. write: function (stream, buffer, offset, length, pos) {
  4165. for (var i = 0; i < length; i++) {
  4166. try {
  4167. output(buffer[offset + i]);
  4168. } catch (e) {
  4169. throw new FS.ErrnoError(ERRNO_CODES.EIO);
  4170. }
  4171. }
  4172. if (length) {
  4173. stream.node.timestamp = Date.now();
  4174. }
  4175. return i;
  4176. }
  4177. });
  4178. return FS.mkdev(path, mode, dev);
  4179. },
  4180. createLink: function (parent, name, target, canRead, canWrite) {
  4181. var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
  4182. return FS.symlink(target, path);
  4183. },
  4184. forceLoadFile: function (obj) {
  4185. if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true;
  4186. var success = true;
  4187. if (typeof XMLHttpRequest !== 'undefined') {
  4188. throw new Error("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.");
  4189. } else if (Module['read']) {
  4190. // Command-line.
  4191. try {
  4192. // WARNING: Can't read binary files in V8's d8 or tracemonkey's js, as
  4193. // read() will try to parse UTF8.
  4194. obj.contents = intArrayFromString(Module['read'](obj.url), true);
  4195. } catch (e) {
  4196. success = false;
  4197. }
  4198. } else {
  4199. throw new Error('Cannot load without read() or XMLHttpRequest.');
  4200. }
  4201. if (!success) ___setErrNo(ERRNO_CODES.EIO);
  4202. return success;
  4203. },
  4204. createLazyFile: function (parent, name, url, canRead, canWrite) {
  4205. if (typeof XMLHttpRequest !== 'undefined') {
  4206. if (!ENVIRONMENT_IS_WORKER) throw 'Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc';
  4207. // Lazy chunked Uint8Array (implements get and length from Uint8Array). Actual getting is abstracted away for eventual reuse.
  4208. function LazyUint8Array() {
  4209. this.lengthKnown = false;
  4210. this.chunks = []; // Loaded chunks. Index is the chunk number
  4211. }
  4212. LazyUint8Array.prototype.get = function LazyUint8Array_get(idx) {
  4213. if (idx > this.length - 1 || idx < 0) {
  4214. return undefined;
  4215. }
  4216. var chunkOffset = idx % this.chunkSize;
  4217. var chunkNum = Math.floor(idx / this.chunkSize);
  4218. return this.getter(chunkNum)[chunkOffset];
  4219. }
  4220. LazyUint8Array.prototype.setDataGetter = function LazyUint8Array_setDataGetter(getter) {
  4221. this.getter = getter;
  4222. }
  4223. LazyUint8Array.prototype.cacheLength = function LazyUint8Array_cacheLength() {
  4224. // Find length
  4225. var xhr = new XMLHttpRequest();
  4226. xhr.open('HEAD', url, false);
  4227. xhr.send(null);
  4228. if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
  4229. var datalength = Number(xhr.getResponseHeader("Content-length"));
  4230. var header;
  4231. var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
  4232. var chunkSize = 1024 * 1024; // Chunk size in bytes
  4233. if (!hasByteServing) chunkSize = datalength;
  4234. // Function to get a range from the remote URL.
  4235. var doXHR = (function (from, to) {
  4236. if (from > to) throw new Error("invalid range (" + from + ", " + to + ") or no bytes requested!");
  4237. if (to > datalength - 1) throw new Error("only " + datalength + " bytes available! programmer error!");
  4238. // TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
  4239. var xhr = new XMLHttpRequest();
  4240. xhr.open('GET', url, false);
  4241. if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
  4242. // Some hints to the browser that we want binary data.
  4243. if (typeof Uint8Array != 'undefined') xhr.responseType = 'arraybuffer';
  4244. if (xhr.overrideMimeType) {
  4245. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  4246. }
  4247. xhr.send(null);
  4248. if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
  4249. if (xhr.response !== undefined) {
  4250. return new Uint8Array(xhr.response || []);
  4251. } else {
  4252. return intArrayFromString(xhr.responseText || '', true);
  4253. }
  4254. });
  4255. var lazyArray = this;
  4256. lazyArray.setDataGetter(function (chunkNum) {
  4257. var start = chunkNum * chunkSize;
  4258. var end = (chunkNum + 1) * chunkSize - 1; // including this byte
  4259. end = Math.min(end, datalength - 1); // if datalength-1 is selected, this is the last block
  4260. if (typeof (lazyArray.chunks[chunkNum]) === "undefined") {
  4261. lazyArray.chunks[chunkNum] = doXHR(start, end);
  4262. }
  4263. if (typeof (lazyArray.chunks[chunkNum]) === "undefined") throw new Error("doXHR failed!");
  4264. return lazyArray.chunks[chunkNum];
  4265. });
  4266. this._length = datalength;
  4267. this._chunkSize = chunkSize;
  4268. this.lengthKnown = true;
  4269. }
  4270. var lazyArray = new LazyUint8Array();
  4271. Object.defineProperty(lazyArray, "length", {
  4272. get: function () {
  4273. if (!this.lengthKnown) {
  4274. this.cacheLength();
  4275. }
  4276. return this._length;
  4277. }
  4278. });
  4279. Object.defineProperty(lazyArray, "chunkSize", {
  4280. get: function () {
  4281. if (!this.lengthKnown) {
  4282. this.cacheLength();
  4283. }
  4284. return this._chunkSize;
  4285. }
  4286. });
  4287. var properties = {
  4288. isDevice: false,
  4289. contents: lazyArray
  4290. };
  4291. } else {
  4292. var properties = {
  4293. isDevice: false,
  4294. url: url
  4295. };
  4296. }
  4297. var node = FS.createFile(parent, name, properties, canRead, canWrite);
  4298. // This is a total hack, but I want to get this lazy file code out of the
  4299. // core of MEMFS. If we want to keep this lazy file concept I feel it should
  4300. // be its own thin LAZYFS proxying calls to MEMFS.
  4301. if (properties.contents) {
  4302. node.contents = properties.contents;
  4303. } else if (properties.url) {
  4304. node.contents = null;
  4305. node.url = properties.url;
  4306. }
  4307. // override each stream op with one that tries to force load the lazy file first
  4308. var stream_ops = {};
  4309. var keys = Object.keys(node.stream_ops);
  4310. keys.forEach(function (key) {
  4311. var fn = node.stream_ops[key];
  4312. stream_ops[key] = function forceLoadLazyFile() {
  4313. if (!FS.forceLoadFile(node)) {
  4314. throw new FS.ErrnoError(ERRNO_CODES.EIO);
  4315. }
  4316. return fn.apply(null, arguments);
  4317. };
  4318. });
  4319. // use a custom read function
  4320. stream_ops.read = function stream_ops_read(stream, buffer, offset, length, position) {
  4321. if (!FS.forceLoadFile(node)) {
  4322. throw new FS.ErrnoError(ERRNO_CODES.EIO);
  4323. }
  4324. var contents = stream.node.contents;
  4325. if (position >= contents.length)
  4326. return 0;
  4327. var size = Math.min(contents.length - position, length);
  4328. assert(size >= 0);
  4329. if (contents.slice) { // normal array
  4330. for (var i = 0; i < size; i++) {
  4331. buffer[offset + i] = contents[position + i];
  4332. }
  4333. } else {
  4334. for (var i = 0; i < size; i++) { // LazyUint8Array from sync binary XHR
  4335. buffer[offset + i] = contents.get(position + i);
  4336. }
  4337. }
  4338. return size;
  4339. };
  4340. node.stream_ops = stream_ops;
  4341. return node;
  4342. },
  4343. createPreloadedFile: function (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn) {
  4344. Browser.init();
  4345. // TODO we should allow people to just pass in a complete filename instead
  4346. // of parent and name being that we just join them anyways
  4347. var fullname = name ? PATH.resolve(PATH.join2(parent, name)) : parent;
  4348. function processData(byteArray) {
  4349. function finish(byteArray) {
  4350. if (!dontCreateFile) {
  4351. FS.createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
  4352. }
  4353. if (onload) onload();
  4354. removeRunDependency('cp ' + fullname);
  4355. }
  4356. var handled = false;
  4357. Module['preloadPlugins'].forEach(function (plugin) {
  4358. if (handled) return;
  4359. if (plugin['canHandle'](fullname)) {
  4360. plugin['handle'](byteArray, fullname, finish, function () {
  4361. if (onerror) onerror();
  4362. removeRunDependency('cp ' + fullname);
  4363. });
  4364. handled = true;
  4365. }
  4366. });
  4367. if (!handled) finish(byteArray);
  4368. }
  4369. addRunDependency('cp ' + fullname);
  4370. if (typeof url == 'string') {
  4371. Browser.asyncLoad(url, function (byteArray) {
  4372. processData(byteArray);
  4373. }, onerror);
  4374. } else {
  4375. processData(url);
  4376. }
  4377. },
  4378. indexedDB: function () {
  4379. return window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
  4380. },
  4381. DB_NAME: function () {
  4382. return 'EM_FS_' + window.location.pathname;
  4383. },
  4384. DB_VERSION: 20,
  4385. DB_STORE_NAME: "FILE_DATA",
  4386. saveFilesToDB: function (paths, onload, onerror) {
  4387. onload = onload || function () {};
  4388. onerror = onerror || function () {};
  4389. var indexedDB = FS.indexedDB();
  4390. try {
  4391. var openRequest = indexedDB.open(FS.DB_NAME(), FS.DB_VERSION);
  4392. } catch (e) {
  4393. return onerror(e);
  4394. }
  4395. openRequest.onupgradeneeded = function openRequest_onupgradeneeded() {
  4396. console.log('creating db');
  4397. var db = openRequest.result;
  4398. db.createObjectStore(FS.DB_STORE_NAME);
  4399. };
  4400. openRequest.onsuccess = function openRequest_onsuccess() {
  4401. var db = openRequest.result;
  4402. var transaction = db.transaction([FS.DB_STORE_NAME], 'readwrite');
  4403. var files = transaction.objectStore(FS.DB_STORE_NAME);
  4404. var ok = 0,
  4405. fail = 0,
  4406. total = paths.length;
  4407. function finish() {
  4408. if (fail == 0) onload();
  4409. else onerror();
  4410. }
  4411. paths.forEach(function (path) {
  4412. var putRequest = files.put(FS.analyzePath(path).object.contents, path);
  4413. putRequest.onsuccess = function putRequest_onsuccess() {
  4414. ok++;
  4415. if (ok + fail == total) finish()
  4416. };
  4417. putRequest.onerror = function putRequest_onerror() {
  4418. fail++;
  4419. if (ok + fail == total) finish()
  4420. };
  4421. });
  4422. transaction.onerror = onerror;
  4423. };
  4424. openRequest.onerror = onerror;
  4425. },
  4426. loadFilesFromDB: function (paths, onload, onerror) {
  4427. onload = onload || function () {};
  4428. onerror = onerror || function () {};
  4429. var indexedDB = FS.indexedDB();
  4430. try {
  4431. var openRequest = indexedDB.open(FS.DB_NAME(), FS.DB_VERSION);
  4432. } catch (e) {
  4433. return onerror(e);
  4434. }
  4435. openRequest.onupgradeneeded = onerror; // no database to load from
  4436. openRequest.onsuccess = function openRequest_onsuccess() {
  4437. var db = openRequest.result;
  4438. try {
  4439. var transaction = db.transaction([FS.DB_STORE_NAME], 'readonly');
  4440. } catch (e) {
  4441. onerror(e);
  4442. return;
  4443. }
  4444. var files = transaction.objectStore(FS.DB_STORE_NAME);
  4445. var ok = 0,
  4446. fail = 0,
  4447. total = paths.length;
  4448. function finish() {
  4449. if (fail == 0) onload();
  4450. else onerror();
  4451. }
  4452. paths.forEach(function (path) {
  4453. var getRequest = files.get(path);
  4454. getRequest.onsuccess = function getRequest_onsuccess() {
  4455. if (FS.analyzePath(path).exists) {
  4456. FS.unlink(path);
  4457. }
  4458. FS.createDataFile(PATH.dirname(path), PATH.basename(path), getRequest.result, true, true, true);
  4459. ok++;
  4460. if (ok + fail == total) finish();
  4461. };
  4462. getRequest.onerror = function getRequest_onerror() {
  4463. fail++;
  4464. if (ok + fail == total) finish()
  4465. };
  4466. });
  4467. transaction.onerror = onerror;
  4468. };
  4469. openRequest.onerror = onerror;
  4470. }
  4471. };
  4472. var PATH = {
  4473. splitPath: function (filename) {
  4474. var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  4475. return splitPathRe.exec(filename).slice(1);
  4476. },
  4477. normalizeArray: function (parts, allowAboveRoot) {
  4478. // if the path tries to go above the root, `up` ends up > 0
  4479. var up = 0;
  4480. for (var i = parts.length - 1; i >= 0; i--) {
  4481. var last = parts[i];
  4482. if (last === '.') {
  4483. parts.splice(i, 1);
  4484. } else if (last === '..') {
  4485. parts.splice(i, 1);
  4486. up++;
  4487. } else if (up) {
  4488. parts.splice(i, 1);
  4489. up--;
  4490. }
  4491. }
  4492. // if the path is allowed to go above the root, restore leading ..s
  4493. if (allowAboveRoot) {
  4494. for (; up--; up) {
  4495. parts.unshift('..');
  4496. }
  4497. }
  4498. return parts;
  4499. },
  4500. normalize: function (path) {
  4501. var isAbsolute = path.charAt(0) === '/',
  4502. trailingSlash = path.substr(-1) === '/';
  4503. // Normalize the path
  4504. path = PATH.normalizeArray(path.split('/').filter(function (p) {
  4505. return !!p;
  4506. }), !isAbsolute).join('/');
  4507. if (!path && !isAbsolute) {
  4508. path = '.';
  4509. }
  4510. if (path && trailingSlash) {
  4511. path += '/';
  4512. }
  4513. return (isAbsolute ? '/' : '') + path;
  4514. },
  4515. dirname: function (path) {
  4516. var result = PATH.splitPath(path),
  4517. root = result[0],
  4518. dir = result[1];
  4519. if (!root && !dir) {
  4520. // No dirname whatsoever
  4521. return '.';
  4522. }
  4523. if (dir) {
  4524. // It has a dirname, strip trailing slash
  4525. dir = dir.substr(0, dir.length - 1);
  4526. }
  4527. return root + dir;
  4528. },
  4529. basename: function (path) {
  4530. // EMSCRIPTEN return '/'' for '/', not an empty string
  4531. if (path === '/') return '/';
  4532. var lastSlash = path.lastIndexOf('/');
  4533. if (lastSlash === -1) return path;
  4534. return path.substr(lastSlash + 1);
  4535. },
  4536. extname: function (path) {
  4537. return PATH.splitPath(path)[3];
  4538. },
  4539. join: function () {
  4540. var paths = Array.prototype.slice.call(arguments, 0);
  4541. return PATH.normalize(paths.join('/'));
  4542. },
  4543. join2: function (l, r) {
  4544. return PATH.normalize(l + '/' + r);
  4545. },
  4546. resolve: function () {
  4547. var resolvedPath = '',
  4548. resolvedAbsolute = false;
  4549. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  4550. var path = (i >= 0) ? arguments[i] : FS.cwd();
  4551. // Skip empty and invalid entries
  4552. if (typeof path !== 'string') {
  4553. throw new TypeError('Arguments to path.resolve must be strings');
  4554. } else if (!path) {
  4555. continue;
  4556. }
  4557. resolvedPath = path + '/' + resolvedPath;
  4558. resolvedAbsolute = path.charAt(0) === '/';
  4559. }
  4560. // At this point the path should be resolved to a full absolute path, but
  4561. // handle relative paths to be safe (might happen when process.cwd() fails)
  4562. resolvedPath = PATH.normalizeArray(resolvedPath.split('/').filter(function (p) {
  4563. return !!p;
  4564. }), !resolvedAbsolute).join('/');
  4565. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  4566. },
  4567. relative: function (from, to) {
  4568. from = PATH.resolve(from).substr(1);
  4569. to = PATH.resolve(to).substr(1);
  4570. function trim(arr) {
  4571. var start = 0;
  4572. for (; start < arr.length; start++) {
  4573. if (arr[start] !== '') break;
  4574. }
  4575. var end = arr.length - 1;
  4576. for (; end >= 0; end--) {
  4577. if (arr[end] !== '') break;
  4578. }
  4579. if (start > end) return [];
  4580. return arr.slice(start, end - start + 1);
  4581. }
  4582. var fromParts = trim(from.split('/'));
  4583. var toParts = trim(to.split('/'));
  4584. var length = Math.min(fromParts.length, toParts.length);
  4585. var samePartsLength = length;
  4586. for (var i = 0; i < length; i++) {
  4587. if (fromParts[i] !== toParts[i]) {
  4588. samePartsLength = i;
  4589. break;
  4590. }
  4591. }
  4592. var outputParts = [];
  4593. for (var i = samePartsLength; i < fromParts.length; i++) {
  4594. outputParts.push('..');
  4595. }
  4596. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  4597. return outputParts.join('/');
  4598. }
  4599. };
  4600. var Browser = {
  4601. mainLoop: {
  4602. scheduler: null,
  4603. method: "",
  4604. shouldPause: false,
  4605. paused: false,
  4606. queue: [],
  4607. pause: function () {
  4608. Browser.mainLoop.shouldPause = true;
  4609. },
  4610. resume: function () {
  4611. if (Browser.mainLoop.paused) {
  4612. Browser.mainLoop.paused = false;
  4613. Browser.mainLoop.scheduler();
  4614. }
  4615. Browser.mainLoop.shouldPause = false;
  4616. },
  4617. updateStatus: function () {
  4618. if (Module['setStatus']) {
  4619. var message = Module['statusMessage'] || 'Please wait...';
  4620. var remaining = Browser.mainLoop.remainingBlockers;
  4621. var expected = Browser.mainLoop.expectedBlockers;
  4622. if (remaining) {
  4623. if (remaining < expected) {
  4624. Module['setStatus'](message + ' (' + (expected - remaining) + '/' + expected + ')');
  4625. } else {
  4626. Module['setStatus'](message);
  4627. }
  4628. } else {
  4629. Module['setStatus']('');
  4630. }
  4631. }
  4632. }
  4633. },
  4634. isFullScreen: false,
  4635. pointerLock: false,
  4636. moduleContextCreatedCallbacks: [],
  4637. workers: [],
  4638. init: function () {
  4639. if (!Module["preloadPlugins"]) Module["preloadPlugins"] = []; // needs to exist even in workers
  4640. if (Browser.initted || ENVIRONMENT_IS_WORKER) return;
  4641. Browser.initted = true;
  4642. try {
  4643. new Blob();
  4644. Browser.hasBlobConstructor = true;
  4645. } catch (e) {
  4646. Browser.hasBlobConstructor = false;
  4647. console.log("warning: no blob constructor, cannot create blobs with mimetypes");
  4648. }
  4649. Browser.BlobBuilder = typeof MozBlobBuilder != "undefined" ? MozBlobBuilder : (typeof WebKitBlobBuilder != "undefined" ? WebKitBlobBuilder : (!Browser.hasBlobConstructor ? console.log("warning: no BlobBuilder") : null));
  4650. Browser.URLObject = typeof window != "undefined" ? (window.URL ? window.URL : window.webkitURL) : undefined;
  4651. if (!Module.noImageDecoding && typeof Browser.URLObject === 'undefined') {
  4652. console.log("warning: Browser does not support creating object URLs. Built-in browser image decoding will not be available.");
  4653. Module.noImageDecoding = true;
  4654. }
  4655. // Support for plugins that can process preloaded files. You can add more of these to
  4656. // your app by creating and appending to Module.preloadPlugins.
  4657. //
  4658. // Each plugin is asked if it can handle a file based on the file's name. If it can,
  4659. // it is given the file's raw data. When it is done, it calls a callback with the file's
  4660. // (possibly modified) data. For example, a plugin might decompress a file, or it
  4661. // might create some side data structure for use later (like an Image element, etc.).
  4662. var imagePlugin = {};
  4663. imagePlugin['canHandle'] = function imagePlugin_canHandle(name) {
  4664. return !Module.noImageDecoding && /\.(jpg|jpeg|png|bmp)$/i.test(name);
  4665. };
  4666. imagePlugin['handle'] = function imagePlugin_handle(byteArray, name, onload, onerror) {
  4667. var b = null;
  4668. if (Browser.hasBlobConstructor) {
  4669. try {
  4670. b = new Blob([byteArray], {
  4671. type: Browser.getMimetype(name)
  4672. });
  4673. if (b.size !== byteArray.length) { // Safari bug #118630
  4674. // Safari's Blob can only take an ArrayBuffer
  4675. b = new Blob([(new Uint8Array(byteArray)).buffer], {
  4676. type: Browser.getMimetype(name)
  4677. });
  4678. }
  4679. } catch (e) {
  4680. Runtime.warnOnce('Blob constructor present but fails: ' + e + '; falling back to blob builder');
  4681. }
  4682. }
  4683. if (!b) {
  4684. var bb = new Browser.BlobBuilder();
  4685. bb.append((new Uint8Array(byteArray)).buffer); // we need to pass a buffer, and must copy the array to get the right data range
  4686. b = bb.getBlob();
  4687. }
  4688. var url = Browser.URLObject.createObjectURL(b);
  4689. var img = new Image();
  4690. img.onload = function img_onload() {
  4691. assert(img.complete, 'Image ' + name + ' could not be decoded');
  4692. var canvas = document.createElement('canvas');
  4693. canvas.width = img.width;
  4694. canvas.height = img.height;
  4695. var ctx = canvas.getContext('2d');
  4696. ctx.drawImage(img, 0, 0);
  4697. Module["preloadedImages"][name] = canvas;
  4698. Browser.URLObject.revokeObjectURL(url);
  4699. if (onload) onload(byteArray);
  4700. };
  4701. img.onerror = function img_onerror(event) {
  4702. console.log('Image ' + url + ' could not be decoded');
  4703. if (onerror) onerror();
  4704. };
  4705. img.src = url;
  4706. };
  4707. Module['preloadPlugins'].push(imagePlugin);
  4708. var audioPlugin = {};
  4709. audioPlugin['canHandle'] = function audioPlugin_canHandle(name) {
  4710. return !Module.noAudioDecoding && name.substr(-4) in {
  4711. '.ogg': 1,
  4712. '.wav': 1,
  4713. '.mp3': 1
  4714. };
  4715. };
  4716. audioPlugin['handle'] = function audioPlugin_handle(byteArray, name, onload, onerror) {
  4717. var done = false;
  4718. function finish(audio) {
  4719. if (done) return;
  4720. done = true;
  4721. Module["preloadedAudios"][name] = audio;
  4722. if (onload) onload(byteArray);
  4723. }
  4724. function fail() {
  4725. if (done) return;
  4726. done = true;
  4727. Module["preloadedAudios"][name] = new Audio(); // empty shim
  4728. if (onerror) onerror();
  4729. }
  4730. if (Browser.hasBlobConstructor) {
  4731. try {
  4732. var b = new Blob([byteArray], {
  4733. type: Browser.getMimetype(name)
  4734. });
  4735. } catch (e) {
  4736. return fail();
  4737. }
  4738. var url = Browser.URLObject.createObjectURL(b); // XXX we never revoke this!
  4739. var audio = new Audio();
  4740. audio.addEventListener('canplaythrough', function () {
  4741. finish(audio)
  4742. }, false); // use addEventListener due to chromium bug 124926
  4743. audio.onerror = function audio_onerror(event) {
  4744. if (done) return;
  4745. console.log('warning: browser could not fully decode audio ' + name + ', trying slower base64 approach');
  4746. function encode64(data) {
  4747. var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  4748. var PAD = '=';
  4749. var ret = '';
  4750. var leftchar = 0;
  4751. var leftbits = 0;
  4752. for (var i = 0; i < data.length; i++) {
  4753. leftchar = (leftchar << 8) | data[i];
  4754. leftbits += 8;
  4755. while (leftbits >= 6) {
  4756. var curr = (leftchar >> (leftbits - 6)) & 0x3f;
  4757. leftbits -= 6;
  4758. ret += BASE[curr];
  4759. }
  4760. }
  4761. if (leftbits == 2) {
  4762. ret += BASE[(leftchar & 3) << 4];
  4763. ret += PAD + PAD;
  4764. } else if (leftbits == 4) {
  4765. ret += BASE[(leftchar & 0xf) << 2];
  4766. ret += PAD;
  4767. }
  4768. return ret;
  4769. }
  4770. audio.src = 'data:audio/x-' + name.substr(-3) + ';base64,' + encode64(byteArray);
  4771. finish(audio); // we don't wait for confirmation this worked - but it's worth trying
  4772. };
  4773. audio.src = url;
  4774. // workaround for chrome bug 124926 - we do not always get oncanplaythrough or onerror
  4775. Browser.safeSetTimeout(function () {
  4776. finish(audio); // try to use it even though it is not necessarily ready to play
  4777. }, 10000);
  4778. } else {
  4779. return fail();
  4780. }
  4781. };
  4782. Module['preloadPlugins'].push(audioPlugin);
  4783. // Canvas event setup
  4784. var canvas = Module['canvas'];
  4785. // forced aspect ratio can be enabled by defining 'forcedAspectRatio' on Module
  4786. // Module['forcedAspectRatio'] = 4 / 3;
  4787. canvas.requestPointerLock = canvas['requestPointerLock'] ||
  4788. canvas['mozRequestPointerLock'] ||
  4789. canvas['webkitRequestPointerLock'] ||
  4790. canvas['msRequestPointerLock'] ||
  4791. function () {};
  4792. canvas.exitPointerLock = document['exitPointerLock'] ||
  4793. document['mozExitPointerLock'] ||
  4794. document['webkitExitPointerLock'] ||
  4795. document['msExitPointerLock'] ||
  4796. function () {}; // no-op if function does not exist
  4797. canvas.exitPointerLock = canvas.exitPointerLock.bind(document);
  4798. function pointerLockChange() {
  4799. Browser.pointerLock = document['pointerLockElement'] === canvas ||
  4800. document['mozPointerLockElement'] === canvas ||
  4801. document['webkitPointerLockElement'] === canvas ||
  4802. document['msPointerLockElement'] === canvas;
  4803. }
  4804. document.addEventListener('pointerlockchange', pointerLockChange, false);
  4805. document.addEventListener('mozpointerlockchange', pointerLockChange, false);
  4806. document.addEventListener('webkitpointerlockchange', pointerLockChange, false);
  4807. document.addEventListener('mspointerlockchange', pointerLockChange, false);
  4808. if (Module['elementPointerLock']) {
  4809. canvas.addEventListener("click", function (ev) {
  4810. if (!Browser.pointerLock && canvas.requestPointerLock) {
  4811. canvas.requestPointerLock();
  4812. ev.preventDefault();
  4813. }
  4814. }, false);
  4815. }
  4816. },
  4817. createContext: function (canvas, useWebGL, setInModule, webGLContextAttributes) {
  4818. var ctx;
  4819. var errorInfo = '?';
  4820. function onContextCreationError(event) {
  4821. errorInfo = event.statusMessage || errorInfo;
  4822. }
  4823. try {
  4824. if (useWebGL) {
  4825. var contextAttributes = {
  4826. antialias: false,
  4827. alpha: false
  4828. };
  4829. if (webGLContextAttributes) {
  4830. for (var attribute in webGLContextAttributes) {
  4831. contextAttributes[attribute] = webGLContextAttributes[attribute];
  4832. }
  4833. }
  4834. canvas.addEventListener('webglcontextcreationerror', onContextCreationError, false);
  4835. try {
  4836. ['experimental-webgl', 'webgl'].some(function (webglId) {
  4837. return ctx = canvas.getContext(webglId, contextAttributes);
  4838. });
  4839. } finally {
  4840. canvas.removeEventListener('webglcontextcreationerror', onContextCreationError, false);
  4841. }
  4842. } else {
  4843. ctx = canvas.getContext('2d');
  4844. }
  4845. if (!ctx) throw ':(';
  4846. } catch (e) {
  4847. Module.print('Could not create canvas: ' + [errorInfo, e]);
  4848. return null;
  4849. }
  4850. if (useWebGL) {
  4851. // Set the background of the WebGL canvas to black
  4852. canvas.style.backgroundColor = "black";
  4853. // Warn on context loss
  4854. canvas.addEventListener('webglcontextlost', function (event) {
  4855. alert('WebGL context lost. You will need to reload the page.');
  4856. }, false);
  4857. }
  4858. if (setInModule) {
  4859. GLctx = Module.ctx = ctx;
  4860. Module.useWebGL = useWebGL;
  4861. Browser.moduleContextCreatedCallbacks.forEach(function (callback) {
  4862. callback()
  4863. });
  4864. Browser.init();
  4865. }
  4866. return ctx;
  4867. },
  4868. destroyContext: function (canvas, useWebGL, setInModule) {},
  4869. fullScreenHandlersInstalled: false,
  4870. lockPointer: undefined,
  4871. resizeCanvas: undefined,
  4872. requestFullScreen: function (lockPointer, resizeCanvas) {
  4873. Browser.lockPointer = lockPointer;
  4874. Browser.resizeCanvas = resizeCanvas;
  4875. if (typeof Browser.lockPointer === 'undefined') Browser.lockPointer = true;
  4876. if (typeof Browser.resizeCanvas === 'undefined') Browser.resizeCanvas = false;
  4877. var canvas = Module['canvas'];
  4878. var canvasContainer = canvas.parentNode;
  4879. function fullScreenChange() {
  4880. Browser.isFullScreen = false;
  4881. if ((document['webkitFullScreenElement'] || document['webkitFullscreenElement'] ||
  4882. document['mozFullScreenElement'] || document['mozFullscreenElement'] ||
  4883. document['fullScreenElement'] || document['fullscreenElement'] ||
  4884. document['msFullScreenElement'] || document['msFullscreenElement'] ||
  4885. document['webkitCurrentFullScreenElement']) === canvasContainer) {
  4886. canvas.cancelFullScreen = document['cancelFullScreen'] ||
  4887. document['mozCancelFullScreen'] ||
  4888. document['webkitCancelFullScreen'] ||
  4889. document['msExitFullscreen'] ||
  4890. document['exitFullscreen'] ||
  4891. function () {};
  4892. canvas.cancelFullScreen = canvas.cancelFullScreen.bind(document);
  4893. if (Browser.lockPointer) canvas.requestPointerLock();
  4894. Browser.isFullScreen = true;
  4895. if (Browser.resizeCanvas) Browser.setFullScreenCanvasSize();
  4896. } else {
  4897. // remove the full screen specific parent of the canvas again to restore the HTML structure from before going full screen
  4898. var canvasContainer = canvas.parentNode;
  4899. canvasContainer.parentNode.insertBefore(canvas, canvasContainer);
  4900. canvasContainer.parentNode.removeChild(canvasContainer);
  4901. if (Browser.resizeCanvas) Browser.setWindowedCanvasSize();
  4902. }
  4903. if (Module['onFullScreen']) Module['onFullScreen'](Browser.isFullScreen);
  4904. Browser.updateCanvasDimensions(canvas);
  4905. }
  4906. if (!Browser.fullScreenHandlersInstalled) {
  4907. Browser.fullScreenHandlersInstalled = true;
  4908. document.addEventListener('fullscreenchange', fullScreenChange, false);
  4909. document.addEventListener('mozfullscreenchange', fullScreenChange, false);
  4910. document.addEventListener('webkitfullscreenchange', fullScreenChange, false);
  4911. document.addEventListener('MSFullscreenChange', fullScreenChange, false);
  4912. }
  4913. // create a new parent to ensure the canvas has no siblings. this allows browsers to optimize full screen performance when its parent is the full screen root
  4914. var canvasContainer = document.createElement("div");
  4915. canvas.parentNode.insertBefore(canvasContainer, canvas);
  4916. canvasContainer.appendChild(canvas);
  4917. // use parent of canvas as full screen root to allow aspect ratio correction (Firefox stretches the root to screen size)
  4918. canvasContainer.requestFullScreen = canvasContainer['requestFullScreen'] ||
  4919. canvasContainer['mozRequestFullScreen'] ||
  4920. canvasContainer['msRequestFullscreen'] ||
  4921. (canvasContainer['webkitRequestFullScreen'] ? function () {
  4922. canvasContainer['webkitRequestFullScreen'](Element['ALLOW_KEYBOARD_INPUT'])
  4923. } : null);
  4924. canvasContainer.requestFullScreen();
  4925. },
  4926. requestAnimationFrame: function requestAnimationFrame(func) {
  4927. if (typeof window === 'undefined') { // Provide fallback to setTimeout if window is undefined (e.g. in Node.js)
  4928. setTimeout(func, 1000 / 60);
  4929. } else {
  4930. if (!window.requestAnimationFrame) {
  4931. window.requestAnimationFrame = window['requestAnimationFrame'] ||
  4932. window['mozRequestAnimationFrame'] ||
  4933. window['webkitRequestAnimationFrame'] ||
  4934. window['msRequestAnimationFrame'] ||
  4935. window['oRequestAnimationFrame'] ||
  4936. window['setTimeout'];
  4937. }
  4938. window.requestAnimationFrame(func);
  4939. }
  4940. },
  4941. safeCallback: function (func) {
  4942. return function () {
  4943. if (!ABORT) return func.apply(null, arguments);
  4944. };
  4945. },
  4946. safeRequestAnimationFrame: function (func) {
  4947. return Browser.requestAnimationFrame(function () {
  4948. if (!ABORT) func();
  4949. });
  4950. },
  4951. safeSetTimeout: function (func, timeout) {
  4952. return setTimeout(function () {
  4953. if (!ABORT) func();
  4954. }, timeout);
  4955. },
  4956. safeSetInterval: function (func, timeout) {
  4957. return setInterval(function () {
  4958. if (!ABORT) func();
  4959. }, timeout);
  4960. },
  4961. getMimetype: function (name) {
  4962. return {
  4963. 'jpg': 'image/jpeg',
  4964. 'jpeg': 'image/jpeg',
  4965. 'png': 'image/png',
  4966. 'bmp': 'image/bmp',
  4967. 'ogg': 'audio/ogg',
  4968. 'wav': 'audio/wav',
  4969. 'mp3': 'audio/mpeg'
  4970. }[name.substr(name.lastIndexOf('.') + 1)];
  4971. },
  4972. getUserMedia: function (func) {
  4973. if (!window.getUserMedia) {
  4974. window.getUserMedia = navigator['getUserMedia'] ||
  4975. navigator['mozGetUserMedia'];
  4976. }
  4977. window.getUserMedia(func);
  4978. },
  4979. getMovementX: function (event) {
  4980. return event['movementX'] ||
  4981. event['mozMovementX'] ||
  4982. event['webkitMovementX'] ||
  4983. 0;
  4984. },
  4985. getMovementY: function (event) {
  4986. return event['movementY'] ||
  4987. event['mozMovementY'] ||
  4988. event['webkitMovementY'] ||
  4989. 0;
  4990. },
  4991. getMouseWheelDelta: function (event) {
  4992. return Math.max(-1, Math.min(1, event.type === 'DOMMouseScroll' ? event.detail : -event.wheelDelta));
  4993. },
  4994. mouseX: 0,
  4995. mouseY: 0,
  4996. mouseMovementX: 0,
  4997. mouseMovementY: 0,
  4998. calculateMouseEvent: function (event) { // event should be mousemove, mousedown or mouseup
  4999. if (Browser.pointerLock) {
  5000. // When the pointer is locked, calculate the coordinates
  5001. // based on the movement of the mouse.
  5002. // Workaround for Firefox bug 764498
  5003. if (event.type != 'mousemove' &&
  5004. ('mozMovementX' in event)) {
  5005. Browser.mouseMovementX = Browser.mouseMovementY = 0;
  5006. } else {
  5007. Browser.mouseMovementX = Browser.getMovementX(event);
  5008. Browser.mouseMovementY = Browser.getMovementY(event);
  5009. }
  5010. // check if SDL is available
  5011. if (typeof SDL != "undefined") {
  5012. Browser.mouseX = SDL.mouseX + Browser.mouseMovementX;
  5013. Browser.mouseY = SDL.mouseY + Browser.mouseMovementY;
  5014. } else {
  5015. // just add the mouse delta to the current absolut mouse position
  5016. // FIXME: ideally this should be clamped against the canvas size and zero
  5017. Browser.mouseX += Browser.mouseMovementX;
  5018. Browser.mouseY += Browser.mouseMovementY;
  5019. }
  5020. } else {
  5021. // Otherwise, calculate the movement based on the changes
  5022. // in the coordinates.
  5023. var rect = Module["canvas"].getBoundingClientRect();
  5024. var x, y;
  5025. // Neither .scrollX or .pageXOffset are defined in a spec, but
  5026. // we prefer .scrollX because it is currently in a spec draft.
  5027. // (see: http://www.w3.org/TR/2013/WD-cssom-view-20131217/)
  5028. var scrollX = ((typeof window.scrollX !== 'undefined') ? window.scrollX : window.pageXOffset);
  5029. var scrollY = ((typeof window.scrollY !== 'undefined') ? window.scrollY : window.pageYOffset);
  5030. if (event.type == 'touchstart' ||
  5031. event.type == 'touchend' ||
  5032. event.type == 'touchmove') {
  5033. var t = event.touches.item(0);
  5034. if (t) {
  5035. x = t.pageX - (scrollX + rect.left);
  5036. y = t.pageY - (scrollY + rect.top);
  5037. } else {
  5038. return;
  5039. }
  5040. } else {
  5041. x = event.pageX - (scrollX + rect.left);
  5042. y = event.pageY - (scrollY + rect.top);
  5043. }
  5044. // the canvas might be CSS-scaled compared to its backbuffer;
  5045. // SDL-using content will want mouse coordinates in terms
  5046. // of backbuffer units.
  5047. var cw = Module["canvas"].width;
  5048. var ch = Module["canvas"].height;
  5049. x = x * (cw / rect.width);
  5050. y = y * (ch / rect.height);
  5051. Browser.mouseMovementX = x - Browser.mouseX;
  5052. Browser.mouseMovementY = y - Browser.mouseY;
  5053. Browser.mouseX = x;
  5054. Browser.mouseY = y;
  5055. }
  5056. },
  5057. xhrLoad: function (url, onload, onerror) {
  5058. var xhr = new XMLHttpRequest();
  5059. xhr.open('GET', url, true);
  5060. xhr.responseType = 'arraybuffer';
  5061. xhr.onload = function xhr_onload() {
  5062. if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
  5063. onload(xhr.response);
  5064. } else {
  5065. onerror();
  5066. }
  5067. };
  5068. xhr.onerror = onerror;
  5069. xhr.send(null);
  5070. },
  5071. asyncLoad: function (url, onload, onerror, noRunDep) {
  5072. Browser.xhrLoad(url, function (arrayBuffer) {
  5073. assert(arrayBuffer, 'Loading data file "' + url + '" failed (no arrayBuffer).');
  5074. onload(new Uint8Array(arrayBuffer));
  5075. if (!noRunDep) removeRunDependency('al ' + url);
  5076. }, function (event) {
  5077. if (onerror) {
  5078. onerror();
  5079. } else {
  5080. throw 'Loading data file "' + url + '" failed.';
  5081. }
  5082. });
  5083. if (!noRunDep) addRunDependency('al ' + url);
  5084. },
  5085. resizeListeners: [],
  5086. updateResizeListeners: function () {
  5087. var canvas = Module['canvas'];
  5088. Browser.resizeListeners.forEach(function (listener) {
  5089. listener(canvas.width, canvas.height);
  5090. });
  5091. },
  5092. setCanvasSize: function (width, height, noUpdates) {
  5093. var canvas = Module['canvas'];
  5094. Browser.updateCanvasDimensions(canvas, width, height);
  5095. if (!noUpdates) Browser.updateResizeListeners();
  5096. },
  5097. windowedWidth: 0,
  5098. windowedHeight: 0,
  5099. setFullScreenCanvasSize: function () {
  5100. // check if SDL is available
  5101. if (typeof SDL != "undefined") {
  5102. var flags = HEAPU32[((SDL.screen + Runtime.QUANTUM_SIZE * 0) >> 2)];
  5103. flags = flags | 0x00800000; // set SDL_FULLSCREEN flag
  5104. HEAP32[((SDL.screen + Runtime.QUANTUM_SIZE * 0) >> 2)] = flags
  5105. }
  5106. Browser.updateResizeListeners();
  5107. },
  5108. setWindowedCanvasSize: function () {
  5109. // check if SDL is available
  5110. if (typeof SDL != "undefined") {
  5111. var flags = HEAPU32[((SDL.screen + Runtime.QUANTUM_SIZE * 0) >> 2)];
  5112. flags = flags & ~0x00800000; // clear SDL_FULLSCREEN flag
  5113. HEAP32[((SDL.screen + Runtime.QUANTUM_SIZE * 0) >> 2)] = flags
  5114. }
  5115. Browser.updateResizeListeners();
  5116. },
  5117. updateCanvasDimensions: function (canvas, wNative, hNative) {
  5118. if (wNative && hNative) {
  5119. canvas.widthNative = wNative;
  5120. canvas.heightNative = hNative;
  5121. } else {
  5122. wNative = canvas.widthNative;
  5123. hNative = canvas.heightNative;
  5124. }
  5125. var w = wNative;
  5126. var h = hNative;
  5127. if (Module['forcedAspectRatio'] && Module['forcedAspectRatio'] > 0) {
  5128. if (w / h < Module['forcedAspectRatio']) {
  5129. w = Math.round(h * Module['forcedAspectRatio']);
  5130. } else {
  5131. h = Math.round(w / Module['forcedAspectRatio']);
  5132. }
  5133. }
  5134. if (((document['webkitFullScreenElement'] || document['webkitFullscreenElement'] ||
  5135. document['mozFullScreenElement'] || document['mozFullscreenElement'] ||
  5136. document['fullScreenElement'] || document['fullscreenElement'] ||
  5137. document['msFullScreenElement'] || document['msFullscreenElement'] ||
  5138. document['webkitCurrentFullScreenElement']) === canvas.parentNode) && (typeof screen != 'undefined')) {
  5139. var factor = Math.min(screen.width / w, screen.height / h);
  5140. w = Math.round(w * factor);
  5141. h = Math.round(h * factor);
  5142. }
  5143. if (Browser.resizeCanvas) {
  5144. if (canvas.width != w) canvas.width = w;
  5145. if (canvas.height != h) canvas.height = h;
  5146. if (typeof canvas.style != 'undefined') {
  5147. canvas.style.removeProperty("width");
  5148. canvas.style.removeProperty("height");
  5149. }
  5150. } else {
  5151. if (canvas.width != wNative) canvas.width = wNative;
  5152. if (canvas.height != hNative) canvas.height = hNative;
  5153. if (typeof canvas.style != 'undefined') {
  5154. if (w != wNative || h != hNative) {
  5155. canvas.style.setProperty("width", w + "px", "important");
  5156. canvas.style.setProperty("height", h + "px", "important");
  5157. } else {
  5158. canvas.style.removeProperty("width");
  5159. canvas.style.removeProperty("height");
  5160. }
  5161. }
  5162. }
  5163. }
  5164. };
  5165. function _time(ptr) {
  5166. var ret = Math.floor(Date.now() / 1000);
  5167. if (ptr) {
  5168. HEAP32[((ptr) >> 2)] = ret;
  5169. }
  5170. return ret;
  5171. }
  5172. Module["_strlen"] = _strlen;
  5173. ___errno_state = Runtime.staticAlloc(4);
  5174. HEAP32[((___errno_state) >> 2)] = 0;
  5175. Module["requestFullScreen"] = function Module_requestFullScreen(lockPointer, resizeCanvas) {
  5176. Browser.requestFullScreen(lockPointer, resizeCanvas)
  5177. };
  5178. Module["requestAnimationFrame"] = function Module_requestAnimationFrame(func) {
  5179. Browser.requestAnimationFrame(func)
  5180. };
  5181. Module["setCanvasSize"] = function Module_setCanvasSize(width, height, noUpdates) {
  5182. Browser.setCanvasSize(width, height, noUpdates)
  5183. };
  5184. Module["pauseMainLoop"] = function Module_pauseMainLoop() {
  5185. Browser.mainLoop.pause()
  5186. };
  5187. Module["resumeMainLoop"] = function Module_resumeMainLoop() {
  5188. Browser.mainLoop.resume()
  5189. };
  5190. Module["getUserMedia"] = function Module_getUserMedia() {
  5191. Browser.getUserMedia()
  5192. }
  5193. FS.staticInit();
  5194. __ATINIT__.unshift({
  5195. func: function () {
  5196. if (!Module["noFSInit"] && !FS.init.initialized) FS.init()
  5197. }
  5198. });
  5199. __ATMAIN__.push({
  5200. func: function () {
  5201. FS.ignorePermissions = false
  5202. }
  5203. });
  5204. __ATEXIT__.push({
  5205. func: function () {
  5206. FS.quit()
  5207. }
  5208. });
  5209. Module["FS_createFolder"] = FS.createFolder;
  5210. Module["FS_createPath"] = FS.createPath;
  5211. Module["FS_createDataFile"] = FS.createDataFile;
  5212. Module["FS_createPreloadedFile"] = FS.createPreloadedFile;
  5213. Module["FS_createLazyFile"] = FS.createLazyFile;
  5214. Module["FS_createLink"] = FS.createLink;
  5215. Module["FS_createDevice"] = FS.createDevice;
  5216. __ATINIT__.unshift({
  5217. func: function () {
  5218. TTY.init()
  5219. }
  5220. });
  5221. __ATEXIT__.push({
  5222. func: function () {
  5223. TTY.shutdown()
  5224. }
  5225. });
  5226. TTY.utf8 = new Runtime.UTF8Processor();
  5227. if (ENVIRONMENT_IS_NODE) {
  5228. var fs = require("fs");
  5229. NODEFS.staticInit();
  5230. }
  5231. STACK_BASE = STACKTOP = Runtime.alignMemory(STATICTOP);
  5232. staticSealed = true; // seal the static portion of memory
  5233. STACK_MAX = STACK_BASE + 5242880;
  5234. DYNAMIC_BASE = DYNAMICTOP = Runtime.alignMemory(STACK_MAX);
  5235. assert(DYNAMIC_BASE < TOTAL_MEMORY, "TOTAL_MEMORY not big enough for stack");
  5236. var Math_min = Math.min;
  5237. function asmPrintInt(x, y) {
  5238. Module.print('int ' + x + ',' + y); // + ' ' + new Error().stack);
  5239. }
  5240. function asmPrintFloat(x, y) {
  5241. Module.print('float ' + x + ',' + y); // + ' ' + new Error().stack);
  5242. }
  5243. // EMSCRIPTEN_START_ASM
  5244. var asm = (function (global, env, buffer) {
  5245. "use asm";
  5246. var a = new global.Int8Array(buffer);
  5247. var b = new global.Int16Array(buffer);
  5248. var c = new global.Int32Array(buffer);
  5249. var d = new global.Uint8Array(buffer);
  5250. var e = new global.Uint16Array(buffer);
  5251. var f = new global.Uint32Array(buffer);
  5252. var g = new global.Float32Array(buffer);
  5253. var h = new global.Float64Array(buffer);
  5254. var i = env.STACKTOP | 0;
  5255. var j = env.STACK_MAX | 0;
  5256. var k = env.tempDoublePtr | 0;
  5257. var l = env.ABORT | 0;
  5258. var m = 0;
  5259. var n = 0;
  5260. var o = 0;
  5261. var p = 0;
  5262. var q = +env.NaN,
  5263. r = +env.Infinity;
  5264. var s = 0,
  5265. t = 0,
  5266. u = 0,
  5267. v = 0,
  5268. w = 0.0,
  5269. x = 0,
  5270. y = 0,
  5271. z = 0,
  5272. A = 0.0;
  5273. var B = 0;
  5274. var C = 0;
  5275. var D = 0;
  5276. var E = 0;
  5277. var F = 0;
  5278. var G = 0;
  5279. var H = 0;
  5280. var I = 0;
  5281. var J = 0;
  5282. var K = 0;
  5283. var L = global.Math.floor;
  5284. var M = global.Math.abs;
  5285. var N = global.Math.sqrt;
  5286. var O = global.Math.pow;
  5287. var P = global.Math.cos;
  5288. var Q = global.Math.sin;
  5289. var R = global.Math.tan;
  5290. var S = global.Math.acos;
  5291. var T = global.Math.asin;
  5292. var U = global.Math.atan;
  5293. var V = global.Math.atan2;
  5294. var W = global.Math.exp;
  5295. var X = global.Math.log;
  5296. var Y = global.Math.ceil;
  5297. var Z = global.Math.imul;
  5298. var _ = env.abort;
  5299. var $ = env.assert;
  5300. var aa = env.asmPrintInt;
  5301. var ba = env.asmPrintFloat;
  5302. var ca = env.min;
  5303. var da = env._clock;
  5304. var ea = env._fflush;
  5305. var fa = env._abort;
  5306. var ga = env.___setErrNo;
  5307. var ha = env._sbrk;
  5308. var ia = env._time;
  5309. var ja = env._emscripten_memcpy_big;
  5310. var ka = env._sysconf;
  5311. var la = env.___errno_location;
  5312. var ma = 0.0;
  5313. // EMSCRIPTEN_START_FUNCS
  5314. function na(a) {
  5315. a = a | 0;
  5316. var b = 0;
  5317. b = i;
  5318. i = i + a | 0;
  5319. i = i + 7 & -8;
  5320. return b | 0
  5321. }
  5322. function oa() {
  5323. return i | 0
  5324. }
  5325. function pa(a) {
  5326. a = a | 0;
  5327. i = a
  5328. }
  5329. function qa(a, b) {
  5330. a = a | 0;
  5331. b = b | 0;
  5332. if ((m | 0) == 0) {
  5333. m = a;
  5334. n = b
  5335. }
  5336. }
  5337. function ra(b) {
  5338. b = b | 0;
  5339. a[k] = a[b];
  5340. a[k + 1 | 0] = a[b + 1 | 0];
  5341. a[k + 2 | 0] = a[b + 2 | 0];
  5342. a[k + 3 | 0] = a[b + 3 | 0]
  5343. }
  5344. function sa(b) {
  5345. b = b | 0;
  5346. a[k] = a[b];
  5347. a[k + 1 | 0] = a[b + 1 | 0];
  5348. a[k + 2 | 0] = a[b + 2 | 0];
  5349. a[k + 3 | 0] = a[b + 3 | 0];
  5350. a[k + 4 | 0] = a[b + 4 | 0];
  5351. a[k + 5 | 0] = a[b + 5 | 0];
  5352. a[k + 6 | 0] = a[b + 6 | 0];
  5353. a[k + 7 | 0] = a[b + 7 | 0]
  5354. }
  5355. function ta(a) {
  5356. a = a | 0;
  5357. B = a
  5358. }
  5359. function ua(a) {
  5360. a = a | 0;
  5361. C = a
  5362. }
  5363. function va(a) {
  5364. a = a | 0;
  5365. D = a
  5366. }
  5367. function wa(a) {
  5368. a = a | 0;
  5369. E = a
  5370. }
  5371. function xa(a) {
  5372. a = a | 0;
  5373. F = a
  5374. }
  5375. function ya(a) {
  5376. a = a | 0;
  5377. G = a
  5378. }
  5379. function za(a) {
  5380. a = a | 0;
  5381. H = a
  5382. }
  5383. function Aa(a) {
  5384. a = a | 0;
  5385. I = a
  5386. }
  5387. function Ba(a) {
  5388. a = a | 0;
  5389. J = a
  5390. }
  5391. function Ca(a) {
  5392. a = a | 0;
  5393. K = a
  5394. }
  5395. function Da() {
  5396. var b = 0,
  5397. d = 0,
  5398. e = 0,
  5399. f = 0;
  5400. b = i;
  5401. da() | 0;
  5402. da() | 0;
  5403. d = Ea(48) | 0;
  5404. c[2] = d;
  5405. e = Ea(48) | 0;
  5406. c[4] = e;
  5407. c[e >> 2] = d;
  5408. c[e + 4 >> 2] = 0;
  5409. c[e + 8 >> 2] = 10001;
  5410. c[e + 12 >> 2] = 40;
  5411. d = e + 16 | 0;
  5412. e = 24 | 0;
  5413. f = d + 31 | 0;
  5414. do {
  5415. a[d] = a[e] | 0;
  5416. d = d + 1 | 0;
  5417. e = e + 1 | 0
  5418. } while ((d | 0) < (f | 0));
  5419. c[1716 >> 2] = 10;
  5420. da() | 0;
  5421. e = 0;
  5422. do {
  5423. a[10688] = 65;
  5424. a[10680] = 66;
  5425. c[2616] = 1;
  5426. c[10504 >> 2] = 7;
  5427. c[10508 >> 2] = 7;
  5428. c[10624 >> 2] = 8;
  5429. c[1720 >> 2] = 8;
  5430. c[1724 >> 2] = 8;
  5431. c[1716 >> 2] = (c[1716 >> 2] | 0) + 1;
  5432. c[5800 >> 2] = 7;
  5433. c[2674] = 5;
  5434. d = c[4] | 0;
  5435. c[d + 12 >> 2] = 5;
  5436. f = c[d >> 2] | 0;
  5437. c[f + 12 >> 2] = 5;
  5438. c[f >> 2] = f;
  5439. f = a[10680] | 0;
  5440. if (!(f << 24 >> 24 < 65)) {
  5441. d = 65;
  5442. do {
  5443. d = d + 1 << 24 >> 24;
  5444. } while (!(d << 24 >> 24 > f << 24 >> 24))
  5445. }
  5446. e = e + 1 | 0;
  5447. } while ((e | 0) != 1e8);
  5448. i = b;
  5449. return 0
  5450. }
  5451. function Ea(a) {
  5452. a = a | 0;
  5453. var b = 0,
  5454. d = 0,
  5455. e = 0,
  5456. f = 0,
  5457. g = 0,
  5458. h = 0,
  5459. j = 0,
  5460. k = 0,
  5461. l = 0,
  5462. m = 0,
  5463. n = 0,
  5464. o = 0,
  5465. p = 0,
  5466. q = 0,
  5467. r = 0,
  5468. s = 0,
  5469. t = 0,
  5470. u = 0,
  5471. v = 0,
  5472. w = 0,
  5473. x = 0,
  5474. y = 0,
  5475. z = 0,
  5476. A = 0,
  5477. B = 0,
  5478. C = 0,
  5479. D = 0,
  5480. E = 0,
  5481. F = 0,
  5482. G = 0,
  5483. H = 0,
  5484. I = 0,
  5485. J = 0,
  5486. K = 0,
  5487. L = 0,
  5488. M = 0,
  5489. N = 0,
  5490. O = 0,
  5491. P = 0,
  5492. Q = 0,
  5493. R = 0,
  5494. S = 0,
  5495. T = 0,
  5496. U = 0,
  5497. V = 0,
  5498. W = 0,
  5499. X = 0,
  5500. Y = 0,
  5501. Z = 0,
  5502. _ = 0,
  5503. $ = 0,
  5504. aa = 0,
  5505. ba = 0,
  5506. ca = 0,
  5507. da = 0,
  5508. ea = 0,
  5509. ga = 0,
  5510. ja = 0,
  5511. ma = 0,
  5512. na = 0,
  5513. oa = 0,
  5514. pa = 0,
  5515. qa = 0,
  5516. ra = 0,
  5517. sa = 0,
  5518. ta = 0,
  5519. ua = 0,
  5520. va = 0,
  5521. wa = 0,
  5522. xa = 0,
  5523. ya = 0,
  5524. za = 0,
  5525. Aa = 0,
  5526. Ba = 0,
  5527. Ca = 0,
  5528. Da = 0,
  5529. Ea = 0,
  5530. Fa = 0,
  5531. Ga = 0,
  5532. Ha = 0,
  5533. Ia = 0,
  5534. Ja = 0,
  5535. Ka = 0,
  5536. La = 0,
  5537. Ma = 0,
  5538. Na = 0,
  5539. Oa = 0,
  5540. Pa = 0,
  5541. Qa = 0,
  5542. Ra = 0,
  5543. Sa = 0;
  5544. b = i;
  5545. do {
  5546. if (a >>> 0 < 245) {
  5547. if (a >>> 0 < 11) {
  5548. d = 16
  5549. } else {
  5550. d = a + 11 & -8
  5551. }
  5552. e = d >>> 3;
  5553. f = c[2676] | 0;
  5554. g = f >>> e;
  5555. if ((g & 3 | 0) != 0) {
  5556. h = (g & 1 ^ 1) + e | 0;
  5557. j = h << 1;
  5558. k = 10744 + (j << 2) | 0;
  5559. l = 10744 + (j + 2 << 2) | 0;
  5560. j = c[l >> 2] | 0;
  5561. m = j + 8 | 0;
  5562. n = c[m >> 2] | 0;
  5563. do {
  5564. if ((k | 0) == (n | 0)) {
  5565. c[2676] = f & ~(1 << h)
  5566. } else {
  5567. if (n >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  5568. fa()
  5569. }
  5570. o = n + 12 | 0;
  5571. if ((c[o >> 2] | 0) == (j | 0)) {
  5572. c[o >> 2] = k;
  5573. c[l >> 2] = n;
  5574. break
  5575. } else {
  5576. fa()
  5577. }
  5578. }
  5579. } while (0);
  5580. n = h << 3;
  5581. c[j + 4 >> 2] = n | 3;
  5582. l = j + (n | 4) | 0;
  5583. c[l >> 2] = c[l >> 2] | 1;
  5584. p = m;
  5585. i = b;
  5586. return p | 0
  5587. }
  5588. if (!(d >>> 0 > (c[10712 >> 2] | 0) >>> 0)) {
  5589. q = d;
  5590. break
  5591. }
  5592. if ((g | 0) != 0) {
  5593. l = 2 << e;
  5594. n = g << e & (l | 0 - l);
  5595. l = (n & 0 - n) + -1 | 0;
  5596. n = l >>> 12 & 16;
  5597. k = l >>> n;
  5598. l = k >>> 5 & 8;
  5599. o = k >>> l;
  5600. k = o >>> 2 & 4;
  5601. r = o >>> k;
  5602. o = r >>> 1 & 2;
  5603. s = r >>> o;
  5604. r = s >>> 1 & 1;
  5605. t = (l | n | k | o | r) + (s >>> r) | 0;
  5606. r = t << 1;
  5607. s = 10744 + (r << 2) | 0;
  5608. o = 10744 + (r + 2 << 2) | 0;
  5609. r = c[o >> 2] | 0;
  5610. k = r + 8 | 0;
  5611. n = c[k >> 2] | 0;
  5612. do {
  5613. if ((s | 0) == (n | 0)) {
  5614. c[2676] = f & ~(1 << t)
  5615. } else {
  5616. if (n >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  5617. fa()
  5618. }
  5619. l = n + 12 | 0;
  5620. if ((c[l >> 2] | 0) == (r | 0)) {
  5621. c[l >> 2] = s;
  5622. c[o >> 2] = n;
  5623. break
  5624. } else {
  5625. fa()
  5626. }
  5627. }
  5628. } while (0);
  5629. n = t << 3;
  5630. o = n - d | 0;
  5631. c[r + 4 >> 2] = d | 3;
  5632. s = r;
  5633. f = s + d | 0;
  5634. c[s + (d | 4) >> 2] = o | 1;
  5635. c[s + n >> 2] = o;
  5636. n = c[10712 >> 2] | 0;
  5637. if ((n | 0) != 0) {
  5638. s = c[10724 >> 2] | 0;
  5639. e = n >>> 3;
  5640. n = e << 1;
  5641. g = 10744 + (n << 2) | 0;
  5642. m = c[2676] | 0;
  5643. j = 1 << e;
  5644. do {
  5645. if ((m & j | 0) == 0) {
  5646. c[2676] = m | j;
  5647. u = 10744 + (n + 2 << 2) | 0;
  5648. v = g
  5649. } else {
  5650. e = 10744 + (n + 2 << 2) | 0;
  5651. h = c[e >> 2] | 0;
  5652. if (!(h >>> 0 < (c[10720 >> 2] | 0) >>> 0)) {
  5653. u = e;
  5654. v = h;
  5655. break
  5656. }
  5657. fa()
  5658. }
  5659. } while (0);
  5660. c[u >> 2] = s;
  5661. c[v + 12 >> 2] = s;
  5662. c[s + 8 >> 2] = v;
  5663. c[s + 12 >> 2] = g
  5664. }
  5665. c[10712 >> 2] = o;
  5666. c[10724 >> 2] = f;
  5667. p = k;
  5668. i = b;
  5669. return p | 0
  5670. }
  5671. n = c[10708 >> 2] | 0;
  5672. if ((n | 0) == 0) {
  5673. q = d;
  5674. break
  5675. }
  5676. j = (n & 0 - n) + -1 | 0;
  5677. n = j >>> 12 & 16;
  5678. m = j >>> n;
  5679. j = m >>> 5 & 8;
  5680. r = m >>> j;
  5681. m = r >>> 2 & 4;
  5682. t = r >>> m;
  5683. r = t >>> 1 & 2;
  5684. h = t >>> r;
  5685. t = h >>> 1 & 1;
  5686. e = c[11008 + ((j | n | m | r | t) + (h >>> t) << 2) >> 2] | 0;
  5687. t = (c[e + 4 >> 2] & -8) - d | 0;
  5688. h = e;
  5689. r = e;
  5690. while (1) {
  5691. e = c[h + 16 >> 2] | 0;
  5692. if ((e | 0) == 0) {
  5693. m = c[h + 20 >> 2] | 0;
  5694. if ((m | 0) == 0) {
  5695. break
  5696. } else {
  5697. w = m
  5698. }
  5699. } else {
  5700. w = e
  5701. }
  5702. e = (c[w + 4 >> 2] & -8) - d | 0;
  5703. m = e >>> 0 < t >>> 0;
  5704. t = m ? e : t;
  5705. h = w;
  5706. r = m ? w : r
  5707. }
  5708. h = r;
  5709. k = c[10720 >> 2] | 0;
  5710. if (h >>> 0 < k >>> 0) {
  5711. fa()
  5712. }
  5713. f = h + d | 0;
  5714. o = f;
  5715. if (!(h >>> 0 < f >>> 0)) {
  5716. fa()
  5717. }
  5718. f = c[r + 24 >> 2] | 0;
  5719. g = c[r + 12 >> 2] | 0;
  5720. do {
  5721. if ((g | 0) == (r | 0)) {
  5722. s = r + 20 | 0;
  5723. m = c[s >> 2] | 0;
  5724. if ((m | 0) == 0) {
  5725. e = r + 16 | 0;
  5726. n = c[e >> 2] | 0;
  5727. if ((n | 0) == 0) {
  5728. x = 0;
  5729. break
  5730. } else {
  5731. y = n;
  5732. z = e
  5733. }
  5734. } else {
  5735. y = m;
  5736. z = s
  5737. }
  5738. while (1) {
  5739. s = y + 20 | 0;
  5740. m = c[s >> 2] | 0;
  5741. if ((m | 0) != 0) {
  5742. z = s;
  5743. y = m;
  5744. continue
  5745. }
  5746. m = y + 16 | 0;
  5747. s = c[m >> 2] | 0;
  5748. if ((s | 0) == 0) {
  5749. break
  5750. } else {
  5751. y = s;
  5752. z = m
  5753. }
  5754. }
  5755. if (z >>> 0 < k >>> 0) {
  5756. fa()
  5757. } else {
  5758. c[z >> 2] = 0;
  5759. x = y;
  5760. break
  5761. }
  5762. } else {
  5763. m = c[r + 8 >> 2] | 0;
  5764. if (m >>> 0 < k >>> 0) {
  5765. fa()
  5766. }
  5767. s = m + 12 | 0;
  5768. if ((c[s >> 2] | 0) != (r | 0)) {
  5769. fa()
  5770. }
  5771. e = g + 8 | 0;
  5772. if ((c[e >> 2] | 0) == (r | 0)) {
  5773. c[s >> 2] = g;
  5774. c[e >> 2] = m;
  5775. x = g;
  5776. break
  5777. } else {
  5778. fa()
  5779. }
  5780. }
  5781. } while (0);
  5782. a: do {
  5783. if ((f | 0) != 0) {
  5784. g = c[r + 28 >> 2] | 0;
  5785. k = 11008 + (g << 2) | 0;
  5786. do {
  5787. if ((r | 0) == (c[k >> 2] | 0)) {
  5788. c[k >> 2] = x;
  5789. if ((x | 0) != 0) {
  5790. break
  5791. }
  5792. c[10708 >> 2] = c[10708 >> 2] & ~(1 << g);
  5793. break a
  5794. } else {
  5795. if (f >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  5796. fa()
  5797. }
  5798. m = f + 16 | 0;
  5799. if ((c[m >> 2] | 0) == (r | 0)) {
  5800. c[m >> 2] = x
  5801. } else {
  5802. c[f + 20 >> 2] = x
  5803. } if ((x | 0) == 0) {
  5804. break a
  5805. }
  5806. }
  5807. } while (0);
  5808. if (x >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  5809. fa()
  5810. }
  5811. c[x + 24 >> 2] = f;
  5812. g = c[r + 16 >> 2] | 0;
  5813. do {
  5814. if ((g | 0) != 0) {
  5815. if (g >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  5816. fa()
  5817. } else {
  5818. c[x + 16 >> 2] = g;
  5819. c[g + 24 >> 2] = x;
  5820. break
  5821. }
  5822. }
  5823. } while (0);
  5824. g = c[r + 20 >> 2] | 0;
  5825. if ((g | 0) == 0) {
  5826. break
  5827. }
  5828. if (g >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  5829. fa()
  5830. } else {
  5831. c[x + 20 >> 2] = g;
  5832. c[g + 24 >> 2] = x;
  5833. break
  5834. }
  5835. }
  5836. } while (0);
  5837. if (t >>> 0 < 16) {
  5838. f = t + d | 0;
  5839. c[r + 4 >> 2] = f | 3;
  5840. g = h + (f + 4) | 0;
  5841. c[g >> 2] = c[g >> 2] | 1
  5842. } else {
  5843. c[r + 4 >> 2] = d | 3;
  5844. c[h + (d | 4) >> 2] = t | 1;
  5845. c[h + (t + d) >> 2] = t;
  5846. g = c[10712 >> 2] | 0;
  5847. if ((g | 0) != 0) {
  5848. f = c[10724 >> 2] | 0;
  5849. k = g >>> 3;
  5850. g = k << 1;
  5851. m = 10744 + (g << 2) | 0;
  5852. e = c[2676] | 0;
  5853. s = 1 << k;
  5854. do {
  5855. if ((e & s | 0) == 0) {
  5856. c[2676] = e | s;
  5857. A = 10744 + (g + 2 << 2) | 0;
  5858. B = m
  5859. } else {
  5860. k = 10744 + (g + 2 << 2) | 0;
  5861. n = c[k >> 2] | 0;
  5862. if (!(n >>> 0 < (c[10720 >> 2] | 0) >>> 0)) {
  5863. A = k;
  5864. B = n;
  5865. break
  5866. }
  5867. fa()
  5868. }
  5869. } while (0);
  5870. c[A >> 2] = f;
  5871. c[B + 12 >> 2] = f;
  5872. c[f + 8 >> 2] = B;
  5873. c[f + 12 >> 2] = m
  5874. }
  5875. c[10712 >> 2] = t;
  5876. c[10724 >> 2] = o
  5877. }
  5878. p = r + 8 | 0;
  5879. i = b;
  5880. return p | 0
  5881. } else {
  5882. if (a >>> 0 > 4294967231) {
  5883. q = -1;
  5884. break
  5885. }
  5886. g = a + 11 | 0;
  5887. s = g & -8;
  5888. e = c[10708 >> 2] | 0;
  5889. if ((e | 0) == 0) {
  5890. q = s;
  5891. break
  5892. }
  5893. h = 0 - s | 0;
  5894. n = g >>> 8;
  5895. do {
  5896. if ((n | 0) == 0) {
  5897. C = 0
  5898. } else {
  5899. if (s >>> 0 > 16777215) {
  5900. C = 31;
  5901. break
  5902. }
  5903. g = (n + 1048320 | 0) >>> 16 & 8;
  5904. k = n << g;
  5905. j = (k + 520192 | 0) >>> 16 & 4;
  5906. l = k << j;
  5907. k = (l + 245760 | 0) >>> 16 & 2;
  5908. D = 14 - (j | g | k) + (l << k >>> 15) | 0;
  5909. C = s >>> (D + 7 | 0) & 1 | D << 1
  5910. }
  5911. } while (0);
  5912. n = c[11008 + (C << 2) >> 2] | 0;
  5913. b: do {
  5914. if ((n | 0) == 0) {
  5915. E = h;
  5916. F = 0;
  5917. G = 0
  5918. } else {
  5919. if ((C | 0) == 31) {
  5920. H = 0
  5921. } else {
  5922. H = 25 - (C >>> 1) | 0
  5923. }
  5924. r = h;
  5925. o = 0;
  5926. t = s << H;
  5927. m = n;
  5928. f = 0;
  5929. while (1) {
  5930. D = c[m + 4 >> 2] & -8;
  5931. k = D - s | 0;
  5932. if (k >>> 0 < r >>> 0) {
  5933. if ((D | 0) == (s | 0)) {
  5934. E = k;
  5935. F = m;
  5936. G = m;
  5937. break b
  5938. } else {
  5939. I = k;
  5940. J = m
  5941. }
  5942. } else {
  5943. I = r;
  5944. J = f
  5945. }
  5946. k = c[m + 20 >> 2] | 0;
  5947. D = c[m + (t >>> 31 << 2) + 16 >> 2] | 0;
  5948. l = (k | 0) == 0 | (k | 0) == (D | 0) ? o : k;
  5949. if ((D | 0) == 0) {
  5950. E = I;
  5951. F = l;
  5952. G = J;
  5953. break
  5954. } else {
  5955. r = I;
  5956. o = l;
  5957. t = t << 1;
  5958. m = D;
  5959. f = J
  5960. }
  5961. }
  5962. }
  5963. } while (0);
  5964. if ((F | 0) == 0 & (G | 0) == 0) {
  5965. n = 2 << C;
  5966. h = e & (n | 0 - n);
  5967. if ((h | 0) == 0) {
  5968. q = s;
  5969. break
  5970. }
  5971. n = (h & 0 - h) + -1 | 0;
  5972. h = n >>> 12 & 16;
  5973. f = n >>> h;
  5974. n = f >>> 5 & 8;
  5975. m = f >>> n;
  5976. f = m >>> 2 & 4;
  5977. t = m >>> f;
  5978. m = t >>> 1 & 2;
  5979. o = t >>> m;
  5980. t = o >>> 1 & 1;
  5981. K = c[11008 + ((n | h | f | m | t) + (o >>> t) << 2) >> 2] | 0
  5982. } else {
  5983. K = F
  5984. } if ((K | 0) == 0) {
  5985. L = E;
  5986. M = G
  5987. } else {
  5988. t = E;
  5989. o = K;
  5990. m = G;
  5991. while (1) {
  5992. f = (c[o + 4 >> 2] & -8) - s | 0;
  5993. h = f >>> 0 < t >>> 0;
  5994. n = h ? f : t;
  5995. f = h ? o : m;
  5996. h = c[o + 16 >> 2] | 0;
  5997. if ((h | 0) != 0) {
  5998. N = f;
  5999. O = n;
  6000. m = N;
  6001. o = h;
  6002. t = O;
  6003. continue
  6004. }
  6005. h = c[o + 20 >> 2] | 0;
  6006. if ((h | 0) == 0) {
  6007. L = n;
  6008. M = f;
  6009. break
  6010. } else {
  6011. N = f;
  6012. O = n;
  6013. o = h;
  6014. m = N;
  6015. t = O
  6016. }
  6017. }
  6018. } if ((M | 0) == 0) {
  6019. q = s;
  6020. break
  6021. }
  6022. if (!(L >>> 0 < ((c[10712 >> 2] | 0) - s | 0) >>> 0)) {
  6023. q = s;
  6024. break
  6025. }
  6026. t = M;
  6027. m = c[10720 >> 2] | 0;
  6028. if (t >>> 0 < m >>> 0) {
  6029. fa()
  6030. }
  6031. o = t + s | 0;
  6032. e = o;
  6033. if (!(t >>> 0 < o >>> 0)) {
  6034. fa()
  6035. }
  6036. h = c[M + 24 >> 2] | 0;
  6037. n = c[M + 12 >> 2] | 0;
  6038. do {
  6039. if ((n | 0) == (M | 0)) {
  6040. f = M + 20 | 0;
  6041. r = c[f >> 2] | 0;
  6042. if ((r | 0) == 0) {
  6043. D = M + 16 | 0;
  6044. l = c[D >> 2] | 0;
  6045. if ((l | 0) == 0) {
  6046. P = 0;
  6047. break
  6048. } else {
  6049. Q = l;
  6050. R = D
  6051. }
  6052. } else {
  6053. Q = r;
  6054. R = f
  6055. }
  6056. while (1) {
  6057. f = Q + 20 | 0;
  6058. r = c[f >> 2] | 0;
  6059. if ((r | 0) != 0) {
  6060. R = f;
  6061. Q = r;
  6062. continue
  6063. }
  6064. r = Q + 16 | 0;
  6065. f = c[r >> 2] | 0;
  6066. if ((f | 0) == 0) {
  6067. break
  6068. } else {
  6069. Q = f;
  6070. R = r
  6071. }
  6072. }
  6073. if (R >>> 0 < m >>> 0) {
  6074. fa()
  6075. } else {
  6076. c[R >> 2] = 0;
  6077. P = Q;
  6078. break
  6079. }
  6080. } else {
  6081. r = c[M + 8 >> 2] | 0;
  6082. if (r >>> 0 < m >>> 0) {
  6083. fa()
  6084. }
  6085. f = r + 12 | 0;
  6086. if ((c[f >> 2] | 0) != (M | 0)) {
  6087. fa()
  6088. }
  6089. D = n + 8 | 0;
  6090. if ((c[D >> 2] | 0) == (M | 0)) {
  6091. c[f >> 2] = n;
  6092. c[D >> 2] = r;
  6093. P = n;
  6094. break
  6095. } else {
  6096. fa()
  6097. }
  6098. }
  6099. } while (0);
  6100. c: do {
  6101. if ((h | 0) != 0) {
  6102. n = c[M + 28 >> 2] | 0;
  6103. m = 11008 + (n << 2) | 0;
  6104. do {
  6105. if ((M | 0) == (c[m >> 2] | 0)) {
  6106. c[m >> 2] = P;
  6107. if ((P | 0) != 0) {
  6108. break
  6109. }
  6110. c[10708 >> 2] = c[10708 >> 2] & ~(1 << n);
  6111. break c
  6112. } else {
  6113. if (h >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6114. fa()
  6115. }
  6116. r = h + 16 | 0;
  6117. if ((c[r >> 2] | 0) == (M | 0)) {
  6118. c[r >> 2] = P
  6119. } else {
  6120. c[h + 20 >> 2] = P
  6121. } if ((P | 0) == 0) {
  6122. break c
  6123. }
  6124. }
  6125. } while (0);
  6126. if (P >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6127. fa()
  6128. }
  6129. c[P + 24 >> 2] = h;
  6130. n = c[M + 16 >> 2] | 0;
  6131. do {
  6132. if ((n | 0) != 0) {
  6133. if (n >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6134. fa()
  6135. } else {
  6136. c[P + 16 >> 2] = n;
  6137. c[n + 24 >> 2] = P;
  6138. break
  6139. }
  6140. }
  6141. } while (0);
  6142. n = c[M + 20 >> 2] | 0;
  6143. if ((n | 0) == 0) {
  6144. break
  6145. }
  6146. if (n >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6147. fa()
  6148. } else {
  6149. c[P + 20 >> 2] = n;
  6150. c[n + 24 >> 2] = P;
  6151. break
  6152. }
  6153. }
  6154. } while (0);
  6155. d: do {
  6156. if (L >>> 0 < 16) {
  6157. h = L + s | 0;
  6158. c[M + 4 >> 2] = h | 3;
  6159. n = t + (h + 4) | 0;
  6160. c[n >> 2] = c[n >> 2] | 1
  6161. } else {
  6162. c[M + 4 >> 2] = s | 3;
  6163. c[t + (s | 4) >> 2] = L | 1;
  6164. c[t + (L + s) >> 2] = L;
  6165. n = L >>> 3;
  6166. if (L >>> 0 < 256) {
  6167. h = n << 1;
  6168. m = 10744 + (h << 2) | 0;
  6169. r = c[2676] | 0;
  6170. D = 1 << n;
  6171. do {
  6172. if ((r & D | 0) == 0) {
  6173. c[2676] = r | D;
  6174. S = 10744 + (h + 2 << 2) | 0;
  6175. T = m
  6176. } else {
  6177. n = 10744 + (h + 2 << 2) | 0;
  6178. f = c[n >> 2] | 0;
  6179. if (!(f >>> 0 < (c[10720 >> 2] | 0) >>> 0)) {
  6180. S = n;
  6181. T = f;
  6182. break
  6183. }
  6184. fa()
  6185. }
  6186. } while (0);
  6187. c[S >> 2] = e;
  6188. c[T + 12 >> 2] = e;
  6189. c[t + (s + 8) >> 2] = T;
  6190. c[t + (s + 12) >> 2] = m;
  6191. break
  6192. }
  6193. h = o;
  6194. D = L >>> 8;
  6195. do {
  6196. if ((D | 0) == 0) {
  6197. U = 0
  6198. } else {
  6199. if (L >>> 0 > 16777215) {
  6200. U = 31;
  6201. break
  6202. }
  6203. r = (D + 1048320 | 0) >>> 16 & 8;
  6204. f = D << r;
  6205. n = (f + 520192 | 0) >>> 16 & 4;
  6206. l = f << n;
  6207. f = (l + 245760 | 0) >>> 16 & 2;
  6208. k = 14 - (n | r | f) + (l << f >>> 15) | 0;
  6209. U = L >>> (k + 7 | 0) & 1 | k << 1
  6210. }
  6211. } while (0);
  6212. D = 11008 + (U << 2) | 0;
  6213. c[t + (s + 28) >> 2] = U;
  6214. c[t + (s + 20) >> 2] = 0;
  6215. c[t + (s + 16) >> 2] = 0;
  6216. m = c[10708 >> 2] | 0;
  6217. k = 1 << U;
  6218. if ((m & k | 0) == 0) {
  6219. c[10708 >> 2] = m | k;
  6220. c[D >> 2] = h;
  6221. c[t + (s + 24) >> 2] = D;
  6222. c[t + (s + 12) >> 2] = h;
  6223. c[t + (s + 8) >> 2] = h;
  6224. break
  6225. }
  6226. k = c[D >> 2] | 0;
  6227. if ((U | 0) == 31) {
  6228. V = 0
  6229. } else {
  6230. V = 25 - (U >>> 1) | 0
  6231. }
  6232. e: do {
  6233. if ((c[k + 4 >> 2] & -8 | 0) == (L | 0)) {
  6234. W = k
  6235. } else {
  6236. D = L << V;
  6237. m = k;
  6238. while (1) {
  6239. X = m + (D >>> 31 << 2) + 16 | 0;
  6240. f = c[X >> 2] | 0;
  6241. if ((f | 0) == 0) {
  6242. break
  6243. }
  6244. if ((c[f + 4 >> 2] & -8 | 0) == (L | 0)) {
  6245. W = f;
  6246. break e
  6247. } else {
  6248. D = D << 1;
  6249. m = f
  6250. }
  6251. }
  6252. if (X >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6253. fa()
  6254. } else {
  6255. c[X >> 2] = h;
  6256. c[t + (s + 24) >> 2] = m;
  6257. c[t + (s + 12) >> 2] = h;
  6258. c[t + (s + 8) >> 2] = h;
  6259. break d
  6260. }
  6261. }
  6262. } while (0);
  6263. k = W + 8 | 0;
  6264. D = c[k >> 2] | 0;
  6265. f = c[10720 >> 2] | 0;
  6266. if (W >>> 0 < f >>> 0) {
  6267. fa()
  6268. }
  6269. if (D >>> 0 < f >>> 0) {
  6270. fa()
  6271. } else {
  6272. c[D + 12 >> 2] = h;
  6273. c[k >> 2] = h;
  6274. c[t + (s + 8) >> 2] = D;
  6275. c[t + (s + 12) >> 2] = W;
  6276. c[t + (s + 24) >> 2] = 0;
  6277. break
  6278. }
  6279. }
  6280. } while (0);
  6281. p = M + 8 | 0;
  6282. i = b;
  6283. return p | 0
  6284. }
  6285. } while (0);
  6286. M = c[10712 >> 2] | 0;
  6287. if (!(q >>> 0 > M >>> 0)) {
  6288. W = M - q | 0;
  6289. X = c[10724 >> 2] | 0;
  6290. if (W >>> 0 > 15) {
  6291. L = X;
  6292. c[10724 >> 2] = L + q;
  6293. c[10712 >> 2] = W;
  6294. c[L + (q + 4) >> 2] = W | 1;
  6295. c[L + M >> 2] = W;
  6296. c[X + 4 >> 2] = q | 3
  6297. } else {
  6298. c[10712 >> 2] = 0;
  6299. c[10724 >> 2] = 0;
  6300. c[X + 4 >> 2] = M | 3;
  6301. W = X + (M + 4) | 0;
  6302. c[W >> 2] = c[W >> 2] | 1
  6303. }
  6304. p = X + 8 | 0;
  6305. i = b;
  6306. return p | 0
  6307. }
  6308. X = c[10716 >> 2] | 0;
  6309. if (q >>> 0 < X >>> 0) {
  6310. W = X - q | 0;
  6311. c[10716 >> 2] = W;
  6312. X = c[10728 >> 2] | 0;
  6313. M = X;
  6314. c[10728 >> 2] = M + q;
  6315. c[M + (q + 4) >> 2] = W | 1;
  6316. c[X + 4 >> 2] = q | 3;
  6317. p = X + 8 | 0;
  6318. i = b;
  6319. return p | 0
  6320. }
  6321. do {
  6322. if ((c[2794] | 0) == 0) {
  6323. X = ka(30) | 0;
  6324. if ((X + -1 & X | 0) == 0) {
  6325. c[11184 >> 2] = X;
  6326. c[11180 >> 2] = X;
  6327. c[11188 >> 2] = -1;
  6328. c[11192 >> 2] = -1;
  6329. c[11196 >> 2] = 0;
  6330. c[11148 >> 2] = 0;
  6331. c[2794] = (ia(0) | 0) & -16 ^ 1431655768;
  6332. break
  6333. } else {
  6334. fa()
  6335. }
  6336. }
  6337. } while (0);
  6338. X = q + 48 | 0;
  6339. W = c[11184 >> 2] | 0;
  6340. M = q + 47 | 0;
  6341. L = W + M | 0;
  6342. V = 0 - W | 0;
  6343. W = L & V;
  6344. if (!(W >>> 0 > q >>> 0)) {
  6345. p = 0;
  6346. i = b;
  6347. return p | 0
  6348. }
  6349. U = c[11144 >> 2] | 0;
  6350. do {
  6351. if ((U | 0) != 0) {
  6352. T = c[11136 >> 2] | 0;
  6353. S = T + W | 0;
  6354. if (S >>> 0 <= T >>> 0 | S >>> 0 > U >>> 0) {
  6355. p = 0
  6356. } else {
  6357. break
  6358. }
  6359. i = b;
  6360. return p | 0
  6361. }
  6362. } while (0);
  6363. f: do {
  6364. if ((c[11148 >> 2] & 4 | 0) == 0) {
  6365. U = c[10728 >> 2] | 0;
  6366. g: do {
  6367. if ((U | 0) == 0) {
  6368. Y = 182
  6369. } else {
  6370. S = U;
  6371. T = 11152 | 0;
  6372. while (1) {
  6373. Z = T;
  6374. P = c[Z >> 2] | 0;
  6375. if (!(P >>> 0 > S >>> 0)) {
  6376. _ = T + 4 | 0;
  6377. if ((P + (c[_ >> 2] | 0) | 0) >>> 0 > S >>> 0) {
  6378. break
  6379. }
  6380. }
  6381. P = c[T + 8 >> 2] | 0;
  6382. if ((P | 0) == 0) {
  6383. Y = 182;
  6384. break g
  6385. } else {
  6386. T = P
  6387. }
  6388. }
  6389. if ((T | 0) == 0) {
  6390. Y = 182;
  6391. break
  6392. }
  6393. S = L - (c[10716 >> 2] | 0) & V;
  6394. if (!(S >>> 0 < 2147483647)) {
  6395. $ = 0;
  6396. break
  6397. }
  6398. h = ha(S | 0) | 0;
  6399. P = (h | 0) == ((c[Z >> 2] | 0) + (c[_ >> 2] | 0) | 0);
  6400. aa = h;
  6401. ba = S;
  6402. ca = P ? h : -1;
  6403. da = P ? S : 0;
  6404. Y = 191
  6405. }
  6406. } while (0);
  6407. do {
  6408. if ((Y | 0) == 182) {
  6409. U = ha(0) | 0;
  6410. if ((U | 0) == (-1 | 0)) {
  6411. $ = 0;
  6412. break
  6413. }
  6414. S = U;
  6415. P = c[11180 >> 2] | 0;
  6416. h = P + -1 | 0;
  6417. if ((h & S | 0) == 0) {
  6418. ea = W
  6419. } else {
  6420. ea = W - S + (h + S & 0 - P) | 0
  6421. }
  6422. P = c[11136 >> 2] | 0;
  6423. S = P + ea | 0;
  6424. if (!(ea >>> 0 > q >>> 0 & ea >>> 0 < 2147483647)) {
  6425. $ = 0;
  6426. break
  6427. }
  6428. h = c[11144 >> 2] | 0;
  6429. if ((h | 0) != 0) {
  6430. if (S >>> 0 <= P >>> 0 | S >>> 0 > h >>> 0) {
  6431. $ = 0;
  6432. break
  6433. }
  6434. }
  6435. h = ha(ea | 0) | 0;
  6436. S = (h | 0) == (U | 0);
  6437. aa = h;
  6438. ba = ea;
  6439. ca = S ? U : -1;
  6440. da = S ? ea : 0;
  6441. Y = 191
  6442. }
  6443. } while (0);
  6444. h: do {
  6445. if ((Y | 0) == 191) {
  6446. S = 0 - ba | 0;
  6447. if ((ca | 0) != (-1 | 0)) {
  6448. ga = ca;
  6449. ja = da;
  6450. Y = 202;
  6451. break f
  6452. }
  6453. do {
  6454. if ((aa | 0) != (-1 | 0) & ba >>> 0 < 2147483647 & ba >>> 0 < X >>> 0) {
  6455. U = c[11184 >> 2] | 0;
  6456. h = M - ba + U & 0 - U;
  6457. if (!(h >>> 0 < 2147483647)) {
  6458. ma = ba;
  6459. break
  6460. }
  6461. if ((ha(h | 0) | 0) == (-1 | 0)) {
  6462. ha(S | 0) | 0;
  6463. $ = da;
  6464. break h
  6465. } else {
  6466. ma = h + ba | 0;
  6467. break
  6468. }
  6469. } else {
  6470. ma = ba
  6471. }
  6472. } while (0);
  6473. if ((aa | 0) == (-1 | 0)) {
  6474. $ = da
  6475. } else {
  6476. ga = aa;
  6477. ja = ma;
  6478. Y = 202;
  6479. break f
  6480. }
  6481. }
  6482. } while (0);
  6483. c[11148 >> 2] = c[11148 >> 2] | 4;
  6484. na = $;
  6485. Y = 199
  6486. } else {
  6487. na = 0;
  6488. Y = 199
  6489. }
  6490. } while (0);
  6491. do {
  6492. if ((Y | 0) == 199) {
  6493. if (!(W >>> 0 < 2147483647)) {
  6494. break
  6495. }
  6496. $ = ha(W | 0) | 0;
  6497. ma = ha(0) | 0;
  6498. if (!((ma | 0) != (-1 | 0) & ($ | 0) != (-1 | 0) & $ >>> 0 < ma >>> 0)) {
  6499. break
  6500. }
  6501. aa = ma - $ | 0;
  6502. ma = aa >>> 0 > (q + 40 | 0) >>> 0;
  6503. if (ma) {
  6504. ga = $;
  6505. ja = ma ? aa : na;
  6506. Y = 202
  6507. }
  6508. }
  6509. } while (0);
  6510. do {
  6511. if ((Y | 0) == 202) {
  6512. na = (c[11136 >> 2] | 0) + ja | 0;
  6513. c[11136 >> 2] = na;
  6514. if (na >>> 0 > (c[11140 >> 2] | 0) >>> 0) {
  6515. c[11140 >> 2] = na
  6516. }
  6517. na = c[10728 >> 2] | 0;
  6518. i: do {
  6519. if ((na | 0) == 0) {
  6520. W = c[10720 >> 2] | 0;
  6521. if ((W | 0) == 0 | ga >>> 0 < W >>> 0) {
  6522. c[10720 >> 2] = ga
  6523. }
  6524. c[11152 >> 2] = ga;
  6525. c[11156 >> 2] = ja;
  6526. c[11164 >> 2] = 0;
  6527. c[10740 >> 2] = c[2794];
  6528. c[10736 >> 2] = -1;
  6529. W = 0;
  6530. do {
  6531. aa = W << 1;
  6532. ma = 10744 + (aa << 2) | 0;
  6533. c[10744 + (aa + 3 << 2) >> 2] = ma;
  6534. c[10744 + (aa + 2 << 2) >> 2] = ma;
  6535. W = W + 1 | 0;
  6536. } while ((W | 0) != 32);
  6537. W = ga + 8 | 0;
  6538. if ((W & 7 | 0) == 0) {
  6539. oa = 0
  6540. } else {
  6541. oa = 0 - W & 7
  6542. }
  6543. W = ja + -40 - oa | 0;
  6544. c[10728 >> 2] = ga + oa;
  6545. c[10716 >> 2] = W;
  6546. c[ga + (oa + 4) >> 2] = W | 1;
  6547. c[ga + (ja + -36) >> 2] = 40;
  6548. c[10732 >> 2] = c[11192 >> 2]
  6549. } else {
  6550. W = 11152 | 0;
  6551. while (1) {
  6552. pa = c[W >> 2] | 0;
  6553. qa = W + 4 | 0;
  6554. ra = c[qa >> 2] | 0;
  6555. if ((ga | 0) == (pa + ra | 0)) {
  6556. Y = 214;
  6557. break
  6558. }
  6559. ma = c[W + 8 >> 2] | 0;
  6560. if ((ma | 0) == 0) {
  6561. break
  6562. } else {
  6563. W = ma
  6564. }
  6565. }
  6566. do {
  6567. if ((Y | 0) == 214) {
  6568. if ((c[W + 12 >> 2] & 8 | 0) != 0) {
  6569. break
  6570. }
  6571. ma = na;
  6572. if (!(ma >>> 0 >= pa >>> 0 & ma >>> 0 < ga >>> 0)) {
  6573. break
  6574. }
  6575. c[qa >> 2] = ra + ja;
  6576. aa = (c[10716 >> 2] | 0) + ja | 0;
  6577. $ = na + 8 | 0;
  6578. if (($ & 7 | 0) == 0) {
  6579. sa = 0
  6580. } else {
  6581. sa = 0 - $ & 7
  6582. }
  6583. $ = aa - sa | 0;
  6584. c[10728 >> 2] = ma + sa;
  6585. c[10716 >> 2] = $;
  6586. c[ma + (sa + 4) >> 2] = $ | 1;
  6587. c[ma + (aa + 4) >> 2] = 40;
  6588. c[10732 >> 2] = c[11192 >> 2];
  6589. break i
  6590. }
  6591. } while (0);
  6592. if (ga >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6593. c[10720 >> 2] = ga
  6594. }
  6595. W = ga + ja | 0;
  6596. aa = 11152 | 0;
  6597. while (1) {
  6598. ta = aa;
  6599. if ((c[ta >> 2] | 0) == (W | 0)) {
  6600. Y = 224;
  6601. break
  6602. }
  6603. ma = c[aa + 8 >> 2] | 0;
  6604. if ((ma | 0) == 0) {
  6605. break
  6606. } else {
  6607. aa = ma
  6608. }
  6609. }
  6610. do {
  6611. if ((Y | 0) == 224) {
  6612. if ((c[aa + 12 >> 2] & 8 | 0) != 0) {
  6613. break
  6614. }
  6615. c[ta >> 2] = ga;
  6616. W = aa + 4 | 0;
  6617. c[W >> 2] = (c[W >> 2] | 0) + ja;
  6618. W = ga + 8 | 0;
  6619. if ((W & 7 | 0) == 0) {
  6620. ua = 0
  6621. } else {
  6622. ua = 0 - W & 7
  6623. }
  6624. W = ga + (ja + 8) | 0;
  6625. if ((W & 7 | 0) == 0) {
  6626. va = 0
  6627. } else {
  6628. va = 0 - W & 7
  6629. }
  6630. W = ga + (va + ja) | 0;
  6631. ma = W;
  6632. $ = ua + q | 0;
  6633. da = ga + $ | 0;
  6634. ba = da;
  6635. M = W - (ga + ua) - q | 0;
  6636. c[ga + (ua + 4) >> 2] = q | 3;
  6637. j: do {
  6638. if ((ma | 0) == (c[10728 >> 2] | 0)) {
  6639. X = (c[10716 >> 2] | 0) + M | 0;
  6640. c[10716 >> 2] = X;
  6641. c[10728 >> 2] = ba;
  6642. c[ga + ($ + 4) >> 2] = X | 1
  6643. } else {
  6644. if ((ma | 0) == (c[10724 >> 2] | 0)) {
  6645. X = (c[10712 >> 2] | 0) + M | 0;
  6646. c[10712 >> 2] = X;
  6647. c[10724 >> 2] = ba;
  6648. c[ga + ($ + 4) >> 2] = X | 1;
  6649. c[ga + (X + $) >> 2] = X;
  6650. break
  6651. }
  6652. X = ja + 4 | 0;
  6653. ca = c[ga + (X + va) >> 2] | 0;
  6654. if ((ca & 3 | 0) == 1) {
  6655. ea = ca & -8;
  6656. _ = ca >>> 3;
  6657. k: do {
  6658. if (ca >>> 0 < 256) {
  6659. Z = c[ga + ((va | 8) + ja) >> 2] | 0;
  6660. V = c[ga + (ja + 12 + va) >> 2] | 0;
  6661. L = 10744 + (_ << 1 << 2) | 0;
  6662. do {
  6663. if ((Z | 0) != (L | 0)) {
  6664. if (Z >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6665. fa()
  6666. }
  6667. if ((c[Z + 12 >> 2] | 0) == (ma | 0)) {
  6668. break
  6669. }
  6670. fa()
  6671. }
  6672. } while (0);
  6673. if ((V | 0) == (Z | 0)) {
  6674. c[2676] = c[2676] & ~(1 << _);
  6675. break
  6676. }
  6677. do {
  6678. if ((V | 0) == (L | 0)) {
  6679. wa = V + 8 | 0
  6680. } else {
  6681. if (V >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6682. fa()
  6683. }
  6684. S = V + 8 | 0;
  6685. if ((c[S >> 2] | 0) == (ma | 0)) {
  6686. wa = S;
  6687. break
  6688. }
  6689. fa()
  6690. }
  6691. } while (0);
  6692. c[Z + 12 >> 2] = V;
  6693. c[wa >> 2] = Z
  6694. } else {
  6695. L = W;
  6696. S = c[ga + ((va | 24) + ja) >> 2] | 0;
  6697. T = c[ga + (ja + 12 + va) >> 2] | 0;
  6698. do {
  6699. if ((T | 0) == (L | 0)) {
  6700. h = va | 16;
  6701. U = ga + (X + h) | 0;
  6702. P = c[U >> 2] | 0;
  6703. if ((P | 0) == 0) {
  6704. Q = ga + (h + ja) | 0;
  6705. h = c[Q >> 2] | 0;
  6706. if ((h | 0) == 0) {
  6707. xa = 0;
  6708. break
  6709. } else {
  6710. ya = h;
  6711. za = Q
  6712. }
  6713. } else {
  6714. ya = P;
  6715. za = U
  6716. }
  6717. while (1) {
  6718. U = ya + 20 | 0;
  6719. P = c[U >> 2] | 0;
  6720. if ((P | 0) != 0) {
  6721. za = U;
  6722. ya = P;
  6723. continue
  6724. }
  6725. P = ya + 16 | 0;
  6726. U = c[P >> 2] | 0;
  6727. if ((U | 0) == 0) {
  6728. break
  6729. } else {
  6730. ya = U;
  6731. za = P
  6732. }
  6733. }
  6734. if (za >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6735. fa()
  6736. } else {
  6737. c[za >> 2] = 0;
  6738. xa = ya;
  6739. break
  6740. }
  6741. } else {
  6742. P = c[ga + ((va | 8) + ja) >> 2] | 0;
  6743. if (P >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6744. fa()
  6745. }
  6746. U = P + 12 | 0;
  6747. if ((c[U >> 2] | 0) != (L | 0)) {
  6748. fa()
  6749. }
  6750. Q = T + 8 | 0;
  6751. if ((c[Q >> 2] | 0) == (L | 0)) {
  6752. c[U >> 2] = T;
  6753. c[Q >> 2] = P;
  6754. xa = T;
  6755. break
  6756. } else {
  6757. fa()
  6758. }
  6759. }
  6760. } while (0);
  6761. if ((S | 0) == 0) {
  6762. break
  6763. }
  6764. T = c[ga + (ja + 28 + va) >> 2] | 0;
  6765. Z = 11008 + (T << 2) | 0;
  6766. do {
  6767. if ((L | 0) == (c[Z >> 2] | 0)) {
  6768. c[Z >> 2] = xa;
  6769. if ((xa | 0) != 0) {
  6770. break
  6771. }
  6772. c[10708 >> 2] = c[10708 >> 2] & ~(1 << T);
  6773. break k
  6774. } else {
  6775. if (S >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6776. fa()
  6777. }
  6778. V = S + 16 | 0;
  6779. if ((c[V >> 2] | 0) == (L | 0)) {
  6780. c[V >> 2] = xa
  6781. } else {
  6782. c[S + 20 >> 2] = xa
  6783. } if ((xa | 0) == 0) {
  6784. break k
  6785. }
  6786. }
  6787. } while (0);
  6788. if (xa >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6789. fa()
  6790. }
  6791. c[xa + 24 >> 2] = S;
  6792. L = va | 16;
  6793. T = c[ga + (L + ja) >> 2] | 0;
  6794. do {
  6795. if ((T | 0) != 0) {
  6796. if (T >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6797. fa()
  6798. } else {
  6799. c[xa + 16 >> 2] = T;
  6800. c[T + 24 >> 2] = xa;
  6801. break
  6802. }
  6803. }
  6804. } while (0);
  6805. T = c[ga + (X + L) >> 2] | 0;
  6806. if ((T | 0) == 0) {
  6807. break
  6808. }
  6809. if (T >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6810. fa()
  6811. } else {
  6812. c[xa + 20 >> 2] = T;
  6813. c[T + 24 >> 2] = xa;
  6814. break
  6815. }
  6816. }
  6817. } while (0);
  6818. Aa = ga + ((ea | va) + ja) | 0;
  6819. Ba = ea + M | 0
  6820. } else {
  6821. Aa = ma;
  6822. Ba = M
  6823. }
  6824. X = Aa + 4 | 0;
  6825. c[X >> 2] = c[X >> 2] & -2;
  6826. c[ga + ($ + 4) >> 2] = Ba | 1;
  6827. c[ga + (Ba + $) >> 2] = Ba;
  6828. X = Ba >>> 3;
  6829. if (Ba >>> 0 < 256) {
  6830. _ = X << 1;
  6831. ca = 10744 + (_ << 2) | 0;
  6832. T = c[2676] | 0;
  6833. S = 1 << X;
  6834. do {
  6835. if ((T & S | 0) == 0) {
  6836. c[2676] = T | S;
  6837. Ca = 10744 + (_ + 2 << 2) | 0;
  6838. Da = ca
  6839. } else {
  6840. X = 10744 + (_ + 2 << 2) | 0;
  6841. Z = c[X >> 2] | 0;
  6842. if (!(Z >>> 0 < (c[10720 >> 2] | 0) >>> 0)) {
  6843. Ca = X;
  6844. Da = Z;
  6845. break
  6846. }
  6847. fa()
  6848. }
  6849. } while (0);
  6850. c[Ca >> 2] = ba;
  6851. c[Da + 12 >> 2] = ba;
  6852. c[ga + ($ + 8) >> 2] = Da;
  6853. c[ga + ($ + 12) >> 2] = ca;
  6854. break
  6855. }
  6856. _ = da;
  6857. S = Ba >>> 8;
  6858. do {
  6859. if ((S | 0) == 0) {
  6860. Ea = 0
  6861. } else {
  6862. if (Ba >>> 0 > 16777215) {
  6863. Ea = 31;
  6864. break
  6865. }
  6866. T = (S + 1048320 | 0) >>> 16 & 8;
  6867. ea = S << T;
  6868. Z = (ea + 520192 | 0) >>> 16 & 4;
  6869. X = ea << Z;
  6870. ea = (X + 245760 | 0) >>> 16 & 2;
  6871. V = 14 - (Z | T | ea) + (X << ea >>> 15) | 0;
  6872. Ea = Ba >>> (V + 7 | 0) & 1 | V << 1
  6873. }
  6874. } while (0);
  6875. S = 11008 + (Ea << 2) | 0;
  6876. c[ga + ($ + 28) >> 2] = Ea;
  6877. c[ga + ($ + 20) >> 2] = 0;
  6878. c[ga + ($ + 16) >> 2] = 0;
  6879. ca = c[10708 >> 2] | 0;
  6880. V = 1 << Ea;
  6881. if ((ca & V | 0) == 0) {
  6882. c[10708 >> 2] = ca | V;
  6883. c[S >> 2] = _;
  6884. c[ga + ($ + 24) >> 2] = S;
  6885. c[ga + ($ + 12) >> 2] = _;
  6886. c[ga + ($ + 8) >> 2] = _;
  6887. break
  6888. }
  6889. V = c[S >> 2] | 0;
  6890. if ((Ea | 0) == 31) {
  6891. Fa = 0
  6892. } else {
  6893. Fa = 25 - (Ea >>> 1) | 0
  6894. }
  6895. l: do {
  6896. if ((c[V + 4 >> 2] & -8 | 0) == (Ba | 0)) {
  6897. Ga = V
  6898. } else {
  6899. S = Ba << Fa;
  6900. ca = V;
  6901. while (1) {
  6902. Ha = ca + (S >>> 31 << 2) + 16 | 0;
  6903. ea = c[Ha >> 2] | 0;
  6904. if ((ea | 0) == 0) {
  6905. break
  6906. }
  6907. if ((c[ea + 4 >> 2] & -8 | 0) == (Ba | 0)) {
  6908. Ga = ea;
  6909. break l
  6910. } else {
  6911. S = S << 1;
  6912. ca = ea
  6913. }
  6914. }
  6915. if (Ha >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  6916. fa()
  6917. } else {
  6918. c[Ha >> 2] = _;
  6919. c[ga + ($ + 24) >> 2] = ca;
  6920. c[ga + ($ + 12) >> 2] = _;
  6921. c[ga + ($ + 8) >> 2] = _;
  6922. break j
  6923. }
  6924. }
  6925. } while (0);
  6926. V = Ga + 8 | 0;
  6927. S = c[V >> 2] | 0;
  6928. L = c[10720 >> 2] | 0;
  6929. if (Ga >>> 0 < L >>> 0) {
  6930. fa()
  6931. }
  6932. if (S >>> 0 < L >>> 0) {
  6933. fa()
  6934. } else {
  6935. c[S + 12 >> 2] = _;
  6936. c[V >> 2] = _;
  6937. c[ga + ($ + 8) >> 2] = S;
  6938. c[ga + ($ + 12) >> 2] = Ga;
  6939. c[ga + ($ + 24) >> 2] = 0;
  6940. break
  6941. }
  6942. }
  6943. } while (0);
  6944. p = ga + (ua | 8) | 0;
  6945. i = b;
  6946. return p | 0
  6947. }
  6948. } while (0);
  6949. aa = na;
  6950. $ = 11152 | 0;
  6951. while (1) {
  6952. Ia = c[$ >> 2] | 0;
  6953. if (!(Ia >>> 0 > aa >>> 0)) {
  6954. Ja = c[$ + 4 >> 2] | 0;
  6955. Ka = Ia + Ja | 0;
  6956. if (Ka >>> 0 > aa >>> 0) {
  6957. break
  6958. }
  6959. }
  6960. $ = c[$ + 8 >> 2] | 0
  6961. }
  6962. $ = Ia + (Ja + -39) | 0;
  6963. if (($ & 7 | 0) == 0) {
  6964. La = 0
  6965. } else {
  6966. La = 0 - $ & 7
  6967. }
  6968. $ = Ia + (Ja + -47 + La) | 0;
  6969. da = $ >>> 0 < (na + 16 | 0) >>> 0 ? aa : $;
  6970. $ = da + 8 | 0;
  6971. ba = $;
  6972. M = ga + 8 | 0;
  6973. if ((M & 7 | 0) == 0) {
  6974. Ma = 0
  6975. } else {
  6976. Ma = 0 - M & 7
  6977. }
  6978. M = ja + -40 - Ma | 0;
  6979. c[10728 >> 2] = ga + Ma;
  6980. c[10716 >> 2] = M;
  6981. c[ga + (Ma + 4) >> 2] = M | 1;
  6982. c[ga + (ja + -36) >> 2] = 40;
  6983. c[10732 >> 2] = c[11192 >> 2];
  6984. c[da + 4 >> 2] = 27;
  6985. c[$ + 0 >> 2] = c[11152 >> 2];
  6986. c[$ + 4 >> 2] = c[11156 >> 2];
  6987. c[$ + 8 >> 2] = c[11160 >> 2];
  6988. c[$ + 12 >> 2] = c[11164 >> 2];
  6989. c[11152 >> 2] = ga;
  6990. c[11156 >> 2] = ja;
  6991. c[11164 >> 2] = 0;
  6992. c[11160 >> 2] = ba;
  6993. ba = da + 28 | 0;
  6994. c[ba >> 2] = 7;
  6995. if ((da + 32 | 0) >>> 0 < Ka >>> 0) {
  6996. $ = ba;
  6997. while (1) {
  6998. ba = $ + 4 | 0;
  6999. c[ba >> 2] = 7;
  7000. if (($ + 8 | 0) >>> 0 < Ka >>> 0) {
  7001. $ = ba
  7002. } else {
  7003. break
  7004. }
  7005. }
  7006. }
  7007. if ((da | 0) == (aa | 0)) {
  7008. break
  7009. }
  7010. $ = da - na | 0;
  7011. ba = aa + ($ + 4) | 0;
  7012. c[ba >> 2] = c[ba >> 2] & -2;
  7013. c[na + 4 >> 2] = $ | 1;
  7014. c[aa + $ >> 2] = $;
  7015. ba = $ >>> 3;
  7016. if ($ >>> 0 < 256) {
  7017. M = ba << 1;
  7018. ma = 10744 + (M << 2) | 0;
  7019. W = c[2676] | 0;
  7020. m = 1 << ba;
  7021. do {
  7022. if ((W & m | 0) == 0) {
  7023. c[2676] = W | m;
  7024. Na = 10744 + (M + 2 << 2) | 0;
  7025. Oa = ma
  7026. } else {
  7027. ba = 10744 + (M + 2 << 2) | 0;
  7028. S = c[ba >> 2] | 0;
  7029. if (!(S >>> 0 < (c[10720 >> 2] | 0) >>> 0)) {
  7030. Na = ba;
  7031. Oa = S;
  7032. break
  7033. }
  7034. fa()
  7035. }
  7036. } while (0);
  7037. c[Na >> 2] = na;
  7038. c[Oa + 12 >> 2] = na;
  7039. c[na + 8 >> 2] = Oa;
  7040. c[na + 12 >> 2] = ma;
  7041. break
  7042. }
  7043. M = na;
  7044. m = $ >>> 8;
  7045. do {
  7046. if ((m | 0) == 0) {
  7047. Pa = 0
  7048. } else {
  7049. if ($ >>> 0 > 16777215) {
  7050. Pa = 31;
  7051. break
  7052. }
  7053. W = (m + 1048320 | 0) >>> 16 & 8;
  7054. aa = m << W;
  7055. da = (aa + 520192 | 0) >>> 16 & 4;
  7056. S = aa << da;
  7057. aa = (S + 245760 | 0) >>> 16 & 2;
  7058. ba = 14 - (da | W | aa) + (S << aa >>> 15) | 0;
  7059. Pa = $ >>> (ba + 7 | 0) & 1 | ba << 1
  7060. }
  7061. } while (0);
  7062. m = 11008 + (Pa << 2) | 0;
  7063. c[na + 28 >> 2] = Pa;
  7064. c[na + 20 >> 2] = 0;
  7065. c[na + 16 >> 2] = 0;
  7066. ma = c[10708 >> 2] | 0;
  7067. ba = 1 << Pa;
  7068. if ((ma & ba | 0) == 0) {
  7069. c[10708 >> 2] = ma | ba;
  7070. c[m >> 2] = M;
  7071. c[na + 24 >> 2] = m;
  7072. c[na + 12 >> 2] = na;
  7073. c[na + 8 >> 2] = na;
  7074. break
  7075. }
  7076. ba = c[m >> 2] | 0;
  7077. if ((Pa | 0) == 31) {
  7078. Qa = 0
  7079. } else {
  7080. Qa = 25 - (Pa >>> 1) | 0
  7081. }
  7082. m: do {
  7083. if ((c[ba + 4 >> 2] & -8 | 0) == ($ | 0)) {
  7084. Ra = ba
  7085. } else {
  7086. m = $ << Qa;
  7087. ma = ba;
  7088. while (1) {
  7089. Sa = ma + (m >>> 31 << 2) + 16 | 0;
  7090. aa = c[Sa >> 2] | 0;
  7091. if ((aa | 0) == 0) {
  7092. break
  7093. }
  7094. if ((c[aa + 4 >> 2] & -8 | 0) == ($ | 0)) {
  7095. Ra = aa;
  7096. break m
  7097. } else {
  7098. m = m << 1;
  7099. ma = aa
  7100. }
  7101. }
  7102. if (Sa >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7103. fa()
  7104. } else {
  7105. c[Sa >> 2] = M;
  7106. c[na + 24 >> 2] = ma;
  7107. c[na + 12 >> 2] = na;
  7108. c[na + 8 >> 2] = na;
  7109. break i
  7110. }
  7111. }
  7112. } while (0);
  7113. $ = Ra + 8 | 0;
  7114. ba = c[$ >> 2] | 0;
  7115. m = c[10720 >> 2] | 0;
  7116. if (Ra >>> 0 < m >>> 0) {
  7117. fa()
  7118. }
  7119. if (ba >>> 0 < m >>> 0) {
  7120. fa()
  7121. } else {
  7122. c[ba + 12 >> 2] = M;
  7123. c[$ >> 2] = M;
  7124. c[na + 8 >> 2] = ba;
  7125. c[na + 12 >> 2] = Ra;
  7126. c[na + 24 >> 2] = 0;
  7127. break
  7128. }
  7129. }
  7130. } while (0);
  7131. na = c[10716 >> 2] | 0;
  7132. if (!(na >>> 0 > q >>> 0)) {
  7133. break
  7134. }
  7135. ba = na - q | 0;
  7136. c[10716 >> 2] = ba;
  7137. na = c[10728 >> 2] | 0;
  7138. $ = na;
  7139. c[10728 >> 2] = $ + q;
  7140. c[$ + (q + 4) >> 2] = ba | 1;
  7141. c[na + 4 >> 2] = q | 3;
  7142. p = na + 8 | 0;
  7143. i = b;
  7144. return p | 0
  7145. }
  7146. } while (0);
  7147. c[(la() | 0) >> 2] = 12;
  7148. p = 0;
  7149. i = b;
  7150. return p | 0
  7151. }
  7152. function Fa(a) {
  7153. a = a | 0;
  7154. var b = 0,
  7155. d = 0,
  7156. e = 0,
  7157. f = 0,
  7158. g = 0,
  7159. h = 0,
  7160. j = 0,
  7161. k = 0,
  7162. l = 0,
  7163. m = 0,
  7164. n = 0,
  7165. o = 0,
  7166. p = 0,
  7167. q = 0,
  7168. r = 0,
  7169. s = 0,
  7170. t = 0,
  7171. u = 0,
  7172. v = 0,
  7173. w = 0,
  7174. x = 0,
  7175. y = 0,
  7176. z = 0,
  7177. A = 0,
  7178. B = 0,
  7179. C = 0,
  7180. D = 0,
  7181. E = 0,
  7182. F = 0,
  7183. G = 0,
  7184. H = 0,
  7185. I = 0,
  7186. J = 0,
  7187. K = 0,
  7188. L = 0,
  7189. M = 0,
  7190. N = 0,
  7191. O = 0,
  7192. P = 0,
  7193. Q = 0;
  7194. b = i;
  7195. if ((a | 0) == 0) {
  7196. i = b;
  7197. return
  7198. }
  7199. d = a + -8 | 0;
  7200. e = d;
  7201. f = c[10720 >> 2] | 0;
  7202. if (d >>> 0 < f >>> 0) {
  7203. fa()
  7204. }
  7205. g = c[a + -4 >> 2] | 0;
  7206. h = g & 3;
  7207. if ((h | 0) == 1) {
  7208. fa()
  7209. }
  7210. j = g & -8;
  7211. k = a + (j + -8) | 0;
  7212. l = k;
  7213. a: do {
  7214. if ((g & 1 | 0) == 0) {
  7215. m = c[d >> 2] | 0;
  7216. if ((h | 0) == 0) {
  7217. i = b;
  7218. return
  7219. }
  7220. n = -8 - m | 0;
  7221. o = a + n | 0;
  7222. p = o;
  7223. q = m + j | 0;
  7224. if (o >>> 0 < f >>> 0) {
  7225. fa()
  7226. }
  7227. if ((p | 0) == (c[10724 >> 2] | 0)) {
  7228. r = a + (j + -4) | 0;
  7229. if ((c[r >> 2] & 3 | 0) != 3) {
  7230. s = p;
  7231. t = q;
  7232. break
  7233. }
  7234. c[10712 >> 2] = q;
  7235. c[r >> 2] = c[r >> 2] & -2;
  7236. c[a + (n + 4) >> 2] = q | 1;
  7237. c[k >> 2] = q;
  7238. i = b;
  7239. return
  7240. }
  7241. r = m >>> 3;
  7242. if (m >>> 0 < 256) {
  7243. m = c[a + (n + 8) >> 2] | 0;
  7244. u = c[a + (n + 12) >> 2] | 0;
  7245. v = 10744 + (r << 1 << 2) | 0;
  7246. do {
  7247. if ((m | 0) != (v | 0)) {
  7248. if (m >>> 0 < f >>> 0) {
  7249. fa()
  7250. }
  7251. if ((c[m + 12 >> 2] | 0) == (p | 0)) {
  7252. break
  7253. }
  7254. fa()
  7255. }
  7256. } while (0);
  7257. if ((u | 0) == (m | 0)) {
  7258. c[2676] = c[2676] & ~(1 << r);
  7259. s = p;
  7260. t = q;
  7261. break
  7262. }
  7263. do {
  7264. if ((u | 0) == (v | 0)) {
  7265. w = u + 8 | 0
  7266. } else {
  7267. if (u >>> 0 < f >>> 0) {
  7268. fa()
  7269. }
  7270. x = u + 8 | 0;
  7271. if ((c[x >> 2] | 0) == (p | 0)) {
  7272. w = x;
  7273. break
  7274. }
  7275. fa()
  7276. }
  7277. } while (0);
  7278. c[m + 12 >> 2] = u;
  7279. c[w >> 2] = m;
  7280. s = p;
  7281. t = q;
  7282. break
  7283. }
  7284. v = o;
  7285. r = c[a + (n + 24) >> 2] | 0;
  7286. x = c[a + (n + 12) >> 2] | 0;
  7287. do {
  7288. if ((x | 0) == (v | 0)) {
  7289. y = a + (n + 20) | 0;
  7290. z = c[y >> 2] | 0;
  7291. if ((z | 0) == 0) {
  7292. A = a + (n + 16) | 0;
  7293. B = c[A >> 2] | 0;
  7294. if ((B | 0) == 0) {
  7295. C = 0;
  7296. break
  7297. } else {
  7298. D = B;
  7299. E = A
  7300. }
  7301. } else {
  7302. D = z;
  7303. E = y
  7304. }
  7305. while (1) {
  7306. y = D + 20 | 0;
  7307. z = c[y >> 2] | 0;
  7308. if ((z | 0) != 0) {
  7309. E = y;
  7310. D = z;
  7311. continue
  7312. }
  7313. z = D + 16 | 0;
  7314. y = c[z >> 2] | 0;
  7315. if ((y | 0) == 0) {
  7316. break
  7317. } else {
  7318. D = y;
  7319. E = z
  7320. }
  7321. }
  7322. if (E >>> 0 < f >>> 0) {
  7323. fa()
  7324. } else {
  7325. c[E >> 2] = 0;
  7326. C = D;
  7327. break
  7328. }
  7329. } else {
  7330. z = c[a + (n + 8) >> 2] | 0;
  7331. if (z >>> 0 < f >>> 0) {
  7332. fa()
  7333. }
  7334. y = z + 12 | 0;
  7335. if ((c[y >> 2] | 0) != (v | 0)) {
  7336. fa()
  7337. }
  7338. A = x + 8 | 0;
  7339. if ((c[A >> 2] | 0) == (v | 0)) {
  7340. c[y >> 2] = x;
  7341. c[A >> 2] = z;
  7342. C = x;
  7343. break
  7344. } else {
  7345. fa()
  7346. }
  7347. }
  7348. } while (0);
  7349. if ((r | 0) == 0) {
  7350. s = p;
  7351. t = q;
  7352. break
  7353. }
  7354. x = c[a + (n + 28) >> 2] | 0;
  7355. o = 11008 + (x << 2) | 0;
  7356. do {
  7357. if ((v | 0) == (c[o >> 2] | 0)) {
  7358. c[o >> 2] = C;
  7359. if ((C | 0) != 0) {
  7360. break
  7361. }
  7362. c[10708 >> 2] = c[10708 >> 2] & ~(1 << x);
  7363. s = p;
  7364. t = q;
  7365. break a
  7366. } else {
  7367. if (r >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7368. fa()
  7369. }
  7370. m = r + 16 | 0;
  7371. if ((c[m >> 2] | 0) == (v | 0)) {
  7372. c[m >> 2] = C
  7373. } else {
  7374. c[r + 20 >> 2] = C
  7375. } if ((C | 0) == 0) {
  7376. s = p;
  7377. t = q;
  7378. break a
  7379. }
  7380. }
  7381. } while (0);
  7382. if (C >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7383. fa()
  7384. }
  7385. c[C + 24 >> 2] = r;
  7386. v = c[a + (n + 16) >> 2] | 0;
  7387. do {
  7388. if ((v | 0) != 0) {
  7389. if (v >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7390. fa()
  7391. } else {
  7392. c[C + 16 >> 2] = v;
  7393. c[v + 24 >> 2] = C;
  7394. break
  7395. }
  7396. }
  7397. } while (0);
  7398. v = c[a + (n + 20) >> 2] | 0;
  7399. if ((v | 0) == 0) {
  7400. s = p;
  7401. t = q;
  7402. break
  7403. }
  7404. if (v >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7405. fa()
  7406. } else {
  7407. c[C + 20 >> 2] = v;
  7408. c[v + 24 >> 2] = C;
  7409. s = p;
  7410. t = q;
  7411. break
  7412. }
  7413. } else {
  7414. s = e;
  7415. t = j
  7416. }
  7417. } while (0);
  7418. e = s;
  7419. if (!(e >>> 0 < k >>> 0)) {
  7420. fa()
  7421. }
  7422. C = a + (j + -4) | 0;
  7423. f = c[C >> 2] | 0;
  7424. if ((f & 1 | 0) == 0) {
  7425. fa()
  7426. }
  7427. do {
  7428. if ((f & 2 | 0) == 0) {
  7429. if ((l | 0) == (c[10728 >> 2] | 0)) {
  7430. D = (c[10716 >> 2] | 0) + t | 0;
  7431. c[10716 >> 2] = D;
  7432. c[10728 >> 2] = s;
  7433. c[s + 4 >> 2] = D | 1;
  7434. if ((s | 0) != (c[10724 >> 2] | 0)) {
  7435. i = b;
  7436. return
  7437. }
  7438. c[10724 >> 2] = 0;
  7439. c[10712 >> 2] = 0;
  7440. i = b;
  7441. return
  7442. }
  7443. if ((l | 0) == (c[10724 >> 2] | 0)) {
  7444. D = (c[10712 >> 2] | 0) + t | 0;
  7445. c[10712 >> 2] = D;
  7446. c[10724 >> 2] = s;
  7447. c[s + 4 >> 2] = D | 1;
  7448. c[e + D >> 2] = D;
  7449. i = b;
  7450. return
  7451. }
  7452. D = (f & -8) + t | 0;
  7453. E = f >>> 3;
  7454. b: do {
  7455. if (f >>> 0 < 256) {
  7456. w = c[a + j >> 2] | 0;
  7457. h = c[a + (j | 4) >> 2] | 0;
  7458. d = 10744 + (E << 1 << 2) | 0;
  7459. do {
  7460. if ((w | 0) != (d | 0)) {
  7461. if (w >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7462. fa()
  7463. }
  7464. if ((c[w + 12 >> 2] | 0) == (l | 0)) {
  7465. break
  7466. }
  7467. fa()
  7468. }
  7469. } while (0);
  7470. if ((h | 0) == (w | 0)) {
  7471. c[2676] = c[2676] & ~(1 << E);
  7472. break
  7473. }
  7474. do {
  7475. if ((h | 0) == (d | 0)) {
  7476. F = h + 8 | 0
  7477. } else {
  7478. if (h >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7479. fa()
  7480. }
  7481. g = h + 8 | 0;
  7482. if ((c[g >> 2] | 0) == (l | 0)) {
  7483. F = g;
  7484. break
  7485. }
  7486. fa()
  7487. }
  7488. } while (0);
  7489. c[w + 12 >> 2] = h;
  7490. c[F >> 2] = w
  7491. } else {
  7492. d = k;
  7493. g = c[a + (j + 16) >> 2] | 0;
  7494. v = c[a + (j | 4) >> 2] | 0;
  7495. do {
  7496. if ((v | 0) == (d | 0)) {
  7497. r = a + (j + 12) | 0;
  7498. x = c[r >> 2] | 0;
  7499. if ((x | 0) == 0) {
  7500. o = a + (j + 8) | 0;
  7501. m = c[o >> 2] | 0;
  7502. if ((m | 0) == 0) {
  7503. G = 0;
  7504. break
  7505. } else {
  7506. H = m;
  7507. I = o
  7508. }
  7509. } else {
  7510. H = x;
  7511. I = r
  7512. }
  7513. while (1) {
  7514. r = H + 20 | 0;
  7515. x = c[r >> 2] | 0;
  7516. if ((x | 0) != 0) {
  7517. I = r;
  7518. H = x;
  7519. continue
  7520. }
  7521. x = H + 16 | 0;
  7522. r = c[x >> 2] | 0;
  7523. if ((r | 0) == 0) {
  7524. break
  7525. } else {
  7526. H = r;
  7527. I = x
  7528. }
  7529. }
  7530. if (I >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7531. fa()
  7532. } else {
  7533. c[I >> 2] = 0;
  7534. G = H;
  7535. break
  7536. }
  7537. } else {
  7538. x = c[a + j >> 2] | 0;
  7539. if (x >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7540. fa()
  7541. }
  7542. r = x + 12 | 0;
  7543. if ((c[r >> 2] | 0) != (d | 0)) {
  7544. fa()
  7545. }
  7546. o = v + 8 | 0;
  7547. if ((c[o >> 2] | 0) == (d | 0)) {
  7548. c[r >> 2] = v;
  7549. c[o >> 2] = x;
  7550. G = v;
  7551. break
  7552. } else {
  7553. fa()
  7554. }
  7555. }
  7556. } while (0);
  7557. if ((g | 0) == 0) {
  7558. break
  7559. }
  7560. v = c[a + (j + 20) >> 2] | 0;
  7561. w = 11008 + (v << 2) | 0;
  7562. do {
  7563. if ((d | 0) == (c[w >> 2] | 0)) {
  7564. c[w >> 2] = G;
  7565. if ((G | 0) != 0) {
  7566. break
  7567. }
  7568. c[10708 >> 2] = c[10708 >> 2] & ~(1 << v);
  7569. break b
  7570. } else {
  7571. if (g >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7572. fa()
  7573. }
  7574. h = g + 16 | 0;
  7575. if ((c[h >> 2] | 0) == (d | 0)) {
  7576. c[h >> 2] = G
  7577. } else {
  7578. c[g + 20 >> 2] = G
  7579. } if ((G | 0) == 0) {
  7580. break b
  7581. }
  7582. }
  7583. } while (0);
  7584. if (G >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7585. fa()
  7586. }
  7587. c[G + 24 >> 2] = g;
  7588. d = c[a + (j + 8) >> 2] | 0;
  7589. do {
  7590. if ((d | 0) != 0) {
  7591. if (d >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7592. fa()
  7593. } else {
  7594. c[G + 16 >> 2] = d;
  7595. c[d + 24 >> 2] = G;
  7596. break
  7597. }
  7598. }
  7599. } while (0);
  7600. d = c[a + (j + 12) >> 2] | 0;
  7601. if ((d | 0) == 0) {
  7602. break
  7603. }
  7604. if (d >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7605. fa()
  7606. } else {
  7607. c[G + 20 >> 2] = d;
  7608. c[d + 24 >> 2] = G;
  7609. break
  7610. }
  7611. }
  7612. } while (0);
  7613. c[s + 4 >> 2] = D | 1;
  7614. c[e + D >> 2] = D;
  7615. if ((s | 0) != (c[10724 >> 2] | 0)) {
  7616. J = D;
  7617. break
  7618. }
  7619. c[10712 >> 2] = D;
  7620. i = b;
  7621. return
  7622. } else {
  7623. c[C >> 2] = f & -2;
  7624. c[s + 4 >> 2] = t | 1;
  7625. c[e + t >> 2] = t;
  7626. J = t
  7627. }
  7628. } while (0);
  7629. t = J >>> 3;
  7630. if (J >>> 0 < 256) {
  7631. e = t << 1;
  7632. f = 10744 + (e << 2) | 0;
  7633. C = c[2676] | 0;
  7634. G = 1 << t;
  7635. do {
  7636. if ((C & G | 0) == 0) {
  7637. c[2676] = C | G;
  7638. K = 10744 + (e + 2 << 2) | 0;
  7639. L = f
  7640. } else {
  7641. t = 10744 + (e + 2 << 2) | 0;
  7642. j = c[t >> 2] | 0;
  7643. if (!(j >>> 0 < (c[10720 >> 2] | 0) >>> 0)) {
  7644. K = t;
  7645. L = j;
  7646. break
  7647. }
  7648. fa()
  7649. }
  7650. } while (0);
  7651. c[K >> 2] = s;
  7652. c[L + 12 >> 2] = s;
  7653. c[s + 8 >> 2] = L;
  7654. c[s + 12 >> 2] = f;
  7655. i = b;
  7656. return
  7657. }
  7658. f = s;
  7659. L = J >>> 8;
  7660. do {
  7661. if ((L | 0) == 0) {
  7662. M = 0
  7663. } else {
  7664. if (J >>> 0 > 16777215) {
  7665. M = 31;
  7666. break
  7667. }
  7668. K = (L + 1048320 | 0) >>> 16 & 8;
  7669. e = L << K;
  7670. G = (e + 520192 | 0) >>> 16 & 4;
  7671. C = e << G;
  7672. e = (C + 245760 | 0) >>> 16 & 2;
  7673. j = 14 - (G | K | e) + (C << e >>> 15) | 0;
  7674. M = J >>> (j + 7 | 0) & 1 | j << 1
  7675. }
  7676. } while (0);
  7677. L = 11008 + (M << 2) | 0;
  7678. c[s + 28 >> 2] = M;
  7679. c[s + 20 >> 2] = 0;
  7680. c[s + 16 >> 2] = 0;
  7681. j = c[10708 >> 2] | 0;
  7682. e = 1 << M;
  7683. c: do {
  7684. if ((j & e | 0) == 0) {
  7685. c[10708 >> 2] = j | e;
  7686. c[L >> 2] = f;
  7687. c[s + 24 >> 2] = L;
  7688. c[s + 12 >> 2] = s;
  7689. c[s + 8 >> 2] = s
  7690. } else {
  7691. C = c[L >> 2] | 0;
  7692. if ((M | 0) == 31) {
  7693. N = 0
  7694. } else {
  7695. N = 25 - (M >>> 1) | 0
  7696. }
  7697. d: do {
  7698. if ((c[C + 4 >> 2] & -8 | 0) == (J | 0)) {
  7699. O = C
  7700. } else {
  7701. K = J << N;
  7702. G = C;
  7703. while (1) {
  7704. P = G + (K >>> 31 << 2) + 16 | 0;
  7705. t = c[P >> 2] | 0;
  7706. if ((t | 0) == 0) {
  7707. break
  7708. }
  7709. if ((c[t + 4 >> 2] & -8 | 0) == (J | 0)) {
  7710. O = t;
  7711. break d
  7712. } else {
  7713. K = K << 1;
  7714. G = t
  7715. }
  7716. }
  7717. if (P >>> 0 < (c[10720 >> 2] | 0) >>> 0) {
  7718. fa()
  7719. } else {
  7720. c[P >> 2] = f;
  7721. c[s + 24 >> 2] = G;
  7722. c[s + 12 >> 2] = s;
  7723. c[s + 8 >> 2] = s;
  7724. break c
  7725. }
  7726. }
  7727. } while (0);
  7728. C = O + 8 | 0;
  7729. D = c[C >> 2] | 0;
  7730. K = c[10720 >> 2] | 0;
  7731. if (O >>> 0 < K >>> 0) {
  7732. fa()
  7733. }
  7734. if (D >>> 0 < K >>> 0) {
  7735. fa()
  7736. } else {
  7737. c[D + 12 >> 2] = f;
  7738. c[C >> 2] = f;
  7739. c[s + 8 >> 2] = D;
  7740. c[s + 12 >> 2] = O;
  7741. c[s + 24 >> 2] = 0;
  7742. break
  7743. }
  7744. }
  7745. } while (0);
  7746. s = (c[10736 >> 2] | 0) + -1 | 0;
  7747. c[10736 >> 2] = s;
  7748. if ((s | 0) == 0) {
  7749. Q = 11160 | 0
  7750. } else {
  7751. i = b;
  7752. return
  7753. }
  7754. while (1) {
  7755. s = c[Q >> 2] | 0;
  7756. if ((s | 0) == 0) {
  7757. break
  7758. } else {
  7759. Q = s + 8 | 0
  7760. }
  7761. }
  7762. c[10736 >> 2] = -1;
  7763. i = b;
  7764. return
  7765. }
  7766. function Ga() {}
  7767. function Ha(b, d, e) {
  7768. b = b | 0;
  7769. d = d | 0;
  7770. e = e | 0;
  7771. var f = 0;
  7772. if ((e | 0) >= 4096) return ja(b | 0, d | 0, e | 0) | 0;
  7773. f = b | 0;
  7774. if ((b & 3) == (d & 3)) {
  7775. while (b & 3) {
  7776. if ((e | 0) == 0) return f | 0;
  7777. a[b] = a[d] | 0;
  7778. b = b + 1 | 0;
  7779. d = d + 1 | 0;
  7780. e = e - 1 | 0
  7781. }
  7782. while ((e | 0) >= 4) {
  7783. c[b >> 2] = c[d >> 2];
  7784. b = b + 4 | 0;
  7785. d = d + 4 | 0;
  7786. e = e - 4 | 0
  7787. }
  7788. }
  7789. while ((e | 0) > 0) {
  7790. a[b] = a[d] | 0;
  7791. b = b + 1 | 0;
  7792. d = d + 1 | 0;
  7793. e = e - 1 | 0
  7794. }
  7795. return f | 0
  7796. }
  7797. function Ia(b, d, e) {
  7798. b = b | 0;
  7799. d = d | 0;
  7800. e = e | 0;
  7801. var f = 0,
  7802. g = 0,
  7803. h = 0,
  7804. i = 0;
  7805. f = b + e | 0;
  7806. if ((e | 0) >= 20) {
  7807. d = d & 255;
  7808. g = b & 3;
  7809. h = d | d << 8 | d << 16 | d << 24;
  7810. i = f & ~3;
  7811. if (g) {
  7812. g = b + 4 - g | 0;
  7813. while ((b | 0) < (g | 0)) {
  7814. a[b] = d;
  7815. b = b + 1 | 0
  7816. }
  7817. }
  7818. while ((b | 0) < (i | 0)) {
  7819. c[b >> 2] = h;
  7820. b = b + 4 | 0
  7821. }
  7822. }
  7823. while ((b | 0) < (f | 0)) {
  7824. a[b] = d;
  7825. b = b + 1 | 0
  7826. }
  7827. return b - e | 0
  7828. }
  7829. function Ja(b) {
  7830. b = b | 0;
  7831. var c = 0;
  7832. c = b;
  7833. while (a[c] | 0) {
  7834. c = c + 1 | 0
  7835. }
  7836. return c - b | 0
  7837. }
  7838. // EMSCRIPTEN_END_FUNCS
  7839. return {
  7840. _strlen: Ja,
  7841. _free: Fa,
  7842. _main: Da,
  7843. _memset: Ia,
  7844. _malloc: Ea,
  7845. _memcpy: Ha,
  7846. runPostSets: Ga,
  7847. stackAlloc: na,
  7848. stackSave: oa,
  7849. stackRestore: pa,
  7850. setThrew: qa,
  7851. setTempRet0: ta,
  7852. setTempRet1: ua,
  7853. setTempRet2: va,
  7854. setTempRet3: wa,
  7855. setTempRet4: xa,
  7856. setTempRet5: ya,
  7857. setTempRet6: za,
  7858. setTempRet7: Aa,
  7859. setTempRet8: Ba,
  7860. setTempRet9: Ca
  7861. }
  7862. })
  7863. // EMSCRIPTEN_END_ASM
  7864. ({
  7865. "Math": Math,
  7866. "Int8Array": Int8Array,
  7867. "Int16Array": Int16Array,
  7868. "Int32Array": Int32Array,
  7869. "Uint8Array": Uint8Array,
  7870. "Uint16Array": Uint16Array,
  7871. "Uint32Array": Uint32Array,
  7872. "Float32Array": Float32Array,
  7873. "Float64Array": Float64Array
  7874. }, {
  7875. "abort": abort,
  7876. "assert": assert,
  7877. "asmPrintInt": asmPrintInt,
  7878. "asmPrintFloat": asmPrintFloat,
  7879. "min": Math_min,
  7880. "_clock": _clock,
  7881. "_fflush": _fflush,
  7882. "_abort": _abort,
  7883. "___setErrNo": ___setErrNo,
  7884. "_sbrk": _sbrk,
  7885. "_time": _time,
  7886. "_emscripten_memcpy_big": _emscripten_memcpy_big,
  7887. "_sysconf": _sysconf,
  7888. "___errno_location": ___errno_location,
  7889. "STACKTOP": STACKTOP,
  7890. "STACK_MAX": STACK_MAX,
  7891. "tempDoublePtr": tempDoublePtr,
  7892. "ABORT": ABORT,
  7893. "NaN": NaN,
  7894. "Infinity": Infinity
  7895. }, buffer);
  7896. var _strlen = Module["_strlen"] = asm["_strlen"];
  7897. var _free = Module["_free"] = asm["_free"];
  7898. var _main = Module["_main"] = asm["_main"];
  7899. var _memset = Module["_memset"] = asm["_memset"];
  7900. var _malloc = Module["_malloc"] = asm["_malloc"];
  7901. var _memcpy = Module["_memcpy"] = asm["_memcpy"];
  7902. var runPostSets = Module["runPostSets"] = asm["runPostSets"];
  7903. Runtime.stackAlloc = function (size) {
  7904. return asm['stackAlloc'](size)
  7905. };
  7906. Runtime.stackSave = function () {
  7907. return asm['stackSave']()
  7908. };
  7909. Runtime.stackRestore = function (top) {
  7910. asm['stackRestore'](top)
  7911. };
  7912. // Warning: printing of i64 values may be slightly rounded! No deep i64 math used, so precise i64 code not included
  7913. var i64Math = null;
  7914. // === Auto-generated postamble setup entry stuff ===
  7915. if (memoryInitializer) {
  7916. if (ENVIRONMENT_IS_NODE || ENVIRONMENT_IS_SHELL) {
  7917. var data = Module['readBinary'](memoryInitializer);
  7918. HEAPU8.set(data, STATIC_BASE);
  7919. } else {
  7920. addRunDependency('memory initializer');
  7921. Browser.asyncLoad(memoryInitializer, function (data) {
  7922. HEAPU8.set(data, STATIC_BASE);
  7923. removeRunDependency('memory initializer');
  7924. }, function (data) {
  7925. throw 'could not load memory initializer ' + memoryInitializer;
  7926. });
  7927. }
  7928. }
  7929. function ExitStatus(status) {
  7930. this.name = "ExitStatus";
  7931. this.message = "Program terminated with exit(" + status + ")";
  7932. this.status = status;
  7933. };
  7934. ExitStatus.prototype = new Error();
  7935. ExitStatus.prototype.constructor = ExitStatus;
  7936. var initialStackTop;
  7937. var preloadStartTime = null;
  7938. var calledMain = false;
  7939. dependenciesFulfilled = function runCaller() {
  7940. // If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
  7941. if (!Module['calledRun'] && shouldRunNow) run();
  7942. if (!Module['calledRun']) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled
  7943. }
  7944. Module['callMain'] = Module.callMain = function callMain(args) {
  7945. assert(runDependencies == 0, 'cannot call main when async dependencies remain! (listen on __ATMAIN__)');
  7946. assert(__ATPRERUN__.length == 0, 'cannot call main when preRun functions remain to be called');
  7947. args = args || [];
  7948. if (ENVIRONMENT_IS_WEB && preloadStartTime !== null) {
  7949. Module.printErr('preload time: ' + (Date.now() - preloadStartTime) + ' ms');
  7950. }
  7951. ensureInitRuntime();
  7952. var argc = args.length + 1;
  7953. function pad() {
  7954. for (var i = 0; i < 4 - 1; i++) {
  7955. argv.push(0);
  7956. }
  7957. }
  7958. var argv = [allocate(intArrayFromString("/bin/this.program"), 'i8', ALLOC_NORMAL)];
  7959. pad();
  7960. for (var i = 0; i < argc - 1; i = i + 1) {
  7961. argv.push(allocate(intArrayFromString(args[i]), 'i8', ALLOC_NORMAL));
  7962. pad();
  7963. }
  7964. argv.push(0);
  7965. argv = allocate(argv, 'i32', ALLOC_NORMAL);
  7966. initialStackTop = STACKTOP;
  7967. try {
  7968. var ret = Module['_main'](argc, argv, 0);
  7969. // if we're not running an evented main loop, it's time to exit
  7970. if (!Module['noExitRuntime']) {
  7971. exit(ret);
  7972. }
  7973. } catch (e) {
  7974. if (e instanceof ExitStatus) {
  7975. // exit() throws this once it's done to make sure execution
  7976. // has been stopped completely
  7977. return;
  7978. } else if (e == 'SimulateInfiniteLoop') {
  7979. // running an evented main loop, don't immediately exit
  7980. Module['noExitRuntime'] = true;
  7981. return;
  7982. } else {
  7983. if (e && typeof e === 'object' && e.stack) Module.printErr('exception thrown: ' + [e, e.stack]);
  7984. throw e;
  7985. }
  7986. } finally {
  7987. calledMain = true;
  7988. }
  7989. }
  7990. function run(args) {
  7991. args = args || Module['arguments'];
  7992. if (preloadStartTime === null) preloadStartTime = Date.now();
  7993. if (runDependencies > 0) {
  7994. Module.printErr('run() called, but dependencies remain, so not running');
  7995. return;
  7996. }
  7997. preRun();
  7998. if (runDependencies > 0) return; // a preRun added a dependency, run will be called later
  7999. if (Module['calledRun']) return; // run may have just been called through dependencies being fulfilled just in this very frame
  8000. function doRun() {
  8001. if (Module['calledRun']) return; // run may have just been called while the async setStatus time below was happening
  8002. Module['calledRun'] = true;
  8003. ensureInitRuntime();
  8004. preMain();
  8005. if (Module['_main'] && shouldRunNow) {
  8006. Module['callMain'](args);
  8007. }
  8008. postRun();
  8009. }
  8010. if (Module['setStatus']) {
  8011. Module['setStatus']('Running...');
  8012. setTimeout(function () {
  8013. setTimeout(function () {
  8014. Module['setStatus']('');
  8015. }, 1);
  8016. if (!ABORT) doRun();
  8017. }, 1);
  8018. } else {
  8019. doRun();
  8020. }
  8021. }
  8022. Module['run'] = Module.run = run;
  8023. function exit(status) {
  8024. ABORT = true;
  8025. EXITSTATUS = status;
  8026. STACKTOP = initialStackTop;
  8027. // exit the runtime
  8028. exitRuntime();
  8029. // TODO We should handle this differently based on environment.
  8030. // In the browser, the best we can do is throw an exception
  8031. // to halt execution, but in node we could process.exit and
  8032. // I'd imagine SM shell would have something equivalent.
  8033. // This would let us set a proper exit status (which
  8034. // would be great for checking test exit statuses).
  8035. // https://github.com/kripken/emscripten/issues/1371
  8036. // throw an exception to halt the current execution
  8037. throw new ExitStatus(status);
  8038. }
  8039. Module['exit'] = Module.exit = exit;
  8040. function abort(text) {
  8041. if (text) {
  8042. Module.print(text);
  8043. Module.printErr(text);
  8044. }
  8045. ABORT = true;
  8046. EXITSTATUS = 1;
  8047. var extra = '\nIf this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.';
  8048. throw 'abort() at ' + stackTrace() + extra;
  8049. }
  8050. Module['abort'] = Module.abort = abort;
  8051. // {{PRE_RUN_ADDITIONS}}
  8052. if (Module['preInit']) {
  8053. if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
  8054. while (Module['preInit'].length > 0) {
  8055. Module['preInit'].pop()();
  8056. }
  8057. }
  8058. // shouldRunNow refers to calling main(), not run().
  8059. var shouldRunNow = true;
  8060. if (Module['noInitialRun']) {
  8061. shouldRunNow = false;
  8062. }
  8063. run();
  8064. // {{POST_RUN_ADDITIONS}}
  8065. // {{MODULE_ADDITIONS}}
  8066. ////////////////////////////////////////////////////////////////////////////////
  8067. // Runner
  8068. ////////////////////////////////////////////////////////////////////////////////
  8069. var __time_after = top.JetStream.goodTime();
  8070. top.JetStream.reportResult(__time_after - __time_before);