libOpenDrive.js 366 KB

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