libSystemTransform.js 286 KB

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