Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

lesspass.js 362 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.LessPass = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. (function (Buffer){
  3. var pbkdf2 = require('pbkdf2');
  4. var createHmac = require('create-hmac');
  5. var Promise = require("bluebird");
  6. module.exports = {
  7. encryptLogin: _encryptLogin,
  8. renderPassword: _renderPassword,
  9. createFingerprint: createFingerprint,
  10. _deriveEncryptedLogin: _deriveEncryptedLogin,
  11. _getPasswordTemplate: _getPasswordTemplate,
  12. _prettyPrint: _prettyPrint,
  13. _string2charCodes: _string2charCodes,
  14. _getCharType: _getCharType,
  15. _getPasswordChar: _getPasswordChar,
  16. _createHmac: _createHmac
  17. };
  18. function _encryptLogin(login, masterPassword, options) {
  19. var _options = options !== undefined ? options : {};
  20. var iterations = _options.iterations || 8192;
  21. var keylen = _options.keylen || 32;
  22. return new Promise(function (resolve, reject) {
  23. if (!login || !masterPassword) {
  24. reject('login and master password parameters could not be empty');
  25. }
  26. pbkdf2.pbkdf2(masterPassword, login, iterations, keylen, 'sha256', function (error, key) {
  27. if (error) {
  28. reject('error in pbkdf2');
  29. } else {
  30. resolve(key.toString('hex'));
  31. }
  32. });
  33. })
  34. }
  35. function _renderPassword(encryptedLogin, site, passwordOptions) {
  36. return _deriveEncryptedLogin(encryptedLogin, site, passwordOptions).then(function (derivedEncryptedLogin) {
  37. var template = passwordOptions.template || _getPasswordTemplate(passwordOptions);
  38. return _prettyPrint(derivedEncryptedLogin, template);
  39. });
  40. }
  41. function _createHmac(encryptedLogin, salt) {
  42. return new Promise(function (resolve) {
  43. resolve(createHmac('sha256', new Buffer(encryptedLogin)).update(salt).digest('hex'));
  44. });
  45. }
  46. function _deriveEncryptedLogin(encryptedLogin, site, options) {
  47. var _options = options !== undefined ? options : {};
  48. var length = _options.length || 12;
  49. var counter = _options.counter || 1;
  50. var salt = site + counter.toString();
  51. return _createHmac(encryptedLogin, salt).then(function (derivedHash) {
  52. return derivedHash.substring(0, length);
  53. });
  54. }
  55. function _getPasswordTemplate(passwordTypes) {
  56. var templates = {
  57. lowercase: 'vc',
  58. uppercase: 'VC',
  59. numbers: 'n',
  60. symbols: 's',
  61. };
  62. var returnedTemplate = '';
  63. Object.keys(templates).forEach(function (template) {
  64. if (passwordTypes.hasOwnProperty(template) && passwordTypes[template]) {
  65. returnedTemplate += templates[template]
  66. }
  67. });
  68. return returnedTemplate;
  69. }
  70. function _prettyPrint(hash, template) {
  71. var password = '';
  72. _string2charCodes(hash).forEach(function (charCode, index) {
  73. var charType = _getCharType(template, index);
  74. password += _getPasswordChar(charType, charCode);
  75. });
  76. return password;
  77. }
  78. function _string2charCodes(text) {
  79. var charCodes = [];
  80. for (var i = 0; i < text.length; i++) {
  81. charCodes.push(text.charCodeAt(i));
  82. }
  83. return charCodes;
  84. }
  85. function _getCharType(template, index) {
  86. return template[index % template.length];
  87. }
  88. function _getPasswordChar(charType, index) {
  89. var passwordsChars = {
  90. V: 'AEIOUY',
  91. C: 'BCDFGHJKLMNPQRSTVWXZ',
  92. v: 'aeiouy',
  93. c: 'bcdfghjklmnpqrstvwxz',
  94. A: 'AEIOUYBCDFGHJKLMNPQRSTVWXZ',
  95. a: 'AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz',
  96. n: '0123456789',
  97. s: '@&%?,=[]_:-+*$#!\'^~;()/.',
  98. x: 'AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz0123456789@&%?,=[]_:-+*$#!\'^~;()/.'
  99. };
  100. var passwordChar = passwordsChars[charType];
  101. return passwordChar[index % passwordChar.length];
  102. }
  103. function createFingerprint(str) {
  104. return new Promise(function (resolve) {
  105. resolve(createHmac('sha256', new Buffer(str)).digest('hex'))
  106. });
  107. }
  108. }).call(this,require("buffer").Buffer)
  109. },{"bluebird":3,"buffer":6,"create-hmac":12,"pbkdf2":18}],2:[function(require,module,exports){
  110. 'use strict'
  111. exports.byteLength = byteLength
  112. exports.toByteArray = toByteArray
  113. exports.fromByteArray = fromByteArray
  114. var lookup = []
  115. var revLookup = []
  116. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  117. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  118. for (var i = 0, len = code.length; i < len; ++i) {
  119. lookup[i] = code[i]
  120. revLookup[code.charCodeAt(i)] = i
  121. }
  122. revLookup['-'.charCodeAt(0)] = 62
  123. revLookup['_'.charCodeAt(0)] = 63
  124. function placeHoldersCount (b64) {
  125. var len = b64.length
  126. if (len % 4 > 0) {
  127. throw new Error('Invalid string. Length must be a multiple of 4')
  128. }
  129. // the number of equal signs (place holders)
  130. // if there are two placeholders, than the two characters before it
  131. // represent one byte
  132. // if there is only one, then the three characters before it represent 2 bytes
  133. // this is just a cheap hack to not do indexOf twice
  134. return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  135. }
  136. function byteLength (b64) {
  137. // base64 is 4/3 + up to two characters of the original data
  138. return b64.length * 3 / 4 - placeHoldersCount(b64)
  139. }
  140. function toByteArray (b64) {
  141. var i, j, l, tmp, placeHolders, arr
  142. var len = b64.length
  143. placeHolders = placeHoldersCount(b64)
  144. arr = new Arr(len * 3 / 4 - placeHolders)
  145. // if there are placeholders, only get up to the last complete 4 chars
  146. l = placeHolders > 0 ? len - 4 : len
  147. var L = 0
  148. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  149. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  150. arr[L++] = (tmp >> 16) & 0xFF
  151. arr[L++] = (tmp >> 8) & 0xFF
  152. arr[L++] = tmp & 0xFF
  153. }
  154. if (placeHolders === 2) {
  155. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  156. arr[L++] = tmp & 0xFF
  157. } else if (placeHolders === 1) {
  158. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  159. arr[L++] = (tmp >> 8) & 0xFF
  160. arr[L++] = tmp & 0xFF
  161. }
  162. return arr
  163. }
  164. function tripletToBase64 (num) {
  165. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  166. }
  167. function encodeChunk (uint8, start, end) {
  168. var tmp
  169. var output = []
  170. for (var i = start; i < end; i += 3) {
  171. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  172. output.push(tripletToBase64(tmp))
  173. }
  174. return output.join('')
  175. }
  176. function fromByteArray (uint8) {
  177. var tmp
  178. var len = uint8.length
  179. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  180. var output = ''
  181. var parts = []
  182. var maxChunkLength = 16383 // must be multiple of 3
  183. // go through the array every three bytes, we'll deal with trailing stuff later
  184. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  185. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  186. }
  187. // pad the end with zeros, but make sure to not forget the extra bytes
  188. if (extraBytes === 1) {
  189. tmp = uint8[len - 1]
  190. output += lookup[tmp >> 2]
  191. output += lookup[(tmp << 4) & 0x3F]
  192. output += '=='
  193. } else if (extraBytes === 2) {
  194. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  195. output += lookup[tmp >> 10]
  196. output += lookup[(tmp >> 4) & 0x3F]
  197. output += lookup[(tmp << 2) & 0x3F]
  198. output += '='
  199. }
  200. parts.push(output)
  201. return parts.join('')
  202. }
  203. },{}],3:[function(require,module,exports){
  204. (function (process,global){
  205. /* @preserve
  206. * The MIT License (MIT)
  207. *
  208. * Copyright (c) 2013-2015 Petka Antonov
  209. *
  210. * Permission is hereby granted, free of charge, to any person obtaining a copy
  211. * of this software and associated documentation files (the "Software"), to deal
  212. * in the Software without restriction, including without limitation the rights
  213. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  214. * copies of the Software, and to permit persons to whom the Software is
  215. * furnished to do so, subject to the following conditions:
  216. *
  217. * The above copyright notice and this permission notice shall be included in
  218. * all copies or substantial portions of the Software.
  219. *
  220. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  221. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  222. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  223. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  224. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  225. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  226. * THE SOFTWARE.
  227. *
  228. */
  229. /**
  230. * bluebird build version 3.4.6
  231. * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, using, timers, filter, any, each
  232. */
  233. !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Promise=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof _dereq_=="function"&&_dereq_;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  234. "use strict";
  235. module.exports = function(Promise) {
  236. var SomePromiseArray = Promise._SomePromiseArray;
  237. function any(promises) {
  238. var ret = new SomePromiseArray(promises);
  239. var promise = ret.promise();
  240. ret.setHowMany(1);
  241. ret.setUnwrap();
  242. ret.init();
  243. return promise;
  244. }
  245. Promise.any = function (promises) {
  246. return any(promises);
  247. };
  248. Promise.prototype.any = function () {
  249. return any(this);
  250. };
  251. };
  252. },{}],2:[function(_dereq_,module,exports){
  253. "use strict";
  254. var firstLineError;
  255. try {throw new Error(); } catch (e) {firstLineError = e;}
  256. var schedule = _dereq_("./schedule");
  257. var Queue = _dereq_("./queue");
  258. var util = _dereq_("./util");
  259. function Async() {
  260. this._customScheduler = false;
  261. this._isTickUsed = false;
  262. this._lateQueue = new Queue(16);
  263. this._normalQueue = new Queue(16);
  264. this._haveDrainedQueues = false;
  265. this._trampolineEnabled = true;
  266. var self = this;
  267. this.drainQueues = function () {
  268. self._drainQueues();
  269. };
  270. this._schedule = schedule;
  271. }
  272. Async.prototype.setScheduler = function(fn) {
  273. var prev = this._schedule;
  274. this._schedule = fn;
  275. this._customScheduler = true;
  276. return prev;
  277. };
  278. Async.prototype.hasCustomScheduler = function() {
  279. return this._customScheduler;
  280. };
  281. Async.prototype.enableTrampoline = function() {
  282. this._trampolineEnabled = true;
  283. };
  284. Async.prototype.disableTrampolineIfNecessary = function() {
  285. if (util.hasDevTools) {
  286. this._trampolineEnabled = false;
  287. }
  288. };
  289. Async.prototype.haveItemsQueued = function () {
  290. return this._isTickUsed || this._haveDrainedQueues;
  291. };
  292. Async.prototype.fatalError = function(e, isNode) {
  293. if (isNode) {
  294. process.stderr.write("Fatal " + (e instanceof Error ? e.stack : e) +
  295. "\n");
  296. process.exit(2);
  297. } else {
  298. this.throwLater(e);
  299. }
  300. };
  301. Async.prototype.throwLater = function(fn, arg) {
  302. if (arguments.length === 1) {
  303. arg = fn;
  304. fn = function () { throw arg; };
  305. }
  306. if (typeof setTimeout !== "undefined") {
  307. setTimeout(function() {
  308. fn(arg);
  309. }, 0);
  310. } else try {
  311. this._schedule(function() {
  312. fn(arg);
  313. });
  314. } catch (e) {
  315. throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  316. }
  317. };
  318. function AsyncInvokeLater(fn, receiver, arg) {
  319. this._lateQueue.push(fn, receiver, arg);
  320. this._queueTick();
  321. }
  322. function AsyncInvoke(fn, receiver, arg) {
  323. this._normalQueue.push(fn, receiver, arg);
  324. this._queueTick();
  325. }
  326. function AsyncSettlePromises(promise) {
  327. this._normalQueue._pushOne(promise);
  328. this._queueTick();
  329. }
  330. if (!util.hasDevTools) {
  331. Async.prototype.invokeLater = AsyncInvokeLater;
  332. Async.prototype.invoke = AsyncInvoke;
  333. Async.prototype.settlePromises = AsyncSettlePromises;
  334. } else {
  335. Async.prototype.invokeLater = function (fn, receiver, arg) {
  336. if (this._trampolineEnabled) {
  337. AsyncInvokeLater.call(this, fn, receiver, arg);
  338. } else {
  339. this._schedule(function() {
  340. setTimeout(function() {
  341. fn.call(receiver, arg);
  342. }, 100);
  343. });
  344. }
  345. };
  346. Async.prototype.invoke = function (fn, receiver, arg) {
  347. if (this._trampolineEnabled) {
  348. AsyncInvoke.call(this, fn, receiver, arg);
  349. } else {
  350. this._schedule(function() {
  351. fn.call(receiver, arg);
  352. });
  353. }
  354. };
  355. Async.prototype.settlePromises = function(promise) {
  356. if (this._trampolineEnabled) {
  357. AsyncSettlePromises.call(this, promise);
  358. } else {
  359. this._schedule(function() {
  360. promise._settlePromises();
  361. });
  362. }
  363. };
  364. }
  365. Async.prototype.invokeFirst = function (fn, receiver, arg) {
  366. this._normalQueue.unshift(fn, receiver, arg);
  367. this._queueTick();
  368. };
  369. Async.prototype._drainQueue = function(queue) {
  370. while (queue.length() > 0) {
  371. var fn = queue.shift();
  372. if (typeof fn !== "function") {
  373. fn._settlePromises();
  374. continue;
  375. }
  376. var receiver = queue.shift();
  377. var arg = queue.shift();
  378. fn.call(receiver, arg);
  379. }
  380. };
  381. Async.prototype._drainQueues = function () {
  382. this._drainQueue(this._normalQueue);
  383. this._reset();
  384. this._haveDrainedQueues = true;
  385. this._drainQueue(this._lateQueue);
  386. };
  387. Async.prototype._queueTick = function () {
  388. if (!this._isTickUsed) {
  389. this._isTickUsed = true;
  390. this._schedule(this.drainQueues);
  391. }
  392. };
  393. Async.prototype._reset = function () {
  394. this._isTickUsed = false;
  395. };
  396. module.exports = Async;
  397. module.exports.firstLineError = firstLineError;
  398. },{"./queue":26,"./schedule":29,"./util":36}],3:[function(_dereq_,module,exports){
  399. "use strict";
  400. module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) {
  401. var calledBind = false;
  402. var rejectThis = function(_, e) {
  403. this._reject(e);
  404. };
  405. var targetRejected = function(e, context) {
  406. context.promiseRejectionQueued = true;
  407. context.bindingPromise._then(rejectThis, rejectThis, null, this, e);
  408. };
  409. var bindingResolved = function(thisArg, context) {
  410. if (((this._bitField & 50397184) === 0)) {
  411. this._resolveCallback(context.target);
  412. }
  413. };
  414. var bindingRejected = function(e, context) {
  415. if (!context.promiseRejectionQueued) this._reject(e);
  416. };
  417. Promise.prototype.bind = function (thisArg) {
  418. if (!calledBind) {
  419. calledBind = true;
  420. Promise.prototype._propagateFrom = debug.propagateFromFunction();
  421. Promise.prototype._boundValue = debug.boundValueFunction();
  422. }
  423. var maybePromise = tryConvertToPromise(thisArg);
  424. var ret = new Promise(INTERNAL);
  425. ret._propagateFrom(this, 1);
  426. var target = this._target();
  427. ret._setBoundTo(maybePromise);
  428. if (maybePromise instanceof Promise) {
  429. var context = {
  430. promiseRejectionQueued: false,
  431. promise: ret,
  432. target: target,
  433. bindingPromise: maybePromise
  434. };
  435. target._then(INTERNAL, targetRejected, undefined, ret, context);
  436. maybePromise._then(
  437. bindingResolved, bindingRejected, undefined, ret, context);
  438. ret._setOnCancel(maybePromise);
  439. } else {
  440. ret._resolveCallback(target);
  441. }
  442. return ret;
  443. };
  444. Promise.prototype._setBoundTo = function (obj) {
  445. if (obj !== undefined) {
  446. this._bitField = this._bitField | 2097152;
  447. this._boundTo = obj;
  448. } else {
  449. this._bitField = this._bitField & (~2097152);
  450. }
  451. };
  452. Promise.prototype._isBound = function () {
  453. return (this._bitField & 2097152) === 2097152;
  454. };
  455. Promise.bind = function (thisArg, value) {
  456. return Promise.resolve(value).bind(thisArg);
  457. };
  458. };
  459. },{}],4:[function(_dereq_,module,exports){
  460. "use strict";
  461. var old;
  462. if (typeof Promise !== "undefined") old = Promise;
  463. function noConflict() {
  464. try { if (Promise === bluebird) Promise = old; }
  465. catch (e) {}
  466. return bluebird;
  467. }
  468. var bluebird = _dereq_("./promise")();
  469. bluebird.noConflict = noConflict;
  470. module.exports = bluebird;
  471. },{"./promise":22}],5:[function(_dereq_,module,exports){
  472. "use strict";
  473. var cr = Object.create;
  474. if (cr) {
  475. var callerCache = cr(null);
  476. var getterCache = cr(null);
  477. callerCache[" size"] = getterCache[" size"] = 0;
  478. }
  479. module.exports = function(Promise) {
  480. var util = _dereq_("./util");
  481. var canEvaluate = util.canEvaluate;
  482. var isIdentifier = util.isIdentifier;
  483. var getMethodCaller;
  484. var getGetter;
  485. if (!true) {
  486. var makeMethodCaller = function (methodName) {
  487. return new Function("ensureMethod", " \n\
  488. return function(obj) { \n\
  489. 'use strict' \n\
  490. var len = this.length; \n\
  491. ensureMethod(obj, 'methodName'); \n\
  492. switch(len) { \n\
  493. case 1: return obj.methodName(this[0]); \n\
  494. case 2: return obj.methodName(this[0], this[1]); \n\
  495. case 3: return obj.methodName(this[0], this[1], this[2]); \n\
  496. case 0: return obj.methodName(); \n\
  497. default: \n\
  498. return obj.methodName.apply(obj, this); \n\
  499. } \n\
  500. }; \n\
  501. ".replace(/methodName/g, methodName))(ensureMethod);
  502. };
  503. var makeGetter = function (propertyName) {
  504. return new Function("obj", " \n\
  505. 'use strict'; \n\
  506. return obj.propertyName; \n\
  507. ".replace("propertyName", propertyName));
  508. };
  509. var getCompiled = function(name, compiler, cache) {
  510. var ret = cache[name];
  511. if (typeof ret !== "function") {
  512. if (!isIdentifier(name)) {
  513. return null;
  514. }
  515. ret = compiler(name);
  516. cache[name] = ret;
  517. cache[" size"]++;
  518. if (cache[" size"] > 512) {
  519. var keys = Object.keys(cache);
  520. for (var i = 0; i < 256; ++i) delete cache[keys[i]];
  521. cache[" size"] = keys.length - 256;
  522. }
  523. }
  524. return ret;
  525. };
  526. getMethodCaller = function(name) {
  527. return getCompiled(name, makeMethodCaller, callerCache);
  528. };
  529. getGetter = function(name) {
  530. return getCompiled(name, makeGetter, getterCache);
  531. };
  532. }
  533. function ensureMethod(obj, methodName) {
  534. var fn;
  535. if (obj != null) fn = obj[methodName];
  536. if (typeof fn !== "function") {
  537. var message = "Object " + util.classString(obj) + " has no method '" +
  538. util.toString(methodName) + "'";
  539. throw new Promise.TypeError(message);
  540. }
  541. return fn;
  542. }
  543. function caller(obj) {
  544. var methodName = this.pop();
  545. var fn = ensureMethod(obj, methodName);
  546. return fn.apply(obj, this);
  547. }
  548. Promise.prototype.call = function (methodName) {
  549. var args = [].slice.call(arguments, 1);;
  550. if (!true) {
  551. if (canEvaluate) {
  552. var maybeCaller = getMethodCaller(methodName);
  553. if (maybeCaller !== null) {
  554. return this._then(
  555. maybeCaller, undefined, undefined, args, undefined);
  556. }
  557. }
  558. }
  559. args.push(methodName);
  560. return this._then(caller, undefined, undefined, args, undefined);
  561. };
  562. function namedGetter(obj) {
  563. return obj[this];
  564. }
  565. function indexedGetter(obj) {
  566. var index = +this;
  567. if (index < 0) index = Math.max(0, index + obj.length);
  568. return obj[index];
  569. }
  570. Promise.prototype.get = function (propertyName) {
  571. var isIndex = (typeof propertyName === "number");
  572. var getter;
  573. if (!isIndex) {
  574. if (canEvaluate) {
  575. var maybeGetter = getGetter(propertyName);
  576. getter = maybeGetter !== null ? maybeGetter : namedGetter;
  577. } else {
  578. getter = namedGetter;
  579. }
  580. } else {
  581. getter = indexedGetter;
  582. }
  583. return this._then(getter, undefined, undefined, propertyName, undefined);
  584. };
  585. };
  586. },{"./util":36}],6:[function(_dereq_,module,exports){
  587. "use strict";
  588. module.exports = function(Promise, PromiseArray, apiRejection, debug) {
  589. var util = _dereq_("./util");
  590. var tryCatch = util.tryCatch;
  591. var errorObj = util.errorObj;
  592. var async = Promise._async;
  593. Promise.prototype["break"] = Promise.prototype.cancel = function() {
  594. if (!debug.cancellation()) return this._warn("cancellation is disabled");
  595. var promise = this;
  596. var child = promise;
  597. while (promise._isCancellable()) {
  598. if (!promise._cancelBy(child)) {
  599. if (child._isFollowing()) {
  600. child._followee().cancel();
  601. } else {
  602. child._cancelBranched();
  603. }
  604. break;
  605. }
  606. var parent = promise._cancellationParent;
  607. if (parent == null || !parent._isCancellable()) {
  608. if (promise._isFollowing()) {
  609. promise._followee().cancel();
  610. } else {
  611. promise._cancelBranched();
  612. }
  613. break;
  614. } else {
  615. if (promise._isFollowing()) promise._followee().cancel();
  616. promise._setWillBeCancelled();
  617. child = promise;
  618. promise = parent;
  619. }
  620. }
  621. };
  622. Promise.prototype._branchHasCancelled = function() {
  623. this._branchesRemainingToCancel--;
  624. };
  625. Promise.prototype._enoughBranchesHaveCancelled = function() {
  626. return this._branchesRemainingToCancel === undefined ||
  627. this._branchesRemainingToCancel <= 0;
  628. };
  629. Promise.prototype._cancelBy = function(canceller) {
  630. if (canceller === this) {
  631. this._branchesRemainingToCancel = 0;
  632. this._invokeOnCancel();
  633. return true;
  634. } else {
  635. this._branchHasCancelled();
  636. if (this._enoughBranchesHaveCancelled()) {
  637. this._invokeOnCancel();
  638. return true;
  639. }
  640. }
  641. return false;
  642. };
  643. Promise.prototype._cancelBranched = function() {
  644. if (this._enoughBranchesHaveCancelled()) {
  645. this._cancel();
  646. }
  647. };
  648. Promise.prototype._cancel = function() {
  649. if (!this._isCancellable()) return;
  650. this._setCancelled();
  651. async.invoke(this._cancelPromises, this, undefined);
  652. };
  653. Promise.prototype._cancelPromises = function() {
  654. if (this._length() > 0) this._settlePromises();
  655. };
  656. Promise.prototype._unsetOnCancel = function() {
  657. this._onCancelField = undefined;
  658. };
  659. Promise.prototype._isCancellable = function() {
  660. return this.isPending() && !this._isCancelled();
  661. };
  662. Promise.prototype.isCancellable = function() {
  663. return this.isPending() && !this.isCancelled();
  664. };
  665. Promise.prototype._doInvokeOnCancel = function(onCancelCallback, internalOnly) {
  666. if (util.isArray(onCancelCallback)) {
  667. for (var i = 0; i < onCancelCallback.length; ++i) {
  668. this._doInvokeOnCancel(onCancelCallback[i], internalOnly);
  669. }
  670. } else if (onCancelCallback !== undefined) {
  671. if (typeof onCancelCallback === "function") {
  672. if (!internalOnly) {
  673. var e = tryCatch(onCancelCallback).call(this._boundValue());
  674. if (e === errorObj) {
  675. this._attachExtraTrace(e.e);
  676. async.throwLater(e.e);
  677. }
  678. }
  679. } else {
  680. onCancelCallback._resultCancelled(this);
  681. }
  682. }
  683. };
  684. Promise.prototype._invokeOnCancel = function() {
  685. var onCancelCallback = this._onCancel();
  686. this._unsetOnCancel();
  687. async.invoke(this._doInvokeOnCancel, this, onCancelCallback);
  688. };
  689. Promise.prototype._invokeInternalOnCancel = function() {
  690. if (this._isCancellable()) {
  691. this._doInvokeOnCancel(this._onCancel(), true);
  692. this._unsetOnCancel();
  693. }
  694. };
  695. Promise.prototype._resultCancelled = function() {
  696. this.cancel();
  697. };
  698. };
  699. },{"./util":36}],7:[function(_dereq_,module,exports){
  700. "use strict";
  701. module.exports = function(NEXT_FILTER) {
  702. var util = _dereq_("./util");
  703. var getKeys = _dereq_("./es5").keys;
  704. var tryCatch = util.tryCatch;
  705. var errorObj = util.errorObj;
  706. function catchFilter(instances, cb, promise) {
  707. return function(e) {
  708. var boundTo = promise._boundValue();
  709. predicateLoop: for (var i = 0; i < instances.length; ++i) {
  710. var item = instances[i];
  711. if (item === Error ||
  712. (item != null && item.prototype instanceof Error)) {
  713. if (e instanceof item) {
  714. return tryCatch(cb).call(boundTo, e);
  715. }
  716. } else if (typeof item === "function") {
  717. var matchesPredicate = tryCatch(item).call(boundTo, e);
  718. if (matchesPredicate === errorObj) {
  719. return matchesPredicate;
  720. } else if (matchesPredicate) {
  721. return tryCatch(cb).call(boundTo, e);
  722. }
  723. } else if (util.isObject(e)) {
  724. var keys = getKeys(item);
  725. for (var j = 0; j < keys.length; ++j) {
  726. var key = keys[j];
  727. if (item[key] != e[key]) {
  728. continue predicateLoop;
  729. }
  730. }
  731. return tryCatch(cb).call(boundTo, e);
  732. }
  733. }
  734. return NEXT_FILTER;
  735. };
  736. }
  737. return catchFilter;
  738. };
  739. },{"./es5":13,"./util":36}],8:[function(_dereq_,module,exports){
  740. "use strict";
  741. module.exports = function(Promise) {
  742. var longStackTraces = false;
  743. var contextStack = [];
  744. Promise.prototype._promiseCreated = function() {};
  745. Promise.prototype._pushContext = function() {};
  746. Promise.prototype._popContext = function() {return null;};
  747. Promise._peekContext = Promise.prototype._peekContext = function() {};
  748. function Context() {
  749. this._trace = new Context.CapturedTrace(peekContext());
  750. }
  751. Context.prototype._pushContext = function () {
  752. if (this._trace !== undefined) {
  753. this._trace._promiseCreated = null;
  754. contextStack.push(this._trace);
  755. }
  756. };
  757. Context.prototype._popContext = function () {
  758. if (this._trace !== undefined) {
  759. var trace = contextStack.pop();
  760. var ret = trace._promiseCreated;
  761. trace._promiseCreated = null;
  762. return ret;
  763. }
  764. return null;
  765. };
  766. function createContext() {
  767. if (longStackTraces) return new Context();
  768. }
  769. function peekContext() {
  770. var lastIndex = contextStack.length - 1;
  771. if (lastIndex >= 0) {
  772. return contextStack[lastIndex];
  773. }
  774. return undefined;
  775. }
  776. Context.CapturedTrace = null;
  777. Context.create = createContext;
  778. Context.deactivateLongStackTraces = function() {};
  779. Context.activateLongStackTraces = function() {
  780. var Promise_pushContext = Promise.prototype._pushContext;
  781. var Promise_popContext = Promise.prototype._popContext;
  782. var Promise_PeekContext = Promise._peekContext;
  783. var Promise_peekContext = Promise.prototype._peekContext;
  784. var Promise_promiseCreated = Promise.prototype._promiseCreated;
  785. Context.deactivateLongStackTraces = function() {
  786. Promise.prototype._pushContext = Promise_pushContext;
  787. Promise.prototype._popContext = Promise_popContext;
  788. Promise._peekContext = Promise_PeekContext;
  789. Promise.prototype._peekContext = Promise_peekContext;
  790. Promise.prototype._promiseCreated = Promise_promiseCreated;
  791. longStackTraces = false;
  792. };
  793. longStackTraces = true;
  794. Promise.prototype._pushContext = Context.prototype._pushContext;
  795. Promise.prototype._popContext = Context.prototype._popContext;
  796. Promise._peekContext = Promise.prototype._peekContext = peekContext;
  797. Promise.prototype._promiseCreated = function() {
  798. var ctx = this._peekContext();
  799. if (ctx && ctx._promiseCreated == null) ctx._promiseCreated = this;
  800. };
  801. };
  802. return Context;
  803. };
  804. },{}],9:[function(_dereq_,module,exports){
  805. "use strict";
  806. module.exports = function(Promise, Context) {
  807. var getDomain = Promise._getDomain;
  808. var async = Promise._async;
  809. var Warning = _dereq_("./errors").Warning;
  810. var util = _dereq_("./util");
  811. var canAttachTrace = util.canAttachTrace;
  812. var unhandledRejectionHandled;
  813. var possiblyUnhandledRejection;
  814. var bluebirdFramePattern =
  815. /[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/;
  816. var nodeFramePattern = /\((?:timers\.js):\d+:\d+\)/;
  817. var parseLinePattern = /[\/<\(](.+?):(\d+):(\d+)\)?\s*$/;
  818. var stackFramePattern = null;
  819. var formatStack = null;
  820. var indentStackFrames = false;
  821. var printWarning;
  822. var debugging = !!(util.env("BLUEBIRD_DEBUG") != 0 &&
  823. (true ||
  824. util.env("BLUEBIRD_DEBUG") ||
  825. util.env("NODE_ENV") === "development"));
  826. var warnings = !!(util.env("BLUEBIRD_WARNINGS") != 0 &&
  827. (debugging || util.env("BLUEBIRD_WARNINGS")));
  828. var longStackTraces = !!(util.env("BLUEBIRD_LONG_STACK_TRACES") != 0 &&
  829. (debugging || util.env("BLUEBIRD_LONG_STACK_TRACES")));
  830. var wForgottenReturn = util.env("BLUEBIRD_W_FORGOTTEN_RETURN") != 0 &&
  831. (warnings || !!util.env("BLUEBIRD_W_FORGOTTEN_RETURN"));
  832. Promise.prototype.suppressUnhandledRejections = function() {
  833. var target = this._target();
  834. target._bitField = ((target._bitField & (~1048576)) |
  835. 524288);
  836. };
  837. Promise.prototype._ensurePossibleRejectionHandled = function () {
  838. if ((this._bitField & 524288) !== 0) return;
  839. this._setRejectionIsUnhandled();
  840. async.invokeLater(this._notifyUnhandledRejection, this, undefined);
  841. };
  842. Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
  843. fireRejectionEvent("rejectionHandled",
  844. unhandledRejectionHandled, undefined, this);
  845. };
  846. Promise.prototype._setReturnedNonUndefined = function() {
  847. this._bitField = this._bitField | 268435456;
  848. };
  849. Promise.prototype._returnedNonUndefined = function() {
  850. return (this._bitField & 268435456) !== 0;
  851. };
  852. Promise.prototype._notifyUnhandledRejection = function () {
  853. if (this._isRejectionUnhandled()) {
  854. var reason = this._settledValue();
  855. this._setUnhandledRejectionIsNotified();
  856. fireRejectionEvent("unhandledRejection",
  857. possiblyUnhandledRejection, reason, this);
  858. }
  859. };
  860. Promise.prototype._setUnhandledRejectionIsNotified = function () {
  861. this._bitField = this._bitField | 262144;
  862. };
  863. Promise.prototype._unsetUnhandledRejectionIsNotified = function () {
  864. this._bitField = this._bitField & (~262144);
  865. };
  866. Promise.prototype._isUnhandledRejectionNotified = function () {
  867. return (this._bitField & 262144) > 0;
  868. };
  869. Promise.prototype._setRejectionIsUnhandled = function () {
  870. this._bitField = this._bitField | 1048576;
  871. };
  872. Promise.prototype._unsetRejectionIsUnhandled = function () {
  873. this._bitField = this._bitField & (~1048576);
  874. if (this._isUnhandledRejectionNotified()) {
  875. this._unsetUnhandledRejectionIsNotified();
  876. this._notifyUnhandledRejectionIsHandled();
  877. }
  878. };
  879. Promise.prototype._isRejectionUnhandled = function () {
  880. return (this._bitField & 1048576) > 0;
  881. };
  882. Promise.prototype._warn = function(message, shouldUseOwnTrace, promise) {
  883. return warn(message, shouldUseOwnTrace, promise || this);
  884. };
  885. Promise.onPossiblyUnhandledRejection = function (fn) {
  886. var domain = getDomain();
  887. possiblyUnhandledRejection =
  888. typeof fn === "function" ? (domain === null ?
  889. fn : util.domainBind(domain, fn))
  890. : undefined;
  891. };
  892. Promise.onUnhandledRejectionHandled = function (fn) {
  893. var domain = getDomain();
  894. unhandledRejectionHandled =
  895. typeof fn === "function" ? (domain === null ?
  896. fn : util.domainBind(domain, fn))
  897. : undefined;
  898. };
  899. var disableLongStackTraces = function() {};
  900. Promise.longStackTraces = function () {
  901. if (async.haveItemsQueued() && !config.longStackTraces) {
  902. throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  903. }
  904. if (!config.longStackTraces && longStackTracesIsSupported()) {
  905. var Promise_captureStackTrace = Promise.prototype._captureStackTrace;
  906. var Promise_attachExtraTrace = Promise.prototype._attachExtraTrace;
  907. config.longStackTraces = true;
  908. disableLongStackTraces = function() {
  909. if (async.haveItemsQueued() && !config.longStackTraces) {
  910. throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  911. }
  912. Promise.prototype._captureStackTrace = Promise_captureStackTrace;
  913. Promise.prototype._attachExtraTrace = Promise_attachExtraTrace;
  914. Context.deactivateLongStackTraces();
  915. async.enableTrampoline();
  916. config.longStackTraces = false;
  917. };
  918. Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace;
  919. Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace;
  920. Context.activateLongStackTraces();
  921. async.disableTrampolineIfNecessary();
  922. }
  923. };
  924. Promise.hasLongStackTraces = function () {
  925. return config.longStackTraces && longStackTracesIsSupported();
  926. };
  927. var fireDomEvent = (function() {
  928. try {
  929. if (typeof CustomEvent === "function") {
  930. var event = new CustomEvent("CustomEvent");
  931. util.global.dispatchEvent(event);
  932. return function(name, event) {
  933. var domEvent = new CustomEvent(name.toLowerCase(), {
  934. detail: event,
  935. cancelable: true
  936. });
  937. return !util.global.dispatchEvent(domEvent);
  938. };
  939. } else if (typeof Event === "function") {
  940. var event = new Event("CustomEvent");
  941. util.global.dispatchEvent(event);
  942. return function(name, event) {
  943. var domEvent = new Event(name.toLowerCase(), {
  944. cancelable: true
  945. });
  946. domEvent.detail = event;
  947. return !util.global.dispatchEvent(domEvent);
  948. };
  949. } else {
  950. var event = document.createEvent("CustomEvent");
  951. event.initCustomEvent("testingtheevent", false, true, {});
  952. util.global.dispatchEvent(event);
  953. return function(name, event) {
  954. var domEvent = document.createEvent("CustomEvent");
  955. domEvent.initCustomEvent(name.toLowerCase(), false, true,
  956. event);
  957. return !util.global.dispatchEvent(domEvent);
  958. };
  959. }
  960. } catch (e) {}
  961. return function() {
  962. return false;
  963. };
  964. })();
  965. var fireGlobalEvent = (function() {
  966. if (util.isNode) {
  967. return function() {
  968. return process.emit.apply(process, arguments);
  969. };
  970. } else {
  971. if (!util.global) {
  972. return function() {
  973. return false;
  974. };
  975. }
  976. return function(name) {
  977. var methodName = "on" + name.toLowerCase();
  978. var method = util.global[methodName];
  979. if (!method) return false;
  980. method.apply(util.global, [].slice.call(arguments, 1));
  981. return true;
  982. };
  983. }
  984. })();
  985. function generatePromiseLifecycleEventObject(name, promise) {
  986. return {promise: promise};
  987. }
  988. var eventToObjectGenerator = {
  989. promiseCreated: generatePromiseLifecycleEventObject,
  990. promiseFulfilled: generatePromiseLifecycleEventObject,
  991. promiseRejected: generatePromiseLifecycleEventObject,
  992. promiseResolved: generatePromiseLifecycleEventObject,
  993. promiseCancelled: generatePromiseLifecycleEventObject,
  994. promiseChained: function(name, promise, child) {
  995. return {promise: promise, child: child};
  996. },
  997. warning: function(name, warning) {
  998. return {warning: warning};
  999. },
  1000. unhandledRejection: function (name, reason, promise) {
  1001. return {reason: reason, promise: promise};
  1002. },
  1003. rejectionHandled: generatePromiseLifecycleEventObject
  1004. };
  1005. var activeFireEvent = function (name) {
  1006. var globalEventFired = false;
  1007. try {
  1008. globalEventFired = fireGlobalEvent.apply(null, arguments);
  1009. } catch (e) {
  1010. async.throwLater(e);
  1011. globalEventFired = true;
  1012. }
  1013. var domEventFired = false;
  1014. try {
  1015. domEventFired = fireDomEvent(name,
  1016. eventToObjectGenerator[name].apply(null, arguments));
  1017. } catch (e) {
  1018. async.throwLater(e);
  1019. domEventFired = true;
  1020. }
  1021. return domEventFired || globalEventFired;
  1022. };
  1023. Promise.config = function(opts) {
  1024. opts = Object(opts);
  1025. if ("longStackTraces" in opts) {
  1026. if (opts.longStackTraces) {
  1027. Promise.longStackTraces();
  1028. } else if (!opts.longStackTraces && Promise.hasLongStackTraces()) {
  1029. disableLongStackTraces();
  1030. }
  1031. }
  1032. if ("warnings" in opts) {
  1033. var warningsOption = opts.warnings;
  1034. config.warnings = !!warningsOption;
  1035. wForgottenReturn = config.warnings;
  1036. if (util.isObject(warningsOption)) {
  1037. if ("wForgottenReturn" in warningsOption) {
  1038. wForgottenReturn = !!warningsOption.wForgottenReturn;
  1039. }
  1040. }
  1041. }
  1042. if ("cancellation" in opts && opts.cancellation && !config.cancellation) {
  1043. if (async.haveItemsQueued()) {
  1044. throw new Error(
  1045. "cannot enable cancellation after promises are in use");
  1046. }
  1047. Promise.prototype._clearCancellationData =
  1048. cancellationClearCancellationData;
  1049. Promise.prototype._propagateFrom = cancellationPropagateFrom;
  1050. Promise.prototype._onCancel = cancellationOnCancel;
  1051. Promise.prototype._setOnCancel = cancellationSetOnCancel;
  1052. Promise.prototype._attachCancellationCallback =
  1053. cancellationAttachCancellationCallback;
  1054. Promise.prototype._execute = cancellationExecute;
  1055. propagateFromFunction = cancellationPropagateFrom;
  1056. config.cancellation = true;
  1057. }
  1058. if ("monitoring" in opts) {
  1059. if (opts.monitoring && !config.monitoring) {
  1060. config.monitoring = true;
  1061. Promise.prototype._fireEvent = activeFireEvent;
  1062. } else if (!opts.monitoring && config.monitoring) {
  1063. config.monitoring = false;
  1064. Promise.prototype._fireEvent = defaultFireEvent;
  1065. }
  1066. }
  1067. };
  1068. function defaultFireEvent() { return false; }
  1069. Promise.prototype._fireEvent = defaultFireEvent;
  1070. Promise.prototype._execute = function(executor, resolve, reject) {
  1071. try {
  1072. executor(resolve, reject);
  1073. } catch (e) {
  1074. return e;
  1075. }
  1076. };
  1077. Promise.prototype._onCancel = function () {};
  1078. Promise.prototype._setOnCancel = function (handler) { ; };
  1079. Promise.prototype._attachCancellationCallback = function(onCancel) {
  1080. ;
  1081. };
  1082. Promise.prototype._captureStackTrace = function () {};
  1083. Promise.prototype._attachExtraTrace = function () {};
  1084. Promise.prototype._clearCancellationData = function() {};
  1085. Promise.prototype._propagateFrom = function (parent, flags) {
  1086. ;
  1087. ;
  1088. };
  1089. function cancellationExecute(executor, resolve, reject) {
  1090. var promise = this;
  1091. try {
  1092. executor(resolve, reject, function(onCancel) {
  1093. if (typeof onCancel !== "function") {
  1094. throw new TypeError("onCancel must be a function, got: " +
  1095. util.toString(onCancel));
  1096. }
  1097. promise._attachCancellationCallback(onCancel);
  1098. });
  1099. } catch (e) {
  1100. return e;
  1101. }
  1102. }
  1103. function cancellationAttachCancellationCallback(onCancel) {
  1104. if (!this._isCancellable()) return this;
  1105. var previousOnCancel = this._onCancel();
  1106. if (previousOnCancel !== undefined) {
  1107. if (util.isArray(previousOnCancel)) {
  1108. previousOnCancel.push(onCancel);
  1109. } else {
  1110. this._setOnCancel([previousOnCancel, onCancel]);
  1111. }
  1112. } else {
  1113. this._setOnCancel(onCancel);
  1114. }
  1115. }
  1116. function cancellationOnCancel() {
  1117. return this._onCancelField;
  1118. }
  1119. function cancellationSetOnCancel(onCancel) {
  1120. this._onCancelField = onCancel;
  1121. }
  1122. function cancellationClearCancellationData() {
  1123. this._cancellationParent = undefined;
  1124. this._onCancelField = undefined;
  1125. }
  1126. function cancellationPropagateFrom(parent, flags) {
  1127. if ((flags & 1) !== 0) {
  1128. this._cancellationParent = parent;
  1129. var branchesRemainingToCancel = parent._branchesRemainingToCancel;
  1130. if (branchesRemainingToCancel === undefined) {
  1131. branchesRemainingToCancel = 0;
  1132. }
  1133. parent._branchesRemainingToCancel = branchesRemainingToCancel + 1;
  1134. }
  1135. if ((flags & 2) !== 0 && parent._isBound()) {
  1136. this._setBoundTo(parent._boundTo);
  1137. }
  1138. }
  1139. function bindingPropagateFrom(parent, flags) {
  1140. if ((flags & 2) !== 0 && parent._isBound()) {
  1141. this._setBoundTo(parent._boundTo);
  1142. }
  1143. }
  1144. var propagateFromFunction = bindingPropagateFrom;
  1145. function boundValueFunction() {
  1146. var ret = this._boundTo;
  1147. if (ret !== undefined) {
  1148. if (ret instanceof Promise) {
  1149. if (ret.isFulfilled()) {
  1150. return ret.value();
  1151. } else {
  1152. return undefined;
  1153. }
  1154. }
  1155. }
  1156. return ret;
  1157. }
  1158. function longStackTracesCaptureStackTrace() {
  1159. this._trace = new CapturedTrace(this._peekContext());
  1160. }
  1161. function longStackTracesAttachExtraTrace(error, ignoreSelf) {
  1162. if (canAttachTrace(error)) {
  1163. var trace = this._trace;
  1164. if (trace !== undefined) {
  1165. if (ignoreSelf) trace = trace._parent;
  1166. }
  1167. if (trace !== undefined) {
  1168. trace.attachExtraTrace(error);
  1169. } else if (!error.__stackCleaned__) {
  1170. var parsed = parseStackAndMessage(error);
  1171. util.notEnumerableProp(error, "stack",
  1172. parsed.message + "\n" + parsed.stack.join("\n"));
  1173. util.notEnumerableProp(error, "__stackCleaned__", true);
  1174. }
  1175. }
  1176. }
  1177. function checkForgottenReturns(returnValue, promiseCreated, name, promise,
  1178. parent) {
  1179. if (returnValue === undefined && promiseCreated !== null &&
  1180. wForgottenReturn) {
  1181. if (parent !== undefined && parent._returnedNonUndefined()) return;
  1182. if ((promise._bitField & 65535) === 0) return;
  1183. if (name) name = name + " ";
  1184. var handlerLine = "";
  1185. var creatorLine = "";
  1186. if (promiseCreated._trace) {
  1187. var traceLines = promiseCreated._trace.stack.split("\n");
  1188. var stack = cleanStack(traceLines);
  1189. for (var i = stack.length - 1; i >= 0; --i) {
  1190. var line = stack[i];
  1191. if (!nodeFramePattern.test(line)) {
  1192. var lineMatches = line.match(parseLinePattern);
  1193. if (lineMatches) {
  1194. handlerLine = "at " + lineMatches[1] +
  1195. ":" + lineMatches[2] + ":" + lineMatches[3] + " ";
  1196. }
  1197. break;
  1198. }
  1199. }
  1200. if (stack.length > 0) {
  1201. var firstUserLine = stack[0];
  1202. for (var i = 0; i < traceLines.length; ++i) {
  1203. if (traceLines[i] === firstUserLine) {
  1204. if (i > 0) {
  1205. creatorLine = "\n" + traceLines[i - 1];
  1206. }
  1207. break;
  1208. }
  1209. }
  1210. }
  1211. }
  1212. var msg = "a promise was created in a " + name +
  1213. "handler " + handlerLine + "but was not returned from it, " +
  1214. "see http://goo.gl/rRqMUw" +
  1215. creatorLine;
  1216. promise._warn(msg, true, promiseCreated);
  1217. }
  1218. }
  1219. function deprecated(name, replacement) {
  1220. var message = name +
  1221. " is deprecated and will be removed in a future version.";
  1222. if (replacement) message += " Use " + replacement + " instead.";
  1223. return warn(message);
  1224. }
  1225. function warn(message, shouldUseOwnTrace, promise) {
  1226. if (!config.warnings) return;
  1227. var warning = new Warning(message);
  1228. var ctx;
  1229. if (shouldUseOwnTrace) {
  1230. promise._attachExtraTrace(warning);
  1231. } else if (config.longStackTraces && (ctx = Promise._peekContext())) {
  1232. ctx.attachExtraTrace(warning);
  1233. } else {
  1234. var parsed = parseStackAndMessage(warning);
  1235. warning.stack = parsed.message + "\n" + parsed.stack.join("\n");
  1236. }
  1237. if (!activeFireEvent("warning", warning)) {
  1238. formatAndLogError(warning, "", true);
  1239. }
  1240. }
  1241. function reconstructStack(message, stacks) {
  1242. for (var i = 0; i < stacks.length - 1; ++i) {
  1243. stacks[i].push("From previous event:");
  1244. stacks[i] = stacks[i].join("\n");
  1245. }
  1246. if (i < stacks.length) {
  1247. stacks[i] = stacks[i].join("\n");
  1248. }
  1249. return message + "\n" + stacks.join("\n");
  1250. }
  1251. function removeDuplicateOrEmptyJumps(stacks) {
  1252. for (var i = 0; i < stacks.length; ++i) {
  1253. if (stacks[i].length === 0 ||
  1254. ((i + 1 < stacks.length) && stacks[i][0] === stacks[i+1][0])) {
  1255. stacks.splice(i, 1);
  1256. i--;
  1257. }
  1258. }
  1259. }
  1260. function removeCommonRoots(stacks) {
  1261. var current = stacks[0];
  1262. for (var i = 1; i < stacks.length; ++i) {
  1263. var prev = stacks[i];
  1264. var currentLastIndex = current.length - 1;
  1265. var currentLastLine = current[currentLastIndex];
  1266. var commonRootMeetPoint = -1;
  1267. for (var j = prev.length - 1; j >= 0; --j) {
  1268. if (prev[j] === currentLastLine) {
  1269. commonRootMeetPoint = j;
  1270. break;
  1271. }
  1272. }
  1273. for (var j = commonRootMeetPoint; j >= 0; --j) {
  1274. var line = prev[j];
  1275. if (current[currentLastIndex] === line) {
  1276. current.pop();
  1277. currentLastIndex--;
  1278. } else {
  1279. break;
  1280. }
  1281. }
  1282. current = prev;
  1283. }
  1284. }
  1285. function cleanStack(stack) {
  1286. var ret = [];
  1287. for (var i = 0; i < stack.length; ++i) {
  1288. var line = stack[i];
  1289. var isTraceLine = " (No stack trace)" === line ||
  1290. stackFramePattern.test(line);
  1291. var isInternalFrame = isTraceLine && shouldIgnore(line);
  1292. if (isTraceLine && !isInternalFrame) {
  1293. if (indentStackFrames && line.charAt(0) !== " ") {
  1294. line = " " + line;
  1295. }
  1296. ret.push(line);
  1297. }
  1298. }
  1299. return ret;
  1300. }
  1301. function stackFramesAsArray(error) {
  1302. var stack = error.stack.replace(/\s+$/g, "").split("\n");
  1303. for (var i = 0; i < stack.length; ++i) {
  1304. var line = stack[i];
  1305. if (" (No stack trace)" === line || stackFramePattern.test(line)) {
  1306. break;
  1307. }
  1308. }
  1309. if (i > 0) {
  1310. stack = stack.slice(i);
  1311. }
  1312. return stack;
  1313. }
  1314. function parseStackAndMessage(error) {
  1315. var stack = error.stack;
  1316. var message = error.toString();
  1317. stack = typeof stack === "string" && stack.length > 0
  1318. ? stackFramesAsArray(error) : [" (No stack trace)"];
  1319. return {
  1320. message: message,
  1321. stack: cleanStack(stack)
  1322. };
  1323. }
  1324. function formatAndLogError(error, title, isSoft) {
  1325. if (typeof console !== "undefined") {
  1326. var message;
  1327. if (util.isObject(error)) {
  1328. var stack = error.stack;
  1329. message = title + formatStack(stack, error);
  1330. } else {
  1331. message = title + String(error);
  1332. }
  1333. if (typeof printWarning === "function") {
  1334. printWarning(message, isSoft);
  1335. } else if (typeof console.log === "function" ||
  1336. typeof console.log === "object") {
  1337. console.log(message);
  1338. }
  1339. }
  1340. }
  1341. function fireRejectionEvent(name, localHandler, reason, promise) {
  1342. var localEventFired = false;
  1343. try {
  1344. if (typeof localHandler === "function") {
  1345. localEventFired = true;
  1346. if (name === "rejectionHandled") {
  1347. localHandler(promise);
  1348. } else {
  1349. localHandler(reason, promise);
  1350. }
  1351. }
  1352. } catch (e) {
  1353. async.throwLater(e);
  1354. }
  1355. if (name === "unhandledRejection") {
  1356. if (!activeFireEvent(name, reason, promise) && !localEventFired) {
  1357. formatAndLogError(reason, "Unhandled rejection ");
  1358. }
  1359. } else {
  1360. activeFireEvent(name, promise);
  1361. }
  1362. }
  1363. function formatNonError(obj) {
  1364. var str;
  1365. if (typeof obj === "function") {
  1366. str = "[function " +
  1367. (obj.name || "anonymous") +
  1368. "]";
  1369. } else {
  1370. str = obj && typeof obj.toString === "function"
  1371. ? obj.toString() : util.toString(obj);
  1372. var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
  1373. if (ruselessToString.test(str)) {
  1374. try {
  1375. var newStr = JSON.stringify(obj);
  1376. str = newStr;
  1377. }
  1378. catch(e) {
  1379. }
  1380. }
  1381. if (str.length === 0) {
  1382. str = "(empty array)";
  1383. }
  1384. }
  1385. return ("(<" + snip(str) + ">, no stack trace)");
  1386. }
  1387. function snip(str) {
  1388. var maxChars = 41;
  1389. if (str.length < maxChars) {
  1390. return str;
  1391. }
  1392. return str.substr(0, maxChars - 3) + "...";
  1393. }
  1394. function longStackTracesIsSupported() {
  1395. return typeof captureStackTrace === "function";
  1396. }
  1397. var shouldIgnore = function() { return false; };
  1398. var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;
  1399. function parseLineInfo(line) {
  1400. var matches = line.match(parseLineInfoRegex);
  1401. if (matches) {
  1402. return {
  1403. fileName: matches[1],
  1404. line: parseInt(matches[2], 10)
  1405. };
  1406. }
  1407. }
  1408. function setBounds(firstLineError, lastLineError) {
  1409. if (!longStackTracesIsSupported()) return;
  1410. var firstStackLines = firstLineError.stack.split("\n");
  1411. var lastStackLines = lastLineError.stack.split("\n");
  1412. var firstIndex = -1;
  1413. var lastIndex = -1;
  1414. var firstFileName;
  1415. var lastFileName;
  1416. for (var i = 0; i < firstStackLines.length; ++i) {
  1417. var result = parseLineInfo(firstStackLines[i]);
  1418. if (result) {
  1419. firstFileName = result.fileName;
  1420. firstIndex = result.line;
  1421. break;
  1422. }
  1423. }
  1424. for (var i = 0; i < lastStackLines.length; ++i) {
  1425. var result = parseLineInfo(lastStackLines[i]);
  1426. if (result) {
  1427. lastFileName = result.fileName;
  1428. lastIndex = result.line;
  1429. break;
  1430. }
  1431. }
  1432. if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName ||
  1433. firstFileName !== lastFileName || firstIndex >= lastIndex) {
  1434. return;
  1435. }
  1436. shouldIgnore = function(line) {
  1437. if (bluebirdFramePattern.test(line)) return true;
  1438. var info = parseLineInfo(line);
  1439. if (info) {
  1440. if (info.fileName === firstFileName &&
  1441. (firstIndex <= info.line && info.line <= lastIndex)) {
  1442. return true;
  1443. }
  1444. }
  1445. return false;
  1446. };
  1447. }
  1448. function CapturedTrace(parent) {
  1449. this._parent = parent;
  1450. this._promisesCreated = 0;
  1451. var length = this._length = 1 + (parent === undefined ? 0 : parent._length);
  1452. captureStackTrace(this, CapturedTrace);
  1453. if (length > 32) this.uncycle();
  1454. }
  1455. util.inherits(CapturedTrace, Error);
  1456. Context.CapturedTrace = CapturedTrace;
  1457. CapturedTrace.prototype.uncycle = function() {
  1458. var length = this._length;
  1459. if (length < 2) return;
  1460. var nodes = [];
  1461. var stackToIndex = {};
  1462. for (var i = 0, node = this; node !== undefined; ++i) {
  1463. nodes.push(node);
  1464. node = node._parent;
  1465. }
  1466. length = this._length = i;
  1467. for (var i = length - 1; i >= 0; --i) {
  1468. var stack = nodes[i].stack;
  1469. if (stackToIndex[stack] === undefined) {
  1470. stackToIndex[stack] = i;
  1471. }
  1472. }
  1473. for (var i = 0; i < length; ++i) {
  1474. var currentStack = nodes[i].stack;
  1475. var index = stackToIndex[currentStack];
  1476. if (index !== undefined && index !== i) {
  1477. if (index > 0) {
  1478. nodes[index - 1]._parent = undefined;
  1479. nodes[index - 1]._length = 1;
  1480. }
  1481. nodes[i]._parent = undefined;
  1482. nodes[i]._length = 1;
  1483. var cycleEdgeNode = i > 0 ? nodes[i - 1] : this;
  1484. if (index < length - 1) {
  1485. cycleEdgeNode._parent = nodes[index + 1];
  1486. cycleEdgeNode._parent.uncycle();
  1487. cycleEdgeNode._length =
  1488. cycleEdgeNode._parent._length + 1;
  1489. } else {
  1490. cycleEdgeNode._parent = undefined;
  1491. cycleEdgeNode._length = 1;
  1492. }
  1493. var currentChildLength = cycleEdgeNode._length + 1;
  1494. for (var j = i - 2; j >= 0; --j) {
  1495. nodes[j]._length = currentChildLength;
  1496. currentChildLength++;
  1497. }
  1498. return;
  1499. }
  1500. }
  1501. };
  1502. CapturedTrace.prototype.attachExtraTrace = function(error) {
  1503. if (error.__stackCleaned__) return;
  1504. this.uncycle();
  1505. var parsed = parseStackAndMessage(error);
  1506. var message = parsed.message;
  1507. var stacks = [parsed.stack];
  1508. var trace = this;
  1509. while (trace !== undefined) {
  1510. stacks.push(cleanStack(trace.stack.split("\n")));
  1511. trace = trace._parent;
  1512. }
  1513. removeCommonRoots(stacks);
  1514. removeDuplicateOrEmptyJumps(stacks);
  1515. util.notEnumerableProp(error, "stack", reconstructStack(message, stacks));
  1516. util.notEnumerableProp(error, "__stackCleaned__", true);
  1517. };
  1518. var captureStackTrace = (function stackDetection() {
  1519. var v8stackFramePattern = /^\s*at\s*/;
  1520. var v8stackFormatter = function(stack, error) {
  1521. if (typeof stack === "string") return stack;
  1522. if (error.name !== undefined &&
  1523. error.message !== undefined) {
  1524. return error.toString();
  1525. }
  1526. return formatNonError(error);
  1527. };
  1528. if (typeof Error.stackTraceLimit === "number" &&
  1529. typeof Error.captureStackTrace === "function") {
  1530. Error.stackTraceLimit += 6;
  1531. stackFramePattern = v8stackFramePattern;
  1532. formatStack = v8stackFormatter;
  1533. var captureStackTrace = Error.captureStackTrace;
  1534. shouldIgnore = function(line) {
  1535. return bluebirdFramePattern.test(line);
  1536. };
  1537. return function(receiver, ignoreUntil) {
  1538. Error.stackTraceLimit += 6;
  1539. captureStackTrace(receiver, ignoreUntil);
  1540. Error.stackTraceLimit -= 6;
  1541. };
  1542. }
  1543. var err = new Error();
  1544. if (typeof err.stack === "string" &&
  1545. err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) {
  1546. stackFramePattern = /@/;
  1547. formatStack = v8stackFormatter;
  1548. indentStackFrames = true;
  1549. return function captureStackTrace(o) {
  1550. o.stack = new Error().stack;
  1551. };
  1552. }
  1553. var hasStackAfterThrow;
  1554. try { throw new Error(); }
  1555. catch(e) {
  1556. hasStackAfterThrow = ("stack" in e);
  1557. }
  1558. if (!("stack" in err) && hasStackAfterThrow &&
  1559. typeof Error.stackTraceLimit === "number") {
  1560. stackFramePattern = v8stackFramePattern;
  1561. formatStack = v8stackFormatter;
  1562. return function captureStackTrace(o) {
  1563. Error.stackTraceLimit += 6;
  1564. try { throw new Error(); }
  1565. catch(e) { o.stack = e.stack; }
  1566. Error.stackTraceLimit -= 6;
  1567. };
  1568. }
  1569. formatStack = function(stack, error) {
  1570. if (typeof stack === "string") return stack;
  1571. if ((typeof error === "object" ||
  1572. typeof error === "function") &&
  1573. error.name !== undefined &&
  1574. error.message !== undefined) {
  1575. return error.toString();
  1576. }
  1577. return formatNonError(error);
  1578. };
  1579. return null;
  1580. })([]);
  1581. if (typeof console !== "undefined" && typeof console.warn !== "undefined") {
  1582. printWarning = function (message) {
  1583. console.warn(message);
  1584. };
  1585. if (util.isNode && process.stderr.isTTY) {
  1586. printWarning = function(message, isSoft) {
  1587. var color = isSoft ? "\u001b[33m" : "\u001b[31m";
  1588. console.warn(color + message + "\u001b[0m\n");
  1589. };
  1590. } else if (!util.isNode && typeof (new Error().stack) === "string") {
  1591. printWarning = function(message, isSoft) {
  1592. console.warn("%c" + message,
  1593. isSoft ? "color: darkorange" : "color: red");
  1594. };
  1595. }
  1596. }
  1597. var config = {
  1598. warnings: warnings,
  1599. longStackTraces: false,
  1600. cancellation: false,
  1601. monitoring: false
  1602. };
  1603. if (longStackTraces) Promise.longStackTraces();
  1604. return {
  1605. longStackTraces: function() {
  1606. return config.longStackTraces;
  1607. },
  1608. warnings: function() {
  1609. return config.warnings;
  1610. },
  1611. cancellation: function() {
  1612. return config.cancellation;
  1613. },
  1614. monitoring: function() {
  1615. return config.monitoring;
  1616. },
  1617. propagateFromFunction: function() {
  1618. return propagateFromFunction;
  1619. },
  1620. boundValueFunction: function() {
  1621. return boundValueFunction;
  1622. },
  1623. checkForgottenReturns: checkForgottenReturns,
  1624. setBounds: setBounds,
  1625. warn: warn,
  1626. deprecated: deprecated,
  1627. CapturedTrace: CapturedTrace,
  1628. fireDomEvent: fireDomEvent,
  1629. fireGlobalEvent: fireGlobalEvent
  1630. };
  1631. };
  1632. },{"./errors":12,"./util":36}],10:[function(_dereq_,module,exports){
  1633. "use strict";
  1634. module.exports = function(Promise) {
  1635. function returner() {
  1636. return this.value;
  1637. }
  1638. function thrower() {
  1639. throw this.reason;
  1640. }
  1641. Promise.prototype["return"] =
  1642. Promise.prototype.thenReturn = function (value) {
  1643. if (value instanceof Promise) value.suppressUnhandledRejections();
  1644. return this._then(
  1645. returner, undefined, undefined, {value: value}, undefined);
  1646. };
  1647. Promise.prototype["throw"] =
  1648. Promise.prototype.thenThrow = function (reason) {
  1649. return this._then(
  1650. thrower, undefined, undefined, {reason: reason}, undefined);
  1651. };
  1652. Promise.prototype.catchThrow = function (reason) {
  1653. if (arguments.length <= 1) {
  1654. return this._then(
  1655. undefined, thrower, undefined, {reason: reason}, undefined);
  1656. } else {
  1657. var _reason = arguments[1];
  1658. var handler = function() {throw _reason;};
  1659. return this.caught(reason, handler);
  1660. }
  1661. };
  1662. Promise.prototype.catchReturn = function (value) {
  1663. if (arguments.length <= 1) {
  1664. if (value instanceof Promise) value.suppressUnhandledRejections();
  1665. return this._then(
  1666. undefined, returner, undefined, {value: value}, undefined);
  1667. } else {
  1668. var _value = arguments[1];
  1669. if (_value instanceof Promise) _value.suppressUnhandledRejections();
  1670. var handler = function() {return _value;};
  1671. return this.caught(value, handler);
  1672. }
  1673. };
  1674. };
  1675. },{}],11:[function(_dereq_,module,exports){
  1676. "use strict";
  1677. module.exports = function(Promise, INTERNAL) {
  1678. var PromiseReduce = Promise.reduce;
  1679. var PromiseAll = Promise.all;
  1680. function promiseAllThis() {
  1681. return PromiseAll(this);
  1682. }
  1683. function PromiseMapSeries(promises, fn) {
  1684. return PromiseReduce(promises, fn, INTERNAL, INTERNAL);
  1685. }
  1686. Promise.prototype.each = function (fn) {
  1687. return PromiseReduce(this, fn, INTERNAL, 0)
  1688. ._then(promiseAllThis, undefined, undefined, this, undefined);
  1689. };
  1690. Promise.prototype.mapSeries = function (fn) {
  1691. return PromiseReduce(this, fn, INTERNAL, INTERNAL);
  1692. };
  1693. Promise.each = function (promises, fn) {
  1694. return PromiseReduce(promises, fn, INTERNAL, 0)
  1695. ._then(promiseAllThis, undefined, undefined, promises, undefined);
  1696. };
  1697. Promise.mapSeries = PromiseMapSeries;
  1698. };
  1699. },{}],12:[function(_dereq_,module,exports){
  1700. "use strict";
  1701. var es5 = _dereq_("./es5");
  1702. var Objectfreeze = es5.freeze;
  1703. var util = _dereq_("./util");
  1704. var inherits = util.inherits;
  1705. var notEnumerableProp = util.notEnumerableProp;
  1706. function subError(nameProperty, defaultMessage) {
  1707. function SubError(message) {
  1708. if (!(this instanceof SubError)) return new SubError(message);
  1709. notEnumerableProp(this, "message",
  1710. typeof message === "string" ? message : defaultMessage);
  1711. notEnumerableProp(this, "name", nameProperty);
  1712. if (Error.captureStackTrace) {
  1713. Error.captureStackTrace(this, this.constructor);
  1714. } else {
  1715. Error.call(this);
  1716. }
  1717. }
  1718. inherits(SubError, Error);
  1719. return SubError;
  1720. }
  1721. var _TypeError, _RangeError;
  1722. var Warning = subError("Warning", "warning");
  1723. var CancellationError = subError("CancellationError", "cancellation error");
  1724. var TimeoutError = subError("TimeoutError", "timeout error");
  1725. var AggregateError = subError("AggregateError", "aggregate error");
  1726. try {
  1727. _TypeError = TypeError;
  1728. _RangeError = RangeError;
  1729. } catch(e) {
  1730. _TypeError = subError("TypeError", "type error");
  1731. _RangeError = subError("RangeError", "range error");
  1732. }
  1733. var methods = ("join pop push shift unshift slice filter forEach some " +
  1734. "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" ");
  1735. for (var i = 0; i < methods.length; ++i) {
  1736. if (typeof Array.prototype[methods[i]] === "function") {
  1737. AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];
  1738. }
  1739. }
  1740. es5.defineProperty(AggregateError.prototype, "length", {
  1741. value: 0,
  1742. configurable: false,
  1743. writable: true,
  1744. enumerable: true
  1745. });
  1746. AggregateError.prototype["isOperational"] = true;
  1747. var level = 0;
  1748. AggregateError.prototype.toString = function() {
  1749. var indent = Array(level * 4 + 1).join(" ");
  1750. var ret = "\n" + indent + "AggregateError of:" + "\n";
  1751. level++;
  1752. indent = Array(level * 4 + 1).join(" ");
  1753. for (var i = 0; i < this.length; ++i) {
  1754. var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";
  1755. var lines = str.split("\n");
  1756. for (var j = 0; j < lines.length; ++j) {
  1757. lines[j] = indent + lines[j];
  1758. }
  1759. str = lines.join("\n");
  1760. ret += str + "\n";
  1761. }
  1762. level--;
  1763. return ret;
  1764. };
  1765. function OperationalError(message) {
  1766. if (!(this instanceof OperationalError))
  1767. return new OperationalError(message);
  1768. notEnumerableProp(this, "name", "OperationalError");
  1769. notEnumerableProp(this, "message", message);
  1770. this.cause = message;
  1771. this["isOperational"] = true;
  1772. if (message instanceof Error) {
  1773. notEnumerableProp(this, "message", message.message);
  1774. notEnumerableProp(this, "stack", message.stack);
  1775. } else if (Error.captureStackTrace) {
  1776. Error.captureStackTrace(this, this.constructor);
  1777. }
  1778. }
  1779. inherits(OperationalError, Error);
  1780. var errorTypes = Error["__BluebirdErrorTypes__"];
  1781. if (!errorTypes) {
  1782. errorTypes = Objectfreeze({
  1783. CancellationError: CancellationError,
  1784. TimeoutError: TimeoutError,
  1785. OperationalError: OperationalError,
  1786. RejectionError: OperationalError,
  1787. AggregateError: AggregateError
  1788. });
  1789. es5.defineProperty(Error, "__BluebirdErrorTypes__", {
  1790. value: errorTypes,
  1791. writable: false,
  1792. enumerable: false,
  1793. configurable: false
  1794. });
  1795. }
  1796. module.exports = {
  1797. Error: Error,
  1798. TypeError: _TypeError,
  1799. RangeError: _RangeError,
  1800. CancellationError: errorTypes.CancellationError,
  1801. OperationalError: errorTypes.OperationalError,
  1802. TimeoutError: errorTypes.TimeoutError,
  1803. AggregateError: errorTypes.AggregateError,
  1804. Warning: Warning
  1805. };
  1806. },{"./es5":13,"./util":36}],13:[function(_dereq_,module,exports){
  1807. var isES5 = (function(){
  1808. "use strict";
  1809. return this === undefined;
  1810. })();
  1811. if (isES5) {
  1812. module.exports = {
  1813. freeze: Object.freeze,
  1814. defineProperty: Object.defineProperty,
  1815. getDescriptor: Object.getOwnPropertyDescriptor,
  1816. keys: Object.keys,
  1817. names: Object.getOwnPropertyNames,
  1818. getPrototypeOf: Object.getPrototypeOf,
  1819. isArray: Array.isArray,
  1820. isES5: isES5,
  1821. propertyIsWritable: function(obj, prop) {
  1822. var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
  1823. return !!(!descriptor || descriptor.writable || descriptor.set);
  1824. }
  1825. };
  1826. } else {
  1827. var has = {}.hasOwnProperty;
  1828. var str = {}.toString;
  1829. var proto = {}.constructor.prototype;
  1830. var ObjectKeys = function (o) {
  1831. var ret = [];
  1832. for (var key in o) {
  1833. if (has.call(o, key)) {
  1834. ret.push(key);
  1835. }
  1836. }
  1837. return ret;
  1838. };
  1839. var ObjectGetDescriptor = function(o, key) {
  1840. return {value: o[key]};
  1841. };
  1842. var ObjectDefineProperty = function (o, key, desc) {
  1843. o[key] = desc.value;
  1844. return o;
  1845. };
  1846. var ObjectFreeze = function (obj) {
  1847. return obj;
  1848. };
  1849. var ObjectGetPrototypeOf = function (obj) {
  1850. try {
  1851. return Object(obj).constructor.prototype;
  1852. }
  1853. catch (e) {
  1854. return proto;
  1855. }
  1856. };
  1857. var ArrayIsArray = function (obj) {
  1858. try {
  1859. return str.call(obj) === "[object Array]";
  1860. }
  1861. catch(e) {
  1862. return false;
  1863. }
  1864. };
  1865. module.exports = {
  1866. isArray: ArrayIsArray,
  1867. keys: ObjectKeys,
  1868. names: ObjectKeys,
  1869. defineProperty: ObjectDefineProperty,
  1870. getDescriptor: ObjectGetDescriptor,
  1871. freeze: ObjectFreeze,
  1872. getPrototypeOf: ObjectGetPrototypeOf,
  1873. isES5: isES5,
  1874. propertyIsWritable: function() {
  1875. return true;
  1876. }
  1877. };
  1878. }
  1879. },{}],14:[function(_dereq_,module,exports){
  1880. "use strict";
  1881. module.exports = function(Promise, INTERNAL) {
  1882. var PromiseMap = Promise.map;
  1883. Promise.prototype.filter = function (fn, options) {
  1884. return PromiseMap(this, fn, options, INTERNAL);
  1885. };
  1886. Promise.filter = function (promises, fn, options) {
  1887. return PromiseMap(promises, fn, options, INTERNAL);
  1888. };
  1889. };
  1890. },{}],15:[function(_dereq_,module,exports){
  1891. "use strict";
  1892. module.exports = function(Promise, tryConvertToPromise) {
  1893. var util = _dereq_("./util");
  1894. var CancellationError = Promise.CancellationError;
  1895. var errorObj = util.errorObj;
  1896. function PassThroughHandlerContext(promise, type, handler) {
  1897. this.promise = promise;
  1898. this.type = type;
  1899. this.handler = handler;
  1900. this.called = false;
  1901. this.cancelPromise = null;
  1902. }
  1903. PassThroughHandlerContext.prototype.isFinallyHandler = function() {
  1904. return this.type === 0;
  1905. };
  1906. function FinallyHandlerCancelReaction(finallyHandler) {
  1907. this.finallyHandler = finallyHandler;
  1908. }
  1909. FinallyHandlerCancelReaction.prototype._resultCancelled = function() {
  1910. checkCancel(this.finallyHandler);
  1911. };
  1912. function checkCancel(ctx, reason) {
  1913. if (ctx.cancelPromise != null) {
  1914. if (arguments.length > 1) {
  1915. ctx.cancelPromise._reject(reason);
  1916. } else {
  1917. ctx.cancelPromise._cancel();
  1918. }
  1919. ctx.cancelPromise = null;
  1920. return true;
  1921. }
  1922. return false;
  1923. }
  1924. function succeed() {
  1925. return finallyHandler.call(this, this.promise._target()._settledValue());
  1926. }
  1927. function fail(reason) {
  1928. if (checkCancel(this, reason)) return;
  1929. errorObj.e = reason;
  1930. return errorObj;
  1931. }
  1932. function finallyHandler(reasonOrValue) {
  1933. var promise = this.promise;
  1934. var handler = this.handler;
  1935. if (!this.called) {
  1936. this.called = true;
  1937. var ret = this.isFinallyHandler()
  1938. ? handler.call(promise._boundValue())
  1939. : handler.call(promise._boundValue(), reasonOrValue);
  1940. if (ret !== undefined) {
  1941. promise._setReturnedNonUndefined();
  1942. var maybePromise = tryConvertToPromise(ret, promise);
  1943. if (maybePromise instanceof Promise) {
  1944. if (this.cancelPromise != null) {
  1945. if (maybePromise._isCancelled()) {
  1946. var reason =
  1947. new CancellationError("late cancellation observer");
  1948. promise._attachExtraTrace(reason);
  1949. errorObj.e = reason;
  1950. return errorObj;
  1951. } else if (maybePromise.isPending()) {
  1952. maybePromise._attachCancellationCallback(
  1953. new FinallyHandlerCancelReaction(this));
  1954. }
  1955. }
  1956. return maybePromise._then(
  1957. succeed, fail, undefined, this, undefined);
  1958. }
  1959. }
  1960. }
  1961. if (promise.isRejected()) {
  1962. checkCancel(this);
  1963. errorObj.e = reasonOrValue;
  1964. return errorObj;
  1965. } else {
  1966. checkCancel(this);
  1967. return reasonOrValue;
  1968. }
  1969. }
  1970. Promise.prototype._passThrough = function(handler, type, success, fail) {
  1971. if (typeof handler !== "function") return this.then();
  1972. return this._then(success,
  1973. fail,
  1974. undefined,
  1975. new PassThroughHandlerContext(this, type, handler),
  1976. undefined);
  1977. };
  1978. Promise.prototype.lastly =
  1979. Promise.prototype["finally"] = function (handler) {
  1980. return this._passThrough(handler,
  1981. 0,
  1982. finallyHandler,
  1983. finallyHandler);
  1984. };
  1985. Promise.prototype.tap = function (handler) {
  1986. return this._passThrough(handler, 1, finallyHandler);
  1987. };
  1988. return PassThroughHandlerContext;
  1989. };
  1990. },{"./util":36}],16:[function(_dereq_,module,exports){
  1991. "use strict";
  1992. module.exports = function(Promise,
  1993. apiRejection,
  1994. INTERNAL,
  1995. tryConvertToPromise,
  1996. Proxyable,
  1997. debug) {
  1998. var errors = _dereq_("./errors");
  1999. var TypeError = errors.TypeError;
  2000. var util = _dereq_("./util");
  2001. var errorObj = util.errorObj;
  2002. var tryCatch = util.tryCatch;
  2003. var yieldHandlers = [];
  2004. function promiseFromYieldHandler(value, yieldHandlers, traceParent) {
  2005. for (var i = 0; i < yieldHandlers.length; ++i) {
  2006. traceParent._pushContext();
  2007. var result = tryCatch(yieldHandlers[i])(value);
  2008. traceParent._popContext();
  2009. if (result === errorObj) {
  2010. traceParent._pushContext();
  2011. var ret = Promise.reject(errorObj.e);
  2012. traceParent._popContext();
  2013. return ret;
  2014. }
  2015. var maybePromise = tryConvertToPromise(result, traceParent);
  2016. if (maybePromise instanceof Promise) return maybePromise;
  2017. }
  2018. return null;
  2019. }
  2020. function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) {
  2021. if (debug.cancellation()) {
  2022. var internal = new Promise(INTERNAL);
  2023. var _finallyPromise = this._finallyPromise = new Promise(INTERNAL);
  2024. this._promise = internal.lastly(function() {
  2025. return _finallyPromise;
  2026. });
  2027. internal._captureStackTrace();
  2028. internal._setOnCancel(this);
  2029. } else {
  2030. var promise = this._promise = new Promise(INTERNAL);
  2031. promise._captureStackTrace();
  2032. }
  2033. this._stack = stack;
  2034. this._generatorFunction = generatorFunction;
  2035. this._receiver = receiver;
  2036. this._generator = undefined;
  2037. this._yieldHandlers = typeof yieldHandler === "function"
  2038. ? [yieldHandler].concat(yieldHandlers)
  2039. : yieldHandlers;
  2040. this._yieldedPromise = null;
  2041. this._cancellationPhase = false;
  2042. }
  2043. util.inherits(PromiseSpawn, Proxyable);
  2044. PromiseSpawn.prototype._isResolved = function() {
  2045. return this._promise === null;
  2046. };
  2047. PromiseSpawn.prototype._cleanup = function() {
  2048. this._promise = this._generator = null;
  2049. if (debug.cancellation() && this._finallyPromise !== null) {
  2050. this._finallyPromise._fulfill();
  2051. this._finallyPromise = null;
  2052. }
  2053. };
  2054. PromiseSpawn.prototype._promiseCancelled = function() {
  2055. if (this._isResolved()) return;
  2056. var implementsReturn = typeof this._generator["return"] !== "undefined";
  2057. var result;
  2058. if (!implementsReturn) {
  2059. var reason = new Promise.CancellationError(
  2060. "generator .return() sentinel");
  2061. Promise.coroutine.returnSentinel = reason;
  2062. this._promise._attachExtraTrace(reason);
  2063. this._promise._pushContext();
  2064. result = tryCatch(this._generator["throw"]).call(this._generator,
  2065. reason);
  2066. this._promise._popContext();
  2067. } else {
  2068. this._promise._pushContext();
  2069. result = tryCatch(this._generator["return"]).call(this._generator,
  2070. undefined);
  2071. this._promise._popContext();
  2072. }
  2073. this._cancellationPhase = true;
  2074. this._yieldedPromise = null;
  2075. this._continue(result);
  2076. };
  2077. PromiseSpawn.prototype._promiseFulfilled = function(value) {
  2078. this._yieldedPromise = null;
  2079. this._promise._pushContext();
  2080. var result = tryCatch(this._generator.next).call(this._generator, value);
  2081. this._promise._popContext();
  2082. this._continue(result);
  2083. };
  2084. PromiseSpawn.prototype._promiseRejected = function(reason) {
  2085. this._yieldedPromise = null;
  2086. this._promise._attachExtraTrace(reason);
  2087. this._promise._pushContext();
  2088. var result = tryCatch(this._generator["throw"])
  2089. .call(this._generator, reason);
  2090. this._promise._popContext();
  2091. this._continue(result);
  2092. };
  2093. PromiseSpawn.prototype._resultCancelled = function() {
  2094. if (this._yieldedPromise instanceof Promise) {
  2095. var promise = this._yieldedPromise;
  2096. this._yieldedPromise = null;
  2097. promise.cancel();
  2098. }
  2099. };
  2100. PromiseSpawn.prototype.promise = function () {
  2101. return this._promise;
  2102. };
  2103. PromiseSpawn.prototype._run = function () {
  2104. this._generator = this._generatorFunction.call(this._receiver);
  2105. this._receiver =
  2106. this._generatorFunction = undefined;
  2107. this._promiseFulfilled(undefined);
  2108. };
  2109. PromiseSpawn.prototype._continue = function (result) {
  2110. var promise = this._promise;
  2111. if (result === errorObj) {
  2112. this._cleanup();
  2113. if (this._cancellationPhase) {
  2114. return promise.cancel();
  2115. } else {
  2116. return promise._rejectCallback(result.e, false);
  2117. }
  2118. }
  2119. var value = result.value;
  2120. if (result.done === true) {
  2121. this._cleanup();
  2122. if (this._cancellationPhase) {
  2123. return promise.cancel();
  2124. } else {
  2125. return promise._resolveCallback(value);
  2126. }
  2127. } else {
  2128. var maybePromise = tryConvertToPromise(value, this._promise);
  2129. if (!(maybePromise instanceof Promise)) {
  2130. maybePromise =
  2131. promiseFromYieldHandler(maybePromise,
  2132. this._yieldHandlers,
  2133. this._promise);
  2134. if (maybePromise === null) {
  2135. this._promiseRejected(
  2136. new TypeError(
  2137. "A value %s was yielded that could not be treated as a promise\u000a\u000a See http://goo.gl/MqrFmX\u000a\u000a".replace("%s", value) +
  2138. "From coroutine:\u000a" +
  2139. this._stack.split("\n").slice(1, -7).join("\n")
  2140. )
  2141. );
  2142. return;
  2143. }
  2144. }
  2145. maybePromise = maybePromise._target();
  2146. var bitField = maybePromise._bitField;
  2147. ;
  2148. if (((bitField & 50397184) === 0)) {
  2149. this._yieldedPromise = maybePromise;
  2150. maybePromise._proxy(this, null);
  2151. } else if (((bitField & 33554432) !== 0)) {
  2152. Promise._async.invoke(
  2153. this._promiseFulfilled, this, maybePromise._value()
  2154. );
  2155. } else if (((bitField & 16777216) !== 0)) {
  2156. Promise._async.invoke(
  2157. this._promiseRejected, this, maybePromise._reason()
  2158. );
  2159. } else {
  2160. this._promiseCancelled();
  2161. }
  2162. }
  2163. };
  2164. Promise.coroutine = function (generatorFunction, options) {
  2165. if (typeof generatorFunction !== "function") {
  2166. throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  2167. }
  2168. var yieldHandler = Object(options).yieldHandler;
  2169. var PromiseSpawn$ = PromiseSpawn;
  2170. var stack = new Error().stack;
  2171. return function () {
  2172. var generator = generatorFunction.apply(this, arguments);
  2173. var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler,
  2174. stack);
  2175. var ret = spawn.promise();
  2176. spawn._generator = generator;
  2177. spawn._promiseFulfilled(undefined);
  2178. return ret;
  2179. };
  2180. };
  2181. Promise.coroutine.addYieldHandler = function(fn) {
  2182. if (typeof fn !== "function") {
  2183. throw new TypeError("expecting a function but got " + util.classString(fn));
  2184. }
  2185. yieldHandlers.push(fn);
  2186. };
  2187. Promise.spawn = function (generatorFunction) {
  2188. debug.deprecated("Promise.spawn()", "Promise.coroutine()");
  2189. if (typeof generatorFunction !== "function") {
  2190. return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  2191. }
  2192. var spawn = new PromiseSpawn(generatorFunction, this);
  2193. var ret = spawn.promise();
  2194. spawn._run(Promise.spawn);
  2195. return ret;
  2196. };
  2197. };
  2198. },{"./errors":12,"./util":36}],17:[function(_dereq_,module,exports){
  2199. "use strict";
  2200. module.exports =
  2201. function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async,
  2202. getDomain) {
  2203. var util = _dereq_("./util");
  2204. var canEvaluate = util.canEvaluate;
  2205. var tryCatch = util.tryCatch;
  2206. var errorObj = util.errorObj;
  2207. var reject;
  2208. if (!true) {
  2209. if (canEvaluate) {
  2210. var thenCallback = function(i) {
  2211. return new Function("value", "holder", " \n\
  2212. 'use strict'; \n\
  2213. holder.pIndex = value; \n\
  2214. holder.checkFulfillment(this); \n\
  2215. ".replace(/Index/g, i));
  2216. };
  2217. var promiseSetter = function(i) {
  2218. return new Function("promise", "holder", " \n\
  2219. 'use strict'; \n\
  2220. holder.pIndex = promise; \n\
  2221. ".replace(/Index/g, i));
  2222. };
  2223. var generateHolderClass = function(total) {
  2224. var props = new Array(total);
  2225. for (var i = 0; i < props.length; ++i) {
  2226. props[i] = "this.p" + (i+1);
  2227. }
  2228. var assignment = props.join(" = ") + " = null;";
  2229. var cancellationCode= "var promise;\n" + props.map(function(prop) {
  2230. return " \n\
  2231. promise = " + prop + "; \n\
  2232. if (promise instanceof Promise) { \n\
  2233. promise.cancel(); \n\
  2234. } \n\
  2235. ";
  2236. }).join("\n");
  2237. var passedArguments = props.join(", ");
  2238. var name = "Holder$" + total;
  2239. var code = "return function(tryCatch, errorObj, Promise, async) { \n\
  2240. 'use strict'; \n\
  2241. function [TheName](fn) { \n\
  2242. [TheProperties] \n\
  2243. this.fn = fn; \n\
  2244. this.asyncNeeded = true; \n\
  2245. this.now = 0; \n\
  2246. } \n\
  2247. \n\
  2248. [TheName].prototype._callFunction = function(promise) { \n\
  2249. promise._pushContext(); \n\
  2250. var ret = tryCatch(this.fn)([ThePassedArguments]); \n\
  2251. promise._popContext(); \n\
  2252. if (ret === errorObj) { \n\
  2253. promise._rejectCallback(ret.e, false); \n\
  2254. } else { \n\
  2255. promise._resolveCallback(ret); \n\
  2256. } \n\
  2257. }; \n\
  2258. \n\
  2259. [TheName].prototype.checkFulfillment = function(promise) { \n\
  2260. var now = ++this.now; \n\
  2261. if (now === [TheTotal]) { \n\
  2262. if (this.asyncNeeded) { \n\
  2263. async.invoke(this._callFunction, this, promise); \n\
  2264. } else { \n\
  2265. this._callFunction(promise); \n\
  2266. } \n\
  2267. \n\
  2268. } \n\
  2269. }; \n\
  2270. \n\
  2271. [TheName].prototype._resultCancelled = function() { \n\
  2272. [CancellationCode] \n\
  2273. }; \n\
  2274. \n\
  2275. return [TheName]; \n\
  2276. }(tryCatch, errorObj, Promise, async); \n\
  2277. ";
  2278. code = code.replace(/\[TheName\]/g, name)
  2279. .replace(/\[TheTotal\]/g, total)
  2280. .replace(/\[ThePassedArguments\]/g, passedArguments)
  2281. .replace(/\[TheProperties\]/g, assignment)
  2282. .replace(/\[CancellationCode\]/g, cancellationCode);
  2283. return new Function("tryCatch", "errorObj", "Promise", "async", code)
  2284. (tryCatch, errorObj, Promise, async);
  2285. };
  2286. var holderClasses = [];
  2287. var thenCallbacks = [];
  2288. var promiseSetters = [];
  2289. for (var i = 0; i < 8; ++i) {
  2290. holderClasses.push(generateHolderClass(i + 1));
  2291. thenCallbacks.push(thenCallback(i + 1));
  2292. promiseSetters.push(promiseSetter(i + 1));
  2293. }
  2294. reject = function (reason) {
  2295. this._reject(reason);
  2296. };
  2297. }}
  2298. Promise.join = function () {
  2299. var last = arguments.length - 1;
  2300. var fn;
  2301. if (last > 0 && typeof arguments[last] === "function") {
  2302. fn = arguments[last];
  2303. if (!true) {
  2304. if (last <= 8 && canEvaluate) {
  2305. var ret = new Promise(INTERNAL);
  2306. ret._captureStackTrace();
  2307. var HolderClass = holderClasses[last - 1];
  2308. var holder = new HolderClass(fn);
  2309. var callbacks = thenCallbacks;
  2310. for (var i = 0; i < last; ++i) {
  2311. var maybePromise = tryConvertToPromise(arguments[i], ret);
  2312. if (maybePromise instanceof Promise) {
  2313. maybePromise = maybePromise._target();
  2314. var bitField = maybePromise._bitField;
  2315. ;
  2316. if (((bitField & 50397184) === 0)) {
  2317. maybePromise._then(callbacks[i], reject,
  2318. undefined, ret, holder);
  2319. promiseSetters[i](maybePromise, holder);
  2320. holder.asyncNeeded = false;
  2321. } else if (((bitField & 33554432) !== 0)) {
  2322. callbacks[i].call(ret,
  2323. maybePromise._value(), holder);
  2324. } else if (((bitField & 16777216) !== 0)) {
  2325. ret._reject(maybePromise._reason());
  2326. } else {
  2327. ret._cancel();
  2328. }
  2329. } else {
  2330. callbacks[i].call(ret, maybePromise, holder);
  2331. }
  2332. }
  2333. if (!ret._isFateSealed()) {
  2334. if (holder.asyncNeeded) {
  2335. var domain = getDomain();
  2336. if (domain !== null) {
  2337. holder.fn = util.domainBind(domain, holder.fn);
  2338. }
  2339. }
  2340. ret._setAsyncGuaranteed();
  2341. ret._setOnCancel(holder);
  2342. }
  2343. return ret;
  2344. }
  2345. }
  2346. }
  2347. var args = [].slice.call(arguments);;
  2348. if (fn) args.pop();
  2349. var ret = new PromiseArray(args).promise();
  2350. return fn !== undefined ? ret.spread(fn) : ret;
  2351. };
  2352. };
  2353. },{"./util":36}],18:[function(_dereq_,module,exports){
  2354. "use strict";
  2355. module.exports = function(Promise,
  2356. PromiseArray,
  2357. apiRejection,
  2358. tryConvertToPromise,
  2359. INTERNAL,
  2360. debug) {
  2361. var getDomain = Promise._getDomain;
  2362. var util = _dereq_("./util");
  2363. var tryCatch = util.tryCatch;
  2364. var errorObj = util.errorObj;
  2365. var async = Promise._async;
  2366. function MappingPromiseArray(promises, fn, limit, _filter) {
  2367. this.constructor$(promises);
  2368. this._promise._captureStackTrace();
  2369. var domain = getDomain();
  2370. this._callback = domain === null ? fn : util.domainBind(domain, fn);
  2371. this._preservedValues = _filter === INTERNAL
  2372. ? new Array(this.length())
  2373. : null;
  2374. this._limit = limit;
  2375. this._inFlight = 0;
  2376. this._queue = [];
  2377. async.invoke(this._asyncInit, this, undefined);
  2378. }
  2379. util.inherits(MappingPromiseArray, PromiseArray);
  2380. MappingPromiseArray.prototype._asyncInit = function() {
  2381. this._init$(undefined, -2);
  2382. };
  2383. MappingPromiseArray.prototype._init = function () {};
  2384. MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
  2385. var values = this._values;
  2386. var length = this.length();
  2387. var preservedValues = this._preservedValues;
  2388. var limit = this._limit;
  2389. if (index < 0) {
  2390. index = (index * -1) - 1;
  2391. values[index] = value;
  2392. if (limit >= 1) {
  2393. this._inFlight--;
  2394. this._drainQueue();
  2395. if (this._isResolved()) return true;
  2396. }
  2397. } else {
  2398. if (limit >= 1 && this._inFlight >= limit) {
  2399. values[index] = value;
  2400. this._queue.push(index);
  2401. return false;
  2402. }
  2403. if (preservedValues !== null) preservedValues[index] = value;
  2404. var promise = this._promise;
  2405. var callback = this._callback;
  2406. var receiver = promise._boundValue();
  2407. promise._pushContext();
  2408. var ret = tryCatch(callback).call(receiver, value, index, length);
  2409. var promiseCreated = promise._popContext();
  2410. debug.checkForgottenReturns(
  2411. ret,
  2412. promiseCreated,
  2413. preservedValues !== null ? "Promise.filter" : "Promise.map",
  2414. promise
  2415. );
  2416. if (ret === errorObj) {
  2417. this._reject(ret.e);
  2418. return true;
  2419. }
  2420. var maybePromise = tryConvertToPromise(ret, this._promise);
  2421. if (maybePromise instanceof Promise) {
  2422. maybePromise = maybePromise._target();
  2423. var bitField = maybePromise._bitField;
  2424. ;
  2425. if (((bitField & 50397184) === 0)) {
  2426. if (limit >= 1) this._inFlight++;
  2427. values[index] = maybePromise;
  2428. maybePromise._proxy(this, (index + 1) * -1);
  2429. return false;
  2430. } else if (((bitField & 33554432) !== 0)) {
  2431. ret = maybePromise._value();
  2432. } else if (((bitField & 16777216) !== 0)) {
  2433. this._reject(maybePromise._reason());
  2434. return true;
  2435. } else {
  2436. this._cancel();
  2437. return true;
  2438. }
  2439. }
  2440. values[index] = ret;
  2441. }
  2442. var totalResolved = ++this._totalResolved;
  2443. if (totalResolved >= length) {
  2444. if (preservedValues !== null) {
  2445. this._filter(values, preservedValues);
  2446. } else {
  2447. this._resolve(values);
  2448. }
  2449. return true;
  2450. }
  2451. return false;
  2452. };
  2453. MappingPromiseArray.prototype._drainQueue = function () {
  2454. var queue = this._queue;
  2455. var limit = this._limit;
  2456. var values = this._values;
  2457. while (queue.length > 0 && this._inFlight < limit) {
  2458. if (this._isResolved()) return;
  2459. var index = queue.pop();
  2460. this._promiseFulfilled(values[index], index);
  2461. }
  2462. };
  2463. MappingPromiseArray.prototype._filter = function (booleans, values) {
  2464. var len = values.length;
  2465. var ret = new Array(len);
  2466. var j = 0;
  2467. for (var i = 0; i < len; ++i) {
  2468. if (booleans[i]) ret[j++] = values[i];
  2469. }
  2470. ret.length = j;
  2471. this._resolve(ret);
  2472. };
  2473. MappingPromiseArray.prototype.preservedValues = function () {
  2474. return this._preservedValues;
  2475. };
  2476. function map(promises, fn, options, _filter) {
  2477. if (typeof fn !== "function") {
  2478. return apiRejection("expecting a function but got " + util.classString(fn));
  2479. }
  2480. var limit = 0;
  2481. if (options !== undefined) {
  2482. if (typeof options === "object" && options !== null) {
  2483. if (typeof options.concurrency !== "number") {
  2484. return Promise.reject(
  2485. new TypeError("'concurrency' must be a number but it is " +
  2486. util.classString(options.concurrency)));
  2487. }
  2488. limit = options.concurrency;
  2489. } else {
  2490. return Promise.reject(new TypeError(
  2491. "options argument must be an object but it is " +
  2492. util.classString(options)));
  2493. }
  2494. }
  2495. limit = typeof limit === "number" &&
  2496. isFinite(limit) && limit >= 1 ? limit : 0;
  2497. return new MappingPromiseArray(promises, fn, limit, _filter).promise();
  2498. }
  2499. Promise.prototype.map = function (fn, options) {
  2500. return map(this, fn, options, null);
  2501. };
  2502. Promise.map = function (promises, fn, options, _filter) {
  2503. return map(promises, fn, options, _filter);
  2504. };
  2505. };
  2506. },{"./util":36}],19:[function(_dereq_,module,exports){
  2507. "use strict";
  2508. module.exports =
  2509. function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) {
  2510. var util = _dereq_("./util");
  2511. var tryCatch = util.tryCatch;
  2512. Promise.method = function (fn) {
  2513. if (typeof fn !== "function") {
  2514. throw new Promise.TypeError("expecting a function but got " + util.classString(fn));
  2515. }
  2516. return function () {
  2517. var ret = new Promise(INTERNAL);
  2518. ret._captureStackTrace();
  2519. ret._pushContext();
  2520. var value = tryCatch(fn).apply(this, arguments);
  2521. var promiseCreated = ret._popContext();
  2522. debug.checkForgottenReturns(
  2523. value, promiseCreated, "Promise.method", ret);
  2524. ret._resolveFromSyncValue(value);
  2525. return ret;
  2526. };
  2527. };
  2528. Promise.attempt = Promise["try"] = function (fn) {
  2529. if (typeof fn !== "function") {
  2530. return apiRejection("expecting a function but got " + util.classString(fn));
  2531. }
  2532. var ret = new Promise(INTERNAL);
  2533. ret._captureStackTrace();
  2534. ret._pushContext();
  2535. var value;
  2536. if (arguments.length > 1) {
  2537. debug.deprecated("calling Promise.try with more than 1 argument");
  2538. var arg = arguments[1];
  2539. var ctx = arguments[2];
  2540. value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg)
  2541. : tryCatch(fn).call(ctx, arg);
  2542. } else {
  2543. value = tryCatch(fn)();
  2544. }
  2545. var promiseCreated = ret._popContext();
  2546. debug.checkForgottenReturns(
  2547. value, promiseCreated, "Promise.try", ret);
  2548. ret._resolveFromSyncValue(value);
  2549. return ret;
  2550. };
  2551. Promise.prototype._resolveFromSyncValue = function (value) {
  2552. if (value === util.errorObj) {
  2553. this._rejectCallback(value.e, false);
  2554. } else {
  2555. this._resolveCallback(value, true);
  2556. }
  2557. };
  2558. };
  2559. },{"./util":36}],20:[function(_dereq_,module,exports){
  2560. "use strict";
  2561. var util = _dereq_("./util");
  2562. var maybeWrapAsError = util.maybeWrapAsError;
  2563. var errors = _dereq_("./errors");
  2564. var OperationalError = errors.OperationalError;
  2565. var es5 = _dereq_("./es5");
  2566. function isUntypedError(obj) {
  2567. return obj instanceof Error &&
  2568. es5.getPrototypeOf(obj) === Error.prototype;
  2569. }
  2570. var rErrorKey = /^(?:name|message|stack|cause)$/;
  2571. function wrapAsOperationalError(obj) {
  2572. var ret;
  2573. if (isUntypedError(obj)) {
  2574. ret = new OperationalError(obj);
  2575. ret.name = obj.name;
  2576. ret.message = obj.message;
  2577. ret.stack = obj.stack;
  2578. var keys = es5.keys(obj);
  2579. for (var i = 0; i < keys.length; ++i) {
  2580. var key = keys[i];
  2581. if (!rErrorKey.test(key)) {
  2582. ret[key] = obj[key];
  2583. }
  2584. }
  2585. return ret;
  2586. }
  2587. util.markAsOriginatingFromRejection(obj);
  2588. return obj;
  2589. }
  2590. function nodebackForPromise(promise, multiArgs) {
  2591. return function(err, value) {
  2592. if (promise === null) return;
  2593. if (err) {
  2594. var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
  2595. promise._attachExtraTrace(wrapped);
  2596. promise._reject(wrapped);
  2597. } else if (!multiArgs) {
  2598. promise._fulfill(value);
  2599. } else {
  2600. var args = [].slice.call(arguments, 1);;
  2601. promise._fulfill(args);
  2602. }
  2603. promise = null;
  2604. };
  2605. }
  2606. module.exports = nodebackForPromise;
  2607. },{"./errors":12,"./es5":13,"./util":36}],21:[function(_dereq_,module,exports){
  2608. "use strict";
  2609. module.exports = function(Promise) {
  2610. var util = _dereq_("./util");
  2611. var async = Promise._async;
  2612. var tryCatch = util.tryCatch;
  2613. var errorObj = util.errorObj;
  2614. function spreadAdapter(val, nodeback) {
  2615. var promise = this;
  2616. if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback);
  2617. var ret =
  2618. tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val));
  2619. if (ret === errorObj) {
  2620. async.throwLater(ret.e);
  2621. }
  2622. }
  2623. function successAdapter(val, nodeback) {
  2624. var promise = this;
  2625. var receiver = promise._boundValue();
  2626. var ret = val === undefined
  2627. ? tryCatch(nodeback).call(receiver, null)
  2628. : tryCatch(nodeback).call(receiver, null, val);
  2629. if (ret === errorObj) {
  2630. async.throwLater(ret.e);
  2631. }
  2632. }
  2633. function errorAdapter(reason, nodeback) {
  2634. var promise = this;
  2635. if (!reason) {
  2636. var newReason = new Error(reason + "");
  2637. newReason.cause = reason;
  2638. reason = newReason;
  2639. }
  2640. var ret = tryCatch(nodeback).call(promise._boundValue(), reason);
  2641. if (ret === errorObj) {
  2642. async.throwLater(ret.e);
  2643. }
  2644. }
  2645. Promise.prototype.asCallback = Promise.prototype.nodeify = function (nodeback,
  2646. options) {
  2647. if (typeof nodeback == "function") {
  2648. var adapter = successAdapter;
  2649. if (options !== undefined && Object(options).spread) {
  2650. adapter = spreadAdapter;
  2651. }
  2652. this._then(
  2653. adapter,
  2654. errorAdapter,
  2655. undefined,
  2656. this,
  2657. nodeback
  2658. );
  2659. }
  2660. return this;
  2661. };
  2662. };
  2663. },{"./util":36}],22:[function(_dereq_,module,exports){
  2664. "use strict";
  2665. module.exports = function() {
  2666. var makeSelfResolutionError = function () {
  2667. return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  2668. };
  2669. var reflectHandler = function() {
  2670. return new Promise.PromiseInspection(this._target());
  2671. };
  2672. var apiRejection = function(msg) {
  2673. return Promise.reject(new TypeError(msg));
  2674. };
  2675. function Proxyable() {}
  2676. var UNDEFINED_BINDING = {};
  2677. var util = _dereq_("./util");
  2678. var getDomain;
  2679. if (util.isNode) {
  2680. getDomain = function() {
  2681. var ret = process.domain;
  2682. if (ret === undefined) ret = null;
  2683. return ret;
  2684. };
  2685. } else {
  2686. getDomain = function() {
  2687. return null;
  2688. };
  2689. }
  2690. util.notEnumerableProp(Promise, "_getDomain", getDomain);
  2691. var es5 = _dereq_("./es5");
  2692. var Async = _dereq_("./async");
  2693. var async = new Async();
  2694. es5.defineProperty(Promise, "_async", {value: async});
  2695. var errors = _dereq_("./errors");
  2696. var TypeError = Promise.TypeError = errors.TypeError;
  2697. Promise.RangeError = errors.RangeError;
  2698. var CancellationError = Promise.CancellationError = errors.CancellationError;
  2699. Promise.TimeoutError = errors.TimeoutError;
  2700. Promise.OperationalError = errors.OperationalError;
  2701. Promise.RejectionError = errors.OperationalError;
  2702. Promise.AggregateError = errors.AggregateError;
  2703. var INTERNAL = function(){};
  2704. var APPLY = {};
  2705. var NEXT_FILTER = {};
  2706. var tryConvertToPromise = _dereq_("./thenables")(Promise, INTERNAL);
  2707. var PromiseArray =
  2708. _dereq_("./promise_array")(Promise, INTERNAL,
  2709. tryConvertToPromise, apiRejection, Proxyable);
  2710. var Context = _dereq_("./context")(Promise);
  2711. /*jshint unused:false*/
  2712. var createContext = Context.create;
  2713. var debug = _dereq_("./debuggability")(Promise, Context);
  2714. var CapturedTrace = debug.CapturedTrace;
  2715. var PassThroughHandlerContext =
  2716. _dereq_("./finally")(Promise, tryConvertToPromise);
  2717. var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER);
  2718. var nodebackForPromise = _dereq_("./nodeback");
  2719. var errorObj = util.errorObj;
  2720. var tryCatch = util.tryCatch;
  2721. function check(self, executor) {
  2722. if (typeof executor !== "function") {
  2723. throw new TypeError("expecting a function but got " + util.classString(executor));
  2724. }
  2725. if (self.constructor !== Promise) {
  2726. throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  2727. }
  2728. }
  2729. function Promise(executor) {
  2730. this._bitField = 0;
  2731. this._fulfillmentHandler0 = undefined;
  2732. this._rejectionHandler0 = undefined;
  2733. this._promise0 = undefined;
  2734. this._receiver0 = undefined;
  2735. if (executor !== INTERNAL) {
  2736. check(this, executor);
  2737. this._resolveFromExecutor(executor);
  2738. }
  2739. this._promiseCreated();
  2740. this._fireEvent("promiseCreated", this);
  2741. }
  2742. Promise.prototype.toString = function () {
  2743. return "[object Promise]";
  2744. };
  2745. Promise.prototype.caught = Promise.prototype["catch"] = function (fn) {
  2746. var len = arguments.length;
  2747. if (len > 1) {
  2748. var catchInstances = new Array(len - 1),
  2749. j = 0, i;
  2750. for (i = 0; i < len - 1; ++i) {
  2751. var item = arguments[i];
  2752. if (util.isObject(item)) {
  2753. catchInstances[j++] = item;
  2754. } else {
  2755. return apiRejection("expecting an object but got " +
  2756. "A catch statement predicate " + util.classString(item));
  2757. }
  2758. }
  2759. catchInstances.length = j;
  2760. fn = arguments[i];
  2761. return this.then(undefined, catchFilter(catchInstances, fn, this));
  2762. }
  2763. return this.then(undefined, fn);
  2764. };
  2765. Promise.prototype.reflect = function () {
  2766. return this._then(reflectHandler,
  2767. reflectHandler, undefined, this, undefined);
  2768. };
  2769. Promise.prototype.then = function (didFulfill, didReject) {
  2770. if (debug.warnings() && arguments.length > 0 &&
  2771. typeof didFulfill !== "function" &&
  2772. typeof didReject !== "function") {
  2773. var msg = ".then() only accepts functions but was passed: " +
  2774. util.classString(didFulfill);
  2775. if (arguments.length > 1) {
  2776. msg += ", " + util.classString(didReject);
  2777. }
  2778. this._warn(msg);
  2779. }
  2780. return this._then(didFulfill, didReject, undefined, undefined, undefined);
  2781. };
  2782. Promise.prototype.done = function (didFulfill, didReject) {
  2783. var promise =
  2784. this._then(didFulfill, didReject, undefined, undefined, undefined);
  2785. promise._setIsFinal();
  2786. };
  2787. Promise.prototype.spread = function (fn) {
  2788. if (typeof fn !== "function") {
  2789. return apiRejection("expecting a function but got " + util.classString(fn));
  2790. }
  2791. return this.all()._then(fn, undefined, undefined, APPLY, undefined);
  2792. };
  2793. Promise.prototype.toJSON = function () {
  2794. var ret = {
  2795. isFulfilled: false,
  2796. isRejected: false,
  2797. fulfillmentValue: undefined,
  2798. rejectionReason: undefined
  2799. };
  2800. if (this.isFulfilled()) {
  2801. ret.fulfillmentValue = this.value();
  2802. ret.isFulfilled = true;
  2803. } else if (this.isRejected()) {
  2804. ret.rejectionReason = this.reason();
  2805. ret.isRejected = true;
  2806. }
  2807. return ret;
  2808. };
  2809. Promise.prototype.all = function () {
  2810. if (arguments.length > 0) {
  2811. this._warn(".all() was passed arguments but it does not take any");
  2812. }
  2813. return new PromiseArray(this).promise();
  2814. };
  2815. Promise.prototype.error = function (fn) {
  2816. return this.caught(util.originatesFromRejection, fn);
  2817. };
  2818. Promise.getNewLibraryCopy = module.exports;
  2819. Promise.is = function (val) {
  2820. return val instanceof Promise;
  2821. };
  2822. Promise.fromNode = Promise.fromCallback = function(fn) {
  2823. var ret = new Promise(INTERNAL);
  2824. ret._captureStackTrace();
  2825. var multiArgs = arguments.length > 1 ? !!Object(arguments[1]).multiArgs
  2826. : false;
  2827. var result = tryCatch(fn)(nodebackForPromise(ret, multiArgs));
  2828. if (result === errorObj) {
  2829. ret._rejectCallback(result.e, true);
  2830. }
  2831. if (!ret._isFateSealed()) ret._setAsyncGuaranteed();
  2832. return ret;
  2833. };
  2834. Promise.all = function (promises) {
  2835. return new PromiseArray(promises).promise();
  2836. };
  2837. Promise.cast = function (obj) {
  2838. var ret = tryConvertToPromise(obj);
  2839. if (!(ret instanceof Promise)) {
  2840. ret = new Promise(INTERNAL);
  2841. ret._captureStackTrace();
  2842. ret._setFulfilled();
  2843. ret._rejectionHandler0 = obj;
  2844. }
  2845. return ret;
  2846. };
  2847. Promise.resolve = Promise.fulfilled = Promise.cast;
  2848. Promise.reject = Promise.rejected = function (reason) {
  2849. var ret = new Promise(INTERNAL);
  2850. ret._captureStackTrace();
  2851. ret._rejectCallback(reason, true);
  2852. return ret;
  2853. };
  2854. Promise.setScheduler = function(fn) {
  2855. if (typeof fn !== "function") {
  2856. throw new TypeError("expecting a function but got " + util.classString(fn));
  2857. }
  2858. return async.setScheduler(fn);
  2859. };
  2860. Promise.prototype._then = function (
  2861. didFulfill,
  2862. didReject,
  2863. _, receiver,
  2864. internalData
  2865. ) {
  2866. var haveInternalData = internalData !== undefined;
  2867. var promise = haveInternalData ? internalData : new Promise(INTERNAL);
  2868. var target = this._target();
  2869. var bitField = target._bitField;
  2870. if (!haveInternalData) {
  2871. promise._propagateFrom(this, 3);
  2872. promise._captureStackTrace();
  2873. if (receiver === undefined &&
  2874. ((this._bitField & 2097152) !== 0)) {
  2875. if (!((bitField & 50397184) === 0)) {
  2876. receiver = this._boundValue();
  2877. } else {
  2878. receiver = target === this ? undefined : this._boundTo;
  2879. }
  2880. }
  2881. this._fireEvent("promiseChained", this, promise);
  2882. }
  2883. var domain = getDomain();
  2884. if (!((bitField & 50397184) === 0)) {
  2885. var handler, value, settler = target._settlePromiseCtx;
  2886. if (((bitField & 33554432) !== 0)) {
  2887. value = target._rejectionHandler0;
  2888. handler = didFulfill;
  2889. } else if (((bitField & 16777216) !== 0)) {
  2890. value = target._fulfillmentHandler0;
  2891. handler = didReject;
  2892. target._unsetRejectionIsUnhandled();
  2893. } else {
  2894. settler = target._settlePromiseLateCancellationObserver;
  2895. value = new CancellationError("late cancellation observer");
  2896. target._attachExtraTrace(value);
  2897. handler = didReject;
  2898. }
  2899. async.invoke(settler, target, {
  2900. handler: domain === null ? handler
  2901. : (typeof handler === "function" &&
  2902. util.domainBind(domain, handler)),
  2903. promise: promise,
  2904. receiver: receiver,
  2905. value: value
  2906. });
  2907. } else {
  2908. target._addCallbacks(didFulfill, didReject, promise, receiver, domain);
  2909. }
  2910. return promise;
  2911. };
  2912. Promise.prototype._length = function () {
  2913. return this._bitField & 65535;
  2914. };
  2915. Promise.prototype._isFateSealed = function () {
  2916. return (this._bitField & 117506048) !== 0;
  2917. };
  2918. Promise.prototype._isFollowing = function () {
  2919. return (this._bitField & 67108864) === 67108864;
  2920. };
  2921. Promise.prototype._setLength = function (len) {
  2922. this._bitField = (this._bitField & -65536) |
  2923. (len & 65535);
  2924. };
  2925. Promise.prototype._setFulfilled = function () {
  2926. this._bitField = this._bitField | 33554432;
  2927. this._fireEvent("promiseFulfilled", this);
  2928. };
  2929. Promise.prototype._setRejected = function () {
  2930. this._bitField = this._bitField | 16777216;
  2931. this._fireEvent("promiseRejected", this);
  2932. };
  2933. Promise.prototype._setFollowing = function () {
  2934. this._bitField = this._bitField | 67108864;
  2935. this._fireEvent("promiseResolved", this);
  2936. };
  2937. Promise.prototype._setIsFinal = function () {
  2938. this._bitField = this._bitField | 4194304;
  2939. };
  2940. Promise.prototype._isFinal = function () {
  2941. return (this._bitField & 4194304) > 0;
  2942. };
  2943. Promise.prototype._unsetCancelled = function() {
  2944. this._bitField = this._bitField & (~65536);
  2945. };
  2946. Promise.prototype._setCancelled = function() {
  2947. this._bitField = this._bitField | 65536;
  2948. this._fireEvent("promiseCancelled", this);
  2949. };
  2950. Promise.prototype._setWillBeCancelled = function() {
  2951. this._bitField = this._bitField | 8388608;
  2952. };
  2953. Promise.prototype._setAsyncGuaranteed = function() {
  2954. if (async.hasCustomScheduler()) return;
  2955. this._bitField = this._bitField | 134217728;
  2956. };
  2957. Promise.prototype._receiverAt = function (index) {
  2958. var ret = index === 0 ? this._receiver0 : this[
  2959. index * 4 - 4 + 3];
  2960. if (ret === UNDEFINED_BINDING) {
  2961. return undefined;
  2962. } else if (ret === undefined && this._isBound()) {
  2963. return this._boundValue();
  2964. }
  2965. return ret;
  2966. };
  2967. Promise.prototype._promiseAt = function (index) {
  2968. return this[
  2969. index * 4 - 4 + 2];
  2970. };
  2971. Promise.prototype._fulfillmentHandlerAt = function (index) {
  2972. return this[
  2973. index * 4 - 4 + 0];
  2974. };
  2975. Promise.prototype._rejectionHandlerAt = function (index) {
  2976. return this[
  2977. index * 4 - 4 + 1];
  2978. };
  2979. Promise.prototype._boundValue = function() {};
  2980. Promise.prototype._migrateCallback0 = function (follower) {
  2981. var bitField = follower._bitField;
  2982. var fulfill = follower._fulfillmentHandler0;
  2983. var reject = follower._rejectionHandler0;
  2984. var promise = follower._promise0;
  2985. var receiver = follower._receiverAt(0);
  2986. if (receiver === undefined) receiver = UNDEFINED_BINDING;
  2987. this._addCallbacks(fulfill, reject, promise, receiver, null);
  2988. };
  2989. Promise.prototype._migrateCallbackAt = function (follower, index) {
  2990. var fulfill = follower._fulfillmentHandlerAt(index);
  2991. var reject = follower._rejectionHandlerAt(index);
  2992. var promise = follower._promiseAt(index);
  2993. var receiver = follower._receiverAt(index);
  2994. if (receiver === undefined) receiver = UNDEFINED_BINDING;
  2995. this._addCallbacks(fulfill, reject, promise, receiver, null);
  2996. };
  2997. Promise.prototype._addCallbacks = function (
  2998. fulfill,
  2999. reject,
  3000. promise,
  3001. receiver,
  3002. domain
  3003. ) {
  3004. var index = this._length();
  3005. if (index >= 65535 - 4) {
  3006. index = 0;
  3007. this._setLength(0);
  3008. }
  3009. if (index === 0) {
  3010. this._promise0 = promise;
  3011. this._receiver0 = receiver;
  3012. if (typeof fulfill === "function") {
  3013. this._fulfillmentHandler0 =
  3014. domain === null ? fulfill : util.domainBind(domain, fulfill);
  3015. }
  3016. if (typeof reject === "function") {
  3017. this._rejectionHandler0 =
  3018. domain === null ? reject : util.domainBind(domain, reject);
  3019. }
  3020. } else {
  3021. var base = index * 4 - 4;
  3022. this[base + 2] = promise;
  3023. this[base + 3] = receiver;
  3024. if (typeof fulfill === "function") {
  3025. this[base + 0] =
  3026. domain === null ? fulfill : util.domainBind(domain, fulfill);
  3027. }
  3028. if (typeof reject === "function") {
  3029. this[base + 1] =
  3030. domain === null ? reject : util.domainBind(domain, reject);
  3031. }
  3032. }
  3033. this._setLength(index + 1);
  3034. return index;
  3035. };
  3036. Promise.prototype._proxy = function (proxyable, arg) {
  3037. this._addCallbacks(undefined, undefined, arg, proxyable, null);
  3038. };
  3039. Promise.prototype._resolveCallback = function(value, shouldBind) {
  3040. if (((this._bitField & 117506048) !== 0)) return;
  3041. if (value === this)
  3042. return this._rejectCallback(makeSelfResolutionError(), false);
  3043. var maybePromise = tryConvertToPromise(value, this);
  3044. if (!(maybePromise instanceof Promise)) return this._fulfill(value);
  3045. if (shouldBind) this._propagateFrom(maybePromise, 2);
  3046. var promise = maybePromise._target();
  3047. if (promise === this) {
  3048. this._reject(makeSelfResolutionError());
  3049. return;
  3050. }
  3051. var bitField = promise._bitField;
  3052. if (((bitField & 50397184) === 0)) {
  3053. var len = this._length();
  3054. if (len > 0) promise._migrateCallback0(this);
  3055. for (var i = 1; i < len; ++i) {
  3056. promise._migrateCallbackAt(this, i);
  3057. }
  3058. this._setFollowing();
  3059. this._setLength(0);
  3060. this._setFollowee(promise);
  3061. } else if (((bitField & 33554432) !== 0)) {
  3062. this._fulfill(promise._value());
  3063. } else if (((bitField & 16777216) !== 0)) {
  3064. this._reject(promise._reason());
  3065. } else {
  3066. var reason = new CancellationError("late cancellation observer");
  3067. promise._attachExtraTrace(reason);
  3068. this._reject(reason);
  3069. }
  3070. };
  3071. Promise.prototype._rejectCallback =
  3072. function(reason, synchronous, ignoreNonErrorWarnings) {
  3073. var trace = util.ensureErrorObject(reason);
  3074. var hasStack = trace === reason;
  3075. if (!hasStack && !ignoreNonErrorWarnings && debug.warnings()) {
  3076. var message = "a promise was rejected with a non-error: " +
  3077. util.classString(reason);
  3078. this._warn(message, true);
  3079. }
  3080. this._attachExtraTrace(trace, synchronous ? hasStack : false);
  3081. this._reject(reason);
  3082. };
  3083. Promise.prototype._resolveFromExecutor = function (executor) {
  3084. var promise = this;
  3085. this._captureStackTrace();
  3086. this._pushContext();
  3087. var synchronous = true;
  3088. var r = this._execute(executor, function(value) {
  3089. promise._resolveCallback(value);
  3090. }, function (reason) {
  3091. promise._rejectCallback(reason, synchronous);
  3092. });
  3093. synchronous = false;
  3094. this._popContext();
  3095. if (r !== undefined) {
  3096. promise._rejectCallback(r, true);
  3097. }
  3098. };
  3099. Promise.prototype._settlePromiseFromHandler = function (
  3100. handler, receiver, value, promise
  3101. ) {
  3102. var bitField = promise._bitField;
  3103. if (((bitField & 65536) !== 0)) return;
  3104. promise._pushContext();
  3105. var x;
  3106. if (receiver === APPLY) {
  3107. if (!value || typeof value.length !== "number") {
  3108. x = errorObj;
  3109. x.e = new TypeError("cannot .spread() a non-array: " +
  3110. util.classString(value));
  3111. } else {
  3112. x = tryCatch(handler).apply(this._boundValue(), value);
  3113. }
  3114. } else {
  3115. x = tryCatch(handler).call(receiver, value);
  3116. }
  3117. var promiseCreated = promise._popContext();
  3118. bitField = promise._bitField;
  3119. if (((bitField & 65536) !== 0)) return;
  3120. if (x === NEXT_FILTER) {
  3121. promise._reject(value);
  3122. } else if (x === errorObj) {
  3123. promise._rejectCallback(x.e, false);
  3124. } else {
  3125. debug.checkForgottenReturns(x, promiseCreated, "", promise, this);
  3126. promise._resolveCallback(x);
  3127. }
  3128. };
  3129. Promise.prototype._target = function() {
  3130. var ret = this;
  3131. while (ret._isFollowing()) ret = ret._followee();
  3132. return ret;
  3133. };
  3134. Promise.prototype._followee = function() {
  3135. return this._rejectionHandler0;
  3136. };
  3137. Promise.prototype._setFollowee = function(promise) {
  3138. this._rejectionHandler0 = promise;
  3139. };
  3140. Promise.prototype._settlePromise = function(promise, handler, receiver, value) {
  3141. var isPromise = promise instanceof Promise;
  3142. var bitField = this._bitField;
  3143. var asyncGuaranteed = ((bitField & 134217728) !== 0);
  3144. if (((bitField & 65536) !== 0)) {
  3145. if (isPromise) promise._invokeInternalOnCancel();
  3146. if (receiver instanceof PassThroughHandlerContext &&
  3147. receiver.isFinallyHandler()) {
  3148. receiver.cancelPromise = promise;
  3149. if (tryCatch(handler).call(receiver, value) === errorObj) {
  3150. promise._reject(errorObj.e);
  3151. }
  3152. } else if (handler === reflectHandler) {
  3153. promise._fulfill(reflectHandler.call(receiver));
  3154. } else if (receiver instanceof Proxyable) {
  3155. receiver._promiseCancelled(promise);
  3156. } else if (isPromise || promise instanceof PromiseArray) {
  3157. promise._cancel();
  3158. } else {
  3159. receiver.cancel();
  3160. }
  3161. } else if (typeof handler === "function") {
  3162. if (!isPromise) {
  3163. handler.call(receiver, value, promise);
  3164. } else {
  3165. if (asyncGuaranteed) promise._setAsyncGuaranteed();
  3166. this._settlePromiseFromHandler(handler, receiver, value, promise);
  3167. }
  3168. } else if (receiver instanceof Proxyable) {
  3169. if (!receiver._isResolved()) {
  3170. if (((bitField & 33554432) !== 0)) {
  3171. receiver._promiseFulfilled(value, promise);
  3172. } else {
  3173. receiver._promiseRejected(value, promise);
  3174. }
  3175. }
  3176. } else if (isPromise) {
  3177. if (asyncGuaranteed) promise._setAsyncGuaranteed();
  3178. if (((bitField & 33554432) !== 0)) {
  3179. promise._fulfill(value);
  3180. } else {
  3181. promise._reject(value);
  3182. }
  3183. }
  3184. };
  3185. Promise.prototype._settlePromiseLateCancellationObserver = function(ctx) {
  3186. var handler = ctx.handler;
  3187. var promise = ctx.promise;
  3188. var receiver = ctx.receiver;
  3189. var value = ctx.value;
  3190. if (typeof handler === "function") {
  3191. if (!(promise instanceof Promise)) {
  3192. handler.call(receiver, value, promise);
  3193. } else {
  3194. this._settlePromiseFromHandler(handler, receiver, value, promise);
  3195. }
  3196. } else if (promise instanceof Promise) {
  3197. promise._reject(value);
  3198. }
  3199. };
  3200. Promise.prototype._settlePromiseCtx = function(ctx) {
  3201. this._settlePromise(ctx.promise, ctx.handler, ctx.receiver, ctx.value);
  3202. };
  3203. Promise.prototype._settlePromise0 = function(handler, value, bitField) {
  3204. var promise = this._promise0;
  3205. var receiver = this._receiverAt(0);
  3206. this._promise0 = undefined;
  3207. this._receiver0 = undefined;
  3208. this._settlePromise(promise, handler, receiver, value);
  3209. };
  3210. Promise.prototype._clearCallbackDataAtIndex = function(index) {
  3211. var base = index * 4 - 4;
  3212. this[base + 2] =
  3213. this[base + 3] =
  3214. this[base + 0] =
  3215. this[base + 1] = undefined;
  3216. };
  3217. Promise.prototype._fulfill = function (value) {
  3218. var bitField = this._bitField;
  3219. if (((bitField & 117506048) >>> 16)) return;
  3220. if (value === this) {
  3221. var err = makeSelfResolutionError();
  3222. this._attachExtraTrace(err);
  3223. return this._reject(err);
  3224. }
  3225. this._setFulfilled();
  3226. this._rejectionHandler0 = value;
  3227. if ((bitField & 65535) > 0) {
  3228. if (((bitField & 134217728) !== 0)) {
  3229. this._settlePromises();
  3230. } else {
  3231. async.settlePromises(this);
  3232. }
  3233. }
  3234. };
  3235. Promise.prototype._reject = function (reason) {
  3236. var bitField = this._bitField;
  3237. if (((bitField & 117506048) >>> 16)) return;
  3238. this._setRejected();
  3239. this._fulfillmentHandler0 = reason;
  3240. if (this._isFinal()) {
  3241. return async.fatalError(reason, util.isNode);
  3242. }
  3243. if ((bitField & 65535) > 0) {
  3244. async.settlePromises(this);
  3245. } else {
  3246. this._ensurePossibleRejectionHandled();
  3247. }
  3248. };
  3249. Promise.prototype._fulfillPromises = function (len, value) {
  3250. for (var i = 1; i < len; i++) {
  3251. var handler = this._fulfillmentHandlerAt(i);
  3252. var promise = this._promiseAt(i);
  3253. var receiver = this._receiverAt(i);
  3254. this._clearCallbackDataAtIndex(i);
  3255. this._settlePromise(promise, handler, receiver, value);
  3256. }
  3257. };
  3258. Promise.prototype._rejectPromises = function (len, reason) {
  3259. for (var i = 1; i < len; i++) {
  3260. var handler = this._rejectionHandlerAt(i);
  3261. var promise = this._promiseAt(i);
  3262. var receiver = this._receiverAt(i);
  3263. this._clearCallbackDataAtIndex(i);
  3264. this._settlePromise(promise, handler, receiver, reason);
  3265. }
  3266. };
  3267. Promise.prototype._settlePromises = function () {
  3268. var bitField = this._bitField;
  3269. var len = (bitField & 65535);
  3270. if (len > 0) {
  3271. if (((bitField & 16842752) !== 0)) {
  3272. var reason = this._fulfillmentHandler0;
  3273. this._settlePromise0(this._rejectionHandler0, reason, bitField);
  3274. this._rejectPromises(len, reason);
  3275. } else {
  3276. var value = this._rejectionHandler0;
  3277. this._settlePromise0(this._fulfillmentHandler0, value, bitField);
  3278. this._fulfillPromises(len, value);
  3279. }
  3280. this._setLength(0);
  3281. }
  3282. this._clearCancellationData();
  3283. };
  3284. Promise.prototype._settledValue = function() {
  3285. var bitField = this._bitField;
  3286. if (((bitField & 33554432) !== 0)) {
  3287. return this._rejectionHandler0;
  3288. } else if (((bitField & 16777216) !== 0)) {
  3289. return this._fulfillmentHandler0;
  3290. }
  3291. };
  3292. function deferResolve(v) {this.promise._resolveCallback(v);}
  3293. function deferReject(v) {this.promise._rejectCallback(v, false);}
  3294. Promise.defer = Promise.pending = function() {
  3295. debug.deprecated("Promise.defer", "new Promise");
  3296. var promise = new Promise(INTERNAL);
  3297. return {
  3298. promise: promise,
  3299. resolve: deferResolve,
  3300. reject: deferReject
  3301. };
  3302. };
  3303. util.notEnumerableProp(Promise,
  3304. "_makeSelfResolutionError",
  3305. makeSelfResolutionError);
  3306. _dereq_("./method")(Promise, INTERNAL, tryConvertToPromise, apiRejection,
  3307. debug);
  3308. _dereq_("./bind")(Promise, INTERNAL, tryConvertToPromise, debug);
  3309. _dereq_("./cancel")(Promise, PromiseArray, apiRejection, debug);
  3310. _dereq_("./direct_resolve")(Promise);
  3311. _dereq_("./synchronous_inspection")(Promise);
  3312. _dereq_("./join")(
  3313. Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, getDomain);
  3314. Promise.Promise = Promise;
  3315. Promise.version = "3.4.6";
  3316. _dereq_('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
  3317. _dereq_('./call_get.js')(Promise);
  3318. _dereq_('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug);
  3319. _dereq_('./timers.js')(Promise, INTERNAL, debug);
  3320. _dereq_('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise, Proxyable, debug);
  3321. _dereq_('./nodeify.js')(Promise);
  3322. _dereq_('./promisify.js')(Promise, INTERNAL);
  3323. _dereq_('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection);
  3324. _dereq_('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection);
  3325. _dereq_('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
  3326. _dereq_('./settle.js')(Promise, PromiseArray, debug);
  3327. _dereq_('./some.js')(Promise, PromiseArray, apiRejection);
  3328. _dereq_('./filter.js')(Promise, INTERNAL);
  3329. _dereq_('./each.js')(Promise, INTERNAL);
  3330. _dereq_('./any.js')(Promise);
  3331. util.toFastProperties(Promise);
  3332. util.toFastProperties(Promise.prototype);
  3333. function fillTypes(value) {
  3334. var p = new Promise(INTERNAL);
  3335. p._fulfillmentHandler0 = value;
  3336. p._rejectionHandler0 = value;
  3337. p._promise0 = value;
  3338. p._receiver0 = value;
  3339. }
  3340. // Complete slack tracking, opt out of field-type tracking and
  3341. // stabilize map
  3342. fillTypes({a: 1});
  3343. fillTypes({b: 2});
  3344. fillTypes({c: 3});
  3345. fillTypes(1);
  3346. fillTypes(function(){});
  3347. fillTypes(undefined);
  3348. fillTypes(false);
  3349. fillTypes(new Promise(INTERNAL));
  3350. debug.setBounds(Async.firstLineError, util.lastLineError);
  3351. return Promise;
  3352. };
  3353. },{"./any.js":1,"./async":2,"./bind":3,"./call_get.js":5,"./cancel":6,"./catch_filter":7,"./context":8,"./debuggability":9,"./direct_resolve":10,"./each.js":11,"./errors":12,"./es5":13,"./filter.js":14,"./finally":15,"./generators.js":16,"./join":17,"./map.js":18,"./method":19,"./nodeback":20,"./nodeify.js":21,"./promise_array":23,"./promisify.js":24,"./props.js":25,"./race.js":27,"./reduce.js":28,"./settle.js":30,"./some.js":31,"./synchronous_inspection":32,"./thenables":33,"./timers.js":34,"./using.js":35,"./util":36}],23:[function(_dereq_,module,exports){
  3354. "use strict";
  3355. module.exports = function(Promise, INTERNAL, tryConvertToPromise,
  3356. apiRejection, Proxyable) {
  3357. var util = _dereq_("./util");
  3358. var isArray = util.isArray;
  3359. function toResolutionValue(val) {
  3360. switch(val) {
  3361. case -2: return [];
  3362. case -3: return {};
  3363. }
  3364. }
  3365. function PromiseArray(values) {
  3366. var promise = this._promise = new Promise(INTERNAL);
  3367. if (values instanceof Promise) {
  3368. promise._propagateFrom(values, 3);
  3369. }
  3370. promise._setOnCancel(this);
  3371. this._values = values;
  3372. this._length = 0;
  3373. this._totalResolved = 0;
  3374. this._init(undefined, -2);
  3375. }
  3376. util.inherits(PromiseArray, Proxyable);
  3377. PromiseArray.prototype.length = function () {
  3378. return this._length;
  3379. };
  3380. PromiseArray.prototype.promise = function () {
  3381. return this._promise;
  3382. };
  3383. PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
  3384. var values = tryConvertToPromise(this._values, this._promise);
  3385. if (values instanceof Promise) {
  3386. values = values._target();
  3387. var bitField = values._bitField;
  3388. ;
  3389. this._values = values;
  3390. if (((bitField & 50397184) === 0)) {
  3391. this._promise._setAsyncGuaranteed();
  3392. return values._then(
  3393. init,
  3394. this._reject,
  3395. undefined,
  3396. this,
  3397. resolveValueIfEmpty
  3398. );
  3399. } else if (((bitField & 33554432) !== 0)) {
  3400. values = values._value();
  3401. } else if (((bitField & 16777216) !== 0)) {
  3402. return this._reject(values._reason());
  3403. } else {
  3404. return this._cancel();
  3405. }
  3406. }
  3407. values = util.asArray(values);
  3408. if (values === null) {
  3409. var err = apiRejection(
  3410. "expecting an array or an iterable object but got " + util.classString(values)).reason();
  3411. this._promise._rejectCallback(err, false);
  3412. return;
  3413. }
  3414. if (values.length === 0) {
  3415. if (resolveValueIfEmpty === -5) {
  3416. this._resolveEmptyArray();
  3417. }
  3418. else {
  3419. this._resolve(toResolutionValue(resolveValueIfEmpty));
  3420. }
  3421. return;
  3422. }
  3423. this._iterate(values);
  3424. };
  3425. PromiseArray.prototype._iterate = function(values) {
  3426. var len = this.getActualLength(values.length);
  3427. this._length = len;
  3428. this._values = this.shouldCopyValues() ? new Array(len) : this._values;
  3429. var result = this._promise;
  3430. var isResolved = false;
  3431. var bitField = null;
  3432. for (var i = 0; i < len; ++i) {
  3433. var maybePromise = tryConvertToPromise(values[i], result);
  3434. if (maybePromise instanceof Promise) {
  3435. maybePromise = maybePromise._target();
  3436. bitField = maybePromise._bitField;
  3437. } else {
  3438. bitField = null;
  3439. }
  3440. if (isResolved) {
  3441. if (bitField !== null) {
  3442. maybePromise.suppressUnhandledRejections();
  3443. }
  3444. } else if (bitField !== null) {
  3445. if (((bitField & 50397184) === 0)) {
  3446. maybePromise._proxy(this, i);
  3447. this._values[i] = maybePromise;
  3448. } else if (((bitField & 33554432) !== 0)) {
  3449. isResolved = this._promiseFulfilled(maybePromise._value(), i);
  3450. } else if (((bitField & 16777216) !== 0)) {
  3451. isResolved = this._promiseRejected(maybePromise._reason(), i);
  3452. } else {
  3453. isResolved = this._promiseCancelled(i);
  3454. }
  3455. } else {
  3456. isResolved = this._promiseFulfilled(maybePromise, i);
  3457. }
  3458. }
  3459. if (!isResolved) result._setAsyncGuaranteed();
  3460. };
  3461. PromiseArray.prototype._isResolved = function () {
  3462. return this._values === null;
  3463. };
  3464. PromiseArray.prototype._resolve = function (value) {
  3465. this._values = null;
  3466. this._promise._fulfill(value);
  3467. };
  3468. PromiseArray.prototype._cancel = function() {
  3469. if (this._isResolved() || !this._promise._isCancellable()) return;
  3470. this._values = null;
  3471. this._promise._cancel();
  3472. };
  3473. PromiseArray.prototype._reject = function (reason) {
  3474. this._values = null;
  3475. this._promise._rejectCallback(reason, false);
  3476. };
  3477. PromiseArray.prototype._promiseFulfilled = function (value, index) {
  3478. this._values[index] = value;
  3479. var totalResolved = ++this._totalResolved;
  3480. if (totalResolved >= this._length) {
  3481. this._resolve(this._values);
  3482. return true;
  3483. }
  3484. return false;
  3485. };
  3486. PromiseArray.prototype._promiseCancelled = function() {
  3487. this._cancel();
  3488. return true;
  3489. };
  3490. PromiseArray.prototype._promiseRejected = function (reason) {
  3491. this._totalResolved++;
  3492. this._reject(reason);
  3493. return true;
  3494. };
  3495. PromiseArray.prototype._resultCancelled = function() {
  3496. if (this._isResolved()) return;
  3497. var values = this._values;
  3498. this._cancel();
  3499. if (values instanceof Promise) {
  3500. values.cancel();
  3501. } else {
  3502. for (var i = 0; i < values.length; ++i) {
  3503. if (values[i] instanceof Promise) {
  3504. values[i].cancel();
  3505. }
  3506. }
  3507. }
  3508. };
  3509. PromiseArray.prototype.shouldCopyValues = function () {
  3510. return true;
  3511. };
  3512. PromiseArray.prototype.getActualLength = function (len) {
  3513. return len;
  3514. };
  3515. return PromiseArray;
  3516. };
  3517. },{"./util":36}],24:[function(_dereq_,module,exports){
  3518. "use strict";
  3519. module.exports = function(Promise, INTERNAL) {
  3520. var THIS = {};
  3521. var util = _dereq_("./util");
  3522. var nodebackForPromise = _dereq_("./nodeback");
  3523. var withAppended = util.withAppended;
  3524. var maybeWrapAsError = util.maybeWrapAsError;
  3525. var canEvaluate = util.canEvaluate;
  3526. var TypeError = _dereq_("./errors").TypeError;
  3527. var defaultSuffix = "Async";
  3528. var defaultPromisified = {__isPromisified__: true};
  3529. var noCopyProps = [
  3530. "arity", "length",
  3531. "name",
  3532. "arguments",
  3533. "caller",
  3534. "callee",
  3535. "prototype",
  3536. "__isPromisified__"
  3537. ];
  3538. var noCopyPropsPattern = new RegExp("^(?:" + noCopyProps.join("|") + ")$");
  3539. var defaultFilter = function(name) {
  3540. return util.isIdentifier(name) &&
  3541. name.charAt(0) !== "_" &&
  3542. name !== "constructor";
  3543. };
  3544. function propsFilter(key) {
  3545. return !noCopyPropsPattern.test(key);
  3546. }
  3547. function isPromisified(fn) {
  3548. try {
  3549. return fn.__isPromisified__ === true;
  3550. }
  3551. catch (e) {
  3552. return false;
  3553. }
  3554. }
  3555. function hasPromisified(obj, key, suffix) {
  3556. var val = util.getDataPropertyOrDefault(obj, key + suffix,
  3557. defaultPromisified);
  3558. return val ? isPromisified(val) : false;
  3559. }
  3560. function checkValid(ret, suffix, suffixRegexp) {
  3561. for (var i = 0; i < ret.length; i += 2) {
  3562. var key = ret[i];
  3563. if (suffixRegexp.test(key)) {
  3564. var keyWithoutAsyncSuffix = key.replace(suffixRegexp, "");
  3565. for (var j = 0; j < ret.length; j += 2) {
  3566. if (ret[j] === keyWithoutAsyncSuffix) {
  3567. throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\u000a\u000a See http://goo.gl/MqrFmX\u000a"
  3568. .replace("%s", suffix));
  3569. }
  3570. }
  3571. }
  3572. }
  3573. }
  3574. function promisifiableMethods(obj, suffix, suffixRegexp, filter) {
  3575. var keys = util.inheritedDataKeys(obj);
  3576. var ret = [];
  3577. for (var i = 0; i < keys.length; ++i) {
  3578. var key = keys[i];
  3579. var value = obj[key];
  3580. var passesDefaultFilter = filter === defaultFilter
  3581. ? true : defaultFilter(key, value, obj);
  3582. if (typeof value === "function" &&
  3583. !isPromisified(value) &&
  3584. !hasPromisified(obj, key, suffix) &&
  3585. filter(key, value, obj, passesDefaultFilter)) {
  3586. ret.push(key, value);
  3587. }
  3588. }
  3589. checkValid(ret, suffix, suffixRegexp);
  3590. return ret;
  3591. }
  3592. var escapeIdentRegex = function(str) {
  3593. return str.replace(/([$])/, "\\$");
  3594. };
  3595. var makeNodePromisifiedEval;
  3596. if (!true) {
  3597. var switchCaseArgumentOrder = function(likelyArgumentCount) {
  3598. var ret = [likelyArgumentCount];
  3599. var min = Math.max(0, likelyArgumentCount - 1 - 3);
  3600. for(var i = likelyArgumentCount - 1; i >= min; --i) {
  3601. ret.push(i);
  3602. }
  3603. for(var i = likelyArgumentCount + 1; i <= 3; ++i) {
  3604. ret.push(i);
  3605. }
  3606. return ret;
  3607. };
  3608. var argumentSequence = function(argumentCount) {
  3609. return util.filledRange(argumentCount, "_arg", "");
  3610. };
  3611. var parameterDeclaration = function(parameterCount) {
  3612. return util.filledRange(
  3613. Math.max(parameterCount, 3), "_arg", "");
  3614. };
  3615. var parameterCount = function(fn) {
  3616. if (typeof fn.length === "number") {
  3617. return Math.max(Math.min(fn.length, 1023 + 1), 0);
  3618. }
  3619. return 0;
  3620. };
  3621. makeNodePromisifiedEval =
  3622. function(callback, receiver, originalName, fn, _, multiArgs) {
  3623. var newParameterCount = Math.max(0, parameterCount(fn) - 1);
  3624. var argumentOrder = switchCaseArgumentOrder(newParameterCount);
  3625. var shouldProxyThis = typeof callback === "string" || receiver === THIS;
  3626. function generateCallForArgumentCount(count) {
  3627. var args = argumentSequence(count).join(", ");
  3628. var comma = count > 0 ? ", " : "";
  3629. var ret;
  3630. if (shouldProxyThis) {
  3631. ret = "ret = callback.call(this, {{args}}, nodeback); break;\n";
  3632. } else {
  3633. ret = receiver === undefined
  3634. ? "ret = callback({{args}}, nodeback); break;\n"
  3635. : "ret = callback.call(receiver, {{args}}, nodeback); break;\n";
  3636. }
  3637. return ret.replace("{{args}}", args).replace(", ", comma);
  3638. }
  3639. function generateArgumentSwitchCase() {
  3640. var ret = "";
  3641. for (var i = 0; i < argumentOrder.length; ++i) {
  3642. ret += "case " + argumentOrder[i] +":" +
  3643. generateCallForArgumentCount(argumentOrder[i]);
  3644. }
  3645. ret += " \n\
  3646. default: \n\
  3647. var args = new Array(len + 1); \n\
  3648. var i = 0; \n\
  3649. for (var i = 0; i < len; ++i) { \n\
  3650. args[i] = arguments[i]; \n\
  3651. } \n\
  3652. args[i] = nodeback; \n\
  3653. [CodeForCall] \n\
  3654. break; \n\
  3655. ".replace("[CodeForCall]", (shouldProxyThis
  3656. ? "ret = callback.apply(this, args);\n"
  3657. : "ret = callback.apply(receiver, args);\n"));
  3658. return ret;
  3659. }
  3660. var getFunctionCode = typeof callback === "string"
  3661. ? ("this != null ? this['"+callback+"'] : fn")
  3662. : "fn";
  3663. var body = "'use strict'; \n\
  3664. var ret = function (Parameters) { \n\
  3665. 'use strict'; \n\
  3666. var len = arguments.length; \n\
  3667. var promise = new Promise(INTERNAL); \n\
  3668. promise._captureStackTrace(); \n\
  3669. var nodeback = nodebackForPromise(promise, " + multiArgs + "); \n\
  3670. var ret; \n\
  3671. var callback = tryCatch([GetFunctionCode]); \n\
  3672. switch(len) { \n\
  3673. [CodeForSwitchCase] \n\
  3674. } \n\
  3675. if (ret === errorObj) { \n\
  3676. promise._rejectCallback(maybeWrapAsError(ret.e), true, true);\n\
  3677. } \n\
  3678. if (!promise._isFateSealed()) promise._setAsyncGuaranteed(); \n\
  3679. return promise; \n\
  3680. }; \n\
  3681. notEnumerableProp(ret, '__isPromisified__', true); \n\
  3682. return ret; \n\
  3683. ".replace("[CodeForSwitchCase]", generateArgumentSwitchCase())
  3684. .replace("[GetFunctionCode]", getFunctionCode);
  3685. body = body.replace("Parameters", parameterDeclaration(newParameterCount));
  3686. return new Function("Promise",
  3687. "fn",
  3688. "receiver",
  3689. "withAppended",
  3690. "maybeWrapAsError",
  3691. "nodebackForPromise",
  3692. "tryCatch",
  3693. "errorObj",
  3694. "notEnumerableProp",
  3695. "INTERNAL",
  3696. body)(
  3697. Promise,
  3698. fn,
  3699. receiver,
  3700. withAppended,
  3701. maybeWrapAsError,
  3702. nodebackForPromise,
  3703. util.tryCatch,
  3704. util.errorObj,
  3705. util.notEnumerableProp,
  3706. INTERNAL);
  3707. };
  3708. }
  3709. function makeNodePromisifiedClosure(callback, receiver, _, fn, __, multiArgs) {
  3710. var defaultThis = (function() {return this;})();
  3711. var method = callback;
  3712. if (typeof method === "string") {
  3713. callback = fn;
  3714. }
  3715. function promisified() {
  3716. var _receiver = receiver;
  3717. if (receiver === THIS) _receiver = this;
  3718. var promise = new Promise(INTERNAL);
  3719. promise._captureStackTrace();
  3720. var cb = typeof method === "string" && this !== defaultThis
  3721. ? this[method] : callback;
  3722. var fn = nodebackForPromise(promise, multiArgs);
  3723. try {
  3724. cb.apply(_receiver, withAppended(arguments, fn));
  3725. } catch(e) {
  3726. promise._rejectCallback(maybeWrapAsError(e), true, true);
  3727. }
  3728. if (!promise._isFateSealed()) promise._setAsyncGuaranteed();
  3729. return promise;
  3730. }
  3731. util.notEnumerableProp(promisified, "__isPromisified__", true);
  3732. return promisified;
  3733. }
  3734. var makeNodePromisified = canEvaluate
  3735. ? makeNodePromisifiedEval
  3736. : makeNodePromisifiedClosure;
  3737. function promisifyAll(obj, suffix, filter, promisifier, multiArgs) {
  3738. var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$");
  3739. var methods =
  3740. promisifiableMethods(obj, suffix, suffixRegexp, filter);
  3741. for (var i = 0, len = methods.length; i < len; i+= 2) {
  3742. var key = methods[i];
  3743. var fn = methods[i+1];
  3744. var promisifiedKey = key + suffix;
  3745. if (promisifier === makeNodePromisified) {
  3746. obj[promisifiedKey] =
  3747. makeNodePromisified(key, THIS, key, fn, suffix, multiArgs);
  3748. } else {
  3749. var promisified = promisifier(fn, function() {
  3750. return makeNodePromisified(key, THIS, key,
  3751. fn, suffix, multiArgs);
  3752. });
  3753. util.notEnumerableProp(promisified, "__isPromisified__", true);
  3754. obj[promisifiedKey] = promisified;
  3755. }
  3756. }
  3757. util.toFastProperties(obj);
  3758. return obj;
  3759. }
  3760. function promisify(callback, receiver, multiArgs) {
  3761. return makeNodePromisified(callback, receiver, undefined,
  3762. callback, null, multiArgs);
  3763. }
  3764. Promise.promisify = function (fn, options) {
  3765. if (typeof fn !== "function") {
  3766. throw new TypeError("expecting a function but got " + util.classString(fn));
  3767. }
  3768. if (isPromisified(fn)) {
  3769. return fn;
  3770. }
  3771. options = Object(options);
  3772. var receiver = options.context === undefined ? THIS : options.context;
  3773. var multiArgs = !!options.multiArgs;
  3774. var ret = promisify(fn, receiver, multiArgs);
  3775. util.copyDescriptors(fn, ret, propsFilter);
  3776. return ret;
  3777. };
  3778. Promise.promisifyAll = function (target, options) {
  3779. if (typeof target !== "function" && typeof target !== "object") {
  3780. throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  3781. }
  3782. options = Object(options);
  3783. var multiArgs = !!options.multiArgs;
  3784. var suffix = options.suffix;
  3785. if (typeof suffix !== "string") suffix = defaultSuffix;
  3786. var filter = options.filter;
  3787. if (typeof filter !== "function") filter = defaultFilter;
  3788. var promisifier = options.promisifier;
  3789. if (typeof promisifier !== "function") promisifier = makeNodePromisified;
  3790. if (!util.isIdentifier(suffix)) {
  3791. throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  3792. }
  3793. var keys = util.inheritedDataKeys(target);
  3794. for (var i = 0; i < keys.length; ++i) {
  3795. var value = target[keys[i]];
  3796. if (keys[i] !== "constructor" &&
  3797. util.isClass(value)) {
  3798. promisifyAll(value.prototype, suffix, filter, promisifier,
  3799. multiArgs);
  3800. promisifyAll(value, suffix, filter, promisifier, multiArgs);
  3801. }
  3802. }
  3803. return promisifyAll(target, suffix, filter, promisifier, multiArgs);
  3804. };
  3805. };
  3806. },{"./errors":12,"./nodeback":20,"./util":36}],25:[function(_dereq_,module,exports){
  3807. "use strict";
  3808. module.exports = function(
  3809. Promise, PromiseArray, tryConvertToPromise, apiRejection) {
  3810. var util = _dereq_("./util");
  3811. var isObject = util.isObject;
  3812. var es5 = _dereq_("./es5");
  3813. var Es6Map;
  3814. if (typeof Map === "function") Es6Map = Map;
  3815. var mapToEntries = (function() {
  3816. var index = 0;
  3817. var size = 0;
  3818. function extractEntry(value, key) {
  3819. this[index] = value;
  3820. this[index + size] = key;
  3821. index++;
  3822. }
  3823. return function mapToEntries(map) {
  3824. size = map.size;
  3825. index = 0;
  3826. var ret = new Array(map.size * 2);
  3827. map.forEach(extractEntry, ret);
  3828. return ret;
  3829. };
  3830. })();
  3831. var entriesToMap = function(entries) {
  3832. var ret = new Es6Map();
  3833. var length = entries.length / 2 | 0;
  3834. for (var i = 0; i < length; ++i) {
  3835. var key = entries[length + i];
  3836. var value = entries[i];
  3837. ret.set(key, value);
  3838. }
  3839. return ret;
  3840. };
  3841. function PropertiesPromiseArray(obj) {
  3842. var isMap = false;
  3843. var entries;
  3844. if (Es6Map !== undefined && obj instanceof Es6Map) {
  3845. entries = mapToEntries(obj);
  3846. isMap = true;
  3847. } else {
  3848. var keys = es5.keys(obj);
  3849. var len = keys.length;
  3850. entries = new Array(len * 2);
  3851. for (var i = 0; i < len; ++i) {
  3852. var key = keys[i];
  3853. entries[i] = obj[key];
  3854. entries[i + len] = key;
  3855. }
  3856. }
  3857. this.constructor$(entries);
  3858. this._isMap = isMap;
  3859. this._init$(undefined, -3);
  3860. }
  3861. util.inherits(PropertiesPromiseArray, PromiseArray);
  3862. PropertiesPromiseArray.prototype._init = function () {};
  3863. PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {
  3864. this._values[index] = value;
  3865. var totalResolved = ++this._totalResolved;
  3866. if (totalResolved >= this._length) {
  3867. var val;
  3868. if (this._isMap) {
  3869. val = entriesToMap(this._values);
  3870. } else {
  3871. val = {};
  3872. var keyOffset = this.length();
  3873. for (var i = 0, len = this.length(); i < len; ++i) {
  3874. val[this._values[i + keyOffset]] = this._values[i];
  3875. }
  3876. }
  3877. this._resolve(val);
  3878. return true;
  3879. }
  3880. return false;
  3881. };
  3882. PropertiesPromiseArray.prototype.shouldCopyValues = function () {
  3883. return false;
  3884. };
  3885. PropertiesPromiseArray.prototype.getActualLength = function (len) {
  3886. return len >> 1;
  3887. };
  3888. function props(promises) {
  3889. var ret;
  3890. var castValue = tryConvertToPromise(promises);
  3891. if (!isObject(castValue)) {
  3892. return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  3893. } else if (castValue instanceof Promise) {
  3894. ret = castValue._then(
  3895. Promise.props, undefined, undefined, undefined, undefined);
  3896. } else {
  3897. ret = new PropertiesPromiseArray(castValue).promise();
  3898. }
  3899. if (castValue instanceof Promise) {
  3900. ret._propagateFrom(castValue, 2);
  3901. }
  3902. return ret;
  3903. }
  3904. Promise.prototype.props = function () {
  3905. return props(this);
  3906. };
  3907. Promise.props = function (promises) {
  3908. return props(promises);
  3909. };
  3910. };
  3911. },{"./es5":13,"./util":36}],26:[function(_dereq_,module,exports){
  3912. "use strict";
  3913. function arrayMove(src, srcIndex, dst, dstIndex, len) {
  3914. for (var j = 0; j < len; ++j) {
  3915. dst[j + dstIndex] = src[j + srcIndex];
  3916. src[j + srcIndex] = void 0;
  3917. }
  3918. }
  3919. function Queue(capacity) {
  3920. this._capacity = capacity;
  3921. this._length = 0;
  3922. this._front = 0;
  3923. }
  3924. Queue.prototype._willBeOverCapacity = function (size) {
  3925. return this._capacity < size;
  3926. };
  3927. Queue.prototype._pushOne = function (arg) {
  3928. var length = this.length();
  3929. this._checkCapacity(length + 1);
  3930. var i = (this._front + length) & (this._capacity - 1);
  3931. this[i] = arg;
  3932. this._length = length + 1;
  3933. };
  3934. Queue.prototype._unshiftOne = function(value) {
  3935. var capacity = this._capacity;
  3936. this._checkCapacity(this.length() + 1);
  3937. var front = this._front;
  3938. var i = (((( front - 1 ) &
  3939. ( capacity - 1) ) ^ capacity ) - capacity );
  3940. this[i] = value;
  3941. this._front = i;
  3942. this._length = this.length() + 1;
  3943. };
  3944. Queue.prototype.unshift = function(fn, receiver, arg) {
  3945. this._unshiftOne(arg);
  3946. this._unshiftOne(receiver);
  3947. this._unshiftOne(fn);
  3948. };
  3949. Queue.prototype.push = function (fn, receiver, arg) {
  3950. var length = this.length() + 3;
  3951. if (this._willBeOverCapacity(length)) {
  3952. this._pushOne(fn);
  3953. this._pushOne(receiver);
  3954. this._pushOne(arg);
  3955. return;
  3956. }
  3957. var j = this._front + length - 3;
  3958. this._checkCapacity(length);
  3959. var wrapMask = this._capacity - 1;
  3960. this[(j + 0) & wrapMask] = fn;
  3961. this[(j + 1) & wrapMask] = receiver;
  3962. this[(j + 2) & wrapMask] = arg;
  3963. this._length = length;
  3964. };
  3965. Queue.prototype.shift = function () {
  3966. var front = this._front,
  3967. ret = this[front];
  3968. this[front] = undefined;
  3969. this._front = (front + 1) & (this._capacity - 1);
  3970. this._length--;
  3971. return ret;
  3972. };
  3973. Queue.prototype.length = function () {
  3974. return this._length;
  3975. };
  3976. Queue.prototype._checkCapacity = function (size) {
  3977. if (this._capacity < size) {
  3978. this._resizeTo(this._capacity << 1);
  3979. }
  3980. };
  3981. Queue.prototype._resizeTo = function (capacity) {
  3982. var oldCapacity = this._capacity;
  3983. this._capacity = capacity;
  3984. var front = this._front;
  3985. var length = this._length;
  3986. var moveItemsCount = (front + length) & (oldCapacity - 1);
  3987. arrayMove(this, 0, this, oldCapacity, moveItemsCount);
  3988. };
  3989. module.exports = Queue;
  3990. },{}],27:[function(_dereq_,module,exports){
  3991. "use strict";
  3992. module.exports = function(
  3993. Promise, INTERNAL, tryConvertToPromise, apiRejection) {
  3994. var util = _dereq_("./util");
  3995. var raceLater = function (promise) {
  3996. return promise.then(function(array) {
  3997. return race(array, promise);
  3998. });
  3999. };
  4000. function race(promises, parent) {
  4001. var maybePromise = tryConvertToPromise(promises);
  4002. if (maybePromise instanceof Promise) {
  4003. return raceLater(maybePromise);
  4004. } else {
  4005. promises = util.asArray(promises);
  4006. if (promises === null)
  4007. return apiRejection("expecting an array or an iterable object but got " + util.classString(promises));
  4008. }
  4009. var ret = new Promise(INTERNAL);
  4010. if (parent !== undefined) {
  4011. ret._propagateFrom(parent, 3);
  4012. }
  4013. var fulfill = ret._fulfill;
  4014. var reject = ret._reject;
  4015. for (var i = 0, len = promises.length; i < len; ++i) {
  4016. var val = promises[i];
  4017. if (val === undefined && !(i in promises)) {
  4018. continue;
  4019. }
  4020. Promise.cast(val)._then(fulfill, reject, undefined, ret, null);
  4021. }
  4022. return ret;
  4023. }
  4024. Promise.race = function (promises) {
  4025. return race(promises, undefined);
  4026. };
  4027. Promise.prototype.race = function () {
  4028. return race(this, undefined);
  4029. };
  4030. };
  4031. },{"./util":36}],28:[function(_dereq_,module,exports){
  4032. "use strict";
  4033. module.exports = function(Promise,
  4034. PromiseArray,
  4035. apiRejection,
  4036. tryConvertToPromise,
  4037. INTERNAL,
  4038. debug) {
  4039. var getDomain = Promise._getDomain;
  4040. var util = _dereq_("./util");
  4041. var tryCatch = util.tryCatch;
  4042. function ReductionPromiseArray(promises, fn, initialValue, _each) {
  4043. this.constructor$(promises);
  4044. var domain = getDomain();
  4045. this._fn = domain === null ? fn : util.domainBind(domain, fn);
  4046. if (initialValue !== undefined) {
  4047. initialValue = Promise.resolve(initialValue);
  4048. initialValue._attachCancellationCallback(this);
  4049. }
  4050. this._initialValue = initialValue;
  4051. this._currentCancellable = null;
  4052. if(_each === INTERNAL) {
  4053. this._eachValues = Array(this._length);
  4054. } else if (_each === 0) {
  4055. this._eachValues = null;
  4056. } else {
  4057. this._eachValues = undefined;
  4058. }
  4059. this._promise._captureStackTrace();
  4060. this._init$(undefined, -5);
  4061. }
  4062. util.inherits(ReductionPromiseArray, PromiseArray);
  4063. ReductionPromiseArray.prototype._gotAccum = function(accum) {
  4064. if (this._eachValues !== undefined &&
  4065. this._eachValues !== null &&
  4066. accum !== INTERNAL) {
  4067. this._eachValues.push(accum);
  4068. }
  4069. };
  4070. ReductionPromiseArray.prototype._eachComplete = function(value) {
  4071. if (this._eachValues !== null) {
  4072. this._eachValues.push(value);
  4073. }
  4074. return this._eachValues;
  4075. };
  4076. ReductionPromiseArray.prototype._init = function() {};
  4077. ReductionPromiseArray.prototype._resolveEmptyArray = function() {
  4078. this._resolve(this._eachValues !== undefined ? this._eachValues
  4079. : this._initialValue);
  4080. };
  4081. ReductionPromiseArray.prototype.shouldCopyValues = function () {
  4082. return false;
  4083. };
  4084. ReductionPromiseArray.prototype._resolve = function(value) {
  4085. this._promise._resolveCallback(value);
  4086. this._values = null;
  4087. };
  4088. ReductionPromiseArray.prototype._resultCancelled = function(sender) {
  4089. if (sender === this._initialValue) return this._cancel();
  4090. if (this._isResolved()) return;
  4091. this._resultCancelled$();
  4092. if (this._currentCancellable instanceof Promise) {
  4093. this._currentCancellable.cancel();
  4094. }
  4095. if (this._initialValue instanceof Promise) {
  4096. this._initialValue.cancel();
  4097. }
  4098. };
  4099. ReductionPromiseArray.prototype._iterate = function (values) {
  4100. this._values = values;
  4101. var value;
  4102. var i;
  4103. var length = values.length;
  4104. if (this._initialValue !== undefined) {
  4105. value = this._initialValue;
  4106. i = 0;
  4107. } else {
  4108. value = Promise.resolve(values[0]);
  4109. i = 1;
  4110. }
  4111. this._currentCancellable = value;
  4112. if (!value.isRejected()) {
  4113. for (; i < length; ++i) {
  4114. var ctx = {
  4115. accum: null,
  4116. value: values[i],
  4117. index: i,
  4118. length: length,
  4119. array: this
  4120. };
  4121. value = value._then(gotAccum, undefined, undefined, ctx, undefined);
  4122. }
  4123. }
  4124. if (this._eachValues !== undefined) {
  4125. value = value
  4126. ._then(this._eachComplete, undefined, undefined, this, undefined);
  4127. }
  4128. value._then(completed, completed, undefined, value, this);
  4129. };
  4130. Promise.prototype.reduce = function (fn, initialValue) {
  4131. return reduce(this, fn, initialValue, null);
  4132. };
  4133. Promise.reduce = function (promises, fn, initialValue, _each) {
  4134. return reduce(promises, fn, initialValue, _each);
  4135. };
  4136. function completed(valueOrReason, array) {
  4137. if (this.isFulfilled()) {
  4138. array._resolve(valueOrReason);
  4139. } else {
  4140. array._reject(valueOrReason);
  4141. }
  4142. }
  4143. function reduce(promises, fn, initialValue, _each) {
  4144. if (typeof fn !== "function") {
  4145. return apiRejection("expecting a function but got " + util.classString(fn));
  4146. }
  4147. var array = new ReductionPromiseArray(promises, fn, initialValue, _each);
  4148. return array.promise();
  4149. }
  4150. function gotAccum(accum) {
  4151. this.accum = accum;
  4152. this.array._gotAccum(accum);
  4153. var value = tryConvertToPromise(this.value, this.array._promise);
  4154. if (value instanceof Promise) {
  4155. this.array._currentCancellable = value;
  4156. return value._then(gotValue, undefined, undefined, this, undefined);
  4157. } else {
  4158. return gotValue.call(this, value);
  4159. }
  4160. }
  4161. function gotValue(value) {
  4162. var array = this.array;
  4163. var promise = array._promise;
  4164. var fn = tryCatch(array._fn);
  4165. promise._pushContext();
  4166. var ret;
  4167. if (array._eachValues !== undefined) {
  4168. ret = fn.call(promise._boundValue(), value, this.index, this.length);
  4169. } else {
  4170. ret = fn.call(promise._boundValue(),
  4171. this.accum, value, this.index, this.length);
  4172. }
  4173. if (ret instanceof Promise) {
  4174. array._currentCancellable = ret;
  4175. }
  4176. var promiseCreated = promise._popContext();
  4177. debug.checkForgottenReturns(
  4178. ret,
  4179. promiseCreated,
  4180. array._eachValues !== undefined ? "Promise.each" : "Promise.reduce",
  4181. promise
  4182. );
  4183. return ret;
  4184. }
  4185. };
  4186. },{"./util":36}],29:[function(_dereq_,module,exports){
  4187. "use strict";
  4188. var util = _dereq_("./util");
  4189. var schedule;
  4190. var noAsyncScheduler = function() {
  4191. throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  4192. };
  4193. var NativePromise = util.getNativePromise();
  4194. if (util.isNode && typeof MutationObserver === "undefined") {
  4195. var GlobalSetImmediate = global.setImmediate;
  4196. var ProcessNextTick = process.nextTick;
  4197. schedule = util.isRecentNode
  4198. ? function(fn) { GlobalSetImmediate.call(global, fn); }
  4199. : function(fn) { ProcessNextTick.call(process, fn); };
  4200. } else if (typeof NativePromise === "function" &&
  4201. typeof NativePromise.resolve === "function") {
  4202. var nativePromise = NativePromise.resolve();
  4203. schedule = function(fn) {
  4204. nativePromise.then(fn);
  4205. };
  4206. } else if ((typeof MutationObserver !== "undefined") &&
  4207. !(typeof window !== "undefined" &&
  4208. window.navigator &&
  4209. (window.navigator.standalone || window.cordova))) {
  4210. schedule = (function() {
  4211. var div = document.createElement("div");
  4212. var opts = {attributes: true};
  4213. var toggleScheduled = false;
  4214. var div2 = document.createElement("div");
  4215. var o2 = new MutationObserver(function() {
  4216. div.classList.toggle("foo");
  4217. toggleScheduled = false;
  4218. });
  4219. o2.observe(div2, opts);
  4220. var scheduleToggle = function() {
  4221. if (toggleScheduled) return;
  4222. toggleScheduled = true;
  4223. div2.classList.toggle("foo");
  4224. };
  4225. return function schedule(fn) {
  4226. var o = new MutationObserver(function() {
  4227. o.disconnect();
  4228. fn();
  4229. });
  4230. o.observe(div, opts);
  4231. scheduleToggle();
  4232. };
  4233. })();
  4234. } else if (typeof setImmediate !== "undefined") {
  4235. schedule = function (fn) {
  4236. setImmediate(fn);
  4237. };
  4238. } else if (typeof setTimeout !== "undefined") {
  4239. schedule = function (fn) {
  4240. setTimeout(fn, 0);
  4241. };
  4242. } else {
  4243. schedule = noAsyncScheduler;
  4244. }
  4245. module.exports = schedule;
  4246. },{"./util":36}],30:[function(_dereq_,module,exports){
  4247. "use strict";
  4248. module.exports =
  4249. function(Promise, PromiseArray, debug) {
  4250. var PromiseInspection = Promise.PromiseInspection;
  4251. var util = _dereq_("./util");
  4252. function SettledPromiseArray(values) {
  4253. this.constructor$(values);
  4254. }
  4255. util.inherits(SettledPromiseArray, PromiseArray);
  4256. SettledPromiseArray.prototype._promiseResolved = function (index, inspection) {
  4257. this._values[index] = inspection;
  4258. var totalResolved = ++this._totalResolved;
  4259. if (totalResolved >= this._length) {
  4260. this._resolve(this._values);
  4261. return true;
  4262. }
  4263. return false;
  4264. };
  4265. SettledPromiseArray.prototype._promiseFulfilled = function (value, index) {
  4266. var ret = new PromiseInspection();
  4267. ret._bitField = 33554432;
  4268. ret._settledValueField = value;
  4269. return this._promiseResolved(index, ret);
  4270. };
  4271. SettledPromiseArray.prototype._promiseRejected = function (reason, index) {
  4272. var ret = new PromiseInspection();
  4273. ret._bitField = 16777216;
  4274. ret._settledValueField = reason;
  4275. return this._promiseResolved(index, ret);
  4276. };
  4277. Promise.settle = function (promises) {
  4278. debug.deprecated(".settle()", ".reflect()");
  4279. return new SettledPromiseArray(promises).promise();
  4280. };
  4281. Promise.prototype.settle = function () {
  4282. return Promise.settle(this);
  4283. };
  4284. };
  4285. },{"./util":36}],31:[function(_dereq_,module,exports){
  4286. "use strict";
  4287. module.exports =
  4288. function(Promise, PromiseArray, apiRejection) {
  4289. var util = _dereq_("./util");
  4290. var RangeError = _dereq_("./errors").RangeError;
  4291. var AggregateError = _dereq_("./errors").AggregateError;
  4292. var isArray = util.isArray;
  4293. var CANCELLATION = {};
  4294. function SomePromiseArray(values) {
  4295. this.constructor$(values);
  4296. this._howMany = 0;
  4297. this._unwrap = false;
  4298. this._initialized = false;
  4299. }
  4300. util.inherits(SomePromiseArray, PromiseArray);
  4301. SomePromiseArray.prototype._init = function () {
  4302. if (!this._initialized) {
  4303. return;
  4304. }
  4305. if (this._howMany === 0) {
  4306. this._resolve([]);
  4307. return;
  4308. }
  4309. this._init$(undefined, -5);
  4310. var isArrayResolved = isArray(this._values);
  4311. if (!this._isResolved() &&
  4312. isArrayResolved &&
  4313. this._howMany > this._canPossiblyFulfill()) {
  4314. this._reject(this._getRangeError(this.length()));
  4315. }
  4316. };
  4317. SomePromiseArray.prototype.init = function () {
  4318. this._initialized = true;
  4319. this._init();
  4320. };
  4321. SomePromiseArray.prototype.setUnwrap = function () {
  4322. this._unwrap = true;
  4323. };
  4324. SomePromiseArray.prototype.howMany = function () {
  4325. return this._howMany;
  4326. };
  4327. SomePromiseArray.prototype.setHowMany = function (count) {
  4328. this._howMany = count;
  4329. };
  4330. SomePromiseArray.prototype._promiseFulfilled = function (value) {
  4331. this._addFulfilled(value);
  4332. if (this._fulfilled() === this.howMany()) {
  4333. this._values.length = this.howMany();
  4334. if (this.howMany() === 1 && this._unwrap) {
  4335. this._resolve(this._values[0]);
  4336. } else {
  4337. this._resolve(this._values);
  4338. }
  4339. return true;
  4340. }
  4341. return false;
  4342. };
  4343. SomePromiseArray.prototype._promiseRejected = function (reason) {
  4344. this._addRejected(reason);
  4345. return this._checkOutcome();
  4346. };
  4347. SomePromiseArray.prototype._promiseCancelled = function () {
  4348. if (this._values instanceof Promise || this._values == null) {
  4349. return this._cancel();
  4350. }
  4351. this._addRejected(CANCELLATION);
  4352. return this._checkOutcome();
  4353. };
  4354. SomePromiseArray.prototype._checkOutcome = function() {
  4355. if (this.howMany() > this._canPossiblyFulfill()) {
  4356. var e = new AggregateError();
  4357. for (var i = this.length(); i < this._values.length; ++i) {
  4358. if (this._values[i] !== CANCELLATION) {
  4359. e.push(this._values[i]);
  4360. }
  4361. }
  4362. if (e.length > 0) {
  4363. this._reject(e);
  4364. } else {
  4365. this._cancel();
  4366. }
  4367. return true;
  4368. }
  4369. return false;
  4370. };
  4371. SomePromiseArray.prototype._fulfilled = function () {
  4372. return this._totalResolved;
  4373. };
  4374. SomePromiseArray.prototype._rejected = function () {
  4375. return this._values.length - this.length();
  4376. };
  4377. SomePromiseArray.prototype._addRejected = function (reason) {
  4378. this._values.push(reason);
  4379. };
  4380. SomePromiseArray.prototype._addFulfilled = function (value) {
  4381. this._values[this._totalResolved++] = value;
  4382. };
  4383. SomePromiseArray.prototype._canPossiblyFulfill = function () {
  4384. return this.length() - this._rejected();
  4385. };
  4386. SomePromiseArray.prototype._getRangeError = function (count) {
  4387. var message = "Input array must contain at least " +
  4388. this._howMany + " items but contains only " + count + " items";
  4389. return new RangeError(message);
  4390. };
  4391. SomePromiseArray.prototype._resolveEmptyArray = function () {
  4392. this._reject(this._getRangeError(0));
  4393. };
  4394. function some(promises, howMany) {
  4395. if ((howMany | 0) !== howMany || howMany < 0) {
  4396. return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  4397. }
  4398. var ret = new SomePromiseArray(promises);
  4399. var promise = ret.promise();
  4400. ret.setHowMany(howMany);
  4401. ret.init();
  4402. return promise;
  4403. }
  4404. Promise.some = function (promises, howMany) {
  4405. return some(promises, howMany);
  4406. };
  4407. Promise.prototype.some = function (howMany) {
  4408. return some(this, howMany);
  4409. };
  4410. Promise._SomePromiseArray = SomePromiseArray;
  4411. };
  4412. },{"./errors":12,"./util":36}],32:[function(_dereq_,module,exports){
  4413. "use strict";
  4414. module.exports = function(Promise) {
  4415. function PromiseInspection(promise) {
  4416. if (promise !== undefined) {
  4417. promise = promise._target();
  4418. this._bitField = promise._bitField;
  4419. this._settledValueField = promise._isFateSealed()
  4420. ? promise._settledValue() : undefined;
  4421. }
  4422. else {
  4423. this._bitField = 0;
  4424. this._settledValueField = undefined;
  4425. }
  4426. }
  4427. PromiseInspection.prototype._settledValue = function() {
  4428. return this._settledValueField;
  4429. };
  4430. var value = PromiseInspection.prototype.value = function () {
  4431. if (!this.isFulfilled()) {
  4432. throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  4433. }
  4434. return this._settledValue();
  4435. };
  4436. var reason = PromiseInspection.prototype.error =
  4437. PromiseInspection.prototype.reason = function () {
  4438. if (!this.isRejected()) {
  4439. throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  4440. }
  4441. return this._settledValue();
  4442. };
  4443. var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
  4444. return (this._bitField & 33554432) !== 0;
  4445. };
  4446. var isRejected = PromiseInspection.prototype.isRejected = function () {
  4447. return (this._bitField & 16777216) !== 0;
  4448. };
  4449. var isPending = PromiseInspection.prototype.isPending = function () {
  4450. return (this._bitField & 50397184) === 0;
  4451. };
  4452. var isResolved = PromiseInspection.prototype.isResolved = function () {
  4453. return (this._bitField & 50331648) !== 0;
  4454. };
  4455. PromiseInspection.prototype.isCancelled = function() {
  4456. return (this._bitField & 8454144) !== 0;
  4457. };
  4458. Promise.prototype.__isCancelled = function() {
  4459. return (this._bitField & 65536) === 65536;
  4460. };
  4461. Promise.prototype._isCancelled = function() {
  4462. return this._target().__isCancelled();
  4463. };
  4464. Promise.prototype.isCancelled = function() {
  4465. return (this._target()._bitField & 8454144) !== 0;
  4466. };
  4467. Promise.prototype.isPending = function() {
  4468. return isPending.call(this._target());
  4469. };
  4470. Promise.prototype.isRejected = function() {
  4471. return isRejected.call(this._target());
  4472. };
  4473. Promise.prototype.isFulfilled = function() {
  4474. return isFulfilled.call(this._target());
  4475. };
  4476. Promise.prototype.isResolved = function() {
  4477. return isResolved.call(this._target());
  4478. };
  4479. Promise.prototype.value = function() {
  4480. return value.call(this._target());
  4481. };
  4482. Promise.prototype.reason = function() {
  4483. var target = this._target();
  4484. target._unsetRejectionIsUnhandled();
  4485. return reason.call(target);
  4486. };
  4487. Promise.prototype._value = function() {
  4488. return this._settledValue();
  4489. };
  4490. Promise.prototype._reason = function() {
  4491. this._unsetRejectionIsUnhandled();
  4492. return this._settledValue();
  4493. };
  4494. Promise.PromiseInspection = PromiseInspection;
  4495. };
  4496. },{}],33:[function(_dereq_,module,exports){
  4497. "use strict";
  4498. module.exports = function(Promise, INTERNAL) {
  4499. var util = _dereq_("./util");
  4500. var errorObj = util.errorObj;
  4501. var isObject = util.isObject;
  4502. function tryConvertToPromise(obj, context) {
  4503. if (isObject(obj)) {
  4504. if (obj instanceof Promise) return obj;
  4505. var then = getThen(obj);
  4506. if (then === errorObj) {
  4507. if (context) context._pushContext();
  4508. var ret = Promise.reject(then.e);
  4509. if (context) context._popContext();
  4510. return ret;
  4511. } else if (typeof then === "function") {
  4512. if (isAnyBluebirdPromise(obj)) {
  4513. var ret = new Promise(INTERNAL);
  4514. obj._then(
  4515. ret._fulfill,
  4516. ret._reject,
  4517. undefined,
  4518. ret,
  4519. null
  4520. );
  4521. return ret;
  4522. }
  4523. return doThenable(obj, then, context);
  4524. }
  4525. }
  4526. return obj;
  4527. }
  4528. function doGetThen(obj) {
  4529. return obj.then;
  4530. }
  4531. function getThen(obj) {
  4532. try {
  4533. return doGetThen(obj);
  4534. } catch (e) {
  4535. errorObj.e = e;
  4536. return errorObj;
  4537. }
  4538. }
  4539. var hasProp = {}.hasOwnProperty;
  4540. function isAnyBluebirdPromise(obj) {
  4541. try {
  4542. return hasProp.call(obj, "_promise0");
  4543. } catch (e) {
  4544. return false;
  4545. }
  4546. }
  4547. function doThenable(x, then, context) {
  4548. var promise = new Promise(INTERNAL);
  4549. var ret = promise;
  4550. if (context) context._pushContext();
  4551. promise._captureStackTrace();
  4552. if (context) context._popContext();
  4553. var synchronous = true;
  4554. var result = util.tryCatch(then).call(x, resolve, reject);
  4555. synchronous = false;
  4556. if (promise && result === errorObj) {
  4557. promise._rejectCallback(result.e, true, true);
  4558. promise = null;
  4559. }
  4560. function resolve(value) {
  4561. if (!promise) return;
  4562. promise._resolveCallback(value);
  4563. promise = null;
  4564. }
  4565. function reject(reason) {
  4566. if (!promise) return;
  4567. promise._rejectCallback(reason, synchronous, true);
  4568. promise = null;
  4569. }
  4570. return ret;
  4571. }
  4572. return tryConvertToPromise;
  4573. };
  4574. },{"./util":36}],34:[function(_dereq_,module,exports){
  4575. "use strict";
  4576. module.exports = function(Promise, INTERNAL, debug) {
  4577. var util = _dereq_("./util");
  4578. var TimeoutError = Promise.TimeoutError;
  4579. function HandleWrapper(handle) {
  4580. this.handle = handle;
  4581. }
  4582. HandleWrapper.prototype._resultCancelled = function() {
  4583. clearTimeout(this.handle);
  4584. };
  4585. var afterValue = function(value) { return delay(+this).thenReturn(value); };
  4586. var delay = Promise.delay = function (ms, value) {
  4587. var ret;
  4588. var handle;
  4589. if (value !== undefined) {
  4590. ret = Promise.resolve(value)
  4591. ._then(afterValue, null, null, ms, undefined);
  4592. if (debug.cancellation() && value instanceof Promise) {
  4593. ret._setOnCancel(value);
  4594. }
  4595. } else {
  4596. ret = new Promise(INTERNAL);
  4597. handle = setTimeout(function() { ret._fulfill(); }, +ms);
  4598. if (debug.cancellation()) {
  4599. ret._setOnCancel(new HandleWrapper(handle));
  4600. }
  4601. ret._captureStackTrace();
  4602. }
  4603. ret._setAsyncGuaranteed();
  4604. return ret;
  4605. };
  4606. Promise.prototype.delay = function (ms) {
  4607. return delay(ms, this);
  4608. };
  4609. var afterTimeout = function (promise, message, parent) {
  4610. var err;
  4611. if (typeof message !== "string") {
  4612. if (message instanceof Error) {
  4613. err = message;
  4614. } else {
  4615. err = new TimeoutError("operation timed out");
  4616. }
  4617. } else {
  4618. err = new TimeoutError(message);
  4619. }
  4620. util.markAsOriginatingFromRejection(err);
  4621. promise._attachExtraTrace(err);
  4622. promise._reject(err);
  4623. if (parent != null) {
  4624. parent.cancel();
  4625. }
  4626. };
  4627. function successClear(value) {
  4628. clearTimeout(this.handle);
  4629. return value;
  4630. }
  4631. function failureClear(reason) {
  4632. clearTimeout(this.handle);
  4633. throw reason;
  4634. }
  4635. Promise.prototype.timeout = function (ms, message) {
  4636. ms = +ms;
  4637. var ret, parent;
  4638. var handleWrapper = new HandleWrapper(setTimeout(function timeoutTimeout() {
  4639. if (ret.isPending()) {
  4640. afterTimeout(ret, message, parent);
  4641. }
  4642. }, ms));
  4643. if (debug.cancellation()) {
  4644. parent = this.then();
  4645. ret = parent._then(successClear, failureClear,
  4646. undefined, handleWrapper, undefined);
  4647. ret._setOnCancel(handleWrapper);
  4648. } else {
  4649. ret = this._then(successClear, failureClear,
  4650. undefined, handleWrapper, undefined);
  4651. }
  4652. return ret;
  4653. };
  4654. };
  4655. },{"./util":36}],35:[function(_dereq_,module,exports){
  4656. "use strict";
  4657. module.exports = function (Promise, apiRejection, tryConvertToPromise,
  4658. createContext, INTERNAL, debug) {
  4659. var util = _dereq_("./util");
  4660. var TypeError = _dereq_("./errors").TypeError;
  4661. var inherits = _dereq_("./util").inherits;
  4662. var errorObj = util.errorObj;
  4663. var tryCatch = util.tryCatch;
  4664. var NULL = {};
  4665. function thrower(e) {
  4666. setTimeout(function(){throw e;}, 0);
  4667. }
  4668. function castPreservingDisposable(thenable) {
  4669. var maybePromise = tryConvertToPromise(thenable);
  4670. if (maybePromise !== thenable &&
  4671. typeof thenable._isDisposable === "function" &&
  4672. typeof thenable._getDisposer === "function" &&
  4673. thenable._isDisposable()) {
  4674. maybePromise._setDisposable(thenable._getDisposer());
  4675. }
  4676. return maybePromise;
  4677. }
  4678. function dispose(resources, inspection) {
  4679. var i = 0;
  4680. var len = resources.length;
  4681. var ret = new Promise(INTERNAL);
  4682. function iterator() {
  4683. if (i >= len) return ret._fulfill();
  4684. var maybePromise = castPreservingDisposable(resources[i++]);
  4685. if (maybePromise instanceof Promise &&
  4686. maybePromise._isDisposable()) {
  4687. try {
  4688. maybePromise = tryConvertToPromise(
  4689. maybePromise._getDisposer().tryDispose(inspection),
  4690. resources.promise);
  4691. } catch (e) {
  4692. return thrower(e);
  4693. }
  4694. if (maybePromise instanceof Promise) {
  4695. return maybePromise._then(iterator, thrower,
  4696. null, null, null);
  4697. }
  4698. }
  4699. iterator();
  4700. }
  4701. iterator();
  4702. return ret;
  4703. }
  4704. function Disposer(data, promise, context) {
  4705. this._data = data;
  4706. this._promise = promise;
  4707. this._context = context;
  4708. }
  4709. Disposer.prototype.data = function () {
  4710. return this._data;
  4711. };
  4712. Disposer.prototype.promise = function () {
  4713. return this._promise;
  4714. };
  4715. Disposer.prototype.resource = function () {
  4716. if (this.promise().isFulfilled()) {
  4717. return this.promise().value();
  4718. }
  4719. return NULL;
  4720. };
  4721. Disposer.prototype.tryDispose = function(inspection) {
  4722. var resource = this.resource();
  4723. var context = this._context;
  4724. if (context !== undefined) context._pushContext();
  4725. var ret = resource !== NULL
  4726. ? this.doDispose(resource, inspection) : null;
  4727. if (context !== undefined) context._popContext();
  4728. this._promise._unsetDisposable();
  4729. this._data = null;
  4730. return ret;
  4731. };
  4732. Disposer.isDisposer = function (d) {
  4733. return (d != null &&
  4734. typeof d.resource === "function" &&
  4735. typeof d.tryDispose === "function");
  4736. };
  4737. function FunctionDisposer(fn, promise, context) {
  4738. this.constructor$(fn, promise, context);
  4739. }
  4740. inherits(FunctionDisposer, Disposer);
  4741. FunctionDisposer.prototype.doDispose = function (resource, inspection) {
  4742. var fn = this.data();
  4743. return fn.call(resource, resource, inspection);
  4744. };
  4745. function maybeUnwrapDisposer(value) {
  4746. if (Disposer.isDisposer(value)) {
  4747. this.resources[this.index]._setDisposable(value);
  4748. return value.promise();
  4749. }
  4750. return value;
  4751. }
  4752. function ResourceList(length) {
  4753. this.length = length;
  4754. this.promise = null;
  4755. this[length-1] = null;
  4756. }
  4757. ResourceList.prototype._resultCancelled = function() {
  4758. var len = this.length;
  4759. for (var i = 0; i < len; ++i) {
  4760. var item = this[i];
  4761. if (item instanceof Promise) {
  4762. item.cancel();
  4763. }
  4764. }
  4765. };
  4766. Promise.using = function () {
  4767. var len = arguments.length;
  4768. if (len < 2) return apiRejection(
  4769. "you must pass at least 2 arguments to Promise.using");
  4770. var fn = arguments[len - 1];
  4771. if (typeof fn !== "function") {
  4772. return apiRejection("expecting a function but got " + util.classString(fn));
  4773. }
  4774. var input;
  4775. var spreadArgs = true;
  4776. if (len === 2 && Array.isArray(arguments[0])) {
  4777. input = arguments[0];
  4778. len = input.length;
  4779. spreadArgs = false;
  4780. } else {
  4781. input = arguments;
  4782. len--;
  4783. }
  4784. var resources = new ResourceList(len);
  4785. for (var i = 0; i < len; ++i) {
  4786. var resource = input[i];
  4787. if (Disposer.isDisposer(resource)) {
  4788. var disposer = resource;
  4789. resource = resource.promise();
  4790. resource._setDisposable(disposer);
  4791. } else {
  4792. var maybePromise = tryConvertToPromise(resource);
  4793. if (maybePromise instanceof Promise) {
  4794. resource =
  4795. maybePromise._then(maybeUnwrapDisposer, null, null, {
  4796. resources: resources,
  4797. index: i
  4798. }, undefined);
  4799. }
  4800. }
  4801. resources[i] = resource;
  4802. }
  4803. var reflectedResources = new Array(resources.length);
  4804. for (var i = 0; i < reflectedResources.length; ++i) {
  4805. reflectedResources[i] = Promise.resolve(resources[i]).reflect();
  4806. }
  4807. var resultPromise = Promise.all(reflectedResources)
  4808. .then(function(inspections) {
  4809. for (var i = 0; i < inspections.length; ++i) {
  4810. var inspection = inspections[i];
  4811. if (inspection.isRejected()) {
  4812. errorObj.e = inspection.error();
  4813. return errorObj;
  4814. } else if (!inspection.isFulfilled()) {
  4815. resultPromise.cancel();
  4816. return;
  4817. }
  4818. inspections[i] = inspection.value();
  4819. }
  4820. promise._pushContext();
  4821. fn = tryCatch(fn);
  4822. var ret = spreadArgs
  4823. ? fn.apply(undefined, inspections) : fn(inspections);
  4824. var promiseCreated = promise._popContext();
  4825. debug.checkForgottenReturns(
  4826. ret, promiseCreated, "Promise.using", promise);
  4827. return ret;
  4828. });
  4829. var promise = resultPromise.lastly(function() {
  4830. var inspection = new Promise.PromiseInspection(resultPromise);
  4831. return dispose(resources, inspection);
  4832. });
  4833. resources.promise = promise;
  4834. promise._setOnCancel(resources);
  4835. return promise;
  4836. };
  4837. Promise.prototype._setDisposable = function (disposer) {
  4838. this._bitField = this._bitField | 131072;
  4839. this._disposer = disposer;
  4840. };
  4841. Promise.prototype._isDisposable = function () {
  4842. return (this._bitField & 131072) > 0;
  4843. };
  4844. Promise.prototype._getDisposer = function () {
  4845. return this._disposer;
  4846. };
  4847. Promise.prototype._unsetDisposable = function () {
  4848. this._bitField = this._bitField & (~131072);
  4849. this._disposer = undefined;
  4850. };
  4851. Promise.prototype.disposer = function (fn) {
  4852. if (typeof fn === "function") {
  4853. return new FunctionDisposer(fn, this, createContext());
  4854. }
  4855. throw new TypeError();
  4856. };
  4857. };
  4858. },{"./errors":12,"./util":36}],36:[function(_dereq_,module,exports){
  4859. "use strict";
  4860. var es5 = _dereq_("./es5");
  4861. var canEvaluate = typeof navigator == "undefined";
  4862. var errorObj = {e: {}};
  4863. var tryCatchTarget;
  4864. var globalObject = typeof self !== "undefined" ? self :
  4865. typeof window !== "undefined" ? window :
  4866. typeof global !== "undefined" ? global :
  4867. this !== undefined ? this : null;
  4868. function tryCatcher() {
  4869. try {
  4870. var target = tryCatchTarget;
  4871. tryCatchTarget = null;
  4872. return target.apply(this, arguments);
  4873. } catch (e) {
  4874. errorObj.e = e;
  4875. return errorObj;
  4876. }
  4877. }
  4878. function tryCatch(fn) {
  4879. tryCatchTarget = fn;
  4880. return tryCatcher;
  4881. }
  4882. var inherits = function(Child, Parent) {
  4883. var hasProp = {}.hasOwnProperty;
  4884. function T() {
  4885. this.constructor = Child;
  4886. this.constructor$ = Parent;
  4887. for (var propertyName in Parent.prototype) {
  4888. if (hasProp.call(Parent.prototype, propertyName) &&
  4889. propertyName.charAt(propertyName.length-1) !== "$"
  4890. ) {
  4891. this[propertyName + "$"] = Parent.prototype[propertyName];
  4892. }
  4893. }
  4894. }
  4895. T.prototype = Parent.prototype;
  4896. Child.prototype = new T();
  4897. return Child.prototype;
  4898. };
  4899. function isPrimitive(val) {
  4900. return val == null || val === true || val === false ||
  4901. typeof val === "string" || typeof val === "number";
  4902. }
  4903. function isObject(value) {
  4904. return typeof value === "function" ||
  4905. typeof value === "object" && value !== null;
  4906. }
  4907. function maybeWrapAsError(maybeError) {
  4908. if (!isPrimitive(maybeError)) return maybeError;
  4909. return new Error(safeToString(maybeError));
  4910. }
  4911. function withAppended(target, appendee) {
  4912. var len = target.length;
  4913. var ret = new Array(len + 1);
  4914. var i;
  4915. for (i = 0; i < len; ++i) {
  4916. ret[i] = target[i];
  4917. }
  4918. ret[i] = appendee;
  4919. return ret;
  4920. }
  4921. function getDataPropertyOrDefault(obj, key, defaultValue) {
  4922. if (es5.isES5) {
  4923. var desc = Object.getOwnPropertyDescriptor(obj, key);
  4924. if (desc != null) {
  4925. return desc.get == null && desc.set == null
  4926. ? desc.value
  4927. : defaultValue;
  4928. }
  4929. } else {
  4930. return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
  4931. }
  4932. }
  4933. function notEnumerableProp(obj, name, value) {
  4934. if (isPrimitive(obj)) return obj;
  4935. var descriptor = {
  4936. value: value,
  4937. configurable: true,
  4938. enumerable: false,
  4939. writable: true
  4940. };
  4941. es5.defineProperty(obj, name, descriptor);
  4942. return obj;
  4943. }
  4944. function thrower(r) {
  4945. throw r;
  4946. }
  4947. var inheritedDataKeys = (function() {
  4948. var excludedPrototypes = [
  4949. Array.prototype,
  4950. Object.prototype,
  4951. Function.prototype
  4952. ];
  4953. var isExcludedProto = function(val) {
  4954. for (var i = 0; i < excludedPrototypes.length; ++i) {
  4955. if (excludedPrototypes[i] === val) {
  4956. return true;
  4957. }
  4958. }
  4959. return false;
  4960. };
  4961. if (es5.isES5) {
  4962. var getKeys = Object.getOwnPropertyNames;
  4963. return function(obj) {
  4964. var ret = [];
  4965. var visitedKeys = Object.create(null);
  4966. while (obj != null && !isExcludedProto(obj)) {
  4967. var keys;
  4968. try {
  4969. keys = getKeys(obj);
  4970. } catch (e) {
  4971. return ret;
  4972. }
  4973. for (var i = 0; i < keys.length; ++i) {
  4974. var key = keys[i];
  4975. if (visitedKeys[key]) continue;
  4976. visitedKeys[key] = true;
  4977. var desc = Object.getOwnPropertyDescriptor(obj, key);
  4978. if (desc != null && desc.get == null && desc.set == null) {
  4979. ret.push(key);
  4980. }
  4981. }
  4982. obj = es5.getPrototypeOf(obj);
  4983. }
  4984. return ret;
  4985. };
  4986. } else {
  4987. var hasProp = {}.hasOwnProperty;
  4988. return function(obj) {
  4989. if (isExcludedProto(obj)) return [];
  4990. var ret = [];
  4991. /*jshint forin:false */
  4992. enumeration: for (var key in obj) {
  4993. if (hasProp.call(obj, key)) {
  4994. ret.push(key);
  4995. } else {
  4996. for (var i = 0; i < excludedPrototypes.length; ++i) {
  4997. if (hasProp.call(excludedPrototypes[i], key)) {
  4998. continue enumeration;
  4999. }
  5000. }
  5001. ret.push(key);
  5002. }
  5003. }
  5004. return ret;
  5005. };
  5006. }
  5007. })();
  5008. var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/;
  5009. function isClass(fn) {
  5010. try {
  5011. if (typeof fn === "function") {
  5012. var keys = es5.names(fn.prototype);
  5013. var hasMethods = es5.isES5 && keys.length > 1;
  5014. var hasMethodsOtherThanConstructor = keys.length > 0 &&
  5015. !(keys.length === 1 && keys[0] === "constructor");
  5016. var hasThisAssignmentAndStaticMethods =
  5017. thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0;
  5018. if (hasMethods || hasMethodsOtherThanConstructor ||
  5019. hasThisAssignmentAndStaticMethods) {
  5020. return true;
  5021. }
  5022. }
  5023. return false;
  5024. } catch (e) {
  5025. return false;
  5026. }
  5027. }
  5028. function toFastProperties(obj) {
  5029. /*jshint -W027,-W055,-W031*/
  5030. function FakeConstructor() {}
  5031. FakeConstructor.prototype = obj;
  5032. var l = 8;
  5033. while (l--) new FakeConstructor();
  5034. return obj;
  5035. eval(obj);
  5036. }
  5037. var rident = /^[a-z$_][a-z$_0-9]*$/i;
  5038. function isIdentifier(str) {
  5039. return rident.test(str);
  5040. }
  5041. function filledRange(count, prefix, suffix) {
  5042. var ret = new Array(count);
  5043. for(var i = 0; i < count; ++i) {
  5044. ret[i] = prefix + i + suffix;
  5045. }
  5046. return ret;
  5047. }
  5048. function safeToString(obj) {
  5049. try {
  5050. return obj + "";
  5051. } catch (e) {
  5052. return "[no string representation]";
  5053. }
  5054. }
  5055. function isError(obj) {
  5056. return obj !== null &&
  5057. typeof obj === "object" &&
  5058. typeof obj.message === "string" &&
  5059. typeof obj.name === "string";
  5060. }
  5061. function markAsOriginatingFromRejection(e) {
  5062. try {
  5063. notEnumerableProp(e, "isOperational", true);
  5064. }
  5065. catch(ignore) {}
  5066. }
  5067. function originatesFromRejection(e) {
  5068. if (e == null) return false;
  5069. return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) ||
  5070. e["isOperational"] === true);
  5071. }
  5072. function canAttachTrace(obj) {
  5073. return isError(obj) && es5.propertyIsWritable(obj, "stack");
  5074. }
  5075. var ensureErrorObject = (function() {
  5076. if (!("stack" in new Error())) {
  5077. return function(value) {
  5078. if (canAttachTrace(value)) return value;
  5079. try {throw new Error(safeToString(value));}
  5080. catch(err) {return err;}
  5081. };
  5082. } else {
  5083. return function(value) {
  5084. if (canAttachTrace(value)) return value;
  5085. return new Error(safeToString(value));
  5086. };
  5087. }
  5088. })();
  5089. function classString(obj) {
  5090. return {}.toString.call(obj);
  5091. }
  5092. function copyDescriptors(from, to, filter) {
  5093. var keys = es5.names(from);
  5094. for (var i = 0; i < keys.length; ++i) {
  5095. var key = keys[i];
  5096. if (filter(key)) {
  5097. try {
  5098. es5.defineProperty(to, key, es5.getDescriptor(from, key));
  5099. } catch (ignore) {}
  5100. }
  5101. }
  5102. }
  5103. var asArray = function(v) {
  5104. if (es5.isArray(v)) {
  5105. return v;
  5106. }
  5107. return null;
  5108. };
  5109. if (typeof Symbol !== "undefined" && Symbol.iterator) {
  5110. var ArrayFrom = typeof Array.from === "function" ? function(v) {
  5111. return Array.from(v);
  5112. } : function(v) {
  5113. var ret = [];
  5114. var it = v[Symbol.iterator]();
  5115. var itResult;
  5116. while (!((itResult = it.next()).done)) {
  5117. ret.push(itResult.value);
  5118. }
  5119. return ret;
  5120. };
  5121. asArray = function(v) {
  5122. if (es5.isArray(v)) {
  5123. return v;
  5124. } else if (v != null && typeof v[Symbol.iterator] === "function") {
  5125. return ArrayFrom(v);
  5126. }
  5127. return null;
  5128. };
  5129. }
  5130. var isNode = typeof process !== "undefined" &&
  5131. classString(process).toLowerCase() === "[object process]";
  5132. function env(key, def) {
  5133. return isNode ? process.env[key] : def;
  5134. }
  5135. function getNativePromise() {
  5136. if (typeof Promise === "function") {
  5137. try {
  5138. var promise = new Promise(function(){});
  5139. if ({}.toString.call(promise) === "[object Promise]") {
  5140. return Promise;
  5141. }
  5142. } catch (e) {}
  5143. }
  5144. }
  5145. function domainBind(self, cb) {
  5146. return self.bind(cb);
  5147. }
  5148. var ret = {
  5149. isClass: isClass,
  5150. isIdentifier: isIdentifier,
  5151. inheritedDataKeys: inheritedDataKeys,
  5152. getDataPropertyOrDefault: getDataPropertyOrDefault,
  5153. thrower: thrower,
  5154. isArray: es5.isArray,
  5155. asArray: asArray,
  5156. notEnumerableProp: notEnumerableProp,
  5157. isPrimitive: isPrimitive,
  5158. isObject: isObject,
  5159. isError: isError,
  5160. canEvaluate: canEvaluate,
  5161. errorObj: errorObj,
  5162. tryCatch: tryCatch,
  5163. inherits: inherits,
  5164. withAppended: withAppended,
  5165. maybeWrapAsError: maybeWrapAsError,
  5166. toFastProperties: toFastProperties,
  5167. filledRange: filledRange,
  5168. toString: safeToString,
  5169. canAttachTrace: canAttachTrace,
  5170. ensureErrorObject: ensureErrorObject,
  5171. originatesFromRejection: originatesFromRejection,
  5172. markAsOriginatingFromRejection: markAsOriginatingFromRejection,
  5173. classString: classString,
  5174. copyDescriptors: copyDescriptors,
  5175. hasDevTools: typeof chrome !== "undefined" && chrome &&
  5176. typeof chrome.loadTimes === "function",
  5177. isNode: isNode,
  5178. env: env,
  5179. global: globalObject,
  5180. getNativePromise: getNativePromise,
  5181. domainBind: domainBind
  5182. };
  5183. ret.isRecentNode = ret.isNode && (function() {
  5184. var version = process.versions.node.split(".").map(Number);
  5185. return (version[0] === 0 && version[1] > 10) || (version[0] > 0);
  5186. })();
  5187. if (ret.isNode) ret.toFastProperties(process);
  5188. try {throw new Error(); } catch (e) {ret.lastLineError = e;}
  5189. module.exports = ret;
  5190. },{"./es5":13}]},{},[4])(4)
  5191. }); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }
  5192. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5193. },{"_process":21}],4:[function(require,module,exports){
  5194. },{}],5:[function(require,module,exports){
  5195. (function (global){
  5196. 'use strict';
  5197. var buffer = require('buffer');
  5198. var Buffer = buffer.Buffer;
  5199. var SlowBuffer = buffer.SlowBuffer;
  5200. var MAX_LEN = buffer.kMaxLength || 2147483647;
  5201. exports.alloc = function alloc(size, fill, encoding) {
  5202. if (typeof Buffer.alloc === 'function') {
  5203. return Buffer.alloc(size, fill, encoding);
  5204. }
  5205. if (typeof encoding === 'number') {
  5206. throw new TypeError('encoding must not be number');
  5207. }
  5208. if (typeof size !== 'number') {
  5209. throw new TypeError('size must be a number');
  5210. }
  5211. if (size > MAX_LEN) {
  5212. throw new RangeError('size is too large');
  5213. }
  5214. var enc = encoding;
  5215. var _fill = fill;
  5216. if (_fill === undefined) {
  5217. enc = undefined;
  5218. _fill = 0;
  5219. }
  5220. var buf = new Buffer(size);
  5221. if (typeof _fill === 'string') {
  5222. var fillBuf = new Buffer(_fill, enc);
  5223. var flen = fillBuf.length;
  5224. var i = -1;
  5225. while (++i < size) {
  5226. buf[i] = fillBuf[i % flen];
  5227. }
  5228. } else {
  5229. buf.fill(_fill);
  5230. }
  5231. return buf;
  5232. }
  5233. exports.allocUnsafe = function allocUnsafe(size) {
  5234. if (typeof Buffer.allocUnsafe === 'function') {
  5235. return Buffer.allocUnsafe(size);
  5236. }
  5237. if (typeof size !== 'number') {
  5238. throw new TypeError('size must be a number');
  5239. }
  5240. if (size > MAX_LEN) {
  5241. throw new RangeError('size is too large');
  5242. }
  5243. return new Buffer(size);
  5244. }
  5245. exports.from = function from(value, encodingOrOffset, length) {
  5246. if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) {
  5247. return Buffer.from(value, encodingOrOffset, length);
  5248. }
  5249. if (typeof value === 'number') {
  5250. throw new TypeError('"value" argument must not be a number');
  5251. }
  5252. if (typeof value === 'string') {
  5253. return new Buffer(value, encodingOrOffset);
  5254. }
  5255. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  5256. var offset = encodingOrOffset;
  5257. if (arguments.length === 1) {
  5258. return new Buffer(value);
  5259. }
  5260. if (typeof offset === 'undefined') {
  5261. offset = 0;
  5262. }
  5263. var len = length;
  5264. if (typeof len === 'undefined') {
  5265. len = value.byteLength - offset;
  5266. }
  5267. if (offset >= value.byteLength) {
  5268. throw new RangeError('\'offset\' is out of bounds');
  5269. }
  5270. if (len > value.byteLength - offset) {
  5271. throw new RangeError('\'length\' is out of bounds');
  5272. }
  5273. return new Buffer(value.slice(offset, offset + len));
  5274. }
  5275. if (Buffer.isBuffer(value)) {
  5276. var out = new Buffer(value.length);
  5277. value.copy(out, 0, 0, value.length);
  5278. return out;
  5279. }
  5280. if (value) {
  5281. if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) {
  5282. return new Buffer(value);
  5283. }
  5284. if (value.type === 'Buffer' && Array.isArray(value.data)) {
  5285. return new Buffer(value.data);
  5286. }
  5287. }
  5288. throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.');
  5289. }
  5290. exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
  5291. if (typeof Buffer.allocUnsafeSlow === 'function') {
  5292. return Buffer.allocUnsafeSlow(size);
  5293. }
  5294. if (typeof size !== 'number') {
  5295. throw new TypeError('size must be a number');
  5296. }
  5297. if (size >= MAX_LEN) {
  5298. throw new RangeError('size is too large');
  5299. }
  5300. return new SlowBuffer(size);
  5301. }
  5302. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5303. },{"buffer":6}],6:[function(require,module,exports){
  5304. (function (global){
  5305. /*!
  5306. * The buffer module from node.js, for the browser.
  5307. *
  5308. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  5309. * @license MIT
  5310. */
  5311. /* eslint-disable no-proto */
  5312. 'use strict'
  5313. var base64 = require('base64-js')
  5314. var ieee754 = require('ieee754')
  5315. var isArray = require('isarray')
  5316. exports.Buffer = Buffer
  5317. exports.SlowBuffer = SlowBuffer
  5318. exports.INSPECT_MAX_BYTES = 50
  5319. /**
  5320. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  5321. * === true Use Uint8Array implementation (fastest)
  5322. * === false Use Object implementation (most compatible, even IE6)
  5323. *
  5324. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  5325. * Opera 11.6+, iOS 4.2+.
  5326. *
  5327. * Due to various browser bugs, sometimes the Object implementation will be used even
  5328. * when the browser supports typed arrays.
  5329. *
  5330. * Note:
  5331. *
  5332. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  5333. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  5334. *
  5335. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  5336. *
  5337. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  5338. * incorrect length in some situations.
  5339. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  5340. * get the Object implementation, which is slower but behaves correctly.
  5341. */
  5342. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  5343. ? global.TYPED_ARRAY_SUPPORT
  5344. : typedArraySupport()
  5345. /*
  5346. * Export kMaxLength after typed array support is determined.
  5347. */
  5348. exports.kMaxLength = kMaxLength()
  5349. function typedArraySupport () {
  5350. try {
  5351. var arr = new Uint8Array(1)
  5352. arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
  5353. return arr.foo() === 42 && // typed array instances can be augmented
  5354. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  5355. arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  5356. } catch (e) {
  5357. return false
  5358. }
  5359. }
  5360. function kMaxLength () {
  5361. return Buffer.TYPED_ARRAY_SUPPORT
  5362. ? 0x7fffffff
  5363. : 0x3fffffff
  5364. }
  5365. function createBuffer (that, length) {
  5366. if (kMaxLength() < length) {
  5367. throw new RangeError('Invalid typed array length')
  5368. }
  5369. if (Buffer.TYPED_ARRAY_SUPPORT) {
  5370. // Return an augmented `Uint8Array` instance, for best performance
  5371. that = new Uint8Array(length)
  5372. that.__proto__ = Buffer.prototype
  5373. } else {
  5374. // Fallback: Return an object instance of the Buffer class
  5375. if (that === null) {
  5376. that = new Buffer(length)
  5377. }
  5378. that.length = length
  5379. }
  5380. return that
  5381. }
  5382. /**
  5383. * The Buffer constructor returns instances of `Uint8Array` that have their
  5384. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  5385. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  5386. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  5387. * returns a single octet.
  5388. *
  5389. * The `Uint8Array` prototype remains unmodified.
  5390. */
  5391. function Buffer (arg, encodingOrOffset, length) {
  5392. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  5393. return new Buffer(arg, encodingOrOffset, length)
  5394. }
  5395. // Common case.
  5396. if (typeof arg === 'number') {
  5397. if (typeof encodingOrOffset === 'string') {
  5398. throw new Error(
  5399. 'If encoding is specified then the first argument must be a string'
  5400. )
  5401. }
  5402. return allocUnsafe(this, arg)
  5403. }
  5404. return from(this, arg, encodingOrOffset, length)
  5405. }
  5406. Buffer.poolSize = 8192 // not used by this implementation
  5407. // TODO: Legacy, not needed anymore. Remove in next major version.
  5408. Buffer._augment = function (arr) {
  5409. arr.__proto__ = Buffer.prototype
  5410. return arr
  5411. }
  5412. function from (that, value, encodingOrOffset, length) {
  5413. if (typeof value === 'number') {
  5414. throw new TypeError('"value" argument must not be a number')
  5415. }
  5416. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  5417. return fromArrayBuffer(that, value, encodingOrOffset, length)
  5418. }
  5419. if (typeof value === 'string') {
  5420. return fromString(that, value, encodingOrOffset)
  5421. }
  5422. return fromObject(that, value)
  5423. }
  5424. /**
  5425. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  5426. * if value is a number.
  5427. * Buffer.from(str[, encoding])
  5428. * Buffer.from(array)
  5429. * Buffer.from(buffer)
  5430. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  5431. **/
  5432. Buffer.from = function (value, encodingOrOffset, length) {
  5433. return from(null, value, encodingOrOffset, length)
  5434. }
  5435. if (Buffer.TYPED_ARRAY_SUPPORT) {
  5436. Buffer.prototype.__proto__ = Uint8Array.prototype
  5437. Buffer.__proto__ = Uint8Array
  5438. if (typeof Symbol !== 'undefined' && Symbol.species &&
  5439. Buffer[Symbol.species] === Buffer) {
  5440. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  5441. Object.defineProperty(Buffer, Symbol.species, {
  5442. value: null,
  5443. configurable: true
  5444. })
  5445. }
  5446. }
  5447. function assertSize (size) {
  5448. if (typeof size !== 'number') {
  5449. throw new TypeError('"size" argument must be a number')
  5450. } else if (size < 0) {
  5451. throw new RangeError('"size" argument must not be negative')
  5452. }
  5453. }
  5454. function alloc (that, size, fill, encoding) {
  5455. assertSize(size)
  5456. if (size <= 0) {
  5457. return createBuffer(that, size)
  5458. }
  5459. if (fill !== undefined) {
  5460. // Only pay attention to encoding if it's a string. This
  5461. // prevents accidentally sending in a number that would
  5462. // be interpretted as a start offset.
  5463. return typeof encoding === 'string'
  5464. ? createBuffer(that, size).fill(fill, encoding)
  5465. : createBuffer(that, size).fill(fill)
  5466. }
  5467. return createBuffer(that, size)
  5468. }
  5469. /**
  5470. * Creates a new filled Buffer instance.
  5471. * alloc(size[, fill[, encoding]])
  5472. **/
  5473. Buffer.alloc = function (size, fill, encoding) {
  5474. return alloc(null, size, fill, encoding)
  5475. }
  5476. function allocUnsafe (that, size) {
  5477. assertSize(size)
  5478. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  5479. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  5480. for (var i = 0; i < size; ++i) {
  5481. that[i] = 0
  5482. }
  5483. }
  5484. return that
  5485. }
  5486. /**
  5487. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  5488. * */
  5489. Buffer.allocUnsafe = function (size) {
  5490. return allocUnsafe(null, size)
  5491. }
  5492. /**
  5493. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  5494. */
  5495. Buffer.allocUnsafeSlow = function (size) {
  5496. return allocUnsafe(null, size)
  5497. }
  5498. function fromString (that, string, encoding) {
  5499. if (typeof encoding !== 'string' || encoding === '') {
  5500. encoding = 'utf8'
  5501. }
  5502. if (!Buffer.isEncoding(encoding)) {
  5503. throw new TypeError('"encoding" must be a valid string encoding')
  5504. }
  5505. var length = byteLength(string, encoding) | 0
  5506. that = createBuffer(that, length)
  5507. var actual = that.write(string, encoding)
  5508. if (actual !== length) {
  5509. // Writing a hex string, for example, that contains invalid characters will
  5510. // cause everything after the first invalid character to be ignored. (e.g.
  5511. // 'abxxcd' will be treated as 'ab')
  5512. that = that.slice(0, actual)
  5513. }
  5514. return that
  5515. }
  5516. function fromArrayLike (that, array) {
  5517. var length = array.length < 0 ? 0 : checked(array.length) | 0
  5518. that = createBuffer(that, length)
  5519. for (var i = 0; i < length; i += 1) {
  5520. that[i] = array[i] & 255
  5521. }
  5522. return that
  5523. }
  5524. function fromArrayBuffer (that, array, byteOffset, length) {
  5525. array.byteLength // this throws if `array` is not a valid ArrayBuffer
  5526. if (byteOffset < 0 || array.byteLength < byteOffset) {
  5527. throw new RangeError('\'offset\' is out of bounds')
  5528. }
  5529. if (array.byteLength < byteOffset + (length || 0)) {
  5530. throw new RangeError('\'length\' is out of bounds')
  5531. }
  5532. if (byteOffset === undefined && length === undefined) {
  5533. array = new Uint8Array(array)
  5534. } else if (length === undefined) {
  5535. array = new Uint8Array(array, byteOffset)
  5536. } else {
  5537. array = new Uint8Array(array, byteOffset, length)
  5538. }
  5539. if (Buffer.TYPED_ARRAY_SUPPORT) {
  5540. // Return an augmented `Uint8Array` instance, for best performance
  5541. that = array
  5542. that.__proto__ = Buffer.prototype
  5543. } else {
  5544. // Fallback: Return an object instance of the Buffer class
  5545. that = fromArrayLike(that, array)
  5546. }
  5547. return that
  5548. }
  5549. function fromObject (that, obj) {
  5550. if (Buffer.isBuffer(obj)) {
  5551. var len = checked(obj.length) | 0
  5552. that = createBuffer(that, len)
  5553. if (that.length === 0) {
  5554. return that
  5555. }
  5556. obj.copy(that, 0, 0, len)
  5557. return that
  5558. }
  5559. if (obj) {
  5560. if ((typeof ArrayBuffer !== 'undefined' &&
  5561. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  5562. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  5563. return createBuffer(that, 0)
  5564. }
  5565. return fromArrayLike(that, obj)
  5566. }
  5567. if (obj.type === 'Buffer' && isArray(obj.data)) {
  5568. return fromArrayLike(that, obj.data)
  5569. }
  5570. }
  5571. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  5572. }
  5573. function checked (length) {
  5574. // Note: cannot use `length < kMaxLength()` here because that fails when
  5575. // length is NaN (which is otherwise coerced to zero.)
  5576. if (length >= kMaxLength()) {
  5577. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  5578. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  5579. }
  5580. return length | 0
  5581. }
  5582. function SlowBuffer (length) {
  5583. if (+length != length) { // eslint-disable-line eqeqeq
  5584. length = 0
  5585. }
  5586. return Buffer.alloc(+length)
  5587. }
  5588. Buffer.isBuffer = function isBuffer (b) {
  5589. return !!(b != null && b._isBuffer)
  5590. }
  5591. Buffer.compare = function compare (a, b) {
  5592. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  5593. throw new TypeError('Arguments must be Buffers')
  5594. }
  5595. if (a === b) return 0
  5596. var x = a.length
  5597. var y = b.length
  5598. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  5599. if (a[i] !== b[i]) {
  5600. x = a[i]
  5601. y = b[i]
  5602. break
  5603. }
  5604. }
  5605. if (x < y) return -1
  5606. if (y < x) return 1
  5607. return 0
  5608. }
  5609. Buffer.isEncoding = function isEncoding (encoding) {
  5610. switch (String(encoding).toLowerCase()) {
  5611. case 'hex':
  5612. case 'utf8':
  5613. case 'utf-8':
  5614. case 'ascii':
  5615. case 'latin1':
  5616. case 'binary':
  5617. case 'base64':
  5618. case 'ucs2':
  5619. case 'ucs-2':
  5620. case 'utf16le':
  5621. case 'utf-16le':
  5622. return true
  5623. default:
  5624. return false
  5625. }
  5626. }
  5627. Buffer.concat = function concat (list, length) {
  5628. if (!isArray(list)) {
  5629. throw new TypeError('"list" argument must be an Array of Buffers')
  5630. }
  5631. if (list.length === 0) {
  5632. return Buffer.alloc(0)
  5633. }
  5634. var i
  5635. if (length === undefined) {
  5636. length = 0
  5637. for (i = 0; i < list.length; ++i) {
  5638. length += list[i].length
  5639. }
  5640. }
  5641. var buffer = Buffer.allocUnsafe(length)
  5642. var pos = 0
  5643. for (i = 0; i < list.length; ++i) {
  5644. var buf = list[i]
  5645. if (!Buffer.isBuffer(buf)) {
  5646. throw new TypeError('"list" argument must be an Array of Buffers')
  5647. }
  5648. buf.copy(buffer, pos)
  5649. pos += buf.length
  5650. }
  5651. return buffer
  5652. }
  5653. function byteLength (string, encoding) {
  5654. if (Buffer.isBuffer(string)) {
  5655. return string.length
  5656. }
  5657. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  5658. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  5659. return string.byteLength
  5660. }
  5661. if (typeof string !== 'string') {
  5662. string = '' + string
  5663. }
  5664. var len = string.length
  5665. if (len === 0) return 0
  5666. // Use a for loop to avoid recursion
  5667. var loweredCase = false
  5668. for (;;) {
  5669. switch (encoding) {
  5670. case 'ascii':
  5671. case 'latin1':
  5672. case 'binary':
  5673. return len
  5674. case 'utf8':
  5675. case 'utf-8':
  5676. case undefined:
  5677. return utf8ToBytes(string).length
  5678. case 'ucs2':
  5679. case 'ucs-2':
  5680. case 'utf16le':
  5681. case 'utf-16le':
  5682. return len * 2
  5683. case 'hex':
  5684. return len >>> 1
  5685. case 'base64':
  5686. return base64ToBytes(string).length
  5687. default:
  5688. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  5689. encoding = ('' + encoding).toLowerCase()
  5690. loweredCase = true
  5691. }
  5692. }
  5693. }
  5694. Buffer.byteLength = byteLength
  5695. function slowToString (encoding, start, end) {
  5696. var loweredCase = false
  5697. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  5698. // property of a typed array.
  5699. // This behaves neither like String nor Uint8Array in that we set start/end
  5700. // to their upper/lower bounds if the value passed is out of range.
  5701. // undefined is handled specially as per ECMA-262 6th Edition,
  5702. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  5703. if (start === undefined || start < 0) {
  5704. start = 0
  5705. }
  5706. // Return early if start > this.length. Done here to prevent potential uint32
  5707. // coercion fail below.
  5708. if (start > this.length) {
  5709. return ''
  5710. }
  5711. if (end === undefined || end > this.length) {
  5712. end = this.length
  5713. }
  5714. if (end <= 0) {
  5715. return ''
  5716. }
  5717. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  5718. end >>>= 0
  5719. start >>>= 0
  5720. if (end <= start) {
  5721. return ''
  5722. }
  5723. if (!encoding) encoding = 'utf8'
  5724. while (true) {
  5725. switch (encoding) {
  5726. case 'hex':
  5727. return hexSlice(this, start, end)
  5728. case 'utf8':
  5729. case 'utf-8':
  5730. return utf8Slice(this, start, end)
  5731. case 'ascii':
  5732. return asciiSlice(this, start, end)
  5733. case 'latin1':
  5734. case 'binary':
  5735. return latin1Slice(this, start, end)
  5736. case 'base64':
  5737. return base64Slice(this, start, end)
  5738. case 'ucs2':
  5739. case 'ucs-2':
  5740. case 'utf16le':
  5741. case 'utf-16le':
  5742. return utf16leSlice(this, start, end)
  5743. default:
  5744. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  5745. encoding = (encoding + '').toLowerCase()
  5746. loweredCase = true
  5747. }
  5748. }
  5749. }
  5750. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  5751. // Buffer instances.
  5752. Buffer.prototype._isBuffer = true
  5753. function swap (b, n, m) {
  5754. var i = b[n]
  5755. b[n] = b[m]
  5756. b[m] = i
  5757. }
  5758. Buffer.prototype.swap16 = function swap16 () {
  5759. var len = this.length
  5760. if (len % 2 !== 0) {
  5761. throw new RangeError('Buffer size must be a multiple of 16-bits')
  5762. }
  5763. for (var i = 0; i < len; i += 2) {
  5764. swap(this, i, i + 1)
  5765. }
  5766. return this
  5767. }
  5768. Buffer.prototype.swap32 = function swap32 () {
  5769. var len = this.length
  5770. if (len % 4 !== 0) {
  5771. throw new RangeError('Buffer size must be a multiple of 32-bits')
  5772. }
  5773. for (var i = 0; i < len; i += 4) {
  5774. swap(this, i, i + 3)
  5775. swap(this, i + 1, i + 2)
  5776. }
  5777. return this
  5778. }
  5779. Buffer.prototype.swap64 = function swap64 () {
  5780. var len = this.length
  5781. if (len % 8 !== 0) {
  5782. throw new RangeError('Buffer size must be a multiple of 64-bits')
  5783. }
  5784. for (var i = 0; i < len; i += 8) {
  5785. swap(this, i, i + 7)
  5786. swap(this, i + 1, i + 6)
  5787. swap(this, i + 2, i + 5)
  5788. swap(this, i + 3, i + 4)
  5789. }
  5790. return this
  5791. }
  5792. Buffer.prototype.toString = function toString () {
  5793. var length = this.length | 0
  5794. if (length === 0) return ''
  5795. if (arguments.length === 0) return utf8Slice(this, 0, length)
  5796. return slowToString.apply(this, arguments)
  5797. }
  5798. Buffer.prototype.equals = function equals (b) {
  5799. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  5800. if (this === b) return true
  5801. return Buffer.compare(this, b) === 0
  5802. }
  5803. Buffer.prototype.inspect = function inspect () {
  5804. var str = ''
  5805. var max = exports.INSPECT_MAX_BYTES
  5806. if (this.length > 0) {
  5807. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  5808. if (this.length > max) str += ' ... '
  5809. }
  5810. return '<Buffer ' + str + '>'
  5811. }
  5812. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  5813. if (!Buffer.isBuffer(target)) {
  5814. throw new TypeError('Argument must be a Buffer')
  5815. }
  5816. if (start === undefined) {
  5817. start = 0
  5818. }
  5819. if (end === undefined) {
  5820. end = target ? target.length : 0
  5821. }
  5822. if (thisStart === undefined) {
  5823. thisStart = 0
  5824. }
  5825. if (thisEnd === undefined) {
  5826. thisEnd = this.length
  5827. }
  5828. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  5829. throw new RangeError('out of range index')
  5830. }
  5831. if (thisStart >= thisEnd && start >= end) {
  5832. return 0
  5833. }
  5834. if (thisStart >= thisEnd) {
  5835. return -1
  5836. }
  5837. if (start >= end) {
  5838. return 1
  5839. }
  5840. start >>>= 0
  5841. end >>>= 0
  5842. thisStart >>>= 0
  5843. thisEnd >>>= 0
  5844. if (this === target) return 0
  5845. var x = thisEnd - thisStart
  5846. var y = end - start
  5847. var len = Math.min(x, y)
  5848. var thisCopy = this.slice(thisStart, thisEnd)
  5849. var targetCopy = target.slice(start, end)
  5850. for (var i = 0; i < len; ++i) {
  5851. if (thisCopy[i] !== targetCopy[i]) {
  5852. x = thisCopy[i]
  5853. y = targetCopy[i]
  5854. break
  5855. }
  5856. }
  5857. if (x < y) return -1
  5858. if (y < x) return 1
  5859. return 0
  5860. }
  5861. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  5862. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  5863. //
  5864. // Arguments:
  5865. // - buffer - a Buffer to search
  5866. // - val - a string, Buffer, or number
  5867. // - byteOffset - an index into `buffer`; will be clamped to an int32
  5868. // - encoding - an optional encoding, relevant is val is a string
  5869. // - dir - true for indexOf, false for lastIndexOf
  5870. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  5871. // Empty buffer means no match
  5872. if (buffer.length === 0) return -1
  5873. // Normalize byteOffset
  5874. if (typeof byteOffset === 'string') {
  5875. encoding = byteOffset
  5876. byteOffset = 0
  5877. } else if (byteOffset > 0x7fffffff) {
  5878. byteOffset = 0x7fffffff
  5879. } else if (byteOffset < -0x80000000) {
  5880. byteOffset = -0x80000000
  5881. }
  5882. byteOffset = +byteOffset // Coerce to Number.
  5883. if (isNaN(byteOffset)) {
  5884. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  5885. byteOffset = dir ? 0 : (buffer.length - 1)
  5886. }
  5887. // Normalize byteOffset: negative offsets start from the end of the buffer
  5888. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  5889. if (byteOffset >= buffer.length) {
  5890. if (dir) return -1
  5891. else byteOffset = buffer.length - 1
  5892. } else if (byteOffset < 0) {
  5893. if (dir) byteOffset = 0
  5894. else return -1
  5895. }
  5896. // Normalize val
  5897. if (typeof val === 'string') {
  5898. val = Buffer.from(val, encoding)
  5899. }
  5900. // Finally, search either indexOf (if dir is true) or lastIndexOf
  5901. if (Buffer.isBuffer(val)) {
  5902. // Special case: looking for empty string/buffer always fails
  5903. if (val.length === 0) {
  5904. return -1
  5905. }
  5906. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  5907. } else if (typeof val === 'number') {
  5908. val = val & 0xFF // Search for a byte value [0-255]
  5909. if (Buffer.TYPED_ARRAY_SUPPORT &&
  5910. typeof Uint8Array.prototype.indexOf === 'function') {
  5911. if (dir) {
  5912. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  5913. } else {
  5914. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  5915. }
  5916. }
  5917. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  5918. }
  5919. throw new TypeError('val must be string, number or Buffer')
  5920. }
  5921. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  5922. var indexSize = 1
  5923. var arrLength = arr.length
  5924. var valLength = val.length
  5925. if (encoding !== undefined) {
  5926. encoding = String(encoding).toLowerCase()
  5927. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  5928. encoding === 'utf16le' || encoding === 'utf-16le') {
  5929. if (arr.length < 2 || val.length < 2) {
  5930. return -1
  5931. }
  5932. indexSize = 2
  5933. arrLength /= 2
  5934. valLength /= 2
  5935. byteOffset /= 2
  5936. }
  5937. }
  5938. function read (buf, i) {
  5939. if (indexSize === 1) {
  5940. return buf[i]
  5941. } else {
  5942. return buf.readUInt16BE(i * indexSize)
  5943. }
  5944. }
  5945. var i
  5946. if (dir) {
  5947. var foundIndex = -1
  5948. for (i = byteOffset; i < arrLength; i++) {
  5949. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  5950. if (foundIndex === -1) foundIndex = i
  5951. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  5952. } else {
  5953. if (foundIndex !== -1) i -= i - foundIndex
  5954. foundIndex = -1
  5955. }
  5956. }
  5957. } else {
  5958. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  5959. for (i = byteOffset; i >= 0; i--) {
  5960. var found = true
  5961. for (var j = 0; j < valLength; j++) {
  5962. if (read(arr, i + j) !== read(val, j)) {
  5963. found = false
  5964. break
  5965. }
  5966. }
  5967. if (found) return i
  5968. }
  5969. }
  5970. return -1
  5971. }
  5972. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  5973. return this.indexOf(val, byteOffset, encoding) !== -1
  5974. }
  5975. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  5976. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  5977. }
  5978. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  5979. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  5980. }
  5981. function hexWrite (buf, string, offset, length) {
  5982. offset = Number(offset) || 0
  5983. var remaining = buf.length - offset
  5984. if (!length) {
  5985. length = remaining
  5986. } else {
  5987. length = Number(length)
  5988. if (length > remaining) {
  5989. length = remaining
  5990. }
  5991. }
  5992. // must be an even number of digits
  5993. var strLen = string.length
  5994. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  5995. if (length > strLen / 2) {
  5996. length = strLen / 2
  5997. }
  5998. for (var i = 0; i < length; ++i) {
  5999. var parsed = parseInt(string.substr(i * 2, 2), 16)
  6000. if (isNaN(parsed)) return i
  6001. buf[offset + i] = parsed
  6002. }
  6003. return i
  6004. }
  6005. function utf8Write (buf, string, offset, length) {
  6006. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  6007. }
  6008. function asciiWrite (buf, string, offset, length) {
  6009. return blitBuffer(asciiToBytes(string), buf, offset, length)
  6010. }
  6011. function latin1Write (buf, string, offset, length) {
  6012. return asciiWrite(buf, string, offset, length)
  6013. }
  6014. function base64Write (buf, string, offset, length) {
  6015. return blitBuffer(base64ToBytes(string), buf, offset, length)
  6016. }
  6017. function ucs2Write (buf, string, offset, length) {
  6018. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  6019. }
  6020. Buffer.prototype.write = function write (string, offset, length, encoding) {
  6021. // Buffer#write(string)
  6022. if (offset === undefined) {
  6023. encoding = 'utf8'
  6024. length = this.length
  6025. offset = 0
  6026. // Buffer#write(string, encoding)
  6027. } else if (length === undefined && typeof offset === 'string') {
  6028. encoding = offset
  6029. length = this.length
  6030. offset = 0
  6031. // Buffer#write(string, offset[, length][, encoding])
  6032. } else if (isFinite(offset)) {
  6033. offset = offset | 0
  6034. if (isFinite(length)) {
  6035. length = length | 0
  6036. if (encoding === undefined) encoding = 'utf8'
  6037. } else {
  6038. encoding = length
  6039. length = undefined
  6040. }
  6041. // legacy write(string, encoding, offset, length) - remove in v0.13
  6042. } else {
  6043. throw new Error(
  6044. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  6045. )
  6046. }
  6047. var remaining = this.length - offset
  6048. if (length === undefined || length > remaining) length = remaining
  6049. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  6050. throw new RangeError('Attempt to write outside buffer bounds')
  6051. }
  6052. if (!encoding) encoding = 'utf8'
  6053. var loweredCase = false
  6054. for (;;) {
  6055. switch (encoding) {
  6056. case 'hex':
  6057. return hexWrite(this, string, offset, length)
  6058. case 'utf8':
  6059. case 'utf-8':
  6060. return utf8Write(this, string, offset, length)
  6061. case 'ascii':
  6062. return asciiWrite(this, string, offset, length)
  6063. case 'latin1':
  6064. case 'binary':
  6065. return latin1Write(this, string, offset, length)
  6066. case 'base64':
  6067. // Warning: maxLength not taken into account in base64Write
  6068. return base64Write(this, string, offset, length)
  6069. case 'ucs2':
  6070. case 'ucs-2':
  6071. case 'utf16le':
  6072. case 'utf-16le':
  6073. return ucs2Write(this, string, offset, length)
  6074. default:
  6075. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6076. encoding = ('' + encoding).toLowerCase()
  6077. loweredCase = true
  6078. }
  6079. }
  6080. }
  6081. Buffer.prototype.toJSON = function toJSON () {
  6082. return {
  6083. type: 'Buffer',
  6084. data: Array.prototype.slice.call(this._arr || this, 0)
  6085. }
  6086. }
  6087. function base64Slice (buf, start, end) {
  6088. if (start === 0 && end === buf.length) {
  6089. return base64.fromByteArray(buf)
  6090. } else {
  6091. return base64.fromByteArray(buf.slice(start, end))
  6092. }
  6093. }
  6094. function utf8Slice (buf, start, end) {
  6095. end = Math.min(buf.length, end)
  6096. var res = []
  6097. var i = start
  6098. while (i < end) {
  6099. var firstByte = buf[i]
  6100. var codePoint = null
  6101. var bytesPerSequence = (firstByte > 0xEF) ? 4
  6102. : (firstByte > 0xDF) ? 3
  6103. : (firstByte > 0xBF) ? 2
  6104. : 1
  6105. if (i + bytesPerSequence <= end) {
  6106. var secondByte, thirdByte, fourthByte, tempCodePoint
  6107. switch (bytesPerSequence) {
  6108. case 1:
  6109. if (firstByte < 0x80) {
  6110. codePoint = firstByte
  6111. }
  6112. break
  6113. case 2:
  6114. secondByte = buf[i + 1]
  6115. if ((secondByte & 0xC0) === 0x80) {
  6116. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  6117. if (tempCodePoint > 0x7F) {
  6118. codePoint = tempCodePoint
  6119. }
  6120. }
  6121. break
  6122. case 3:
  6123. secondByte = buf[i + 1]
  6124. thirdByte = buf[i + 2]
  6125. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  6126. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  6127. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  6128. codePoint = tempCodePoint
  6129. }
  6130. }
  6131. break
  6132. case 4:
  6133. secondByte = buf[i + 1]
  6134. thirdByte = buf[i + 2]
  6135. fourthByte = buf[i + 3]
  6136. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  6137. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  6138. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  6139. codePoint = tempCodePoint
  6140. }
  6141. }
  6142. }
  6143. }
  6144. if (codePoint === null) {
  6145. // we did not generate a valid codePoint so insert a
  6146. // replacement char (U+FFFD) and advance only 1 byte
  6147. codePoint = 0xFFFD
  6148. bytesPerSequence = 1
  6149. } else if (codePoint > 0xFFFF) {
  6150. // encode to utf16 (surrogate pair dance)
  6151. codePoint -= 0x10000
  6152. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  6153. codePoint = 0xDC00 | codePoint & 0x3FF
  6154. }
  6155. res.push(codePoint)
  6156. i += bytesPerSequence
  6157. }
  6158. return decodeCodePointsArray(res)
  6159. }
  6160. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  6161. // the lowest limit is Chrome, with 0x10000 args.
  6162. // We go 1 magnitude less, for safety
  6163. var MAX_ARGUMENTS_LENGTH = 0x1000
  6164. function decodeCodePointsArray (codePoints) {
  6165. var len = codePoints.length
  6166. if (len <= MAX_ARGUMENTS_LENGTH) {
  6167. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  6168. }
  6169. // Decode in chunks to avoid "call stack size exceeded".
  6170. var res = ''
  6171. var i = 0
  6172. while (i < len) {
  6173. res += String.fromCharCode.apply(
  6174. String,
  6175. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  6176. )
  6177. }
  6178. return res
  6179. }
  6180. function asciiSlice (buf, start, end) {
  6181. var ret = ''
  6182. end = Math.min(buf.length, end)
  6183. for (var i = start; i < end; ++i) {
  6184. ret += String.fromCharCode(buf[i] & 0x7F)
  6185. }
  6186. return ret
  6187. }
  6188. function latin1Slice (buf, start, end) {
  6189. var ret = ''
  6190. end = Math.min(buf.length, end)
  6191. for (var i = start; i < end; ++i) {
  6192. ret += String.fromCharCode(buf[i])
  6193. }
  6194. return ret
  6195. }
  6196. function hexSlice (buf, start, end) {
  6197. var len = buf.length
  6198. if (!start || start < 0) start = 0
  6199. if (!end || end < 0 || end > len) end = len
  6200. var out = ''
  6201. for (var i = start; i < end; ++i) {
  6202. out += toHex(buf[i])
  6203. }
  6204. return out
  6205. }
  6206. function utf16leSlice (buf, start, end) {
  6207. var bytes = buf.slice(start, end)
  6208. var res = ''
  6209. for (var i = 0; i < bytes.length; i += 2) {
  6210. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  6211. }
  6212. return res
  6213. }
  6214. Buffer.prototype.slice = function slice (start, end) {
  6215. var len = this.length
  6216. start = ~~start
  6217. end = end === undefined ? len : ~~end
  6218. if (start < 0) {
  6219. start += len
  6220. if (start < 0) start = 0
  6221. } else if (start > len) {
  6222. start = len
  6223. }
  6224. if (end < 0) {
  6225. end += len
  6226. if (end < 0) end = 0
  6227. } else if (end > len) {
  6228. end = len
  6229. }
  6230. if (end < start) end = start
  6231. var newBuf
  6232. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6233. newBuf = this.subarray(start, end)
  6234. newBuf.__proto__ = Buffer.prototype
  6235. } else {
  6236. var sliceLen = end - start
  6237. newBuf = new Buffer(sliceLen, undefined)
  6238. for (var i = 0; i < sliceLen; ++i) {
  6239. newBuf[i] = this[i + start]
  6240. }
  6241. }
  6242. return newBuf
  6243. }
  6244. /*
  6245. * Need to make sure that buffer isn't trying to write out of bounds.
  6246. */
  6247. function checkOffset (offset, ext, length) {
  6248. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  6249. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  6250. }
  6251. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  6252. offset = offset | 0
  6253. byteLength = byteLength | 0
  6254. if (!noAssert) checkOffset(offset, byteLength, this.length)
  6255. var val = this[offset]
  6256. var mul = 1
  6257. var i = 0
  6258. while (++i < byteLength && (mul *= 0x100)) {
  6259. val += this[offset + i] * mul
  6260. }
  6261. return val
  6262. }
  6263. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  6264. offset = offset | 0
  6265. byteLength = byteLength | 0
  6266. if (!noAssert) {
  6267. checkOffset(offset, byteLength, this.length)
  6268. }
  6269. var val = this[offset + --byteLength]
  6270. var mul = 1
  6271. while (byteLength > 0 && (mul *= 0x100)) {
  6272. val += this[offset + --byteLength] * mul
  6273. }
  6274. return val
  6275. }
  6276. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  6277. if (!noAssert) checkOffset(offset, 1, this.length)
  6278. return this[offset]
  6279. }
  6280. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  6281. if (!noAssert) checkOffset(offset, 2, this.length)
  6282. return this[offset] | (this[offset + 1] << 8)
  6283. }
  6284. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  6285. if (!noAssert) checkOffset(offset, 2, this.length)
  6286. return (this[offset] << 8) | this[offset + 1]
  6287. }
  6288. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  6289. if (!noAssert) checkOffset(offset, 4, this.length)
  6290. return ((this[offset]) |
  6291. (this[offset + 1] << 8) |
  6292. (this[offset + 2] << 16)) +
  6293. (this[offset + 3] * 0x1000000)
  6294. }
  6295. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  6296. if (!noAssert) checkOffset(offset, 4, this.length)
  6297. return (this[offset] * 0x1000000) +
  6298. ((this[offset + 1] << 16) |
  6299. (this[offset + 2] << 8) |
  6300. this[offset + 3])
  6301. }
  6302. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  6303. offset = offset | 0
  6304. byteLength = byteLength | 0
  6305. if (!noAssert) checkOffset(offset, byteLength, this.length)
  6306. var val = this[offset]
  6307. var mul = 1
  6308. var i = 0
  6309. while (++i < byteLength && (mul *= 0x100)) {
  6310. val += this[offset + i] * mul
  6311. }
  6312. mul *= 0x80
  6313. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  6314. return val
  6315. }
  6316. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  6317. offset = offset | 0
  6318. byteLength = byteLength | 0
  6319. if (!noAssert) checkOffset(offset, byteLength, this.length)
  6320. var i = byteLength
  6321. var mul = 1
  6322. var val = this[offset + --i]
  6323. while (i > 0 && (mul *= 0x100)) {
  6324. val += this[offset + --i] * mul
  6325. }
  6326. mul *= 0x80
  6327. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  6328. return val
  6329. }
  6330. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  6331. if (!noAssert) checkOffset(offset, 1, this.length)
  6332. if (!(this[offset] & 0x80)) return (this[offset])
  6333. return ((0xff - this[offset] + 1) * -1)
  6334. }
  6335. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  6336. if (!noAssert) checkOffset(offset, 2, this.length)
  6337. var val = this[offset] | (this[offset + 1] << 8)
  6338. return (val & 0x8000) ? val | 0xFFFF0000 : val
  6339. }
  6340. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  6341. if (!noAssert) checkOffset(offset, 2, this.length)
  6342. var val = this[offset + 1] | (this[offset] << 8)
  6343. return (val & 0x8000) ? val | 0xFFFF0000 : val
  6344. }
  6345. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  6346. if (!noAssert) checkOffset(offset, 4, this.length)
  6347. return (this[offset]) |
  6348. (this[offset + 1] << 8) |
  6349. (this[offset + 2] << 16) |
  6350. (this[offset + 3] << 24)
  6351. }
  6352. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  6353. if (!noAssert) checkOffset(offset, 4, this.length)
  6354. return (this[offset] << 24) |
  6355. (this[offset + 1] << 16) |
  6356. (this[offset + 2] << 8) |
  6357. (this[offset + 3])
  6358. }
  6359. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  6360. if (!noAssert) checkOffset(offset, 4, this.length)
  6361. return ieee754.read(this, offset, true, 23, 4)
  6362. }
  6363. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  6364. if (!noAssert) checkOffset(offset, 4, this.length)
  6365. return ieee754.read(this, offset, false, 23, 4)
  6366. }
  6367. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  6368. if (!noAssert) checkOffset(offset, 8, this.length)
  6369. return ieee754.read(this, offset, true, 52, 8)
  6370. }
  6371. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  6372. if (!noAssert) checkOffset(offset, 8, this.length)
  6373. return ieee754.read(this, offset, false, 52, 8)
  6374. }
  6375. function checkInt (buf, value, offset, ext, max, min) {
  6376. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  6377. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  6378. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  6379. }
  6380. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  6381. value = +value
  6382. offset = offset | 0
  6383. byteLength = byteLength | 0
  6384. if (!noAssert) {
  6385. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  6386. checkInt(this, value, offset, byteLength, maxBytes, 0)
  6387. }
  6388. var mul = 1
  6389. var i = 0
  6390. this[offset] = value & 0xFF
  6391. while (++i < byteLength && (mul *= 0x100)) {
  6392. this[offset + i] = (value / mul) & 0xFF
  6393. }
  6394. return offset + byteLength
  6395. }
  6396. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  6397. value = +value
  6398. offset = offset | 0
  6399. byteLength = byteLength | 0
  6400. if (!noAssert) {
  6401. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  6402. checkInt(this, value, offset, byteLength, maxBytes, 0)
  6403. }
  6404. var i = byteLength - 1
  6405. var mul = 1
  6406. this[offset + i] = value & 0xFF
  6407. while (--i >= 0 && (mul *= 0x100)) {
  6408. this[offset + i] = (value / mul) & 0xFF
  6409. }
  6410. return offset + byteLength
  6411. }
  6412. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  6413. value = +value
  6414. offset = offset | 0
  6415. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  6416. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  6417. this[offset] = (value & 0xff)
  6418. return offset + 1
  6419. }
  6420. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  6421. if (value < 0) value = 0xffff + value + 1
  6422. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  6423. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  6424. (littleEndian ? i : 1 - i) * 8
  6425. }
  6426. }
  6427. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  6428. value = +value
  6429. offset = offset | 0
  6430. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  6431. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6432. this[offset] = (value & 0xff)
  6433. this[offset + 1] = (value >>> 8)
  6434. } else {
  6435. objectWriteUInt16(this, value, offset, true)
  6436. }
  6437. return offset + 2
  6438. }
  6439. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  6440. value = +value
  6441. offset = offset | 0
  6442. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  6443. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6444. this[offset] = (value >>> 8)
  6445. this[offset + 1] = (value & 0xff)
  6446. } else {
  6447. objectWriteUInt16(this, value, offset, false)
  6448. }
  6449. return offset + 2
  6450. }
  6451. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  6452. if (value < 0) value = 0xffffffff + value + 1
  6453. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  6454. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  6455. }
  6456. }
  6457. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  6458. value = +value
  6459. offset = offset | 0
  6460. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  6461. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6462. this[offset + 3] = (value >>> 24)
  6463. this[offset + 2] = (value >>> 16)
  6464. this[offset + 1] = (value >>> 8)
  6465. this[offset] = (value & 0xff)
  6466. } else {
  6467. objectWriteUInt32(this, value, offset, true)
  6468. }
  6469. return offset + 4
  6470. }
  6471. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  6472. value = +value
  6473. offset = offset | 0
  6474. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  6475. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6476. this[offset] = (value >>> 24)
  6477. this[offset + 1] = (value >>> 16)
  6478. this[offset + 2] = (value >>> 8)
  6479. this[offset + 3] = (value & 0xff)
  6480. } else {
  6481. objectWriteUInt32(this, value, offset, false)
  6482. }
  6483. return offset + 4
  6484. }
  6485. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  6486. value = +value
  6487. offset = offset | 0
  6488. if (!noAssert) {
  6489. var limit = Math.pow(2, 8 * byteLength - 1)
  6490. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  6491. }
  6492. var i = 0
  6493. var mul = 1
  6494. var sub = 0
  6495. this[offset] = value & 0xFF
  6496. while (++i < byteLength && (mul *= 0x100)) {
  6497. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  6498. sub = 1
  6499. }
  6500. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  6501. }
  6502. return offset + byteLength
  6503. }
  6504. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  6505. value = +value
  6506. offset = offset | 0
  6507. if (!noAssert) {
  6508. var limit = Math.pow(2, 8 * byteLength - 1)
  6509. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  6510. }
  6511. var i = byteLength - 1
  6512. var mul = 1
  6513. var sub = 0
  6514. this[offset + i] = value & 0xFF
  6515. while (--i >= 0 && (mul *= 0x100)) {
  6516. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  6517. sub = 1
  6518. }
  6519. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  6520. }
  6521. return offset + byteLength
  6522. }
  6523. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  6524. value = +value
  6525. offset = offset | 0
  6526. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  6527. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  6528. if (value < 0) value = 0xff + value + 1
  6529. this[offset] = (value & 0xff)
  6530. return offset + 1
  6531. }
  6532. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  6533. value = +value
  6534. offset = offset | 0
  6535. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  6536. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6537. this[offset] = (value & 0xff)
  6538. this[offset + 1] = (value >>> 8)
  6539. } else {
  6540. objectWriteUInt16(this, value, offset, true)
  6541. }
  6542. return offset + 2
  6543. }
  6544. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  6545. value = +value
  6546. offset = offset | 0
  6547. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  6548. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6549. this[offset] = (value >>> 8)
  6550. this[offset + 1] = (value & 0xff)
  6551. } else {
  6552. objectWriteUInt16(this, value, offset, false)
  6553. }
  6554. return offset + 2
  6555. }
  6556. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  6557. value = +value
  6558. offset = offset | 0
  6559. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  6560. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6561. this[offset] = (value & 0xff)
  6562. this[offset + 1] = (value >>> 8)
  6563. this[offset + 2] = (value >>> 16)
  6564. this[offset + 3] = (value >>> 24)
  6565. } else {
  6566. objectWriteUInt32(this, value, offset, true)
  6567. }
  6568. return offset + 4
  6569. }
  6570. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  6571. value = +value
  6572. offset = offset | 0
  6573. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  6574. if (value < 0) value = 0xffffffff + value + 1
  6575. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6576. this[offset] = (value >>> 24)
  6577. this[offset + 1] = (value >>> 16)
  6578. this[offset + 2] = (value >>> 8)
  6579. this[offset + 3] = (value & 0xff)
  6580. } else {
  6581. objectWriteUInt32(this, value, offset, false)
  6582. }
  6583. return offset + 4
  6584. }
  6585. function checkIEEE754 (buf, value, offset, ext, max, min) {
  6586. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  6587. if (offset < 0) throw new RangeError('Index out of range')
  6588. }
  6589. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  6590. if (!noAssert) {
  6591. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  6592. }
  6593. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  6594. return offset + 4
  6595. }
  6596. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  6597. return writeFloat(this, value, offset, true, noAssert)
  6598. }
  6599. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  6600. return writeFloat(this, value, offset, false, noAssert)
  6601. }
  6602. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  6603. if (!noAssert) {
  6604. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  6605. }
  6606. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  6607. return offset + 8
  6608. }
  6609. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  6610. return writeDouble(this, value, offset, true, noAssert)
  6611. }
  6612. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  6613. return writeDouble(this, value, offset, false, noAssert)
  6614. }
  6615. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  6616. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  6617. if (!start) start = 0
  6618. if (!end && end !== 0) end = this.length
  6619. if (targetStart >= target.length) targetStart = target.length
  6620. if (!targetStart) targetStart = 0
  6621. if (end > 0 && end < start) end = start
  6622. // Copy 0 bytes; we're done
  6623. if (end === start) return 0
  6624. if (target.length === 0 || this.length === 0) return 0
  6625. // Fatal error conditions
  6626. if (targetStart < 0) {
  6627. throw new RangeError('targetStart out of bounds')
  6628. }
  6629. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  6630. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  6631. // Are we oob?
  6632. if (end > this.length) end = this.length
  6633. if (target.length - targetStart < end - start) {
  6634. end = target.length - targetStart + start
  6635. }
  6636. var len = end - start
  6637. var i
  6638. if (this === target && start < targetStart && targetStart < end) {
  6639. // descending copy from end
  6640. for (i = len - 1; i >= 0; --i) {
  6641. target[i + targetStart] = this[i + start]
  6642. }
  6643. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  6644. // ascending copy from start
  6645. for (i = 0; i < len; ++i) {
  6646. target[i + targetStart] = this[i + start]
  6647. }
  6648. } else {
  6649. Uint8Array.prototype.set.call(
  6650. target,
  6651. this.subarray(start, start + len),
  6652. targetStart
  6653. )
  6654. }
  6655. return len
  6656. }
  6657. // Usage:
  6658. // buffer.fill(number[, offset[, end]])
  6659. // buffer.fill(buffer[, offset[, end]])
  6660. // buffer.fill(string[, offset[, end]][, encoding])
  6661. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  6662. // Handle string cases:
  6663. if (typeof val === 'string') {
  6664. if (typeof start === 'string') {
  6665. encoding = start
  6666. start = 0
  6667. end = this.length
  6668. } else if (typeof end === 'string') {
  6669. encoding = end
  6670. end = this.length
  6671. }
  6672. if (val.length === 1) {
  6673. var code = val.charCodeAt(0)
  6674. if (code < 256) {
  6675. val = code
  6676. }
  6677. }
  6678. if (encoding !== undefined && typeof encoding !== 'string') {
  6679. throw new TypeError('encoding must be a string')
  6680. }
  6681. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  6682. throw new TypeError('Unknown encoding: ' + encoding)
  6683. }
  6684. } else if (typeof val === 'number') {
  6685. val = val & 255
  6686. }
  6687. // Invalid ranges are not set to a default, so can range check early.
  6688. if (start < 0 || this.length < start || this.length < end) {
  6689. throw new RangeError('Out of range index')
  6690. }
  6691. if (end <= start) {
  6692. return this
  6693. }
  6694. start = start >>> 0
  6695. end = end === undefined ? this.length : end >>> 0
  6696. if (!val) val = 0
  6697. var i
  6698. if (typeof val === 'number') {
  6699. for (i = start; i < end; ++i) {
  6700. this[i] = val
  6701. }
  6702. } else {
  6703. var bytes = Buffer.isBuffer(val)
  6704. ? val
  6705. : utf8ToBytes(new Buffer(val, encoding).toString())
  6706. var len = bytes.length
  6707. for (i = 0; i < end - start; ++i) {
  6708. this[i + start] = bytes[i % len]
  6709. }
  6710. }
  6711. return this
  6712. }
  6713. // HELPER FUNCTIONS
  6714. // ================
  6715. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
  6716. function base64clean (str) {
  6717. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  6718. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  6719. // Node converts strings with length < 2 to ''
  6720. if (str.length < 2) return ''
  6721. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  6722. while (str.length % 4 !== 0) {
  6723. str = str + '='
  6724. }
  6725. return str
  6726. }
  6727. function stringtrim (str) {
  6728. if (str.trim) return str.trim()
  6729. return str.replace(/^\s+|\s+$/g, '')
  6730. }
  6731. function toHex (n) {
  6732. if (n < 16) return '0' + n.toString(16)
  6733. return n.toString(16)
  6734. }
  6735. function utf8ToBytes (string, units) {
  6736. units = units || Infinity
  6737. var codePoint
  6738. var length = string.length
  6739. var leadSurrogate = null
  6740. var bytes = []
  6741. for (var i = 0; i < length; ++i) {
  6742. codePoint = string.charCodeAt(i)
  6743. // is surrogate component
  6744. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  6745. // last char was a lead
  6746. if (!leadSurrogate) {
  6747. // no lead yet
  6748. if (codePoint > 0xDBFF) {
  6749. // unexpected trail
  6750. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  6751. continue
  6752. } else if (i + 1 === length) {
  6753. // unpaired lead
  6754. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  6755. continue
  6756. }
  6757. // valid lead
  6758. leadSurrogate = codePoint
  6759. continue
  6760. }
  6761. // 2 leads in a row
  6762. if (codePoint < 0xDC00) {
  6763. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  6764. leadSurrogate = codePoint
  6765. continue
  6766. }
  6767. // valid surrogate pair
  6768. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  6769. } else if (leadSurrogate) {
  6770. // valid bmp char, but last char was a lead
  6771. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  6772. }
  6773. leadSurrogate = null
  6774. // encode utf8
  6775. if (codePoint < 0x80) {
  6776. if ((units -= 1) < 0) break
  6777. bytes.push(codePoint)
  6778. } else if (codePoint < 0x800) {
  6779. if ((units -= 2) < 0) break
  6780. bytes.push(
  6781. codePoint >> 0x6 | 0xC0,
  6782. codePoint & 0x3F | 0x80
  6783. )
  6784. } else if (codePoint < 0x10000) {
  6785. if ((units -= 3) < 0) break
  6786. bytes.push(
  6787. codePoint >> 0xC | 0xE0,
  6788. codePoint >> 0x6 & 0x3F | 0x80,
  6789. codePoint & 0x3F | 0x80
  6790. )
  6791. } else if (codePoint < 0x110000) {
  6792. if ((units -= 4) < 0) break
  6793. bytes.push(
  6794. codePoint >> 0x12 | 0xF0,
  6795. codePoint >> 0xC & 0x3F | 0x80,
  6796. codePoint >> 0x6 & 0x3F | 0x80,
  6797. codePoint & 0x3F | 0x80
  6798. )
  6799. } else {
  6800. throw new Error('Invalid code point')
  6801. }
  6802. }
  6803. return bytes
  6804. }
  6805. function asciiToBytes (str) {
  6806. var byteArray = []
  6807. for (var i = 0; i < str.length; ++i) {
  6808. // Node's code seems to be doing this and not & 0x7F..
  6809. byteArray.push(str.charCodeAt(i) & 0xFF)
  6810. }
  6811. return byteArray
  6812. }
  6813. function utf16leToBytes (str, units) {
  6814. var c, hi, lo
  6815. var byteArray = []
  6816. for (var i = 0; i < str.length; ++i) {
  6817. if ((units -= 2) < 0) break
  6818. c = str.charCodeAt(i)
  6819. hi = c >> 8
  6820. lo = c % 256
  6821. byteArray.push(lo)
  6822. byteArray.push(hi)
  6823. }
  6824. return byteArray
  6825. }
  6826. function base64ToBytes (str) {
  6827. return base64.toByteArray(base64clean(str))
  6828. }
  6829. function blitBuffer (src, dst, offset, length) {
  6830. for (var i = 0; i < length; ++i) {
  6831. if ((i + offset >= dst.length) || (i >= src.length)) break
  6832. dst[i + offset] = src[i]
  6833. }
  6834. return i
  6835. }
  6836. function isnan (val) {
  6837. return val !== val // eslint-disable-line no-self-compare
  6838. }
  6839. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6840. },{"base64-js":2,"ieee754":14,"isarray":17}],7:[function(require,module,exports){
  6841. (function (Buffer){
  6842. var Transform = require('stream').Transform
  6843. var inherits = require('inherits')
  6844. var StringDecoder = require('string_decoder').StringDecoder
  6845. module.exports = CipherBase
  6846. inherits(CipherBase, Transform)
  6847. function CipherBase (hashMode) {
  6848. Transform.call(this)
  6849. this.hashMode = typeof hashMode === 'string'
  6850. if (this.hashMode) {
  6851. this[hashMode] = this._finalOrDigest
  6852. } else {
  6853. this.final = this._finalOrDigest
  6854. }
  6855. this._decoder = null
  6856. this._encoding = null
  6857. }
  6858. CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
  6859. if (typeof data === 'string') {
  6860. data = new Buffer(data, inputEnc)
  6861. }
  6862. var outData = this._update(data)
  6863. if (this.hashMode) {
  6864. return this
  6865. }
  6866. if (outputEnc) {
  6867. outData = this._toString(outData, outputEnc)
  6868. }
  6869. return outData
  6870. }
  6871. CipherBase.prototype.setAutoPadding = function () {}
  6872. CipherBase.prototype.getAuthTag = function () {
  6873. throw new Error('trying to get auth tag in unsupported state')
  6874. }
  6875. CipherBase.prototype.setAuthTag = function () {
  6876. throw new Error('trying to set auth tag in unsupported state')
  6877. }
  6878. CipherBase.prototype.setAAD = function () {
  6879. throw new Error('trying to set aad in unsupported state')
  6880. }
  6881. CipherBase.prototype._transform = function (data, _, next) {
  6882. var err
  6883. try {
  6884. if (this.hashMode) {
  6885. this._update(data)
  6886. } else {
  6887. this.push(this._update(data))
  6888. }
  6889. } catch (e) {
  6890. err = e
  6891. } finally {
  6892. next(err)
  6893. }
  6894. }
  6895. CipherBase.prototype._flush = function (done) {
  6896. var err
  6897. try {
  6898. this.push(this._final())
  6899. } catch (e) {
  6900. err = e
  6901. } finally {
  6902. done(err)
  6903. }
  6904. }
  6905. CipherBase.prototype._finalOrDigest = function (outputEnc) {
  6906. var outData = this._final() || new Buffer('')
  6907. if (outputEnc) {
  6908. outData = this._toString(outData, outputEnc, true)
  6909. }
  6910. return outData
  6911. }
  6912. CipherBase.prototype._toString = function (value, enc, fin) {
  6913. if (!this._decoder) {
  6914. this._decoder = new StringDecoder(enc)
  6915. this._encoding = enc
  6916. }
  6917. if (this._encoding !== enc) {
  6918. throw new Error('can\'t switch encodings')
  6919. }
  6920. var out = this._decoder.write(value)
  6921. if (fin) {
  6922. out += this._decoder.end()
  6923. }
  6924. return out
  6925. }
  6926. }).call(this,require("buffer").Buffer)
  6927. },{"buffer":6,"inherits":15,"stream":42,"string_decoder":43}],8:[function(require,module,exports){
  6928. (function (Buffer){
  6929. // Copyright Joyent, Inc. and other Node contributors.
  6930. //
  6931. // Permission is hereby granted, free of charge, to any person obtaining a
  6932. // copy of this software and associated documentation files (the
  6933. // "Software"), to deal in the Software without restriction, including
  6934. // without limitation the rights to use, copy, modify, merge, publish,
  6935. // distribute, sublicense, and/or sell copies of the Software, and to permit
  6936. // persons to whom the Software is furnished to do so, subject to the
  6937. // following conditions:
  6938. //
  6939. // The above copyright notice and this permission notice shall be included
  6940. // in all copies or substantial portions of the Software.
  6941. //
  6942. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  6943. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  6944. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  6945. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  6946. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  6947. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  6948. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  6949. // NOTE: These type checking functions intentionally don't use `instanceof`
  6950. // because it is fragile and can be easily faked with `Object.create()`.
  6951. function isArray(arg) {
  6952. if (Array.isArray) {
  6953. return Array.isArray(arg);
  6954. }
  6955. return objectToString(arg) === '[object Array]';
  6956. }
  6957. exports.isArray = isArray;
  6958. function isBoolean(arg) {
  6959. return typeof arg === 'boolean';
  6960. }
  6961. exports.isBoolean = isBoolean;
  6962. function isNull(arg) {
  6963. return arg === null;
  6964. }
  6965. exports.isNull = isNull;
  6966. function isNullOrUndefined(arg) {
  6967. return arg == null;
  6968. }
  6969. exports.isNullOrUndefined = isNullOrUndefined;
  6970. function isNumber(arg) {
  6971. return typeof arg === 'number';
  6972. }
  6973. exports.isNumber = isNumber;
  6974. function isString(arg) {
  6975. return typeof arg === 'string';
  6976. }
  6977. exports.isString = isString;
  6978. function isSymbol(arg) {
  6979. return typeof arg === 'symbol';
  6980. }
  6981. exports.isSymbol = isSymbol;
  6982. function isUndefined(arg) {
  6983. return arg === void 0;
  6984. }
  6985. exports.isUndefined = isUndefined;
  6986. function isRegExp(re) {
  6987. return objectToString(re) === '[object RegExp]';
  6988. }
  6989. exports.isRegExp = isRegExp;
  6990. function isObject(arg) {
  6991. return typeof arg === 'object' && arg !== null;
  6992. }
  6993. exports.isObject = isObject;
  6994. function isDate(d) {
  6995. return objectToString(d) === '[object Date]';
  6996. }
  6997. exports.isDate = isDate;
  6998. function isError(e) {
  6999. return (objectToString(e) === '[object Error]' || e instanceof Error);
  7000. }
  7001. exports.isError = isError;
  7002. function isFunction(arg) {
  7003. return typeof arg === 'function';
  7004. }
  7005. exports.isFunction = isFunction;
  7006. function isPrimitive(arg) {
  7007. return arg === null ||
  7008. typeof arg === 'boolean' ||
  7009. typeof arg === 'number' ||
  7010. typeof arg === 'string' ||
  7011. typeof arg === 'symbol' || // ES6 symbol
  7012. typeof arg === 'undefined';
  7013. }
  7014. exports.isPrimitive = isPrimitive;
  7015. exports.isBuffer = Buffer.isBuffer;
  7016. function objectToString(o) {
  7017. return Object.prototype.toString.call(o);
  7018. }
  7019. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  7020. },{"../../is-buffer/index.js":16}],9:[function(require,module,exports){
  7021. (function (Buffer){
  7022. 'use strict';
  7023. var inherits = require('inherits')
  7024. var md5 = require('./md5')
  7025. var rmd160 = require('ripemd160')
  7026. var sha = require('sha.js')
  7027. var Base = require('cipher-base')
  7028. function HashNoConstructor(hash) {
  7029. Base.call(this, 'digest')
  7030. this._hash = hash
  7031. this.buffers = []
  7032. }
  7033. inherits(HashNoConstructor, Base)
  7034. HashNoConstructor.prototype._update = function (data) {
  7035. this.buffers.push(data)
  7036. }
  7037. HashNoConstructor.prototype._final = function () {
  7038. var buf = Buffer.concat(this.buffers)
  7039. var r = this._hash(buf)
  7040. this.buffers = null
  7041. return r
  7042. }
  7043. function Hash(hash) {
  7044. Base.call(this, 'digest')
  7045. this._hash = hash
  7046. }
  7047. inherits(Hash, Base)
  7048. Hash.prototype._update = function (data) {
  7049. this._hash.update(data)
  7050. }
  7051. Hash.prototype._final = function () {
  7052. return this._hash.digest()
  7053. }
  7054. module.exports = function createHash (alg) {
  7055. alg = alg.toLowerCase()
  7056. if ('md5' === alg) return new HashNoConstructor(md5)
  7057. if ('rmd160' === alg || 'ripemd160' === alg) return new HashNoConstructor(rmd160)
  7058. return new Hash(sha(alg))
  7059. }
  7060. }).call(this,require("buffer").Buffer)
  7061. },{"./md5":11,"buffer":6,"cipher-base":7,"inherits":15,"ripemd160":33,"sha.js":35}],10:[function(require,module,exports){
  7062. (function (Buffer){
  7063. 'use strict';
  7064. var intSize = 4;
  7065. var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0);
  7066. var chrsz = 8;
  7067. function toArray(buf, bigEndian) {
  7068. if ((buf.length % intSize) !== 0) {
  7069. var len = buf.length + (intSize - (buf.length % intSize));
  7070. buf = Buffer.concat([buf, zeroBuffer], len);
  7071. }
  7072. var arr = [];
  7073. var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE;
  7074. for (var i = 0; i < buf.length; i += intSize) {
  7075. arr.push(fn.call(buf, i));
  7076. }
  7077. return arr;
  7078. }
  7079. function toBuffer(arr, size, bigEndian) {
  7080. var buf = new Buffer(size);
  7081. var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
  7082. for (var i = 0; i < arr.length; i++) {
  7083. fn.call(buf, arr[i], i * 4, true);
  7084. }
  7085. return buf;
  7086. }
  7087. function hash(buf, fn, hashSize, bigEndian) {
  7088. if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
  7089. var arr = fn(toArray(buf, bigEndian), buf.length * chrsz);
  7090. return toBuffer(arr, hashSize, bigEndian);
  7091. }
  7092. exports.hash = hash;
  7093. }).call(this,require("buffer").Buffer)
  7094. },{"buffer":6}],11:[function(require,module,exports){
  7095. 'use strict';
  7096. /*
  7097. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  7098. * Digest Algorithm, as defined in RFC 1321.
  7099. * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
  7100. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  7101. * Distributed under the BSD License
  7102. * See http://pajhome.org.uk/crypt/md5 for more info.
  7103. */
  7104. var helpers = require('./helpers');
  7105. /*
  7106. * Calculate the MD5 of an array of little-endian words, and a bit length
  7107. */
  7108. function core_md5(x, len)
  7109. {
  7110. /* append padding */
  7111. x[len >> 5] |= 0x80 << ((len) % 32);
  7112. x[(((len + 64) >>> 9) << 4) + 14] = len;
  7113. var a = 1732584193;
  7114. var b = -271733879;
  7115. var c = -1732584194;
  7116. var d = 271733878;
  7117. for(var i = 0; i < x.length; i += 16)
  7118. {
  7119. var olda = a;
  7120. var oldb = b;
  7121. var oldc = c;
  7122. var oldd = d;
  7123. a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
  7124. d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
  7125. c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
  7126. b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
  7127. a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
  7128. d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
  7129. c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
  7130. b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
  7131. a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
  7132. d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
  7133. c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
  7134. b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
  7135. a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
  7136. d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
  7137. c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
  7138. b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
  7139. a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
  7140. d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
  7141. c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
  7142. b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
  7143. a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
  7144. d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
  7145. c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
  7146. b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
  7147. a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
  7148. d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
  7149. c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
  7150. b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
  7151. a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
  7152. d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
  7153. c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
  7154. b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
  7155. a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
  7156. d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
  7157. c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
  7158. b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
  7159. a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
  7160. d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
  7161. c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
  7162. b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
  7163. a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
  7164. d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
  7165. c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
  7166. b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
  7167. a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
  7168. d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
  7169. c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
  7170. b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
  7171. a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
  7172. d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
  7173. c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
  7174. b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
  7175. a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
  7176. d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
  7177. c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
  7178. b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
  7179. a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
  7180. d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
  7181. c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
  7182. b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
  7183. a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
  7184. d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
  7185. c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
  7186. b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
  7187. a = safe_add(a, olda);
  7188. b = safe_add(b, oldb);
  7189. c = safe_add(c, oldc);
  7190. d = safe_add(d, oldd);
  7191. }
  7192. return Array(a, b, c, d);
  7193. }
  7194. /*
  7195. * These functions implement the four basic operations the algorithm uses.
  7196. */
  7197. function md5_cmn(q, a, b, x, s, t)
  7198. {
  7199. return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
  7200. }
  7201. function md5_ff(a, b, c, d, x, s, t)
  7202. {
  7203. return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
  7204. }
  7205. function md5_gg(a, b, c, d, x, s, t)
  7206. {
  7207. return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
  7208. }
  7209. function md5_hh(a, b, c, d, x, s, t)
  7210. {
  7211. return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  7212. }
  7213. function md5_ii(a, b, c, d, x, s, t)
  7214. {
  7215. return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
  7216. }
  7217. /*
  7218. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  7219. * to work around bugs in some JS interpreters.
  7220. */
  7221. function safe_add(x, y)
  7222. {
  7223. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  7224. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  7225. return (msw << 16) | (lsw & 0xFFFF);
  7226. }
  7227. /*
  7228. * Bitwise rotate a 32-bit number to the left.
  7229. */
  7230. function bit_rol(num, cnt)
  7231. {
  7232. return (num << cnt) | (num >>> (32 - cnt));
  7233. }
  7234. module.exports = function md5(buf) {
  7235. return helpers.hash(buf, core_md5, 16);
  7236. };
  7237. },{"./helpers":10}],12:[function(require,module,exports){
  7238. (function (Buffer){
  7239. 'use strict';
  7240. var createHash = require('create-hash/browser');
  7241. var inherits = require('inherits')
  7242. var Transform = require('stream').Transform
  7243. var ZEROS = new Buffer(128)
  7244. ZEROS.fill(0)
  7245. function Hmac(alg, key) {
  7246. Transform.call(this)
  7247. alg = alg.toLowerCase()
  7248. if (typeof key === 'string') {
  7249. key = new Buffer(key)
  7250. }
  7251. var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
  7252. this._alg = alg
  7253. this._key = key
  7254. if (key.length > blocksize) {
  7255. key = createHash(alg).update(key).digest()
  7256. } else if (key.length < blocksize) {
  7257. key = Buffer.concat([key, ZEROS], blocksize)
  7258. }
  7259. var ipad = this._ipad = new Buffer(blocksize)
  7260. var opad = this._opad = new Buffer(blocksize)
  7261. for (var i = 0; i < blocksize; i++) {
  7262. ipad[i] = key[i] ^ 0x36
  7263. opad[i] = key[i] ^ 0x5C
  7264. }
  7265. this._hash = createHash(alg).update(ipad)
  7266. }
  7267. inherits(Hmac, Transform)
  7268. Hmac.prototype.update = function (data, enc) {
  7269. this._hash.update(data, enc)
  7270. return this
  7271. }
  7272. Hmac.prototype._transform = function (data, _, next) {
  7273. this._hash.update(data)
  7274. next()
  7275. }
  7276. Hmac.prototype._flush = function (next) {
  7277. this.push(this.digest())
  7278. next()
  7279. }
  7280. Hmac.prototype.digest = function (enc) {
  7281. var h = this._hash.digest()
  7282. return createHash(this._alg).update(this._opad).update(h).digest(enc)
  7283. }
  7284. module.exports = function createHmac(alg, key) {
  7285. return new Hmac(alg, key)
  7286. }
  7287. }).call(this,require("buffer").Buffer)
  7288. },{"buffer":6,"create-hash/browser":9,"inherits":15,"stream":42}],13:[function(require,module,exports){
  7289. // Copyright Joyent, Inc. and other Node contributors.
  7290. //
  7291. // Permission is hereby granted, free of charge, to any person obtaining a
  7292. // copy of this software and associated documentation files (the
  7293. // "Software"), to deal in the Software without restriction, including
  7294. // without limitation the rights to use, copy, modify, merge, publish,
  7295. // distribute, sublicense, and/or sell copies of the Software, and to permit
  7296. // persons to whom the Software is furnished to do so, subject to the
  7297. // following conditions:
  7298. //
  7299. // The above copyright notice and this permission notice shall be included
  7300. // in all copies or substantial portions of the Software.
  7301. //
  7302. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7303. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7304. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  7305. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7306. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7307. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  7308. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  7309. function EventEmitter() {
  7310. this._events = this._events || {};
  7311. this._maxListeners = this._maxListeners || undefined;
  7312. }
  7313. module.exports = EventEmitter;
  7314. // Backwards-compat with node 0.10.x
  7315. EventEmitter.EventEmitter = EventEmitter;
  7316. EventEmitter.prototype._events = undefined;
  7317. EventEmitter.prototype._maxListeners = undefined;
  7318. // By default EventEmitters will print a warning if more than 10 listeners are
  7319. // added to it. This is a useful default which helps finding memory leaks.
  7320. EventEmitter.defaultMaxListeners = 10;
  7321. // Obviously not all Emitters should be limited to 10. This function allows
  7322. // that to be increased. Set to zero for unlimited.
  7323. EventEmitter.prototype.setMaxListeners = function(n) {
  7324. if (!isNumber(n) || n < 0 || isNaN(n))
  7325. throw TypeError('n must be a positive number');
  7326. this._maxListeners = n;
  7327. return this;
  7328. };
  7329. EventEmitter.prototype.emit = function(type) {
  7330. var er, handler, len, args, i, listeners;
  7331. if (!this._events)
  7332. this._events = {};
  7333. // If there is no 'error' event listener then throw.
  7334. if (type === 'error') {
  7335. if (!this._events.error ||
  7336. (isObject(this._events.error) && !this._events.error.length)) {
  7337. er = arguments[1];
  7338. if (er instanceof Error) {
  7339. throw er; // Unhandled 'error' event
  7340. } else {
  7341. // At least give some kind of context to the user
  7342. var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
  7343. err.context = er;
  7344. throw err;
  7345. }
  7346. }
  7347. }
  7348. handler = this._events[type];
  7349. if (isUndefined(handler))
  7350. return false;
  7351. if (isFunction(handler)) {
  7352. switch (arguments.length) {
  7353. // fast cases
  7354. case 1:
  7355. handler.call(this);
  7356. break;
  7357. case 2:
  7358. handler.call(this, arguments[1]);
  7359. break;
  7360. case 3:
  7361. handler.call(this, arguments[1], arguments[2]);
  7362. break;
  7363. // slower
  7364. default:
  7365. args = Array.prototype.slice.call(arguments, 1);
  7366. handler.apply(this, args);
  7367. }
  7368. } else if (isObject(handler)) {
  7369. args = Array.prototype.slice.call(arguments, 1);
  7370. listeners = handler.slice();
  7371. len = listeners.length;
  7372. for (i = 0; i < len; i++)
  7373. listeners[i].apply(this, args);
  7374. }
  7375. return true;
  7376. };
  7377. EventEmitter.prototype.addListener = function(type, listener) {
  7378. var m;
  7379. if (!isFunction(listener))
  7380. throw TypeError('listener must be a function');
  7381. if (!this._events)
  7382. this._events = {};
  7383. // To avoid recursion in the case that type === "newListener"! Before
  7384. // adding it to the listeners, first emit "newListener".
  7385. if (this._events.newListener)
  7386. this.emit('newListener', type,
  7387. isFunction(listener.listener) ?
  7388. listener.listener : listener);
  7389. if (!this._events[type])
  7390. // Optimize the case of one listener. Don't need the extra array object.
  7391. this._events[type] = listener;
  7392. else if (isObject(this._events[type]))
  7393. // If we've already got an array, just append.
  7394. this._events[type].push(listener);
  7395. else
  7396. // Adding the second element, need to change to array.
  7397. this._events[type] = [this._events[type], listener];
  7398. // Check for listener leak
  7399. if (isObject(this._events[type]) && !this._events[type].warned) {
  7400. if (!isUndefined(this._maxListeners)) {
  7401. m = this._maxListeners;
  7402. } else {
  7403. m = EventEmitter.defaultMaxListeners;
  7404. }
  7405. if (m && m > 0 && this._events[type].length > m) {
  7406. this._events[type].warned = true;
  7407. console.error('(node) warning: possible EventEmitter memory ' +
  7408. 'leak detected. %d listeners added. ' +
  7409. 'Use emitter.setMaxListeners() to increase limit.',
  7410. this._events[type].length);
  7411. if (typeof console.trace === 'function') {
  7412. // not supported in IE 10
  7413. console.trace();
  7414. }
  7415. }
  7416. }
  7417. return this;
  7418. };
  7419. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  7420. EventEmitter.prototype.once = function(type, listener) {
  7421. if (!isFunction(listener))
  7422. throw TypeError('listener must be a function');
  7423. var fired = false;
  7424. function g() {
  7425. this.removeListener(type, g);
  7426. if (!fired) {
  7427. fired = true;
  7428. listener.apply(this, arguments);
  7429. }
  7430. }
  7431. g.listener = listener;
  7432. this.on(type, g);
  7433. return this;
  7434. };
  7435. // emits a 'removeListener' event iff the listener was removed
  7436. EventEmitter.prototype.removeListener = function(type, listener) {
  7437. var list, position, length, i;
  7438. if (!isFunction(listener))
  7439. throw TypeError('listener must be a function');
  7440. if (!this._events || !this._events[type])
  7441. return this;
  7442. list = this._events[type];
  7443. length = list.length;
  7444. position = -1;
  7445. if (list === listener ||
  7446. (isFunction(list.listener) && list.listener === listener)) {
  7447. delete this._events[type];
  7448. if (this._events.removeListener)
  7449. this.emit('removeListener', type, listener);
  7450. } else if (isObject(list)) {
  7451. for (i = length; i-- > 0;) {
  7452. if (list[i] === listener ||
  7453. (list[i].listener && list[i].listener === listener)) {
  7454. position = i;
  7455. break;
  7456. }
  7457. }
  7458. if (position < 0)
  7459. return this;
  7460. if (list.length === 1) {
  7461. list.length = 0;
  7462. delete this._events[type];
  7463. } else {
  7464. list.splice(position, 1);
  7465. }
  7466. if (this._events.removeListener)
  7467. this.emit('removeListener', type, listener);
  7468. }
  7469. return this;
  7470. };
  7471. EventEmitter.prototype.removeAllListeners = function(type) {
  7472. var key, listeners;
  7473. if (!this._events)
  7474. return this;
  7475. // not listening for removeListener, no need to emit
  7476. if (!this._events.removeListener) {
  7477. if (arguments.length === 0)
  7478. this._events = {};
  7479. else if (this._events[type])
  7480. delete this._events[type];
  7481. return this;
  7482. }
  7483. // emit removeListener for all listeners on all events
  7484. if (arguments.length === 0) {
  7485. for (key in this._events) {
  7486. if (key === 'removeListener') continue;
  7487. this.removeAllListeners(key);
  7488. }
  7489. this.removeAllListeners('removeListener');
  7490. this._events = {};
  7491. return this;
  7492. }
  7493. listeners = this._events[type];
  7494. if (isFunction(listeners)) {
  7495. this.removeListener(type, listeners);
  7496. } else if (listeners) {
  7497. // LIFO order
  7498. while (listeners.length)
  7499. this.removeListener(type, listeners[listeners.length - 1]);
  7500. }
  7501. delete this._events[type];
  7502. return this;
  7503. };
  7504. EventEmitter.prototype.listeners = function(type) {
  7505. var ret;
  7506. if (!this._events || !this._events[type])
  7507. ret = [];
  7508. else if (isFunction(this._events[type]))
  7509. ret = [this._events[type]];
  7510. else
  7511. ret = this._events[type].slice();
  7512. return ret;
  7513. };
  7514. EventEmitter.prototype.listenerCount = function(type) {
  7515. if (this._events) {
  7516. var evlistener = this._events[type];
  7517. if (isFunction(evlistener))
  7518. return 1;
  7519. else if (evlistener)
  7520. return evlistener.length;
  7521. }
  7522. return 0;
  7523. };
  7524. EventEmitter.listenerCount = function(emitter, type) {
  7525. return emitter.listenerCount(type);
  7526. };
  7527. function isFunction(arg) {
  7528. return typeof arg === 'function';
  7529. }
  7530. function isNumber(arg) {
  7531. return typeof arg === 'number';
  7532. }
  7533. function isObject(arg) {
  7534. return typeof arg === 'object' && arg !== null;
  7535. }
  7536. function isUndefined(arg) {
  7537. return arg === void 0;
  7538. }
  7539. },{}],14:[function(require,module,exports){
  7540. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  7541. var e, m
  7542. var eLen = nBytes * 8 - mLen - 1
  7543. var eMax = (1 << eLen) - 1
  7544. var eBias = eMax >> 1
  7545. var nBits = -7
  7546. var i = isLE ? (nBytes - 1) : 0
  7547. var d = isLE ? -1 : 1
  7548. var s = buffer[offset + i]
  7549. i += d
  7550. e = s & ((1 << (-nBits)) - 1)
  7551. s >>= (-nBits)
  7552. nBits += eLen
  7553. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  7554. m = e & ((1 << (-nBits)) - 1)
  7555. e >>= (-nBits)
  7556. nBits += mLen
  7557. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  7558. if (e === 0) {
  7559. e = 1 - eBias
  7560. } else if (e === eMax) {
  7561. return m ? NaN : ((s ? -1 : 1) * Infinity)
  7562. } else {
  7563. m = m + Math.pow(2, mLen)
  7564. e = e - eBias
  7565. }
  7566. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  7567. }
  7568. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  7569. var e, m, c
  7570. var eLen = nBytes * 8 - mLen - 1
  7571. var eMax = (1 << eLen) - 1
  7572. var eBias = eMax >> 1
  7573. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  7574. var i = isLE ? 0 : (nBytes - 1)
  7575. var d = isLE ? 1 : -1
  7576. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  7577. value = Math.abs(value)
  7578. if (isNaN(value) || value === Infinity) {
  7579. m = isNaN(value) ? 1 : 0
  7580. e = eMax
  7581. } else {
  7582. e = Math.floor(Math.log(value) / Math.LN2)
  7583. if (value * (c = Math.pow(2, -e)) < 1) {
  7584. e--
  7585. c *= 2
  7586. }
  7587. if (e + eBias >= 1) {
  7588. value += rt / c
  7589. } else {
  7590. value += rt * Math.pow(2, 1 - eBias)
  7591. }
  7592. if (value * c >= 2) {
  7593. e++
  7594. c /= 2
  7595. }
  7596. if (e + eBias >= eMax) {
  7597. m = 0
  7598. e = eMax
  7599. } else if (e + eBias >= 1) {
  7600. m = (value * c - 1) * Math.pow(2, mLen)
  7601. e = e + eBias
  7602. } else {
  7603. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  7604. e = 0
  7605. }
  7606. }
  7607. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  7608. e = (e << mLen) | m
  7609. eLen += mLen
  7610. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  7611. buffer[offset + i - d] |= s * 128
  7612. }
  7613. },{}],15:[function(require,module,exports){
  7614. if (typeof Object.create === 'function') {
  7615. // implementation from standard node.js 'util' module
  7616. module.exports = function inherits(ctor, superCtor) {
  7617. ctor.super_ = superCtor
  7618. ctor.prototype = Object.create(superCtor.prototype, {
  7619. constructor: {
  7620. value: ctor,
  7621. enumerable: false,
  7622. writable: true,
  7623. configurable: true
  7624. }
  7625. });
  7626. };
  7627. } else {
  7628. // old school shim for old browsers
  7629. module.exports = function inherits(ctor, superCtor) {
  7630. ctor.super_ = superCtor
  7631. var TempCtor = function () {}
  7632. TempCtor.prototype = superCtor.prototype
  7633. ctor.prototype = new TempCtor()
  7634. ctor.prototype.constructor = ctor
  7635. }
  7636. }
  7637. },{}],16:[function(require,module,exports){
  7638. /*!
  7639. * Determine if an object is a Buffer
  7640. *
  7641. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  7642. * @license MIT
  7643. */
  7644. // The _isBuffer check is for Safari 5-7 support, because it's missing
  7645. // Object.prototype.constructor. Remove this eventually
  7646. module.exports = function (obj) {
  7647. return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
  7648. }
  7649. function isBuffer (obj) {
  7650. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  7651. }
  7652. // For Node v0.10 support. Remove this eventually.
  7653. function isSlowBuffer (obj) {
  7654. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
  7655. }
  7656. },{}],17:[function(require,module,exports){
  7657. var toString = {}.toString;
  7658. module.exports = Array.isArray || function (arr) {
  7659. return toString.call(arr) == '[object Array]';
  7660. };
  7661. },{}],18:[function(require,module,exports){
  7662. (function (process,Buffer){
  7663. var createHmac = require('create-hmac')
  7664. var checkParameters = require('./precondition')
  7665. exports.pbkdf2 = function (password, salt, iterations, keylen, digest, callback) {
  7666. if (typeof digest === 'function') {
  7667. callback = digest
  7668. digest = undefined
  7669. }
  7670. checkParameters(iterations, keylen)
  7671. if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2')
  7672. setTimeout(function () {
  7673. callback(null, exports.pbkdf2Sync(password, salt, iterations, keylen, digest))
  7674. })
  7675. }
  7676. var defaultEncoding
  7677. if (process.browser) {
  7678. defaultEncoding = 'utf-8'
  7679. } else {
  7680. var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10)
  7681. defaultEncoding = pVersionMajor >= 6 ? 'utf-8' : 'binary'
  7682. }
  7683. exports.pbkdf2Sync = function (password, salt, iterations, keylen, digest) {
  7684. if (!Buffer.isBuffer(password)) password = new Buffer(password, defaultEncoding)
  7685. if (!Buffer.isBuffer(salt)) salt = new Buffer(salt, defaultEncoding)
  7686. checkParameters(iterations, keylen)
  7687. digest = digest || 'sha1'
  7688. var hLen
  7689. var l = 1
  7690. var DK = new Buffer(keylen)
  7691. var block1 = new Buffer(salt.length + 4)
  7692. salt.copy(block1, 0, 0, salt.length)
  7693. var r
  7694. var T
  7695. for (var i = 1; i <= l; i++) {
  7696. block1.writeUInt32BE(i, salt.length)
  7697. var U = createHmac(digest, password).update(block1).digest()
  7698. if (!hLen) {
  7699. hLen = U.length
  7700. T = new Buffer(hLen)
  7701. l = Math.ceil(keylen / hLen)
  7702. r = keylen - (l - 1) * hLen
  7703. }
  7704. U.copy(T, 0, 0, hLen)
  7705. for (var j = 1; j < iterations; j++) {
  7706. U = createHmac(digest, password).update(U).digest()
  7707. for (var k = 0; k < hLen; k++) T[k] ^= U[k]
  7708. }
  7709. var destPos = (i - 1) * hLen
  7710. var len = (i === l ? r : hLen)
  7711. T.copy(DK, destPos, 0, len)
  7712. }
  7713. return DK
  7714. }
  7715. }).call(this,require('_process'),require("buffer").Buffer)
  7716. },{"./precondition":19,"_process":21,"buffer":6,"create-hmac":12}],19:[function(require,module,exports){
  7717. var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
  7718. module.exports = function (iterations, keylen) {
  7719. if (typeof iterations !== 'number') {
  7720. throw new TypeError('Iterations not a number')
  7721. }
  7722. if (iterations < 0) {
  7723. throw new TypeError('Bad iterations')
  7724. }
  7725. if (typeof keylen !== 'number') {
  7726. throw new TypeError('Key length not a number')
  7727. }
  7728. if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { /* eslint no-self-compare: 0 */
  7729. throw new TypeError('Bad key length')
  7730. }
  7731. }
  7732. },{}],20:[function(require,module,exports){
  7733. (function (process){
  7734. 'use strict';
  7735. if (!process.version ||
  7736. process.version.indexOf('v0.') === 0 ||
  7737. process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  7738. module.exports = nextTick;
  7739. } else {
  7740. module.exports = process.nextTick;
  7741. }
  7742. function nextTick(fn, arg1, arg2, arg3) {
  7743. if (typeof fn !== 'function') {
  7744. throw new TypeError('"callback" argument must be a function');
  7745. }
  7746. var len = arguments.length;
  7747. var args, i;
  7748. switch (len) {
  7749. case 0:
  7750. case 1:
  7751. return process.nextTick(fn);
  7752. case 2:
  7753. return process.nextTick(function afterTickOne() {
  7754. fn.call(null, arg1);
  7755. });
  7756. case 3:
  7757. return process.nextTick(function afterTickTwo() {
  7758. fn.call(null, arg1, arg2);
  7759. });
  7760. case 4:
  7761. return process.nextTick(function afterTickThree() {
  7762. fn.call(null, arg1, arg2, arg3);
  7763. });
  7764. default:
  7765. args = new Array(len - 1);
  7766. i = 0;
  7767. while (i < args.length) {
  7768. args[i++] = arguments[i];
  7769. }
  7770. return process.nextTick(function afterTick() {
  7771. fn.apply(null, args);
  7772. });
  7773. }
  7774. }
  7775. }).call(this,require('_process'))
  7776. },{"_process":21}],21:[function(require,module,exports){
  7777. // shim for using process in browser
  7778. var process = module.exports = {};
  7779. // cached from whatever global is present so that test runners that stub it
  7780. // don't break things. But we need to wrap it in a try catch in case it is
  7781. // wrapped in strict mode code which doesn't define any globals. It's inside a
  7782. // function because try/catches deoptimize in certain engines.
  7783. var cachedSetTimeout;
  7784. var cachedClearTimeout;
  7785. function defaultSetTimout() {
  7786. throw new Error('setTimeout has not been defined');
  7787. }
  7788. function defaultClearTimeout () {
  7789. throw new Error('clearTimeout has not been defined');
  7790. }
  7791. (function () {
  7792. try {
  7793. if (typeof setTimeout === 'function') {
  7794. cachedSetTimeout = setTimeout;
  7795. } else {
  7796. cachedSetTimeout = defaultSetTimout;
  7797. }
  7798. } catch (e) {
  7799. cachedSetTimeout = defaultSetTimout;
  7800. }
  7801. try {
  7802. if (typeof clearTimeout === 'function') {
  7803. cachedClearTimeout = clearTimeout;
  7804. } else {
  7805. cachedClearTimeout = defaultClearTimeout;
  7806. }
  7807. } catch (e) {
  7808. cachedClearTimeout = defaultClearTimeout;
  7809. }
  7810. } ())
  7811. function runTimeout(fun) {
  7812. if (cachedSetTimeout === setTimeout) {
  7813. //normal enviroments in sane situations
  7814. return setTimeout(fun, 0);
  7815. }
  7816. // if setTimeout wasn't available but was latter defined
  7817. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  7818. cachedSetTimeout = setTimeout;
  7819. return setTimeout(fun, 0);
  7820. }
  7821. try {
  7822. // when when somebody has screwed with setTimeout but no I.E. maddness
  7823. return cachedSetTimeout(fun, 0);
  7824. } catch(e){
  7825. try {
  7826. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  7827. return cachedSetTimeout.call(null, fun, 0);
  7828. } catch(e){
  7829. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  7830. return cachedSetTimeout.call(this, fun, 0);
  7831. }
  7832. }
  7833. }
  7834. function runClearTimeout(marker) {
  7835. if (cachedClearTimeout === clearTimeout) {
  7836. //normal enviroments in sane situations
  7837. return clearTimeout(marker);
  7838. }
  7839. // if clearTimeout wasn't available but was latter defined
  7840. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  7841. cachedClearTimeout = clearTimeout;
  7842. return clearTimeout(marker);
  7843. }
  7844. try {
  7845. // when when somebody has screwed with setTimeout but no I.E. maddness
  7846. return cachedClearTimeout(marker);
  7847. } catch (e){
  7848. try {
  7849. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  7850. return cachedClearTimeout.call(null, marker);
  7851. } catch (e){
  7852. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  7853. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  7854. return cachedClearTimeout.call(this, marker);
  7855. }
  7856. }
  7857. }
  7858. var queue = [];
  7859. var draining = false;
  7860. var currentQueue;
  7861. var queueIndex = -1;
  7862. function cleanUpNextTick() {
  7863. if (!draining || !currentQueue) {
  7864. return;
  7865. }
  7866. draining = false;
  7867. if (currentQueue.length) {
  7868. queue = currentQueue.concat(queue);
  7869. } else {
  7870. queueIndex = -1;
  7871. }
  7872. if (queue.length) {
  7873. drainQueue();
  7874. }
  7875. }
  7876. function drainQueue() {
  7877. if (draining) {
  7878. return;
  7879. }
  7880. var timeout = runTimeout(cleanUpNextTick);
  7881. draining = true;
  7882. var len = queue.length;
  7883. while(len) {
  7884. currentQueue = queue;
  7885. queue = [];
  7886. while (++queueIndex < len) {
  7887. if (currentQueue) {
  7888. currentQueue[queueIndex].run();
  7889. }
  7890. }
  7891. queueIndex = -1;
  7892. len = queue.length;
  7893. }
  7894. currentQueue = null;
  7895. draining = false;
  7896. runClearTimeout(timeout);
  7897. }
  7898. process.nextTick = function (fun) {
  7899. var args = new Array(arguments.length - 1);
  7900. if (arguments.length > 1) {
  7901. for (var i = 1; i < arguments.length; i++) {
  7902. args[i - 1] = arguments[i];
  7903. }
  7904. }
  7905. queue.push(new Item(fun, args));
  7906. if (queue.length === 1 && !draining) {
  7907. runTimeout(drainQueue);
  7908. }
  7909. };
  7910. // v8 likes predictible objects
  7911. function Item(fun, array) {
  7912. this.fun = fun;
  7913. this.array = array;
  7914. }
  7915. Item.prototype.run = function () {
  7916. this.fun.apply(null, this.array);
  7917. };
  7918. process.title = 'browser';
  7919. process.browser = true;
  7920. process.env = {};
  7921. process.argv = [];
  7922. process.version = ''; // empty string to avoid regexp issues
  7923. process.versions = {};
  7924. function noop() {}
  7925. process.on = noop;
  7926. process.addListener = noop;
  7927. process.once = noop;
  7928. process.off = noop;
  7929. process.removeListener = noop;
  7930. process.removeAllListeners = noop;
  7931. process.emit = noop;
  7932. process.binding = function (name) {
  7933. throw new Error('process.binding is not supported');
  7934. };
  7935. process.cwd = function () { return '/' };
  7936. process.chdir = function (dir) {
  7937. throw new Error('process.chdir is not supported');
  7938. };
  7939. process.umask = function() { return 0; };
  7940. },{}],22:[function(require,module,exports){
  7941. module.exports = require("./lib/_stream_duplex.js")
  7942. },{"./lib/_stream_duplex.js":23}],23:[function(require,module,exports){
  7943. // a duplex stream is just a stream that is both readable and writable.
  7944. // Since JS doesn't have multiple prototypal inheritance, this class
  7945. // prototypally inherits from Readable, and then parasitically from
  7946. // Writable.
  7947. 'use strict';
  7948. /*<replacement>*/
  7949. var objectKeys = Object.keys || function (obj) {
  7950. var keys = [];
  7951. for (var key in obj) {
  7952. keys.push(key);
  7953. }return keys;
  7954. };
  7955. /*</replacement>*/
  7956. module.exports = Duplex;
  7957. /*<replacement>*/
  7958. var processNextTick = require('process-nextick-args');
  7959. /*</replacement>*/
  7960. /*<replacement>*/
  7961. var util = require('core-util-is');
  7962. util.inherits = require('inherits');
  7963. /*</replacement>*/
  7964. var Readable = require('./_stream_readable');
  7965. var Writable = require('./_stream_writable');
  7966. util.inherits(Duplex, Readable);
  7967. var keys = objectKeys(Writable.prototype);
  7968. for (var v = 0; v < keys.length; v++) {
  7969. var method = keys[v];
  7970. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  7971. }
  7972. function Duplex(options) {
  7973. if (!(this instanceof Duplex)) return new Duplex(options);
  7974. Readable.call(this, options);
  7975. Writable.call(this, options);
  7976. if (options && options.readable === false) this.readable = false;
  7977. if (options && options.writable === false) this.writable = false;
  7978. this.allowHalfOpen = true;
  7979. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  7980. this.once('end', onend);
  7981. }
  7982. // the no-half-open enforcer
  7983. function onend() {
  7984. // if we allow half-open state, or if the writable side ended,
  7985. // then we're ok.
  7986. if (this.allowHalfOpen || this._writableState.ended) return;
  7987. // no more data can be written.
  7988. // But allow more writes to happen in this tick.
  7989. processNextTick(onEndNT, this);
  7990. }
  7991. function onEndNT(self) {
  7992. self.end();
  7993. }
  7994. function forEach(xs, f) {
  7995. for (var i = 0, l = xs.length; i < l; i++) {
  7996. f(xs[i], i);
  7997. }
  7998. }
  7999. },{"./_stream_readable":25,"./_stream_writable":27,"core-util-is":8,"inherits":15,"process-nextick-args":20}],24:[function(require,module,exports){
  8000. // a passthrough stream.
  8001. // basically just the most minimal sort of Transform stream.
  8002. // Every written chunk gets output as-is.
  8003. 'use strict';
  8004. module.exports = PassThrough;
  8005. var Transform = require('./_stream_transform');
  8006. /*<replacement>*/
  8007. var util = require('core-util-is');
  8008. util.inherits = require('inherits');
  8009. /*</replacement>*/
  8010. util.inherits(PassThrough, Transform);
  8011. function PassThrough(options) {
  8012. if (!(this instanceof PassThrough)) return new PassThrough(options);
  8013. Transform.call(this, options);
  8014. }
  8015. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  8016. cb(null, chunk);
  8017. };
  8018. },{"./_stream_transform":26,"core-util-is":8,"inherits":15}],25:[function(require,module,exports){
  8019. (function (process){
  8020. 'use strict';
  8021. module.exports = Readable;
  8022. /*<replacement>*/
  8023. var processNextTick = require('process-nextick-args');
  8024. /*</replacement>*/
  8025. /*<replacement>*/
  8026. var isArray = require('isarray');
  8027. /*</replacement>*/
  8028. Readable.ReadableState = ReadableState;
  8029. /*<replacement>*/
  8030. var EE = require('events').EventEmitter;
  8031. var EElistenerCount = function (emitter, type) {
  8032. return emitter.listeners(type).length;
  8033. };
  8034. /*</replacement>*/
  8035. /*<replacement>*/
  8036. var Stream;
  8037. (function () {
  8038. try {
  8039. Stream = require('st' + 'ream');
  8040. } catch (_) {} finally {
  8041. if (!Stream) Stream = require('events').EventEmitter;
  8042. }
  8043. })();
  8044. /*</replacement>*/
  8045. var Buffer = require('buffer').Buffer;
  8046. /*<replacement>*/
  8047. var bufferShim = require('buffer-shims');
  8048. /*</replacement>*/
  8049. /*<replacement>*/
  8050. var util = require('core-util-is');
  8051. util.inherits = require('inherits');
  8052. /*</replacement>*/
  8053. /*<replacement>*/
  8054. var debugUtil = require('util');
  8055. var debug = void 0;
  8056. if (debugUtil && debugUtil.debuglog) {
  8057. debug = debugUtil.debuglog('stream');
  8058. } else {
  8059. debug = function () {};
  8060. }
  8061. /*</replacement>*/
  8062. var BufferList = require('./internal/streams/BufferList');
  8063. var StringDecoder;
  8064. util.inherits(Readable, Stream);
  8065. function prependListener(emitter, event, fn) {
  8066. if (typeof emitter.prependListener === 'function') {
  8067. return emitter.prependListener(event, fn);
  8068. } else {
  8069. // This is a hack to make sure that our error handler is attached before any
  8070. // userland ones. NEVER DO THIS. This is here only because this code needs
  8071. // to continue to work with older versions of Node.js that do not include
  8072. // the prependListener() method. The goal is to eventually remove this hack.
  8073. if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
  8074. }
  8075. }
  8076. var Duplex;
  8077. function ReadableState(options, stream) {
  8078. Duplex = Duplex || require('./_stream_duplex');
  8079. options = options || {};
  8080. // object stream flag. Used to make read(n) ignore n and to
  8081. // make all the buffer merging and length checks go away
  8082. this.objectMode = !!options.objectMode;
  8083. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  8084. // the point at which it stops calling _read() to fill the buffer
  8085. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  8086. var hwm = options.highWaterMark;
  8087. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  8088. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  8089. // cast to ints.
  8090. this.highWaterMark = ~ ~this.highWaterMark;
  8091. // A linked list is used to store data chunks instead of an array because the
  8092. // linked list can remove elements from the beginning faster than
  8093. // array.shift()
  8094. this.buffer = new BufferList();
  8095. this.length = 0;
  8096. this.pipes = null;
  8097. this.pipesCount = 0;
  8098. this.flowing = null;
  8099. this.ended = false;
  8100. this.endEmitted = false;
  8101. this.reading = false;
  8102. // a flag to be able to tell if the onwrite cb is called immediately,
  8103. // or on a later tick. We set this to true at first, because any
  8104. // actions that shouldn't happen until "later" should generally also
  8105. // not happen before the first write call.
  8106. this.sync = true;
  8107. // whenever we return null, then we set a flag to say
  8108. // that we're awaiting a 'readable' event emission.
  8109. this.needReadable = false;
  8110. this.emittedReadable = false;
  8111. this.readableListening = false;
  8112. this.resumeScheduled = false;
  8113. // Crypto is kind of old and crusty. Historically, its default string
  8114. // encoding is 'binary' so we have to make this configurable.
  8115. // Everything else in the universe uses 'utf8', though.
  8116. this.defaultEncoding = options.defaultEncoding || 'utf8';
  8117. // when piping, we only care about 'readable' events that happen
  8118. // after read()ing all the bytes and not getting any pushback.
  8119. this.ranOut = false;
  8120. // the number of writers that are awaiting a drain event in .pipe()s
  8121. this.awaitDrain = 0;
  8122. // if true, a maybeReadMore has been scheduled
  8123. this.readingMore = false;
  8124. this.decoder = null;
  8125. this.encoding = null;
  8126. if (options.encoding) {
  8127. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  8128. this.decoder = new StringDecoder(options.encoding);
  8129. this.encoding = options.encoding;
  8130. }
  8131. }
  8132. var Duplex;
  8133. function Readable(options) {
  8134. Duplex = Duplex || require('./_stream_duplex');
  8135. if (!(this instanceof Readable)) return new Readable(options);
  8136. this._readableState = new ReadableState(options, this);
  8137. // legacy
  8138. this.readable = true;
  8139. if (options && typeof options.read === 'function') this._read = options.read;
  8140. Stream.call(this);
  8141. }
  8142. // Manually shove something into the read() buffer.
  8143. // This returns true if the highWaterMark has not been hit yet,
  8144. // similar to how Writable.write() returns true if you should
  8145. // write() some more.
  8146. Readable.prototype.push = function (chunk, encoding) {
  8147. var state = this._readableState;
  8148. if (!state.objectMode && typeof chunk === 'string') {
  8149. encoding = encoding || state.defaultEncoding;
  8150. if (encoding !== state.encoding) {
  8151. chunk = bufferShim.from(chunk, encoding);
  8152. encoding = '';
  8153. }
  8154. }
  8155. return readableAddChunk(this, state, chunk, encoding, false);
  8156. };
  8157. // Unshift should *always* be something directly out of read()
  8158. Readable.prototype.unshift = function (chunk) {
  8159. var state = this._readableState;
  8160. return readableAddChunk(this, state, chunk, '', true);
  8161. };
  8162. Readable.prototype.isPaused = function () {
  8163. return this._readableState.flowing === false;
  8164. };
  8165. function readableAddChunk(stream, state, chunk, encoding, addToFront) {
  8166. var er = chunkInvalid(state, chunk);
  8167. if (er) {
  8168. stream.emit('error', er);
  8169. } else if (chunk === null) {
  8170. state.reading = false;
  8171. onEofChunk(stream, state);
  8172. } else if (state.objectMode || chunk && chunk.length > 0) {
  8173. if (state.ended && !addToFront) {
  8174. var e = new Error('stream.push() after EOF');
  8175. stream.emit('error', e);
  8176. } else if (state.endEmitted && addToFront) {
  8177. var _e = new Error('stream.unshift() after end event');
  8178. stream.emit('error', _e);
  8179. } else {
  8180. var skipAdd;
  8181. if (state.decoder && !addToFront && !encoding) {
  8182. chunk = state.decoder.write(chunk);
  8183. skipAdd = !state.objectMode && chunk.length === 0;
  8184. }
  8185. if (!addToFront) state.reading = false;
  8186. // Don't add to the buffer if we've decoded to an empty string chunk and
  8187. // we're not in object mode
  8188. if (!skipAdd) {
  8189. // if we want the data now, just emit it.
  8190. if (state.flowing && state.length === 0 && !state.sync) {
  8191. stream.emit('data', chunk);
  8192. stream.read(0);
  8193. } else {
  8194. // update the buffer info.
  8195. state.length += state.objectMode ? 1 : chunk.length;
  8196. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  8197. if (state.needReadable) emitReadable(stream);
  8198. }
  8199. }
  8200. maybeReadMore(stream, state);
  8201. }
  8202. } else if (!addToFront) {
  8203. state.reading = false;
  8204. }
  8205. return needMoreData(state);
  8206. }
  8207. // if it's past the high water mark, we can push in some more.
  8208. // Also, if we have no data yet, we can stand some
  8209. // more bytes. This is to work around cases where hwm=0,
  8210. // such as the repl. Also, if the push() triggered a
  8211. // readable event, and the user called read(largeNumber) such that
  8212. // needReadable was set, then we ought to push more, so that another
  8213. // 'readable' event will be triggered.
  8214. function needMoreData(state) {
  8215. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  8216. }
  8217. // backwards compatibility.
  8218. Readable.prototype.setEncoding = function (enc) {
  8219. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  8220. this._readableState.decoder = new StringDecoder(enc);
  8221. this._readableState.encoding = enc;
  8222. return this;
  8223. };
  8224. // Don't raise the hwm > 8MB
  8225. var MAX_HWM = 0x800000;
  8226. function computeNewHighWaterMark(n) {
  8227. if (n >= MAX_HWM) {
  8228. n = MAX_HWM;
  8229. } else {
  8230. // Get the next highest power of 2 to prevent increasing hwm excessively in
  8231. // tiny amounts
  8232. n--;
  8233. n |= n >>> 1;
  8234. n |= n >>> 2;
  8235. n |= n >>> 4;
  8236. n |= n >>> 8;
  8237. n |= n >>> 16;
  8238. n++;
  8239. }
  8240. return n;
  8241. }
  8242. // This function is designed to be inlinable, so please take care when making
  8243. // changes to the function body.
  8244. function howMuchToRead(n, state) {
  8245. if (n <= 0 || state.length === 0 && state.ended) return 0;
  8246. if (state.objectMode) return 1;
  8247. if (n !== n) {
  8248. // Only flow one buffer at a time
  8249. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  8250. }
  8251. // If we're asking for more than the current hwm, then raise the hwm.
  8252. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  8253. if (n <= state.length) return n;
  8254. // Don't have enough
  8255. if (!state.ended) {
  8256. state.needReadable = true;
  8257. return 0;
  8258. }
  8259. return state.length;
  8260. }
  8261. // you can override either this method, or the async _read(n) below.
  8262. Readable.prototype.read = function (n) {
  8263. debug('read', n);
  8264. n = parseInt(n, 10);
  8265. var state = this._readableState;
  8266. var nOrig = n;
  8267. if (n !== 0) state.emittedReadable = false;
  8268. // if we're doing read(0) to trigger a readable event, but we
  8269. // already have a bunch of data in the buffer, then just trigger
  8270. // the 'readable' event and move on.
  8271. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  8272. debug('read: emitReadable', state.length, state.ended);
  8273. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  8274. return null;
  8275. }
  8276. n = howMuchToRead(n, state);
  8277. // if we've ended, and we're now clear, then finish it up.
  8278. if (n === 0 && state.ended) {
  8279. if (state.length === 0) endReadable(this);
  8280. return null;
  8281. }
  8282. // All the actual chunk generation logic needs to be
  8283. // *below* the call to _read. The reason is that in certain
  8284. // synthetic stream cases, such as passthrough streams, _read
  8285. // may be a completely synchronous operation which may change
  8286. // the state of the read buffer, providing enough data when
  8287. // before there was *not* enough.
  8288. //
  8289. // So, the steps are:
  8290. // 1. Figure out what the state of things will be after we do
  8291. // a read from the buffer.
  8292. //
  8293. // 2. If that resulting state will trigger a _read, then call _read.
  8294. // Note that this may be asynchronous, or synchronous. Yes, it is
  8295. // deeply ugly to write APIs this way, but that still doesn't mean
  8296. // that the Readable class should behave improperly, as streams are
  8297. // designed to be sync/async agnostic.
  8298. // Take note if the _read call is sync or async (ie, if the read call
  8299. // has returned yet), so that we know whether or not it's safe to emit
  8300. // 'readable' etc.
  8301. //
  8302. // 3. Actually pull the requested chunks out of the buffer and return.
  8303. // if we need a readable event, then we need to do some reading.
  8304. var doRead = state.needReadable;
  8305. debug('need readable', doRead);
  8306. // if we currently have less than the highWaterMark, then also read some
  8307. if (state.length === 0 || state.length - n < state.highWaterMark) {
  8308. doRead = true;
  8309. debug('length less than watermark', doRead);
  8310. }
  8311. // however, if we've ended, then there's no point, and if we're already
  8312. // reading, then it's unnecessary.
  8313. if (state.ended || state.reading) {
  8314. doRead = false;
  8315. debug('reading or ended', doRead);
  8316. } else if (doRead) {
  8317. debug('do read');
  8318. state.reading = true;
  8319. state.sync = true;
  8320. // if the length is currently zero, then we *need* a readable event.
  8321. if (state.length === 0) state.needReadable = true;
  8322. // call internal read method
  8323. this._read(state.highWaterMark);
  8324. state.sync = false;
  8325. // If _read pushed data synchronously, then `reading` will be false,
  8326. // and we need to re-evaluate how much data we can return to the user.
  8327. if (!state.reading) n = howMuchToRead(nOrig, state);
  8328. }
  8329. var ret;
  8330. if (n > 0) ret = fromList(n, state);else ret = null;
  8331. if (ret === null) {
  8332. state.needReadable = true;
  8333. n = 0;
  8334. } else {
  8335. state.length -= n;
  8336. }
  8337. if (state.length === 0) {
  8338. // If we have nothing in the buffer, then we want to know
  8339. // as soon as we *do* get something into the buffer.
  8340. if (!state.ended) state.needReadable = true;
  8341. // If we tried to read() past the EOF, then emit end on the next tick.
  8342. if (nOrig !== n && state.ended) endReadable(this);
  8343. }
  8344. if (ret !== null) this.emit('data', ret);
  8345. return ret;
  8346. };
  8347. function chunkInvalid(state, chunk) {
  8348. var er = null;
  8349. if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
  8350. er = new TypeError('Invalid non-string/buffer chunk');
  8351. }
  8352. return er;
  8353. }
  8354. function onEofChunk(stream, state) {
  8355. if (state.ended) return;
  8356. if (state.decoder) {
  8357. var chunk = state.decoder.end();
  8358. if (chunk && chunk.length) {
  8359. state.buffer.push(chunk);
  8360. state.length += state.objectMode ? 1 : chunk.length;
  8361. }
  8362. }
  8363. state.ended = true;
  8364. // emit 'readable' now to make sure it gets picked up.
  8365. emitReadable(stream);
  8366. }
  8367. // Don't emit readable right away in sync mode, because this can trigger
  8368. // another read() call => stack overflow. This way, it might trigger
  8369. // a nextTick recursion warning, but that's not so bad.
  8370. function emitReadable(stream) {
  8371. var state = stream._readableState;
  8372. state.needReadable = false;
  8373. if (!state.emittedReadable) {
  8374. debug('emitReadable', state.flowing);
  8375. state.emittedReadable = true;
  8376. if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
  8377. }
  8378. }
  8379. function emitReadable_(stream) {
  8380. debug('emit readable');
  8381. stream.emit('readable');
  8382. flow(stream);
  8383. }
  8384. // at this point, the user has presumably seen the 'readable' event,
  8385. // and called read() to consume some data. that may have triggered
  8386. // in turn another _read(n) call, in which case reading = true if
  8387. // it's in progress.
  8388. // However, if we're not ended, or reading, and the length < hwm,
  8389. // then go ahead and try to read some more preemptively.
  8390. function maybeReadMore(stream, state) {
  8391. if (!state.readingMore) {
  8392. state.readingMore = true;
  8393. processNextTick(maybeReadMore_, stream, state);
  8394. }
  8395. }
  8396. function maybeReadMore_(stream, state) {
  8397. var len = state.length;
  8398. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  8399. debug('maybeReadMore read 0');
  8400. stream.read(0);
  8401. if (len === state.length)
  8402. // didn't get any data, stop spinning.
  8403. break;else len = state.length;
  8404. }
  8405. state.readingMore = false;
  8406. }
  8407. // abstract method. to be overridden in specific implementation classes.
  8408. // call cb(er, data) where data is <= n in length.
  8409. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  8410. // arbitrary, and perhaps not very meaningful.
  8411. Readable.prototype._read = function (n) {
  8412. this.emit('error', new Error('not implemented'));
  8413. };
  8414. Readable.prototype.pipe = function (dest, pipeOpts) {
  8415. var src = this;
  8416. var state = this._readableState;
  8417. switch (state.pipesCount) {
  8418. case 0:
  8419. state.pipes = dest;
  8420. break;
  8421. case 1:
  8422. state.pipes = [state.pipes, dest];
  8423. break;
  8424. default:
  8425. state.pipes.push(dest);
  8426. break;
  8427. }
  8428. state.pipesCount += 1;
  8429. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  8430. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  8431. var endFn = doEnd ? onend : cleanup;
  8432. if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
  8433. dest.on('unpipe', onunpipe);
  8434. function onunpipe(readable) {
  8435. debug('onunpipe');
  8436. if (readable === src) {
  8437. cleanup();
  8438. }
  8439. }
  8440. function onend() {
  8441. debug('onend');
  8442. dest.end();
  8443. }
  8444. // when the dest drains, it reduces the awaitDrain counter
  8445. // on the source. This would be more elegant with a .once()
  8446. // handler in flow(), but adding and removing repeatedly is
  8447. // too slow.
  8448. var ondrain = pipeOnDrain(src);
  8449. dest.on('drain', ondrain);
  8450. var cleanedUp = false;
  8451. function cleanup() {
  8452. debug('cleanup');
  8453. // cleanup event handlers once the pipe is broken
  8454. dest.removeListener('close', onclose);
  8455. dest.removeListener('finish', onfinish);
  8456. dest.removeListener('drain', ondrain);
  8457. dest.removeListener('error', onerror);
  8458. dest.removeListener('unpipe', onunpipe);
  8459. src.removeListener('end', onend);
  8460. src.removeListener('end', cleanup);
  8461. src.removeListener('data', ondata);
  8462. cleanedUp = true;
  8463. // if the reader is waiting for a drain event from this
  8464. // specific writer, then it would cause it to never start
  8465. // flowing again.
  8466. // So, if this is awaiting a drain, then we just call it now.
  8467. // If we don't know, then assume that we are waiting for one.
  8468. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  8469. }
  8470. // If the user pushes more data while we're writing to dest then we'll end up
  8471. // in ondata again. However, we only want to increase awaitDrain once because
  8472. // dest will only emit one 'drain' event for the multiple writes.
  8473. // => Introduce a guard on increasing awaitDrain.
  8474. var increasedAwaitDrain = false;
  8475. src.on('data', ondata);
  8476. function ondata(chunk) {
  8477. debug('ondata');
  8478. increasedAwaitDrain = false;
  8479. var ret = dest.write(chunk);
  8480. if (false === ret && !increasedAwaitDrain) {
  8481. // If the user unpiped during `dest.write()`, it is possible
  8482. // to get stuck in a permanently paused state if that write
  8483. // also returned false.
  8484. // => Check whether `dest` is still a piping destination.
  8485. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  8486. debug('false write response, pause', src._readableState.awaitDrain);
  8487. src._readableState.awaitDrain++;
  8488. increasedAwaitDrain = true;
  8489. }
  8490. src.pause();
  8491. }
  8492. }
  8493. // if the dest has an error, then stop piping into it.
  8494. // however, don't suppress the throwing behavior for this.
  8495. function onerror(er) {
  8496. debug('onerror', er);
  8497. unpipe();
  8498. dest.removeListener('error', onerror);
  8499. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  8500. }
  8501. // Make sure our error handler is attached before userland ones.
  8502. prependListener(dest, 'error', onerror);
  8503. // Both close and finish should trigger unpipe, but only once.
  8504. function onclose() {
  8505. dest.removeListener('finish', onfinish);
  8506. unpipe();
  8507. }
  8508. dest.once('close', onclose);
  8509. function onfinish() {
  8510. debug('onfinish');
  8511. dest.removeListener('close', onclose);
  8512. unpipe();
  8513. }
  8514. dest.once('finish', onfinish);
  8515. function unpipe() {
  8516. debug('unpipe');
  8517. src.unpipe(dest);
  8518. }
  8519. // tell the dest that it's being piped to
  8520. dest.emit('pipe', src);
  8521. // start the flow if it hasn't been started already.
  8522. if (!state.flowing) {
  8523. debug('pipe resume');
  8524. src.resume();
  8525. }
  8526. return dest;
  8527. };
  8528. function pipeOnDrain(src) {
  8529. return function () {
  8530. var state = src._readableState;
  8531. debug('pipeOnDrain', state.awaitDrain);
  8532. if (state.awaitDrain) state.awaitDrain--;
  8533. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  8534. state.flowing = true;
  8535. flow(src);
  8536. }
  8537. };
  8538. }
  8539. Readable.prototype.unpipe = function (dest) {
  8540. var state = this._readableState;
  8541. // if we're not piping anywhere, then do nothing.
  8542. if (state.pipesCount === 0) return this;
  8543. // just one destination. most common case.
  8544. if (state.pipesCount === 1) {
  8545. // passed in one, but it's not the right one.
  8546. if (dest && dest !== state.pipes) return this;
  8547. if (!dest) dest = state.pipes;
  8548. // got a match.
  8549. state.pipes = null;
  8550. state.pipesCount = 0;
  8551. state.flowing = false;
  8552. if (dest) dest.emit('unpipe', this);
  8553. return this;
  8554. }
  8555. // slow case. multiple pipe destinations.
  8556. if (!dest) {
  8557. // remove all.
  8558. var dests = state.pipes;
  8559. var len = state.pipesCount;
  8560. state.pipes = null;
  8561. state.pipesCount = 0;
  8562. state.flowing = false;
  8563. for (var _i = 0; _i < len; _i++) {
  8564. dests[_i].emit('unpipe', this);
  8565. }return this;
  8566. }
  8567. // try to find the right one.
  8568. var i = indexOf(state.pipes, dest);
  8569. if (i === -1) return this;
  8570. state.pipes.splice(i, 1);
  8571. state.pipesCount -= 1;
  8572. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  8573. dest.emit('unpipe', this);
  8574. return this;
  8575. };
  8576. // set up data events if they are asked for
  8577. // Ensure readable listeners eventually get something
  8578. Readable.prototype.on = function (ev, fn) {
  8579. var res = Stream.prototype.on.call(this, ev, fn);
  8580. if (ev === 'data') {
  8581. // Start flowing on next tick if stream isn't explicitly paused
  8582. if (this._readableState.flowing !== false) this.resume();
  8583. } else if (ev === 'readable') {
  8584. var state = this._readableState;
  8585. if (!state.endEmitted && !state.readableListening) {
  8586. state.readableListening = state.needReadable = true;
  8587. state.emittedReadable = false;
  8588. if (!state.reading) {
  8589. processNextTick(nReadingNextTick, this);
  8590. } else if (state.length) {
  8591. emitReadable(this, state);
  8592. }
  8593. }
  8594. }
  8595. return res;
  8596. };
  8597. Readable.prototype.addListener = Readable.prototype.on;
  8598. function nReadingNextTick(self) {
  8599. debug('readable nexttick read 0');
  8600. self.read(0);
  8601. }
  8602. // pause() and resume() are remnants of the legacy readable stream API
  8603. // If the user uses them, then switch into old mode.
  8604. Readable.prototype.resume = function () {
  8605. var state = this._readableState;
  8606. if (!state.flowing) {
  8607. debug('resume');
  8608. state.flowing = true;
  8609. resume(this, state);
  8610. }
  8611. return this;
  8612. };
  8613. function resume(stream, state) {
  8614. if (!state.resumeScheduled) {
  8615. state.resumeScheduled = true;
  8616. processNextTick(resume_, stream, state);
  8617. }
  8618. }
  8619. function resume_(stream, state) {
  8620. if (!state.reading) {
  8621. debug('resume read 0');
  8622. stream.read(0);
  8623. }
  8624. state.resumeScheduled = false;
  8625. state.awaitDrain = 0;
  8626. stream.emit('resume');
  8627. flow(stream);
  8628. if (state.flowing && !state.reading) stream.read(0);
  8629. }
  8630. Readable.prototype.pause = function () {
  8631. debug('call pause flowing=%j', this._readableState.flowing);
  8632. if (false !== this._readableState.flowing) {
  8633. debug('pause');
  8634. this._readableState.flowing = false;
  8635. this.emit('pause');
  8636. }
  8637. return this;
  8638. };
  8639. function flow(stream) {
  8640. var state = stream._readableState;
  8641. debug('flow', state.flowing);
  8642. while (state.flowing && stream.read() !== null) {}
  8643. }
  8644. // wrap an old-style stream as the async data source.
  8645. // This is *not* part of the readable stream interface.
  8646. // It is an ugly unfortunate mess of history.
  8647. Readable.prototype.wrap = function (stream) {
  8648. var state = this._readableState;
  8649. var paused = false;
  8650. var self = this;
  8651. stream.on('end', function () {
  8652. debug('wrapped end');
  8653. if (state.decoder && !state.ended) {
  8654. var chunk = state.decoder.end();
  8655. if (chunk && chunk.length) self.push(chunk);
  8656. }
  8657. self.push(null);
  8658. });
  8659. stream.on('data', function (chunk) {
  8660. debug('wrapped data');
  8661. if (state.decoder) chunk = state.decoder.write(chunk);
  8662. // don't skip over falsy values in objectMode
  8663. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  8664. var ret = self.push(chunk);
  8665. if (!ret) {
  8666. paused = true;
  8667. stream.pause();
  8668. }
  8669. });
  8670. // proxy all the other methods.
  8671. // important when wrapping filters and duplexes.
  8672. for (var i in stream) {
  8673. if (this[i] === undefined && typeof stream[i] === 'function') {
  8674. this[i] = function (method) {
  8675. return function () {
  8676. return stream[method].apply(stream, arguments);
  8677. };
  8678. }(i);
  8679. }
  8680. }
  8681. // proxy certain important events.
  8682. var events = ['error', 'close', 'destroy', 'pause', 'resume'];
  8683. forEach(events, function (ev) {
  8684. stream.on(ev, self.emit.bind(self, ev));
  8685. });
  8686. // when we try to consume some more bytes, simply unpause the
  8687. // underlying stream.
  8688. self._read = function (n) {
  8689. debug('wrapped _read', n);
  8690. if (paused) {
  8691. paused = false;
  8692. stream.resume();
  8693. }
  8694. };
  8695. return self;
  8696. };
  8697. // exposed for testing purposes only.
  8698. Readable._fromList = fromList;
  8699. // Pluck off n bytes from an array of buffers.
  8700. // Length is the combined lengths of all the buffers in the list.
  8701. // This function is designed to be inlinable, so please take care when making
  8702. // changes to the function body.
  8703. function fromList(n, state) {
  8704. // nothing buffered
  8705. if (state.length === 0) return null;
  8706. var ret;
  8707. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  8708. // read it all, truncate the list
  8709. if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
  8710. state.buffer.clear();
  8711. } else {
  8712. // read part of list
  8713. ret = fromListPartial(n, state.buffer, state.decoder);
  8714. }
  8715. return ret;
  8716. }
  8717. // Extracts only enough buffered data to satisfy the amount requested.
  8718. // This function is designed to be inlinable, so please take care when making
  8719. // changes to the function body.
  8720. function fromListPartial(n, list, hasStrings) {
  8721. var ret;
  8722. if (n < list.head.data.length) {
  8723. // slice is the same for buffers and strings
  8724. ret = list.head.data.slice(0, n);
  8725. list.head.data = list.head.data.slice(n);
  8726. } else if (n === list.head.data.length) {
  8727. // first chunk is a perfect match
  8728. ret = list.shift();
  8729. } else {
  8730. // result spans more than one buffer
  8731. ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
  8732. }
  8733. return ret;
  8734. }
  8735. // Copies a specified amount of characters from the list of buffered data
  8736. // chunks.
  8737. // This function is designed to be inlinable, so please take care when making
  8738. // changes to the function body.
  8739. function copyFromBufferString(n, list) {
  8740. var p = list.head;
  8741. var c = 1;
  8742. var ret = p.data;
  8743. n -= ret.length;
  8744. while (p = p.next) {
  8745. var str = p.data;
  8746. var nb = n > str.length ? str.length : n;
  8747. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  8748. n -= nb;
  8749. if (n === 0) {
  8750. if (nb === str.length) {
  8751. ++c;
  8752. if (p.next) list.head = p.next;else list.head = list.tail = null;
  8753. } else {
  8754. list.head = p;
  8755. p.data = str.slice(nb);
  8756. }
  8757. break;
  8758. }
  8759. ++c;
  8760. }
  8761. list.length -= c;
  8762. return ret;
  8763. }
  8764. // Copies a specified amount of bytes from the list of buffered data chunks.
  8765. // This function is designed to be inlinable, so please take care when making
  8766. // changes to the function body.
  8767. function copyFromBuffer(n, list) {
  8768. var ret = bufferShim.allocUnsafe(n);
  8769. var p = list.head;
  8770. var c = 1;
  8771. p.data.copy(ret);
  8772. n -= p.data.length;
  8773. while (p = p.next) {
  8774. var buf = p.data;
  8775. var nb = n > buf.length ? buf.length : n;
  8776. buf.copy(ret, ret.length - n, 0, nb);
  8777. n -= nb;
  8778. if (n === 0) {
  8779. if (nb === buf.length) {
  8780. ++c;
  8781. if (p.next) list.head = p.next;else list.head = list.tail = null;
  8782. } else {
  8783. list.head = p;
  8784. p.data = buf.slice(nb);
  8785. }
  8786. break;
  8787. }
  8788. ++c;
  8789. }
  8790. list.length -= c;
  8791. return ret;
  8792. }
  8793. function endReadable(stream) {
  8794. var state = stream._readableState;
  8795. // If we get here before consuming all the bytes, then that is a
  8796. // bug in node. Should never happen.
  8797. if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
  8798. if (!state.endEmitted) {
  8799. state.ended = true;
  8800. processNextTick(endReadableNT, state, stream);
  8801. }
  8802. }
  8803. function endReadableNT(state, stream) {
  8804. // Check that we didn't get one last unshift.
  8805. if (!state.endEmitted && state.length === 0) {
  8806. state.endEmitted = true;
  8807. stream.readable = false;
  8808. stream.emit('end');
  8809. }
  8810. }
  8811. function forEach(xs, f) {
  8812. for (var i = 0, l = xs.length; i < l; i++) {
  8813. f(xs[i], i);
  8814. }
  8815. }
  8816. function indexOf(xs, x) {
  8817. for (var i = 0, l = xs.length; i < l; i++) {
  8818. if (xs[i] === x) return i;
  8819. }
  8820. return -1;
  8821. }
  8822. }).call(this,require('_process'))
  8823. },{"./_stream_duplex":23,"./internal/streams/BufferList":28,"_process":21,"buffer":6,"buffer-shims":5,"core-util-is":8,"events":13,"inherits":15,"isarray":17,"process-nextick-args":20,"string_decoder/":43,"util":4}],26:[function(require,module,exports){
  8824. // a transform stream is a readable/writable stream where you do
  8825. // something with the data. Sometimes it's called a "filter",
  8826. // but that's not a great name for it, since that implies a thing where
  8827. // some bits pass through, and others are simply ignored. (That would
  8828. // be a valid example of a transform, of course.)
  8829. //
  8830. // While the output is causally related to the input, it's not a
  8831. // necessarily symmetric or synchronous transformation. For example,
  8832. // a zlib stream might take multiple plain-text writes(), and then
  8833. // emit a single compressed chunk some time in the future.
  8834. //
  8835. // Here's how this works:
  8836. //
  8837. // The Transform stream has all the aspects of the readable and writable
  8838. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  8839. // internally, and returns false if there's a lot of pending writes
  8840. // buffered up. When you call read(), that calls _read(n) until
  8841. // there's enough pending readable data buffered up.
  8842. //
  8843. // In a transform stream, the written data is placed in a buffer. When
  8844. // _read(n) is called, it transforms the queued up data, calling the
  8845. // buffered _write cb's as it consumes chunks. If consuming a single
  8846. // written chunk would result in multiple output chunks, then the first
  8847. // outputted bit calls the readcb, and subsequent chunks just go into
  8848. // the read buffer, and will cause it to emit 'readable' if necessary.
  8849. //
  8850. // This way, back-pressure is actually determined by the reading side,
  8851. // since _read has to be called to start processing a new chunk. However,
  8852. // a pathological inflate type of transform can cause excessive buffering
  8853. // here. For example, imagine a stream where every byte of input is
  8854. // interpreted as an integer from 0-255, and then results in that many
  8855. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  8856. // 1kb of data being output. In this case, you could write a very small
  8857. // amount of input, and end up with a very large amount of output. In
  8858. // such a pathological inflating mechanism, there'd be no way to tell
  8859. // the system to stop doing the transform. A single 4MB write could
  8860. // cause the system to run out of memory.
  8861. //
  8862. // However, even in such a pathological case, only a single written chunk
  8863. // would be consumed, and then the rest would wait (un-transformed) until
  8864. // the results of the previous transformed chunk were consumed.
  8865. 'use strict';
  8866. module.exports = Transform;
  8867. var Duplex = require('./_stream_duplex');
  8868. /*<replacement>*/
  8869. var util = require('core-util-is');
  8870. util.inherits = require('inherits');
  8871. /*</replacement>*/
  8872. util.inherits(Transform, Duplex);
  8873. function TransformState(stream) {
  8874. this.afterTransform = function (er, data) {
  8875. return afterTransform(stream, er, data);
  8876. };
  8877. this.needTransform = false;
  8878. this.transforming = false;
  8879. this.writecb = null;
  8880. this.writechunk = null;
  8881. this.writeencoding = null;
  8882. }
  8883. function afterTransform(stream, er, data) {
  8884. var ts = stream._transformState;
  8885. ts.transforming = false;
  8886. var cb = ts.writecb;
  8887. if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
  8888. ts.writechunk = null;
  8889. ts.writecb = null;
  8890. if (data !== null && data !== undefined) stream.push(data);
  8891. cb(er);
  8892. var rs = stream._readableState;
  8893. rs.reading = false;
  8894. if (rs.needReadable || rs.length < rs.highWaterMark) {
  8895. stream._read(rs.highWaterMark);
  8896. }
  8897. }
  8898. function Transform(options) {
  8899. if (!(this instanceof Transform)) return new Transform(options);
  8900. Duplex.call(this, options);
  8901. this._transformState = new TransformState(this);
  8902. // when the writable side finishes, then flush out anything remaining.
  8903. var stream = this;
  8904. // start out asking for a readable event once data is transformed.
  8905. this._readableState.needReadable = true;
  8906. // we have implemented the _read method, and done the other things
  8907. // that Readable wants before the first _read call, so unset the
  8908. // sync guard flag.
  8909. this._readableState.sync = false;
  8910. if (options) {
  8911. if (typeof options.transform === 'function') this._transform = options.transform;
  8912. if (typeof options.flush === 'function') this._flush = options.flush;
  8913. }
  8914. this.once('prefinish', function () {
  8915. if (typeof this._flush === 'function') this._flush(function (er) {
  8916. done(stream, er);
  8917. });else done(stream);
  8918. });
  8919. }
  8920. Transform.prototype.push = function (chunk, encoding) {
  8921. this._transformState.needTransform = false;
  8922. return Duplex.prototype.push.call(this, chunk, encoding);
  8923. };
  8924. // This is the part where you do stuff!
  8925. // override this function in implementation classes.
  8926. // 'chunk' is an input chunk.
  8927. //
  8928. // Call `push(newChunk)` to pass along transformed output
  8929. // to the readable side. You may call 'push' zero or more times.
  8930. //
  8931. // Call `cb(err)` when you are done with this chunk. If you pass
  8932. // an error, then that'll put the hurt on the whole operation. If you
  8933. // never call cb(), then you'll never get another chunk.
  8934. Transform.prototype._transform = function (chunk, encoding, cb) {
  8935. throw new Error('Not implemented');
  8936. };
  8937. Transform.prototype._write = function (chunk, encoding, cb) {
  8938. var ts = this._transformState;
  8939. ts.writecb = cb;
  8940. ts.writechunk = chunk;
  8941. ts.writeencoding = encoding;
  8942. if (!ts.transforming) {
  8943. var rs = this._readableState;
  8944. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  8945. }
  8946. };
  8947. // Doesn't matter what the args are here.
  8948. // _transform does all the work.
  8949. // That we got here means that the readable side wants more data.
  8950. Transform.prototype._read = function (n) {
  8951. var ts = this._transformState;
  8952. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  8953. ts.transforming = true;
  8954. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  8955. } else {
  8956. // mark that we need a transform, so that any data that comes in
  8957. // will get processed, now that we've asked for it.
  8958. ts.needTransform = true;
  8959. }
  8960. };
  8961. function done(stream, er) {
  8962. if (er) return stream.emit('error', er);
  8963. // if there's nothing in the write buffer, then that means
  8964. // that nothing more will ever be provided
  8965. var ws = stream._writableState;
  8966. var ts = stream._transformState;
  8967. if (ws.length) throw new Error('Calling transform done when ws.length != 0');
  8968. if (ts.transforming) throw new Error('Calling transform done when still transforming');
  8969. return stream.push(null);
  8970. }
  8971. },{"./_stream_duplex":23,"core-util-is":8,"inherits":15}],27:[function(require,module,exports){
  8972. (function (process){
  8973. // A bit simpler than readable streams.
  8974. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  8975. // the drain event emission and buffering.
  8976. 'use strict';
  8977. module.exports = Writable;
  8978. /*<replacement>*/
  8979. var processNextTick = require('process-nextick-args');
  8980. /*</replacement>*/
  8981. /*<replacement>*/
  8982. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
  8983. /*</replacement>*/
  8984. Writable.WritableState = WritableState;
  8985. /*<replacement>*/
  8986. var util = require('core-util-is');
  8987. util.inherits = require('inherits');
  8988. /*</replacement>*/
  8989. /*<replacement>*/
  8990. var internalUtil = {
  8991. deprecate: require('util-deprecate')
  8992. };
  8993. /*</replacement>*/
  8994. /*<replacement>*/
  8995. var Stream;
  8996. (function () {
  8997. try {
  8998. Stream = require('st' + 'ream');
  8999. } catch (_) {} finally {
  9000. if (!Stream) Stream = require('events').EventEmitter;
  9001. }
  9002. })();
  9003. /*</replacement>*/
  9004. var Buffer = require('buffer').Buffer;
  9005. /*<replacement>*/
  9006. var bufferShim = require('buffer-shims');
  9007. /*</replacement>*/
  9008. util.inherits(Writable, Stream);
  9009. function nop() {}
  9010. function WriteReq(chunk, encoding, cb) {
  9011. this.chunk = chunk;
  9012. this.encoding = encoding;
  9013. this.callback = cb;
  9014. this.next = null;
  9015. }
  9016. var Duplex;
  9017. function WritableState(options, stream) {
  9018. Duplex = Duplex || require('./_stream_duplex');
  9019. options = options || {};
  9020. // object stream flag to indicate whether or not this stream
  9021. // contains buffers or objects.
  9022. this.objectMode = !!options.objectMode;
  9023. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  9024. // the point at which write() starts returning false
  9025. // Note: 0 is a valid value, means that we always return false if
  9026. // the entire buffer is not flushed immediately on write()
  9027. var hwm = options.highWaterMark;
  9028. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  9029. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  9030. // cast to ints.
  9031. this.highWaterMark = ~ ~this.highWaterMark;
  9032. this.needDrain = false;
  9033. // at the start of calling end()
  9034. this.ending = false;
  9035. // when end() has been called, and returned
  9036. this.ended = false;
  9037. // when 'finish' is emitted
  9038. this.finished = false;
  9039. // should we decode strings into buffers before passing to _write?
  9040. // this is here so that some node-core streams can optimize string
  9041. // handling at a lower level.
  9042. var noDecode = options.decodeStrings === false;
  9043. this.decodeStrings = !noDecode;
  9044. // Crypto is kind of old and crusty. Historically, its default string
  9045. // encoding is 'binary' so we have to make this configurable.
  9046. // Everything else in the universe uses 'utf8', though.
  9047. this.defaultEncoding = options.defaultEncoding || 'utf8';
  9048. // not an actual buffer we keep track of, but a measurement
  9049. // of how much we're waiting to get pushed to some underlying
  9050. // socket or file.
  9051. this.length = 0;
  9052. // a flag to see when we're in the middle of a write.
  9053. this.writing = false;
  9054. // when true all writes will be buffered until .uncork() call
  9055. this.corked = 0;
  9056. // a flag to be able to tell if the onwrite cb is called immediately,
  9057. // or on a later tick. We set this to true at first, because any
  9058. // actions that shouldn't happen until "later" should generally also
  9059. // not happen before the first write call.
  9060. this.sync = true;
  9061. // a flag to know if we're processing previously buffered items, which
  9062. // may call the _write() callback in the same tick, so that we don't
  9063. // end up in an overlapped onwrite situation.
  9064. this.bufferProcessing = false;
  9065. // the callback that's passed to _write(chunk,cb)
  9066. this.onwrite = function (er) {
  9067. onwrite(stream, er);
  9068. };
  9069. // the callback that the user supplies to write(chunk,encoding,cb)
  9070. this.writecb = null;
  9071. // the amount that is being written when _write is called.
  9072. this.writelen = 0;
  9073. this.bufferedRequest = null;
  9074. this.lastBufferedRequest = null;
  9075. // number of pending user-supplied write callbacks
  9076. // this must be 0 before 'finish' can be emitted
  9077. this.pendingcb = 0;
  9078. // emit prefinish if the only thing we're waiting for is _write cbs
  9079. // This is relevant for synchronous Transform streams
  9080. this.prefinished = false;
  9081. // True if the error was already emitted and should not be thrown again
  9082. this.errorEmitted = false;
  9083. // count buffered requests
  9084. this.bufferedRequestCount = 0;
  9085. // allocate the first CorkedRequest, there is always
  9086. // one allocated and free to use, and we maintain at most two
  9087. this.corkedRequestsFree = new CorkedRequest(this);
  9088. }
  9089. WritableState.prototype.getBuffer = function writableStateGetBuffer() {
  9090. var current = this.bufferedRequest;
  9091. var out = [];
  9092. while (current) {
  9093. out.push(current);
  9094. current = current.next;
  9095. }
  9096. return out;
  9097. };
  9098. (function () {
  9099. try {
  9100. Object.defineProperty(WritableState.prototype, 'buffer', {
  9101. get: internalUtil.deprecate(function () {
  9102. return this.getBuffer();
  9103. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
  9104. });
  9105. } catch (_) {}
  9106. })();
  9107. var Duplex;
  9108. function Writable(options) {
  9109. Duplex = Duplex || require('./_stream_duplex');
  9110. // Writable ctor is applied to Duplexes, though they're not
  9111. // instanceof Writable, they're instanceof Readable.
  9112. if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options);
  9113. this._writableState = new WritableState(options, this);
  9114. // legacy.
  9115. this.writable = true;
  9116. if (options) {
  9117. if (typeof options.write === 'function') this._write = options.write;
  9118. if (typeof options.writev === 'function') this._writev = options.writev;
  9119. }
  9120. Stream.call(this);
  9121. }
  9122. // Otherwise people can pipe Writable streams, which is just wrong.
  9123. Writable.prototype.pipe = function () {
  9124. this.emit('error', new Error('Cannot pipe, not readable'));
  9125. };
  9126. function writeAfterEnd(stream, cb) {
  9127. var er = new Error('write after end');
  9128. // TODO: defer error events consistently everywhere, not just the cb
  9129. stream.emit('error', er);
  9130. processNextTick(cb, er);
  9131. }
  9132. // If we get something that is not a buffer, string, null, or undefined,
  9133. // and we're not in objectMode, then that's an error.
  9134. // Otherwise stream chunks are all considered to be of length=1, and the
  9135. // watermarks determine how many objects to keep in the buffer, rather than
  9136. // how many bytes or characters.
  9137. function validChunk(stream, state, chunk, cb) {
  9138. var valid = true;
  9139. var er = false;
  9140. // Always throw error if a null is written
  9141. // if we are not in object mode then throw
  9142. // if it is not a buffer, string, or undefined.
  9143. if (chunk === null) {
  9144. er = new TypeError('May not write null values to stream');
  9145. } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  9146. er = new TypeError('Invalid non-string/buffer chunk');
  9147. }
  9148. if (er) {
  9149. stream.emit('error', er);
  9150. processNextTick(cb, er);
  9151. valid = false;
  9152. }
  9153. return valid;
  9154. }
  9155. Writable.prototype.write = function (chunk, encoding, cb) {
  9156. var state = this._writableState;
  9157. var ret = false;
  9158. if (typeof encoding === 'function') {
  9159. cb = encoding;
  9160. encoding = null;
  9161. }
  9162. if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  9163. if (typeof cb !== 'function') cb = nop;
  9164. if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
  9165. state.pendingcb++;
  9166. ret = writeOrBuffer(this, state, chunk, encoding, cb);
  9167. }
  9168. return ret;
  9169. };
  9170. Writable.prototype.cork = function () {
  9171. var state = this._writableState;
  9172. state.corked++;
  9173. };
  9174. Writable.prototype.uncork = function () {
  9175. var state = this._writableState;
  9176. if (state.corked) {
  9177. state.corked--;
  9178. if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  9179. }
  9180. };
  9181. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  9182. // node::ParseEncoding() requires lower case.
  9183. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  9184. if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
  9185. this._writableState.defaultEncoding = encoding;
  9186. return this;
  9187. };
  9188. function decodeChunk(state, chunk, encoding) {
  9189. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  9190. chunk = bufferShim.from(chunk, encoding);
  9191. }
  9192. return chunk;
  9193. }
  9194. // if we're already writing something, then just put this
  9195. // in the queue, and wait our turn. Otherwise, call _write
  9196. // If we return false, then we need a drain event, so set that flag.
  9197. function writeOrBuffer(stream, state, chunk, encoding, cb) {
  9198. chunk = decodeChunk(state, chunk, encoding);
  9199. if (Buffer.isBuffer(chunk)) encoding = 'buffer';
  9200. var len = state.objectMode ? 1 : chunk.length;
  9201. state.length += len;
  9202. var ret = state.length < state.highWaterMark;
  9203. // we must ensure that previous needDrain will not be reset to false.
  9204. if (!ret) state.needDrain = true;
  9205. if (state.writing || state.corked) {
  9206. var last = state.lastBufferedRequest;
  9207. state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
  9208. if (last) {
  9209. last.next = state.lastBufferedRequest;
  9210. } else {
  9211. state.bufferedRequest = state.lastBufferedRequest;
  9212. }
  9213. state.bufferedRequestCount += 1;
  9214. } else {
  9215. doWrite(stream, state, false, len, chunk, encoding, cb);
  9216. }
  9217. return ret;
  9218. }
  9219. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  9220. state.writelen = len;
  9221. state.writecb = cb;
  9222. state.writing = true;
  9223. state.sync = true;
  9224. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  9225. state.sync = false;
  9226. }
  9227. function onwriteError(stream, state, sync, er, cb) {
  9228. --state.pendingcb;
  9229. if (sync) processNextTick(cb, er);else cb(er);
  9230. stream._writableState.errorEmitted = true;
  9231. stream.emit('error', er);
  9232. }
  9233. function onwriteStateUpdate(state) {
  9234. state.writing = false;
  9235. state.writecb = null;
  9236. state.length -= state.writelen;
  9237. state.writelen = 0;
  9238. }
  9239. function onwrite(stream, er) {
  9240. var state = stream._writableState;
  9241. var sync = state.sync;
  9242. var cb = state.writecb;
  9243. onwriteStateUpdate(state);
  9244. if (er) onwriteError(stream, state, sync, er, cb);else {
  9245. // Check if we're actually ready to finish, but don't emit yet
  9246. var finished = needFinish(state);
  9247. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  9248. clearBuffer(stream, state);
  9249. }
  9250. if (sync) {
  9251. /*<replacement>*/
  9252. asyncWrite(afterWrite, stream, state, finished, cb);
  9253. /*</replacement>*/
  9254. } else {
  9255. afterWrite(stream, state, finished, cb);
  9256. }
  9257. }
  9258. }
  9259. function afterWrite(stream, state, finished, cb) {
  9260. if (!finished) onwriteDrain(stream, state);
  9261. state.pendingcb--;
  9262. cb();
  9263. finishMaybe(stream, state);
  9264. }
  9265. // Must force callback to be called on nextTick, so that we don't
  9266. // emit 'drain' before the write() consumer gets the 'false' return
  9267. // value, and has a chance to attach a 'drain' listener.
  9268. function onwriteDrain(stream, state) {
  9269. if (state.length === 0 && state.needDrain) {
  9270. state.needDrain = false;
  9271. stream.emit('drain');
  9272. }
  9273. }
  9274. // if there's something in the buffer waiting, then process it
  9275. function clearBuffer(stream, state) {
  9276. state.bufferProcessing = true;
  9277. var entry = state.bufferedRequest;
  9278. if (stream._writev && entry && entry.next) {
  9279. // Fast case, write everything using _writev()
  9280. var l = state.bufferedRequestCount;
  9281. var buffer = new Array(l);
  9282. var holder = state.corkedRequestsFree;
  9283. holder.entry = entry;
  9284. var count = 0;
  9285. while (entry) {
  9286. buffer[count] = entry;
  9287. entry = entry.next;
  9288. count += 1;
  9289. }
  9290. doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  9291. // doWrite is almost always async, defer these to save a bit of time
  9292. // as the hot path ends with doWrite
  9293. state.pendingcb++;
  9294. state.lastBufferedRequest = null;
  9295. if (holder.next) {
  9296. state.corkedRequestsFree = holder.next;
  9297. holder.next = null;
  9298. } else {
  9299. state.corkedRequestsFree = new CorkedRequest(state);
  9300. }
  9301. } else {
  9302. // Slow case, write chunks one-by-one
  9303. while (entry) {
  9304. var chunk = entry.chunk;
  9305. var encoding = entry.encoding;
  9306. var cb = entry.callback;
  9307. var len = state.objectMode ? 1 : chunk.length;
  9308. doWrite(stream, state, false, len, chunk, encoding, cb);
  9309. entry = entry.next;
  9310. // if we didn't call the onwrite immediately, then
  9311. // it means that we need to wait until it does.
  9312. // also, that means that the chunk and cb are currently
  9313. // being processed, so move the buffer counter past them.
  9314. if (state.writing) {
  9315. break;
  9316. }
  9317. }
  9318. if (entry === null) state.lastBufferedRequest = null;
  9319. }
  9320. state.bufferedRequestCount = 0;
  9321. state.bufferedRequest = entry;
  9322. state.bufferProcessing = false;
  9323. }
  9324. Writable.prototype._write = function (chunk, encoding, cb) {
  9325. cb(new Error('not implemented'));
  9326. };
  9327. Writable.prototype._writev = null;
  9328. Writable.prototype.end = function (chunk, encoding, cb) {
  9329. var state = this._writableState;
  9330. if (typeof chunk === 'function') {
  9331. cb = chunk;
  9332. chunk = null;
  9333. encoding = null;
  9334. } else if (typeof encoding === 'function') {
  9335. cb = encoding;
  9336. encoding = null;
  9337. }
  9338. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  9339. // .end() fully uncorks
  9340. if (state.corked) {
  9341. state.corked = 1;
  9342. this.uncork();
  9343. }
  9344. // ignore unnecessary end() calls.
  9345. if (!state.ending && !state.finished) endWritable(this, state, cb);
  9346. };
  9347. function needFinish(state) {
  9348. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  9349. }
  9350. function prefinish(stream, state) {
  9351. if (!state.prefinished) {
  9352. state.prefinished = true;
  9353. stream.emit('prefinish');
  9354. }
  9355. }
  9356. function finishMaybe(stream, state) {
  9357. var need = needFinish(state);
  9358. if (need) {
  9359. if (state.pendingcb === 0) {
  9360. prefinish(stream, state);
  9361. state.finished = true;
  9362. stream.emit('finish');
  9363. } else {
  9364. prefinish(stream, state);
  9365. }
  9366. }
  9367. return need;
  9368. }
  9369. function endWritable(stream, state, cb) {
  9370. state.ending = true;
  9371. finishMaybe(stream, state);
  9372. if (cb) {
  9373. if (state.finished) processNextTick(cb);else stream.once('finish', cb);
  9374. }
  9375. state.ended = true;
  9376. stream.writable = false;
  9377. }
  9378. // It seems a linked list but it is not
  9379. // there will be only 2 of these for each stream
  9380. function CorkedRequest(state) {
  9381. var _this = this;
  9382. this.next = null;
  9383. this.entry = null;
  9384. this.finish = function (err) {
  9385. var entry = _this.entry;
  9386. _this.entry = null;
  9387. while (entry) {
  9388. var cb = entry.callback;
  9389. state.pendingcb--;
  9390. cb(err);
  9391. entry = entry.next;
  9392. }
  9393. if (state.corkedRequestsFree) {
  9394. state.corkedRequestsFree.next = _this;
  9395. } else {
  9396. state.corkedRequestsFree = _this;
  9397. }
  9398. };
  9399. }
  9400. }).call(this,require('_process'))
  9401. },{"./_stream_duplex":23,"_process":21,"buffer":6,"buffer-shims":5,"core-util-is":8,"events":13,"inherits":15,"process-nextick-args":20,"util-deprecate":44}],28:[function(require,module,exports){
  9402. 'use strict';
  9403. var Buffer = require('buffer').Buffer;
  9404. /*<replacement>*/
  9405. var bufferShim = require('buffer-shims');
  9406. /*</replacement>*/
  9407. module.exports = BufferList;
  9408. function BufferList() {
  9409. this.head = null;
  9410. this.tail = null;
  9411. this.length = 0;
  9412. }
  9413. BufferList.prototype.push = function (v) {
  9414. var entry = { data: v, next: null };
  9415. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  9416. this.tail = entry;
  9417. ++this.length;
  9418. };
  9419. BufferList.prototype.unshift = function (v) {
  9420. var entry = { data: v, next: this.head };
  9421. if (this.length === 0) this.tail = entry;
  9422. this.head = entry;
  9423. ++this.length;
  9424. };
  9425. BufferList.prototype.shift = function () {
  9426. if (this.length === 0) return;
  9427. var ret = this.head.data;
  9428. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  9429. --this.length;
  9430. return ret;
  9431. };
  9432. BufferList.prototype.clear = function () {
  9433. this.head = this.tail = null;
  9434. this.length = 0;
  9435. };
  9436. BufferList.prototype.join = function (s) {
  9437. if (this.length === 0) return '';
  9438. var p = this.head;
  9439. var ret = '' + p.data;
  9440. while (p = p.next) {
  9441. ret += s + p.data;
  9442. }return ret;
  9443. };
  9444. BufferList.prototype.concat = function (n) {
  9445. if (this.length === 0) return bufferShim.alloc(0);
  9446. if (this.length === 1) return this.head.data;
  9447. var ret = bufferShim.allocUnsafe(n >>> 0);
  9448. var p = this.head;
  9449. var i = 0;
  9450. while (p) {
  9451. p.data.copy(ret, i);
  9452. i += p.data.length;
  9453. p = p.next;
  9454. }
  9455. return ret;
  9456. };
  9457. },{"buffer":6,"buffer-shims":5}],29:[function(require,module,exports){
  9458. module.exports = require("./lib/_stream_passthrough.js")
  9459. },{"./lib/_stream_passthrough.js":24}],30:[function(require,module,exports){
  9460. (function (process){
  9461. var Stream = (function (){
  9462. try {
  9463. return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify
  9464. } catch(_){}
  9465. }());
  9466. exports = module.exports = require('./lib/_stream_readable.js');
  9467. exports.Stream = Stream || exports;
  9468. exports.Readable = exports;
  9469. exports.Writable = require('./lib/_stream_writable.js');
  9470. exports.Duplex = require('./lib/_stream_duplex.js');
  9471. exports.Transform = require('./lib/_stream_transform.js');
  9472. exports.PassThrough = require('./lib/_stream_passthrough.js');
  9473. if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) {
  9474. module.exports = Stream;
  9475. }
  9476. }).call(this,require('_process'))
  9477. },{"./lib/_stream_duplex.js":23,"./lib/_stream_passthrough.js":24,"./lib/_stream_readable.js":25,"./lib/_stream_transform.js":26,"./lib/_stream_writable.js":27,"_process":21}],31:[function(require,module,exports){
  9478. module.exports = require("./lib/_stream_transform.js")
  9479. },{"./lib/_stream_transform.js":26}],32:[function(require,module,exports){
  9480. module.exports = require("./lib/_stream_writable.js")
  9481. },{"./lib/_stream_writable.js":27}],33:[function(require,module,exports){
  9482. (function (Buffer){
  9483. /*
  9484. CryptoJS v3.1.2
  9485. code.google.com/p/crypto-js
  9486. (c) 2009-2013 by Jeff Mott. All rights reserved.
  9487. code.google.com/p/crypto-js/wiki/License
  9488. */
  9489. /** @preserve
  9490. (c) 2012 by Cédric Mesnil. All rights reserved.
  9491. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  9492. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  9493. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  9494. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9495. */
  9496. // constants table
  9497. var zl = [
  9498. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  9499. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  9500. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  9501. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  9502. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
  9503. ]
  9504. var zr = [
  9505. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  9506. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  9507. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  9508. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  9509. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
  9510. ]
  9511. var sl = [
  9512. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  9513. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  9514. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  9515. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  9516. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
  9517. ]
  9518. var sr = [
  9519. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  9520. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  9521. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  9522. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  9523. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
  9524. ]
  9525. var hl = [0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]
  9526. var hr = [0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]
  9527. function bytesToWords (bytes) {
  9528. var words = []
  9529. for (var i = 0, b = 0; i < bytes.length; i++, b += 8) {
  9530. words[b >>> 5] |= bytes[i] << (24 - b % 32)
  9531. }
  9532. return words
  9533. }
  9534. function wordsToBytes (words) {
  9535. var bytes = []
  9536. for (var b = 0; b < words.length * 32; b += 8) {
  9537. bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF)
  9538. }
  9539. return bytes
  9540. }
  9541. function processBlock (H, M, offset) {
  9542. // swap endian
  9543. for (var i = 0; i < 16; i++) {
  9544. var offset_i = offset + i
  9545. var M_offset_i = M[offset_i]
  9546. // Swap
  9547. M[offset_i] = (
  9548. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  9549. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  9550. )
  9551. }
  9552. // Working variables
  9553. var al, bl, cl, dl, el
  9554. var ar, br, cr, dr, er
  9555. ar = al = H[0]
  9556. br = bl = H[1]
  9557. cr = cl = H[2]
  9558. dr = dl = H[3]
  9559. er = el = H[4]
  9560. // computation
  9561. var t
  9562. for (i = 0; i < 80; i += 1) {
  9563. t = (al + M[offset + zl[i]]) | 0
  9564. if (i < 16) {
  9565. t += f1(bl, cl, dl) + hl[0]
  9566. } else if (i < 32) {
  9567. t += f2(bl, cl, dl) + hl[1]
  9568. } else if (i < 48) {
  9569. t += f3(bl, cl, dl) + hl[2]
  9570. } else if (i < 64) {
  9571. t += f4(bl, cl, dl) + hl[3]
  9572. } else {// if (i<80) {
  9573. t += f5(bl, cl, dl) + hl[4]
  9574. }
  9575. t = t | 0
  9576. t = rotl(t, sl[i])
  9577. t = (t + el) | 0
  9578. al = el
  9579. el = dl
  9580. dl = rotl(cl, 10)
  9581. cl = bl
  9582. bl = t
  9583. t = (ar + M[offset + zr[i]]) | 0
  9584. if (i < 16) {
  9585. t += f5(br, cr, dr) + hr[0]
  9586. } else if (i < 32) {
  9587. t += f4(br, cr, dr) + hr[1]
  9588. } else if (i < 48) {
  9589. t += f3(br, cr, dr) + hr[2]
  9590. } else if (i < 64) {
  9591. t += f2(br, cr, dr) + hr[3]
  9592. } else {// if (i<80) {
  9593. t += f1(br, cr, dr) + hr[4]
  9594. }
  9595. t = t | 0
  9596. t = rotl(t, sr[i])
  9597. t = (t + er) | 0
  9598. ar = er
  9599. er = dr
  9600. dr = rotl(cr, 10)
  9601. cr = br
  9602. br = t
  9603. }
  9604. // intermediate hash value
  9605. t = (H[1] + cl + dr) | 0
  9606. H[1] = (H[2] + dl + er) | 0
  9607. H[2] = (H[3] + el + ar) | 0
  9608. H[3] = (H[4] + al + br) | 0
  9609. H[4] = (H[0] + bl + cr) | 0
  9610. H[0] = t
  9611. }
  9612. function f1 (x, y, z) {
  9613. return ((x) ^ (y) ^ (z))
  9614. }
  9615. function f2 (x, y, z) {
  9616. return (((x) & (y)) | ((~x) & (z)))
  9617. }
  9618. function f3 (x, y, z) {
  9619. return (((x) | (~(y))) ^ (z))
  9620. }
  9621. function f4 (x, y, z) {
  9622. return (((x) & (z)) | ((y) & (~(z))))
  9623. }
  9624. function f5 (x, y, z) {
  9625. return ((x) ^ ((y) | (~(z))))
  9626. }
  9627. function rotl (x, n) {
  9628. return (x << n) | (x >>> (32 - n))
  9629. }
  9630. function ripemd160 (message) {
  9631. var H = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
  9632. if (typeof message === 'string') {
  9633. message = new Buffer(message, 'utf8')
  9634. }
  9635. var m = bytesToWords(message)
  9636. var nBitsLeft = message.length * 8
  9637. var nBitsTotal = message.length * 8
  9638. // Add padding
  9639. m[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32)
  9640. m[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  9641. (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
  9642. (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
  9643. )
  9644. for (var i = 0; i < m.length; i += 16) {
  9645. processBlock(H, m, i)
  9646. }
  9647. // swap endian
  9648. for (i = 0; i < 5; i++) {
  9649. // shortcut
  9650. var H_i = H[i]
  9651. // Swap
  9652. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  9653. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00)
  9654. }
  9655. var digestbytes = wordsToBytes(H)
  9656. return new Buffer(digestbytes)
  9657. }
  9658. module.exports = ripemd160
  9659. }).call(this,require("buffer").Buffer)
  9660. },{"buffer":6}],34:[function(require,module,exports){
  9661. (function (Buffer){
  9662. // prototype class for hash functions
  9663. function Hash (blockSize, finalSize) {
  9664. this._block = new Buffer(blockSize)
  9665. this._finalSize = finalSize
  9666. this._blockSize = blockSize
  9667. this._len = 0
  9668. this._s = 0
  9669. }
  9670. Hash.prototype.update = function (data, enc) {
  9671. if (typeof data === 'string') {
  9672. enc = enc || 'utf8'
  9673. data = new Buffer(data, enc)
  9674. }
  9675. var l = this._len += data.length
  9676. var s = this._s || 0
  9677. var f = 0
  9678. var buffer = this._block
  9679. while (s < l) {
  9680. var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize))
  9681. var ch = (t - f)
  9682. for (var i = 0; i < ch; i++) {
  9683. buffer[(s % this._blockSize) + i] = data[i + f]
  9684. }
  9685. s += ch
  9686. f += ch
  9687. if ((s % this._blockSize) === 0) {
  9688. this._update(buffer)
  9689. }
  9690. }
  9691. this._s = s
  9692. return this
  9693. }
  9694. Hash.prototype.digest = function (enc) {
  9695. // Suppose the length of the message M, in bits, is l
  9696. var l = this._len * 8
  9697. // Append the bit 1 to the end of the message
  9698. this._block[this._len % this._blockSize] = 0x80
  9699. // and then k zero bits, where k is the smallest non-negative solution to the equation (l + 1 + k) === finalSize mod blockSize
  9700. this._block.fill(0, this._len % this._blockSize + 1)
  9701. if (l % (this._blockSize * 8) >= this._finalSize * 8) {
  9702. this._update(this._block)
  9703. this._block.fill(0)
  9704. }
  9705. // to this append the block which is equal to the number l written in binary
  9706. // TODO: handle case where l is > Math.pow(2, 29)
  9707. this._block.writeInt32BE(l, this._blockSize - 4)
  9708. var hash = this._update(this._block) || this._hash()
  9709. return enc ? hash.toString(enc) : hash
  9710. }
  9711. Hash.prototype._update = function () {
  9712. throw new Error('_update must be implemented by subclass')
  9713. }
  9714. module.exports = Hash
  9715. }).call(this,require("buffer").Buffer)
  9716. },{"buffer":6}],35:[function(require,module,exports){
  9717. var exports = module.exports = function SHA (algorithm) {
  9718. algorithm = algorithm.toLowerCase()
  9719. var Algorithm = exports[algorithm]
  9720. if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
  9721. return new Algorithm()
  9722. }
  9723. exports.sha = require('./sha')
  9724. exports.sha1 = require('./sha1')
  9725. exports.sha224 = require('./sha224')
  9726. exports.sha256 = require('./sha256')
  9727. exports.sha384 = require('./sha384')
  9728. exports.sha512 = require('./sha512')
  9729. },{"./sha":36,"./sha1":37,"./sha224":38,"./sha256":39,"./sha384":40,"./sha512":41}],36:[function(require,module,exports){
  9730. (function (Buffer){
  9731. /*
  9732. * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
  9733. * in FIPS PUB 180-1
  9734. * This source code is derived from sha1.js of the same repository.
  9735. * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
  9736. * operation was added.
  9737. */
  9738. var inherits = require('inherits')
  9739. var Hash = require('./hash')
  9740. var K = [
  9741. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  9742. ]
  9743. var W = new Array(80)
  9744. function Sha () {
  9745. this.init()
  9746. this._w = W
  9747. Hash.call(this, 64, 56)
  9748. }
  9749. inherits(Sha, Hash)
  9750. Sha.prototype.init = function () {
  9751. this._a = 0x67452301
  9752. this._b = 0xefcdab89
  9753. this._c = 0x98badcfe
  9754. this._d = 0x10325476
  9755. this._e = 0xc3d2e1f0
  9756. return this
  9757. }
  9758. function rotl5 (num) {
  9759. return (num << 5) | (num >>> 27)
  9760. }
  9761. function rotl30 (num) {
  9762. return (num << 30) | (num >>> 2)
  9763. }
  9764. function ft (s, b, c, d) {
  9765. if (s === 0) return (b & c) | ((~b) & d)
  9766. if (s === 2) return (b & c) | (b & d) | (c & d)
  9767. return b ^ c ^ d
  9768. }
  9769. Sha.prototype._update = function (M) {
  9770. var W = this._w
  9771. var a = this._a | 0
  9772. var b = this._b | 0
  9773. var c = this._c | 0
  9774. var d = this._d | 0
  9775. var e = this._e | 0
  9776. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  9777. for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
  9778. for (var j = 0; j < 80; ++j) {
  9779. var s = ~~(j / 20)
  9780. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  9781. e = d
  9782. d = c
  9783. c = rotl30(b)
  9784. b = a
  9785. a = t
  9786. }
  9787. this._a = (a + this._a) | 0
  9788. this._b = (b + this._b) | 0
  9789. this._c = (c + this._c) | 0
  9790. this._d = (d + this._d) | 0
  9791. this._e = (e + this._e) | 0
  9792. }
  9793. Sha.prototype._hash = function () {
  9794. var H = new Buffer(20)
  9795. H.writeInt32BE(this._a | 0, 0)
  9796. H.writeInt32BE(this._b | 0, 4)
  9797. H.writeInt32BE(this._c | 0, 8)
  9798. H.writeInt32BE(this._d | 0, 12)
  9799. H.writeInt32BE(this._e | 0, 16)
  9800. return H
  9801. }
  9802. module.exports = Sha
  9803. }).call(this,require("buffer").Buffer)
  9804. },{"./hash":34,"buffer":6,"inherits":15}],37:[function(require,module,exports){
  9805. (function (Buffer){
  9806. /*
  9807. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  9808. * in FIPS PUB 180-1
  9809. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  9810. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  9811. * Distributed under the BSD License
  9812. * See http://pajhome.org.uk/crypt/md5 for details.
  9813. */
  9814. var inherits = require('inherits')
  9815. var Hash = require('./hash')
  9816. var K = [
  9817. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  9818. ]
  9819. var W = new Array(80)
  9820. function Sha1 () {
  9821. this.init()
  9822. this._w = W
  9823. Hash.call(this, 64, 56)
  9824. }
  9825. inherits(Sha1, Hash)
  9826. Sha1.prototype.init = function () {
  9827. this._a = 0x67452301
  9828. this._b = 0xefcdab89
  9829. this._c = 0x98badcfe
  9830. this._d = 0x10325476
  9831. this._e = 0xc3d2e1f0
  9832. return this
  9833. }
  9834. function rotl1 (num) {
  9835. return (num << 1) | (num >>> 31)
  9836. }
  9837. function rotl5 (num) {
  9838. return (num << 5) | (num >>> 27)
  9839. }
  9840. function rotl30 (num) {
  9841. return (num << 30) | (num >>> 2)
  9842. }
  9843. function ft (s, b, c, d) {
  9844. if (s === 0) return (b & c) | ((~b) & d)
  9845. if (s === 2) return (b & c) | (b & d) | (c & d)
  9846. return b ^ c ^ d
  9847. }
  9848. Sha1.prototype._update = function (M) {
  9849. var W = this._w
  9850. var a = this._a | 0
  9851. var b = this._b | 0
  9852. var c = this._c | 0
  9853. var d = this._d | 0
  9854. var e = this._e | 0
  9855. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  9856. for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
  9857. for (var j = 0; j < 80; ++j) {
  9858. var s = ~~(j / 20)
  9859. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  9860. e = d
  9861. d = c
  9862. c = rotl30(b)
  9863. b = a
  9864. a = t
  9865. }
  9866. this._a = (a + this._a) | 0
  9867. this._b = (b + this._b) | 0
  9868. this._c = (c + this._c) | 0
  9869. this._d = (d + this._d) | 0
  9870. this._e = (e + this._e) | 0
  9871. }
  9872. Sha1.prototype._hash = function () {
  9873. var H = new Buffer(20)
  9874. H.writeInt32BE(this._a | 0, 0)
  9875. H.writeInt32BE(this._b | 0, 4)
  9876. H.writeInt32BE(this._c | 0, 8)
  9877. H.writeInt32BE(this._d | 0, 12)
  9878. H.writeInt32BE(this._e | 0, 16)
  9879. return H
  9880. }
  9881. module.exports = Sha1
  9882. }).call(this,require("buffer").Buffer)
  9883. },{"./hash":34,"buffer":6,"inherits":15}],38:[function(require,module,exports){
  9884. (function (Buffer){
  9885. /**
  9886. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  9887. * in FIPS 180-2
  9888. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  9889. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  9890. *
  9891. */
  9892. var inherits = require('inherits')
  9893. var Sha256 = require('./sha256')
  9894. var Hash = require('./hash')
  9895. var W = new Array(64)
  9896. function Sha224 () {
  9897. this.init()
  9898. this._w = W // new Array(64)
  9899. Hash.call(this, 64, 56)
  9900. }
  9901. inherits(Sha224, Sha256)
  9902. Sha224.prototype.init = function () {
  9903. this._a = 0xc1059ed8
  9904. this._b = 0x367cd507
  9905. this._c = 0x3070dd17
  9906. this._d = 0xf70e5939
  9907. this._e = 0xffc00b31
  9908. this._f = 0x68581511
  9909. this._g = 0x64f98fa7
  9910. this._h = 0xbefa4fa4
  9911. return this
  9912. }
  9913. Sha224.prototype._hash = function () {
  9914. var H = new Buffer(28)
  9915. H.writeInt32BE(this._a, 0)
  9916. H.writeInt32BE(this._b, 4)
  9917. H.writeInt32BE(this._c, 8)
  9918. H.writeInt32BE(this._d, 12)
  9919. H.writeInt32BE(this._e, 16)
  9920. H.writeInt32BE(this._f, 20)
  9921. H.writeInt32BE(this._g, 24)
  9922. return H
  9923. }
  9924. module.exports = Sha224
  9925. }).call(this,require("buffer").Buffer)
  9926. },{"./hash":34,"./sha256":39,"buffer":6,"inherits":15}],39:[function(require,module,exports){
  9927. (function (Buffer){
  9928. /**
  9929. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  9930. * in FIPS 180-2
  9931. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  9932. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  9933. *
  9934. */
  9935. var inherits = require('inherits')
  9936. var Hash = require('./hash')
  9937. var K = [
  9938. 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
  9939. 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
  9940. 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
  9941. 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
  9942. 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
  9943. 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
  9944. 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
  9945. 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
  9946. 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
  9947. 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
  9948. 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
  9949. 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
  9950. 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
  9951. 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
  9952. 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
  9953. 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
  9954. ]
  9955. var W = new Array(64)
  9956. function Sha256 () {
  9957. this.init()
  9958. this._w = W // new Array(64)
  9959. Hash.call(this, 64, 56)
  9960. }
  9961. inherits(Sha256, Hash)
  9962. Sha256.prototype.init = function () {
  9963. this._a = 0x6a09e667
  9964. this._b = 0xbb67ae85
  9965. this._c = 0x3c6ef372
  9966. this._d = 0xa54ff53a
  9967. this._e = 0x510e527f
  9968. this._f = 0x9b05688c
  9969. this._g = 0x1f83d9ab
  9970. this._h = 0x5be0cd19
  9971. return this
  9972. }
  9973. function ch (x, y, z) {
  9974. return z ^ (x & (y ^ z))
  9975. }
  9976. function maj (x, y, z) {
  9977. return (x & y) | (z & (x | y))
  9978. }
  9979. function sigma0 (x) {
  9980. return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
  9981. }
  9982. function sigma1 (x) {
  9983. return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
  9984. }
  9985. function gamma0 (x) {
  9986. return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
  9987. }
  9988. function gamma1 (x) {
  9989. return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
  9990. }
  9991. Sha256.prototype._update = function (M) {
  9992. var W = this._w
  9993. var a = this._a | 0
  9994. var b = this._b | 0
  9995. var c = this._c | 0
  9996. var d = this._d | 0
  9997. var e = this._e | 0
  9998. var f = this._f | 0
  9999. var g = this._g | 0
  10000. var h = this._h | 0
  10001. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  10002. for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
  10003. for (var j = 0; j < 64; ++j) {
  10004. var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
  10005. var T2 = (sigma0(a) + maj(a, b, c)) | 0
  10006. h = g
  10007. g = f
  10008. f = e
  10009. e = (d + T1) | 0
  10010. d = c
  10011. c = b
  10012. b = a
  10013. a = (T1 + T2) | 0
  10014. }
  10015. this._a = (a + this._a) | 0
  10016. this._b = (b + this._b) | 0
  10017. this._c = (c + this._c) | 0
  10018. this._d = (d + this._d) | 0
  10019. this._e = (e + this._e) | 0
  10020. this._f = (f + this._f) | 0
  10021. this._g = (g + this._g) | 0
  10022. this._h = (h + this._h) | 0
  10023. }
  10024. Sha256.prototype._hash = function () {
  10025. var H = new Buffer(32)
  10026. H.writeInt32BE(this._a, 0)
  10027. H.writeInt32BE(this._b, 4)
  10028. H.writeInt32BE(this._c, 8)
  10029. H.writeInt32BE(this._d, 12)
  10030. H.writeInt32BE(this._e, 16)
  10031. H.writeInt32BE(this._f, 20)
  10032. H.writeInt32BE(this._g, 24)
  10033. H.writeInt32BE(this._h, 28)
  10034. return H
  10035. }
  10036. module.exports = Sha256
  10037. }).call(this,require("buffer").Buffer)
  10038. },{"./hash":34,"buffer":6,"inherits":15}],40:[function(require,module,exports){
  10039. (function (Buffer){
  10040. var inherits = require('inherits')
  10041. var SHA512 = require('./sha512')
  10042. var Hash = require('./hash')
  10043. var W = new Array(160)
  10044. function Sha384 () {
  10045. this.init()
  10046. this._w = W
  10047. Hash.call(this, 128, 112)
  10048. }
  10049. inherits(Sha384, SHA512)
  10050. Sha384.prototype.init = function () {
  10051. this._ah = 0xcbbb9d5d
  10052. this._bh = 0x629a292a
  10053. this._ch = 0x9159015a
  10054. this._dh = 0x152fecd8
  10055. this._eh = 0x67332667
  10056. this._fh = 0x8eb44a87
  10057. this._gh = 0xdb0c2e0d
  10058. this._hh = 0x47b5481d
  10059. this._al = 0xc1059ed8
  10060. this._bl = 0x367cd507
  10061. this._cl = 0x3070dd17
  10062. this._dl = 0xf70e5939
  10063. this._el = 0xffc00b31
  10064. this._fl = 0x68581511
  10065. this._gl = 0x64f98fa7
  10066. this._hl = 0xbefa4fa4
  10067. return this
  10068. }
  10069. Sha384.prototype._hash = function () {
  10070. var H = new Buffer(48)
  10071. function writeInt64BE (h, l, offset) {
  10072. H.writeInt32BE(h, offset)
  10073. H.writeInt32BE(l, offset + 4)
  10074. }
  10075. writeInt64BE(this._ah, this._al, 0)
  10076. writeInt64BE(this._bh, this._bl, 8)
  10077. writeInt64BE(this._ch, this._cl, 16)
  10078. writeInt64BE(this._dh, this._dl, 24)
  10079. writeInt64BE(this._eh, this._el, 32)
  10080. writeInt64BE(this._fh, this._fl, 40)
  10081. return H
  10082. }
  10083. module.exports = Sha384
  10084. }).call(this,require("buffer").Buffer)
  10085. },{"./hash":34,"./sha512":41,"buffer":6,"inherits":15}],41:[function(require,module,exports){
  10086. (function (Buffer){
  10087. var inherits = require('inherits')
  10088. var Hash = require('./hash')
  10089. var K = [
  10090. 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
  10091. 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
  10092. 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
  10093. 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
  10094. 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
  10095. 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
  10096. 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
  10097. 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
  10098. 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
  10099. 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
  10100. 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
  10101. 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
  10102. 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
  10103. 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
  10104. 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
  10105. 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
  10106. 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
  10107. 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
  10108. 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
  10109. 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
  10110. 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
  10111. 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
  10112. 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
  10113. 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
  10114. 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
  10115. 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
  10116. 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
  10117. 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
  10118. 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
  10119. 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
  10120. 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
  10121. 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
  10122. 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
  10123. 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
  10124. 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
  10125. 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
  10126. 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
  10127. 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
  10128. 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
  10129. 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
  10130. ]
  10131. var W = new Array(160)
  10132. function Sha512 () {
  10133. this.init()
  10134. this._w = W
  10135. Hash.call(this, 128, 112)
  10136. }
  10137. inherits(Sha512, Hash)
  10138. Sha512.prototype.init = function () {
  10139. this._ah = 0x6a09e667
  10140. this._bh = 0xbb67ae85
  10141. this._ch = 0x3c6ef372
  10142. this._dh = 0xa54ff53a
  10143. this._eh = 0x510e527f
  10144. this._fh = 0x9b05688c
  10145. this._gh = 0x1f83d9ab
  10146. this._hh = 0x5be0cd19
  10147. this._al = 0xf3bcc908
  10148. this._bl = 0x84caa73b
  10149. this._cl = 0xfe94f82b
  10150. this._dl = 0x5f1d36f1
  10151. this._el = 0xade682d1
  10152. this._fl = 0x2b3e6c1f
  10153. this._gl = 0xfb41bd6b
  10154. this._hl = 0x137e2179
  10155. return this
  10156. }
  10157. function Ch (x, y, z) {
  10158. return z ^ (x & (y ^ z))
  10159. }
  10160. function maj (x, y, z) {
  10161. return (x & y) | (z & (x | y))
  10162. }
  10163. function sigma0 (x, xl) {
  10164. return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
  10165. }
  10166. function sigma1 (x, xl) {
  10167. return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
  10168. }
  10169. function Gamma0 (x, xl) {
  10170. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
  10171. }
  10172. function Gamma0l (x, xl) {
  10173. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
  10174. }
  10175. function Gamma1 (x, xl) {
  10176. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
  10177. }
  10178. function Gamma1l (x, xl) {
  10179. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
  10180. }
  10181. function getCarry (a, b) {
  10182. return (a >>> 0) < (b >>> 0) ? 1 : 0
  10183. }
  10184. Sha512.prototype._update = function (M) {
  10185. var W = this._w
  10186. var ah = this._ah | 0
  10187. var bh = this._bh | 0
  10188. var ch = this._ch | 0
  10189. var dh = this._dh | 0
  10190. var eh = this._eh | 0
  10191. var fh = this._fh | 0
  10192. var gh = this._gh | 0
  10193. var hh = this._hh | 0
  10194. var al = this._al | 0
  10195. var bl = this._bl | 0
  10196. var cl = this._cl | 0
  10197. var dl = this._dl | 0
  10198. var el = this._el | 0
  10199. var fl = this._fl | 0
  10200. var gl = this._gl | 0
  10201. var hl = this._hl | 0
  10202. for (var i = 0; i < 32; i += 2) {
  10203. W[i] = M.readInt32BE(i * 4)
  10204. W[i + 1] = M.readInt32BE(i * 4 + 4)
  10205. }
  10206. for (; i < 160; i += 2) {
  10207. var xh = W[i - 15 * 2]
  10208. var xl = W[i - 15 * 2 + 1]
  10209. var gamma0 = Gamma0(xh, xl)
  10210. var gamma0l = Gamma0l(xl, xh)
  10211. xh = W[i - 2 * 2]
  10212. xl = W[i - 2 * 2 + 1]
  10213. var gamma1 = Gamma1(xh, xl)
  10214. var gamma1l = Gamma1l(xl, xh)
  10215. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  10216. var Wi7h = W[i - 7 * 2]
  10217. var Wi7l = W[i - 7 * 2 + 1]
  10218. var Wi16h = W[i - 16 * 2]
  10219. var Wi16l = W[i - 16 * 2 + 1]
  10220. var Wil = (gamma0l + Wi7l) | 0
  10221. var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
  10222. Wil = (Wil + gamma1l) | 0
  10223. Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
  10224. Wil = (Wil + Wi16l) | 0
  10225. Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
  10226. W[i] = Wih
  10227. W[i + 1] = Wil
  10228. }
  10229. for (var j = 0; j < 160; j += 2) {
  10230. Wih = W[j]
  10231. Wil = W[j + 1]
  10232. var majh = maj(ah, bh, ch)
  10233. var majl = maj(al, bl, cl)
  10234. var sigma0h = sigma0(ah, al)
  10235. var sigma0l = sigma0(al, ah)
  10236. var sigma1h = sigma1(eh, el)
  10237. var sigma1l = sigma1(el, eh)
  10238. // t1 = h + sigma1 + ch + K[j] + W[j]
  10239. var Kih = K[j]
  10240. var Kil = K[j + 1]
  10241. var chh = Ch(eh, fh, gh)
  10242. var chl = Ch(el, fl, gl)
  10243. var t1l = (hl + sigma1l) | 0
  10244. var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
  10245. t1l = (t1l + chl) | 0
  10246. t1h = (t1h + chh + getCarry(t1l, chl)) | 0
  10247. t1l = (t1l + Kil) | 0
  10248. t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
  10249. t1l = (t1l + Wil) | 0
  10250. t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
  10251. // t2 = sigma0 + maj
  10252. var t2l = (sigma0l + majl) | 0
  10253. var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
  10254. hh = gh
  10255. hl = gl
  10256. gh = fh
  10257. gl = fl
  10258. fh = eh
  10259. fl = el
  10260. el = (dl + t1l) | 0
  10261. eh = (dh + t1h + getCarry(el, dl)) | 0
  10262. dh = ch
  10263. dl = cl
  10264. ch = bh
  10265. cl = bl
  10266. bh = ah
  10267. bl = al
  10268. al = (t1l + t2l) | 0
  10269. ah = (t1h + t2h + getCarry(al, t1l)) | 0
  10270. }
  10271. this._al = (this._al + al) | 0
  10272. this._bl = (this._bl + bl) | 0
  10273. this._cl = (this._cl + cl) | 0
  10274. this._dl = (this._dl + dl) | 0
  10275. this._el = (this._el + el) | 0
  10276. this._fl = (this._fl + fl) | 0
  10277. this._gl = (this._gl + gl) | 0
  10278. this._hl = (this._hl + hl) | 0
  10279. this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
  10280. this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
  10281. this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
  10282. this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
  10283. this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
  10284. this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
  10285. this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
  10286. this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
  10287. }
  10288. Sha512.prototype._hash = function () {
  10289. var H = new Buffer(64)
  10290. function writeInt64BE (h, l, offset) {
  10291. H.writeInt32BE(h, offset)
  10292. H.writeInt32BE(l, offset + 4)
  10293. }
  10294. writeInt64BE(this._ah, this._al, 0)
  10295. writeInt64BE(this._bh, this._bl, 8)
  10296. writeInt64BE(this._ch, this._cl, 16)
  10297. writeInt64BE(this._dh, this._dl, 24)
  10298. writeInt64BE(this._eh, this._el, 32)
  10299. writeInt64BE(this._fh, this._fl, 40)
  10300. writeInt64BE(this._gh, this._gl, 48)
  10301. writeInt64BE(this._hh, this._hl, 56)
  10302. return H
  10303. }
  10304. module.exports = Sha512
  10305. }).call(this,require("buffer").Buffer)
  10306. },{"./hash":34,"buffer":6,"inherits":15}],42:[function(require,module,exports){
  10307. // Copyright Joyent, Inc. and other Node contributors.
  10308. //
  10309. // Permission is hereby granted, free of charge, to any person obtaining a
  10310. // copy of this software and associated documentation files (the
  10311. // "Software"), to deal in the Software without restriction, including
  10312. // without limitation the rights to use, copy, modify, merge, publish,
  10313. // distribute, sublicense, and/or sell copies of the Software, and to permit
  10314. // persons to whom the Software is furnished to do so, subject to the
  10315. // following conditions:
  10316. //
  10317. // The above copyright notice and this permission notice shall be included
  10318. // in all copies or substantial portions of the Software.
  10319. //
  10320. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  10321. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10322. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  10323. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  10324. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  10325. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  10326. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  10327. module.exports = Stream;
  10328. var EE = require('events').EventEmitter;
  10329. var inherits = require('inherits');
  10330. inherits(Stream, EE);
  10331. Stream.Readable = require('readable-stream/readable.js');
  10332. Stream.Writable = require('readable-stream/writable.js');
  10333. Stream.Duplex = require('readable-stream/duplex.js');
  10334. Stream.Transform = require('readable-stream/transform.js');
  10335. Stream.PassThrough = require('readable-stream/passthrough.js');
  10336. // Backwards-compat with node 0.4.x
  10337. Stream.Stream = Stream;
  10338. // old-style streams. Note that the pipe method (the only relevant
  10339. // part of this class) is overridden in the Readable class.
  10340. function Stream() {
  10341. EE.call(this);
  10342. }
  10343. Stream.prototype.pipe = function(dest, options) {
  10344. var source = this;
  10345. function ondata(chunk) {
  10346. if (dest.writable) {
  10347. if (false === dest.write(chunk) && source.pause) {
  10348. source.pause();
  10349. }
  10350. }
  10351. }
  10352. source.on('data', ondata);
  10353. function ondrain() {
  10354. if (source.readable && source.resume) {
  10355. source.resume();
  10356. }
  10357. }
  10358. dest.on('drain', ondrain);
  10359. // If the 'end' option is not supplied, dest.end() will be called when
  10360. // source gets the 'end' or 'close' events. Only dest.end() once.
  10361. if (!dest._isStdio && (!options || options.end !== false)) {
  10362. source.on('end', onend);
  10363. source.on('close', onclose);
  10364. }
  10365. var didOnEnd = false;
  10366. function onend() {
  10367. if (didOnEnd) return;
  10368. didOnEnd = true;
  10369. dest.end();
  10370. }
  10371. function onclose() {
  10372. if (didOnEnd) return;
  10373. didOnEnd = true;
  10374. if (typeof dest.destroy === 'function') dest.destroy();
  10375. }
  10376. // don't leave dangling pipes when there are errors.
  10377. function onerror(er) {
  10378. cleanup();
  10379. if (EE.listenerCount(this, 'error') === 0) {
  10380. throw er; // Unhandled stream error in pipe.
  10381. }
  10382. }
  10383. source.on('error', onerror);
  10384. dest.on('error', onerror);
  10385. // remove all the event listeners that were added.
  10386. function cleanup() {
  10387. source.removeListener('data', ondata);
  10388. dest.removeListener('drain', ondrain);
  10389. source.removeListener('end', onend);
  10390. source.removeListener('close', onclose);
  10391. source.removeListener('error', onerror);
  10392. dest.removeListener('error', onerror);
  10393. source.removeListener('end', cleanup);
  10394. source.removeListener('close', cleanup);
  10395. dest.removeListener('close', cleanup);
  10396. }
  10397. source.on('end', cleanup);
  10398. source.on('close', cleanup);
  10399. dest.on('close', cleanup);
  10400. dest.emit('pipe', source);
  10401. // Allow for unix-like usage: A.pipe(B).pipe(C)
  10402. return dest;
  10403. };
  10404. },{"events":13,"inherits":15,"readable-stream/duplex.js":22,"readable-stream/passthrough.js":29,"readable-stream/readable.js":30,"readable-stream/transform.js":31,"readable-stream/writable.js":32}],43:[function(require,module,exports){
  10405. // Copyright Joyent, Inc. and other Node contributors.
  10406. //
  10407. // Permission is hereby granted, free of charge, to any person obtaining a
  10408. // copy of this software and associated documentation files (the
  10409. // "Software"), to deal in the Software without restriction, including
  10410. // without limitation the rights to use, copy, modify, merge, publish,
  10411. // distribute, sublicense, and/or sell copies of the Software, and to permit
  10412. // persons to whom the Software is furnished to do so, subject to the
  10413. // following conditions:
  10414. //
  10415. // The above copyright notice and this permission notice shall be included
  10416. // in all copies or substantial portions of the Software.
  10417. //
  10418. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  10419. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10420. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  10421. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  10422. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  10423. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  10424. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  10425. var Buffer = require('buffer').Buffer;
  10426. var isBufferEncoding = Buffer.isEncoding
  10427. || function(encoding) {
  10428. switch (encoding && encoding.toLowerCase()) {
  10429. case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true;
  10430. default: return false;
  10431. }
  10432. }
  10433. function assertEncoding(encoding) {
  10434. if (encoding && !isBufferEncoding(encoding)) {
  10435. throw new Error('Unknown encoding: ' + encoding);
  10436. }
  10437. }
  10438. // StringDecoder provides an interface for efficiently splitting a series of
  10439. // buffers into a series of JS strings without breaking apart multi-byte
  10440. // characters. CESU-8 is handled as part of the UTF-8 encoding.
  10441. //
  10442. // @TODO Handling all encodings inside a single object makes it very difficult
  10443. // to reason about this code, so it should be split up in the future.
  10444. // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
  10445. // points as used by CESU-8.
  10446. var StringDecoder = exports.StringDecoder = function(encoding) {
  10447. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  10448. assertEncoding(encoding);
  10449. switch (this.encoding) {
  10450. case 'utf8':
  10451. // CESU-8 represents each of Surrogate Pair by 3-bytes
  10452. this.surrogateSize = 3;
  10453. break;
  10454. case 'ucs2':
  10455. case 'utf16le':
  10456. // UTF-16 represents each of Surrogate Pair by 2-bytes
  10457. this.surrogateSize = 2;
  10458. this.detectIncompleteChar = utf16DetectIncompleteChar;
  10459. break;
  10460. case 'base64':
  10461. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  10462. this.surrogateSize = 3;
  10463. this.detectIncompleteChar = base64DetectIncompleteChar;
  10464. break;
  10465. default:
  10466. this.write = passThroughWrite;
  10467. return;
  10468. }
  10469. // Enough space to store all bytes of a single character. UTF-8 needs 4
  10470. // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
  10471. this.charBuffer = new Buffer(6);
  10472. // Number of bytes received for the current incomplete multi-byte character.
  10473. this.charReceived = 0;
  10474. // Number of bytes expected for the current incomplete multi-byte character.
  10475. this.charLength = 0;
  10476. };
  10477. // write decodes the given buffer and returns it as JS string that is
  10478. // guaranteed to not contain any partial multi-byte characters. Any partial
  10479. // character found at the end of the buffer is buffered up, and will be
  10480. // returned when calling write again with the remaining bytes.
  10481. //
  10482. // Note: Converting a Buffer containing an orphan surrogate to a String
  10483. // currently works, but converting a String to a Buffer (via `new Buffer`, or
  10484. // Buffer#write) will replace incomplete surrogates with the unicode
  10485. // replacement character. See https://codereview.chromium.org/121173009/ .
  10486. StringDecoder.prototype.write = function(buffer) {
  10487. var charStr = '';
  10488. // if our last write ended with an incomplete multibyte character
  10489. while (this.charLength) {
  10490. // determine how many remaining bytes this buffer has to offer for this char
  10491. var available = (buffer.length >= this.charLength - this.charReceived) ?
  10492. this.charLength - this.charReceived :
  10493. buffer.length;
  10494. // add the new bytes to the char buffer
  10495. buffer.copy(this.charBuffer, this.charReceived, 0, available);
  10496. this.charReceived += available;
  10497. if (this.charReceived < this.charLength) {
  10498. // still not enough chars in this buffer? wait for more ...
  10499. return '';
  10500. }
  10501. // remove bytes belonging to the current character from the buffer
  10502. buffer = buffer.slice(available, buffer.length);
  10503. // get the character that was split
  10504. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  10505. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  10506. var charCode = charStr.charCodeAt(charStr.length - 1);
  10507. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  10508. this.charLength += this.surrogateSize;
  10509. charStr = '';
  10510. continue;
  10511. }
  10512. this.charReceived = this.charLength = 0;
  10513. // if there are no more bytes in this buffer, just emit our char
  10514. if (buffer.length === 0) {
  10515. return charStr;
  10516. }
  10517. break;
  10518. }
  10519. // determine and set charLength / charReceived
  10520. this.detectIncompleteChar(buffer);
  10521. var end = buffer.length;
  10522. if (this.charLength) {
  10523. // buffer the incomplete character bytes we got
  10524. buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
  10525. end -= this.charReceived;
  10526. }
  10527. charStr += buffer.toString(this.encoding, 0, end);
  10528. var end = charStr.length - 1;
  10529. var charCode = charStr.charCodeAt(end);
  10530. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  10531. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  10532. var size = this.surrogateSize;
  10533. this.charLength += size;
  10534. this.charReceived += size;
  10535. this.charBuffer.copy(this.charBuffer, size, 0, size);
  10536. buffer.copy(this.charBuffer, 0, 0, size);
  10537. return charStr.substring(0, end);
  10538. }
  10539. // or just emit the charStr
  10540. return charStr;
  10541. };
  10542. // detectIncompleteChar determines if there is an incomplete UTF-8 character at
  10543. // the end of the given buffer. If so, it sets this.charLength to the byte
  10544. // length that character, and sets this.charReceived to the number of bytes
  10545. // that are available for this character.
  10546. StringDecoder.prototype.detectIncompleteChar = function(buffer) {
  10547. // determine how many bytes we have to check at the end of this buffer
  10548. var i = (buffer.length >= 3) ? 3 : buffer.length;
  10549. // Figure out if one of the last i bytes of our buffer announces an
  10550. // incomplete char.
  10551. for (; i > 0; i--) {
  10552. var c = buffer[buffer.length - i];
  10553. // See http://en.wikipedia.org/wiki/UTF-8#Description
  10554. // 110XXXXX
  10555. if (i == 1 && c >> 5 == 0x06) {
  10556. this.charLength = 2;
  10557. break;
  10558. }
  10559. // 1110XXXX
  10560. if (i <= 2 && c >> 4 == 0x0E) {
  10561. this.charLength = 3;
  10562. break;
  10563. }
  10564. // 11110XXX
  10565. if (i <= 3 && c >> 3 == 0x1E) {
  10566. this.charLength = 4;
  10567. break;
  10568. }
  10569. }
  10570. this.charReceived = i;
  10571. };
  10572. StringDecoder.prototype.end = function(buffer) {
  10573. var res = '';
  10574. if (buffer && buffer.length)
  10575. res = this.write(buffer);
  10576. if (this.charReceived) {
  10577. var cr = this.charReceived;
  10578. var buf = this.charBuffer;
  10579. var enc = this.encoding;
  10580. res += buf.slice(0, cr).toString(enc);
  10581. }
  10582. return res;
  10583. };
  10584. function passThroughWrite(buffer) {
  10585. return buffer.toString(this.encoding);
  10586. }
  10587. function utf16DetectIncompleteChar(buffer) {
  10588. this.charReceived = buffer.length % 2;
  10589. this.charLength = this.charReceived ? 2 : 0;
  10590. }
  10591. function base64DetectIncompleteChar(buffer) {
  10592. this.charReceived = buffer.length % 3;
  10593. this.charLength = this.charReceived ? 3 : 0;
  10594. }
  10595. },{"buffer":6}],44:[function(require,module,exports){
  10596. (function (global){
  10597. /**
  10598. * Module exports.
  10599. */
  10600. module.exports = deprecate;
  10601. /**
  10602. * Mark that a method should not be used.
  10603. * Returns a modified function which warns once by default.
  10604. *
  10605. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  10606. *
  10607. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  10608. * will throw an Error when invoked.
  10609. *
  10610. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  10611. * will invoke `console.trace()` instead of `console.error()`.
  10612. *
  10613. * @param {Function} fn - the function to deprecate
  10614. * @param {String} msg - the string to print to the console when `fn` is invoked
  10615. * @returns {Function} a new "deprecated" version of `fn`
  10616. * @api public
  10617. */
  10618. function deprecate (fn, msg) {
  10619. if (config('noDeprecation')) {
  10620. return fn;
  10621. }
  10622. var warned = false;
  10623. function deprecated() {
  10624. if (!warned) {
  10625. if (config('throwDeprecation')) {
  10626. throw new Error(msg);
  10627. } else if (config('traceDeprecation')) {
  10628. console.trace(msg);
  10629. } else {
  10630. console.warn(msg);
  10631. }
  10632. warned = true;
  10633. }
  10634. return fn.apply(this, arguments);
  10635. }
  10636. return deprecated;
  10637. }
  10638. /**
  10639. * Checks `localStorage` for boolean values for the given `name`.
  10640. *
  10641. * @param {String} name
  10642. * @returns {Boolean}
  10643. * @api private
  10644. */
  10645. function config (name) {
  10646. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  10647. try {
  10648. if (!global.localStorage) return false;
  10649. } catch (_) {
  10650. return false;
  10651. }
  10652. var val = global.localStorage[name];
  10653. if (null == val) return false;
  10654. return String(val).toLowerCase() === 'true';
  10655. }
  10656. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  10657. },{}]},{},[1])(1)
  10658. });