wasmconverter.js 297 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857
  1. /**
  2. * @license
  3. * Copyright 2010 The Emscripten Authors
  4. * SPDX-License-Identifier: MIT
  5. * The Module from https://github.com/kopytjuk/wasm-image-converter
  6. */
  7. // The Module object: Our interface to the outside world. We import
  8. // and export values on it. There are various ways Module can be used:
  9. // 1. Not defined. We create it here
  10. // 2. A function parameter, function(Module) { ..generated code.. }
  11. // 3. pre-run appended it, var Module = {}; ..generated code..
  12. // 4. External script tag defines var Module.
  13. // We need to check if Module already exists (e.g. case 3 above).
  14. // Substitution will be replaced with actual code on later stage of the build,
  15. // this way Closure Compiler will not mangle it (e.g. case 4. above).
  16. // Note that if you want to run closure, and also to use Module
  17. // after the generated code, you will need to define var Module = {};
  18. // before the code. Then that object will be used in the code, and you
  19. // can continue to use Module afterwards as well.
  20. var Module = typeof Module !== 'undefined' ? Module : {};
  21. // --pre-jses are emitted after the Module integration code, so that they can
  22. // refer to Module (if they choose; they can also define Module)
  23. // {{PRE_JSES}}
  24. // Sometimes an existing Module object exists with properties
  25. // meant to overwrite the default module functionality. Here
  26. // we collect those properties and reapply _after_ we configure
  27. // the current environment's defaults to avoid having to be so
  28. // defensive during initialization.
  29. var moduleOverrides = {};
  30. var key;
  31. for (key in Module) {
  32. if (Module.hasOwnProperty(key)) {
  33. moduleOverrides[key] = Module[key];
  34. }
  35. }
  36. var arguments_ = [];
  37. var thisProgram = './this.program';
  38. var quit_ = function(status, toThrow) {
  39. throw toThrow;
  40. };
  41. // Determine the runtime environment we are in. You can customize this by
  42. // setting the ENVIRONMENT setting at compile time (see settings.js).
  43. var ENVIRONMENT_IS_WEB = false;
  44. var ENVIRONMENT_IS_WORKER = false;
  45. var ENVIRONMENT_IS_NODE = false;
  46. var ENVIRONMENT_IS_SHELL = false;
  47. ENVIRONMENT_IS_WEB = typeof window === 'object';
  48. ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
  49. // N.b. Electron.js environment is simultaneously a NODE-environment, but
  50. // also a web environment.
  51. ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string';
  52. ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
  53. if (Module['ENVIRONMENT']) {
  54. throw new Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -s ENVIRONMENT=web or -s ENVIRONMENT=node)');
  55. }
  56. // `/` should be present at the end if `scriptDirectory` is not empty
  57. var scriptDirectory = '';
  58. function locateFile(path) {
  59. if (Module['locateFile']) {
  60. return Module['locateFile'](path, scriptDirectory);
  61. }
  62. return scriptDirectory + path;
  63. }
  64. // Hooks that are implemented differently in different runtime environments.
  65. var read_,
  66. readAsync,
  67. readBinary,
  68. setWindowTitle;
  69. var nodeFS;
  70. var nodePath;
  71. if (ENVIRONMENT_IS_NODE) {
  72. if (ENVIRONMENT_IS_WORKER) {
  73. scriptDirectory = require('path').dirname(scriptDirectory) + '/';
  74. } else {
  75. scriptDirectory = __dirname + '/';
  76. }
  77. /**
  78. * @license
  79. * Copyright 2019 The Emscripten Authors
  80. * SPDX-License-Identifier: MIT
  81. */
  82. read_ = function shell_read(filename, binary) {
  83. if (!nodeFS) nodeFS = require('fs');
  84. if (!nodePath) nodePath = require('path');
  85. filename = nodePath['normalize'](filename);
  86. return nodeFS['readFileSync'](filename, binary ? null : 'utf8');
  87. };
  88. readBinary = function readBinary(filename) {
  89. var ret = read_(filename, true);
  90. if (!ret.buffer) {
  91. ret = new Uint8Array(ret);
  92. }
  93. assert(ret.buffer);
  94. return ret;
  95. };
  96. if (process['argv'].length > 1) {
  97. thisProgram = process['argv'][1].replace(/\\/g, '/');
  98. }
  99. arguments_ = process['argv'].slice(2);
  100. if (typeof module !== 'undefined') {
  101. module['exports'] = Module;
  102. }
  103. process['on']('uncaughtException', function(ex) {
  104. // suppress ExitStatus exceptions from showing an error
  105. if (!(ex instanceof ExitStatus)) {
  106. throw ex;
  107. }
  108. });
  109. process['on']('unhandledRejection', abort);
  110. quit_ = function(status) {
  111. process['exit'](status);
  112. };
  113. Module['inspect'] = function () { return '[Emscripten Module object]'; };
  114. } else
  115. if (ENVIRONMENT_IS_SHELL) {
  116. if (typeof read != 'undefined') {
  117. read_ = function shell_read(f) {
  118. return read(f);
  119. };
  120. }
  121. readBinary = function readBinary(f) {
  122. var data;
  123. if (typeof readbuffer === 'function') {
  124. return new Uint8Array(readbuffer(f));
  125. }
  126. data = read(f, 'binary');
  127. assert(typeof data === 'object');
  128. return data;
  129. };
  130. if (typeof scriptArgs != 'undefined') {
  131. arguments_ = scriptArgs;
  132. } else if (typeof arguments != 'undefined') {
  133. arguments_ = arguments;
  134. }
  135. if (typeof quit === 'function') {
  136. quit_ = function(status) {
  137. quit(status);
  138. };
  139. }
  140. if (typeof print !== 'undefined') {
  141. // Prefer to use print/printErr where they exist, as they usually work better.
  142. if (typeof console === 'undefined') console = /** @type{!Console} */({});
  143. console.log = /** @type{!function(this:Console, ...*): undefined} */ (print);
  144. console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (typeof printErr !== 'undefined' ? printErr : print);
  145. }
  146. } else
  147. // Note that this includes Node.js workers when relevant (pthreads is enabled).
  148. // Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
  149. // ENVIRONMENT_IS_NODE.
  150. if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
  151. if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
  152. scriptDirectory = self.location.href;
  153. } else if (document.currentScript) { // web
  154. scriptDirectory = document.currentScript.src;
  155. }
  156. // blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
  157. // otherwise, slice off the final part of the url to find the script directory.
  158. // if scriptDirectory does not contain a slash, lastIndexOf will return -1,
  159. // and scriptDirectory will correctly be replaced with an empty string.
  160. if (scriptDirectory.indexOf('blob:') !== 0) {
  161. scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf('/')+1);
  162. } else {
  163. scriptDirectory = '';
  164. }
  165. // Differentiate the Web Worker from the Node Worker case, as reading must
  166. // be done differently.
  167. {
  168. /**
  169. * @license
  170. * Copyright 2019 The Emscripten Authors
  171. * SPDX-License-Identifier: MIT
  172. */
  173. read_ = function shell_read(url) {
  174. var xhr = new XMLHttpRequest();
  175. xhr.open('GET', url, false);
  176. xhr.send(null);
  177. return xhr.responseText;
  178. };
  179. if (ENVIRONMENT_IS_WORKER) {
  180. readBinary = function readBinary(url) {
  181. var xhr = new XMLHttpRequest();
  182. xhr.open('GET', url, false);
  183. xhr.responseType = 'arraybuffer';
  184. xhr.send(null);
  185. return new Uint8Array(/** @type{!ArrayBuffer} */(xhr.response));
  186. };
  187. }
  188. readAsync = function readAsync(url, onload, onerror) {
  189. var xhr = new XMLHttpRequest();
  190. xhr.open('GET', url, true);
  191. xhr.responseType = 'arraybuffer';
  192. xhr.onload = function xhr_onload() {
  193. if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
  194. onload(xhr.response);
  195. return;
  196. }
  197. onerror();
  198. };
  199. xhr.onerror = onerror;
  200. xhr.send(null);
  201. };
  202. }
  203. setWindowTitle = function(title) { document.title = title };
  204. } else
  205. {
  206. throw new Error('environment detection error');
  207. }
  208. // Set up the out() and err() hooks, which are how we can print to stdout or
  209. // stderr, respectively.
  210. var out = Module['print'] || console.log.bind(console);
  211. var err = Module['printErr'] || console.warn.bind(console);
  212. // Merge back in the overrides
  213. for (key in moduleOverrides) {
  214. if (moduleOverrides.hasOwnProperty(key)) {
  215. Module[key] = moduleOverrides[key];
  216. }
  217. }
  218. // Free the object hierarchy contained in the overrides, this lets the GC
  219. // reclaim data used e.g. in memoryInitializerRequest, which is a large typed array.
  220. moduleOverrides = null;
  221. // Emit code to handle expected values on the Module object. This applies Module.x
  222. // to the proper local x. This has two benefits: first, we only emit it if it is
  223. // expected to arrive, and second, by using a local everywhere else that can be
  224. // minified.
  225. if (Module['arguments']) arguments_ = Module['arguments'];if (!Object.getOwnPropertyDescriptor(Module, 'arguments')) Object.defineProperty(Module, 'arguments', { configurable: true, get: function() { abort('Module.arguments has been replaced with plain arguments_') } });
  226. if (Module['thisProgram']) thisProgram = Module['thisProgram'];if (!Object.getOwnPropertyDescriptor(Module, 'thisProgram')) Object.defineProperty(Module, 'thisProgram', { configurable: true, get: function() { abort('Module.thisProgram has been replaced with plain thisProgram') } });
  227. if (Module['quit']) quit_ = Module['quit'];if (!Object.getOwnPropertyDescriptor(Module, 'quit')) Object.defineProperty(Module, 'quit', { configurable: true, get: function() { abort('Module.quit has been replaced with plain quit_') } });
  228. // perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
  229. // Assertions on removed incoming Module JS APIs.
  230. assert(typeof Module['memoryInitializerPrefixURL'] === 'undefined', 'Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead');
  231. assert(typeof Module['pthreadMainPrefixURL'] === 'undefined', 'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead');
  232. assert(typeof Module['cdInitializerPrefixURL'] === 'undefined', 'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead');
  233. assert(typeof Module['filePackagePrefixURL'] === 'undefined', 'Module.filePackagePrefixURL option was removed, use Module.locateFile instead');
  234. assert(typeof Module['read'] === 'undefined', 'Module.read option was removed (modify read_ in JS)');
  235. assert(typeof Module['readAsync'] === 'undefined', 'Module.readAsync option was removed (modify readAsync in JS)');
  236. assert(typeof Module['readBinary'] === 'undefined', 'Module.readBinary option was removed (modify readBinary in JS)');
  237. assert(typeof Module['setWindowTitle'] === 'undefined', 'Module.setWindowTitle option was removed (modify setWindowTitle in JS)');
  238. assert(typeof Module['TOTAL_MEMORY'] === 'undefined', 'Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY');
  239. if (!Object.getOwnPropertyDescriptor(Module, 'read')) Object.defineProperty(Module, 'read', { configurable: true, get: function() { abort('Module.read has been replaced with plain read_') } });
  240. if (!Object.getOwnPropertyDescriptor(Module, 'readAsync')) Object.defineProperty(Module, 'readAsync', { configurable: true, get: function() { abort('Module.readAsync has been replaced with plain readAsync') } });
  241. if (!Object.getOwnPropertyDescriptor(Module, 'readBinary')) Object.defineProperty(Module, 'readBinary', { configurable: true, get: function() { abort('Module.readBinary has been replaced with plain readBinary') } });
  242. // TODO: add when SDL2 is fixed if (!Object.getOwnPropertyDescriptor(Module, 'setWindowTitle')) Object.defineProperty(Module, 'setWindowTitle', { configurable: true, get: function() { abort('Module.setWindowTitle has been replaced with plain setWindowTitle') } });
  243. var IDBFS = 'IDBFS is no longer included by default; build with -lidbfs.js';
  244. var PROXYFS = 'PROXYFS is no longer included by default; build with -lproxyfs.js';
  245. var WORKERFS = 'WORKERFS is no longer included by default; build with -lworkerfs.js';
  246. var NODEFS = 'NODEFS is no longer included by default; build with -lnodefs.js';
  247. // TODO remove when SDL2 is fixed (also see above)
  248. /**
  249. * @license
  250. * Copyright 2017 The Emscripten Authors
  251. * SPDX-License-Identifier: MIT
  252. */
  253. // {{PREAMBLE_ADDITIONS}}
  254. var STACK_ALIGN = 16;
  255. // stack management, and other functionality that is provided by the compiled code,
  256. // should not be used before it is ready
  257. /** @suppress{duplicate} */
  258. var stackSave;
  259. /** @suppress{duplicate} */
  260. var stackRestore;
  261. /** @suppress{duplicate} */
  262. var stackAlloc;
  263. stackSave = stackRestore = stackAlloc = function() {
  264. abort('cannot use the stack before compiled code is ready to run, and has provided stack access');
  265. };
  266. function staticAlloc(size) {
  267. abort('staticAlloc is no longer available at runtime; instead, perform static allocations at compile time (using makeStaticAlloc)');
  268. }
  269. function dynamicAlloc(size) {
  270. assert(DYNAMICTOP_PTR);
  271. var ret = HEAP32[DYNAMICTOP_PTR>>2];
  272. var end = (ret + size + 15) & -16;
  273. assert(end <= HEAP8.length, 'failure to dynamicAlloc - memory growth etc. is not supported there, call malloc/sbrk directly');
  274. HEAP32[DYNAMICTOP_PTR>>2] = end;
  275. return ret;
  276. }
  277. function alignMemory(size, factor) {
  278. if (!factor) factor = STACK_ALIGN; // stack alignment (16-byte) by default
  279. return Math.ceil(size / factor) * factor;
  280. }
  281. function getNativeTypeSize(type) {
  282. switch (type) {
  283. case 'i1': case 'i8': return 1;
  284. case 'i16': return 2;
  285. case 'i32': return 4;
  286. case 'i64': return 8;
  287. case 'float': return 4;
  288. case 'double': return 8;
  289. default: {
  290. if (type[type.length-1] === '*') {
  291. return 4; // A pointer
  292. } else if (type[0] === 'i') {
  293. var bits = Number(type.substr(1));
  294. assert(bits % 8 === 0, 'getNativeTypeSize invalid bits ' + bits + ', type ' + type);
  295. return bits / 8;
  296. } else {
  297. return 0;
  298. }
  299. }
  300. }
  301. }
  302. function warnOnce(text) {
  303. if (!warnOnce.shown) warnOnce.shown = {};
  304. if (!warnOnce.shown[text]) {
  305. warnOnce.shown[text] = 1;
  306. err(text);
  307. }
  308. }
  309. /**
  310. * @license
  311. * Copyright 2020 The Emscripten Authors
  312. * SPDX-License-Identifier: MIT
  313. */
  314. // Wraps a JS function as a wasm function with a given signature.
  315. function convertJsFunctionToWasm(func, sig) {
  316. // If the type reflection proposal is available, use the new
  317. // "WebAssembly.Function" constructor.
  318. // Otherwise, construct a minimal wasm module importing the JS function and
  319. // re-exporting it.
  320. if (typeof WebAssembly.Function === "function") {
  321. var typeNames = {
  322. 'i': 'i32',
  323. 'j': 'i64',
  324. 'f': 'f32',
  325. 'd': 'f64'
  326. };
  327. var type = {
  328. parameters: [],
  329. results: sig[0] == 'v' ? [] : [typeNames[sig[0]]]
  330. };
  331. for (var i = 1; i < sig.length; ++i) {
  332. type.parameters.push(typeNames[sig[i]]);
  333. }
  334. return new WebAssembly.Function(type, func);
  335. }
  336. // The module is static, with the exception of the type section, which is
  337. // generated based on the signature passed in.
  338. var typeSection = [
  339. 0x01, // id: section,
  340. 0x00, // length: 0 (placeholder)
  341. 0x01, // count: 1
  342. 0x60, // form: func
  343. ];
  344. var sigRet = sig.slice(0, 1);
  345. var sigParam = sig.slice(1);
  346. var typeCodes = {
  347. 'i': 0x7f, // i32
  348. 'j': 0x7e, // i64
  349. 'f': 0x7d, // f32
  350. 'd': 0x7c, // f64
  351. };
  352. // Parameters, length + signatures
  353. typeSection.push(sigParam.length);
  354. for (var i = 0; i < sigParam.length; ++i) {
  355. typeSection.push(typeCodes[sigParam[i]]);
  356. }
  357. // Return values, length + signatures
  358. // With no multi-return in MVP, either 0 (void) or 1 (anything else)
  359. if (sigRet == 'v') {
  360. typeSection.push(0x00);
  361. } else {
  362. typeSection = typeSection.concat([0x01, typeCodes[sigRet]]);
  363. }
  364. // Write the overall length of the type section back into the section header
  365. // (excepting the 2 bytes for the section id and length)
  366. typeSection[1] = typeSection.length - 2;
  367. // Rest of the module is static
  368. var bytes = new Uint8Array([
  369. 0x00, 0x61, 0x73, 0x6d, // magic ("\0asm")
  370. 0x01, 0x00, 0x00, 0x00, // version: 1
  371. ].concat(typeSection, [
  372. 0x02, 0x07, // import section
  373. // (import "e" "f" (func 0 (type 0)))
  374. 0x01, 0x01, 0x65, 0x01, 0x66, 0x00, 0x00,
  375. 0x07, 0x05, // export section
  376. // (export "f" (func 0 (type 0)))
  377. 0x01, 0x01, 0x66, 0x00, 0x00,
  378. ]));
  379. // We can compile this wasm module synchronously because it is very small.
  380. // This accepts an import (at "e.f"), that it reroutes to an export (at "f")
  381. var module = new WebAssembly.Module(bytes);
  382. var instance = new WebAssembly.Instance(module, {
  383. 'e': {
  384. 'f': func
  385. }
  386. });
  387. var wrappedFunc = instance.exports['f'];
  388. return wrappedFunc;
  389. }
  390. var freeTableIndexes = [];
  391. // Weak map of functions in the table to their indexes, created on first use.
  392. var functionsInTableMap;
  393. // Add a wasm function to the table.
  394. function addFunctionWasm(func, sig) {
  395. var table = wasmTable;
  396. // Check if the function is already in the table, to ensure each function
  397. // gets a unique index. First, create the map if this is the first use.
  398. if (!functionsInTableMap) {
  399. functionsInTableMap = new WeakMap();
  400. for (var i = 0; i < table.length; i++) {
  401. var item = table.get(i);
  402. // Ignore null values.
  403. if (item) {
  404. functionsInTableMap.set(item, i);
  405. }
  406. }
  407. }
  408. if (functionsInTableMap.has(func)) {
  409. return functionsInTableMap.get(func);
  410. }
  411. // It's not in the table, add it now.
  412. var ret;
  413. // Reuse a free index if there is one, otherwise grow.
  414. if (freeTableIndexes.length) {
  415. ret = freeTableIndexes.pop();
  416. } else {
  417. ret = table.length;
  418. // Grow the table
  419. try {
  420. table.grow(1);
  421. } catch (err) {
  422. if (!(err instanceof RangeError)) {
  423. throw err;
  424. }
  425. throw 'Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.';
  426. }
  427. }
  428. // Set the new value.
  429. try {
  430. // Attempting to call this with JS function will cause of table.set() to fail
  431. table.set(ret, func);
  432. } catch (err) {
  433. if (!(err instanceof TypeError)) {
  434. throw err;
  435. }
  436. assert(typeof sig !== 'undefined', 'Missing signature argument to addFunction');
  437. var wrapped = convertJsFunctionToWasm(func, sig);
  438. table.set(ret, wrapped);
  439. }
  440. functionsInTableMap[func] = ret;
  441. return ret;
  442. }
  443. function removeFunctionWasm(index) {
  444. functionsInTableMap.delete(wasmTable.get(index));
  445. freeTableIndexes.push(index);
  446. }
  447. // 'sig' parameter is required for the llvm backend but only when func is not
  448. // already a WebAssembly function.
  449. function addFunction(func, sig) {
  450. assert(typeof func !== 'undefined');
  451. return addFunctionWasm(func, sig);
  452. }
  453. function removeFunction(index) {
  454. removeFunctionWasm(index);
  455. }
  456. var funcWrappers = {};
  457. function getFuncWrapper(func, sig) {
  458. if (!func) return; // on null pointer, return undefined
  459. assert(sig);
  460. if (!funcWrappers[sig]) {
  461. funcWrappers[sig] = {};
  462. }
  463. var sigCache = funcWrappers[sig];
  464. if (!sigCache[func]) {
  465. // optimize away arguments usage in common cases
  466. if (sig.length === 1) {
  467. sigCache[func] = function dynCall_wrapper() {
  468. return dynCall(sig, func);
  469. };
  470. } else if (sig.length === 2) {
  471. sigCache[func] = function dynCall_wrapper(arg) {
  472. return dynCall(sig, func, [arg]);
  473. };
  474. } else {
  475. // general case
  476. sigCache[func] = function dynCall_wrapper() {
  477. return dynCall(sig, func, Array.prototype.slice.call(arguments));
  478. };
  479. }
  480. }
  481. return sigCache[func];
  482. }
  483. /**
  484. * @license
  485. * Copyright 2020 The Emscripten Authors
  486. * SPDX-License-Identifier: MIT
  487. */
  488. function makeBigInt(low, high, unsigned) {
  489. return unsigned ? ((+((low>>>0)))+((+((high>>>0)))*4294967296.0)) : ((+((low>>>0)))+((+((high|0)))*4294967296.0));
  490. }
  491. /** @param {Array=} args */
  492. function dynCall(sig, ptr, args) {
  493. if (args && args.length) {
  494. // j (64-bit integer) must be passed in as two numbers [low 32, high 32].
  495. assert(args.length === sig.substring(1).replace(/j/g, '--').length);
  496. assert(('dynCall_' + sig) in Module, 'bad function pointer type - no table for sig \'' + sig + '\'');
  497. return Module['dynCall_' + sig].apply(null, [ptr].concat(args));
  498. } else {
  499. assert(sig.length == 1);
  500. assert(('dynCall_' + sig) in Module, 'bad function pointer type - no table for sig \'' + sig + '\'');
  501. return Module['dynCall_' + sig].call(null, ptr);
  502. }
  503. }
  504. var tempRet0 = 0;
  505. var setTempRet0 = function(value) {
  506. tempRet0 = value;
  507. };
  508. var getTempRet0 = function() {
  509. return tempRet0;
  510. };
  511. function getCompilerSetting(name) {
  512. throw 'You must build with -s RETAIN_COMPILER_SETTINGS=1 for getCompilerSetting or emscripten_get_compiler_setting to work';
  513. }
  514. // The address globals begin at. Very low in memory, for code size and optimization opportunities.
  515. // Above 0 is static memory, starting with globals.
  516. // Then the stack.
  517. // Then 'dynamic' memory for sbrk.
  518. var GLOBAL_BASE = 1024;
  519. /**
  520. * @license
  521. * Copyright 2010 The Emscripten Authors
  522. * SPDX-License-Identifier: MIT
  523. */
  524. // === Preamble library stuff ===
  525. // Documentation for the public APIs defined in this file must be updated in:
  526. // site/source/docs/api_reference/preamble.js.rst
  527. // A prebuilt local version of the documentation is available at:
  528. // site/build/text/docs/api_reference/preamble.js.txt
  529. // You can also build docs locally as HTML or other formats in site/
  530. // An online HTML version (which may be of a different version of Emscripten)
  531. // is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
  532. var wasmBinary;if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];if (!Object.getOwnPropertyDescriptor(Module, 'wasmBinary')) Object.defineProperty(Module, 'wasmBinary', { configurable: true, get: function() { abort('Module.wasmBinary has been replaced with plain wasmBinary') } });
  533. var noExitRuntime;if (Module['noExitRuntime']) noExitRuntime = Module['noExitRuntime'];if (!Object.getOwnPropertyDescriptor(Module, 'noExitRuntime')) Object.defineProperty(Module, 'noExitRuntime', { configurable: true, get: function() { abort('Module.noExitRuntime has been replaced with plain noExitRuntime') } });
  534. if (typeof WebAssembly !== 'object') {
  535. abort('No WebAssembly support found. Build with -s WASM=0 to target JavaScript instead.');
  536. }
  537. /**
  538. * @license
  539. * Copyright 2019 The Emscripten Authors
  540. * SPDX-License-Identifier: MIT
  541. */
  542. // In MINIMAL_RUNTIME, setValue() and getValue() are only available when building with safe heap enabled, for heap safety checking.
  543. // In traditional runtime, setValue() and getValue() are always available (although their use is highly discouraged due to perf penalties)
  544. /** @param {number} ptr
  545. @param {number} value
  546. @param {string} type
  547. @param {number|boolean=} noSafe */
  548. function setValue(ptr, value, type, noSafe) {
  549. type = type || 'i8';
  550. if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
  551. switch(type) {
  552. case 'i1': HEAP8[((ptr)>>0)]=value; break;
  553. case 'i8': HEAP8[((ptr)>>0)]=value; break;
  554. case 'i16': HEAP16[((ptr)>>1)]=value; break;
  555. case 'i32': HEAP32[((ptr)>>2)]=value; break;
  556. case 'i64': (tempI64 = [value>>>0,(tempDouble=value,(+(Math_abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math_min((+(Math_floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[((ptr)>>2)]=tempI64[0],HEAP32[(((ptr)+(4))>>2)]=tempI64[1]); break;
  557. case 'float': HEAPF32[((ptr)>>2)]=value; break;
  558. case 'double': HEAPF64[((ptr)>>3)]=value; break;
  559. default: abort('invalid type for setValue: ' + type);
  560. }
  561. }
  562. /** @param {number} ptr
  563. @param {string} type
  564. @param {number|boolean=} noSafe */
  565. function getValue(ptr, type, noSafe) {
  566. type = type || 'i8';
  567. if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
  568. switch(type) {
  569. case 'i1': return HEAP8[((ptr)>>0)];
  570. case 'i8': return HEAP8[((ptr)>>0)];
  571. case 'i16': return HEAP16[((ptr)>>1)];
  572. case 'i32': return HEAP32[((ptr)>>2)];
  573. case 'i64': return HEAP32[((ptr)>>2)];
  574. case 'float': return HEAPF32[((ptr)>>2)];
  575. case 'double': return HEAPF64[((ptr)>>3)];
  576. default: abort('invalid type for getValue: ' + type);
  577. }
  578. return null;
  579. }
  580. // Wasm globals
  581. var wasmMemory;
  582. // In fastcomp asm.js, we don't need a wasm Table at all.
  583. // In the wasm backend, we polyfill the WebAssembly object,
  584. // so this creates a (non-native-wasm) table for us.
  585. var wasmTable = new WebAssembly.Table({
  586. 'initial': 781,
  587. 'maximum': 781 + 0,
  588. 'element': 'anyfunc'
  589. });
  590. //========================================
  591. // Runtime essentials
  592. //========================================
  593. // whether we are quitting the application. no code should run after this.
  594. // set in exit() and abort()
  595. var ABORT = false;
  596. // set by exit() and abort(). Passed to 'onExit' handler.
  597. // NOTE: This is also used as the process return code code in shell environments
  598. // but only when noExitRuntime is false.
  599. var EXITSTATUS = 0;
  600. /** @type {function(*, string=)} */
  601. function assert(condition, text) {
  602. if (!condition) {
  603. abort('Assertion failed: ' + text);
  604. }
  605. }
  606. // Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
  607. function getCFunc(ident) {
  608. var func = Module['_' + ident]; // closure exported function
  609. assert(func, 'Cannot call unknown function ' + ident + ', make sure it is exported');
  610. return func;
  611. }
  612. // C calling interface.
  613. /** @param {string|null=} returnType
  614. @param {Array=} argTypes
  615. @param {Arguments|Array=} args
  616. @param {Object=} opts */
  617. function ccall(ident, returnType, argTypes, args, opts) {
  618. // For fast lookup of conversion functions
  619. var toC = {
  620. 'string': function(str) {
  621. var ret = 0;
  622. if (str !== null && str !== undefined && str !== 0) { // null string
  623. // at most 4 bytes per UTF-8 code point, +1 for the trailing '\0'
  624. var len = (str.length << 2) + 1;
  625. ret = stackAlloc(len);
  626. stringToUTF8(str, ret, len);
  627. }
  628. return ret;
  629. },
  630. 'array': function(arr) {
  631. var ret = stackAlloc(arr.length);
  632. writeArrayToMemory(arr, ret);
  633. return ret;
  634. }
  635. };
  636. function convertReturnValue(ret) {
  637. if (returnType === 'string') return UTF8ToString(ret);
  638. if (returnType === 'boolean') return Boolean(ret);
  639. return ret;
  640. }
  641. var func = getCFunc(ident);
  642. var cArgs = [];
  643. var stack = 0;
  644. assert(returnType !== 'array', 'Return type should not be "array".');
  645. if (args) {
  646. for (var i = 0; i < args.length; i++) {
  647. var converter = toC[argTypes[i]];
  648. if (converter) {
  649. if (stack === 0) stack = stackSave();
  650. cArgs[i] = converter(args[i]);
  651. } else {
  652. cArgs[i] = args[i];
  653. }
  654. }
  655. }
  656. var ret = func.apply(null, cArgs);
  657. ret = convertReturnValue(ret);
  658. if (stack !== 0) stackRestore(stack);
  659. return ret;
  660. }
  661. /** @param {string=} returnType
  662. @param {Array=} argTypes
  663. @param {Object=} opts */
  664. function cwrap(ident, returnType, argTypes, opts) {
  665. return function() {
  666. return ccall(ident, returnType, argTypes, arguments, opts);
  667. }
  668. }
  669. var ALLOC_NORMAL = 0; // Tries to use _malloc()
  670. var ALLOC_STACK = 1; // Lives for the duration of the current function call
  671. var ALLOC_DYNAMIC = 2; // Cannot be freed except through sbrk
  672. var ALLOC_NONE = 3; // Do not allocate
  673. // allocate(): This is for internal use. You can use it yourself as well, but the interface
  674. // is a little tricky (see docs right below). The reason is that it is optimized
  675. // for multiple syntaxes to save space in generated code. So you should
  676. // normally not use allocate(), and instead allocate memory using _malloc(),
  677. // initialize it with setValue(), and so forth.
  678. // @slab: An array of data, or a number. If a number, then the size of the block to allocate,
  679. // in *bytes* (note that this is sometimes confusing: the next parameter does not
  680. // affect this!)
  681. // @types: Either an array of types, one for each byte (or 0 if no type at that position),
  682. // or a single type which is used for the entire block. This only matters if there
  683. // is initial data - if @slab is a number, then this does not matter at all and is
  684. // ignored.
  685. // @allocator: How to allocate memory, see ALLOC_*
  686. /** @type {function((TypedArray|Array<number>|number), string, number, number=)} */
  687. function allocate(slab, types, allocator, ptr) {
  688. var zeroinit, size;
  689. if (typeof slab === 'number') {
  690. zeroinit = true;
  691. size = slab;
  692. } else {
  693. zeroinit = false;
  694. size = slab.length;
  695. }
  696. var singleType = typeof types === 'string' ? types : null;
  697. var ret;
  698. if (allocator == ALLOC_NONE) {
  699. ret = ptr;
  700. } else {
  701. ret = [_malloc,
  702. stackAlloc,
  703. dynamicAlloc][allocator](Math.max(size, singleType ? 1 : types.length));
  704. }
  705. if (zeroinit) {
  706. var stop;
  707. ptr = ret;
  708. assert((ret & 3) == 0);
  709. stop = ret + (size & ~3);
  710. for (; ptr < stop; ptr += 4) {
  711. HEAP32[((ptr)>>2)]=0;
  712. }
  713. stop = ret + size;
  714. while (ptr < stop) {
  715. HEAP8[((ptr++)>>0)]=0;
  716. }
  717. return ret;
  718. }
  719. if (singleType === 'i8') {
  720. if (slab.subarray || slab.slice) {
  721. HEAPU8.set(/** @type {!Uint8Array} */ (slab), ret);
  722. } else {
  723. HEAPU8.set(new Uint8Array(slab), ret);
  724. }
  725. return ret;
  726. }
  727. var i = 0, type, typeSize, previousType;
  728. while (i < size) {
  729. var curr = slab[i];
  730. type = singleType || types[i];
  731. if (type === 0) {
  732. i++;
  733. continue;
  734. }
  735. assert(type, 'Must know what type to store in allocate!');
  736. if (type == 'i64') type = 'i32'; // special case: we have one i32 here, and one i32 later
  737. setValue(ret+i, curr, type);
  738. // no need to look up size unless type changes, so cache it
  739. if (previousType !== type) {
  740. typeSize = getNativeTypeSize(type);
  741. previousType = type;
  742. }
  743. i += typeSize;
  744. }
  745. return ret;
  746. }
  747. // Allocate memory during any stage of startup - static memory early on, dynamic memory later, malloc when ready
  748. function getMemory(size) {
  749. if (!runtimeInitialized) return dynamicAlloc(size);
  750. return _malloc(size);
  751. }
  752. /**
  753. * @license
  754. * Copyright 2019 The Emscripten Authors
  755. * SPDX-License-Identifier: MIT
  756. */
  757. // runtime_strings.js: Strings related runtime functions that are part of both MINIMAL_RUNTIME and regular runtime.
  758. // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the given array that contains uint8 values, returns
  759. // a copy of that string as a Javascript String object.
  760. var UTF8Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf8') : undefined;
  761. /**
  762. * @param {number} idx
  763. * @param {number=} maxBytesToRead
  764. * @return {string}
  765. */
  766. function UTF8ArrayToString(heap, idx, maxBytesToRead) {
  767. var endIdx = idx + maxBytesToRead;
  768. var endPtr = idx;
  769. // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
  770. // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
  771. // (As a tiny code save trick, compare endPtr against endIdx using a negation, so that undefined means Infinity)
  772. while (heap[endPtr] && !(endPtr >= endIdx)) ++endPtr;
  773. if (endPtr - idx > 16 && heap.subarray && UTF8Decoder) {
  774. return UTF8Decoder.decode(heap.subarray(idx, endPtr));
  775. } else {
  776. var str = '';
  777. // If building with TextDecoder, we have already computed the string length above, so test loop end condition against that
  778. while (idx < endPtr) {
  779. // For UTF8 byte structure, see:
  780. // http://en.wikipedia.org/wiki/UTF-8#Description
  781. // https://www.ietf.org/rfc/rfc2279.txt
  782. // https://tools.ietf.org/html/rfc3629
  783. var u0 = heap[idx++];
  784. if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
  785. var u1 = heap[idx++] & 63;
  786. if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
  787. var u2 = heap[idx++] & 63;
  788. if ((u0 & 0xF0) == 0xE0) {
  789. u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
  790. } else {
  791. if ((u0 & 0xF8) != 0xF0) warnOnce('Invalid UTF-8 leading byte 0x' + u0.toString(16) + ' encountered when deserializing a UTF-8 string on the asm.js/wasm heap to a JS string!');
  792. u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heap[idx++] & 63);
  793. }
  794. if (u0 < 0x10000) {
  795. str += String.fromCharCode(u0);
  796. } else {
  797. var ch = u0 - 0x10000;
  798. str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
  799. }
  800. }
  801. }
  802. return str;
  803. }
  804. // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the emscripten HEAP, returns a
  805. // copy of that string as a Javascript String object.
  806. // maxBytesToRead: an optional length that specifies the maximum number of bytes to read. You can omit
  807. // this parameter to scan the string until the first \0 byte. If maxBytesToRead is
  808. // passed, and the string at [ptr, ptr+maxBytesToReadr[ contains a null byte in the
  809. // middle, then the string will cut short at that byte index (i.e. maxBytesToRead will
  810. // not produce a string of exact length [ptr, ptr+maxBytesToRead[)
  811. // N.B. mixing frequent uses of UTF8ToString() with and without maxBytesToRead may
  812. // throw JS JIT optimizations off, so it is worth to consider consistently using one
  813. // style or the other.
  814. /**
  815. * @param {number} ptr
  816. * @param {number=} maxBytesToRead
  817. * @return {string}
  818. */
  819. function UTF8ToString(ptr, maxBytesToRead) {
  820. return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : '';
  821. }
  822. // Copies the given Javascript String object 'str' to the given byte array at address 'outIdx',
  823. // encoded in UTF8 form and null-terminated. The copy will require at most str.length*4+1 bytes of space in the HEAP.
  824. // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
  825. // Parameters:
  826. // str: the Javascript string to copy.
  827. // heap: the array to copy to. Each index in this array is assumed to be one 8-byte element.
  828. // outIdx: The starting offset in the array to begin the copying.
  829. // maxBytesToWrite: The maximum number of bytes this function can write to the array.
  830. // This count should include the null terminator,
  831. // i.e. if maxBytesToWrite=1, only the null terminator will be written and nothing else.
  832. // maxBytesToWrite=0 does not write any bytes to the output, not even the null terminator.
  833. // Returns the number of bytes written, EXCLUDING the null terminator.
  834. function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
  835. if (!(maxBytesToWrite > 0)) // Parameter maxBytesToWrite is not optional. Negative values, 0, null, undefined and false each don't write out any bytes.
  836. return 0;
  837. var startIdx = outIdx;
  838. var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator.
  839. for (var i = 0; i < str.length; ++i) {
  840. // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8.
  841. // See http://unicode.org/faq/utf_bom.html#utf16-3
  842. // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description and https://www.ietf.org/rfc/rfc2279.txt and https://tools.ietf.org/html/rfc3629
  843. var u = str.charCodeAt(i); // possibly a lead surrogate
  844. if (u >= 0xD800 && u <= 0xDFFF) {
  845. var u1 = str.charCodeAt(++i);
  846. u = 0x10000 + ((u & 0x3FF) << 10) | (u1 & 0x3FF);
  847. }
  848. if (u <= 0x7F) {
  849. if (outIdx >= endIdx) break;
  850. heap[outIdx++] = u;
  851. } else if (u <= 0x7FF) {
  852. if (outIdx + 1 >= endIdx) break;
  853. heap[outIdx++] = 0xC0 | (u >> 6);
  854. heap[outIdx++] = 0x80 | (u & 63);
  855. } else if (u <= 0xFFFF) {
  856. if (outIdx + 2 >= endIdx) break;
  857. heap[outIdx++] = 0xE0 | (u >> 12);
  858. heap[outIdx++] = 0x80 | ((u >> 6) & 63);
  859. heap[outIdx++] = 0x80 | (u & 63);
  860. } else {
  861. if (outIdx + 3 >= endIdx) break;
  862. if (u >= 0x200000) warnOnce('Invalid Unicode code point 0x' + u.toString(16) + ' encountered when serializing a JS string to an UTF-8 string on the asm.js/wasm heap! (Valid unicode code points should be in range 0-0x1FFFFF).');
  863. heap[outIdx++] = 0xF0 | (u >> 18);
  864. heap[outIdx++] = 0x80 | ((u >> 12) & 63);
  865. heap[outIdx++] = 0x80 | ((u >> 6) & 63);
  866. heap[outIdx++] = 0x80 | (u & 63);
  867. }
  868. }
  869. // Null-terminate the pointer to the buffer.
  870. heap[outIdx] = 0;
  871. return outIdx - startIdx;
  872. }
  873. // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
  874. // null-terminated and encoded in UTF8 form. The copy will require at most str.length*4+1 bytes of space in the HEAP.
  875. // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
  876. // Returns the number of bytes written, EXCLUDING the null terminator.
  877. function stringToUTF8(str, outPtr, maxBytesToWrite) {
  878. assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
  879. return stringToUTF8Array(str, HEAPU8,outPtr, maxBytesToWrite);
  880. }
  881. // Returns the number of bytes the given Javascript string takes if encoded as a UTF8 byte array, EXCLUDING the null terminator byte.
  882. function lengthBytesUTF8(str) {
  883. var len = 0;
  884. for (var i = 0; i < str.length; ++i) {
  885. // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8.
  886. // See http://unicode.org/faq/utf_bom.html#utf16-3
  887. var u = str.charCodeAt(i); // possibly a lead surrogate
  888. if (u >= 0xD800 && u <= 0xDFFF) u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF);
  889. if (u <= 0x7F) ++len;
  890. else if (u <= 0x7FF) len += 2;
  891. else if (u <= 0xFFFF) len += 3;
  892. else len += 4;
  893. }
  894. return len;
  895. }
  896. /**
  897. * @license
  898. * Copyright 2020 The Emscripten Authors
  899. * SPDX-License-Identifier: MIT
  900. */
  901. // runtime_strings_extra.js: Strings related runtime functions that are available only in regular runtime.
  902. // Given a pointer 'ptr' to a null-terminated ASCII-encoded string in the emscripten HEAP, returns
  903. // a copy of that string as a Javascript String object.
  904. function AsciiToString(ptr) {
  905. var str = '';
  906. while (1) {
  907. var ch = HEAPU8[((ptr++)>>0)];
  908. if (!ch) return str;
  909. str += String.fromCharCode(ch);
  910. }
  911. }
  912. // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
  913. // null-terminated and encoded in ASCII form. The copy will require at most str.length+1 bytes of space in the HEAP.
  914. function stringToAscii(str, outPtr) {
  915. return writeAsciiToMemory(str, outPtr, false);
  916. }
  917. // Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns
  918. // a copy of that string as a Javascript String object.
  919. var UTF16Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-16le') : undefined;
  920. function UTF16ToString(ptr) {
  921. assert(ptr % 2 == 0, 'Pointer passed to UTF16ToString must be aligned to two bytes!');
  922. var endPtr = ptr;
  923. // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
  924. // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
  925. var idx = endPtr >> 1;
  926. while (HEAP16[idx]) ++idx;
  927. endPtr = idx << 1;
  928. if (endPtr - ptr > 32 && UTF16Decoder) {
  929. return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr));
  930. } else {
  931. var i = 0;
  932. var str = '';
  933. while (1) {
  934. var codeUnit = HEAP16[(((ptr)+(i*2))>>1)];
  935. if (codeUnit == 0) return str;
  936. ++i;
  937. // fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through.
  938. str += String.fromCharCode(codeUnit);
  939. }
  940. }
  941. }
  942. // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
  943. // null-terminated and encoded in UTF16 form. The copy will require at most str.length*4+2 bytes of space in the HEAP.
  944. // Use the function lengthBytesUTF16() to compute the exact number of bytes (excluding null terminator) that this function will write.
  945. // Parameters:
  946. // str: the Javascript string to copy.
  947. // outPtr: Byte address in Emscripten HEAP where to write the string to.
  948. // maxBytesToWrite: The maximum number of bytes this function can write to the array. This count should include the null
  949. // terminator, i.e. if maxBytesToWrite=2, only the null terminator will be written and nothing else.
  950. // maxBytesToWrite<2 does not write any bytes to the output, not even the null terminator.
  951. // Returns the number of bytes written, EXCLUDING the null terminator.
  952. function stringToUTF16(str, outPtr, maxBytesToWrite) {
  953. assert(outPtr % 2 == 0, 'Pointer passed to stringToUTF16 must be aligned to two bytes!');
  954. assert(typeof maxBytesToWrite == 'number', 'stringToUTF16(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
  955. // Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
  956. if (maxBytesToWrite === undefined) {
  957. maxBytesToWrite = 0x7FFFFFFF;
  958. }
  959. if (maxBytesToWrite < 2) return 0;
  960. maxBytesToWrite -= 2; // Null terminator.
  961. var startPtr = outPtr;
  962. var numCharsToWrite = (maxBytesToWrite < str.length*2) ? (maxBytesToWrite / 2) : str.length;
  963. for (var i = 0; i < numCharsToWrite; ++i) {
  964. // charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP.
  965. var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
  966. HEAP16[((outPtr)>>1)]=codeUnit;
  967. outPtr += 2;
  968. }
  969. // Null-terminate the pointer to the HEAP.
  970. HEAP16[((outPtr)>>1)]=0;
  971. return outPtr - startPtr;
  972. }
  973. // Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte.
  974. function lengthBytesUTF16(str) {
  975. return str.length*2;
  976. }
  977. function UTF32ToString(ptr) {
  978. assert(ptr % 4 == 0, 'Pointer passed to UTF32ToString must be aligned to four bytes!');
  979. var i = 0;
  980. var str = '';
  981. while (1) {
  982. var utf32 = HEAP32[(((ptr)+(i*4))>>2)];
  983. if (utf32 == 0) return str;
  984. ++i;
  985. // 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.
  986. // See http://unicode.org/faq/utf_bom.html#utf16-3
  987. if (utf32 >= 0x10000) {
  988. var ch = utf32 - 0x10000;
  989. str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
  990. } else {
  991. str += String.fromCharCode(utf32);
  992. }
  993. }
  994. }
  995. // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
  996. // null-terminated and encoded in UTF32 form. The copy will require at most str.length*4+4 bytes of space in the HEAP.
  997. // Use the function lengthBytesUTF32() to compute the exact number of bytes (excluding null terminator) that this function will write.
  998. // Parameters:
  999. // str: the Javascript string to copy.
  1000. // outPtr: Byte address in Emscripten HEAP where to write the string to.
  1001. // maxBytesToWrite: The maximum number of bytes this function can write to the array. This count should include the null
  1002. // terminator, i.e. if maxBytesToWrite=4, only the null terminator will be written and nothing else.
  1003. // maxBytesToWrite<4 does not write any bytes to the output, not even the null terminator.
  1004. // Returns the number of bytes written, EXCLUDING the null terminator.
  1005. function stringToUTF32(str, outPtr, maxBytesToWrite) {
  1006. assert(outPtr % 4 == 0, 'Pointer passed to stringToUTF32 must be aligned to four bytes!');
  1007. assert(typeof maxBytesToWrite == 'number', 'stringToUTF32(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
  1008. // Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
  1009. if (maxBytesToWrite === undefined) {
  1010. maxBytesToWrite = 0x7FFFFFFF;
  1011. }
  1012. if (maxBytesToWrite < 4) return 0;
  1013. var startPtr = outPtr;
  1014. var endPtr = startPtr + maxBytesToWrite - 4;
  1015. for (var i = 0; i < str.length; ++i) {
  1016. // 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.
  1017. // See http://unicode.org/faq/utf_bom.html#utf16-3
  1018. var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
  1019. if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) {
  1020. var trailSurrogate = str.charCodeAt(++i);
  1021. codeUnit = 0x10000 + ((codeUnit & 0x3FF) << 10) | (trailSurrogate & 0x3FF);
  1022. }
  1023. HEAP32[((outPtr)>>2)]=codeUnit;
  1024. outPtr += 4;
  1025. if (outPtr + 4 > endPtr) break;
  1026. }
  1027. // Null-terminate the pointer to the HEAP.
  1028. HEAP32[((outPtr)>>2)]=0;
  1029. return outPtr - startPtr;
  1030. }
  1031. // Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte.
  1032. function lengthBytesUTF32(str) {
  1033. var len = 0;
  1034. for (var i = 0; i < str.length; ++i) {
  1035. // 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.
  1036. // See http://unicode.org/faq/utf_bom.html#utf16-3
  1037. var codeUnit = str.charCodeAt(i);
  1038. if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) ++i; // possibly a lead surrogate, so skip over the tail surrogate.
  1039. len += 4;
  1040. }
  1041. return len;
  1042. }
  1043. // Allocate heap space for a JS string, and write it there.
  1044. // It is the responsibility of the caller to free() that memory.
  1045. function allocateUTF8(str) {
  1046. var size = lengthBytesUTF8(str) + 1;
  1047. var ret = _malloc(size);
  1048. if (ret) stringToUTF8Array(str, HEAP8, ret, size);
  1049. return ret;
  1050. }
  1051. // Allocate stack space for a JS string, and write it there.
  1052. function allocateUTF8OnStack(str) {
  1053. var size = lengthBytesUTF8(str) + 1;
  1054. var ret = stackAlloc(size);
  1055. stringToUTF8Array(str, HEAP8, ret, size);
  1056. return ret;
  1057. }
  1058. // Deprecated: This function should not be called because it is unsafe and does not provide
  1059. // a maximum length limit of how many bytes it is allowed to write. Prefer calling the
  1060. // function stringToUTF8Array() instead, which takes in a maximum length that can be used
  1061. // to be secure from out of bounds writes.
  1062. /** @deprecated
  1063. @param {boolean=} dontAddNull */
  1064. function writeStringToMemory(string, buffer, dontAddNull) {
  1065. warnOnce('writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!');
  1066. var /** @type {number} */ lastChar, /** @type {number} */ end;
  1067. if (dontAddNull) {
  1068. // stringToUTF8Array always appends null. If we don't want to do that, remember the
  1069. // character that existed at the location where the null will be placed, and restore
  1070. // that after the write (below).
  1071. end = buffer + lengthBytesUTF8(string);
  1072. lastChar = HEAP8[end];
  1073. }
  1074. stringToUTF8(string, buffer, Infinity);
  1075. if (dontAddNull) HEAP8[end] = lastChar; // Restore the value under the null character.
  1076. }
  1077. function writeArrayToMemory(array, buffer) {
  1078. assert(array.length >= 0, 'writeArrayToMemory array must have a length (should be an array or typed array)')
  1079. HEAP8.set(array, buffer);
  1080. }
  1081. /** @param {boolean=} dontAddNull */
  1082. function writeAsciiToMemory(str, buffer, dontAddNull) {
  1083. for (var i = 0; i < str.length; ++i) {
  1084. assert(str.charCodeAt(i) === str.charCodeAt(i)&0xff);
  1085. HEAP8[((buffer++)>>0)]=str.charCodeAt(i);
  1086. }
  1087. // Null-terminate the pointer to the HEAP.
  1088. if (!dontAddNull) HEAP8[((buffer)>>0)]=0;
  1089. }
  1090. // Memory management
  1091. var PAGE_SIZE = 16384;
  1092. var WASM_PAGE_SIZE = 65536;
  1093. var ASMJS_PAGE_SIZE = 16777216;
  1094. function alignUp(x, multiple) {
  1095. if (x % multiple > 0) {
  1096. x += multiple - (x % multiple);
  1097. }
  1098. return x;
  1099. }
  1100. var HEAP,
  1101. /** @type {ArrayBuffer} */
  1102. buffer,
  1103. /** @type {Int8Array} */
  1104. HEAP8,
  1105. /** @type {Uint8Array} */
  1106. HEAPU8,
  1107. /** @type {Int16Array} */
  1108. HEAP16,
  1109. /** @type {Uint16Array} */
  1110. HEAPU16,
  1111. /** @type {Int32Array} */
  1112. HEAP32,
  1113. /** @type {Uint32Array} */
  1114. HEAPU32,
  1115. /** @type {Float32Array} */
  1116. HEAPF32,
  1117. /** @type {Float64Array} */
  1118. HEAPF64;
  1119. function updateGlobalBufferAndViews(buf) {
  1120. buffer = buf;
  1121. Module['HEAP8'] = HEAP8 = new Int8Array(buf);
  1122. Module['HEAP16'] = HEAP16 = new Int16Array(buf);
  1123. Module['HEAP32'] = HEAP32 = new Int32Array(buf);
  1124. Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf);
  1125. Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf);
  1126. Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf);
  1127. Module['HEAPF32'] = HEAPF32 = new Float32Array(buf);
  1128. Module['HEAPF64'] = HEAPF64 = new Float64Array(buf);
  1129. }
  1130. var STATIC_BASE = 1024,
  1131. STACK_BASE = 5305952,
  1132. STACKTOP = STACK_BASE,
  1133. STACK_MAX = 63072,
  1134. DYNAMIC_BASE = 5305952,
  1135. DYNAMICTOP_PTR = 62912;
  1136. assert(STACK_BASE % 16 === 0, 'stack must start aligned');
  1137. assert(DYNAMIC_BASE % 16 === 0, 'heap must start aligned');
  1138. var TOTAL_STACK = 5242880;
  1139. if (Module['TOTAL_STACK']) assert(TOTAL_STACK === Module['TOTAL_STACK'], 'the stack size can no longer be determined at runtime')
  1140. var INITIAL_INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 16777216;if (!Object.getOwnPropertyDescriptor(Module, 'INITIAL_MEMORY')) Object.defineProperty(Module, 'INITIAL_MEMORY', { configurable: true, get: function() { abort('Module.INITIAL_MEMORY has been replaced with plain INITIAL_INITIAL_MEMORY') } });
  1141. assert(INITIAL_INITIAL_MEMORY >= TOTAL_STACK, 'INITIAL_MEMORY should be larger than TOTAL_STACK, was ' + INITIAL_INITIAL_MEMORY + '! (TOTAL_STACK=' + TOTAL_STACK + ')');
  1142. // check for full engine support (use string 'subarray' to avoid closure compiler confusion)
  1143. assert(typeof Int32Array !== 'undefined' && typeof Float64Array !== 'undefined' && Int32Array.prototype.subarray !== undefined && Int32Array.prototype.set !== undefined,
  1144. 'JS engine does not provide full typed array support');
  1145. /**
  1146. * @license
  1147. * Copyright 2019 The Emscripten Authors
  1148. * SPDX-License-Identifier: MIT
  1149. */
  1150. // In standalone mode, the wasm creates the memory, and the user can't provide it.
  1151. // In non-standalone/normal mode, we create the memory here.
  1152. /**
  1153. * @license
  1154. * Copyright 2019 The Emscripten Authors
  1155. * SPDX-License-Identifier: MIT
  1156. */
  1157. // Create the main memory. (Note: this isn't used in STANDALONE_WASM mode since the wasm
  1158. // memory is created in the wasm, not in JS.)
  1159. if (Module['wasmMemory']) {
  1160. wasmMemory = Module['wasmMemory'];
  1161. } else
  1162. {
  1163. wasmMemory = new WebAssembly.Memory({
  1164. 'initial': INITIAL_INITIAL_MEMORY / WASM_PAGE_SIZE
  1165. ,
  1166. 'maximum': 2147483648 / WASM_PAGE_SIZE
  1167. });
  1168. }
  1169. if (wasmMemory) {
  1170. buffer = wasmMemory.buffer;
  1171. }
  1172. // If the user provides an incorrect length, just use that length instead rather than providing the user to
  1173. // specifically provide the memory length with Module['INITIAL_MEMORY'].
  1174. INITIAL_INITIAL_MEMORY = buffer.byteLength;
  1175. assert(INITIAL_INITIAL_MEMORY % WASM_PAGE_SIZE === 0);
  1176. assert(65536 % WASM_PAGE_SIZE === 0);
  1177. updateGlobalBufferAndViews(buffer);
  1178. HEAP32[DYNAMICTOP_PTR>>2] = DYNAMIC_BASE;
  1179. /**
  1180. * @license
  1181. * Copyright 2019 The Emscripten Authors
  1182. * SPDX-License-Identifier: MIT
  1183. */
  1184. // Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode.
  1185. function writeStackCookie() {
  1186. assert((STACK_MAX & 3) == 0);
  1187. // The stack grows downwards
  1188. HEAPU32[(STACK_MAX >> 2)+1] = 0x2135467;
  1189. HEAPU32[(STACK_MAX >> 2)+2] = 0x89BACDFE;
  1190. // Also test the global address 0 for integrity.
  1191. // We don't do this with ASan because ASan does its own checks for this.
  1192. HEAP32[0] = 0x63736d65; /* 'emsc' */
  1193. }
  1194. function checkStackCookie() {
  1195. var cookie1 = HEAPU32[(STACK_MAX >> 2)+1];
  1196. var cookie2 = HEAPU32[(STACK_MAX >> 2)+2];
  1197. if (cookie1 != 0x2135467 || cookie2 != 0x89BACDFE) {
  1198. abort('Stack overflow! Stack cookie has been overwritten, expected hex dwords 0x89BACDFE and 0x2135467, but received 0x' + cookie2.toString(16) + ' ' + cookie1.toString(16));
  1199. }
  1200. // Also test the global address 0 for integrity.
  1201. // We don't do this with ASan because ASan does its own checks for this.
  1202. if (HEAP32[0] !== 0x63736d65 /* 'emsc' */) abort('Runtime error: The application has corrupted its heap memory area (address zero)!');
  1203. }
  1204. function abortStackOverflow(allocSize) {
  1205. abort('Stack overflow! Attempted to allocate ' + allocSize + ' bytes on the stack, but stack has only ' + (STACK_MAX - stackSave() + allocSize) + ' bytes available!');
  1206. }
  1207. /**
  1208. * @license
  1209. * Copyright 2019 The Emscripten Authors
  1210. * SPDX-License-Identifier: MIT
  1211. */
  1212. // Endianness check (note: assumes compiler arch was little-endian)
  1213. (function() {
  1214. var h16 = new Int16Array(1);
  1215. var h8 = new Int8Array(h16.buffer);
  1216. h16[0] = 0x6373;
  1217. if (h8[0] !== 0x73 || h8[1] !== 0x63) throw 'Runtime error: expected the system to be little-endian!';
  1218. })();
  1219. function abortFnPtrError(ptr, sig) {
  1220. abort("Invalid function pointer " + ptr + " called with signature '" + sig + "'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this). Build with ASSERTIONS=2 for more info.");
  1221. }
  1222. function callRuntimeCallbacks(callbacks) {
  1223. while(callbacks.length > 0) {
  1224. var callback = callbacks.shift();
  1225. if (typeof callback == 'function') {
  1226. callback(Module); // Pass the module as the first argument.
  1227. continue;
  1228. }
  1229. var func = callback.func;
  1230. if (typeof func === 'number') {
  1231. if (callback.arg === undefined) {
  1232. Module['dynCall_v'](func);
  1233. } else {
  1234. Module['dynCall_vi'](func, callback.arg);
  1235. }
  1236. } else {
  1237. func(callback.arg === undefined ? null : callback.arg);
  1238. }
  1239. }
  1240. }
  1241. var __ATPRERUN__ = []; // functions called before the runtime is initialized
  1242. var __ATINIT__ = []; // functions called during startup
  1243. var __ATMAIN__ = []; // functions called when main() is to be run
  1244. var __ATEXIT__ = []; // functions called during shutdown
  1245. var __ATPOSTRUN__ = []; // functions called after the main() is called
  1246. var runtimeInitialized = false;
  1247. var runtimeExited = false;
  1248. function preRun() {
  1249. if (Module['preRun']) {
  1250. if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
  1251. while (Module['preRun'].length) {
  1252. addOnPreRun(Module['preRun'].shift());
  1253. }
  1254. }
  1255. callRuntimeCallbacks(__ATPRERUN__);
  1256. }
  1257. function initRuntime() {
  1258. checkStackCookie();
  1259. assert(!runtimeInitialized);
  1260. runtimeInitialized = true;
  1261. if (!Module["noFSInit"] && !FS.init.initialized) FS.init();
  1262. TTY.init();
  1263. callRuntimeCallbacks(__ATINIT__);
  1264. }
  1265. function preMain() {
  1266. checkStackCookie();
  1267. FS.ignorePermissions = false;
  1268. callRuntimeCallbacks(__ATMAIN__);
  1269. }
  1270. function exitRuntime() {
  1271. checkStackCookie();
  1272. runtimeExited = true;
  1273. }
  1274. function postRun() {
  1275. checkStackCookie();
  1276. if (Module['postRun']) {
  1277. if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
  1278. while (Module['postRun'].length) {
  1279. addOnPostRun(Module['postRun'].shift());
  1280. }
  1281. }
  1282. callRuntimeCallbacks(__ATPOSTRUN__);
  1283. }
  1284. function addOnPreRun(cb) {
  1285. __ATPRERUN__.unshift(cb);
  1286. }
  1287. function addOnInit(cb) {
  1288. __ATINIT__.unshift(cb);
  1289. }
  1290. function addOnPreMain(cb) {
  1291. __ATMAIN__.unshift(cb);
  1292. }
  1293. function addOnExit(cb) {
  1294. }
  1295. function addOnPostRun(cb) {
  1296. __ATPOSTRUN__.unshift(cb);
  1297. }
  1298. /** @param {number|boolean=} ignore */
  1299. function unSign(value, bits, ignore) {
  1300. if (value >= 0) {
  1301. return value;
  1302. }
  1303. 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
  1304. : Math.pow(2, bits) + value;
  1305. }
  1306. /** @param {number|boolean=} ignore */
  1307. function reSign(value, bits, ignore) {
  1308. if (value <= 0) {
  1309. return value;
  1310. }
  1311. var half = bits <= 32 ? Math.abs(1 << (bits-1)) // abs is needed if bits == 32
  1312. : Math.pow(2, bits-1);
  1313. 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
  1314. // but, in general there is no perfect solution here. With 64-bit ints, we get rounding and errors
  1315. // TODO: In i64 mode 1, resign the two parts separately and safely
  1316. value = -2*half + value; // Cannot bitshift half, as it may be at the limit of the bits JS uses in bitshifts
  1317. }
  1318. return value;
  1319. }
  1320. /**
  1321. * @license
  1322. * Copyright 2019 The Emscripten Authors
  1323. * SPDX-License-Identifier: MIT
  1324. */
  1325. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
  1326. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
  1327. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
  1328. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
  1329. assert(Math.imul, 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  1330. assert(Math.fround, 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  1331. assert(Math.clz32, 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  1332. assert(Math.trunc, 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  1333. var Math_abs = Math.abs;
  1334. var Math_cos = Math.cos;
  1335. var Math_sin = Math.sin;
  1336. var Math_tan = Math.tan;
  1337. var Math_acos = Math.acos;
  1338. var Math_asin = Math.asin;
  1339. var Math_atan = Math.atan;
  1340. var Math_atan2 = Math.atan2;
  1341. var Math_exp = Math.exp;
  1342. var Math_log = Math.log;
  1343. var Math_sqrt = Math.sqrt;
  1344. var Math_ceil = Math.ceil;
  1345. var Math_floor = Math.floor;
  1346. var Math_pow = Math.pow;
  1347. var Math_imul = Math.imul;
  1348. var Math_fround = Math.fround;
  1349. var Math_round = Math.round;
  1350. var Math_min = Math.min;
  1351. var Math_max = Math.max;
  1352. var Math_clz32 = Math.clz32;
  1353. var Math_trunc = Math.trunc;
  1354. // A counter of dependencies for calling run(). If we need to
  1355. // do asynchronous work before running, increment this and
  1356. // decrement it. Incrementing must happen in a place like
  1357. // Module.preRun (used by emcc to add file preloading).
  1358. // Note that you can add dependencies in preRun, even though
  1359. // it happens right before run - run will be postponed until
  1360. // the dependencies are met.
  1361. var runDependencies = 0;
  1362. var runDependencyWatcher = null;
  1363. var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
  1364. var runDependencyTracking = {};
  1365. function getUniqueRunDependency(id) {
  1366. var orig = id;
  1367. while (1) {
  1368. if (!runDependencyTracking[id]) return id;
  1369. id = orig + Math.random();
  1370. }
  1371. }
  1372. function addRunDependency(id) {
  1373. runDependencies++;
  1374. if (Module['monitorRunDependencies']) {
  1375. Module['monitorRunDependencies'](runDependencies);
  1376. }
  1377. if (id) {
  1378. assert(!runDependencyTracking[id]);
  1379. runDependencyTracking[id] = 1;
  1380. if (runDependencyWatcher === null && typeof setInterval !== 'undefined') {
  1381. // Check for missing dependencies every few seconds
  1382. runDependencyWatcher = setInterval(function() {
  1383. if (ABORT) {
  1384. clearInterval(runDependencyWatcher);
  1385. runDependencyWatcher = null;
  1386. return;
  1387. }
  1388. var shown = false;
  1389. for (var dep in runDependencyTracking) {
  1390. if (!shown) {
  1391. shown = true;
  1392. err('still waiting on run dependencies:');
  1393. }
  1394. err('dependency: ' + dep);
  1395. }
  1396. if (shown) {
  1397. err('(end of list)');
  1398. }
  1399. }, 10000);
  1400. }
  1401. } else {
  1402. err('warning: run dependency added without ID');
  1403. }
  1404. }
  1405. function removeRunDependency(id) {
  1406. runDependencies--;
  1407. if (Module['monitorRunDependencies']) {
  1408. Module['monitorRunDependencies'](runDependencies);
  1409. }
  1410. if (id) {
  1411. assert(runDependencyTracking[id]);
  1412. delete runDependencyTracking[id];
  1413. } else {
  1414. err('warning: run dependency removed without ID');
  1415. }
  1416. if (runDependencies == 0) {
  1417. if (runDependencyWatcher !== null) {
  1418. clearInterval(runDependencyWatcher);
  1419. runDependencyWatcher = null;
  1420. }
  1421. if (dependenciesFulfilled) {
  1422. var callback = dependenciesFulfilled;
  1423. dependenciesFulfilled = null;
  1424. callback(); // can add another dependenciesFulfilled
  1425. }
  1426. }
  1427. }
  1428. Module["preloadedImages"] = {}; // maps url to image data
  1429. Module["preloadedAudios"] = {}; // maps url to audio data
  1430. /** @param {string|number=} what */
  1431. function abort(what) {
  1432. if (Module['onAbort']) {
  1433. Module['onAbort'](what);
  1434. }
  1435. what += '';
  1436. out(what);
  1437. err(what);
  1438. ABORT = true;
  1439. EXITSTATUS = 1;
  1440. var output = 'abort(' + what + ') at ' + stackTrace();
  1441. what = output;
  1442. // Throw a wasm runtime error, because a JS error might be seen as a foreign
  1443. // exception, which means we'd run destructors on it. We need the error to
  1444. // simply make the program stop.
  1445. throw new WebAssembly.RuntimeError(what);
  1446. }
  1447. var memoryInitializer = null;
  1448. /**
  1449. * @license
  1450. * Copyright 2015 The Emscripten Authors
  1451. * SPDX-License-Identifier: MIT
  1452. */
  1453. /**
  1454. * @license
  1455. * Copyright 2017 The Emscripten Authors
  1456. * SPDX-License-Identifier: MIT
  1457. */
  1458. // Prefix of data URIs emitted by SINGLE_FILE and related options.
  1459. var dataURIPrefix = 'data:application/octet-stream;base64,';
  1460. // Indicates whether filename is a base64 data URI.
  1461. function isDataURI(filename) {
  1462. return String.prototype.startsWith ?
  1463. filename.startsWith(dataURIPrefix) :
  1464. filename.indexOf(dataURIPrefix) === 0;
  1465. }
  1466. var wasmBinaryFile = 'wasmconverter.wasm';
  1467. if (!isDataURI(wasmBinaryFile)) {
  1468. wasmBinaryFile = locateFile(wasmBinaryFile);
  1469. }
  1470. function getBinary() {
  1471. try {
  1472. if (wasmBinary) {
  1473. return new Uint8Array(wasmBinary);
  1474. }
  1475. if (readBinary) {
  1476. return readBinary(wasmBinaryFile);
  1477. } else {
  1478. throw "both async and sync fetching of the wasm failed";
  1479. }
  1480. }
  1481. catch (err) {
  1482. abort(err);
  1483. }
  1484. }
  1485. function getBinaryPromise() {
  1486. // if we don't have the binary yet, and have the Fetch api, use that
  1487. // in some environments, like Electron's render process, Fetch api may be present, but have a different context than expected, let's only use it on the Web
  1488. if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && typeof fetch === 'function') {
  1489. return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
  1490. if (!response['ok']) {
  1491. throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
  1492. }
  1493. return response['arrayBuffer']();
  1494. }).catch(function () {
  1495. return getBinary();
  1496. });
  1497. }
  1498. // Otherwise, getBinary should be able to get it synchronously
  1499. return new Promise(function(resolve, reject) {
  1500. resolve(getBinary());
  1501. });
  1502. }
  1503. // Create the wasm instance.
  1504. // Receives the wasm imports, returns the exports.
  1505. function createWasm() {
  1506. // prepare imports
  1507. var info = {
  1508. 'env': asmLibraryArg,
  1509. 'wasi_snapshot_preview1': asmLibraryArg
  1510. };
  1511. // Load the wasm module and create an instance of using native support in the JS engine.
  1512. // handle a generated wasm instance, receiving its exports and
  1513. // performing other necessary setup
  1514. /** @param {WebAssembly.Module=} module*/
  1515. function receiveInstance(instance, module) {
  1516. var exports = instance.exports;
  1517. Module['asm'] = exports;
  1518. removeRunDependency('wasm-instantiate');
  1519. }
  1520. // we can't run yet (except in a pthread, where we have a custom sync instantiator)
  1521. addRunDependency('wasm-instantiate');
  1522. // Async compilation can be confusing when an error on the page overwrites Module
  1523. // (for example, if the order of elements is wrong, and the one defining Module is
  1524. // later), so we save Module and check it later.
  1525. var trueModule = Module;
  1526. function receiveInstantiatedSource(output) {
  1527. // 'output' is a WebAssemblyInstantiatedSource object which has both the module and instance.
  1528. // receiveInstance() will swap in the exports (to Module.asm) so they can be called
  1529. assert(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?');
  1530. trueModule = null;
  1531. // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
  1532. // When the regression is fixed, can restore the above USE_PTHREADS-enabled path.
  1533. receiveInstance(output['instance']);
  1534. }
  1535. function instantiateArrayBuffer(receiver) {
  1536. return getBinaryPromise().then(function(binary) {
  1537. return WebAssembly.instantiate(binary, info);
  1538. }).then(receiver, function(reason) {
  1539. err('failed to asynchronously prepare wasm: ' + reason);
  1540. abort(reason);
  1541. });
  1542. }
  1543. // Prefer streaming instantiation if available.
  1544. function instantiateAsync() {
  1545. if (!wasmBinary &&
  1546. typeof WebAssembly.instantiateStreaming === 'function' &&
  1547. !isDataURI(wasmBinaryFile) &&
  1548. typeof fetch === 'function') {
  1549. fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function (response) {
  1550. var result = WebAssembly.instantiateStreaming(response, info);
  1551. return result.then(receiveInstantiatedSource, function(reason) {
  1552. // We expect the most common failure cause to be a bad MIME type for the binary,
  1553. // in which case falling back to ArrayBuffer instantiation should work.
  1554. // err('wasm streaming compile failed: ' + reason);
  1555. // err('falling back to ArrayBuffer instantiation');
  1556. instantiateArrayBuffer(receiveInstantiatedSource);
  1557. });
  1558. });
  1559. } else {
  1560. return instantiateArrayBuffer(receiveInstantiatedSource);
  1561. }
  1562. }
  1563. // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
  1564. // to manually instantiate the Wasm module themselves. This allows pages to run the instantiation parallel
  1565. // to any other async startup actions they are performing.
  1566. if (Module['instantiateWasm']) {
  1567. try {
  1568. var exports = Module['instantiateWasm'](info, receiveInstance);
  1569. return exports;
  1570. } catch(e) {
  1571. err('Module.instantiateWasm callback failed with error: ' + e);
  1572. return false;
  1573. }
  1574. }
  1575. instantiateAsync();
  1576. return {}; // no exports yet; we'll fill them in later
  1577. }
  1578. // Globals used by JS i64 conversions
  1579. var tempDouble;
  1580. var tempI64;
  1581. // === Body ===
  1582. var ASM_CONSTS = {
  1583. };
  1584. // STATICTOP = STATIC_BASE + 62048;
  1585. /* global initializers */ __ATINIT__.push({ func: function() { ___wasm_call_ctors() } });
  1586. /* no memory initializer */
  1587. // {{PRE_LIBRARY}}
  1588. function demangle(func) {
  1589. warnOnce('warning: build with -s DEMANGLE_SUPPORT=1 to link in libcxxabi demangling');
  1590. return func;
  1591. }
  1592. function demangleAll(text) {
  1593. var regex =
  1594. /\b_Z[\w\d_]+/g;
  1595. return text.replace(regex,
  1596. function(x) {
  1597. var y = demangle(x);
  1598. return x === y ? x : (y + ' [' + x + ']');
  1599. });
  1600. }
  1601. function jsStackTrace() {
  1602. var err = new Error();
  1603. if (!err.stack) {
  1604. // IE10+ special cases: It does have callstack info, but it is only populated if an Error object is thrown,
  1605. // so try that as a special-case.
  1606. try {
  1607. throw new Error();
  1608. } catch(e) {
  1609. err = e;
  1610. }
  1611. if (!err.stack) {
  1612. return '(no stack trace available)';
  1613. }
  1614. }
  1615. return err.stack.toString();
  1616. }
  1617. function stackTrace() {
  1618. var js = jsStackTrace();
  1619. if (Module['extraStackTrace']) js += '\n' + Module['extraStackTrace']();
  1620. return demangleAll(js);
  1621. }
  1622. function ___assert_fail(condition, filename, line, func) {
  1623. abort('Assertion failed: ' + UTF8ToString(condition) + ', at: ' + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']);
  1624. }
  1625. function ___cxa_allocate_exception(size) {
  1626. return _malloc(size);
  1627. }
  1628. function _atexit(func, arg) {
  1629. warnOnce('atexit() called, but EXIT_RUNTIME is not set, so atexits() will not be called. set EXIT_RUNTIME to 1 (see the FAQ)');
  1630. __ATEXIT__.unshift({ func: func, arg: arg });
  1631. }function ___cxa_atexit(a0,a1
  1632. ) {
  1633. return _atexit(a0,a1);
  1634. }
  1635. var ___exception_infos={};
  1636. var ___exception_last=0;
  1637. function __ZSt18uncaught_exceptionv() { // std::uncaught_exception()
  1638. return __ZSt18uncaught_exceptionv.uncaught_exceptions > 0;
  1639. }function ___cxa_throw(ptr, type, destructor) {
  1640. ___exception_infos[ptr] = {
  1641. ptr: ptr,
  1642. adjusted: [ptr],
  1643. type: type,
  1644. destructor: destructor,
  1645. refcount: 0,
  1646. caught: false,
  1647. rethrown: false
  1648. };
  1649. ___exception_last = ptr;
  1650. if (!("uncaught_exception" in __ZSt18uncaught_exceptionv)) {
  1651. __ZSt18uncaught_exceptionv.uncaught_exceptions = 1;
  1652. } else {
  1653. __ZSt18uncaught_exceptionv.uncaught_exceptions++;
  1654. }
  1655. throw ptr + " - Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch.";
  1656. }
  1657. function ___handle_stack_overflow() {
  1658. abort('stack overflow')
  1659. }
  1660. function ___setErrNo(value) {
  1661. if (Module['___errno_location']) HEAP32[((Module['___errno_location']())>>2)]=value;
  1662. else err('failed to set errno from JS');
  1663. return value;
  1664. }function ___map_file(pathname, size) {
  1665. ___setErrNo(63);
  1666. return -1;
  1667. }
  1668. var PATH={splitPath:function(filename) {
  1669. var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  1670. return splitPathRe.exec(filename).slice(1);
  1671. },normalizeArray:function(parts, allowAboveRoot) {
  1672. // if the path tries to go above the root, `up` ends up > 0
  1673. var up = 0;
  1674. for (var i = parts.length - 1; i >= 0; i--) {
  1675. var last = parts[i];
  1676. if (last === '.') {
  1677. parts.splice(i, 1);
  1678. } else if (last === '..') {
  1679. parts.splice(i, 1);
  1680. up++;
  1681. } else if (up) {
  1682. parts.splice(i, 1);
  1683. up--;
  1684. }
  1685. }
  1686. // if the path is allowed to go above the root, restore leading ..s
  1687. if (allowAboveRoot) {
  1688. for (; up; up--) {
  1689. parts.unshift('..');
  1690. }
  1691. }
  1692. return parts;
  1693. },normalize:function(path) {
  1694. var isAbsolute = path.charAt(0) === '/',
  1695. trailingSlash = path.substr(-1) === '/';
  1696. // Normalize the path
  1697. path = PATH.normalizeArray(path.split('/').filter(function(p) {
  1698. return !!p;
  1699. }), !isAbsolute).join('/');
  1700. if (!path && !isAbsolute) {
  1701. path = '.';
  1702. }
  1703. if (path && trailingSlash) {
  1704. path += '/';
  1705. }
  1706. return (isAbsolute ? '/' : '') + path;
  1707. },dirname:function(path) {
  1708. var result = PATH.splitPath(path),
  1709. root = result[0],
  1710. dir = result[1];
  1711. if (!root && !dir) {
  1712. // No dirname whatsoever
  1713. return '.';
  1714. }
  1715. if (dir) {
  1716. // It has a dirname, strip trailing slash
  1717. dir = dir.substr(0, dir.length - 1);
  1718. }
  1719. return root + dir;
  1720. },basename:function(path) {
  1721. // EMSCRIPTEN return '/'' for '/', not an empty string
  1722. if (path === '/') return '/';
  1723. var lastSlash = path.lastIndexOf('/');
  1724. if (lastSlash === -1) return path;
  1725. return path.substr(lastSlash+1);
  1726. },extname:function(path) {
  1727. return PATH.splitPath(path)[3];
  1728. },join:function() {
  1729. var paths = Array.prototype.slice.call(arguments, 0);
  1730. return PATH.normalize(paths.join('/'));
  1731. },join2:function(l, r) {
  1732. return PATH.normalize(l + '/' + r);
  1733. }};
  1734. var PATH_FS={resolve:function() {
  1735. var resolvedPath = '',
  1736. resolvedAbsolute = false;
  1737. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  1738. var path = (i >= 0) ? arguments[i] : FS.cwd();
  1739. // Skip empty and invalid entries
  1740. if (typeof path !== 'string') {
  1741. throw new TypeError('Arguments to path.resolve must be strings');
  1742. } else if (!path) {
  1743. return ''; // an invalid portion invalidates the whole thing
  1744. }
  1745. resolvedPath = path + '/' + resolvedPath;
  1746. resolvedAbsolute = path.charAt(0) === '/';
  1747. }
  1748. // At this point the path should be resolved to a full absolute path, but
  1749. // handle relative paths to be safe (might happen when process.cwd() fails)
  1750. resolvedPath = PATH.normalizeArray(resolvedPath.split('/').filter(function(p) {
  1751. return !!p;
  1752. }), !resolvedAbsolute).join('/');
  1753. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  1754. },relative:function(from, to) {
  1755. from = PATH_FS.resolve(from).substr(1);
  1756. to = PATH_FS.resolve(to).substr(1);
  1757. function trim(arr) {
  1758. var start = 0;
  1759. for (; start < arr.length; start++) {
  1760. if (arr[start] !== '') break;
  1761. }
  1762. var end = arr.length - 1;
  1763. for (; end >= 0; end--) {
  1764. if (arr[end] !== '') break;
  1765. }
  1766. if (start > end) return [];
  1767. return arr.slice(start, end - start + 1);
  1768. }
  1769. var fromParts = trim(from.split('/'));
  1770. var toParts = trim(to.split('/'));
  1771. var length = Math.min(fromParts.length, toParts.length);
  1772. var samePartsLength = length;
  1773. for (var i = 0; i < length; i++) {
  1774. if (fromParts[i] !== toParts[i]) {
  1775. samePartsLength = i;
  1776. break;
  1777. }
  1778. }
  1779. var outputParts = [];
  1780. for (var i = samePartsLength; i < fromParts.length; i++) {
  1781. outputParts.push('..');
  1782. }
  1783. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  1784. return outputParts.join('/');
  1785. }};
  1786. var TTY={ttys:[],init:function () {
  1787. // https://github.com/emscripten-core/emscripten/pull/1555
  1788. // if (ENVIRONMENT_IS_NODE) {
  1789. // // currently, FS.init does not distinguish if process.stdin is a file or TTY
  1790. // // device, it always assumes it's a TTY device. because of this, we're forcing
  1791. // // process.stdin to UTF8 encoding to at least make stdin reading compatible
  1792. // // with text files until FS.init can be refactored.
  1793. // process['stdin']['setEncoding']('utf8');
  1794. // }
  1795. },shutdown:function() {
  1796. // https://github.com/emscripten-core/emscripten/pull/1555
  1797. // if (ENVIRONMENT_IS_NODE) {
  1798. // // inolen: any idea as to why node -e 'process.stdin.read()' wouldn't exit immediately (with process.stdin being a tty)?
  1799. // // 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
  1800. // // inolen: I thought read() in that case was a synchronous operation that just grabbed some amount of buffered data if it exists?
  1801. // // isaacs: it is. but it also triggers a _read() call, which calls readStart() on the handle
  1802. // // isaacs: do process.stdin.pause() and i'd think it'd probably close the pending call
  1803. // process['stdin']['pause']();
  1804. // }
  1805. },register:function(dev, ops) {
  1806. TTY.ttys[dev] = { input: [], output: [], ops: ops };
  1807. FS.registerDevice(dev, TTY.stream_ops);
  1808. },stream_ops:{open:function(stream) {
  1809. var tty = TTY.ttys[stream.node.rdev];
  1810. if (!tty) {
  1811. throw new FS.ErrnoError(43);
  1812. }
  1813. stream.tty = tty;
  1814. stream.seekable = false;
  1815. },close:function(stream) {
  1816. // flush any pending line data
  1817. stream.tty.ops.flush(stream.tty);
  1818. },flush:function(stream) {
  1819. stream.tty.ops.flush(stream.tty);
  1820. },read:function(stream, buffer, offset, length, pos /* ignored */) {
  1821. if (!stream.tty || !stream.tty.ops.get_char) {
  1822. throw new FS.ErrnoError(60);
  1823. }
  1824. var bytesRead = 0;
  1825. for (var i = 0; i < length; i++) {
  1826. var result;
  1827. try {
  1828. result = stream.tty.ops.get_char(stream.tty);
  1829. } catch (e) {
  1830. throw new FS.ErrnoError(29);
  1831. }
  1832. if (result === undefined && bytesRead === 0) {
  1833. throw new FS.ErrnoError(6);
  1834. }
  1835. if (result === null || result === undefined) break;
  1836. bytesRead++;
  1837. buffer[offset+i] = result;
  1838. }
  1839. if (bytesRead) {
  1840. stream.node.timestamp = Date.now();
  1841. }
  1842. return bytesRead;
  1843. },write:function(stream, buffer, offset, length, pos) {
  1844. if (!stream.tty || !stream.tty.ops.put_char) {
  1845. throw new FS.ErrnoError(60);
  1846. }
  1847. try {
  1848. for (var i = 0; i < length; i++) {
  1849. stream.tty.ops.put_char(stream.tty, buffer[offset+i]);
  1850. }
  1851. } catch (e) {
  1852. throw new FS.ErrnoError(29);
  1853. }
  1854. if (length) {
  1855. stream.node.timestamp = Date.now();
  1856. }
  1857. return i;
  1858. }},default_tty_ops:{get_char:function(tty) {
  1859. if (!tty.input.length) {
  1860. var result = null;
  1861. if (ENVIRONMENT_IS_NODE) {
  1862. // we will read data by chunks of BUFSIZE
  1863. var BUFSIZE = 256;
  1864. var buf = Buffer.alloc ? Buffer.alloc(BUFSIZE) : new Buffer(BUFSIZE);
  1865. var bytesRead = 0;
  1866. try {
  1867. bytesRead = nodeFS.readSync(process.stdin.fd, buf, 0, BUFSIZE, null);
  1868. } catch(e) {
  1869. // Cross-platform differences: on Windows, reading EOF throws an exception, but on other OSes,
  1870. // reading EOF returns 0. Uniformize behavior by treating the EOF exception to return 0.
  1871. if (e.toString().indexOf('EOF') != -1) bytesRead = 0;
  1872. else throw e;
  1873. }
  1874. if (bytesRead > 0) {
  1875. result = buf.slice(0, bytesRead).toString('utf-8');
  1876. } else {
  1877. result = null;
  1878. }
  1879. } else
  1880. if (typeof window != 'undefined' &&
  1881. typeof window.prompt == 'function') {
  1882. // Browser.
  1883. result = window.prompt('Input: '); // returns null on cancel
  1884. if (result !== null) {
  1885. result += '\n';
  1886. }
  1887. } else if (typeof readline == 'function') {
  1888. // Command line.
  1889. result = readline();
  1890. if (result !== null) {
  1891. result += '\n';
  1892. }
  1893. }
  1894. if (!result) {
  1895. return null;
  1896. }
  1897. tty.input = intArrayFromString(result, true);
  1898. }
  1899. return tty.input.shift();
  1900. },put_char:function(tty, val) {
  1901. if (val === null || val === 10) {
  1902. // out(UTF8ArrayToString(tty.output, 0));
  1903. tty.output = [];
  1904. } else {
  1905. if (val != 0) tty.output.push(val); // val == 0 would cut text output off in the middle.
  1906. }
  1907. },flush:function(tty) {
  1908. if (tty.output && tty.output.length > 0) {
  1909. // out(UTF8ArrayToString(tty.output, 0));
  1910. tty.output = [];
  1911. }
  1912. }},default_tty1_ops:{put_char:function(tty, val) {
  1913. if (val === null || val === 10) {
  1914. // err(UTF8ArrayToString(tty.output, 0));
  1915. tty.output = [];
  1916. } else {
  1917. if (val != 0) tty.output.push(val);
  1918. }
  1919. },flush:function(tty) {
  1920. if (tty.output && tty.output.length > 0) {
  1921. err(UTF8ArrayToString(tty.output, 0));
  1922. tty.output = [];
  1923. }
  1924. }}};
  1925. var MEMFS={ops_table:null,mount:function(mount) {
  1926. return MEMFS.createNode(null, '/', 16384 | 511 /* 0777 */, 0);
  1927. },createNode:function(parent, name, mode, dev) {
  1928. if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
  1929. // no supported
  1930. throw new FS.ErrnoError(63);
  1931. }
  1932. if (!MEMFS.ops_table) {
  1933. MEMFS.ops_table = {
  1934. dir: {
  1935. node: {
  1936. getattr: MEMFS.node_ops.getattr,
  1937. setattr: MEMFS.node_ops.setattr,
  1938. lookup: MEMFS.node_ops.lookup,
  1939. mknod: MEMFS.node_ops.mknod,
  1940. rename: MEMFS.node_ops.rename,
  1941. unlink: MEMFS.node_ops.unlink,
  1942. rmdir: MEMFS.node_ops.rmdir,
  1943. readdir: MEMFS.node_ops.readdir,
  1944. symlink: MEMFS.node_ops.symlink
  1945. },
  1946. stream: {
  1947. llseek: MEMFS.stream_ops.llseek
  1948. }
  1949. },
  1950. file: {
  1951. node: {
  1952. getattr: MEMFS.node_ops.getattr,
  1953. setattr: MEMFS.node_ops.setattr
  1954. },
  1955. stream: {
  1956. llseek: MEMFS.stream_ops.llseek,
  1957. read: MEMFS.stream_ops.read,
  1958. write: MEMFS.stream_ops.write,
  1959. allocate: MEMFS.stream_ops.allocate,
  1960. mmap: MEMFS.stream_ops.mmap,
  1961. msync: MEMFS.stream_ops.msync
  1962. }
  1963. },
  1964. link: {
  1965. node: {
  1966. getattr: MEMFS.node_ops.getattr,
  1967. setattr: MEMFS.node_ops.setattr,
  1968. readlink: MEMFS.node_ops.readlink
  1969. },
  1970. stream: {}
  1971. },
  1972. chrdev: {
  1973. node: {
  1974. getattr: MEMFS.node_ops.getattr,
  1975. setattr: MEMFS.node_ops.setattr
  1976. },
  1977. stream: FS.chrdev_stream_ops
  1978. }
  1979. };
  1980. }
  1981. var node = FS.createNode(parent, name, mode, dev);
  1982. if (FS.isDir(node.mode)) {
  1983. node.node_ops = MEMFS.ops_table.dir.node;
  1984. node.stream_ops = MEMFS.ops_table.dir.stream;
  1985. node.contents = {};
  1986. } else if (FS.isFile(node.mode)) {
  1987. node.node_ops = MEMFS.ops_table.file.node;
  1988. node.stream_ops = MEMFS.ops_table.file.stream;
  1989. node.usedBytes = 0; // The actual number of bytes used in the typed array, as opposed to contents.length which gives the whole capacity.
  1990. // When the byte data of the file is populated, this will point to either a typed array, or a normal JS array. Typed arrays are preferred
  1991. // for performance, and used by default. However, typed arrays are not resizable like normal JS arrays are, so there is a small disk size
  1992. // penalty involved for appending file writes that continuously grow a file similar to std::vector capacity vs used -scheme.
  1993. node.contents = null;
  1994. } else if (FS.isLink(node.mode)) {
  1995. node.node_ops = MEMFS.ops_table.link.node;
  1996. node.stream_ops = MEMFS.ops_table.link.stream;
  1997. } else if (FS.isChrdev(node.mode)) {
  1998. node.node_ops = MEMFS.ops_table.chrdev.node;
  1999. node.stream_ops = MEMFS.ops_table.chrdev.stream;
  2000. }
  2001. node.timestamp = Date.now();
  2002. // add the new node to the parent
  2003. if (parent) {
  2004. parent.contents[name] = node;
  2005. }
  2006. return node;
  2007. },getFileDataAsRegularArray:function(node) {
  2008. if (node.contents && node.contents.subarray) {
  2009. var arr = [];
  2010. for (var i = 0; i < node.usedBytes; ++i) arr.push(node.contents[i]);
  2011. return arr; // Returns a copy of the original data.
  2012. }
  2013. return node.contents; // No-op, the file contents are already in a JS array. Return as-is.
  2014. },getFileDataAsTypedArray:function(node) {
  2015. if (!node.contents) return new Uint8Array(0);
  2016. if (node.contents.subarray) return node.contents.subarray(0, node.usedBytes); // Make sure to not return excess unused bytes.
  2017. return new Uint8Array(node.contents);
  2018. },expandFileStorage:function(node, newCapacity) {
  2019. var prevCapacity = node.contents ? node.contents.length : 0;
  2020. if (prevCapacity >= newCapacity) return; // No need to expand, the storage was already large enough.
  2021. // Don't expand strictly to the given requested limit if it's only a very small increase, but instead geometrically grow capacity.
  2022. // For small filesizes (<1MB), perform size*2 geometric increase, but for large sizes, do a much more conservative size*1.125 increase to
  2023. // avoid overshooting the allocation cap by a very large margin.
  2024. var CAPACITY_DOUBLING_MAX = 1024 * 1024;
  2025. newCapacity = Math.max(newCapacity, (prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2.0 : 1.125)) >>> 0);
  2026. if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256); // At minimum allocate 256b for each file when expanding.
  2027. var oldContents = node.contents;
  2028. node.contents = new Uint8Array(newCapacity); // Allocate new storage.
  2029. if (node.usedBytes > 0) node.contents.set(oldContents.subarray(0, node.usedBytes), 0); // Copy old data over to the new storage.
  2030. return;
  2031. },resizeFileStorage:function(node, newSize) {
  2032. if (node.usedBytes == newSize) return;
  2033. if (newSize == 0) {
  2034. node.contents = null; // Fully decommit when requesting a resize to zero.
  2035. node.usedBytes = 0;
  2036. return;
  2037. }
  2038. if (!node.contents || node.contents.subarray) { // Resize a typed array if that is being used as the backing store.
  2039. var oldContents = node.contents;
  2040. node.contents = new Uint8Array(newSize); // Allocate new storage.
  2041. if (oldContents) {
  2042. node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes))); // Copy old data over to the new storage.
  2043. }
  2044. node.usedBytes = newSize;
  2045. return;
  2046. }
  2047. // Backing with a JS array.
  2048. if (!node.contents) node.contents = [];
  2049. if (node.contents.length > newSize) node.contents.length = newSize;
  2050. else while (node.contents.length < newSize) node.contents.push(0);
  2051. node.usedBytes = newSize;
  2052. },node_ops:{getattr:function(node) {
  2053. var attr = {};
  2054. // device numbers reuse inode numbers.
  2055. attr.dev = FS.isChrdev(node.mode) ? node.id : 1;
  2056. attr.ino = node.id;
  2057. attr.mode = node.mode;
  2058. attr.nlink = 1;
  2059. attr.uid = 0;
  2060. attr.gid = 0;
  2061. attr.rdev = node.rdev;
  2062. if (FS.isDir(node.mode)) {
  2063. attr.size = 4096;
  2064. } else if (FS.isFile(node.mode)) {
  2065. attr.size = node.usedBytes;
  2066. } else if (FS.isLink(node.mode)) {
  2067. attr.size = node.link.length;
  2068. } else {
  2069. attr.size = 0;
  2070. }
  2071. attr.atime = new Date(node.timestamp);
  2072. attr.mtime = new Date(node.timestamp);
  2073. attr.ctime = new Date(node.timestamp);
  2074. // NOTE: In our implementation, st_blocks = Math.ceil(st_size/st_blksize),
  2075. // but this is not required by the standard.
  2076. attr.blksize = 4096;
  2077. attr.blocks = Math.ceil(attr.size / attr.blksize);
  2078. return attr;
  2079. },setattr:function(node, attr) {
  2080. if (attr.mode !== undefined) {
  2081. node.mode = attr.mode;
  2082. }
  2083. if (attr.timestamp !== undefined) {
  2084. node.timestamp = attr.timestamp;
  2085. }
  2086. if (attr.size !== undefined) {
  2087. MEMFS.resizeFileStorage(node, attr.size);
  2088. }
  2089. },lookup:function(parent, name) {
  2090. throw FS.genericErrors[44];
  2091. },mknod:function(parent, name, mode, dev) {
  2092. return MEMFS.createNode(parent, name, mode, dev);
  2093. },rename:function(old_node, new_dir, new_name) {
  2094. // if we're overwriting a directory at new_name, make sure it's empty.
  2095. if (FS.isDir(old_node.mode)) {
  2096. var new_node;
  2097. try {
  2098. new_node = FS.lookupNode(new_dir, new_name);
  2099. } catch (e) {
  2100. }
  2101. if (new_node) {
  2102. for (var i in new_node.contents) {
  2103. throw new FS.ErrnoError(55);
  2104. }
  2105. }
  2106. }
  2107. // do the internal rewiring
  2108. delete old_node.parent.contents[old_node.name];
  2109. old_node.name = new_name;
  2110. new_dir.contents[new_name] = old_node;
  2111. old_node.parent = new_dir;
  2112. },unlink:function(parent, name) {
  2113. delete parent.contents[name];
  2114. },rmdir:function(parent, name) {
  2115. var node = FS.lookupNode(parent, name);
  2116. for (var i in node.contents) {
  2117. throw new FS.ErrnoError(55);
  2118. }
  2119. delete parent.contents[name];
  2120. },readdir:function(node) {
  2121. var entries = ['.', '..'];
  2122. for (var key in node.contents) {
  2123. if (!node.contents.hasOwnProperty(key)) {
  2124. continue;
  2125. }
  2126. entries.push(key);
  2127. }
  2128. return entries;
  2129. },symlink:function(parent, newname, oldpath) {
  2130. var node = MEMFS.createNode(parent, newname, 511 /* 0777 */ | 40960, 0);
  2131. node.link = oldpath;
  2132. return node;
  2133. },readlink:function(node) {
  2134. if (!FS.isLink(node.mode)) {
  2135. throw new FS.ErrnoError(28);
  2136. }
  2137. return node.link;
  2138. }},stream_ops:{read:function(stream, buffer, offset, length, position) {
  2139. var contents = stream.node.contents;
  2140. if (position >= stream.node.usedBytes) return 0;
  2141. var size = Math.min(stream.node.usedBytes - position, length);
  2142. assert(size >= 0);
  2143. if (size > 8 && contents.subarray) { // non-trivial, and typed array
  2144. buffer.set(contents.subarray(position, position + size), offset);
  2145. } else {
  2146. for (var i = 0; i < size; i++) buffer[offset + i] = contents[position + i];
  2147. }
  2148. return size;
  2149. },write:function(stream, buffer, offset, length, position, canOwn) {
  2150. // The data buffer should be a typed array view
  2151. assert(!(buffer instanceof ArrayBuffer));
  2152. // If the buffer is located in main memory (HEAP), and if
  2153. // memory can grow, we can't hold on to references of the
  2154. // memory buffer, as they may get invalidated. That means we
  2155. // need to do copy its contents.
  2156. if (buffer.buffer === HEAP8.buffer) {
  2157. // FIXME: this is inefficient as the file packager may have
  2158. // copied the data into memory already - we may want to
  2159. // integrate more there and let the file packager loading
  2160. // code be able to query if memory growth is on or off.
  2161. if (canOwn) {
  2162. warnOnce('file packager has copied file data into memory, but in memory growth we are forced to copy it again (see --no-heap-copy)');
  2163. }
  2164. canOwn = false;
  2165. }
  2166. if (!length) return 0;
  2167. var node = stream.node;
  2168. node.timestamp = Date.now();
  2169. if (buffer.subarray && (!node.contents || node.contents.subarray)) { // This write is from a typed array to a typed array?
  2170. if (canOwn) {
  2171. assert(position === 0, 'canOwn must imply no weird position inside the file');
  2172. node.contents = buffer.subarray(offset, offset + length);
  2173. node.usedBytes = length;
  2174. return length;
  2175. } else if (node.usedBytes === 0 && position === 0) { // If this is a simple first write to an empty file, do a fast set since we don't need to care about old data.
  2176. node.contents = buffer.slice(offset, offset + length);
  2177. node.usedBytes = length;
  2178. return length;
  2179. } else if (position + length <= node.usedBytes) { // Writing to an already allocated and used subrange of the file?
  2180. node.contents.set(buffer.subarray(offset, offset + length), position);
  2181. return length;
  2182. }
  2183. }
  2184. // Appending to an existing file and we need to reallocate, or source data did not come as a typed array.
  2185. MEMFS.expandFileStorage(node, position+length);
  2186. if (node.contents.subarray && buffer.subarray) node.contents.set(buffer.subarray(offset, offset + length), position); // Use typed array write if available.
  2187. else {
  2188. for (var i = 0; i < length; i++) {
  2189. node.contents[position + i] = buffer[offset + i]; // Or fall back to manual write if not.
  2190. }
  2191. }
  2192. node.usedBytes = Math.max(node.usedBytes, position + length);
  2193. return length;
  2194. },llseek:function(stream, offset, whence) {
  2195. var position = offset;
  2196. if (whence === 1) {
  2197. position += stream.position;
  2198. } else if (whence === 2) {
  2199. if (FS.isFile(stream.node.mode)) {
  2200. position += stream.node.usedBytes;
  2201. }
  2202. }
  2203. if (position < 0) {
  2204. throw new FS.ErrnoError(28);
  2205. }
  2206. return position;
  2207. },allocate:function(stream, offset, length) {
  2208. MEMFS.expandFileStorage(stream.node, offset + length);
  2209. stream.node.usedBytes = Math.max(stream.node.usedBytes, offset + length);
  2210. },mmap:function(stream, buffer, offset, length, position, prot, flags) {
  2211. // The data buffer should be a typed array view
  2212. assert(!(buffer instanceof ArrayBuffer));
  2213. if (!FS.isFile(stream.node.mode)) {
  2214. throw new FS.ErrnoError(43);
  2215. }
  2216. var ptr;
  2217. var allocated;
  2218. var contents = stream.node.contents;
  2219. // Only make a new copy when MAP_PRIVATE is specified.
  2220. if ( !(flags & 2) &&
  2221. contents.buffer === buffer.buffer ) {
  2222. // We can't emulate MAP_SHARED when the file is not backed by the buffer
  2223. // we're mapping to (e.g. the HEAP buffer).
  2224. allocated = false;
  2225. ptr = contents.byteOffset;
  2226. } else {
  2227. // Try to avoid unnecessary slices.
  2228. if (position > 0 || position + length < contents.length) {
  2229. if (contents.subarray) {
  2230. contents = contents.subarray(position, position + length);
  2231. } else {
  2232. contents = Array.prototype.slice.call(contents, position, position + length);
  2233. }
  2234. }
  2235. allocated = true;
  2236. // malloc() can lead to growing the heap. If targeting the heap, we need to
  2237. // re-acquire the heap buffer object in case growth had occurred.
  2238. var fromHeap = (buffer.buffer == HEAP8.buffer);
  2239. ptr = _malloc(length);
  2240. if (!ptr) {
  2241. throw new FS.ErrnoError(48);
  2242. }
  2243. (fromHeap ? HEAP8 : buffer).set(contents, ptr);
  2244. }
  2245. return { ptr: ptr, allocated: allocated };
  2246. },msync:function(stream, buffer, offset, length, mmapFlags) {
  2247. if (!FS.isFile(stream.node.mode)) {
  2248. throw new FS.ErrnoError(43);
  2249. }
  2250. if (mmapFlags & 2) {
  2251. // MAP_PRIVATE calls need not to be synced back to underlying fs
  2252. return 0;
  2253. }
  2254. var bytesWritten = MEMFS.stream_ops.write(stream, buffer, 0, length, offset, false);
  2255. // should we check if bytesWritten and length are the same?
  2256. return 0;
  2257. }}};
  2258. var ERRNO_MESSAGES={0:"Success",1:"Arg list too long",2:"Permission denied",3:"Address already in use",4:"Address not available",5:"Address family not supported by protocol family",6:"No more processes",7:"Socket already connected",8:"Bad file number",9:"Trying to read unreadable message",10:"Mount device busy",11:"Operation canceled",12:"No children",13:"Connection aborted",14:"Connection refused",15:"Connection reset by peer",16:"File locking deadlock error",17:"Destination address required",18:"Math arg out of domain of func",19:"Quota exceeded",20:"File exists",21:"Bad address",22:"File too large",23:"Host is unreachable",24:"Identifier removed",25:"Illegal byte sequence",26:"Connection already in progress",27:"Interrupted system call",28:"Invalid argument",29:"I/O error",30:"Socket is already connected",31:"Is a directory",32:"Too many symbolic links",33:"Too many open files",34:"Too many links",35:"Message too long",36:"Multihop attempted",37:"File or path name too long",38:"Network interface is not configured",39:"Connection reset by network",40:"Network is unreachable",41:"Too many open files in system",42:"No buffer space available",43:"No such device",44:"No such file or directory",45:"Exec format error",46:"No record locks available",47:"The link has been severed",48:"Not enough core",49:"No message of desired type",50:"Protocol not available",51:"No space left on device",52:"Function not implemented",53:"Socket is not connected",54:"Not a directory",55:"Directory not empty",56:"State not recoverable",57:"Socket operation on non-socket",59:"Not a typewriter",60:"No such device or address",61:"Value too large for defined data type",62:"Previous owner died",63:"Not super-user",64:"Broken pipe",65:"Protocol error",66:"Unknown protocol",67:"Protocol wrong type for socket",68:"Math result not representable",69:"Read only file system",70:"Illegal seek",71:"No such process",72:"Stale file handle",73:"Connection timed out",74:"Text file busy",75:"Cross-device link",100:"Device not a stream",101:"Bad font file fmt",102:"Invalid slot",103:"Invalid request code",104:"No anode",105:"Block device required",106:"Channel number out of range",107:"Level 3 halted",108:"Level 3 reset",109:"Link number out of range",110:"Protocol driver not attached",111:"No CSI structure available",112:"Level 2 halted",113:"Invalid exchange",114:"Invalid request descriptor",115:"Exchange full",116:"No data (for no delay io)",117:"Timer expired",118:"Out of streams resources",119:"Machine is not on the network",120:"Package not installed",121:"The object is remote",122:"Advertise error",123:"Srmount error",124:"Communication error on send",125:"Cross mount point (not really error)",126:"Given log. name not unique",127:"f.d. invalid for this operation",128:"Remote address changed",129:"Can access a needed shared lib",130:"Accessing a corrupted shared lib",131:".lib section in a.out corrupted",132:"Attempting to link in too many libs",133:"Attempting to exec a shared library",135:"Streams pipe error",136:"Too many users",137:"Socket type not supported",138:"Not supported",139:"Protocol family not supported",140:"Can't send after socket shutdown",141:"Too many references",142:"Host is down",148:"No medium (in tape drive)",156:"Level 2 not synchronized"};
  2259. var ERRNO_CODES={EPERM:63,ENOENT:44,ESRCH:71,EINTR:27,EIO:29,ENXIO:60,E2BIG:1,ENOEXEC:45,EBADF:8,ECHILD:12,EAGAIN:6,EWOULDBLOCK:6,ENOMEM:48,EACCES:2,EFAULT:21,ENOTBLK:105,EBUSY:10,EEXIST:20,EXDEV:75,ENODEV:43,ENOTDIR:54,EISDIR:31,EINVAL:28,ENFILE:41,EMFILE:33,ENOTTY:59,ETXTBSY:74,EFBIG:22,ENOSPC:51,ESPIPE:70,EROFS:69,EMLINK:34,EPIPE:64,EDOM:18,ERANGE:68,ENOMSG:49,EIDRM:24,ECHRNG:106,EL2NSYNC:156,EL3HLT:107,EL3RST:108,ELNRNG:109,EUNATCH:110,ENOCSI:111,EL2HLT:112,EDEADLK:16,ENOLCK:46,EBADE:113,EBADR:114,EXFULL:115,ENOANO:104,EBADRQC:103,EBADSLT:102,EDEADLOCK:16,EBFONT:101,ENOSTR:100,ENODATA:116,ETIME:117,ENOSR:118,ENONET:119,ENOPKG:120,EREMOTE:121,ENOLINK:47,EADV:122,ESRMNT:123,ECOMM:124,EPROTO:65,EMULTIHOP:36,EDOTDOT:125,EBADMSG:9,ENOTUNIQ:126,EBADFD:127,EREMCHG:128,ELIBACC:129,ELIBBAD:130,ELIBSCN:131,ELIBMAX:132,ELIBEXEC:133,ENOSYS:52,ENOTEMPTY:55,ENAMETOOLONG:37,ELOOP:32,EOPNOTSUPP:138,EPFNOSUPPORT:139,ECONNRESET:15,ENOBUFS:42,EAFNOSUPPORT:5,EPROTOTYPE:67,ENOTSOCK:57,ENOPROTOOPT:50,ESHUTDOWN:140,ECONNREFUSED:14,EADDRINUSE:3,ECONNABORTED:13,ENETUNREACH:40,ENETDOWN:38,ETIMEDOUT:73,EHOSTDOWN:142,EHOSTUNREACH:23,EINPROGRESS:26,EALREADY:7,EDESTADDRREQ:17,EMSGSIZE:35,EPROTONOSUPPORT:66,ESOCKTNOSUPPORT:137,EADDRNOTAVAIL:4,ENETRESET:39,EISCONN:30,ENOTCONN:53,ETOOMANYREFS:141,EUSERS:136,EDQUOT:19,ESTALE:72,ENOTSUP:138,ENOMEDIUM:148,EILSEQ:25,EOVERFLOW:61,ECANCELED:11,ENOTRECOVERABLE:56,EOWNERDEAD:62,ESTRPIPE:135};var FS={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:null,currentPath:"/",initialized:false,ignorePermissions:true,trackingDelegate:{},tracking:{openFlags:{READ:1,WRITE:2}},ErrnoError:null,genericErrors:{},filesystems:null,syncFSRequests:0,handleFSError:function(e) {
  2260. if (!(e instanceof FS.ErrnoError)) throw e + ' : ' + stackTrace();
  2261. return ___setErrNo(e.errno);
  2262. },lookupPath:function(path, opts) {
  2263. path = PATH_FS.resolve(FS.cwd(), path);
  2264. opts = opts || {};
  2265. if (!path) return { path: '', node: null };
  2266. var defaults = {
  2267. follow_mount: true,
  2268. recurse_count: 0
  2269. };
  2270. for (var key in defaults) {
  2271. if (opts[key] === undefined) {
  2272. opts[key] = defaults[key];
  2273. }
  2274. }
  2275. if (opts.recurse_count > 8) { // max recursive lookup of 8
  2276. throw new FS.ErrnoError(32);
  2277. }
  2278. // split the path
  2279. var parts = PATH.normalizeArray(path.split('/').filter(function(p) {
  2280. return !!p;
  2281. }), false);
  2282. // start at the root
  2283. var current = FS.root;
  2284. var current_path = '/';
  2285. for (var i = 0; i < parts.length; i++) {
  2286. var islast = (i === parts.length-1);
  2287. if (islast && opts.parent) {
  2288. // stop resolving
  2289. break;
  2290. }
  2291. current = FS.lookupNode(current, parts[i]);
  2292. current_path = PATH.join2(current_path, parts[i]);
  2293. // jump to the mount's root node if this is a mountpoint
  2294. if (FS.isMountpoint(current)) {
  2295. if (!islast || (islast && opts.follow_mount)) {
  2296. current = current.mounted.root;
  2297. }
  2298. }
  2299. // by default, lookupPath will not follow a symlink if it is the final path component.
  2300. // setting opts.follow = true will override this behavior.
  2301. if (!islast || opts.follow) {
  2302. var count = 0;
  2303. while (FS.isLink(current.mode)) {
  2304. var link = FS.readlink(current_path);
  2305. current_path = PATH_FS.resolve(PATH.dirname(current_path), link);
  2306. var lookup = FS.lookupPath(current_path, { recurse_count: opts.recurse_count });
  2307. current = lookup.node;
  2308. if (count++ > 40) { // limit max consecutive symlinks to 40 (SYMLOOP_MAX).
  2309. throw new FS.ErrnoError(32);
  2310. }
  2311. }
  2312. }
  2313. }
  2314. return { path: current_path, node: current };
  2315. },getPath:function(node) {
  2316. var path;
  2317. while (true) {
  2318. if (FS.isRoot(node)) {
  2319. var mount = node.mount.mountpoint;
  2320. if (!path) return mount;
  2321. return mount[mount.length-1] !== '/' ? mount + '/' + path : mount + path;
  2322. }
  2323. path = path ? node.name + '/' + path : node.name;
  2324. node = node.parent;
  2325. }
  2326. },hashName:function(parentid, name) {
  2327. var hash = 0;
  2328. for (var i = 0; i < name.length; i++) {
  2329. hash = ((hash << 5) - hash + name.charCodeAt(i)) | 0;
  2330. }
  2331. return ((parentid + hash) >>> 0) % FS.nameTable.length;
  2332. },hashAddNode:function(node) {
  2333. var hash = FS.hashName(node.parent.id, node.name);
  2334. node.name_next = FS.nameTable[hash];
  2335. FS.nameTable[hash] = node;
  2336. },hashRemoveNode:function(node) {
  2337. var hash = FS.hashName(node.parent.id, node.name);
  2338. if (FS.nameTable[hash] === node) {
  2339. FS.nameTable[hash] = node.name_next;
  2340. } else {
  2341. var current = FS.nameTable[hash];
  2342. while (current) {
  2343. if (current.name_next === node) {
  2344. current.name_next = node.name_next;
  2345. break;
  2346. }
  2347. current = current.name_next;
  2348. }
  2349. }
  2350. },lookupNode:function(parent, name) {
  2351. var errCode = FS.mayLookup(parent);
  2352. if (errCode) {
  2353. throw new FS.ErrnoError(errCode, parent);
  2354. }
  2355. var hash = FS.hashName(parent.id, name);
  2356. for (var node = FS.nameTable[hash]; node; node = node.name_next) {
  2357. var nodeName = node.name;
  2358. if (node.parent.id === parent.id && nodeName === name) {
  2359. return node;
  2360. }
  2361. }
  2362. // if we failed to find it in the cache, call into the VFS
  2363. return FS.lookup(parent, name);
  2364. },createNode:function(parent, name, mode, rdev) {
  2365. var node = new FS.FSNode(parent, name, mode, rdev);
  2366. FS.hashAddNode(node);
  2367. return node;
  2368. },destroyNode:function(node) {
  2369. FS.hashRemoveNode(node);
  2370. },isRoot:function(node) {
  2371. return node === node.parent;
  2372. },isMountpoint:function(node) {
  2373. return !!node.mounted;
  2374. },isFile:function(mode) {
  2375. return (mode & 61440) === 32768;
  2376. },isDir:function(mode) {
  2377. return (mode & 61440) === 16384;
  2378. },isLink:function(mode) {
  2379. return (mode & 61440) === 40960;
  2380. },isChrdev:function(mode) {
  2381. return (mode & 61440) === 8192;
  2382. },isBlkdev:function(mode) {
  2383. return (mode & 61440) === 24576;
  2384. },isFIFO:function(mode) {
  2385. return (mode & 61440) === 4096;
  2386. },isSocket:function(mode) {
  2387. return (mode & 49152) === 49152;
  2388. },flagModes:{"r":0,"rs":1052672,"r+":2,"w":577,"wx":705,"xw":705,"w+":578,"wx+":706,"xw+":706,"a":1089,"ax":1217,"xa":1217,"a+":1090,"ax+":1218,"xa+":1218},modeStringToFlags:function(str) {
  2389. var flags = FS.flagModes[str];
  2390. if (typeof flags === 'undefined') {
  2391. throw new Error('Unknown file open mode: ' + str);
  2392. }
  2393. return flags;
  2394. },flagsToPermissionString:function(flag) {
  2395. var perms = ['r', 'w', 'rw'][flag & 3];
  2396. if ((flag & 512)) {
  2397. perms += 'w';
  2398. }
  2399. return perms;
  2400. },nodePermissions:function(node, perms) {
  2401. if (FS.ignorePermissions) {
  2402. return 0;
  2403. }
  2404. // return 0 if any user, group or owner bits are set.
  2405. if (perms.indexOf('r') !== -1 && !(node.mode & 292)) {
  2406. return 2;
  2407. } else if (perms.indexOf('w') !== -1 && !(node.mode & 146)) {
  2408. return 2;
  2409. } else if (perms.indexOf('x') !== -1 && !(node.mode & 73)) {
  2410. return 2;
  2411. }
  2412. return 0;
  2413. },mayLookup:function(dir) {
  2414. var errCode = FS.nodePermissions(dir, 'x');
  2415. if (errCode) return errCode;
  2416. if (!dir.node_ops.lookup) return 2;
  2417. return 0;
  2418. },mayCreate:function(dir, name) {
  2419. try {
  2420. var node = FS.lookupNode(dir, name);
  2421. return 20;
  2422. } catch (e) {
  2423. }
  2424. return FS.nodePermissions(dir, 'wx');
  2425. },mayDelete:function(dir, name, isdir) {
  2426. var node;
  2427. try {
  2428. node = FS.lookupNode(dir, name);
  2429. } catch (e) {
  2430. return e.errno;
  2431. }
  2432. var errCode = FS.nodePermissions(dir, 'wx');
  2433. if (errCode) {
  2434. return errCode;
  2435. }
  2436. if (isdir) {
  2437. if (!FS.isDir(node.mode)) {
  2438. return 54;
  2439. }
  2440. if (FS.isRoot(node) || FS.getPath(node) === FS.cwd()) {
  2441. return 10;
  2442. }
  2443. } else {
  2444. if (FS.isDir(node.mode)) {
  2445. return 31;
  2446. }
  2447. }
  2448. return 0;
  2449. },mayOpen:function(node, flags) {
  2450. if (!node) {
  2451. return 44;
  2452. }
  2453. if (FS.isLink(node.mode)) {
  2454. return 32;
  2455. } else if (FS.isDir(node.mode)) {
  2456. if (FS.flagsToPermissionString(flags) !== 'r' || // opening for write
  2457. (flags & 512)) { // TODO: check for O_SEARCH? (== search for dir only)
  2458. return 31;
  2459. }
  2460. }
  2461. return FS.nodePermissions(node, FS.flagsToPermissionString(flags));
  2462. },MAX_OPEN_FDS:4096,nextfd:function(fd_start, fd_end) {
  2463. fd_start = fd_start || 0;
  2464. fd_end = fd_end || FS.MAX_OPEN_FDS;
  2465. for (var fd = fd_start; fd <= fd_end; fd++) {
  2466. if (!FS.streams[fd]) {
  2467. return fd;
  2468. }
  2469. }
  2470. throw new FS.ErrnoError(33);
  2471. },getStream:function(fd) {
  2472. return FS.streams[fd];
  2473. },createStream:function(stream, fd_start, fd_end) {
  2474. if (!FS.FSStream) {
  2475. FS.FSStream = /** @constructor */ function(){};
  2476. FS.FSStream.prototype = {
  2477. object: {
  2478. get: function() { return this.node; },
  2479. set: function(val) { this.node = val; }
  2480. },
  2481. isRead: {
  2482. get: function() { return (this.flags & 2097155) !== 1; }
  2483. },
  2484. isWrite: {
  2485. get: function() { return (this.flags & 2097155) !== 0; }
  2486. },
  2487. isAppend: {
  2488. get: function() { return (this.flags & 1024); }
  2489. }
  2490. };
  2491. }
  2492. // clone it, so we can return an instance of FSStream
  2493. var newStream = new FS.FSStream();
  2494. for (var p in stream) {
  2495. newStream[p] = stream[p];
  2496. }
  2497. stream = newStream;
  2498. var fd = FS.nextfd(fd_start, fd_end);
  2499. stream.fd = fd;
  2500. FS.streams[fd] = stream;
  2501. return stream;
  2502. },closeStream:function(fd) {
  2503. FS.streams[fd] = null;
  2504. },chrdev_stream_ops:{open:function(stream) {
  2505. var device = FS.getDevice(stream.node.rdev);
  2506. // override node's stream ops with the device's
  2507. stream.stream_ops = device.stream_ops;
  2508. // forward the open call
  2509. if (stream.stream_ops.open) {
  2510. stream.stream_ops.open(stream);
  2511. }
  2512. },llseek:function() {
  2513. throw new FS.ErrnoError(70);
  2514. }},major:function(dev) {
  2515. return ((dev) >> 8);
  2516. },minor:function(dev) {
  2517. return ((dev) & 0xff);
  2518. },makedev:function(ma, mi) {
  2519. return ((ma) << 8 | (mi));
  2520. },registerDevice:function(dev, ops) {
  2521. FS.devices[dev] = { stream_ops: ops };
  2522. },getDevice:function(dev) {
  2523. return FS.devices[dev];
  2524. },getMounts:function(mount) {
  2525. var mounts = [];
  2526. var check = [mount];
  2527. while (check.length) {
  2528. var m = check.pop();
  2529. mounts.push(m);
  2530. check.push.apply(check, m.mounts);
  2531. }
  2532. return mounts;
  2533. },syncfs:function(populate, callback) {
  2534. if (typeof(populate) === 'function') {
  2535. callback = populate;
  2536. populate = false;
  2537. }
  2538. FS.syncFSRequests++;
  2539. if (FS.syncFSRequests > 1) {
  2540. err('warning: ' + FS.syncFSRequests + ' FS.syncfs operations in flight at once, probably just doing extra work');
  2541. }
  2542. var mounts = FS.getMounts(FS.root.mount);
  2543. var completed = 0;
  2544. function doCallback(errCode) {
  2545. assert(FS.syncFSRequests > 0);
  2546. FS.syncFSRequests--;
  2547. return callback(errCode);
  2548. }
  2549. function done(errCode) {
  2550. if (errCode) {
  2551. if (!done.errored) {
  2552. done.errored = true;
  2553. return doCallback(errCode);
  2554. }
  2555. return;
  2556. }
  2557. if (++completed >= mounts.length) {
  2558. doCallback(null);
  2559. }
  2560. };
  2561. // sync all mounts
  2562. mounts.forEach(function (mount) {
  2563. if (!mount.type.syncfs) {
  2564. return done(null);
  2565. }
  2566. mount.type.syncfs(mount, populate, done);
  2567. });
  2568. },mount:function(type, opts, mountpoint) {
  2569. if (typeof type === 'string') {
  2570. // The filesystem was not included, and instead we have an error
  2571. // message stored in the variable.
  2572. throw type;
  2573. }
  2574. var root = mountpoint === '/';
  2575. var pseudo = !mountpoint;
  2576. var node;
  2577. if (root && FS.root) {
  2578. throw new FS.ErrnoError(10);
  2579. } else if (!root && !pseudo) {
  2580. var lookup = FS.lookupPath(mountpoint, { follow_mount: false });
  2581. mountpoint = lookup.path; // use the absolute path
  2582. node = lookup.node;
  2583. if (FS.isMountpoint(node)) {
  2584. throw new FS.ErrnoError(10);
  2585. }
  2586. if (!FS.isDir(node.mode)) {
  2587. throw new FS.ErrnoError(54);
  2588. }
  2589. }
  2590. var mount = {
  2591. type: type,
  2592. opts: opts,
  2593. mountpoint: mountpoint,
  2594. mounts: []
  2595. };
  2596. // create a root node for the fs
  2597. var mountRoot = type.mount(mount);
  2598. mountRoot.mount = mount;
  2599. mount.root = mountRoot;
  2600. if (root) {
  2601. FS.root = mountRoot;
  2602. } else if (node) {
  2603. // set as a mountpoint
  2604. node.mounted = mount;
  2605. // add the new mount to the current mount's children
  2606. if (node.mount) {
  2607. node.mount.mounts.push(mount);
  2608. }
  2609. }
  2610. return mountRoot;
  2611. },unmount:function (mountpoint) {
  2612. var lookup = FS.lookupPath(mountpoint, { follow_mount: false });
  2613. if (!FS.isMountpoint(lookup.node)) {
  2614. throw new FS.ErrnoError(28);
  2615. }
  2616. // destroy the nodes for this mount, and all its child mounts
  2617. var node = lookup.node;
  2618. var mount = node.mounted;
  2619. var mounts = FS.getMounts(mount);
  2620. Object.keys(FS.nameTable).forEach(function (hash) {
  2621. var current = FS.nameTable[hash];
  2622. while (current) {
  2623. var next = current.name_next;
  2624. if (mounts.indexOf(current.mount) !== -1) {
  2625. FS.destroyNode(current);
  2626. }
  2627. current = next;
  2628. }
  2629. });
  2630. // no longer a mountpoint
  2631. node.mounted = null;
  2632. // remove this mount from the child mounts
  2633. var idx = node.mount.mounts.indexOf(mount);
  2634. assert(idx !== -1);
  2635. node.mount.mounts.splice(idx, 1);
  2636. },lookup:function(parent, name) {
  2637. return parent.node_ops.lookup(parent, name);
  2638. },mknod:function(path, mode, dev) {
  2639. var lookup = FS.lookupPath(path, { parent: true });
  2640. var parent = lookup.node;
  2641. var name = PATH.basename(path);
  2642. if (!name || name === '.' || name === '..') {
  2643. throw new FS.ErrnoError(28);
  2644. }
  2645. var errCode = FS.mayCreate(parent, name);
  2646. if (errCode) {
  2647. throw new FS.ErrnoError(errCode);
  2648. }
  2649. if (!parent.node_ops.mknod) {
  2650. throw new FS.ErrnoError(63);
  2651. }
  2652. return parent.node_ops.mknod(parent, name, mode, dev);
  2653. },create:function(path, mode) {
  2654. mode = mode !== undefined ? mode : 438 /* 0666 */;
  2655. mode &= 4095;
  2656. mode |= 32768;
  2657. return FS.mknod(path, mode, 0);
  2658. },mkdir:function(path, mode) {
  2659. mode = mode !== undefined ? mode : 511 /* 0777 */;
  2660. mode &= 511 | 512;
  2661. mode |= 16384;
  2662. return FS.mknod(path, mode, 0);
  2663. },mkdirTree:function(path, mode) {
  2664. var dirs = path.split('/');
  2665. var d = '';
  2666. for (var i = 0; i < dirs.length; ++i) {
  2667. if (!dirs[i]) continue;
  2668. d += '/' + dirs[i];
  2669. try {
  2670. FS.mkdir(d, mode);
  2671. } catch(e) {
  2672. if (e.errno != 20) throw e;
  2673. }
  2674. }
  2675. },mkdev:function(path, mode, dev) {
  2676. if (typeof(dev) === 'undefined') {
  2677. dev = mode;
  2678. mode = 438 /* 0666 */;
  2679. }
  2680. mode |= 8192;
  2681. return FS.mknod(path, mode, dev);
  2682. },symlink:function(oldpath, newpath) {
  2683. if (!PATH_FS.resolve(oldpath)) {
  2684. throw new FS.ErrnoError(44);
  2685. }
  2686. var lookup = FS.lookupPath(newpath, { parent: true });
  2687. var parent = lookup.node;
  2688. if (!parent) {
  2689. throw new FS.ErrnoError(44);
  2690. }
  2691. var newname = PATH.basename(newpath);
  2692. var errCode = FS.mayCreate(parent, newname);
  2693. if (errCode) {
  2694. throw new FS.ErrnoError(errCode);
  2695. }
  2696. if (!parent.node_ops.symlink) {
  2697. throw new FS.ErrnoError(63);
  2698. }
  2699. return parent.node_ops.symlink(parent, newname, oldpath);
  2700. },rename:function(old_path, new_path) {
  2701. var old_dirname = PATH.dirname(old_path);
  2702. var new_dirname = PATH.dirname(new_path);
  2703. var old_name = PATH.basename(old_path);
  2704. var new_name = PATH.basename(new_path);
  2705. // parents must exist
  2706. var lookup, old_dir, new_dir;
  2707. try {
  2708. lookup = FS.lookupPath(old_path, { parent: true });
  2709. old_dir = lookup.node;
  2710. lookup = FS.lookupPath(new_path, { parent: true });
  2711. new_dir = lookup.node;
  2712. } catch (e) {
  2713. throw new FS.ErrnoError(10);
  2714. }
  2715. if (!old_dir || !new_dir) throw new FS.ErrnoError(44);
  2716. // need to be part of the same mount
  2717. if (old_dir.mount !== new_dir.mount) {
  2718. throw new FS.ErrnoError(75);
  2719. }
  2720. // source must exist
  2721. var old_node = FS.lookupNode(old_dir, old_name);
  2722. // old path should not be an ancestor of the new path
  2723. var relative = PATH_FS.relative(old_path, new_dirname);
  2724. if (relative.charAt(0) !== '.') {
  2725. throw new FS.ErrnoError(28);
  2726. }
  2727. // new path should not be an ancestor of the old path
  2728. relative = PATH_FS.relative(new_path, old_dirname);
  2729. if (relative.charAt(0) !== '.') {
  2730. throw new FS.ErrnoError(55);
  2731. }
  2732. // see if the new path already exists
  2733. var new_node;
  2734. try {
  2735. new_node = FS.lookupNode(new_dir, new_name);
  2736. } catch (e) {
  2737. // not fatal
  2738. }
  2739. // early out if nothing needs to change
  2740. if (old_node === new_node) {
  2741. return;
  2742. }
  2743. // we'll need to delete the old entry
  2744. var isdir = FS.isDir(old_node.mode);
  2745. var errCode = FS.mayDelete(old_dir, old_name, isdir);
  2746. if (errCode) {
  2747. throw new FS.ErrnoError(errCode);
  2748. }
  2749. // need delete permissions if we'll be overwriting.
  2750. // need create permissions if new doesn't already exist.
  2751. errCode = new_node ?
  2752. FS.mayDelete(new_dir, new_name, isdir) :
  2753. FS.mayCreate(new_dir, new_name);
  2754. if (errCode) {
  2755. throw new FS.ErrnoError(errCode);
  2756. }
  2757. if (!old_dir.node_ops.rename) {
  2758. throw new FS.ErrnoError(63);
  2759. }
  2760. if (FS.isMountpoint(old_node) || (new_node && FS.isMountpoint(new_node))) {
  2761. throw new FS.ErrnoError(10);
  2762. }
  2763. // if we are going to change the parent, check write permissions
  2764. if (new_dir !== old_dir) {
  2765. errCode = FS.nodePermissions(old_dir, 'w');
  2766. if (errCode) {
  2767. throw new FS.ErrnoError(errCode);
  2768. }
  2769. }
  2770. try {
  2771. if (FS.trackingDelegate['willMovePath']) {
  2772. FS.trackingDelegate['willMovePath'](old_path, new_path);
  2773. }
  2774. } catch(e) {
  2775. err("FS.trackingDelegate['willMovePath']('"+old_path+"', '"+new_path+"') threw an exception: " + e.message);
  2776. }
  2777. // remove the node from the lookup hash
  2778. FS.hashRemoveNode(old_node);
  2779. // do the underlying fs rename
  2780. try {
  2781. old_dir.node_ops.rename(old_node, new_dir, new_name);
  2782. } catch (e) {
  2783. throw e;
  2784. } finally {
  2785. // add the node back to the hash (in case node_ops.rename
  2786. // changed its name)
  2787. FS.hashAddNode(old_node);
  2788. }
  2789. try {
  2790. if (FS.trackingDelegate['onMovePath']) FS.trackingDelegate['onMovePath'](old_path, new_path);
  2791. } catch(e) {
  2792. err("FS.trackingDelegate['onMovePath']('"+old_path+"', '"+new_path+"') threw an exception: " + e.message);
  2793. }
  2794. },rmdir:function(path) {
  2795. var lookup = FS.lookupPath(path, { parent: true });
  2796. var parent = lookup.node;
  2797. var name = PATH.basename(path);
  2798. var node = FS.lookupNode(parent, name);
  2799. var errCode = FS.mayDelete(parent, name, true);
  2800. if (errCode) {
  2801. throw new FS.ErrnoError(errCode);
  2802. }
  2803. if (!parent.node_ops.rmdir) {
  2804. throw new FS.ErrnoError(63);
  2805. }
  2806. if (FS.isMountpoint(node)) {
  2807. throw new FS.ErrnoError(10);
  2808. }
  2809. try {
  2810. if (FS.trackingDelegate['willDeletePath']) {
  2811. FS.trackingDelegate['willDeletePath'](path);
  2812. }
  2813. } catch(e) {
  2814. err("FS.trackingDelegate['willDeletePath']('"+path+"') threw an exception: " + e.message);
  2815. }
  2816. parent.node_ops.rmdir(parent, name);
  2817. FS.destroyNode(node);
  2818. try {
  2819. if (FS.trackingDelegate['onDeletePath']) FS.trackingDelegate['onDeletePath'](path);
  2820. } catch(e) {
  2821. err("FS.trackingDelegate['onDeletePath']('"+path+"') threw an exception: " + e.message);
  2822. }
  2823. },readdir:function(path) {
  2824. var lookup = FS.lookupPath(path, { follow: true });
  2825. var node = lookup.node;
  2826. if (!node.node_ops.readdir) {
  2827. throw new FS.ErrnoError(54);
  2828. }
  2829. return node.node_ops.readdir(node);
  2830. },unlink:function(path) {
  2831. var lookup = FS.lookupPath(path, { parent: true });
  2832. var parent = lookup.node;
  2833. var name = PATH.basename(path);
  2834. var node = FS.lookupNode(parent, name);
  2835. var errCode = FS.mayDelete(parent, name, false);
  2836. if (errCode) {
  2837. // According to POSIX, we should map EISDIR to EPERM, but
  2838. // we instead do what Linux does (and we must, as we use
  2839. // the musl linux libc).
  2840. throw new FS.ErrnoError(errCode);
  2841. }
  2842. if (!parent.node_ops.unlink) {
  2843. throw new FS.ErrnoError(63);
  2844. }
  2845. if (FS.isMountpoint(node)) {
  2846. throw new FS.ErrnoError(10);
  2847. }
  2848. try {
  2849. if (FS.trackingDelegate['willDeletePath']) {
  2850. FS.trackingDelegate['willDeletePath'](path);
  2851. }
  2852. } catch(e) {
  2853. err("FS.trackingDelegate['willDeletePath']('"+path+"') threw an exception: " + e.message);
  2854. }
  2855. parent.node_ops.unlink(parent, name);
  2856. FS.destroyNode(node);
  2857. try {
  2858. if (FS.trackingDelegate['onDeletePath']) FS.trackingDelegate['onDeletePath'](path);
  2859. } catch(e) {
  2860. err("FS.trackingDelegate['onDeletePath']('"+path+"') threw an exception: " + e.message);
  2861. }
  2862. },readlink:function(path) {
  2863. var lookup = FS.lookupPath(path);
  2864. var link = lookup.node;
  2865. if (!link) {
  2866. throw new FS.ErrnoError(44);
  2867. }
  2868. if (!link.node_ops.readlink) {
  2869. throw new FS.ErrnoError(28);
  2870. }
  2871. return PATH_FS.resolve(FS.getPath(link.parent), link.node_ops.readlink(link));
  2872. },stat:function(path, dontFollow) {
  2873. var lookup = FS.lookupPath(path, { follow: !dontFollow });
  2874. var node = lookup.node;
  2875. if (!node) {
  2876. throw new FS.ErrnoError(44);
  2877. }
  2878. if (!node.node_ops.getattr) {
  2879. throw new FS.ErrnoError(63);
  2880. }
  2881. return node.node_ops.getattr(node);
  2882. },lstat:function(path) {
  2883. return FS.stat(path, true);
  2884. },chmod:function(path, mode, dontFollow) {
  2885. var node;
  2886. if (typeof path === 'string') {
  2887. var lookup = FS.lookupPath(path, { follow: !dontFollow });
  2888. node = lookup.node;
  2889. } else {
  2890. node = path;
  2891. }
  2892. if (!node.node_ops.setattr) {
  2893. throw new FS.ErrnoError(63);
  2894. }
  2895. node.node_ops.setattr(node, {
  2896. mode: (mode & 4095) | (node.mode & ~4095),
  2897. timestamp: Date.now()
  2898. });
  2899. },lchmod:function(path, mode) {
  2900. FS.chmod(path, mode, true);
  2901. },fchmod:function(fd, mode) {
  2902. var stream = FS.getStream(fd);
  2903. if (!stream) {
  2904. throw new FS.ErrnoError(8);
  2905. }
  2906. FS.chmod(stream.node, mode);
  2907. },chown:function(path, uid, gid, dontFollow) {
  2908. var node;
  2909. if (typeof path === 'string') {
  2910. var lookup = FS.lookupPath(path, { follow: !dontFollow });
  2911. node = lookup.node;
  2912. } else {
  2913. node = path;
  2914. }
  2915. if (!node.node_ops.setattr) {
  2916. throw new FS.ErrnoError(63);
  2917. }
  2918. node.node_ops.setattr(node, {
  2919. timestamp: Date.now()
  2920. // we ignore the uid / gid for now
  2921. });
  2922. },lchown:function(path, uid, gid) {
  2923. FS.chown(path, uid, gid, true);
  2924. },fchown:function(fd, uid, gid) {
  2925. var stream = FS.getStream(fd);
  2926. if (!stream) {
  2927. throw new FS.ErrnoError(8);
  2928. }
  2929. FS.chown(stream.node, uid, gid);
  2930. },truncate:function(path, len) {
  2931. if (len < 0) {
  2932. throw new FS.ErrnoError(28);
  2933. }
  2934. var node;
  2935. if (typeof path === 'string') {
  2936. var lookup = FS.lookupPath(path, { follow: true });
  2937. node = lookup.node;
  2938. } else {
  2939. node = path;
  2940. }
  2941. if (!node.node_ops.setattr) {
  2942. throw new FS.ErrnoError(63);
  2943. }
  2944. if (FS.isDir(node.mode)) {
  2945. throw new FS.ErrnoError(31);
  2946. }
  2947. if (!FS.isFile(node.mode)) {
  2948. throw new FS.ErrnoError(28);
  2949. }
  2950. var errCode = FS.nodePermissions(node, 'w');
  2951. if (errCode) {
  2952. throw new FS.ErrnoError(errCode);
  2953. }
  2954. node.node_ops.setattr(node, {
  2955. size: len,
  2956. timestamp: Date.now()
  2957. });
  2958. },ftruncate:function(fd, len) {
  2959. var stream = FS.getStream(fd);
  2960. if (!stream) {
  2961. throw new FS.ErrnoError(8);
  2962. }
  2963. if ((stream.flags & 2097155) === 0) {
  2964. throw new FS.ErrnoError(28);
  2965. }
  2966. FS.truncate(stream.node, len);
  2967. },utime:function(path, atime, mtime) {
  2968. var lookup = FS.lookupPath(path, { follow: true });
  2969. var node = lookup.node;
  2970. node.node_ops.setattr(node, {
  2971. timestamp: Math.max(atime, mtime)
  2972. });
  2973. },open:function(path, flags, mode, fd_start, fd_end) {
  2974. if (path === "") {
  2975. throw new FS.ErrnoError(44);
  2976. }
  2977. flags = typeof flags === 'string' ? FS.modeStringToFlags(flags) : flags;
  2978. mode = typeof mode === 'undefined' ? 438 /* 0666 */ : mode;
  2979. if ((flags & 64)) {
  2980. mode = (mode & 4095) | 32768;
  2981. } else {
  2982. mode = 0;
  2983. }
  2984. var node;
  2985. if (typeof path === 'object') {
  2986. node = path;
  2987. } else {
  2988. path = PATH.normalize(path);
  2989. try {
  2990. var lookup = FS.lookupPath(path, {
  2991. follow: !(flags & 131072)
  2992. });
  2993. node = lookup.node;
  2994. } catch (e) {
  2995. // ignore
  2996. }
  2997. }
  2998. // perhaps we need to create the node
  2999. var created = false;
  3000. if ((flags & 64)) {
  3001. if (node) {
  3002. // if O_CREAT and O_EXCL are set, error out if the node already exists
  3003. if ((flags & 128)) {
  3004. throw new FS.ErrnoError(20);
  3005. }
  3006. } else {
  3007. // node doesn't exist, try to create it
  3008. node = FS.mknod(path, mode, 0);
  3009. created = true;
  3010. }
  3011. }
  3012. if (!node) {
  3013. throw new FS.ErrnoError(44);
  3014. }
  3015. // can't truncate a device
  3016. if (FS.isChrdev(node.mode)) {
  3017. flags &= ~512;
  3018. }
  3019. // if asked only for a directory, then this must be one
  3020. if ((flags & 65536) && !FS.isDir(node.mode)) {
  3021. throw new FS.ErrnoError(54);
  3022. }
  3023. // check permissions, if this is not a file we just created now (it is ok to
  3024. // create and write to a file with read-only permissions; it is read-only
  3025. // for later use)
  3026. if (!created) {
  3027. var errCode = FS.mayOpen(node, flags);
  3028. if (errCode) {
  3029. throw new FS.ErrnoError(errCode);
  3030. }
  3031. }
  3032. // do truncation if necessary
  3033. if ((flags & 512)) {
  3034. FS.truncate(node, 0);
  3035. }
  3036. // we've already handled these, don't pass down to the underlying vfs
  3037. flags &= ~(128 | 512 | 131072);
  3038. // register the stream with the filesystem
  3039. var stream = FS.createStream({
  3040. node: node,
  3041. path: FS.getPath(node), // we want the absolute path to the node
  3042. flags: flags,
  3043. seekable: true,
  3044. position: 0,
  3045. stream_ops: node.stream_ops,
  3046. // used by the file family libc calls (fopen, fwrite, ferror, etc.)
  3047. ungotten: [],
  3048. error: false
  3049. }, fd_start, fd_end);
  3050. // call the new stream's open function
  3051. if (stream.stream_ops.open) {
  3052. stream.stream_ops.open(stream);
  3053. }
  3054. if (Module['logReadFiles'] && !(flags & 1)) {
  3055. if (!FS.readFiles) FS.readFiles = {};
  3056. if (!(path in FS.readFiles)) {
  3057. FS.readFiles[path] = 1;
  3058. err("FS.trackingDelegate error on read file: " + path);
  3059. }
  3060. }
  3061. try {
  3062. if (FS.trackingDelegate['onOpenFile']) {
  3063. var trackingFlags = 0;
  3064. if ((flags & 2097155) !== 1) {
  3065. trackingFlags |= FS.tracking.openFlags.READ;
  3066. }
  3067. if ((flags & 2097155) !== 0) {
  3068. trackingFlags |= FS.tracking.openFlags.WRITE;
  3069. }
  3070. FS.trackingDelegate['onOpenFile'](path, trackingFlags);
  3071. }
  3072. } catch(e) {
  3073. err("FS.trackingDelegate['onOpenFile']('"+path+"', flags) threw an exception: " + e.message);
  3074. }
  3075. return stream;
  3076. },close:function(stream) {
  3077. if (FS.isClosed(stream)) {
  3078. throw new FS.ErrnoError(8);
  3079. }
  3080. if (stream.getdents) stream.getdents = null; // free readdir state
  3081. try {
  3082. if (stream.stream_ops.close) {
  3083. stream.stream_ops.close(stream);
  3084. }
  3085. } catch (e) {
  3086. throw e;
  3087. } finally {
  3088. FS.closeStream(stream.fd);
  3089. }
  3090. stream.fd = null;
  3091. },isClosed:function(stream) {
  3092. return stream.fd === null;
  3093. },llseek:function(stream, offset, whence) {
  3094. if (FS.isClosed(stream)) {
  3095. throw new FS.ErrnoError(8);
  3096. }
  3097. if (!stream.seekable || !stream.stream_ops.llseek) {
  3098. throw new FS.ErrnoError(70);
  3099. }
  3100. if (whence != 0 && whence != 1 && whence != 2) {
  3101. throw new FS.ErrnoError(28);
  3102. }
  3103. stream.position = stream.stream_ops.llseek(stream, offset, whence);
  3104. stream.ungotten = [];
  3105. return stream.position;
  3106. },read:function(stream, buffer, offset, length, position) {
  3107. if (length < 0 || position < 0) {
  3108. throw new FS.ErrnoError(28);
  3109. }
  3110. if (FS.isClosed(stream)) {
  3111. throw new FS.ErrnoError(8);
  3112. }
  3113. if ((stream.flags & 2097155) === 1) {
  3114. throw new FS.ErrnoError(8);
  3115. }
  3116. if (FS.isDir(stream.node.mode)) {
  3117. throw new FS.ErrnoError(31);
  3118. }
  3119. if (!stream.stream_ops.read) {
  3120. throw new FS.ErrnoError(28);
  3121. }
  3122. var seeking = typeof position !== 'undefined';
  3123. if (!seeking) {
  3124. position = stream.position;
  3125. } else if (!stream.seekable) {
  3126. throw new FS.ErrnoError(70);
  3127. }
  3128. var bytesRead = stream.stream_ops.read(stream, buffer, offset, length, position);
  3129. if (!seeking) stream.position += bytesRead;
  3130. return bytesRead;
  3131. },write:function(stream, buffer, offset, length, position, canOwn) {
  3132. if (length < 0 || position < 0) {
  3133. throw new FS.ErrnoError(28);
  3134. }
  3135. if (FS.isClosed(stream)) {
  3136. throw new FS.ErrnoError(8);
  3137. }
  3138. if ((stream.flags & 2097155) === 0) {
  3139. throw new FS.ErrnoError(8);
  3140. }
  3141. if (FS.isDir(stream.node.mode)) {
  3142. throw new FS.ErrnoError(31);
  3143. }
  3144. if (!stream.stream_ops.write) {
  3145. throw new FS.ErrnoError(28);
  3146. }
  3147. if (stream.seekable && stream.flags & 1024) {
  3148. // seek to the end before writing in append mode
  3149. FS.llseek(stream, 0, 2);
  3150. }
  3151. var seeking = typeof position !== 'undefined';
  3152. if (!seeking) {
  3153. position = stream.position;
  3154. } else if (!stream.seekable) {
  3155. throw new FS.ErrnoError(70);
  3156. }
  3157. var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
  3158. if (!seeking) stream.position += bytesWritten;
  3159. try {
  3160. if (stream.path && FS.trackingDelegate['onWriteToFile']) FS.trackingDelegate['onWriteToFile'](stream.path);
  3161. } catch(e) {
  3162. err("FS.trackingDelegate['onWriteToFile']('"+stream.path+"') threw an exception: " + e.message);
  3163. }
  3164. return bytesWritten;
  3165. },allocate:function(stream, offset, length) {
  3166. if (FS.isClosed(stream)) {
  3167. throw new FS.ErrnoError(8);
  3168. }
  3169. if (offset < 0 || length <= 0) {
  3170. throw new FS.ErrnoError(28);
  3171. }
  3172. if ((stream.flags & 2097155) === 0) {
  3173. throw new FS.ErrnoError(8);
  3174. }
  3175. if (!FS.isFile(stream.node.mode) && !FS.isDir(stream.node.mode)) {
  3176. throw new FS.ErrnoError(43);
  3177. }
  3178. if (!stream.stream_ops.allocate) {
  3179. throw new FS.ErrnoError(138);
  3180. }
  3181. stream.stream_ops.allocate(stream, offset, length);
  3182. },mmap:function(stream, buffer, offset, length, position, prot, flags) {
  3183. // User requests writing to file (prot & PROT_WRITE != 0).
  3184. // Checking if we have permissions to write to the file unless
  3185. // MAP_PRIVATE flag is set. According to POSIX spec it is possible
  3186. // to write to file opened in read-only mode with MAP_PRIVATE flag,
  3187. // as all modifications will be visible only in the memory of
  3188. // the current process.
  3189. if ((prot & 2) !== 0
  3190. && (flags & 2) === 0
  3191. && (stream.flags & 2097155) !== 2) {
  3192. throw new FS.ErrnoError(2);
  3193. }
  3194. if ((stream.flags & 2097155) === 1) {
  3195. throw new FS.ErrnoError(2);
  3196. }
  3197. if (!stream.stream_ops.mmap) {
  3198. throw new FS.ErrnoError(43);
  3199. }
  3200. return stream.stream_ops.mmap(stream, buffer, offset, length, position, prot, flags);
  3201. },msync:function(stream, buffer, offset, length, mmapFlags) {
  3202. if (!stream || !stream.stream_ops.msync) {
  3203. return 0;
  3204. }
  3205. return stream.stream_ops.msync(stream, buffer, offset, length, mmapFlags);
  3206. },munmap:function(stream) {
  3207. return 0;
  3208. },ioctl:function(stream, cmd, arg) {
  3209. if (!stream.stream_ops.ioctl) {
  3210. throw new FS.ErrnoError(59);
  3211. }
  3212. return stream.stream_ops.ioctl(stream, cmd, arg);
  3213. },readFile:function(path, opts) {
  3214. opts = opts || {};
  3215. opts.flags = opts.flags || 'r';
  3216. opts.encoding = opts.encoding || 'binary';
  3217. if (opts.encoding !== 'utf8' && opts.encoding !== 'binary') {
  3218. throw new Error('Invalid encoding type "' + opts.encoding + '"');
  3219. }
  3220. var ret;
  3221. var stream = FS.open(path, opts.flags);
  3222. var stat = FS.stat(path);
  3223. var length = stat.size;
  3224. var buf = new Uint8Array(length);
  3225. FS.read(stream, buf, 0, length, 0);
  3226. if (opts.encoding === 'utf8') {
  3227. ret = UTF8ArrayToString(buf, 0);
  3228. } else if (opts.encoding === 'binary') {
  3229. ret = buf;
  3230. }
  3231. FS.close(stream);
  3232. return ret;
  3233. },writeFile:function(path, data, opts) {
  3234. opts = opts || {};
  3235. opts.flags = opts.flags || 'w';
  3236. var stream = FS.open(path, opts.flags, opts.mode);
  3237. if (typeof data === 'string') {
  3238. var buf = new Uint8Array(lengthBytesUTF8(data)+1);
  3239. var actualNumBytes = stringToUTF8Array(data, buf, 0, buf.length);
  3240. FS.write(stream, buf, 0, actualNumBytes, undefined, opts.canOwn);
  3241. } else if (ArrayBuffer.isView(data)) {
  3242. FS.write(stream, data, 0, data.byteLength, undefined, opts.canOwn);
  3243. } else {
  3244. throw new Error('Unsupported data type');
  3245. }
  3246. FS.close(stream);
  3247. },cwd:function() {
  3248. return FS.currentPath;
  3249. },chdir:function(path) {
  3250. var lookup = FS.lookupPath(path, { follow: true });
  3251. if (lookup.node === null) {
  3252. throw new FS.ErrnoError(44);
  3253. }
  3254. if (!FS.isDir(lookup.node.mode)) {
  3255. throw new FS.ErrnoError(54);
  3256. }
  3257. var errCode = FS.nodePermissions(lookup.node, 'x');
  3258. if (errCode) {
  3259. throw new FS.ErrnoError(errCode);
  3260. }
  3261. FS.currentPath = lookup.path;
  3262. },createDefaultDirectories:function() {
  3263. FS.mkdir('/tmp');
  3264. FS.mkdir('/home');
  3265. FS.mkdir('/home/web_user');
  3266. },createDefaultDevices:function() {
  3267. // create /dev
  3268. FS.mkdir('/dev');
  3269. // setup /dev/null
  3270. FS.registerDevice(FS.makedev(1, 3), {
  3271. read: function() { return 0; },
  3272. write: function(stream, buffer, offset, length, pos) { return length; }
  3273. });
  3274. FS.mkdev('/dev/null', FS.makedev(1, 3));
  3275. // setup /dev/tty and /dev/tty1
  3276. // stderr needs to print output using Module['printErr']
  3277. // so we register a second tty just for it.
  3278. TTY.register(FS.makedev(5, 0), TTY.default_tty_ops);
  3279. TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops);
  3280. FS.mkdev('/dev/tty', FS.makedev(5, 0));
  3281. FS.mkdev('/dev/tty1', FS.makedev(6, 0));
  3282. // setup /dev/[u]random
  3283. var random_device;
  3284. if (typeof crypto === 'object' && typeof crypto['getRandomValues'] === 'function') {
  3285. // for modern web browsers
  3286. var randomBuffer = new Uint8Array(1);
  3287. random_device = function() { crypto.getRandomValues(randomBuffer); return randomBuffer[0]; };
  3288. } else
  3289. if (ENVIRONMENT_IS_NODE) {
  3290. // for nodejs with or without crypto support included
  3291. try {
  3292. var crypto_module = require('crypto');
  3293. // nodejs has crypto support
  3294. random_device = function() { return crypto_module['randomBytes'](1)[0]; };
  3295. } catch (e) {
  3296. // nodejs doesn't have crypto support
  3297. }
  3298. } else
  3299. {}
  3300. if (!random_device) {
  3301. // we couldn't find a proper implementation, as Math.random() is not suitable for /dev/random, see emscripten-core/emscripten/pull/7096
  3302. random_device = function() { abort("no cryptographic support found for random_device. consider polyfilling it if you want to use something insecure like Math.random(), e.g. put this in a --pre-js: var crypto = { getRandomValues: function(array) { for (var i = 0; i < array.length; i++) array[i] = (Math.random()*256)|0 } };"); };
  3303. }
  3304. FS.createDevice('/dev', 'random', random_device);
  3305. FS.createDevice('/dev', 'urandom', random_device);
  3306. // we're not going to emulate the actual shm device,
  3307. // just create the tmp dirs that reside in it commonly
  3308. FS.mkdir('/dev/shm');
  3309. FS.mkdir('/dev/shm/tmp');
  3310. },createSpecialDirectories:function() {
  3311. // create /proc/self/fd which allows /proc/self/fd/6 => readlink gives the name of the stream for fd 6 (see test_unistd_ttyname)
  3312. FS.mkdir('/proc');
  3313. FS.mkdir('/proc/self');
  3314. FS.mkdir('/proc/self/fd');
  3315. FS.mount({
  3316. mount: function() {
  3317. var node = FS.createNode('/proc/self', 'fd', 16384 | 511 /* 0777 */, 73);
  3318. node.node_ops = {
  3319. lookup: function(parent, name) {
  3320. var fd = +name;
  3321. var stream = FS.getStream(fd);
  3322. if (!stream) throw new FS.ErrnoError(8);
  3323. var ret = {
  3324. parent: null,
  3325. mount: { mountpoint: 'fake' },
  3326. node_ops: { readlink: function() { return stream.path } }
  3327. };
  3328. ret.parent = ret; // make it look like a simple root node
  3329. return ret;
  3330. }
  3331. };
  3332. return node;
  3333. }
  3334. }, {}, '/proc/self/fd');
  3335. },createStandardStreams:function() {
  3336. // TODO deprecate the old functionality of a single
  3337. // input / output callback and that utilizes FS.createDevice
  3338. // and instead require a unique set of stream ops
  3339. // by default, we symlink the standard streams to the
  3340. // default tty devices. however, if the standard streams
  3341. // have been overwritten we create a unique device for
  3342. // them instead.
  3343. if (Module['stdin']) {
  3344. FS.createDevice('/dev', 'stdin', Module['stdin']);
  3345. } else {
  3346. FS.symlink('/dev/tty', '/dev/stdin');
  3347. }
  3348. if (Module['stdout']) {
  3349. FS.createDevice('/dev', 'stdout', null, Module['stdout']);
  3350. } else {
  3351. FS.symlink('/dev/tty', '/dev/stdout');
  3352. }
  3353. if (Module['stderr']) {
  3354. FS.createDevice('/dev', 'stderr', null, Module['stderr']);
  3355. } else {
  3356. FS.symlink('/dev/tty1', '/dev/stderr');
  3357. }
  3358. // open default streams for the stdin, stdout and stderr devices
  3359. var stdin = FS.open('/dev/stdin', 'r');
  3360. var stdout = FS.open('/dev/stdout', 'w');
  3361. var stderr = FS.open('/dev/stderr', 'w');
  3362. assert(stdin.fd === 0, 'invalid handle for stdin (' + stdin.fd + ')');
  3363. assert(stdout.fd === 1, 'invalid handle for stdout (' + stdout.fd + ')');
  3364. assert(stderr.fd === 2, 'invalid handle for stderr (' + stderr.fd + ')');
  3365. },ensureErrnoError:function() {
  3366. if (FS.ErrnoError) return;
  3367. FS.ErrnoError = /** @this{Object} */ function ErrnoError(errno, node) {
  3368. this.node = node;
  3369. this.setErrno = /** @this{Object} */ function(errno) {
  3370. this.errno = errno;
  3371. for (var key in ERRNO_CODES) {
  3372. if (ERRNO_CODES[key] === errno) {
  3373. this.code = key;
  3374. break;
  3375. }
  3376. }
  3377. };
  3378. this.setErrno(errno);
  3379. this.message = ERRNO_MESSAGES[errno];
  3380. // Try to get a maximally helpful stack trace. On Node.js, getting Error.stack
  3381. // now ensures it shows what we want.
  3382. if (this.stack) {
  3383. // Define the stack property for Node.js 4, which otherwise errors on the next line.
  3384. Object.defineProperty(this, "stack", { value: (new Error).stack, writable: true });
  3385. this.stack = demangleAll(this.stack);
  3386. }
  3387. };
  3388. FS.ErrnoError.prototype = new Error();
  3389. FS.ErrnoError.prototype.constructor = FS.ErrnoError;
  3390. // Some errors may happen quite a bit, to avoid overhead we reuse them (and suffer a lack of stack info)
  3391. [44].forEach(function(code) {
  3392. FS.genericErrors[code] = new FS.ErrnoError(code);
  3393. FS.genericErrors[code].stack = '<generic error, no stack>';
  3394. });
  3395. },staticInit:function() {
  3396. FS.ensureErrnoError();
  3397. FS.nameTable = new Array(4096);
  3398. FS.mount(MEMFS, {}, '/');
  3399. FS.createDefaultDirectories();
  3400. FS.createDefaultDevices();
  3401. FS.createSpecialDirectories();
  3402. FS.filesystems = {
  3403. 'MEMFS': MEMFS,
  3404. };
  3405. },init:function(input, output, error) {
  3406. 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)');
  3407. FS.init.initialized = true;
  3408. FS.ensureErrnoError();
  3409. // Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
  3410. Module['stdin'] = input || Module['stdin'];
  3411. Module['stdout'] = output || Module['stdout'];
  3412. Module['stderr'] = error || Module['stderr'];
  3413. FS.createStandardStreams();
  3414. },quit:function() {
  3415. FS.init.initialized = false;
  3416. // force-flush all streams, so we get musl std streams printed out
  3417. var fflush = Module['_fflush'];
  3418. if (fflush) fflush(0);
  3419. // close all of our streams
  3420. for (var i = 0; i < FS.streams.length; i++) {
  3421. var stream = FS.streams[i];
  3422. if (!stream) {
  3423. continue;
  3424. }
  3425. FS.close(stream);
  3426. }
  3427. },getMode:function(canRead, canWrite) {
  3428. var mode = 0;
  3429. if (canRead) mode |= 292 | 73;
  3430. if (canWrite) mode |= 146;
  3431. return mode;
  3432. },joinPath:function(parts, forceRelative) {
  3433. var path = PATH.join.apply(null, parts);
  3434. if (forceRelative && path[0] == '/') path = path.substr(1);
  3435. return path;
  3436. },absolutePath:function(relative, base) {
  3437. return PATH_FS.resolve(base, relative);
  3438. },standardizePath:function(path) {
  3439. return PATH.normalize(path);
  3440. },findObject:function(path, dontResolveLastLink) {
  3441. var ret = FS.analyzePath(path, dontResolveLastLink);
  3442. if (ret.exists) {
  3443. return ret.object;
  3444. } else {
  3445. ___setErrNo(ret.error);
  3446. return null;
  3447. }
  3448. },analyzePath:function(path, dontResolveLastLink) {
  3449. // operate from within the context of the symlink's target
  3450. try {
  3451. var lookup = FS.lookupPath(path, { follow: !dontResolveLastLink });
  3452. path = lookup.path;
  3453. } catch (e) {
  3454. }
  3455. var ret = {
  3456. isRoot: false, exists: false, error: 0, name: null, path: null, object: null,
  3457. parentExists: false, parentPath: null, parentObject: null
  3458. };
  3459. try {
  3460. var lookup = FS.lookupPath(path, { parent: true });
  3461. ret.parentExists = true;
  3462. ret.parentPath = lookup.path;
  3463. ret.parentObject = lookup.node;
  3464. ret.name = PATH.basename(path);
  3465. lookup = FS.lookupPath(path, { follow: !dontResolveLastLink });
  3466. ret.exists = true;
  3467. ret.path = lookup.path;
  3468. ret.object = lookup.node;
  3469. ret.name = lookup.node.name;
  3470. ret.isRoot = lookup.path === '/';
  3471. } catch (e) {
  3472. ret.error = e.errno;
  3473. };
  3474. return ret;
  3475. },createFolder:function(parent, name, canRead, canWrite) {
  3476. var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
  3477. var mode = FS.getMode(canRead, canWrite);
  3478. return FS.mkdir(path, mode);
  3479. },createPath:function(parent, path, canRead, canWrite) {
  3480. parent = typeof parent === 'string' ? parent : FS.getPath(parent);
  3481. var parts = path.split('/').reverse();
  3482. while (parts.length) {
  3483. var part = parts.pop();
  3484. if (!part) continue;
  3485. var current = PATH.join2(parent, part);
  3486. try {
  3487. FS.mkdir(current);
  3488. } catch (e) {
  3489. // ignore EEXIST
  3490. }
  3491. parent = current;
  3492. }
  3493. return current;
  3494. },createFile:function(parent, name, properties, canRead, canWrite) {
  3495. var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
  3496. var mode = FS.getMode(canRead, canWrite);
  3497. return FS.create(path, mode);
  3498. },createDataFile:function(parent, name, data, canRead, canWrite, canOwn) {
  3499. var path = name ? PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name) : parent;
  3500. var mode = FS.getMode(canRead, canWrite);
  3501. var node = FS.create(path, mode);
  3502. if (data) {
  3503. if (typeof data === 'string') {
  3504. var arr = new Array(data.length);
  3505. for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
  3506. data = arr;
  3507. }
  3508. // make sure we can write to the file
  3509. FS.chmod(node, mode | 146);
  3510. var stream = FS.open(node, 'w');
  3511. FS.write(stream, data, 0, data.length, 0, canOwn);
  3512. FS.close(stream);
  3513. FS.chmod(node, mode);
  3514. }
  3515. return node;
  3516. },createDevice:function(parent, name, input, output) {
  3517. var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
  3518. var mode = FS.getMode(!!input, !!output);
  3519. if (!FS.createDevice.major) FS.createDevice.major = 64;
  3520. var dev = FS.makedev(FS.createDevice.major++, 0);
  3521. // Create a fake device that a set of stream ops to emulate
  3522. // the old behavior.
  3523. FS.registerDevice(dev, {
  3524. open: function(stream) {
  3525. stream.seekable = false;
  3526. },
  3527. close: function(stream) {
  3528. // flush any pending line data
  3529. if (output && output.buffer && output.buffer.length) {
  3530. output(10);
  3531. }
  3532. },
  3533. read: function(stream, buffer, offset, length, pos /* ignored */) {
  3534. var bytesRead = 0;
  3535. for (var i = 0; i < length; i++) {
  3536. var result;
  3537. try {
  3538. result = input();
  3539. } catch (e) {
  3540. throw new FS.ErrnoError(29);
  3541. }
  3542. if (result === undefined && bytesRead === 0) {
  3543. throw new FS.ErrnoError(6);
  3544. }
  3545. if (result === null || result === undefined) break;
  3546. bytesRead++;
  3547. buffer[offset+i] = result;
  3548. }
  3549. if (bytesRead) {
  3550. stream.node.timestamp = Date.now();
  3551. }
  3552. return bytesRead;
  3553. },
  3554. write: function(stream, buffer, offset, length, pos) {
  3555. for (var i = 0; i < length; i++) {
  3556. try {
  3557. output(buffer[offset+i]);
  3558. } catch (e) {
  3559. throw new FS.ErrnoError(29);
  3560. }
  3561. }
  3562. if (length) {
  3563. stream.node.timestamp = Date.now();
  3564. }
  3565. return i;
  3566. }
  3567. });
  3568. return FS.mkdev(path, mode, dev);
  3569. },createLink:function(parent, name, target, canRead, canWrite) {
  3570. var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
  3571. return FS.symlink(target, path);
  3572. },forceLoadFile:function(obj) {
  3573. if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true;
  3574. var success = true;
  3575. if (typeof XMLHttpRequest !== 'undefined') {
  3576. 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.");
  3577. } else if (read_) {
  3578. // Command-line.
  3579. try {
  3580. // WARNING: Can't read binary files in V8's d8 or tracemonkey's js, as
  3581. // read() will try to parse UTF8.
  3582. obj.contents = intArrayFromString(read_(obj.url), true);
  3583. obj.usedBytes = obj.contents.length;
  3584. } catch (e) {
  3585. success = false;
  3586. }
  3587. } else {
  3588. throw new Error('Cannot load without read() or XMLHttpRequest.');
  3589. }
  3590. if (!success) ___setErrNo(29);
  3591. return success;
  3592. },createLazyFile:function(parent, name, url, canRead, canWrite) {
  3593. // Lazy chunked Uint8Array (implements get and length from Uint8Array). Actual getting is abstracted away for eventual reuse.
  3594. /** @constructor */
  3595. function LazyUint8Array() {
  3596. this.lengthKnown = false;
  3597. this.chunks = []; // Loaded chunks. Index is the chunk number
  3598. }
  3599. LazyUint8Array.prototype.get = /** @this{Object} */ function LazyUint8Array_get(idx) {
  3600. if (idx > this.length-1 || idx < 0) {
  3601. return undefined;
  3602. }
  3603. var chunkOffset = idx % this.chunkSize;
  3604. var chunkNum = (idx / this.chunkSize)|0;
  3605. return this.getter(chunkNum)[chunkOffset];
  3606. };
  3607. LazyUint8Array.prototype.setDataGetter = function LazyUint8Array_setDataGetter(getter) {
  3608. this.getter = getter;
  3609. };
  3610. LazyUint8Array.prototype.cacheLength = function LazyUint8Array_cacheLength() {
  3611. // Find length
  3612. var xhr = new XMLHttpRequest();
  3613. xhr.open('HEAD', url, false);
  3614. xhr.send(null);
  3615. if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
  3616. var datalength = Number(xhr.getResponseHeader("Content-length"));
  3617. var header;
  3618. var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
  3619. var usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip";
  3620. var chunkSize = 1024*1024; // Chunk size in bytes
  3621. if (!hasByteServing) chunkSize = datalength;
  3622. // Function to get a range from the remote URL.
  3623. var doXHR = (function(from, to) {
  3624. if (from > to) throw new Error("invalid range (" + from + ", " + to + ") or no bytes requested!");
  3625. if (to > datalength-1) throw new Error("only " + datalength + " bytes available! programmer error!");
  3626. // TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
  3627. var xhr = new XMLHttpRequest();
  3628. xhr.open('GET', url, false);
  3629. if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
  3630. // Some hints to the browser that we want binary data.
  3631. if (typeof Uint8Array != 'undefined') xhr.responseType = 'arraybuffer';
  3632. if (xhr.overrideMimeType) {
  3633. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  3634. }
  3635. xhr.send(null);
  3636. if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
  3637. if (xhr.response !== undefined) {
  3638. return new Uint8Array(/** @type{Array<number>} */(xhr.response || []));
  3639. } else {
  3640. return intArrayFromString(xhr.responseText || '', true);
  3641. }
  3642. });
  3643. var lazyArray = this;
  3644. lazyArray.setDataGetter(function(chunkNum) {
  3645. var start = chunkNum * chunkSize;
  3646. var end = (chunkNum+1) * chunkSize - 1; // including this byte
  3647. end = Math.min(end, datalength-1); // if datalength-1 is selected, this is the last block
  3648. if (typeof(lazyArray.chunks[chunkNum]) === "undefined") {
  3649. lazyArray.chunks[chunkNum] = doXHR(start, end);
  3650. }
  3651. if (typeof(lazyArray.chunks[chunkNum]) === "undefined") throw new Error("doXHR failed!");
  3652. return lazyArray.chunks[chunkNum];
  3653. });
  3654. if (usesGzip || !datalength) {
  3655. // if the server uses gzip or doesn't supply the length, we have to download the whole file to get the (uncompressed) length
  3656. chunkSize = datalength = 1; // this will force getter(0)/doXHR do download the whole file
  3657. datalength = this.getter(0).length;
  3658. chunkSize = datalength;
  3659. out("LazyFiles on gzip forces download of the whole file when length is accessed");
  3660. }
  3661. this._length = datalength;
  3662. this._chunkSize = chunkSize;
  3663. this.lengthKnown = true;
  3664. };
  3665. if (typeof XMLHttpRequest !== 'undefined') {
  3666. if (!ENVIRONMENT_IS_WORKER) throw 'Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc';
  3667. var lazyArray = new LazyUint8Array();
  3668. Object.defineProperties(lazyArray, {
  3669. length: {
  3670. get: /** @this{Object} */ function() {
  3671. if(!this.lengthKnown) {
  3672. this.cacheLength();
  3673. }
  3674. return this._length;
  3675. }
  3676. },
  3677. chunkSize: {
  3678. get: /** @this{Object} */ function() {
  3679. if(!this.lengthKnown) {
  3680. this.cacheLength();
  3681. }
  3682. return this._chunkSize;
  3683. }
  3684. }
  3685. });
  3686. var properties = { isDevice: false, contents: lazyArray };
  3687. } else {
  3688. var properties = { isDevice: false, url: url };
  3689. }
  3690. var node = FS.createFile(parent, name, properties, canRead, canWrite);
  3691. // This is a total hack, but I want to get this lazy file code out of the
  3692. // core of MEMFS. If we want to keep this lazy file concept I feel it should
  3693. // be its own thin LAZYFS proxying calls to MEMFS.
  3694. if (properties.contents) {
  3695. node.contents = properties.contents;
  3696. } else if (properties.url) {
  3697. node.contents = null;
  3698. node.url = properties.url;
  3699. }
  3700. // Add a function that defers querying the file size until it is asked the first time.
  3701. Object.defineProperties(node, {
  3702. usedBytes: {
  3703. get: /** @this {FSNode} */ function() { return this.contents.length; }
  3704. }
  3705. });
  3706. // override each stream op with one that tries to force load the lazy file first
  3707. var stream_ops = {};
  3708. var keys = Object.keys(node.stream_ops);
  3709. keys.forEach(function(key) {
  3710. var fn = node.stream_ops[key];
  3711. stream_ops[key] = function forceLoadLazyFile() {
  3712. if (!FS.forceLoadFile(node)) {
  3713. throw new FS.ErrnoError(29);
  3714. }
  3715. return fn.apply(null, arguments);
  3716. };
  3717. });
  3718. // use a custom read function
  3719. stream_ops.read = function stream_ops_read(stream, buffer, offset, length, position) {
  3720. if (!FS.forceLoadFile(node)) {
  3721. throw new FS.ErrnoError(29);
  3722. }
  3723. var contents = stream.node.contents;
  3724. if (position >= contents.length)
  3725. return 0;
  3726. var size = Math.min(contents.length - position, length);
  3727. assert(size >= 0);
  3728. if (contents.slice) { // normal array
  3729. for (var i = 0; i < size; i++) {
  3730. buffer[offset + i] = contents[position + i];
  3731. }
  3732. } else {
  3733. for (var i = 0; i < size; i++) { // LazyUint8Array from sync binary XHR
  3734. buffer[offset + i] = contents.get(position + i);
  3735. }
  3736. }
  3737. return size;
  3738. };
  3739. node.stream_ops = stream_ops;
  3740. return node;
  3741. },createPreloadedFile:function(parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) {
  3742. Browser.init(); // XXX perhaps this method should move onto Browser?
  3743. // TODO we should allow people to just pass in a complete filename instead
  3744. // of parent and name being that we just join them anyways
  3745. var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
  3746. var dep = getUniqueRunDependency('cp ' + fullname); // might have several active requests for the same fullname
  3747. function processData(byteArray) {
  3748. function finish(byteArray) {
  3749. if (preFinish) preFinish();
  3750. if (!dontCreateFile) {
  3751. FS.createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
  3752. }
  3753. if (onload) onload();
  3754. removeRunDependency(dep);
  3755. }
  3756. var handled = false;
  3757. Module['preloadPlugins'].forEach(function(plugin) {
  3758. if (handled) return;
  3759. if (plugin['canHandle'](fullname)) {
  3760. plugin['handle'](byteArray, fullname, finish, function() {
  3761. if (onerror) onerror();
  3762. removeRunDependency(dep);
  3763. });
  3764. handled = true;
  3765. }
  3766. });
  3767. if (!handled) finish(byteArray);
  3768. }
  3769. addRunDependency(dep);
  3770. if (typeof url == 'string') {
  3771. Browser.asyncLoad(url, function(byteArray) {
  3772. processData(byteArray);
  3773. }, onerror);
  3774. } else {
  3775. processData(url);
  3776. }
  3777. },indexedDB:function() {
  3778. return window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
  3779. },DB_NAME:function() {
  3780. return 'EM_FS_' + window.location.pathname;
  3781. },DB_VERSION:20,DB_STORE_NAME:"FILE_DATA",saveFilesToDB:function(paths, onload, onerror) {
  3782. onload = onload || function(){};
  3783. onerror = onerror || function(){};
  3784. var indexedDB = FS.indexedDB();
  3785. try {
  3786. var openRequest = indexedDB.open(FS.DB_NAME(), FS.DB_VERSION);
  3787. } catch (e) {
  3788. return onerror(e);
  3789. }
  3790. openRequest.onupgradeneeded = function openRequest_onupgradeneeded() {
  3791. out('creating db');
  3792. var db = openRequest.result;
  3793. db.createObjectStore(FS.DB_STORE_NAME);
  3794. };
  3795. openRequest.onsuccess = function openRequest_onsuccess() {
  3796. var db = openRequest.result;
  3797. var transaction = db.transaction([FS.DB_STORE_NAME], 'readwrite');
  3798. var files = transaction.objectStore(FS.DB_STORE_NAME);
  3799. var ok = 0, fail = 0, total = paths.length;
  3800. function finish() {
  3801. if (fail == 0) onload(); else onerror();
  3802. }
  3803. paths.forEach(function(path) {
  3804. var putRequest = files.put(FS.analyzePath(path).object.contents, path);
  3805. putRequest.onsuccess = function putRequest_onsuccess() { ok++; if (ok + fail == total) finish() };
  3806. putRequest.onerror = function putRequest_onerror() { fail++; if (ok + fail == total) finish() };
  3807. });
  3808. transaction.onerror = onerror;
  3809. };
  3810. openRequest.onerror = onerror;
  3811. },loadFilesFromDB:function(paths, onload, onerror) {
  3812. onload = onload || function(){};
  3813. onerror = onerror || function(){};
  3814. var indexedDB = FS.indexedDB();
  3815. try {
  3816. var openRequest = indexedDB.open(FS.DB_NAME(), FS.DB_VERSION);
  3817. } catch (e) {
  3818. return onerror(e);
  3819. }
  3820. openRequest.onupgradeneeded = onerror; // no database to load from
  3821. openRequest.onsuccess = function openRequest_onsuccess() {
  3822. var db = openRequest.result;
  3823. try {
  3824. var transaction = db.transaction([FS.DB_STORE_NAME], 'readonly');
  3825. } catch(e) {
  3826. onerror(e);
  3827. return;
  3828. }
  3829. var files = transaction.objectStore(FS.DB_STORE_NAME);
  3830. var ok = 0, fail = 0, total = paths.length;
  3831. function finish() {
  3832. if (fail == 0) onload(); else onerror();
  3833. }
  3834. paths.forEach(function(path) {
  3835. var getRequest = files.get(path);
  3836. getRequest.onsuccess = function getRequest_onsuccess() {
  3837. if (FS.analyzePath(path).exists) {
  3838. FS.unlink(path);
  3839. }
  3840. FS.createDataFile(PATH.dirname(path), PATH.basename(path), getRequest.result, true, true, true);
  3841. ok++;
  3842. if (ok + fail == total) finish();
  3843. };
  3844. getRequest.onerror = function getRequest_onerror() { fail++; if (ok + fail == total) finish() };
  3845. });
  3846. transaction.onerror = onerror;
  3847. };
  3848. openRequest.onerror = onerror;
  3849. }};var SYSCALLS={mappings:{},DEFAULT_POLLMASK:5,umask:511,calculateAt:function(dirfd, path) {
  3850. if (path[0] !== '/') {
  3851. // relative path
  3852. var dir;
  3853. if (dirfd === -100) {
  3854. dir = FS.cwd();
  3855. } else {
  3856. var dirstream = FS.getStream(dirfd);
  3857. if (!dirstream) throw new FS.ErrnoError(8);
  3858. dir = dirstream.path;
  3859. }
  3860. path = PATH.join2(dir, path);
  3861. }
  3862. return path;
  3863. },doStat:function(func, path, buf) {
  3864. try {
  3865. var stat = func(path);
  3866. } catch (e) {
  3867. if (e && e.node && PATH.normalize(path) !== PATH.normalize(FS.getPath(e.node))) {
  3868. // an error occurred while trying to look up the path; we should just report ENOTDIR
  3869. return -54;
  3870. }
  3871. throw e;
  3872. }
  3873. HEAP32[((buf)>>2)]=stat.dev;
  3874. HEAP32[(((buf)+(4))>>2)]=0;
  3875. HEAP32[(((buf)+(8))>>2)]=stat.ino;
  3876. HEAP32[(((buf)+(12))>>2)]=stat.mode;
  3877. HEAP32[(((buf)+(16))>>2)]=stat.nlink;
  3878. HEAP32[(((buf)+(20))>>2)]=stat.uid;
  3879. HEAP32[(((buf)+(24))>>2)]=stat.gid;
  3880. HEAP32[(((buf)+(28))>>2)]=stat.rdev;
  3881. HEAP32[(((buf)+(32))>>2)]=0;
  3882. (tempI64 = [stat.size>>>0,(tempDouble=stat.size,(+(Math_abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math_min((+(Math_floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[(((buf)+(40))>>2)]=tempI64[0],HEAP32[(((buf)+(44))>>2)]=tempI64[1]);
  3883. HEAP32[(((buf)+(48))>>2)]=4096;
  3884. HEAP32[(((buf)+(52))>>2)]=stat.blocks;
  3885. HEAP32[(((buf)+(56))>>2)]=(stat.atime.getTime() / 1000)|0;
  3886. HEAP32[(((buf)+(60))>>2)]=0;
  3887. HEAP32[(((buf)+(64))>>2)]=(stat.mtime.getTime() / 1000)|0;
  3888. HEAP32[(((buf)+(68))>>2)]=0;
  3889. HEAP32[(((buf)+(72))>>2)]=(stat.ctime.getTime() / 1000)|0;
  3890. HEAP32[(((buf)+(76))>>2)]=0;
  3891. (tempI64 = [stat.ino>>>0,(tempDouble=stat.ino,(+(Math_abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math_min((+(Math_floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[(((buf)+(80))>>2)]=tempI64[0],HEAP32[(((buf)+(84))>>2)]=tempI64[1]);
  3892. return 0;
  3893. },doMsync:function(addr, stream, len, flags, offset) {
  3894. var buffer = HEAPU8.slice(addr, addr + len);
  3895. FS.msync(stream, buffer, offset, len, flags);
  3896. },doMkdir:function(path, mode) {
  3897. // remove a trailing slash, if one - /a/b/ has basename of '', but
  3898. // we want to create b in the context of this function
  3899. path = PATH.normalize(path);
  3900. if (path[path.length-1] === '/') path = path.substr(0, path.length-1);
  3901. FS.mkdir(path, mode, 0);
  3902. return 0;
  3903. },doMknod:function(path, mode, dev) {
  3904. // we don't want this in the JS API as it uses mknod to create all nodes.
  3905. switch (mode & 61440) {
  3906. case 32768:
  3907. case 8192:
  3908. case 24576:
  3909. case 4096:
  3910. case 49152:
  3911. break;
  3912. default: return -28;
  3913. }
  3914. FS.mknod(path, mode, dev);
  3915. return 0;
  3916. },doReadlink:function(path, buf, bufsize) {
  3917. if (bufsize <= 0) return -28;
  3918. var ret = FS.readlink(path);
  3919. var len = Math.min(bufsize, lengthBytesUTF8(ret));
  3920. var endChar = HEAP8[buf+len];
  3921. stringToUTF8(ret, buf, bufsize+1);
  3922. // readlink is one of the rare functions that write out a C string, but does never append a null to the output buffer(!)
  3923. // stringToUTF8() always appends a null byte, so restore the character under the null byte after the write.
  3924. HEAP8[buf+len] = endChar;
  3925. return len;
  3926. },doAccess:function(path, amode) {
  3927. if (amode & ~7) {
  3928. // need a valid mode
  3929. return -28;
  3930. }
  3931. var node;
  3932. var lookup = FS.lookupPath(path, { follow: true });
  3933. node = lookup.node;
  3934. if (!node) {
  3935. return -44;
  3936. }
  3937. var perms = '';
  3938. if (amode & 4) perms += 'r';
  3939. if (amode & 2) perms += 'w';
  3940. if (amode & 1) perms += 'x';
  3941. if (perms /* otherwise, they've just passed F_OK */ && FS.nodePermissions(node, perms)) {
  3942. return -2;
  3943. }
  3944. return 0;
  3945. },doDup:function(path, flags, suggestFD) {
  3946. var suggest = FS.getStream(suggestFD);
  3947. if (suggest) FS.close(suggest);
  3948. return FS.open(path, flags, 0, suggestFD, suggestFD).fd;
  3949. },doReadv:function(stream, iov, iovcnt, offset) {
  3950. var ret = 0;
  3951. for (var i = 0; i < iovcnt; i++) {
  3952. var ptr = HEAP32[(((iov)+(i*8))>>2)];
  3953. var len = HEAP32[(((iov)+(i*8 + 4))>>2)];
  3954. var curr = FS.read(stream, HEAP8,ptr, len, offset);
  3955. if (curr < 0) return -1;
  3956. ret += curr;
  3957. if (curr < len) break; // nothing more to read
  3958. }
  3959. return ret;
  3960. },doWritev:function(stream, iov, iovcnt, offset) {
  3961. var ret = 0;
  3962. for (var i = 0; i < iovcnt; i++) {
  3963. var ptr = HEAP32[(((iov)+(i*8))>>2)];
  3964. var len = HEAP32[(((iov)+(i*8 + 4))>>2)];
  3965. var curr = FS.write(stream, HEAP8,ptr, len, offset);
  3966. if (curr < 0) return -1;
  3967. ret += curr;
  3968. }
  3969. return ret;
  3970. },varargs:undefined,get:function() {
  3971. assert(SYSCALLS.varargs != undefined);
  3972. SYSCALLS.varargs += 4;
  3973. var ret = HEAP32[(((SYSCALLS.varargs)-(4))>>2)];
  3974. return ret;
  3975. },getStr:function(ptr) {
  3976. var ret = UTF8ToString(ptr);
  3977. return ret;
  3978. },getStreamFromFD:function(fd) {
  3979. var stream = FS.getStream(fd);
  3980. if (!stream) throw new FS.ErrnoError(8);
  3981. return stream;
  3982. },get64:function(low, high) {
  3983. if (low >= 0) assert(high === 0);
  3984. else assert(high === -1);
  3985. return low;
  3986. }};function syscallMunmap(addr, len) {
  3987. if ((addr | 0) === -1 || len === 0) {
  3988. return -28;
  3989. }
  3990. // TODO: support unmmap'ing parts of allocations
  3991. var info = SYSCALLS.mappings[addr];
  3992. if (!info) return 0;
  3993. if (len === info.len) {
  3994. var stream = FS.getStream(info.fd);
  3995. if (info.prot & 2) {
  3996. SYSCALLS.doMsync(addr, stream, len, info.flags, info.offset);
  3997. }
  3998. FS.munmap(stream);
  3999. SYSCALLS.mappings[addr] = null;
  4000. if (info.allocated) {
  4001. _free(info.malloc);
  4002. }
  4003. }
  4004. return 0;
  4005. }function ___sys_munmap(addr, len) {try {
  4006. return syscallMunmap(addr, len);
  4007. } catch (e) {
  4008. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  4009. return -e.errno;
  4010. }
  4011. }
  4012. function getShiftFromSize(size) {
  4013. switch (size) {
  4014. case 1: return 0;
  4015. case 2: return 1;
  4016. case 4: return 2;
  4017. case 8: return 3;
  4018. default:
  4019. throw new TypeError('Unknown type size: ' + size);
  4020. }
  4021. }
  4022. function embind_init_charCodes() {
  4023. var codes = new Array(256);
  4024. for (var i = 0; i < 256; ++i) {
  4025. codes[i] = String.fromCharCode(i);
  4026. }
  4027. embind_charCodes = codes;
  4028. }var embind_charCodes=undefined;function readLatin1String(ptr) {
  4029. var ret = "";
  4030. var c = ptr;
  4031. while (HEAPU8[c]) {
  4032. ret += embind_charCodes[HEAPU8[c++]];
  4033. }
  4034. return ret;
  4035. }
  4036. var awaitingDependencies={};
  4037. var registeredTypes={};
  4038. var typeDependencies={};
  4039. var char_0=48;
  4040. var char_9=57;function makeLegalFunctionName(name) {
  4041. if (undefined === name) {
  4042. return '_unknown';
  4043. }
  4044. name = name.replace(/[^a-zA-Z0-9_]/g, '$');
  4045. var f = name.charCodeAt(0);
  4046. if (f >= char_0 && f <= char_9) {
  4047. return '_' + name;
  4048. } else {
  4049. return name;
  4050. }
  4051. }function createNamedFunction(name, body) {
  4052. name = makeLegalFunctionName(name);
  4053. /*jshint evil:true*/
  4054. return new Function(
  4055. "body",
  4056. "return function " + name + "() {\n" +
  4057. " \"use strict\";" +
  4058. " return body.apply(this, arguments);\n" +
  4059. "};\n"
  4060. )(body);
  4061. }function extendError(baseErrorType, errorName) {
  4062. var errorClass = createNamedFunction(errorName, function(message) {
  4063. this.name = errorName;
  4064. this.message = message;
  4065. var stack = (new Error(message)).stack;
  4066. if (stack !== undefined) {
  4067. this.stack = this.toString() + '\n' +
  4068. stack.replace(/^Error(:[^\n]*)?\n/, '');
  4069. }
  4070. });
  4071. errorClass.prototype = Object.create(baseErrorType.prototype);
  4072. errorClass.prototype.constructor = errorClass;
  4073. errorClass.prototype.toString = function() {
  4074. if (this.message === undefined) {
  4075. return this.name;
  4076. } else {
  4077. return this.name + ': ' + this.message;
  4078. }
  4079. };
  4080. return errorClass;
  4081. }var BindingError=undefined;function throwBindingError(message) {
  4082. throw new BindingError(message);
  4083. }
  4084. var InternalError=undefined;function throwInternalError(message) {
  4085. throw new InternalError(message);
  4086. }function whenDependentTypesAreResolved(myTypes, dependentTypes, getTypeConverters) {
  4087. myTypes.forEach(function(type) {
  4088. typeDependencies[type] = dependentTypes;
  4089. });
  4090. function onComplete(typeConverters) {
  4091. var myTypeConverters = getTypeConverters(typeConverters);
  4092. if (myTypeConverters.length !== myTypes.length) {
  4093. throwInternalError('Mismatched type converter count');
  4094. }
  4095. for (var i = 0; i < myTypes.length; ++i) {
  4096. registerType(myTypes[i], myTypeConverters[i]);
  4097. }
  4098. }
  4099. var typeConverters = new Array(dependentTypes.length);
  4100. var unregisteredTypes = [];
  4101. var registered = 0;
  4102. dependentTypes.forEach(function(dt, i) {
  4103. if (registeredTypes.hasOwnProperty(dt)) {
  4104. typeConverters[i] = registeredTypes[dt];
  4105. } else {
  4106. unregisteredTypes.push(dt);
  4107. if (!awaitingDependencies.hasOwnProperty(dt)) {
  4108. awaitingDependencies[dt] = [];
  4109. }
  4110. awaitingDependencies[dt].push(function() {
  4111. typeConverters[i] = registeredTypes[dt];
  4112. ++registered;
  4113. if (registered === unregisteredTypes.length) {
  4114. onComplete(typeConverters);
  4115. }
  4116. });
  4117. }
  4118. });
  4119. if (0 === unregisteredTypes.length) {
  4120. onComplete(typeConverters);
  4121. }
  4122. }/** @param {Object=} options */
  4123. function registerType(rawType, registeredInstance, options) {
  4124. options = options || {};
  4125. if (!('argPackAdvance' in registeredInstance)) {
  4126. throw new TypeError('registerType registeredInstance requires argPackAdvance');
  4127. }
  4128. var name = registeredInstance.name;
  4129. if (!rawType) {
  4130. throwBindingError('type "' + name + '" must have a positive integer typeid pointer');
  4131. }
  4132. if (registeredTypes.hasOwnProperty(rawType)) {
  4133. if (options.ignoreDuplicateRegistrations) {
  4134. return;
  4135. } else {
  4136. throwBindingError("Cannot register type '" + name + "' twice");
  4137. }
  4138. }
  4139. registeredTypes[rawType] = registeredInstance;
  4140. delete typeDependencies[rawType];
  4141. if (awaitingDependencies.hasOwnProperty(rawType)) {
  4142. var callbacks = awaitingDependencies[rawType];
  4143. delete awaitingDependencies[rawType];
  4144. callbacks.forEach(function(cb) {
  4145. cb();
  4146. });
  4147. }
  4148. }function __embind_register_bool(rawType, name, size, trueValue, falseValue) {
  4149. var shift = getShiftFromSize(size);
  4150. name = readLatin1String(name);
  4151. registerType(rawType, {
  4152. name: name,
  4153. 'fromWireType': function(wt) {
  4154. // ambiguous emscripten ABI: sometimes return values are
  4155. // true or false, and sometimes integers (0 or 1)
  4156. return !!wt;
  4157. },
  4158. 'toWireType': function(destructors, o) {
  4159. return o ? trueValue : falseValue;
  4160. },
  4161. 'argPackAdvance': 8,
  4162. 'readValueFromPointer': function(pointer) {
  4163. // TODO: if heap is fixed (like in asm.js) this could be executed outside
  4164. var heap;
  4165. if (size === 1) {
  4166. heap = HEAP8;
  4167. } else if (size === 2) {
  4168. heap = HEAP16;
  4169. } else if (size === 4) {
  4170. heap = HEAP32;
  4171. } else {
  4172. throw new TypeError("Unknown boolean type size: " + name);
  4173. }
  4174. return this['fromWireType'](heap[pointer >> shift]);
  4175. },
  4176. destructorFunction: null, // This type does not need a destructor
  4177. });
  4178. }
  4179. var emval_free_list=[];
  4180. var emval_handle_array=[{},{value:undefined},{value:null},{value:true},{value:false}];function __emval_decref(handle) {
  4181. if (handle > 4 && 0 === --emval_handle_array[handle].refcount) {
  4182. emval_handle_array[handle] = undefined;
  4183. emval_free_list.push(handle);
  4184. }
  4185. }
  4186. function count_emval_handles() {
  4187. var count = 0;
  4188. for (var i = 5; i < emval_handle_array.length; ++i) {
  4189. if (emval_handle_array[i] !== undefined) {
  4190. ++count;
  4191. }
  4192. }
  4193. return count;
  4194. }
  4195. function get_first_emval() {
  4196. for (var i = 5; i < emval_handle_array.length; ++i) {
  4197. if (emval_handle_array[i] !== undefined) {
  4198. return emval_handle_array[i];
  4199. }
  4200. }
  4201. return null;
  4202. }function init_emval() {
  4203. Module['count_emval_handles'] = count_emval_handles;
  4204. Module['get_first_emval'] = get_first_emval;
  4205. }function __emval_register(value) {
  4206. switch(value){
  4207. case undefined :{ return 1; }
  4208. case null :{ return 2; }
  4209. case true :{ return 3; }
  4210. case false :{ return 4; }
  4211. default:{
  4212. var handle = emval_free_list.length ?
  4213. emval_free_list.pop() :
  4214. emval_handle_array.length;
  4215. emval_handle_array[handle] = {refcount: 1, value: value};
  4216. return handle;
  4217. }
  4218. }
  4219. }
  4220. function simpleReadValueFromPointer(pointer) {
  4221. return this['fromWireType'](HEAPU32[pointer >> 2]);
  4222. }function __embind_register_emval(rawType, name) {
  4223. name = readLatin1String(name);
  4224. registerType(rawType, {
  4225. name: name,
  4226. 'fromWireType': function(handle) {
  4227. var rv = emval_handle_array[handle].value;
  4228. __emval_decref(handle);
  4229. return rv;
  4230. },
  4231. 'toWireType': function(destructors, value) {
  4232. return __emval_register(value);
  4233. },
  4234. 'argPackAdvance': 8,
  4235. 'readValueFromPointer': simpleReadValueFromPointer,
  4236. destructorFunction: null, // This type does not need a destructor
  4237. // TODO: do we need a deleteObject here? write a test where
  4238. // emval is passed into JS via an interface
  4239. });
  4240. }
  4241. function _embind_repr(v) {
  4242. if (v === null) {
  4243. return 'null';
  4244. }
  4245. var t = typeof v;
  4246. if (t === 'object' || t === 'array' || t === 'function') {
  4247. return v.toString();
  4248. } else {
  4249. return '' + v;
  4250. }
  4251. }
  4252. function floatReadValueFromPointer(name, shift) {
  4253. switch (shift) {
  4254. case 2: return function(pointer) {
  4255. return this['fromWireType'](HEAPF32[pointer >> 2]);
  4256. };
  4257. case 3: return function(pointer) {
  4258. return this['fromWireType'](HEAPF64[pointer >> 3]);
  4259. };
  4260. default:
  4261. throw new TypeError("Unknown float type: " + name);
  4262. }
  4263. }function __embind_register_float(rawType, name, size) {
  4264. var shift = getShiftFromSize(size);
  4265. name = readLatin1String(name);
  4266. registerType(rawType, {
  4267. name: name,
  4268. 'fromWireType': function(value) {
  4269. return value;
  4270. },
  4271. 'toWireType': function(destructors, value) {
  4272. // todo: Here we have an opportunity for -O3 level "unsafe" optimizations: we could
  4273. // avoid the following if() and assume value is of proper type.
  4274. if (typeof value !== "number" && typeof value !== "boolean") {
  4275. throw new TypeError('Cannot convert "' + _embind_repr(value) + '" to ' + this.name);
  4276. }
  4277. return value;
  4278. },
  4279. 'argPackAdvance': 8,
  4280. 'readValueFromPointer': floatReadValueFromPointer(name, shift),
  4281. destructorFunction: null, // This type does not need a destructor
  4282. });
  4283. }
  4284. function new_(constructor, argumentList) {
  4285. if (!(constructor instanceof Function)) {
  4286. throw new TypeError('new_ called with constructor type ' + typeof(constructor) + " which is not a function");
  4287. }
  4288. /*
  4289. * Previously, the following line was just:
  4290. function dummy() {};
  4291. * Unfortunately, Chrome was preserving 'dummy' as the object's name, even though at creation, the 'dummy' has the
  4292. * correct constructor name. Thus, objects created with IMVU.new would show up in the debugger as 'dummy', which
  4293. * isn't very helpful. Using IMVU.createNamedFunction addresses the issue. Doublely-unfortunately, there's no way
  4294. * to write a test for this behavior. -NRD 2013.02.22
  4295. */
  4296. var dummy = createNamedFunction(constructor.name || 'unknownFunctionName', function(){});
  4297. dummy.prototype = constructor.prototype;
  4298. var obj = new dummy;
  4299. var r = constructor.apply(obj, argumentList);
  4300. return (r instanceof Object) ? r : obj;
  4301. }
  4302. function runDestructors(destructors) {
  4303. while (destructors.length) {
  4304. var ptr = destructors.pop();
  4305. var del = destructors.pop();
  4306. del(ptr);
  4307. }
  4308. }function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cppTargetFunc) {
  4309. // humanName: a human-readable string name for the function to be generated.
  4310. // argTypes: An array that contains the embind type objects for all types in the function signature.
  4311. // argTypes[0] is the type object for the function return value.
  4312. // argTypes[1] is the type object for function this object/class type, or null if not crafting an invoker for a class method.
  4313. // argTypes[2...] are the actual function parameters.
  4314. // classType: The embind type object for the class to be bound, or null if this is not a method of a class.
  4315. // cppInvokerFunc: JS Function object to the C++-side function that interops into C++ code.
  4316. // cppTargetFunc: Function pointer (an integer to FUNCTION_TABLE) to the target C++ function the cppInvokerFunc will end up calling.
  4317. var argCount = argTypes.length;
  4318. if (argCount < 2) {
  4319. throwBindingError("argTypes array size mismatch! Must at least get return value and 'this' types!");
  4320. }
  4321. var isClassMethodFunc = (argTypes[1] !== null && classType !== null);
  4322. // Free functions with signature "void function()" do not need an invoker that marshalls between wire types.
  4323. // TODO: This omits argument count check - enable only at -O3 or similar.
  4324. // if (ENABLE_UNSAFE_OPTS && argCount == 2 && argTypes[0].name == "void" && !isClassMethodFunc) {
  4325. // return FUNCTION_TABLE[fn];
  4326. // }
  4327. // Determine if we need to use a dynamic stack to store the destructors for the function parameters.
  4328. // TODO: Remove this completely once all function invokers are being dynamically generated.
  4329. var needsDestructorStack = false;
  4330. for(var i = 1; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here.
  4331. if (argTypes[i] !== null && argTypes[i].destructorFunction === undefined) { // The type does not define a destructor function - must use dynamic stack
  4332. needsDestructorStack = true;
  4333. break;
  4334. }
  4335. }
  4336. var returns = (argTypes[0].name !== "void");
  4337. var argsList = "";
  4338. var argsListWired = "";
  4339. for(var i = 0; i < argCount - 2; ++i) {
  4340. argsList += (i!==0?", ":"")+"arg"+i;
  4341. argsListWired += (i!==0?", ":"")+"arg"+i+"Wired";
  4342. }
  4343. var invokerFnBody =
  4344. "return function "+makeLegalFunctionName(humanName)+"("+argsList+") {\n" +
  4345. "if (arguments.length !== "+(argCount - 2)+") {\n" +
  4346. "throwBindingError('function "+humanName+" called with ' + arguments.length + ' arguments, expected "+(argCount - 2)+" args!');\n" +
  4347. "}\n";
  4348. if (needsDestructorStack) {
  4349. invokerFnBody +=
  4350. "var destructors = [];\n";
  4351. }
  4352. var dtorStack = needsDestructorStack ? "destructors" : "null";
  4353. var args1 = ["throwBindingError", "invoker", "fn", "runDestructors", "retType", "classParam"];
  4354. var args2 = [throwBindingError, cppInvokerFunc, cppTargetFunc, runDestructors, argTypes[0], argTypes[1]];
  4355. if (isClassMethodFunc) {
  4356. invokerFnBody += "var thisWired = classParam.toWireType("+dtorStack+", this);\n";
  4357. }
  4358. for(var i = 0; i < argCount - 2; ++i) {
  4359. invokerFnBody += "var arg"+i+"Wired = argType"+i+".toWireType("+dtorStack+", arg"+i+"); // "+argTypes[i+2].name+"\n";
  4360. args1.push("argType"+i);
  4361. args2.push(argTypes[i+2]);
  4362. }
  4363. if (isClassMethodFunc) {
  4364. argsListWired = "thisWired" + (argsListWired.length > 0 ? ", " : "") + argsListWired;
  4365. }
  4366. invokerFnBody +=
  4367. (returns?"var rv = ":"") + "invoker(fn"+(argsListWired.length>0?", ":"")+argsListWired+");\n";
  4368. if (needsDestructorStack) {
  4369. invokerFnBody += "runDestructors(destructors);\n";
  4370. } else {
  4371. for(var i = isClassMethodFunc?1:2; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here. Also skip class type if not a method.
  4372. var paramName = (i === 1 ? "thisWired" : ("arg"+(i - 2)+"Wired"));
  4373. if (argTypes[i].destructorFunction !== null) {
  4374. invokerFnBody += paramName+"_dtor("+paramName+"); // "+argTypes[i].name+"\n";
  4375. args1.push(paramName+"_dtor");
  4376. args2.push(argTypes[i].destructorFunction);
  4377. }
  4378. }
  4379. }
  4380. if (returns) {
  4381. invokerFnBody += "var ret = retType.fromWireType(rv);\n" +
  4382. "return ret;\n";
  4383. } else {
  4384. }
  4385. invokerFnBody += "}\n";
  4386. args1.push(invokerFnBody);
  4387. var invokerFunction = new_(Function, args1).apply(null, args2);
  4388. return invokerFunction;
  4389. }
  4390. function ensureOverloadTable(proto, methodName, humanName) {
  4391. if (undefined === proto[methodName].overloadTable) {
  4392. var prevFunc = proto[methodName];
  4393. // Inject an overload resolver function that routes to the appropriate overload based on the number of arguments.
  4394. proto[methodName] = function() {
  4395. // TODO This check can be removed in -O3 level "unsafe" optimizations.
  4396. if (!proto[methodName].overloadTable.hasOwnProperty(arguments.length)) {
  4397. throwBindingError("Function '" + humanName + "' called with an invalid number of arguments (" + arguments.length + ") - expects one of (" + proto[methodName].overloadTable + ")!");
  4398. }
  4399. return proto[methodName].overloadTable[arguments.length].apply(this, arguments);
  4400. };
  4401. // Move the previous function into the overload table.
  4402. proto[methodName].overloadTable = [];
  4403. proto[methodName].overloadTable[prevFunc.argCount] = prevFunc;
  4404. }
  4405. }/** @param {number=} numArguments */
  4406. function exposePublicSymbol(name, value, numArguments) {
  4407. if (Module.hasOwnProperty(name)) {
  4408. if (undefined === numArguments || (undefined !== Module[name].overloadTable && undefined !== Module[name].overloadTable[numArguments])) {
  4409. throwBindingError("Cannot register public name '" + name + "' twice");
  4410. }
  4411. // We are exposing a function with the same name as an existing function. Create an overload table and a function selector
  4412. // that routes between the two.
  4413. ensureOverloadTable(Module, name, name);
  4414. if (Module.hasOwnProperty(numArguments)) {
  4415. throwBindingError("Cannot register multiple overloads of a function with the same number of arguments (" + numArguments + ")!");
  4416. }
  4417. // Add the new function into the overload table.
  4418. Module[name].overloadTable[numArguments] = value;
  4419. }
  4420. else {
  4421. Module[name] = value;
  4422. if (undefined !== numArguments) {
  4423. Module[name].numArguments = numArguments;
  4424. }
  4425. }
  4426. }
  4427. function heap32VectorToArray(count, firstElement) {
  4428. var array = [];
  4429. for (var i = 0; i < count; i++) {
  4430. array.push(HEAP32[(firstElement >> 2) + i]);
  4431. }
  4432. return array;
  4433. }
  4434. /** @param {number=} numArguments */
  4435. function replacePublicSymbol(name, value, numArguments) {
  4436. if (!Module.hasOwnProperty(name)) {
  4437. throwInternalError('Replacing nonexistant public symbol');
  4438. }
  4439. // If there's an overload table for this symbol, replace the symbol in the overload table instead.
  4440. if (undefined !== Module[name].overloadTable && undefined !== numArguments) {
  4441. Module[name].overloadTable[numArguments] = value;
  4442. }
  4443. else {
  4444. Module[name] = value;
  4445. Module[name].argCount = numArguments;
  4446. }
  4447. }
  4448. function embind__requireFunction(signature, rawFunction) {
  4449. signature = readLatin1String(signature);
  4450. function makeDynCaller(dynCall) {
  4451. var args = [];
  4452. for (var i = 1; i < signature.length; ++i) {
  4453. args.push('a' + i);
  4454. }
  4455. var name = 'dynCall_' + signature + '_' + rawFunction;
  4456. var body = 'return function ' + name + '(' + args.join(', ') + ') {\n';
  4457. body += ' return dynCall(rawFunction' + (args.length ? ', ' : '') + args.join(', ') + ');\n';
  4458. body += '};\n';
  4459. return (new Function('dynCall', 'rawFunction', body))(dynCall, rawFunction);
  4460. }
  4461. var dc = Module['dynCall_' + signature];
  4462. var fp = makeDynCaller(dc);
  4463. if (typeof fp !== "function") {
  4464. throwBindingError("unknown function pointer with signature " + signature + ": " + rawFunction);
  4465. }
  4466. return fp;
  4467. }
  4468. var UnboundTypeError=undefined;
  4469. function getTypeName(type) {
  4470. var ptr = ___getTypeName(type);
  4471. var rv = readLatin1String(ptr);
  4472. _free(ptr);
  4473. return rv;
  4474. }function throwUnboundTypeError(message, types) {
  4475. var unboundTypes = [];
  4476. var seen = {};
  4477. function visit(type) {
  4478. if (seen[type]) {
  4479. return;
  4480. }
  4481. if (registeredTypes[type]) {
  4482. return;
  4483. }
  4484. if (typeDependencies[type]) {
  4485. typeDependencies[type].forEach(visit);
  4486. return;
  4487. }
  4488. unboundTypes.push(type);
  4489. seen[type] = true;
  4490. }
  4491. types.forEach(visit);
  4492. throw new UnboundTypeError(message + ': ' + unboundTypes.map(getTypeName).join([', ']));
  4493. }function __embind_register_function(name, argCount, rawArgTypesAddr, signature, rawInvoker, fn) {
  4494. var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
  4495. name = readLatin1String(name);
  4496. rawInvoker = embind__requireFunction(signature, rawInvoker);
  4497. exposePublicSymbol(name, function() {
  4498. throwUnboundTypeError('Cannot call ' + name + ' due to unbound types', argTypes);
  4499. }, argCount - 1);
  4500. whenDependentTypesAreResolved([], argTypes, function(argTypes) {
  4501. var invokerArgsArray = [argTypes[0] /* return value */, null /* no class 'this'*/].concat(argTypes.slice(1) /* actual params */);
  4502. replacePublicSymbol(name, craftInvokerFunction(name, invokerArgsArray, null /* no class 'this'*/, rawInvoker, fn), argCount - 1);
  4503. return [];
  4504. });
  4505. }
  4506. function integerReadValueFromPointer(name, shift, signed) {
  4507. // integers are quite common, so generate very specialized functions
  4508. switch (shift) {
  4509. case 0: return signed ?
  4510. function readS8FromPointer(pointer) { return HEAP8[pointer]; } :
  4511. function readU8FromPointer(pointer) { return HEAPU8[pointer]; };
  4512. case 1: return signed ?
  4513. function readS16FromPointer(pointer) { return HEAP16[pointer >> 1]; } :
  4514. function readU16FromPointer(pointer) { return HEAPU16[pointer >> 1]; };
  4515. case 2: return signed ?
  4516. function readS32FromPointer(pointer) { return HEAP32[pointer >> 2]; } :
  4517. function readU32FromPointer(pointer) { return HEAPU32[pointer >> 2]; };
  4518. default:
  4519. throw new TypeError("Unknown integer type: " + name);
  4520. }
  4521. }function __embind_register_integer(primitiveType, name, size, minRange, maxRange) {
  4522. name = readLatin1String(name);
  4523. if (maxRange === -1) { // LLVM doesn't have signed and unsigned 32-bit types, so u32 literals come out as 'i32 -1'. Always treat those as max u32.
  4524. maxRange = 4294967295;
  4525. }
  4526. var shift = getShiftFromSize(size);
  4527. var fromWireType = function(value) {
  4528. return value;
  4529. };
  4530. if (minRange === 0) {
  4531. var bitshift = 32 - 8*size;
  4532. fromWireType = function(value) {
  4533. return (value << bitshift) >>> bitshift;
  4534. };
  4535. }
  4536. var isUnsignedType = (name.indexOf('unsigned') != -1);
  4537. registerType(primitiveType, {
  4538. name: name,
  4539. 'fromWireType': fromWireType,
  4540. 'toWireType': function(destructors, value) {
  4541. // todo: Here we have an opportunity for -O3 level "unsafe" optimizations: we could
  4542. // avoid the following two if()s and assume value is of proper type.
  4543. if (typeof value !== "number" && typeof value !== "boolean") {
  4544. throw new TypeError('Cannot convert "' + _embind_repr(value) + '" to ' + this.name);
  4545. }
  4546. if (value < minRange || value > maxRange) {
  4547. throw new TypeError('Passing a number "' + _embind_repr(value) + '" from JS side to C/C++ side to an argument of type "' + name + '", which is outside the valid range [' + minRange + ', ' + maxRange + ']!');
  4548. }
  4549. return isUnsignedType ? (value >>> 0) : (value | 0);
  4550. },
  4551. 'argPackAdvance': 8,
  4552. 'readValueFromPointer': integerReadValueFromPointer(name, shift, minRange !== 0),
  4553. destructorFunction: null, // This type does not need a destructor
  4554. });
  4555. }
  4556. function __embind_register_memory_view(rawType, dataTypeIndex, name) {
  4557. var typeMapping = [
  4558. Int8Array,
  4559. Uint8Array,
  4560. Int16Array,
  4561. Uint16Array,
  4562. Int32Array,
  4563. Uint32Array,
  4564. Float32Array,
  4565. Float64Array,
  4566. ];
  4567. var TA = typeMapping[dataTypeIndex];
  4568. function decodeMemoryView(handle) {
  4569. handle = handle >> 2;
  4570. var heap = HEAPU32;
  4571. var size = heap[handle]; // in elements
  4572. var data = heap[handle + 1]; // byte offset into emscripten heap
  4573. return new TA(buffer, data, size);
  4574. }
  4575. name = readLatin1String(name);
  4576. registerType(rawType, {
  4577. name: name,
  4578. 'fromWireType': decodeMemoryView,
  4579. 'argPackAdvance': 8,
  4580. 'readValueFromPointer': decodeMemoryView,
  4581. }, {
  4582. ignoreDuplicateRegistrations: true,
  4583. });
  4584. }
  4585. function __embind_register_std_string(rawType, name) {
  4586. name = readLatin1String(name);
  4587. var stdStringIsUTF8
  4588. //process only std::string bindings with UTF8 support, in contrast to e.g. std::basic_string<unsigned char>
  4589. = (name === "std::string");
  4590. registerType(rawType, {
  4591. name: name,
  4592. 'fromWireType': function(value) {
  4593. var length = HEAPU32[value >> 2];
  4594. var str;
  4595. if (stdStringIsUTF8) {
  4596. //ensure null termination at one-past-end byte if not present yet
  4597. var endChar = HEAPU8[value + 4 + length];
  4598. var endCharSwap = 0;
  4599. if (endChar != 0) {
  4600. endCharSwap = endChar;
  4601. HEAPU8[value + 4 + length] = 0;
  4602. }
  4603. var decodeStartPtr = value + 4;
  4604. // Looping here to support possible embedded '0' bytes
  4605. for (var i = 0; i <= length; ++i) {
  4606. var currentBytePtr = value + 4 + i;
  4607. if (HEAPU8[currentBytePtr] == 0) {
  4608. var stringSegment = UTF8ToString(decodeStartPtr);
  4609. if (str === undefined) {
  4610. str = stringSegment;
  4611. } else {
  4612. str += String.fromCharCode(0);
  4613. str += stringSegment;
  4614. }
  4615. decodeStartPtr = currentBytePtr + 1;
  4616. }
  4617. }
  4618. if (endCharSwap != 0) {
  4619. HEAPU8[value + 4 + length] = endCharSwap;
  4620. }
  4621. } else {
  4622. var a = new Array(length);
  4623. for (var i = 0; i < length; ++i) {
  4624. a[i] = String.fromCharCode(HEAPU8[value + 4 + i]);
  4625. }
  4626. str = a.join('');
  4627. }
  4628. _free(value);
  4629. return str;
  4630. },
  4631. 'toWireType': function(destructors, value) {
  4632. if (value instanceof ArrayBuffer) {
  4633. value = new Uint8Array(value);
  4634. }
  4635. var getLength;
  4636. var valueIsOfTypeString = (typeof value === 'string');
  4637. if (!(valueIsOfTypeString || value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int8Array)) {
  4638. throwBindingError('Cannot pass non-string to std::string');
  4639. }
  4640. if (stdStringIsUTF8 && valueIsOfTypeString) {
  4641. getLength = function() {return lengthBytesUTF8(value);};
  4642. } else {
  4643. getLength = function() {return value.length;};
  4644. }
  4645. // assumes 4-byte alignment
  4646. var length = getLength();
  4647. var ptr = _malloc(4 + length + 1);
  4648. HEAPU32[ptr >> 2] = length;
  4649. if (stdStringIsUTF8 && valueIsOfTypeString) {
  4650. stringToUTF8(value, ptr + 4, length + 1);
  4651. } else {
  4652. if (valueIsOfTypeString) {
  4653. for (var i = 0; i < length; ++i) {
  4654. var charCode = value.charCodeAt(i);
  4655. if (charCode > 255) {
  4656. _free(ptr);
  4657. throwBindingError('String has UTF-16 code units that do not fit in 8 bits');
  4658. }
  4659. HEAPU8[ptr + 4 + i] = charCode;
  4660. }
  4661. } else {
  4662. for (var i = 0; i < length; ++i) {
  4663. HEAPU8[ptr + 4 + i] = value[i];
  4664. }
  4665. }
  4666. }
  4667. if (destructors !== null) {
  4668. destructors.push(_free, ptr);
  4669. }
  4670. return ptr;
  4671. },
  4672. 'argPackAdvance': 8,
  4673. 'readValueFromPointer': simpleReadValueFromPointer,
  4674. destructorFunction: function(ptr) { _free(ptr); },
  4675. });
  4676. }
  4677. function __embind_register_std_wstring(rawType, charSize, name) {
  4678. name = readLatin1String(name);
  4679. var decodeString, encodeString, getHeap, lengthBytesUTF, shift;
  4680. if (charSize === 2) {
  4681. decodeString = UTF16ToString;
  4682. encodeString = stringToUTF16;
  4683. lengthBytesUTF = lengthBytesUTF16;
  4684. getHeap = function() { return HEAPU16; };
  4685. shift = 1;
  4686. } else if (charSize === 4) {
  4687. decodeString = UTF32ToString;
  4688. encodeString = stringToUTF32;
  4689. lengthBytesUTF = lengthBytesUTF32;
  4690. getHeap = function() { return HEAPU32; };
  4691. shift = 2;
  4692. }
  4693. registerType(rawType, {
  4694. name: name,
  4695. 'fromWireType': function(value) {
  4696. // Code mostly taken from _embind_register_std_string fromWireType
  4697. var length = HEAPU32[value >> 2];
  4698. var HEAP = getHeap();
  4699. var str;
  4700. // Ensure null termination at one-past-end byte if not present yet
  4701. var endChar = HEAP[(value + 4 + length * charSize) >> shift];
  4702. var endCharSwap = 0;
  4703. if (endChar != 0) {
  4704. endCharSwap = endChar;
  4705. HEAP[(value + 4 + length * charSize) >> shift] = 0;
  4706. }
  4707. var decodeStartPtr = value + 4;
  4708. // Looping here to support possible embedded '0' bytes
  4709. for (var i = 0; i <= length; ++i) {
  4710. var currentBytePtr = value + 4 + i * charSize;
  4711. if (HEAP[currentBytePtr >> shift] == 0) {
  4712. var stringSegment = decodeString(decodeStartPtr);
  4713. if (str === undefined) {
  4714. str = stringSegment;
  4715. } else {
  4716. str += String.fromCharCode(0);
  4717. str += stringSegment;
  4718. }
  4719. decodeStartPtr = currentBytePtr + charSize;
  4720. }
  4721. }
  4722. if (endCharSwap != 0) {
  4723. HEAP[(value + 4 + length * charSize) >> shift] = endCharSwap;
  4724. }
  4725. _free(value);
  4726. return str;
  4727. },
  4728. 'toWireType': function(destructors, value) {
  4729. if (!(typeof value === 'string')) {
  4730. throwBindingError('Cannot pass non-string to C++ string type ' + name);
  4731. }
  4732. // assumes 4-byte alignment
  4733. var length = lengthBytesUTF(value);
  4734. var ptr = _malloc(4 + length + charSize);
  4735. HEAPU32[ptr >> 2] = length >> shift;
  4736. encodeString(value, ptr + 4, length + charSize);
  4737. if (destructors !== null) {
  4738. destructors.push(_free, ptr);
  4739. }
  4740. return ptr;
  4741. },
  4742. 'argPackAdvance': 8,
  4743. 'readValueFromPointer': simpleReadValueFromPointer,
  4744. destructorFunction: function(ptr) { _free(ptr); },
  4745. });
  4746. }
  4747. function __embind_register_void(rawType, name) {
  4748. name = readLatin1String(name);
  4749. registerType(rawType, {
  4750. isVoid: true, // void return values can be optimized out sometimes
  4751. name: name,
  4752. 'argPackAdvance': 0,
  4753. 'fromWireType': function() {
  4754. return undefined;
  4755. },
  4756. 'toWireType': function(destructors, o) {
  4757. // TODO: assert if anything else is given?
  4758. return undefined;
  4759. },
  4760. });
  4761. }
  4762. function __emval_incref(handle) {
  4763. if (handle > 4) {
  4764. emval_handle_array[handle].refcount += 1;
  4765. }
  4766. }
  4767. function requireRegisteredType(rawType, humanName) {
  4768. var impl = registeredTypes[rawType];
  4769. if (undefined === impl) {
  4770. throwBindingError(humanName + " has unknown type " + getTypeName(rawType));
  4771. }
  4772. return impl;
  4773. }function __emval_take_value(type, argv) {
  4774. type = requireRegisteredType(type, '_emval_take_value');
  4775. var v = type['readValueFromPointer'](argv);
  4776. return __emval_register(v);
  4777. }
  4778. function _abort() {
  4779. abort();
  4780. }
  4781. function _emscripten_get_sbrk_ptr() {
  4782. return 62912;
  4783. }
  4784. var setjmpId=0;function _saveSetjmp(env, label, table, size) {
  4785. // Not particularly fast: slow table lookup of setjmpId to label. But setjmp
  4786. // prevents relooping anyhow, so slowness is to be expected. And typical case
  4787. // is 1 setjmp per invocation, or less.
  4788. env = env|0;
  4789. label = label|0;
  4790. table = table|0;
  4791. size = size|0;
  4792. var i = 0;
  4793. setjmpId = (setjmpId+1)|0;
  4794. HEAP32[((env)>>2)]=setjmpId;
  4795. while ((i|0) < (size|0)) {
  4796. if (((HEAP32[(((table)+((i<<3)))>>2)])|0) == 0) {
  4797. HEAP32[(((table)+((i<<3)))>>2)]=setjmpId;
  4798. HEAP32[(((table)+((i<<3)+4))>>2)]=label;
  4799. // prepare next slot
  4800. HEAP32[(((table)+((i<<3)+8))>>2)]=0;
  4801. setTempRet0((size) | 0);
  4802. return table | 0;
  4803. }
  4804. i = i+1|0;
  4805. }
  4806. // grow the table
  4807. size = (size*2)|0;
  4808. table = _realloc(table|0, 8*(size+1|0)|0) | 0;
  4809. table = _saveSetjmp(env|0, label|0, table|0, size|0) | 0;
  4810. setTempRet0((size) | 0);
  4811. return table | 0;
  4812. }
  4813. function _testSetjmp(id, table, size) {
  4814. id = id|0;
  4815. table = table|0;
  4816. size = size|0;
  4817. var i = 0, curr = 0;
  4818. while ((i|0) < (size|0)) {
  4819. curr = ((HEAP32[(((table)+((i<<3)))>>2)])|0);
  4820. if ((curr|0) == 0) break;
  4821. if ((curr|0) == (id|0)) {
  4822. return ((HEAP32[(((table)+((i<<3)+4))>>2)])|0);
  4823. }
  4824. i = i+1|0;
  4825. }
  4826. return 0;
  4827. }function _longjmp(env, value) {
  4828. _setThrew(env, value || 1);
  4829. throw 'longjmp';
  4830. }function _emscripten_longjmp(env, value) {
  4831. _longjmp(env, value);
  4832. }
  4833. function _emscripten_memcpy_big(dest, src, num) {
  4834. HEAPU8.copyWithin(dest, src, src + num);
  4835. }
  4836. function _emscripten_get_heap_size() {
  4837. return HEAPU8.length;
  4838. }
  4839. function emscripten_realloc_buffer(size) {
  4840. try {
  4841. // round size grow request up to wasm page size (fixed 64KB per spec)
  4842. wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16); // .grow() takes a delta compared to the previous size
  4843. updateGlobalBufferAndViews(wasmMemory.buffer);
  4844. return 1 /*success*/;
  4845. } catch(e) {
  4846. console.error('emscripten_realloc_buffer: Attempted to grow heap from ' + buffer.byteLength + ' bytes to ' + size + ' bytes, but got error: ' + e);
  4847. }
  4848. }function _emscripten_resize_heap(requestedSize) {
  4849. var oldSize = _emscripten_get_heap_size();
  4850. // With pthreads, races can happen (another thread might increase the size in between), so return a failure, and let the caller retry.
  4851. assert(requestedSize > oldSize);
  4852. var PAGE_MULTIPLE = 65536;
  4853. // Memory resize rules:
  4854. // 1. When resizing, always produce a resized heap that is at least 16MB (to avoid tiny heap sizes receiving lots of repeated resizes at startup)
  4855. // 2. Always increase heap size to at least the requested size, rounded up to next page multiple.
  4856. // 3a. If MEMORY_GROWTH_LINEAR_STEP == -1, excessively resize the heap geometrically: increase the heap size according to
  4857. // MEMORY_GROWTH_GEOMETRIC_STEP factor (default +20%),
  4858. // At most overreserve by MEMORY_GROWTH_GEOMETRIC_CAP bytes (default 96MB).
  4859. // 3b. If MEMORY_GROWTH_LINEAR_STEP != -1, excessively resize the heap linearly: increase the heap size by at least MEMORY_GROWTH_LINEAR_STEP bytes.
  4860. // 4. Max size for the heap is capped at 2048MB-PAGE_MULTIPLE, or by MAXIMUM_MEMORY, or by ASAN limit, depending on which is smallest
  4861. // 5. If we were unable to allocate as much memory, it may be due to over-eager decision to excessively reserve due to (3) above.
  4862. // Hence if an allocation fails, cut down on the amount of excess growth, in an attempt to succeed to perform a smaller allocation.
  4863. // A limit was set for how much we can grow. We should not exceed that
  4864. // (the wasm binary specifies it, so if we tried, we'd fail anyhow).
  4865. var maxHeapSize = 2147483648;
  4866. if (requestedSize > maxHeapSize) {
  4867. err('Cannot enlarge memory, asked to go up to ' + requestedSize + ' bytes, but the limit is ' + maxHeapSize + ' bytes!');
  4868. return false;
  4869. }
  4870. var minHeapSize = 16777216;
  4871. // Loop through potential heap size increases. If we attempt a too eager reservation that fails, cut down on the
  4872. // attempted size and reserve a smaller bump instead. (max 3 times, chosen somewhat arbitrarily)
  4873. for(var cutDown = 1; cutDown <= 4; cutDown *= 2) {
  4874. var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown); // ensure geometric growth
  4875. // but limit overreserving (default to capping at +96MB overgrowth at most)
  4876. overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296 );
  4877. var newSize = Math.min(maxHeapSize, alignUp(Math.max(minHeapSize, requestedSize, overGrownHeapSize), PAGE_MULTIPLE));
  4878. var replacement = emscripten_realloc_buffer(newSize);
  4879. if (replacement) {
  4880. return true;
  4881. }
  4882. }
  4883. err('Failed to grow the heap from ' + oldSize + ' bytes to ' + newSize + ' bytes, not enough memory!');
  4884. return false;
  4885. }
  4886. var ENV={};
  4887. function __getExecutableName() {
  4888. return thisProgram || './this.program';
  4889. }function getEnvStrings() {
  4890. if (!getEnvStrings.strings) {
  4891. // Default values.
  4892. var env = {
  4893. 'USER': 'web_user',
  4894. 'LOGNAME': 'web_user',
  4895. 'PATH': '/',
  4896. 'PWD': '/',
  4897. 'HOME': '/home/web_user',
  4898. // Browser language detection #8751
  4899. 'LANG': ((typeof navigator === 'object' && navigator.languages && navigator.languages[0]) || 'C').replace('-', '_') + '.UTF-8',
  4900. '_': __getExecutableName()
  4901. };
  4902. // Apply the user-provided values, if any.
  4903. for (var x in ENV) {
  4904. env[x] = ENV[x];
  4905. }
  4906. var strings = [];
  4907. for (var x in env) {
  4908. strings.push(x + '=' + env[x]);
  4909. }
  4910. getEnvStrings.strings = strings;
  4911. }
  4912. return getEnvStrings.strings;
  4913. }function _environ_get(__environ, environ_buf) {
  4914. var bufSize = 0;
  4915. getEnvStrings().forEach(function(string, i) {
  4916. var ptr = environ_buf + bufSize;
  4917. HEAP32[(((__environ)+(i * 4))>>2)]=ptr;
  4918. writeAsciiToMemory(string, ptr);
  4919. bufSize += string.length + 1;
  4920. });
  4921. return 0;
  4922. }
  4923. function _environ_sizes_get(penviron_count, penviron_buf_size) {
  4924. var strings = getEnvStrings();
  4925. HEAP32[((penviron_count)>>2)]=strings.length;
  4926. var bufSize = 0;
  4927. strings.forEach(function(string) {
  4928. bufSize += string.length + 1;
  4929. });
  4930. HEAP32[((penviron_buf_size)>>2)]=bufSize;
  4931. return 0;
  4932. }
  4933. function _exit(status) {
  4934. // void _exit(int status);
  4935. // http://pubs.opengroup.org/onlinepubs/000095399/functions/exit.html
  4936. exit(status);
  4937. }
  4938. function _fd_close(fd) {try {
  4939. var stream = SYSCALLS.getStreamFromFD(fd);
  4940. FS.close(stream);
  4941. return 0;
  4942. } catch (e) {
  4943. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  4944. return e.errno;
  4945. }
  4946. }
  4947. function _fd_read(fd, iov, iovcnt, pnum) {try {
  4948. var stream = SYSCALLS.getStreamFromFD(fd);
  4949. var num = SYSCALLS.doReadv(stream, iov, iovcnt);
  4950. HEAP32[((pnum)>>2)]=num
  4951. return 0;
  4952. } catch (e) {
  4953. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  4954. return e.errno;
  4955. }
  4956. }
  4957. function _fd_seek(fd, offset_low, offset_high, whence, newOffset) {try {
  4958. var stream = SYSCALLS.getStreamFromFD(fd);
  4959. var HIGH_OFFSET = 0x100000000; // 2^32
  4960. // use an unsigned operator on low and shift high by 32-bits
  4961. var offset = offset_high * HIGH_OFFSET + (offset_low >>> 0);
  4962. var DOUBLE_LIMIT = 0x20000000000000; // 2^53
  4963. // we also check for equality since DOUBLE_LIMIT + 1 == DOUBLE_LIMIT
  4964. if (offset <= -DOUBLE_LIMIT || offset >= DOUBLE_LIMIT) {
  4965. return -61;
  4966. }
  4967. FS.llseek(stream, offset, whence);
  4968. (tempI64 = [stream.position>>>0,(tempDouble=stream.position,(+(Math_abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math_min((+(Math_floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[((newOffset)>>2)]=tempI64[0],HEAP32[(((newOffset)+(4))>>2)]=tempI64[1]);
  4969. if (stream.getdents && offset === 0 && whence === 0) stream.getdents = null; // reset readdir state
  4970. return 0;
  4971. } catch (e) {
  4972. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  4973. return e.errno;
  4974. }
  4975. }
  4976. function _fd_write(fd, iov, iovcnt, pnum) {try {
  4977. var stream = SYSCALLS.getStreamFromFD(fd);
  4978. var num = SYSCALLS.doWritev(stream, iov, iovcnt);
  4979. HEAP32[((pnum)>>2)]=num
  4980. return 0;
  4981. } catch (e) {
  4982. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  4983. return e.errno;
  4984. }
  4985. }
  4986. function _getTempRet0() {
  4987. return (getTempRet0() | 0);
  4988. }
  4989. function _setTempRet0($i) {
  4990. setTempRet0(($i) | 0);
  4991. }
  4992. function __isLeapYear(year) {
  4993. return year%4 === 0 && (year%100 !== 0 || year%400 === 0);
  4994. }
  4995. function __arraySum(array, index) {
  4996. var sum = 0;
  4997. for (var i = 0; i <= index; sum += array[i++]) {
  4998. // no-op
  4999. }
  5000. return sum;
  5001. }
  5002. var __MONTH_DAYS_LEAP=[31,29,31,30,31,30,31,31,30,31,30,31];
  5003. var __MONTH_DAYS_REGULAR=[31,28,31,30,31,30,31,31,30,31,30,31];function __addDays(date, days) {
  5004. var newDate = new Date(date.getTime());
  5005. while(days > 0) {
  5006. var leap = __isLeapYear(newDate.getFullYear());
  5007. var currentMonth = newDate.getMonth();
  5008. var daysInCurrentMonth = (leap ? __MONTH_DAYS_LEAP : __MONTH_DAYS_REGULAR)[currentMonth];
  5009. if (days > daysInCurrentMonth-newDate.getDate()) {
  5010. // we spill over to next month
  5011. days -= (daysInCurrentMonth-newDate.getDate()+1);
  5012. newDate.setDate(1);
  5013. if (currentMonth < 11) {
  5014. newDate.setMonth(currentMonth+1)
  5015. } else {
  5016. newDate.setMonth(0);
  5017. newDate.setFullYear(newDate.getFullYear()+1);
  5018. }
  5019. } else {
  5020. // we stay in current month
  5021. newDate.setDate(newDate.getDate()+days);
  5022. return newDate;
  5023. }
  5024. }
  5025. return newDate;
  5026. }function _strftime(s, maxsize, format, tm) {
  5027. // size_t strftime(char *restrict s, size_t maxsize, const char *restrict format, const struct tm *restrict timeptr);
  5028. // http://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html
  5029. var tm_zone = HEAP32[(((tm)+(40))>>2)];
  5030. var date = {
  5031. tm_sec: HEAP32[((tm)>>2)],
  5032. tm_min: HEAP32[(((tm)+(4))>>2)],
  5033. tm_hour: HEAP32[(((tm)+(8))>>2)],
  5034. tm_mday: HEAP32[(((tm)+(12))>>2)],
  5035. tm_mon: HEAP32[(((tm)+(16))>>2)],
  5036. tm_year: HEAP32[(((tm)+(20))>>2)],
  5037. tm_wday: HEAP32[(((tm)+(24))>>2)],
  5038. tm_yday: HEAP32[(((tm)+(28))>>2)],
  5039. tm_isdst: HEAP32[(((tm)+(32))>>2)],
  5040. tm_gmtoff: HEAP32[(((tm)+(36))>>2)],
  5041. tm_zone: tm_zone ? UTF8ToString(tm_zone) : ''
  5042. };
  5043. var pattern = UTF8ToString(format);
  5044. // expand format
  5045. var EXPANSION_RULES_1 = {
  5046. '%c': '%a %b %d %H:%M:%S %Y', // Replaced by the locale's appropriate date and time representation - e.g., Mon Aug 3 14:02:01 2013
  5047. '%D': '%m/%d/%y', // Equivalent to %m / %d / %y
  5048. '%F': '%Y-%m-%d', // Equivalent to %Y - %m - %d
  5049. '%h': '%b', // Equivalent to %b
  5050. '%r': '%I:%M:%S %p', // Replaced by the time in a.m. and p.m. notation
  5051. '%R': '%H:%M', // Replaced by the time in 24-hour notation
  5052. '%T': '%H:%M:%S', // Replaced by the time
  5053. '%x': '%m/%d/%y', // Replaced by the locale's appropriate date representation
  5054. '%X': '%H:%M:%S', // Replaced by the locale's appropriate time representation
  5055. // Modified Conversion Specifiers
  5056. '%Ec': '%c', // Replaced by the locale's alternative appropriate date and time representation.
  5057. '%EC': '%C', // Replaced by the name of the base year (period) in the locale's alternative representation.
  5058. '%Ex': '%m/%d/%y', // Replaced by the locale's alternative date representation.
  5059. '%EX': '%H:%M:%S', // Replaced by the locale's alternative time representation.
  5060. '%Ey': '%y', // Replaced by the offset from %EC (year only) in the locale's alternative representation.
  5061. '%EY': '%Y', // Replaced by the full alternative year representation.
  5062. '%Od': '%d', // Replaced by the day of the month, using the locale's alternative numeric symbols, filled as needed with leading zeros if there is any alternative symbol for zero; otherwise, with leading <space> characters.
  5063. '%Oe': '%e', // Replaced by the day of the month, using the locale's alternative numeric symbols, filled as needed with leading <space> characters.
  5064. '%OH': '%H', // Replaced by the hour (24-hour clock) using the locale's alternative numeric symbols.
  5065. '%OI': '%I', // Replaced by the hour (12-hour clock) using the locale's alternative numeric symbols.
  5066. '%Om': '%m', // Replaced by the month using the locale's alternative numeric symbols.
  5067. '%OM': '%M', // Replaced by the minutes using the locale's alternative numeric symbols.
  5068. '%OS': '%S', // Replaced by the seconds using the locale's alternative numeric symbols.
  5069. '%Ou': '%u', // Replaced by the weekday as a number in the locale's alternative representation (Monday=1).
  5070. '%OU': '%U', // Replaced by the week number of the year (Sunday as the first day of the week, rules corresponding to %U ) using the locale's alternative numeric symbols.
  5071. '%OV': '%V', // Replaced by the week number of the year (Monday as the first day of the week, rules corresponding to %V ) using the locale's alternative numeric symbols.
  5072. '%Ow': '%w', // Replaced by the number of the weekday (Sunday=0) using the locale's alternative numeric symbols.
  5073. '%OW': '%W', // Replaced by the week number of the year (Monday as the first day of the week) using the locale's alternative numeric symbols.
  5074. '%Oy': '%y', // Replaced by the year (offset from %C ) using the locale's alternative numeric symbols.
  5075. };
  5076. for (var rule in EXPANSION_RULES_1) {
  5077. pattern = pattern.replace(new RegExp(rule, 'g'), EXPANSION_RULES_1[rule]);
  5078. }
  5079. var WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  5080. var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
  5081. function leadingSomething(value, digits, character) {
  5082. var str = typeof value === 'number' ? value.toString() : (value || '');
  5083. while (str.length < digits) {
  5084. str = character[0]+str;
  5085. }
  5086. return str;
  5087. }
  5088. function leadingNulls(value, digits) {
  5089. return leadingSomething(value, digits, '0');
  5090. }
  5091. function compareByDay(date1, date2) {
  5092. function sgn(value) {
  5093. return value < 0 ? -1 : (value > 0 ? 1 : 0);
  5094. }
  5095. var compare;
  5096. if ((compare = sgn(date1.getFullYear()-date2.getFullYear())) === 0) {
  5097. if ((compare = sgn(date1.getMonth()-date2.getMonth())) === 0) {
  5098. compare = sgn(date1.getDate()-date2.getDate());
  5099. }
  5100. }
  5101. return compare;
  5102. }
  5103. function getFirstWeekStartDate(janFourth) {
  5104. switch (janFourth.getDay()) {
  5105. case 0: // Sunday
  5106. return new Date(janFourth.getFullYear()-1, 11, 29);
  5107. case 1: // Monday
  5108. return janFourth;
  5109. case 2: // Tuesday
  5110. return new Date(janFourth.getFullYear(), 0, 3);
  5111. case 3: // Wednesday
  5112. return new Date(janFourth.getFullYear(), 0, 2);
  5113. case 4: // Thursday
  5114. return new Date(janFourth.getFullYear(), 0, 1);
  5115. case 5: // Friday
  5116. return new Date(janFourth.getFullYear()-1, 11, 31);
  5117. case 6: // Saturday
  5118. return new Date(janFourth.getFullYear()-1, 11, 30);
  5119. }
  5120. }
  5121. function getWeekBasedYear(date) {
  5122. var thisDate = __addDays(new Date(date.tm_year+1900, 0, 1), date.tm_yday);
  5123. var janFourthThisYear = new Date(thisDate.getFullYear(), 0, 4);
  5124. var janFourthNextYear = new Date(thisDate.getFullYear()+1, 0, 4);
  5125. var firstWeekStartThisYear = getFirstWeekStartDate(janFourthThisYear);
  5126. var firstWeekStartNextYear = getFirstWeekStartDate(janFourthNextYear);
  5127. if (compareByDay(firstWeekStartThisYear, thisDate) <= 0) {
  5128. // this date is after the start of the first week of this year
  5129. if (compareByDay(firstWeekStartNextYear, thisDate) <= 0) {
  5130. return thisDate.getFullYear()+1;
  5131. } else {
  5132. return thisDate.getFullYear();
  5133. }
  5134. } else {
  5135. return thisDate.getFullYear()-1;
  5136. }
  5137. }
  5138. var EXPANSION_RULES_2 = {
  5139. '%a': function(date) {
  5140. return WEEKDAYS[date.tm_wday].substring(0,3);
  5141. },
  5142. '%A': function(date) {
  5143. return WEEKDAYS[date.tm_wday];
  5144. },
  5145. '%b': function(date) {
  5146. return MONTHS[date.tm_mon].substring(0,3);
  5147. },
  5148. '%B': function(date) {
  5149. return MONTHS[date.tm_mon];
  5150. },
  5151. '%C': function(date) {
  5152. var year = date.tm_year+1900;
  5153. return leadingNulls((year/100)|0,2);
  5154. },
  5155. '%d': function(date) {
  5156. return leadingNulls(date.tm_mday, 2);
  5157. },
  5158. '%e': function(date) {
  5159. return leadingSomething(date.tm_mday, 2, ' ');
  5160. },
  5161. '%g': function(date) {
  5162. // %g, %G, and %V give values according to the ISO 8601:2000 standard week-based year.
  5163. // In this system, weeks begin on a Monday and week 1 of the year is the week that includes
  5164. // January 4th, which is also the week that includes the first Thursday of the year, and
  5165. // is also the first week that contains at least four days in the year.
  5166. // If the first Monday of January is the 2nd, 3rd, or 4th, the preceding days are part of
  5167. // the last week of the preceding year; thus, for Saturday 2nd January 1999,
  5168. // %G is replaced by 1998 and %V is replaced by 53. If December 29th, 30th,
  5169. // or 31st is a Monday, it and any following days are part of week 1 of the following year.
  5170. // Thus, for Tuesday 30th December 1997, %G is replaced by 1998 and %V is replaced by 01.
  5171. return getWeekBasedYear(date).toString().substring(2);
  5172. },
  5173. '%G': function(date) {
  5174. return getWeekBasedYear(date);
  5175. },
  5176. '%H': function(date) {
  5177. return leadingNulls(date.tm_hour, 2);
  5178. },
  5179. '%I': function(date) {
  5180. var twelveHour = date.tm_hour;
  5181. if (twelveHour == 0) twelveHour = 12;
  5182. else if (twelveHour > 12) twelveHour -= 12;
  5183. return leadingNulls(twelveHour, 2);
  5184. },
  5185. '%j': function(date) {
  5186. // Day of the year (001-366)
  5187. return leadingNulls(date.tm_mday+__arraySum(__isLeapYear(date.tm_year+1900) ? __MONTH_DAYS_LEAP : __MONTH_DAYS_REGULAR, date.tm_mon-1), 3);
  5188. },
  5189. '%m': function(date) {
  5190. return leadingNulls(date.tm_mon+1, 2);
  5191. },
  5192. '%M': function(date) {
  5193. return leadingNulls(date.tm_min, 2);
  5194. },
  5195. '%n': function() {
  5196. return '\n';
  5197. },
  5198. '%p': function(date) {
  5199. if (date.tm_hour >= 0 && date.tm_hour < 12) {
  5200. return 'AM';
  5201. } else {
  5202. return 'PM';
  5203. }
  5204. },
  5205. '%S': function(date) {
  5206. return leadingNulls(date.tm_sec, 2);
  5207. },
  5208. '%t': function() {
  5209. return '\t';
  5210. },
  5211. '%u': function(date) {
  5212. return date.tm_wday || 7;
  5213. },
  5214. '%U': function(date) {
  5215. // Replaced by the week number of the year as a decimal number [00,53].
  5216. // The first Sunday of January is the first day of week 1;
  5217. // days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday]
  5218. var janFirst = new Date(date.tm_year+1900, 0, 1);
  5219. var firstSunday = janFirst.getDay() === 0 ? janFirst : __addDays(janFirst, 7-janFirst.getDay());
  5220. var endDate = new Date(date.tm_year+1900, date.tm_mon, date.tm_mday);
  5221. // is target date after the first Sunday?
  5222. if (compareByDay(firstSunday, endDate) < 0) {
  5223. // calculate difference in days between first Sunday and endDate
  5224. var februaryFirstUntilEndMonth = __arraySum(__isLeapYear(endDate.getFullYear()) ? __MONTH_DAYS_LEAP : __MONTH_DAYS_REGULAR, endDate.getMonth()-1)-31;
  5225. var firstSundayUntilEndJanuary = 31-firstSunday.getDate();
  5226. var days = firstSundayUntilEndJanuary+februaryFirstUntilEndMonth+endDate.getDate();
  5227. return leadingNulls(Math.ceil(days/7), 2);
  5228. }
  5229. return compareByDay(firstSunday, janFirst) === 0 ? '01': '00';
  5230. },
  5231. '%V': function(date) {
  5232. // Replaced by the week number of the year (Monday as the first day of the week)
  5233. // as a decimal number [01,53]. If the week containing 1 January has four
  5234. // or more days in the new year, then it is considered week 1.
  5235. // Otherwise, it is the last week of the previous year, and the next week is week 1.
  5236. // Both January 4th and the first Thursday of January are always in week 1. [ tm_year, tm_wday, tm_yday]
  5237. var janFourthThisYear = new Date(date.tm_year+1900, 0, 4);
  5238. var janFourthNextYear = new Date(date.tm_year+1901, 0, 4);
  5239. var firstWeekStartThisYear = getFirstWeekStartDate(janFourthThisYear);
  5240. var firstWeekStartNextYear = getFirstWeekStartDate(janFourthNextYear);
  5241. var endDate = __addDays(new Date(date.tm_year+1900, 0, 1), date.tm_yday);
  5242. if (compareByDay(endDate, firstWeekStartThisYear) < 0) {
  5243. // if given date is before this years first week, then it belongs to the 53rd week of last year
  5244. return '53';
  5245. }
  5246. if (compareByDay(firstWeekStartNextYear, endDate) <= 0) {
  5247. // if given date is after next years first week, then it belongs to the 01th week of next year
  5248. return '01';
  5249. }
  5250. // given date is in between CW 01..53 of this calendar year
  5251. var daysDifference;
  5252. if (firstWeekStartThisYear.getFullYear() < date.tm_year+1900) {
  5253. // first CW of this year starts last year
  5254. daysDifference = date.tm_yday+32-firstWeekStartThisYear.getDate()
  5255. } else {
  5256. // first CW of this year starts this year
  5257. daysDifference = date.tm_yday+1-firstWeekStartThisYear.getDate();
  5258. }
  5259. return leadingNulls(Math.ceil(daysDifference/7), 2);
  5260. },
  5261. '%w': function(date) {
  5262. return date.tm_wday;
  5263. },
  5264. '%W': function(date) {
  5265. // Replaced by the week number of the year as a decimal number [00,53].
  5266. // The first Monday of January is the first day of week 1;
  5267. // days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday]
  5268. var janFirst = new Date(date.tm_year, 0, 1);
  5269. var firstMonday = janFirst.getDay() === 1 ? janFirst : __addDays(janFirst, janFirst.getDay() === 0 ? 1 : 7-janFirst.getDay()+1);
  5270. var endDate = new Date(date.tm_year+1900, date.tm_mon, date.tm_mday);
  5271. // is target date after the first Monday?
  5272. if (compareByDay(firstMonday, endDate) < 0) {
  5273. var februaryFirstUntilEndMonth = __arraySum(__isLeapYear(endDate.getFullYear()) ? __MONTH_DAYS_LEAP : __MONTH_DAYS_REGULAR, endDate.getMonth()-1)-31;
  5274. var firstMondayUntilEndJanuary = 31-firstMonday.getDate();
  5275. var days = firstMondayUntilEndJanuary+februaryFirstUntilEndMonth+endDate.getDate();
  5276. return leadingNulls(Math.ceil(days/7), 2);
  5277. }
  5278. return compareByDay(firstMonday, janFirst) === 0 ? '01': '00';
  5279. },
  5280. '%y': function(date) {
  5281. // Replaced by the last two digits of the year as a decimal number [00,99]. [ tm_year]
  5282. return (date.tm_year+1900).toString().substring(2);
  5283. },
  5284. '%Y': function(date) {
  5285. // Replaced by the year as a decimal number (for example, 1997). [ tm_year]
  5286. return date.tm_year+1900;
  5287. },
  5288. '%z': function(date) {
  5289. // Replaced by the offset from UTC in the ISO 8601:2000 standard format ( +hhmm or -hhmm ).
  5290. // For example, "-0430" means 4 hours 30 minutes behind UTC (west of Greenwich).
  5291. var off = date.tm_gmtoff;
  5292. var ahead = off >= 0;
  5293. off = Math.abs(off) / 60;
  5294. // convert from minutes into hhmm format (which means 60 minutes = 100 units)
  5295. off = (off / 60)*100 + (off % 60);
  5296. return (ahead ? '+' : '-') + String("0000" + off).slice(-4);
  5297. },
  5298. '%Z': function(date) {
  5299. return date.tm_zone;
  5300. },
  5301. '%%': function() {
  5302. return '%';
  5303. }
  5304. };
  5305. for (var rule in EXPANSION_RULES_2) {
  5306. if (pattern.indexOf(rule) >= 0) {
  5307. pattern = pattern.replace(new RegExp(rule, 'g'), EXPANSION_RULES_2[rule](date));
  5308. }
  5309. }
  5310. var bytes = intArrayFromString(pattern, false);
  5311. if (bytes.length > maxsize) {
  5312. return 0;
  5313. }
  5314. writeArrayToMemory(bytes, s);
  5315. return bytes.length-1;
  5316. }function _strftime_l(s, maxsize, format, tm) {
  5317. return _strftime(s, maxsize, format, tm); // no locale support yet
  5318. }
  5319. var FSNode = /** @constructor */ function(parent, name, mode, rdev) {
  5320. if (!parent) {
  5321. parent = this; // root node sets parent to itself
  5322. }
  5323. this.parent = parent;
  5324. this.mount = parent.mount;
  5325. this.mounted = null;
  5326. this.id = FS.nextInode++;
  5327. this.name = name;
  5328. this.mode = mode;
  5329. this.node_ops = {};
  5330. this.stream_ops = {};
  5331. this.rdev = rdev;
  5332. };
  5333. var readMode = 292/*292*/ | 73/*73*/;
  5334. var writeMode = 146/*146*/;
  5335. Object.defineProperties(FSNode.prototype, {
  5336. read: {
  5337. get: /** @this{FSNode} */function() {
  5338. return (this.mode & readMode) === readMode;
  5339. },
  5340. set: /** @this{FSNode} */function(val) {
  5341. val ? this.mode |= readMode : this.mode &= ~readMode;
  5342. }
  5343. },
  5344. write: {
  5345. get: /** @this{FSNode} */function() {
  5346. return (this.mode & writeMode) === writeMode;
  5347. },
  5348. set: /** @this{FSNode} */function(val) {
  5349. val ? this.mode |= writeMode : this.mode &= ~writeMode;
  5350. }
  5351. },
  5352. isFolder: {
  5353. get: /** @this{FSNode} */function() {
  5354. return FS.isDir(this.mode);
  5355. }
  5356. },
  5357. isDevice: {
  5358. get: /** @this{FSNode} */function() {
  5359. return FS.isChrdev(this.mode);
  5360. }
  5361. }
  5362. });
  5363. FS.FSNode = FSNode;
  5364. FS.staticInit();;
  5365. embind_init_charCodes();
  5366. BindingError = Module['BindingError'] = extendError(Error, 'BindingError');;
  5367. InternalError = Module['InternalError'] = extendError(Error, 'InternalError');;
  5368. init_emval();;
  5369. UnboundTypeError = Module['UnboundTypeError'] = extendError(Error, 'UnboundTypeError');;
  5370. var ASSERTIONS = true;
  5371. /**
  5372. * @license
  5373. * Copyright 2017 The Emscripten Authors
  5374. * SPDX-License-Identifier: MIT
  5375. */
  5376. /** @type {function(string, boolean=, number=)} */
  5377. function intArrayFromString(stringy, dontAddNull, length) {
  5378. var len = length > 0 ? length : lengthBytesUTF8(stringy)+1;
  5379. var u8array = new Array(len);
  5380. var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
  5381. if (dontAddNull) u8array.length = numBytesWritten;
  5382. return u8array;
  5383. }
  5384. function intArrayToString(array) {
  5385. var ret = [];
  5386. for (var i = 0; i < array.length; i++) {
  5387. var chr = array[i];
  5388. if (chr > 0xFF) {
  5389. if (ASSERTIONS) {
  5390. assert(false, 'Character code ' + chr + ' (' + String.fromCharCode(chr) + ') at offset ' + i + ' not in 0x00-0xFF.');
  5391. }
  5392. chr &= 0xFF;
  5393. }
  5394. ret.push(String.fromCharCode(chr));
  5395. }
  5396. return ret.join('');
  5397. }
  5398. var asmGlobalArg = {};
  5399. var asmLibraryArg = { "__assert_fail": ___assert_fail, "__cxa_allocate_exception": ___cxa_allocate_exception, "__cxa_atexit": ___cxa_atexit, "__cxa_throw": ___cxa_throw, "__handle_stack_overflow": ___handle_stack_overflow, "__map_file": ___map_file, "__sys_munmap": ___sys_munmap, "_embind_register_bool": __embind_register_bool, "_embind_register_emval": __embind_register_emval, "_embind_register_float": __embind_register_float, "_embind_register_function": __embind_register_function, "_embind_register_integer": __embind_register_integer, "_embind_register_memory_view": __embind_register_memory_view, "_embind_register_std_string": __embind_register_std_string, "_embind_register_std_wstring": __embind_register_std_wstring, "_embind_register_void": __embind_register_void, "_emval_decref": __emval_decref, "_emval_incref": __emval_incref, "_emval_take_value": __emval_take_value, "abort": _abort, "emscripten_get_sbrk_ptr": _emscripten_get_sbrk_ptr, "emscripten_longjmp": _emscripten_longjmp, "emscripten_memcpy_big": _emscripten_memcpy_big, "emscripten_resize_heap": _emscripten_resize_heap, "environ_get": _environ_get, "environ_sizes_get": _environ_sizes_get, "exit": _exit, "fd_close": _fd_close, "fd_read": _fd_read, "fd_seek": _fd_seek, "fd_write": _fd_write, "getTempRet0": _getTempRet0, "invoke_ii": invoke_ii, "invoke_iii": invoke_iii, "invoke_iiii": invoke_iiii, "invoke_iiiii": invoke_iiiii, "invoke_iiiiii": invoke_iiiiii, "invoke_iiiiiii": invoke_iiiiiii, "invoke_iiiiiiiiii": invoke_iiiiiiiiii, "invoke_iiiiiiiiiii": invoke_iiiiiiiiiii, "invoke_vi": invoke_vi, "invoke_vii": invoke_vii, "invoke_viii": invoke_viii, "invoke_viiii": invoke_viiii, "invoke_viiiii": invoke_viiiii, "memory": wasmMemory, "saveSetjmp": _saveSetjmp, "setTempRet0": _setTempRet0, "strftime_l": _strftime_l, "table": wasmTable, "testSetjmp": _testSetjmp };
  5400. var asm = createWasm();
  5401. Module["asm"] = asm;
  5402. /** @type {function(...*):?} */
  5403. var ___wasm_call_ctors = Module["___wasm_call_ctors"] = function() {
  5404. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5405. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5406. return Module["asm"]["__wasm_call_ctors"].apply(null, arguments)
  5407. };
  5408. /** @type {function(...*):?} */
  5409. var _malloc = Module["_malloc"] = function() {
  5410. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5411. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5412. return Module["asm"]["malloc"].apply(null, arguments)
  5413. };
  5414. /** @type {function(...*):?} */
  5415. var _free = Module["_free"] = function() {
  5416. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5417. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5418. return Module["asm"]["free"].apply(null, arguments)
  5419. };
  5420. /** @type {function(...*):?} */
  5421. var _fflush = Module["_fflush"] = function() {
  5422. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5423. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5424. return Module["asm"]["fflush"].apply(null, arguments)
  5425. };
  5426. /** @type {function(...*):?} */
  5427. var ___errno_location = Module["___errno_location"] = function() {
  5428. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5429. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5430. return Module["asm"]["__errno_location"].apply(null, arguments)
  5431. };
  5432. /** @type {function(...*):?} */
  5433. var _realloc = Module["_realloc"] = function() {
  5434. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5435. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5436. return Module["asm"]["realloc"].apply(null, arguments)
  5437. };
  5438. /** @type {function(...*):?} */
  5439. var _setThrew = Module["_setThrew"] = function() {
  5440. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5441. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5442. return Module["asm"]["setThrew"].apply(null, arguments)
  5443. };
  5444. /** @type {function(...*):?} */
  5445. var ___getTypeName = Module["___getTypeName"] = function() {
  5446. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5447. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5448. return Module["asm"]["__getTypeName"].apply(null, arguments)
  5449. };
  5450. /** @type {function(...*):?} */
  5451. var ___embind_register_native_and_builtin_types = Module["___embind_register_native_and_builtin_types"] = function() {
  5452. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5453. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5454. return Module["asm"]["__embind_register_native_and_builtin_types"].apply(null, arguments)
  5455. };
  5456. /** @type {function(...*):?} */
  5457. var dynCall_vi = Module["dynCall_vi"] = function() {
  5458. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5459. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5460. return Module["asm"]["dynCall_vi"].apply(null, arguments)
  5461. };
  5462. /** @type {function(...*):?} */
  5463. var dynCall_vii = Module["dynCall_vii"] = function() {
  5464. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5465. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5466. return Module["asm"]["dynCall_vii"].apply(null, arguments)
  5467. };
  5468. /** @type {function(...*):?} */
  5469. var dynCall_viii = Module["dynCall_viii"] = function() {
  5470. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5471. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5472. return Module["asm"]["dynCall_viii"].apply(null, arguments)
  5473. };
  5474. /** @type {function(...*):?} */
  5475. var dynCall_viiii = Module["dynCall_viiii"] = function() {
  5476. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5477. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5478. return Module["asm"]["dynCall_viiii"].apply(null, arguments)
  5479. };
  5480. /** @type {function(...*):?} */
  5481. var dynCall_viiiii = Module["dynCall_viiiii"] = function() {
  5482. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5483. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5484. return Module["asm"]["dynCall_viiiii"].apply(null, arguments)
  5485. };
  5486. /** @type {function(...*):?} */
  5487. var dynCall_ii = Module["dynCall_ii"] = function() {
  5488. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5489. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5490. return Module["asm"]["dynCall_ii"].apply(null, arguments)
  5491. };
  5492. /** @type {function(...*):?} */
  5493. var dynCall_iii = Module["dynCall_iii"] = function() {
  5494. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5495. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5496. return Module["asm"]["dynCall_iii"].apply(null, arguments)
  5497. };
  5498. /** @type {function(...*):?} */
  5499. var dynCall_iiii = Module["dynCall_iiii"] = function() {
  5500. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5501. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5502. return Module["asm"]["dynCall_iiii"].apply(null, arguments)
  5503. };
  5504. /** @type {function(...*):?} */
  5505. var dynCall_iiiii = Module["dynCall_iiiii"] = function() {
  5506. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5507. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5508. return Module["asm"]["dynCall_iiiii"].apply(null, arguments)
  5509. };
  5510. /** @type {function(...*):?} */
  5511. var dynCall_iiiiii = Module["dynCall_iiiiii"] = function() {
  5512. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5513. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5514. return Module["asm"]["dynCall_iiiiii"].apply(null, arguments)
  5515. };
  5516. /** @type {function(...*):?} */
  5517. var dynCall_iiiiiii = Module["dynCall_iiiiiii"] = function() {
  5518. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5519. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5520. return Module["asm"]["dynCall_iiiiiii"].apply(null, arguments)
  5521. };
  5522. /** @type {function(...*):?} */
  5523. var dynCall_iiiiiiiiii = Module["dynCall_iiiiiiiiii"] = function() {
  5524. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5525. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5526. return Module["asm"]["dynCall_iiiiiiiiii"].apply(null, arguments)
  5527. };
  5528. /** @type {function(...*):?} */
  5529. var dynCall_iiiiiiiiiii = Module["dynCall_iiiiiiiiiii"] = function() {
  5530. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5531. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5532. return Module["asm"]["dynCall_iiiiiiiiiii"].apply(null, arguments)
  5533. };
  5534. /** @type {function(...*):?} */
  5535. var ___set_stack_limit = Module["___set_stack_limit"] = function() {
  5536. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5537. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5538. return Module["asm"]["__set_stack_limit"].apply(null, arguments)
  5539. };
  5540. /** @type {function(...*):?} */
  5541. var stackSave = Module["stackSave"] = function() {
  5542. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5543. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5544. return Module["asm"]["stackSave"].apply(null, arguments)
  5545. };
  5546. /** @type {function(...*):?} */
  5547. var stackAlloc = Module["stackAlloc"] = function() {
  5548. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5549. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5550. return Module["asm"]["stackAlloc"].apply(null, arguments)
  5551. };
  5552. /** @type {function(...*):?} */
  5553. var stackRestore = Module["stackRestore"] = function() {
  5554. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5555. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5556. return Module["asm"]["stackRestore"].apply(null, arguments)
  5557. };
  5558. /** @type {function(...*):?} */
  5559. var __growWasmMemory = Module["__growWasmMemory"] = function() {
  5560. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5561. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5562. return Module["asm"]["__growWasmMemory"].apply(null, arguments)
  5563. };
  5564. /** @type {function(...*):?} */
  5565. var dynCall_viijii = Module["dynCall_viijii"] = function() {
  5566. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5567. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5568. return Module["asm"]["dynCall_viijii"].apply(null, arguments)
  5569. };
  5570. /** @type {function(...*):?} */
  5571. var dynCall_viiiiiii = Module["dynCall_viiiiiii"] = function() {
  5572. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5573. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5574. return Module["asm"]["dynCall_viiiiiii"].apply(null, arguments)
  5575. };
  5576. /** @type {function(...*):?} */
  5577. var dynCall_jiji = Module["dynCall_jiji"] = function() {
  5578. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5579. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5580. return Module["asm"]["dynCall_jiji"].apply(null, arguments)
  5581. };
  5582. /** @type {function(...*):?} */
  5583. var dynCall_iidiiii = Module["dynCall_iidiiii"] = function() {
  5584. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5585. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5586. return Module["asm"]["dynCall_iidiiii"].apply(null, arguments)
  5587. };
  5588. /** @type {function(...*):?} */
  5589. var dynCall_iiiiiiiii = Module["dynCall_iiiiiiiii"] = function() {
  5590. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5591. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5592. return Module["asm"]["dynCall_iiiiiiiii"].apply(null, arguments)
  5593. };
  5594. /** @type {function(...*):?} */
  5595. var dynCall_iiiiij = Module["dynCall_iiiiij"] = function() {
  5596. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5597. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5598. return Module["asm"]["dynCall_iiiiij"].apply(null, arguments)
  5599. };
  5600. /** @type {function(...*):?} */
  5601. var dynCall_iiiiid = Module["dynCall_iiiiid"] = function() {
  5602. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5603. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5604. return Module["asm"]["dynCall_iiiiid"].apply(null, arguments)
  5605. };
  5606. /** @type {function(...*):?} */
  5607. var dynCall_iiiiijj = Module["dynCall_iiiiijj"] = function() {
  5608. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5609. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5610. return Module["asm"]["dynCall_iiiiijj"].apply(null, arguments)
  5611. };
  5612. /** @type {function(...*):?} */
  5613. var dynCall_iiiiiiii = Module["dynCall_iiiiiiii"] = function() {
  5614. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5615. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5616. return Module["asm"]["dynCall_iiiiiiii"].apply(null, arguments)
  5617. };
  5618. /** @type {function(...*):?} */
  5619. var dynCall_iiiiiijj = Module["dynCall_iiiiiijj"] = function() {
  5620. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5621. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5622. return Module["asm"]["dynCall_iiiiiijj"].apply(null, arguments)
  5623. };
  5624. /** @type {function(...*):?} */
  5625. var dynCall_viiiiii = Module["dynCall_viiiiii"] = function() {
  5626. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5627. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5628. return Module["asm"]["dynCall_viiiiii"].apply(null, arguments)
  5629. };
  5630. /** @type {function(...*):?} */
  5631. var dynCall_v = Module["dynCall_v"] = function() {
  5632. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5633. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5634. return Module["asm"]["dynCall_v"].apply(null, arguments)
  5635. };
  5636. function invoke_ii(index,a1) {
  5637. var sp = stackSave();
  5638. try {
  5639. return dynCall_ii(index,a1);
  5640. } catch(e) {
  5641. stackRestore(sp);
  5642. if (e !== e+0 && e !== 'longjmp') throw e;
  5643. _setThrew(1, 0);
  5644. }
  5645. }
  5646. function invoke_vi(index,a1) {
  5647. var sp = stackSave();
  5648. try {
  5649. dynCall_vi(index,a1);
  5650. } catch(e) {
  5651. stackRestore(sp);
  5652. if (e !== e+0 && e !== 'longjmp') throw e;
  5653. _setThrew(1, 0);
  5654. }
  5655. }
  5656. function invoke_viii(index,a1,a2,a3) {
  5657. var sp = stackSave();
  5658. try {
  5659. dynCall_viii(index,a1,a2,a3);
  5660. } catch(e) {
  5661. stackRestore(sp);
  5662. if (e !== e+0 && e !== 'longjmp') throw e;
  5663. _setThrew(1, 0);
  5664. }
  5665. }
  5666. function invoke_iii(index,a1,a2) {
  5667. var sp = stackSave();
  5668. try {
  5669. return dynCall_iii(index,a1,a2);
  5670. } catch(e) {
  5671. stackRestore(sp);
  5672. if (e !== e+0 && e !== 'longjmp') throw e;
  5673. _setThrew(1, 0);
  5674. }
  5675. }
  5676. function invoke_vii(index,a1,a2) {
  5677. var sp = stackSave();
  5678. try {
  5679. dynCall_vii(index,a1,a2);
  5680. } catch(e) {
  5681. stackRestore(sp);
  5682. if (e !== e+0 && e !== 'longjmp') throw e;
  5683. _setThrew(1, 0);
  5684. }
  5685. }
  5686. function invoke_iiii(index,a1,a2,a3) {
  5687. var sp = stackSave();
  5688. try {
  5689. return dynCall_iiii(index,a1,a2,a3);
  5690. } catch(e) {
  5691. stackRestore(sp);
  5692. if (e !== e+0 && e !== 'longjmp') throw e;
  5693. _setThrew(1, 0);
  5694. }
  5695. }
  5696. function invoke_viiiii(index,a1,a2,a3,a4,a5) {
  5697. var sp = stackSave();
  5698. try {
  5699. dynCall_viiiii(index,a1,a2,a3,a4,a5);
  5700. } catch(e) {
  5701. stackRestore(sp);
  5702. if (e !== e+0 && e !== 'longjmp') throw e;
  5703. _setThrew(1, 0);
  5704. }
  5705. }
  5706. function invoke_iiiii(index,a1,a2,a3,a4) {
  5707. var sp = stackSave();
  5708. try {
  5709. return dynCall_iiiii(index,a1,a2,a3,a4);
  5710. } catch(e) {
  5711. stackRestore(sp);
  5712. if (e !== e+0 && e !== 'longjmp') throw e;
  5713. _setThrew(1, 0);
  5714. }
  5715. }
  5716. function invoke_viiii(index,a1,a2,a3,a4) {
  5717. var sp = stackSave();
  5718. try {
  5719. dynCall_viiii(index,a1,a2,a3,a4);
  5720. } catch(e) {
  5721. stackRestore(sp);
  5722. if (e !== e+0 && e !== 'longjmp') throw e;
  5723. _setThrew(1, 0);
  5724. }
  5725. }
  5726. function invoke_iiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9) {
  5727. var sp = stackSave();
  5728. try {
  5729. return dynCall_iiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9);
  5730. } catch(e) {
  5731. stackRestore(sp);
  5732. if (e !== e+0 && e !== 'longjmp') throw e;
  5733. _setThrew(1, 0);
  5734. }
  5735. }
  5736. function invoke_iiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) {
  5737. var sp = stackSave();
  5738. try {
  5739. return dynCall_iiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10);
  5740. } catch(e) {
  5741. stackRestore(sp);
  5742. if (e !== e+0 && e !== 'longjmp') throw e;
  5743. _setThrew(1, 0);
  5744. }
  5745. }
  5746. function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6) {
  5747. var sp = stackSave();
  5748. try {
  5749. return dynCall_iiiiiii(index,a1,a2,a3,a4,a5,a6);
  5750. } catch(e) {
  5751. stackRestore(sp);
  5752. if (e !== e+0 && e !== 'longjmp') throw e;
  5753. _setThrew(1, 0);
  5754. }
  5755. }
  5756. function invoke_iiiiii(index,a1,a2,a3,a4,a5) {
  5757. var sp = stackSave();
  5758. try {
  5759. return dynCall_iiiiii(index,a1,a2,a3,a4,a5);
  5760. } catch(e) {
  5761. stackRestore(sp);
  5762. if (e !== e+0 && e !== 'longjmp') throw e;
  5763. _setThrew(1, 0);
  5764. }
  5765. }
  5766. /**
  5767. * @license
  5768. * Copyright 2010 The Emscripten Authors
  5769. * SPDX-License-Identifier: MIT
  5770. */
  5771. // === Auto-generated postamble setup entry stuff ===
  5772. Module['asm'] = asm;
  5773. if (!Object.getOwnPropertyDescriptor(Module, "intArrayFromString")) Module["intArrayFromString"] = function() { abort("'intArrayFromString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5774. if (!Object.getOwnPropertyDescriptor(Module, "intArrayToString")) Module["intArrayToString"] = function() { abort("'intArrayToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5775. Module["ccall"] = ccall;
  5776. Module["cwrap"] = cwrap;
  5777. if (!Object.getOwnPropertyDescriptor(Module, "setValue")) Module["setValue"] = function() { abort("'setValue' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5778. if (!Object.getOwnPropertyDescriptor(Module, "getValue")) Module["getValue"] = function() { abort("'getValue' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5779. if (!Object.getOwnPropertyDescriptor(Module, "allocate")) Module["allocate"] = function() { abort("'allocate' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5780. if (!Object.getOwnPropertyDescriptor(Module, "getMemory")) Module["getMemory"] = function() { abort("'getMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") };
  5781. if (!Object.getOwnPropertyDescriptor(Module, "UTF8ArrayToString")) Module["UTF8ArrayToString"] = function() { abort("'UTF8ArrayToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5782. if (!Object.getOwnPropertyDescriptor(Module, "UTF8ToString")) Module["UTF8ToString"] = function() { abort("'UTF8ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5783. if (!Object.getOwnPropertyDescriptor(Module, "stringToUTF8Array")) Module["stringToUTF8Array"] = function() { abort("'stringToUTF8Array' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5784. if (!Object.getOwnPropertyDescriptor(Module, "stringToUTF8")) Module["stringToUTF8"] = function() { abort("'stringToUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5785. if (!Object.getOwnPropertyDescriptor(Module, "lengthBytesUTF8")) Module["lengthBytesUTF8"] = function() { abort("'lengthBytesUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5786. if (!Object.getOwnPropertyDescriptor(Module, "stackTrace")) Module["stackTrace"] = function() { abort("'stackTrace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5787. if (!Object.getOwnPropertyDescriptor(Module, "addOnPreRun")) Module["addOnPreRun"] = function() { abort("'addOnPreRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5788. if (!Object.getOwnPropertyDescriptor(Module, "addOnInit")) Module["addOnInit"] = function() { abort("'addOnInit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5789. if (!Object.getOwnPropertyDescriptor(Module, "addOnPreMain")) Module["addOnPreMain"] = function() { abort("'addOnPreMain' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5790. if (!Object.getOwnPropertyDescriptor(Module, "addOnExit")) Module["addOnExit"] = function() { abort("'addOnExit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5791. if (!Object.getOwnPropertyDescriptor(Module, "addOnPostRun")) Module["addOnPostRun"] = function() { abort("'addOnPostRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5792. if (!Object.getOwnPropertyDescriptor(Module, "writeStringToMemory")) Module["writeStringToMemory"] = function() { abort("'writeStringToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5793. if (!Object.getOwnPropertyDescriptor(Module, "writeArrayToMemory")) Module["writeArrayToMemory"] = function() { abort("'writeArrayToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5794. if (!Object.getOwnPropertyDescriptor(Module, "writeAsciiToMemory")) Module["writeAsciiToMemory"] = function() { abort("'writeAsciiToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5795. if (!Object.getOwnPropertyDescriptor(Module, "addRunDependency")) Module["addRunDependency"] = function() { abort("'addRunDependency' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") };
  5796. if (!Object.getOwnPropertyDescriptor(Module, "removeRunDependency")) Module["removeRunDependency"] = function() { abort("'removeRunDependency' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") };
  5797. if (!Object.getOwnPropertyDescriptor(Module, "FS_createFolder")) Module["FS_createFolder"] = function() { abort("'FS_createFolder' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") };
  5798. if (!Object.getOwnPropertyDescriptor(Module, "FS_createPath")) Module["FS_createPath"] = function() { abort("'FS_createPath' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") };
  5799. if (!Object.getOwnPropertyDescriptor(Module, "FS_createDataFile")) Module["FS_createDataFile"] = function() { abort("'FS_createDataFile' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") };
  5800. if (!Object.getOwnPropertyDescriptor(Module, "FS_createPreloadedFile")) Module["FS_createPreloadedFile"] = function() { abort("'FS_createPreloadedFile' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") };
  5801. if (!Object.getOwnPropertyDescriptor(Module, "FS_createLazyFile")) Module["FS_createLazyFile"] = function() { abort("'FS_createLazyFile' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") };
  5802. if (!Object.getOwnPropertyDescriptor(Module, "FS_createLink")) Module["FS_createLink"] = function() { abort("'FS_createLink' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") };
  5803. if (!Object.getOwnPropertyDescriptor(Module, "FS_createDevice")) Module["FS_createDevice"] = function() { abort("'FS_createDevice' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") };
  5804. if (!Object.getOwnPropertyDescriptor(Module, "FS_unlink")) Module["FS_unlink"] = function() { abort("'FS_unlink' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") };
  5805. if (!Object.getOwnPropertyDescriptor(Module, "dynamicAlloc")) Module["dynamicAlloc"] = function() { abort("'dynamicAlloc' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5806. if (!Object.getOwnPropertyDescriptor(Module, "loadDynamicLibrary")) Module["loadDynamicLibrary"] = function() { abort("'loadDynamicLibrary' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5807. if (!Object.getOwnPropertyDescriptor(Module, "loadWebAssemblyModule")) Module["loadWebAssemblyModule"] = function() { abort("'loadWebAssemblyModule' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5808. if (!Object.getOwnPropertyDescriptor(Module, "getLEB")) Module["getLEB"] = function() { abort("'getLEB' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5809. if (!Object.getOwnPropertyDescriptor(Module, "getFunctionTables")) Module["getFunctionTables"] = function() { abort("'getFunctionTables' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5810. if (!Object.getOwnPropertyDescriptor(Module, "alignFunctionTables")) Module["alignFunctionTables"] = function() { abort("'alignFunctionTables' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5811. if (!Object.getOwnPropertyDescriptor(Module, "registerFunctions")) Module["registerFunctions"] = function() { abort("'registerFunctions' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5812. if (!Object.getOwnPropertyDescriptor(Module, "addFunction")) Module["addFunction"] = function() { abort("'addFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5813. if (!Object.getOwnPropertyDescriptor(Module, "removeFunction")) Module["removeFunction"] = function() { abort("'removeFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5814. if (!Object.getOwnPropertyDescriptor(Module, "getFuncWrapper")) Module["getFuncWrapper"] = function() { abort("'getFuncWrapper' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5815. if (!Object.getOwnPropertyDescriptor(Module, "prettyPrint")) Module["prettyPrint"] = function() { abort("'prettyPrint' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5816. if (!Object.getOwnPropertyDescriptor(Module, "makeBigInt")) Module["makeBigInt"] = function() { abort("'makeBigInt' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5817. if (!Object.getOwnPropertyDescriptor(Module, "dynCall")) Module["dynCall"] = function() { abort("'dynCall' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5818. if (!Object.getOwnPropertyDescriptor(Module, "getCompilerSetting")) Module["getCompilerSetting"] = function() { abort("'getCompilerSetting' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5819. if (!Object.getOwnPropertyDescriptor(Module, "print")) Module["print"] = function() { abort("'print' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5820. if (!Object.getOwnPropertyDescriptor(Module, "printErr")) Module["printErr"] = function() { abort("'printErr' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5821. if (!Object.getOwnPropertyDescriptor(Module, "getTempRet0")) Module["getTempRet0"] = function() { abort("'getTempRet0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5822. if (!Object.getOwnPropertyDescriptor(Module, "setTempRet0")) Module["setTempRet0"] = function() { abort("'setTempRet0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5823. if (!Object.getOwnPropertyDescriptor(Module, "callMain")) Module["callMain"] = function() { abort("'callMain' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5824. if (!Object.getOwnPropertyDescriptor(Module, "abort")) Module["abort"] = function() { abort("'abort' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5825. if (!Object.getOwnPropertyDescriptor(Module, "stringToNewUTF8")) Module["stringToNewUTF8"] = function() { abort("'stringToNewUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5826. if (!Object.getOwnPropertyDescriptor(Module, "emscripten_realloc_buffer")) Module["emscripten_realloc_buffer"] = function() { abort("'emscripten_realloc_buffer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5827. if (!Object.getOwnPropertyDescriptor(Module, "ENV")) Module["ENV"] = function() { abort("'ENV' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5828. if (!Object.getOwnPropertyDescriptor(Module, "setjmpId")) Module["setjmpId"] = function() { abort("'setjmpId' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5829. if (!Object.getOwnPropertyDescriptor(Module, "ERRNO_CODES")) Module["ERRNO_CODES"] = function() { abort("'ERRNO_CODES' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5830. if (!Object.getOwnPropertyDescriptor(Module, "ERRNO_MESSAGES")) Module["ERRNO_MESSAGES"] = function() { abort("'ERRNO_MESSAGES' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5831. if (!Object.getOwnPropertyDescriptor(Module, "DNS")) Module["DNS"] = function() { abort("'DNS' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5832. if (!Object.getOwnPropertyDescriptor(Module, "GAI_ERRNO_MESSAGES")) Module["GAI_ERRNO_MESSAGES"] = function() { abort("'GAI_ERRNO_MESSAGES' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5833. if (!Object.getOwnPropertyDescriptor(Module, "Protocols")) Module["Protocols"] = function() { abort("'Protocols' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5834. if (!Object.getOwnPropertyDescriptor(Module, "Sockets")) Module["Sockets"] = function() { abort("'Sockets' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5835. if (!Object.getOwnPropertyDescriptor(Module, "UNWIND_CACHE")) Module["UNWIND_CACHE"] = function() { abort("'UNWIND_CACHE' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5836. if (!Object.getOwnPropertyDescriptor(Module, "readAsmConstArgs")) Module["readAsmConstArgs"] = function() { abort("'readAsmConstArgs' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5837. if (!Object.getOwnPropertyDescriptor(Module, "jstoi_q")) Module["jstoi_q"] = function() { abort("'jstoi_q' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5838. if (!Object.getOwnPropertyDescriptor(Module, "jstoi_s")) Module["jstoi_s"] = function() { abort("'jstoi_s' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5839. if (!Object.getOwnPropertyDescriptor(Module, "PATH")) Module["PATH"] = function() { abort("'PATH' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5840. if (!Object.getOwnPropertyDescriptor(Module, "PATH_FS")) Module["PATH_FS"] = function() { abort("'PATH_FS' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5841. if (!Object.getOwnPropertyDescriptor(Module, "SYSCALLS")) Module["SYSCALLS"] = function() { abort("'SYSCALLS' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5842. if (!Object.getOwnPropertyDescriptor(Module, "syscallMmap2")) Module["syscallMmap2"] = function() { abort("'syscallMmap2' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5843. if (!Object.getOwnPropertyDescriptor(Module, "syscallMunmap")) Module["syscallMunmap"] = function() { abort("'syscallMunmap' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5844. if (!Object.getOwnPropertyDescriptor(Module, "JSEvents")) Module["JSEvents"] = function() { abort("'JSEvents' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5845. if (!Object.getOwnPropertyDescriptor(Module, "demangle")) Module["demangle"] = function() { abort("'demangle' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5846. if (!Object.getOwnPropertyDescriptor(Module, "demangleAll")) Module["demangleAll"] = function() { abort("'demangleAll' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5847. if (!Object.getOwnPropertyDescriptor(Module, "jsStackTrace")) Module["jsStackTrace"] = function() { abort("'jsStackTrace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5848. if (!Object.getOwnPropertyDescriptor(Module, "stackTrace")) Module["stackTrace"] = function() { abort("'stackTrace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5849. if (!Object.getOwnPropertyDescriptor(Module, "getEnvStrings")) Module["getEnvStrings"] = function() { abort("'getEnvStrings' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5850. if (!Object.getOwnPropertyDescriptor(Module, "writeI53ToI64")) Module["writeI53ToI64"] = function() { abort("'writeI53ToI64' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5851. if (!Object.getOwnPropertyDescriptor(Module, "writeI53ToI64Clamped")) Module["writeI53ToI64Clamped"] = function() { abort("'writeI53ToI64Clamped' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5852. if (!Object.getOwnPropertyDescriptor(Module, "writeI53ToI64Signaling")) Module["writeI53ToI64Signaling"] = function() { abort("'writeI53ToI64Signaling' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5853. if (!Object.getOwnPropertyDescriptor(Module, "writeI53ToU64Clamped")) Module["writeI53ToU64Clamped"] = function() { abort("'writeI53ToU64Clamped' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5854. if (!Object.getOwnPropertyDescriptor(Module, "writeI53ToU64Signaling")) Module["writeI53ToU64Signaling"] = function() { abort("'writeI53ToU64Signaling' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5855. if (!Object.getOwnPropertyDescriptor(Module, "readI53FromI64")) Module["readI53FromI64"] = function() { abort("'readI53FromI64' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5856. if (!Object.getOwnPropertyDescriptor(Module, "readI53FromU64")) Module["readI53FromU64"] = function() { abort("'readI53FromU64' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5857. if (!Object.getOwnPropertyDescriptor(Module, "convertI32PairToI53")) Module["convertI32PairToI53"] = function() { abort("'convertI32PairToI53' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5858. if (!Object.getOwnPropertyDescriptor(Module, "convertU32PairToI53")) Module["convertU32PairToI53"] = function() { abort("'convertU32PairToI53' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5859. if (!Object.getOwnPropertyDescriptor(Module, "Browser")) Module["Browser"] = function() { abort("'Browser' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5860. if (!Object.getOwnPropertyDescriptor(Module, "FS")) Module["FS"] = function() { abort("'FS' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5861. if (!Object.getOwnPropertyDescriptor(Module, "MEMFS")) Module["MEMFS"] = function() { abort("'MEMFS' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5862. if (!Object.getOwnPropertyDescriptor(Module, "TTY")) Module["TTY"] = function() { abort("'TTY' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5863. if (!Object.getOwnPropertyDescriptor(Module, "PIPEFS")) Module["PIPEFS"] = function() { abort("'PIPEFS' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5864. if (!Object.getOwnPropertyDescriptor(Module, "SOCKFS")) Module["SOCKFS"] = function() { abort("'SOCKFS' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5865. if (!Object.getOwnPropertyDescriptor(Module, "GL")) Module["GL"] = function() { abort("'GL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5866. if (!Object.getOwnPropertyDescriptor(Module, "emscriptenWebGLGet")) Module["emscriptenWebGLGet"] = function() { abort("'emscriptenWebGLGet' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5867. if (!Object.getOwnPropertyDescriptor(Module, "emscriptenWebGLGetTexPixelData")) Module["emscriptenWebGLGetTexPixelData"] = function() { abort("'emscriptenWebGLGetTexPixelData' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5868. if (!Object.getOwnPropertyDescriptor(Module, "emscriptenWebGLGetUniform")) Module["emscriptenWebGLGetUniform"] = function() { abort("'emscriptenWebGLGetUniform' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5869. if (!Object.getOwnPropertyDescriptor(Module, "emscriptenWebGLGetVertexAttrib")) Module["emscriptenWebGLGetVertexAttrib"] = function() { abort("'emscriptenWebGLGetVertexAttrib' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5870. if (!Object.getOwnPropertyDescriptor(Module, "AL")) Module["AL"] = function() { abort("'AL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5871. if (!Object.getOwnPropertyDescriptor(Module, "SDL_unicode")) Module["SDL_unicode"] = function() { abort("'SDL_unicode' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5872. if (!Object.getOwnPropertyDescriptor(Module, "SDL_ttfContext")) Module["SDL_ttfContext"] = function() { abort("'SDL_ttfContext' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5873. if (!Object.getOwnPropertyDescriptor(Module, "SDL_audio")) Module["SDL_audio"] = function() { abort("'SDL_audio' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5874. if (!Object.getOwnPropertyDescriptor(Module, "SDL")) Module["SDL"] = function() { abort("'SDL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5875. if (!Object.getOwnPropertyDescriptor(Module, "SDL_gfx")) Module["SDL_gfx"] = function() { abort("'SDL_gfx' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5876. if (!Object.getOwnPropertyDescriptor(Module, "GLUT")) Module["GLUT"] = function() { abort("'GLUT' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5877. if (!Object.getOwnPropertyDescriptor(Module, "EGL")) Module["EGL"] = function() { abort("'EGL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5878. if (!Object.getOwnPropertyDescriptor(Module, "GLFW_Window")) Module["GLFW_Window"] = function() { abort("'GLFW_Window' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5879. if (!Object.getOwnPropertyDescriptor(Module, "GLFW")) Module["GLFW"] = function() { abort("'GLFW' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5880. if (!Object.getOwnPropertyDescriptor(Module, "GLEW")) Module["GLEW"] = function() { abort("'GLEW' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5881. if (!Object.getOwnPropertyDescriptor(Module, "IDBStore")) Module["IDBStore"] = function() { abort("'IDBStore' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5882. if (!Object.getOwnPropertyDescriptor(Module, "runAndAbortIfError")) Module["runAndAbortIfError"] = function() { abort("'runAndAbortIfError' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5883. if (!Object.getOwnPropertyDescriptor(Module, "emval_handle_array")) Module["emval_handle_array"] = function() { abort("'emval_handle_array' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5884. if (!Object.getOwnPropertyDescriptor(Module, "emval_free_list")) Module["emval_free_list"] = function() { abort("'emval_free_list' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5885. if (!Object.getOwnPropertyDescriptor(Module, "emval_symbols")) Module["emval_symbols"] = function() { abort("'emval_symbols' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5886. if (!Object.getOwnPropertyDescriptor(Module, "init_emval")) Module["init_emval"] = function() { abort("'init_emval' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5887. if (!Object.getOwnPropertyDescriptor(Module, "count_emval_handles")) Module["count_emval_handles"] = function() { abort("'count_emval_handles' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5888. if (!Object.getOwnPropertyDescriptor(Module, "get_first_emval")) Module["get_first_emval"] = function() { abort("'get_first_emval' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5889. if (!Object.getOwnPropertyDescriptor(Module, "getStringOrSymbol")) Module["getStringOrSymbol"] = function() { abort("'getStringOrSymbol' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5890. if (!Object.getOwnPropertyDescriptor(Module, "requireHandle")) Module["requireHandle"] = function() { abort("'requireHandle' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5891. if (!Object.getOwnPropertyDescriptor(Module, "emval_newers")) Module["emval_newers"] = function() { abort("'emval_newers' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5892. if (!Object.getOwnPropertyDescriptor(Module, "craftEmvalAllocator")) Module["craftEmvalAllocator"] = function() { abort("'craftEmvalAllocator' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5893. if (!Object.getOwnPropertyDescriptor(Module, "emval_get_global")) Module["emval_get_global"] = function() { abort("'emval_get_global' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5894. if (!Object.getOwnPropertyDescriptor(Module, "emval_methodCallers")) Module["emval_methodCallers"] = function() { abort("'emval_methodCallers' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5895. if (!Object.getOwnPropertyDescriptor(Module, "InternalError")) Module["InternalError"] = function() { abort("'InternalError' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5896. if (!Object.getOwnPropertyDescriptor(Module, "BindingError")) Module["BindingError"] = function() { abort("'BindingError' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5897. if (!Object.getOwnPropertyDescriptor(Module, "UnboundTypeError")) Module["UnboundTypeError"] = function() { abort("'UnboundTypeError' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5898. if (!Object.getOwnPropertyDescriptor(Module, "PureVirtualError")) Module["PureVirtualError"] = function() { abort("'PureVirtualError' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5899. if (!Object.getOwnPropertyDescriptor(Module, "init_embind")) Module["init_embind"] = function() { abort("'init_embind' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5900. if (!Object.getOwnPropertyDescriptor(Module, "throwInternalError")) Module["throwInternalError"] = function() { abort("'throwInternalError' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5901. if (!Object.getOwnPropertyDescriptor(Module, "throwBindingError")) Module["throwBindingError"] = function() { abort("'throwBindingError' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5902. if (!Object.getOwnPropertyDescriptor(Module, "throwUnboundTypeError")) Module["throwUnboundTypeError"] = function() { abort("'throwUnboundTypeError' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5903. if (!Object.getOwnPropertyDescriptor(Module, "ensureOverloadTable")) Module["ensureOverloadTable"] = function() { abort("'ensureOverloadTable' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5904. if (!Object.getOwnPropertyDescriptor(Module, "exposePublicSymbol")) Module["exposePublicSymbol"] = function() { abort("'exposePublicSymbol' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5905. if (!Object.getOwnPropertyDescriptor(Module, "replacePublicSymbol")) Module["replacePublicSymbol"] = function() { abort("'replacePublicSymbol' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5906. if (!Object.getOwnPropertyDescriptor(Module, "extendError")) Module["extendError"] = function() { abort("'extendError' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5907. if (!Object.getOwnPropertyDescriptor(Module, "createNamedFunction")) Module["createNamedFunction"] = function() { abort("'createNamedFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5908. if (!Object.getOwnPropertyDescriptor(Module, "registeredInstances")) Module["registeredInstances"] = function() { abort("'registeredInstances' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5909. if (!Object.getOwnPropertyDescriptor(Module, "getBasestPointer")) Module["getBasestPointer"] = function() { abort("'getBasestPointer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5910. if (!Object.getOwnPropertyDescriptor(Module, "registerInheritedInstance")) Module["registerInheritedInstance"] = function() { abort("'registerInheritedInstance' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5911. if (!Object.getOwnPropertyDescriptor(Module, "unregisterInheritedInstance")) Module["unregisterInheritedInstance"] = function() { abort("'unregisterInheritedInstance' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5912. if (!Object.getOwnPropertyDescriptor(Module, "getInheritedInstance")) Module["getInheritedInstance"] = function() { abort("'getInheritedInstance' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5913. if (!Object.getOwnPropertyDescriptor(Module, "getInheritedInstanceCount")) Module["getInheritedInstanceCount"] = function() { abort("'getInheritedInstanceCount' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5914. if (!Object.getOwnPropertyDescriptor(Module, "getLiveInheritedInstances")) Module["getLiveInheritedInstances"] = function() { abort("'getLiveInheritedInstances' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5915. if (!Object.getOwnPropertyDescriptor(Module, "registeredTypes")) Module["registeredTypes"] = function() { abort("'registeredTypes' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5916. if (!Object.getOwnPropertyDescriptor(Module, "awaitingDependencies")) Module["awaitingDependencies"] = function() { abort("'awaitingDependencies' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5917. if (!Object.getOwnPropertyDescriptor(Module, "typeDependencies")) Module["typeDependencies"] = function() { abort("'typeDependencies' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5918. if (!Object.getOwnPropertyDescriptor(Module, "registeredPointers")) Module["registeredPointers"] = function() { abort("'registeredPointers' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5919. if (!Object.getOwnPropertyDescriptor(Module, "registerType")) Module["registerType"] = function() { abort("'registerType' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5920. if (!Object.getOwnPropertyDescriptor(Module, "whenDependentTypesAreResolved")) Module["whenDependentTypesAreResolved"] = function() { abort("'whenDependentTypesAreResolved' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5921. if (!Object.getOwnPropertyDescriptor(Module, "embind_charCodes")) Module["embind_charCodes"] = function() { abort("'embind_charCodes' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5922. if (!Object.getOwnPropertyDescriptor(Module, "embind_init_charCodes")) Module["embind_init_charCodes"] = function() { abort("'embind_init_charCodes' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5923. if (!Object.getOwnPropertyDescriptor(Module, "readLatin1String")) Module["readLatin1String"] = function() { abort("'readLatin1String' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5924. if (!Object.getOwnPropertyDescriptor(Module, "getTypeName")) Module["getTypeName"] = function() { abort("'getTypeName' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5925. if (!Object.getOwnPropertyDescriptor(Module, "heap32VectorToArray")) Module["heap32VectorToArray"] = function() { abort("'heap32VectorToArray' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5926. if (!Object.getOwnPropertyDescriptor(Module, "requireRegisteredType")) Module["requireRegisteredType"] = function() { abort("'requireRegisteredType' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5927. if (!Object.getOwnPropertyDescriptor(Module, "getShiftFromSize")) Module["getShiftFromSize"] = function() { abort("'getShiftFromSize' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5928. if (!Object.getOwnPropertyDescriptor(Module, "integerReadValueFromPointer")) Module["integerReadValueFromPointer"] = function() { abort("'integerReadValueFromPointer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5929. if (!Object.getOwnPropertyDescriptor(Module, "enumReadValueFromPointer")) Module["enumReadValueFromPointer"] = function() { abort("'enumReadValueFromPointer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5930. if (!Object.getOwnPropertyDescriptor(Module, "floatReadValueFromPointer")) Module["floatReadValueFromPointer"] = function() { abort("'floatReadValueFromPointer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5931. if (!Object.getOwnPropertyDescriptor(Module, "simpleReadValueFromPointer")) Module["simpleReadValueFromPointer"] = function() { abort("'simpleReadValueFromPointer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5932. if (!Object.getOwnPropertyDescriptor(Module, "runDestructors")) Module["runDestructors"] = function() { abort("'runDestructors' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5933. if (!Object.getOwnPropertyDescriptor(Module, "new_")) Module["new_"] = function() { abort("'new_' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5934. if (!Object.getOwnPropertyDescriptor(Module, "craftInvokerFunction")) Module["craftInvokerFunction"] = function() { abort("'craftInvokerFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5935. if (!Object.getOwnPropertyDescriptor(Module, "embind__requireFunction")) Module["embind__requireFunction"] = function() { abort("'embind__requireFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5936. if (!Object.getOwnPropertyDescriptor(Module, "tupleRegistrations")) Module["tupleRegistrations"] = function() { abort("'tupleRegistrations' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5937. if (!Object.getOwnPropertyDescriptor(Module, "structRegistrations")) Module["structRegistrations"] = function() { abort("'structRegistrations' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5938. if (!Object.getOwnPropertyDescriptor(Module, "genericPointerToWireType")) Module["genericPointerToWireType"] = function() { abort("'genericPointerToWireType' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5939. if (!Object.getOwnPropertyDescriptor(Module, "constNoSmartPtrRawPointerToWireType")) Module["constNoSmartPtrRawPointerToWireType"] = function() { abort("'constNoSmartPtrRawPointerToWireType' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5940. if (!Object.getOwnPropertyDescriptor(Module, "nonConstNoSmartPtrRawPointerToWireType")) Module["nonConstNoSmartPtrRawPointerToWireType"] = function() { abort("'nonConstNoSmartPtrRawPointerToWireType' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5941. if (!Object.getOwnPropertyDescriptor(Module, "init_RegisteredPointer")) Module["init_RegisteredPointer"] = function() { abort("'init_RegisteredPointer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5942. if (!Object.getOwnPropertyDescriptor(Module, "RegisteredPointer")) Module["RegisteredPointer"] = function() { abort("'RegisteredPointer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5943. if (!Object.getOwnPropertyDescriptor(Module, "RegisteredPointer_getPointee")) Module["RegisteredPointer_getPointee"] = function() { abort("'RegisteredPointer_getPointee' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5944. if (!Object.getOwnPropertyDescriptor(Module, "RegisteredPointer_destructor")) Module["RegisteredPointer_destructor"] = function() { abort("'RegisteredPointer_destructor' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5945. if (!Object.getOwnPropertyDescriptor(Module, "RegisteredPointer_deleteObject")) Module["RegisteredPointer_deleteObject"] = function() { abort("'RegisteredPointer_deleteObject' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5946. if (!Object.getOwnPropertyDescriptor(Module, "RegisteredPointer_fromWireType")) Module["RegisteredPointer_fromWireType"] = function() { abort("'RegisteredPointer_fromWireType' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5947. if (!Object.getOwnPropertyDescriptor(Module, "runDestructor")) Module["runDestructor"] = function() { abort("'runDestructor' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5948. if (!Object.getOwnPropertyDescriptor(Module, "releaseClassHandle")) Module["releaseClassHandle"] = function() { abort("'releaseClassHandle' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5949. if (!Object.getOwnPropertyDescriptor(Module, "finalizationGroup")) Module["finalizationGroup"] = function() { abort("'finalizationGroup' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5950. if (!Object.getOwnPropertyDescriptor(Module, "detachFinalizer_deps")) Module["detachFinalizer_deps"] = function() { abort("'detachFinalizer_deps' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5951. if (!Object.getOwnPropertyDescriptor(Module, "detachFinalizer")) Module["detachFinalizer"] = function() { abort("'detachFinalizer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5952. if (!Object.getOwnPropertyDescriptor(Module, "attachFinalizer")) Module["attachFinalizer"] = function() { abort("'attachFinalizer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5953. if (!Object.getOwnPropertyDescriptor(Module, "makeClassHandle")) Module["makeClassHandle"] = function() { abort("'makeClassHandle' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5954. if (!Object.getOwnPropertyDescriptor(Module, "init_ClassHandle")) Module["init_ClassHandle"] = function() { abort("'init_ClassHandle' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5955. if (!Object.getOwnPropertyDescriptor(Module, "ClassHandle")) Module["ClassHandle"] = function() { abort("'ClassHandle' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5956. if (!Object.getOwnPropertyDescriptor(Module, "ClassHandle_isAliasOf")) Module["ClassHandle_isAliasOf"] = function() { abort("'ClassHandle_isAliasOf' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5957. if (!Object.getOwnPropertyDescriptor(Module, "throwInstanceAlreadyDeleted")) Module["throwInstanceAlreadyDeleted"] = function() { abort("'throwInstanceAlreadyDeleted' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5958. if (!Object.getOwnPropertyDescriptor(Module, "ClassHandle_clone")) Module["ClassHandle_clone"] = function() { abort("'ClassHandle_clone' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5959. if (!Object.getOwnPropertyDescriptor(Module, "ClassHandle_delete")) Module["ClassHandle_delete"] = function() { abort("'ClassHandle_delete' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5960. if (!Object.getOwnPropertyDescriptor(Module, "deletionQueue")) Module["deletionQueue"] = function() { abort("'deletionQueue' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5961. if (!Object.getOwnPropertyDescriptor(Module, "ClassHandle_isDeleted")) Module["ClassHandle_isDeleted"] = function() { abort("'ClassHandle_isDeleted' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5962. if (!Object.getOwnPropertyDescriptor(Module, "ClassHandle_deleteLater")) Module["ClassHandle_deleteLater"] = function() { abort("'ClassHandle_deleteLater' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5963. if (!Object.getOwnPropertyDescriptor(Module, "flushPendingDeletes")) Module["flushPendingDeletes"] = function() { abort("'flushPendingDeletes' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5964. if (!Object.getOwnPropertyDescriptor(Module, "delayFunction")) Module["delayFunction"] = function() { abort("'delayFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5965. if (!Object.getOwnPropertyDescriptor(Module, "setDelayFunction")) Module["setDelayFunction"] = function() { abort("'setDelayFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5966. if (!Object.getOwnPropertyDescriptor(Module, "RegisteredClass")) Module["RegisteredClass"] = function() { abort("'RegisteredClass' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5967. if (!Object.getOwnPropertyDescriptor(Module, "shallowCopyInternalPointer")) Module["shallowCopyInternalPointer"] = function() { abort("'shallowCopyInternalPointer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5968. if (!Object.getOwnPropertyDescriptor(Module, "downcastPointer")) Module["downcastPointer"] = function() { abort("'downcastPointer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5969. if (!Object.getOwnPropertyDescriptor(Module, "upcastPointer")) Module["upcastPointer"] = function() { abort("'upcastPointer' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5970. if (!Object.getOwnPropertyDescriptor(Module, "validateThis")) Module["validateThis"] = function() { abort("'validateThis' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5971. if (!Object.getOwnPropertyDescriptor(Module, "char_0")) Module["char_0"] = function() { abort("'char_0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5972. if (!Object.getOwnPropertyDescriptor(Module, "char_9")) Module["char_9"] = function() { abort("'char_9' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5973. if (!Object.getOwnPropertyDescriptor(Module, "makeLegalFunctionName")) Module["makeLegalFunctionName"] = function() { abort("'makeLegalFunctionName' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5974. if (!Object.getOwnPropertyDescriptor(Module, "warnOnce")) Module["warnOnce"] = function() { abort("'warnOnce' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5975. if (!Object.getOwnPropertyDescriptor(Module, "stackSave")) Module["stackSave"] = function() { abort("'stackSave' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5976. if (!Object.getOwnPropertyDescriptor(Module, "stackRestore")) Module["stackRestore"] = function() { abort("'stackRestore' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5977. if (!Object.getOwnPropertyDescriptor(Module, "stackAlloc")) Module["stackAlloc"] = function() { abort("'stackAlloc' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5978. if (!Object.getOwnPropertyDescriptor(Module, "AsciiToString")) Module["AsciiToString"] = function() { abort("'AsciiToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5979. if (!Object.getOwnPropertyDescriptor(Module, "stringToAscii")) Module["stringToAscii"] = function() { abort("'stringToAscii' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5980. if (!Object.getOwnPropertyDescriptor(Module, "UTF16ToString")) Module["UTF16ToString"] = function() { abort("'UTF16ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5981. if (!Object.getOwnPropertyDescriptor(Module, "stringToUTF16")) Module["stringToUTF16"] = function() { abort("'stringToUTF16' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5982. if (!Object.getOwnPropertyDescriptor(Module, "lengthBytesUTF16")) Module["lengthBytesUTF16"] = function() { abort("'lengthBytesUTF16' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5983. if (!Object.getOwnPropertyDescriptor(Module, "UTF32ToString")) Module["UTF32ToString"] = function() { abort("'UTF32ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5984. if (!Object.getOwnPropertyDescriptor(Module, "stringToUTF32")) Module["stringToUTF32"] = function() { abort("'stringToUTF32' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5985. if (!Object.getOwnPropertyDescriptor(Module, "lengthBytesUTF32")) Module["lengthBytesUTF32"] = function() { abort("'lengthBytesUTF32' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5986. if (!Object.getOwnPropertyDescriptor(Module, "allocateUTF8")) Module["allocateUTF8"] = function() { abort("'allocateUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5987. if (!Object.getOwnPropertyDescriptor(Module, "allocateUTF8OnStack")) Module["allocateUTF8OnStack"] = function() { abort("'allocateUTF8OnStack' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
  5988. Module["writeStackCookie"] = writeStackCookie;
  5989. Module["checkStackCookie"] = checkStackCookie;
  5990. Module["abortStackOverflow"] = abortStackOverflow;if (!Object.getOwnPropertyDescriptor(Module, "ALLOC_NORMAL")) Object.defineProperty(Module, "ALLOC_NORMAL", { configurable: true, get: function() { abort("'ALLOC_NORMAL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") } });
  5991. if (!Object.getOwnPropertyDescriptor(Module, "ALLOC_STACK")) Object.defineProperty(Module, "ALLOC_STACK", { configurable: true, get: function() { abort("'ALLOC_STACK' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") } });
  5992. if (!Object.getOwnPropertyDescriptor(Module, "ALLOC_DYNAMIC")) Object.defineProperty(Module, "ALLOC_DYNAMIC", { configurable: true, get: function() { abort("'ALLOC_DYNAMIC' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") } });
  5993. if (!Object.getOwnPropertyDescriptor(Module, "ALLOC_NONE")) Object.defineProperty(Module, "ALLOC_NONE", { configurable: true, get: function() { abort("'ALLOC_NONE' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") } });
  5994. var calledRun;
  5995. /**
  5996. * @constructor
  5997. * @this {ExitStatus}
  5998. */
  5999. function ExitStatus(status) {
  6000. this.name = "ExitStatus";
  6001. this.message = "Program terminated with exit(" + status + ")";
  6002. this.status = status;
  6003. }
  6004. var calledMain = false;
  6005. dependenciesFulfilled = function runCaller() {
  6006. // If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
  6007. if (!calledRun) run();
  6008. if (!calledRun) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled
  6009. };
  6010. /** @type {function(Array=)} */
  6011. function run(args) {
  6012. args = args || arguments_;
  6013. if (runDependencies > 0) {
  6014. return;
  6015. }
  6016. writeStackCookie();
  6017. preRun();
  6018. if (runDependencies > 0) return; // a preRun added a dependency, run will be called later
  6019. function doRun() {
  6020. // run may have just been called through dependencies being fulfilled just in this very frame,
  6021. // or while the async setStatus time below was happening
  6022. if (calledRun) return;
  6023. calledRun = true;
  6024. Module['calledRun'] = true;
  6025. if (ABORT) return;
  6026. initRuntime();
  6027. preMain();
  6028. if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']();
  6029. assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
  6030. postRun();
  6031. }
  6032. if (Module['setStatus']) {
  6033. Module['setStatus']('Running...');
  6034. setTimeout(function() {
  6035. setTimeout(function() {
  6036. Module['setStatus']('');
  6037. }, 1);
  6038. doRun();
  6039. }, 1);
  6040. } else
  6041. {
  6042. doRun();
  6043. }
  6044. checkStackCookie();
  6045. }
  6046. Module['run'] = run;
  6047. function checkUnflushedContent() {
  6048. // Compiler settings do not allow exiting the runtime, so flushing
  6049. // the streams is not possible. but in ASSERTIONS mode we check
  6050. // if there was something to flush, and if so tell the user they
  6051. // should request that the runtime be exitable.
  6052. // Normally we would not even include flush() at all, but in ASSERTIONS
  6053. // builds we do so just for this check, and here we see if there is any
  6054. // content to flush, that is, we check if there would have been
  6055. // something a non-ASSERTIONS build would have not seen.
  6056. // How we flush the streams depends on whether we are in SYSCALLS_REQUIRE_FILESYSTEM=0
  6057. // mode (which has its own special function for this; otherwise, all
  6058. // the code is inside libc)
  6059. var print = out;
  6060. var printErr = err;
  6061. var has = false;
  6062. out = err = function(x) {
  6063. has = true;
  6064. }
  6065. try { // it doesn't matter if it fails
  6066. var flush = Module['_fflush'];
  6067. if (flush) flush(0);
  6068. // also flush in the JS FS layer
  6069. ['stdout', 'stderr'].forEach(function(name) {
  6070. var info = FS.analyzePath('/dev/' + name);
  6071. if (!info) return;
  6072. var stream = info.object;
  6073. var rdev = stream.rdev;
  6074. var tty = TTY.ttys[rdev];
  6075. if (tty && tty.output && tty.output.length) {
  6076. has = true;
  6077. }
  6078. });
  6079. } catch(e) {}
  6080. out = print;
  6081. err = printErr;
  6082. if (has) {
  6083. warnOnce('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the FAQ), or make sure to emit a newline when you printf etc.');
  6084. }
  6085. }
  6086. /** @param {boolean|number=} implicit */
  6087. function exit(status, implicit) {
  6088. checkUnflushedContent();
  6089. // if this is just main exit-ing implicitly, and the status is 0, then we
  6090. // don't need to do anything here and can just leave. if the status is
  6091. // non-zero, though, then we need to report it.
  6092. // (we may have warned about this earlier, if a situation justifies doing so)
  6093. if (implicit && noExitRuntime && status === 0) {
  6094. return;
  6095. }
  6096. if (noExitRuntime) {
  6097. // if exit() was called, we may warn the user if the runtime isn't actually being shut down
  6098. if (!implicit) {
  6099. err('program exited (with status: ' + status + '), but EXIT_RUNTIME is not set, so halting execution but not exiting the runtime or preventing further async execution (build with EXIT_RUNTIME=1, if you want a true shutdown)');
  6100. }
  6101. } else {
  6102. ABORT = true;
  6103. EXITSTATUS = status;
  6104. exitRuntime();
  6105. if (Module['onExit']) Module['onExit'](status);
  6106. }
  6107. quit_(status, new ExitStatus(status));
  6108. }
  6109. if (Module['preInit']) {
  6110. if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
  6111. while (Module['preInit'].length > 0) {
  6112. Module['preInit'].pop()();
  6113. }
  6114. }
  6115. noExitRuntime = true;
  6116. run();
  6117. // {{MODULE_ADDITIONS}}