Geen omschrijving

browserify.js 373KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727
  1. (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. require('./test-adapter.js');
  3. require('./scheduler-test.js');
  4. require('./extension-test.js');
  5. require('promises-aplus-tests-phantom/lib/testFiles');
  6. },{"./extension-test.js":52,"./scheduler-test.js":53,"./test-adapter.js":54,"promises-aplus-tests-phantom/lib/testFiles":7}],2:[function(require,module,exports){
  7. // http://wiki.commonjs.org/wiki/Unit_Testing/1.0
  8. //
  9. // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
  10. //
  11. // Originally from narwhal.js (http://narwhaljs.org)
  12. // Copyright (c) 2009 Thomas Robinson <280north.com>
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining a copy
  15. // of this software and associated documentation files (the 'Software'), to
  16. // deal in the Software without restriction, including without limitation the
  17. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  18. // sell copies of the Software, and to permit persons to whom the Software is
  19. // furnished to do so, subject to the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be included in
  22. // all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. // when used in node, this will actually load the util module we depend on
  31. // versus loading the builtin util module as happens otherwise
  32. // this is a bug in node module loading as far as I am concerned
  33. var util = require('util/');
  34. var pSlice = Array.prototype.slice;
  35. var hasOwn = Object.prototype.hasOwnProperty;
  36. // 1. The assert module provides functions that throw
  37. // AssertionError's when particular conditions are not met. The
  38. // assert module must conform to the following interface.
  39. var assert = module.exports = ok;
  40. // 2. The AssertionError is defined in assert.
  41. // new assert.AssertionError({ message: message,
  42. // actual: actual,
  43. // expected: expected })
  44. assert.AssertionError = function AssertionError(options) {
  45. this.name = 'AssertionError';
  46. this.actual = options.actual;
  47. this.expected = options.expected;
  48. this.operator = options.operator;
  49. if (options.message) {
  50. this.message = options.message;
  51. this.generatedMessage = false;
  52. } else {
  53. this.message = getMessage(this);
  54. this.generatedMessage = true;
  55. }
  56. var stackStartFunction = options.stackStartFunction || fail;
  57. if (Error.captureStackTrace) {
  58. Error.captureStackTrace(this, stackStartFunction);
  59. }
  60. else {
  61. // non v8 browsers so we can have a stacktrace
  62. var err = new Error();
  63. if (err.stack) {
  64. var out = err.stack;
  65. // try to strip useless frames
  66. var fn_name = stackStartFunction.name;
  67. var idx = out.indexOf('\n' + fn_name);
  68. if (idx >= 0) {
  69. // once we have located the function frame
  70. // we need to strip out everything before it (and its line)
  71. var next_line = out.indexOf('\n', idx + 1);
  72. out = out.substring(next_line + 1);
  73. }
  74. this.stack = out;
  75. }
  76. }
  77. };
  78. // assert.AssertionError instanceof Error
  79. util.inherits(assert.AssertionError, Error);
  80. function replacer(key, value) {
  81. if (util.isUndefined(value)) {
  82. return '' + value;
  83. }
  84. if (util.isNumber(value) && (isNaN(value) || !isFinite(value))) {
  85. return value.toString();
  86. }
  87. if (util.isFunction(value) || util.isRegExp(value)) {
  88. return value.toString();
  89. }
  90. return value;
  91. }
  92. function truncate(s, n) {
  93. if (util.isString(s)) {
  94. return s.length < n ? s : s.slice(0, n);
  95. } else {
  96. return s;
  97. }
  98. }
  99. function getMessage(self) {
  100. return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' +
  101. self.operator + ' ' +
  102. truncate(JSON.stringify(self.expected, replacer), 128);
  103. }
  104. // At present only the three keys mentioned above are used and
  105. // understood by the spec. Implementations or sub modules can pass
  106. // other keys to the AssertionError's constructor - they will be
  107. // ignored.
  108. // 3. All of the following functions must throw an AssertionError
  109. // when a corresponding condition is not met, with a message that
  110. // may be undefined if not provided. All assertion methods provide
  111. // both the actual and expected values to the assertion error for
  112. // display purposes.
  113. function fail(actual, expected, message, operator, stackStartFunction) {
  114. throw new assert.AssertionError({
  115. message: message,
  116. actual: actual,
  117. expected: expected,
  118. operator: operator,
  119. stackStartFunction: stackStartFunction
  120. });
  121. }
  122. // EXTENSION! allows for well behaved errors defined elsewhere.
  123. assert.fail = fail;
  124. // 4. Pure assertion tests whether a value is truthy, as determined
  125. // by !!guard.
  126. // assert.ok(guard, message_opt);
  127. // This statement is equivalent to assert.equal(true, !!guard,
  128. // message_opt);. To test strictly for the value true, use
  129. // assert.strictEqual(true, guard, message_opt);.
  130. function ok(value, message) {
  131. if (!value) fail(value, true, message, '==', assert.ok);
  132. }
  133. assert.ok = ok;
  134. // 5. The equality assertion tests shallow, coercive equality with
  135. // ==.
  136. // assert.equal(actual, expected, message_opt);
  137. assert.equal = function equal(actual, expected, message) {
  138. if (actual != expected) fail(actual, expected, message, '==', assert.equal);
  139. };
  140. // 6. The non-equality assertion tests for whether two objects are not equal
  141. // with != assert.notEqual(actual, expected, message_opt);
  142. assert.notEqual = function notEqual(actual, expected, message) {
  143. if (actual == expected) {
  144. fail(actual, expected, message, '!=', assert.notEqual);
  145. }
  146. };
  147. // 7. The equivalence assertion tests a deep equality relation.
  148. // assert.deepEqual(actual, expected, message_opt);
  149. assert.deepEqual = function deepEqual(actual, expected, message) {
  150. if (!_deepEqual(actual, expected)) {
  151. fail(actual, expected, message, 'deepEqual', assert.deepEqual);
  152. }
  153. };
  154. function _deepEqual(actual, expected) {
  155. // 7.1. All identical values are equivalent, as determined by ===.
  156. if (actual === expected) {
  157. return true;
  158. } else if (util.isBuffer(actual) && util.isBuffer(expected)) {
  159. if (actual.length != expected.length) return false;
  160. for (var i = 0; i < actual.length; i++) {
  161. if (actual[i] !== expected[i]) return false;
  162. }
  163. return true;
  164. // 7.2. If the expected value is a Date object, the actual value is
  165. // equivalent if it is also a Date object that refers to the same time.
  166. } else if (util.isDate(actual) && util.isDate(expected)) {
  167. return actual.getTime() === expected.getTime();
  168. // 7.3 If the expected value is a RegExp object, the actual value is
  169. // equivalent if it is also a RegExp object with the same source and
  170. // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
  171. } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
  172. return actual.source === expected.source &&
  173. actual.global === expected.global &&
  174. actual.multiline === expected.multiline &&
  175. actual.lastIndex === expected.lastIndex &&
  176. actual.ignoreCase === expected.ignoreCase;
  177. // 7.4. Other pairs that do not both pass typeof value == 'object',
  178. // equivalence is determined by ==.
  179. } else if (!util.isObject(actual) && !util.isObject(expected)) {
  180. return actual == expected;
  181. // 7.5 For all other Object pairs, including Array objects, equivalence is
  182. // determined by having the same number of owned properties (as verified
  183. // with Object.prototype.hasOwnProperty.call), the same set of keys
  184. // (although not necessarily the same order), equivalent values for every
  185. // corresponding key, and an identical 'prototype' property. Note: this
  186. // accounts for both named and indexed properties on Arrays.
  187. } else {
  188. return objEquiv(actual, expected);
  189. }
  190. }
  191. function isArguments(object) {
  192. return Object.prototype.toString.call(object) == '[object Arguments]';
  193. }
  194. function objEquiv(a, b) {
  195. if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b))
  196. return false;
  197. // an identical 'prototype' property.
  198. if (a.prototype !== b.prototype) return false;
  199. //~~~I've managed to break Object.keys through screwy arguments passing.
  200. // Converting to array solves the problem.
  201. if (isArguments(a)) {
  202. if (!isArguments(b)) {
  203. return false;
  204. }
  205. a = pSlice.call(a);
  206. b = pSlice.call(b);
  207. return _deepEqual(a, b);
  208. }
  209. try {
  210. var ka = objectKeys(a),
  211. kb = objectKeys(b),
  212. key, i;
  213. } catch (e) {//happens when one is a string literal and the other isn't
  214. return false;
  215. }
  216. // having the same number of owned properties (keys incorporates
  217. // hasOwnProperty)
  218. if (ka.length != kb.length)
  219. return false;
  220. //the same set of keys (although not necessarily the same order),
  221. ka.sort();
  222. kb.sort();
  223. //~~~cheap key test
  224. for (i = ka.length - 1; i >= 0; i--) {
  225. if (ka[i] != kb[i])
  226. return false;
  227. }
  228. //equivalent values for every corresponding key, and
  229. //~~~possibly expensive deep test
  230. for (i = ka.length - 1; i >= 0; i--) {
  231. key = ka[i];
  232. if (!_deepEqual(a[key], b[key])) return false;
  233. }
  234. return true;
  235. }
  236. // 8. The non-equivalence assertion tests for any deep inequality.
  237. // assert.notDeepEqual(actual, expected, message_opt);
  238. assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
  239. if (_deepEqual(actual, expected)) {
  240. fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
  241. }
  242. };
  243. // 9. The strict equality assertion tests strict equality, as determined by ===.
  244. // assert.strictEqual(actual, expected, message_opt);
  245. assert.strictEqual = function strictEqual(actual, expected, message) {
  246. if (actual !== expected) {
  247. fail(actual, expected, message, '===', assert.strictEqual);
  248. }
  249. };
  250. // 10. The strict non-equality assertion tests for strict inequality, as
  251. // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
  252. assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
  253. if (actual === expected) {
  254. fail(actual, expected, message, '!==', assert.notStrictEqual);
  255. }
  256. };
  257. function expectedException(actual, expected) {
  258. if (!actual || !expected) {
  259. return false;
  260. }
  261. if (Object.prototype.toString.call(expected) == '[object RegExp]') {
  262. return expected.test(actual);
  263. } else if (actual instanceof expected) {
  264. return true;
  265. } else if (expected.call({}, actual) === true) {
  266. return true;
  267. }
  268. return false;
  269. }
  270. function _throws(shouldThrow, block, expected, message) {
  271. var actual;
  272. if (util.isString(expected)) {
  273. message = expected;
  274. expected = null;
  275. }
  276. try {
  277. block();
  278. } catch (e) {
  279. actual = e;
  280. }
  281. message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
  282. (message ? ' ' + message : '.');
  283. if (shouldThrow && !actual) {
  284. fail(actual, expected, 'Missing expected exception' + message);
  285. }
  286. if (!shouldThrow && expectedException(actual, expected)) {
  287. fail(actual, expected, 'Got unwanted exception' + message);
  288. }
  289. if ((shouldThrow && actual && expected &&
  290. !expectedException(actual, expected)) || (!shouldThrow && actual)) {
  291. throw actual;
  292. }
  293. }
  294. // 11. Expected to throw an error:
  295. // assert.throws(block, Error_opt, message_opt);
  296. assert.throws = function(block, /*optional*/error, /*optional*/message) {
  297. _throws.apply(this, [true].concat(pSlice.call(arguments)));
  298. };
  299. // EXTENSION! This is annoying to write outside this module.
  300. assert.doesNotThrow = function(block, /*optional*/message) {
  301. _throws.apply(this, [false].concat(pSlice.call(arguments)));
  302. };
  303. assert.ifError = function(err) { if (err) {throw err;}};
  304. var objectKeys = Object.keys || function (obj) {
  305. var keys = [];
  306. for (var key in obj) {
  307. if (hasOwn.call(obj, key)) keys.push(key);
  308. }
  309. return keys;
  310. };
  311. },{"util/":6}],3:[function(require,module,exports){
  312. if (typeof Object.create === 'function') {
  313. // implementation from standard node.js 'util' module
  314. module.exports = function inherits(ctor, superCtor) {
  315. ctor.super_ = superCtor
  316. ctor.prototype = Object.create(superCtor.prototype, {
  317. constructor: {
  318. value: ctor,
  319. enumerable: false,
  320. writable: true,
  321. configurable: true
  322. }
  323. });
  324. };
  325. } else {
  326. // old school shim for old browsers
  327. module.exports = function inherits(ctor, superCtor) {
  328. ctor.super_ = superCtor
  329. var TempCtor = function () {}
  330. TempCtor.prototype = superCtor.prototype
  331. ctor.prototype = new TempCtor()
  332. ctor.prototype.constructor = ctor
  333. }
  334. }
  335. },{}],4:[function(require,module,exports){
  336. // shim for using process in browser
  337. var process = module.exports = {};
  338. process.nextTick = (function () {
  339. var canSetImmediate = typeof window !== 'undefined'
  340. && window.setImmediate;
  341. var canMutationObserver = typeof window !== 'undefined'
  342. && window.MutationObserver;
  343. var canPost = typeof window !== 'undefined'
  344. && window.postMessage && window.addEventListener
  345. ;
  346. if (canSetImmediate) {
  347. return function (f) { return window.setImmediate(f) };
  348. }
  349. var queue = [];
  350. if (canMutationObserver) {
  351. var hiddenDiv = document.createElement("div");
  352. var observer = new MutationObserver(function () {
  353. var queueList = queue.slice();
  354. queue.length = 0;
  355. queueList.forEach(function (fn) {
  356. fn();
  357. });
  358. });
  359. observer.observe(hiddenDiv, { attributes: true });
  360. return function nextTick(fn) {
  361. if (!queue.length) {
  362. hiddenDiv.setAttribute('yes', 'no');
  363. }
  364. queue.push(fn);
  365. };
  366. }
  367. if (canPost) {
  368. window.addEventListener('message', function (ev) {
  369. var source = ev.source;
  370. if ((source === window || source === null) && ev.data === 'process-tick') {
  371. ev.stopPropagation();
  372. if (queue.length > 0) {
  373. var fn = queue.shift();
  374. fn();
  375. }
  376. }
  377. }, true);
  378. return function nextTick(fn) {
  379. queue.push(fn);
  380. window.postMessage('process-tick', '*');
  381. };
  382. }
  383. return function nextTick(fn) {
  384. setTimeout(fn, 0);
  385. };
  386. })();
  387. process.title = 'browser';
  388. process.browser = true;
  389. process.env = {};
  390. process.argv = [];
  391. function noop() {}
  392. process.on = noop;
  393. process.addListener = noop;
  394. process.once = noop;
  395. process.off = noop;
  396. process.removeListener = noop;
  397. process.removeAllListeners = noop;
  398. process.emit = noop;
  399. process.binding = function (name) {
  400. throw new Error('process.binding is not supported');
  401. };
  402. // TODO(shtylman)
  403. process.cwd = function () { return '/' };
  404. process.chdir = function (dir) {
  405. throw new Error('process.chdir is not supported');
  406. };
  407. },{}],5:[function(require,module,exports){
  408. module.exports = function isBuffer(arg) {
  409. return arg && typeof arg === 'object'
  410. && typeof arg.copy === 'function'
  411. && typeof arg.fill === 'function'
  412. && typeof arg.readUInt8 === 'function';
  413. }
  414. },{}],6:[function(require,module,exports){
  415. (function (process,global){
  416. // Copyright Joyent, Inc. and other Node contributors.
  417. //
  418. // Permission is hereby granted, free of charge, to any person obtaining a
  419. // copy of this software and associated documentation files (the
  420. // "Software"), to deal in the Software without restriction, including
  421. // without limitation the rights to use, copy, modify, merge, publish,
  422. // distribute, sublicense, and/or sell copies of the Software, and to permit
  423. // persons to whom the Software is furnished to do so, subject to the
  424. // following conditions:
  425. //
  426. // The above copyright notice and this permission notice shall be included
  427. // in all copies or substantial portions of the Software.
  428. //
  429. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  430. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  431. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  432. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  433. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  434. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  435. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  436. var formatRegExp = /%[sdj%]/g;
  437. exports.format = function(f) {
  438. if (!isString(f)) {
  439. var objects = [];
  440. for (var i = 0; i < arguments.length; i++) {
  441. objects.push(inspect(arguments[i]));
  442. }
  443. return objects.join(' ');
  444. }
  445. var i = 1;
  446. var args = arguments;
  447. var len = args.length;
  448. var str = String(f).replace(formatRegExp, function(x) {
  449. if (x === '%%') return '%';
  450. if (i >= len) return x;
  451. switch (x) {
  452. case '%s': return String(args[i++]);
  453. case '%d': return Number(args[i++]);
  454. case '%j':
  455. try {
  456. return JSON.stringify(args[i++]);
  457. } catch (_) {
  458. return '[Circular]';
  459. }
  460. default:
  461. return x;
  462. }
  463. });
  464. for (var x = args[i]; i < len; x = args[++i]) {
  465. if (isNull(x) || !isObject(x)) {
  466. str += ' ' + x;
  467. } else {
  468. str += ' ' + inspect(x);
  469. }
  470. }
  471. return str;
  472. };
  473. // Mark that a method should not be used.
  474. // Returns a modified function which warns once by default.
  475. // If --no-deprecation is set, then it is a no-op.
  476. exports.deprecate = function(fn, msg) {
  477. // Allow for deprecating things in the process of starting up.
  478. if (isUndefined(global.process)) {
  479. return function() {
  480. return exports.deprecate(fn, msg).apply(this, arguments);
  481. };
  482. }
  483. if (process.noDeprecation === true) {
  484. return fn;
  485. }
  486. var warned = false;
  487. function deprecated() {
  488. if (!warned) {
  489. if (process.throwDeprecation) {
  490. throw new Error(msg);
  491. } else if (process.traceDeprecation) {
  492. console.trace(msg);
  493. } else {
  494. console.error(msg);
  495. }
  496. warned = true;
  497. }
  498. return fn.apply(this, arguments);
  499. }
  500. return deprecated;
  501. };
  502. var debugs = {};
  503. var debugEnviron;
  504. exports.debuglog = function(set) {
  505. if (isUndefined(debugEnviron))
  506. debugEnviron = process.env.NODE_DEBUG || '';
  507. set = set.toUpperCase();
  508. if (!debugs[set]) {
  509. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  510. var pid = process.pid;
  511. debugs[set] = function() {
  512. var msg = exports.format.apply(exports, arguments);
  513. console.error('%s %d: %s', set, pid, msg);
  514. };
  515. } else {
  516. debugs[set] = function() {};
  517. }
  518. }
  519. return debugs[set];
  520. };
  521. /**
  522. * Echos the value of a value. Trys to print the value out
  523. * in the best way possible given the different types.
  524. *
  525. * @param {Object} obj The object to print out.
  526. * @param {Object} opts Optional options object that alters the output.
  527. */
  528. /* legacy: obj, showHidden, depth, colors*/
  529. function inspect(obj, opts) {
  530. // default options
  531. var ctx = {
  532. seen: [],
  533. stylize: stylizeNoColor
  534. };
  535. // legacy...
  536. if (arguments.length >= 3) ctx.depth = arguments[2];
  537. if (arguments.length >= 4) ctx.colors = arguments[3];
  538. if (isBoolean(opts)) {
  539. // legacy...
  540. ctx.showHidden = opts;
  541. } else if (opts) {
  542. // got an "options" object
  543. exports._extend(ctx, opts);
  544. }
  545. // set default options
  546. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  547. if (isUndefined(ctx.depth)) ctx.depth = 2;
  548. if (isUndefined(ctx.colors)) ctx.colors = false;
  549. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  550. if (ctx.colors) ctx.stylize = stylizeWithColor;
  551. return formatValue(ctx, obj, ctx.depth);
  552. }
  553. exports.inspect = inspect;
  554. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  555. inspect.colors = {
  556. 'bold' : [1, 22],
  557. 'italic' : [3, 23],
  558. 'underline' : [4, 24],
  559. 'inverse' : [7, 27],
  560. 'white' : [37, 39],
  561. 'grey' : [90, 39],
  562. 'black' : [30, 39],
  563. 'blue' : [34, 39],
  564. 'cyan' : [36, 39],
  565. 'green' : [32, 39],
  566. 'magenta' : [35, 39],
  567. 'red' : [31, 39],
  568. 'yellow' : [33, 39]
  569. };
  570. // Don't use 'blue' not visible on cmd.exe
  571. inspect.styles = {
  572. 'special': 'cyan',
  573. 'number': 'yellow',
  574. 'boolean': 'yellow',
  575. 'undefined': 'grey',
  576. 'null': 'bold',
  577. 'string': 'green',
  578. 'date': 'magenta',
  579. // "name": intentionally not styling
  580. 'regexp': 'red'
  581. };
  582. function stylizeWithColor(str, styleType) {
  583. var style = inspect.styles[styleType];
  584. if (style) {
  585. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  586. '\u001b[' + inspect.colors[style][1] + 'm';
  587. } else {
  588. return str;
  589. }
  590. }
  591. function stylizeNoColor(str, styleType) {
  592. return str;
  593. }
  594. function arrayToHash(array) {
  595. var hash = {};
  596. array.forEach(function(val, idx) {
  597. hash[val] = true;
  598. });
  599. return hash;
  600. }
  601. function formatValue(ctx, value, recurseTimes) {
  602. // Provide a hook for user-specified inspect functions.
  603. // Check that value is an object with an inspect function on it
  604. if (ctx.customInspect &&
  605. value &&
  606. isFunction(value.inspect) &&
  607. // Filter out the util module, it's inspect function is special
  608. value.inspect !== exports.inspect &&
  609. // Also filter out any prototype objects using the circular check.
  610. !(value.constructor && value.constructor.prototype === value)) {
  611. var ret = value.inspect(recurseTimes, ctx);
  612. if (!isString(ret)) {
  613. ret = formatValue(ctx, ret, recurseTimes);
  614. }
  615. return ret;
  616. }
  617. // Primitive types cannot have properties
  618. var primitive = formatPrimitive(ctx, value);
  619. if (primitive) {
  620. return primitive;
  621. }
  622. // Look up the keys of the object.
  623. var keys = Object.keys(value);
  624. var visibleKeys = arrayToHash(keys);
  625. if (ctx.showHidden) {
  626. keys = Object.getOwnPropertyNames(value);
  627. }
  628. // IE doesn't make error fields non-enumerable
  629. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  630. if (isError(value)
  631. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  632. return formatError(value);
  633. }
  634. // Some type of object without properties can be shortcutted.
  635. if (keys.length === 0) {
  636. if (isFunction(value)) {
  637. var name = value.name ? ': ' + value.name : '';
  638. return ctx.stylize('[Function' + name + ']', 'special');
  639. }
  640. if (isRegExp(value)) {
  641. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  642. }
  643. if (isDate(value)) {
  644. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  645. }
  646. if (isError(value)) {
  647. return formatError(value);
  648. }
  649. }
  650. var base = '', array = false, braces = ['{', '}'];
  651. // Make Array say that they are Array
  652. if (isArray(value)) {
  653. array = true;
  654. braces = ['[', ']'];
  655. }
  656. // Make functions say that they are functions
  657. if (isFunction(value)) {
  658. var n = value.name ? ': ' + value.name : '';
  659. base = ' [Function' + n + ']';
  660. }
  661. // Make RegExps say that they are RegExps
  662. if (isRegExp(value)) {
  663. base = ' ' + RegExp.prototype.toString.call(value);
  664. }
  665. // Make dates with properties first say the date
  666. if (isDate(value)) {
  667. base = ' ' + Date.prototype.toUTCString.call(value);
  668. }
  669. // Make error with message first say the error
  670. if (isError(value)) {
  671. base = ' ' + formatError(value);
  672. }
  673. if (keys.length === 0 && (!array || value.length == 0)) {
  674. return braces[0] + base + braces[1];
  675. }
  676. if (recurseTimes < 0) {
  677. if (isRegExp(value)) {
  678. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  679. } else {
  680. return ctx.stylize('[Object]', 'special');
  681. }
  682. }
  683. ctx.seen.push(value);
  684. var output;
  685. if (array) {
  686. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  687. } else {
  688. output = keys.map(function(key) {
  689. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  690. });
  691. }
  692. ctx.seen.pop();
  693. return reduceToSingleString(output, base, braces);
  694. }
  695. function formatPrimitive(ctx, value) {
  696. if (isUndefined(value))
  697. return ctx.stylize('undefined', 'undefined');
  698. if (isString(value)) {
  699. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  700. .replace(/'/g, "\\'")
  701. .replace(/\\"/g, '"') + '\'';
  702. return ctx.stylize(simple, 'string');
  703. }
  704. if (isNumber(value))
  705. return ctx.stylize('' + value, 'number');
  706. if (isBoolean(value))
  707. return ctx.stylize('' + value, 'boolean');
  708. // For some reason typeof null is "object", so special case here.
  709. if (isNull(value))
  710. return ctx.stylize('null', 'null');
  711. }
  712. function formatError(value) {
  713. return '[' + Error.prototype.toString.call(value) + ']';
  714. }
  715. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  716. var output = [];
  717. for (var i = 0, l = value.length; i < l; ++i) {
  718. if (hasOwnProperty(value, String(i))) {
  719. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  720. String(i), true));
  721. } else {
  722. output.push('');
  723. }
  724. }
  725. keys.forEach(function(key) {
  726. if (!key.match(/^\d+$/)) {
  727. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  728. key, true));
  729. }
  730. });
  731. return output;
  732. }
  733. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  734. var name, str, desc;
  735. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  736. if (desc.get) {
  737. if (desc.set) {
  738. str = ctx.stylize('[Getter/Setter]', 'special');
  739. } else {
  740. str = ctx.stylize('[Getter]', 'special');
  741. }
  742. } else {
  743. if (desc.set) {
  744. str = ctx.stylize('[Setter]', 'special');
  745. }
  746. }
  747. if (!hasOwnProperty(visibleKeys, key)) {
  748. name = '[' + key + ']';
  749. }
  750. if (!str) {
  751. if (ctx.seen.indexOf(desc.value) < 0) {
  752. if (isNull(recurseTimes)) {
  753. str = formatValue(ctx, desc.value, null);
  754. } else {
  755. str = formatValue(ctx, desc.value, recurseTimes - 1);
  756. }
  757. if (str.indexOf('\n') > -1) {
  758. if (array) {
  759. str = str.split('\n').map(function(line) {
  760. return ' ' + line;
  761. }).join('\n').substr(2);
  762. } else {
  763. str = '\n' + str.split('\n').map(function(line) {
  764. return ' ' + line;
  765. }).join('\n');
  766. }
  767. }
  768. } else {
  769. str = ctx.stylize('[Circular]', 'special');
  770. }
  771. }
  772. if (isUndefined(name)) {
  773. if (array && key.match(/^\d+$/)) {
  774. return str;
  775. }
  776. name = JSON.stringify('' + key);
  777. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  778. name = name.substr(1, name.length - 2);
  779. name = ctx.stylize(name, 'name');
  780. } else {
  781. name = name.replace(/'/g, "\\'")
  782. .replace(/\\"/g, '"')
  783. .replace(/(^"|"$)/g, "'");
  784. name = ctx.stylize(name, 'string');
  785. }
  786. }
  787. return name + ': ' + str;
  788. }
  789. function reduceToSingleString(output, base, braces) {
  790. var numLinesEst = 0;
  791. var length = output.reduce(function(prev, cur) {
  792. numLinesEst++;
  793. if (cur.indexOf('\n') >= 0) numLinesEst++;
  794. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  795. }, 0);
  796. if (length > 60) {
  797. return braces[0] +
  798. (base === '' ? '' : base + '\n ') +
  799. ' ' +
  800. output.join(',\n ') +
  801. ' ' +
  802. braces[1];
  803. }
  804. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  805. }
  806. // NOTE: These type checking functions intentionally don't use `instanceof`
  807. // because it is fragile and can be easily faked with `Object.create()`.
  808. function isArray(ar) {
  809. return Array.isArray(ar);
  810. }
  811. exports.isArray = isArray;
  812. function isBoolean(arg) {
  813. return typeof arg === 'boolean';
  814. }
  815. exports.isBoolean = isBoolean;
  816. function isNull(arg) {
  817. return arg === null;
  818. }
  819. exports.isNull = isNull;
  820. function isNullOrUndefined(arg) {
  821. return arg == null;
  822. }
  823. exports.isNullOrUndefined = isNullOrUndefined;
  824. function isNumber(arg) {
  825. return typeof arg === 'number';
  826. }
  827. exports.isNumber = isNumber;
  828. function isString(arg) {
  829. return typeof arg === 'string';
  830. }
  831. exports.isString = isString;
  832. function isSymbol(arg) {
  833. return typeof arg === 'symbol';
  834. }
  835. exports.isSymbol = isSymbol;
  836. function isUndefined(arg) {
  837. return arg === void 0;
  838. }
  839. exports.isUndefined = isUndefined;
  840. function isRegExp(re) {
  841. return isObject(re) && objectToString(re) === '[object RegExp]';
  842. }
  843. exports.isRegExp = isRegExp;
  844. function isObject(arg) {
  845. return typeof arg === 'object' && arg !== null;
  846. }
  847. exports.isObject = isObject;
  848. function isDate(d) {
  849. return isObject(d) && objectToString(d) === '[object Date]';
  850. }
  851. exports.isDate = isDate;
  852. function isError(e) {
  853. return isObject(e) &&
  854. (objectToString(e) === '[object Error]' || e instanceof Error);
  855. }
  856. exports.isError = isError;
  857. function isFunction(arg) {
  858. return typeof arg === 'function';
  859. }
  860. exports.isFunction = isFunction;
  861. function isPrimitive(arg) {
  862. return arg === null ||
  863. typeof arg === 'boolean' ||
  864. typeof arg === 'number' ||
  865. typeof arg === 'string' ||
  866. typeof arg === 'symbol' || // ES6 symbol
  867. typeof arg === 'undefined';
  868. }
  869. exports.isPrimitive = isPrimitive;
  870. exports.isBuffer = require('./support/isBuffer');
  871. function objectToString(o) {
  872. return Object.prototype.toString.call(o);
  873. }
  874. function pad(n) {
  875. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  876. }
  877. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  878. 'Oct', 'Nov', 'Dec'];
  879. // 26 Feb 16:19:34
  880. function timestamp() {
  881. var d = new Date();
  882. var time = [pad(d.getHours()),
  883. pad(d.getMinutes()),
  884. pad(d.getSeconds())].join(':');
  885. return [d.getDate(), months[d.getMonth()], time].join(' ');
  886. }
  887. // log is just a thin wrapper to console.log that prepends a timestamp
  888. exports.log = function() {
  889. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  890. };
  891. /**
  892. * Inherit the prototype methods from one constructor into another.
  893. *
  894. * The Function.prototype.inherits from lang.js rewritten as a standalone
  895. * function (not on Function.prototype). NOTE: If this file is to be loaded
  896. * during bootstrapping this function needs to be rewritten using some native
  897. * functions as prototype setup using normal JavaScript does not work as
  898. * expected during bootstrapping (see mirror.js in r114903).
  899. *
  900. * @param {function} ctor Constructor function which needs to inherit the
  901. * prototype.
  902. * @param {function} superCtor Constructor function to inherit prototype from.
  903. */
  904. exports.inherits = require('inherits');
  905. exports._extend = function(origin, add) {
  906. // Don't do anything if add isn't an object
  907. if (!add || !isObject(add)) return origin;
  908. var keys = Object.keys(add);
  909. var i = keys.length;
  910. while (i--) {
  911. origin[keys[i]] = add[keys[i]];
  912. }
  913. return origin;
  914. };
  915. function hasOwnProperty(obj, prop) {
  916. return Object.prototype.hasOwnProperty.call(obj, prop);
  917. }
  918. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  919. },{"./support/isBuffer":5,"_process":4,"inherits":3}],7:[function(require,module,exports){
  920. require("./tests/2.1.2");
  921. require("./tests/2.1.3");
  922. require("./tests/2.2.1");
  923. require("./tests/2.2.2");
  924. require("./tests/2.2.3");
  925. require("./tests/2.2.4");
  926. require("./tests/2.2.5");
  927. require("./tests/2.2.6");
  928. require("./tests/2.2.7");
  929. require("./tests/2.3.1");
  930. require("./tests/2.3.2");
  931. require("./tests/2.3.3");
  932. require("./tests/2.3.4");
  933. },{"./tests/2.1.2":8,"./tests/2.1.3":9,"./tests/2.2.1":10,"./tests/2.2.2":11,"./tests/2.2.3":12,"./tests/2.2.4":13,"./tests/2.2.5":14,"./tests/2.2.6":15,"./tests/2.2.7":16,"./tests/2.3.1":17,"./tests/2.3.2":18,"./tests/2.3.3":19,"./tests/2.3.4":20}],8:[function(require,module,exports){
  934. (function (global){
  935. "use strict";
  936. var assert = require("assert");
  937. var testFulfilled = require("./helpers/testThreeCases").testFulfilled;
  938. var adapter = global.adapter;
  939. var deferred = adapter.deferred;
  940. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  941. describe("2.1.2.1: When fulfilled, a promise: must not transition to any other state.", function () {
  942. testFulfilled(dummy, function (promise, done) {
  943. var onFulfilledCalled = false;
  944. promise.then(function onFulfilled() {
  945. onFulfilledCalled = true;
  946. }, function onRejected() {
  947. assert.strictEqual(onFulfilledCalled, false);
  948. done();
  949. });
  950. setTimeout(done, 100);
  951. });
  952. specify("trying to fulfill then immediately reject", function (done) {
  953. var d = deferred();
  954. var onFulfilledCalled = false;
  955. d.promise.then(function onFulfilled() {
  956. onFulfilledCalled = true;
  957. }, function onRejected() {
  958. assert.strictEqual(onFulfilledCalled, false);
  959. done();
  960. });
  961. d.resolve(dummy);
  962. d.reject(dummy);
  963. setTimeout(done, 100);
  964. });
  965. specify("trying to fulfill then reject, delayed", function (done) {
  966. var d = deferred();
  967. var onFulfilledCalled = false;
  968. d.promise.then(function onFulfilled() {
  969. onFulfilledCalled = true;
  970. }, function onRejected() {
  971. assert.strictEqual(onFulfilledCalled, false);
  972. done();
  973. });
  974. setTimeout(function () {
  975. d.resolve(dummy);
  976. d.reject(dummy);
  977. }, 50);
  978. setTimeout(done, 100);
  979. });
  980. specify("trying to fulfill immediately then reject delayed", function (done) {
  981. var d = deferred();
  982. var onFulfilledCalled = false;
  983. d.promise.then(function onFulfilled() {
  984. onFulfilledCalled = true;
  985. }, function onRejected() {
  986. assert.strictEqual(onFulfilledCalled, false);
  987. done();
  988. });
  989. d.resolve(dummy);
  990. setTimeout(function () {
  991. d.reject(dummy);
  992. }, 50);
  993. setTimeout(done, 100);
  994. });
  995. });
  996. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  997. },{"./helpers/testThreeCases":22,"assert":2}],9:[function(require,module,exports){
  998. (function (global){
  999. "use strict";
  1000. var assert = require("assert");
  1001. var testRejected = require("./helpers/testThreeCases").testRejected;
  1002. var adapter = global.adapter;
  1003. var deferred = adapter.deferred;
  1004. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  1005. describe("2.1.3.1: When rejected, a promise: must not transition to any other state.", function () {
  1006. testRejected(dummy, function (promise, done) {
  1007. var onRejectedCalled = false;
  1008. promise.then(function onFulfilled() {
  1009. assert.strictEqual(onRejectedCalled, false);
  1010. done();
  1011. }, function onRejected() {
  1012. onRejectedCalled = true;
  1013. });
  1014. setTimeout(done, 100);
  1015. });
  1016. specify("trying to reject then immediately fulfill", function (done) {
  1017. var d = deferred();
  1018. var onRejectedCalled = false;
  1019. d.promise.then(function onFulfilled() {
  1020. assert.strictEqual(onRejectedCalled, false);
  1021. done();
  1022. }, function onRejected() {
  1023. onRejectedCalled = true;
  1024. });
  1025. d.reject(dummy);
  1026. d.resolve(dummy);
  1027. setTimeout(done, 100);
  1028. });
  1029. specify("trying to reject then fulfill, delayed", function (done) {
  1030. var d = deferred();
  1031. var onRejectedCalled = false;
  1032. d.promise.then(function onFulfilled() {
  1033. assert.strictEqual(onRejectedCalled, false);
  1034. done();
  1035. }, function onRejected() {
  1036. onRejectedCalled = true;
  1037. });
  1038. setTimeout(function () {
  1039. d.reject(dummy);
  1040. d.resolve(dummy);
  1041. }, 50);
  1042. setTimeout(done, 100);
  1043. });
  1044. specify("trying to reject immediately then fulfill delayed", function (done) {
  1045. var d = deferred();
  1046. var onRejectedCalled = false;
  1047. d.promise.then(function onFulfilled() {
  1048. assert.strictEqual(onRejectedCalled, false);
  1049. done();
  1050. }, function onRejected() {
  1051. onRejectedCalled = true;
  1052. });
  1053. d.reject(dummy);
  1054. setTimeout(function () {
  1055. d.resolve(dummy);
  1056. }, 50);
  1057. setTimeout(done, 100);
  1058. });
  1059. });
  1060. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1061. },{"./helpers/testThreeCases":22,"assert":2}],10:[function(require,module,exports){
  1062. (function (global){
  1063. "use strict";
  1064. var adapter = global.adapter;
  1065. var resolved = adapter.resolved;
  1066. var rejected = adapter.rejected;
  1067. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  1068. describe("2.2.1: Both `onFulfilled` and `onRejected` are optional arguments.", function () {
  1069. describe("2.2.1.1: If `onFulfilled` is not a function, it must be ignored.", function () {
  1070. describe("applied to a directly-rejected promise", function () {
  1071. function testNonFunction(nonFunction, stringRepresentation) {
  1072. specify("`onFulfilled` is " + stringRepresentation, function (done) {
  1073. rejected(dummy).then(nonFunction, function () {
  1074. done();
  1075. });
  1076. });
  1077. }
  1078. testNonFunction(undefined, "`undefined`");
  1079. testNonFunction(null, "`null`");
  1080. testNonFunction(false, "`false`");
  1081. testNonFunction(5, "`5`");
  1082. testNonFunction({}, "an object");
  1083. });
  1084. describe("applied to a promise rejected and then chained off of", function () {
  1085. function testNonFunction(nonFunction, stringRepresentation) {
  1086. specify("`onFulfilled` is " + stringRepresentation, function (done) {
  1087. rejected(dummy).then(function () { }, undefined).then(nonFunction, function () {
  1088. done();
  1089. });
  1090. });
  1091. }
  1092. testNonFunction(undefined, "`undefined`");
  1093. testNonFunction(null, "`null`");
  1094. testNonFunction(false, "`false`");
  1095. testNonFunction(5, "`5`");
  1096. testNonFunction({}, "an object");
  1097. });
  1098. });
  1099. describe("2.2.1.2: If `onRejected` is not a function, it must be ignored.", function () {
  1100. describe("applied to a directly-fulfilled promise", function () {
  1101. function testNonFunction(nonFunction, stringRepresentation) {
  1102. specify("`onRejected` is " + stringRepresentation, function (done) {
  1103. resolved(dummy).then(function () {
  1104. done();
  1105. }, nonFunction);
  1106. });
  1107. }
  1108. testNonFunction(undefined, "`undefined`");
  1109. testNonFunction(null, "`null`");
  1110. testNonFunction(false, "`false`");
  1111. testNonFunction(5, "`5`");
  1112. testNonFunction({}, "an object");
  1113. });
  1114. describe("applied to a promise fulfilled and then chained off of", function () {
  1115. function testNonFunction(nonFunction, stringRepresentation) {
  1116. specify("`onFulfilled` is " + stringRepresentation, function (done) {
  1117. resolved(dummy).then(undefined, function () { }).then(function () {
  1118. done();
  1119. }, nonFunction);
  1120. });
  1121. }
  1122. testNonFunction(undefined, "`undefined`");
  1123. testNonFunction(null, "`null`");
  1124. testNonFunction(false, "`false`");
  1125. testNonFunction(5, "`5`");
  1126. testNonFunction({}, "an object");
  1127. });
  1128. });
  1129. });
  1130. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1131. },{}],11:[function(require,module,exports){
  1132. (function (global){
  1133. "use strict";
  1134. var assert = require("assert");
  1135. var testFulfilled = require("./helpers/testThreeCases").testFulfilled;
  1136. var adapter = global.adapter;
  1137. var resolved = adapter.resolved;
  1138. var deferred = adapter.deferred;
  1139. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  1140. var sentinel = { sentinel: "sentinel" }; // a sentinel fulfillment value to test for with strict equality
  1141. describe("2.2.2: If `onFulfilled` is a function,", function () {
  1142. describe("2.2.2.1: it must be called after `promise` is fulfilled, with `promise`’s fulfillment value as its " +
  1143. "first argument.", function () {
  1144. testFulfilled(sentinel, function (promise, done) {
  1145. promise.then(function onFulfilled(value) {
  1146. assert.strictEqual(value, sentinel);
  1147. done();
  1148. });
  1149. });
  1150. });
  1151. describe("2.2.2.2: it must not be called before `promise` is fulfilled", function () {
  1152. specify("fulfilled after a delay", function (done) {
  1153. var d = deferred();
  1154. var isFulfilled = false;
  1155. d.promise.then(function onFulfilled() {
  1156. assert.strictEqual(isFulfilled, true);
  1157. done();
  1158. });
  1159. setTimeout(function () {
  1160. d.resolve(dummy);
  1161. isFulfilled = true;
  1162. }, 50);
  1163. });
  1164. specify("never fulfilled", function (done) {
  1165. var d = deferred();
  1166. var onFulfilledCalled = false;
  1167. d.promise.then(function onFulfilled() {
  1168. onFulfilledCalled = true;
  1169. done();
  1170. });
  1171. setTimeout(function () {
  1172. assert.strictEqual(onFulfilledCalled, false);
  1173. done();
  1174. }, 150);
  1175. });
  1176. });
  1177. describe("2.2.2.3: it must not be called more than once.", function () {
  1178. specify("already-fulfilled", function (done) {
  1179. var timesCalled = 0;
  1180. resolved(dummy).then(function onFulfilled() {
  1181. assert.strictEqual(++timesCalled, 1);
  1182. done();
  1183. });
  1184. });
  1185. specify("trying to fulfill a pending promise more than once, immediately", function (done) {
  1186. var d = deferred();
  1187. var timesCalled = 0;
  1188. d.promise.then(function onFulfilled() {
  1189. assert.strictEqual(++timesCalled, 1);
  1190. done();
  1191. });
  1192. d.resolve(dummy);
  1193. d.resolve(dummy);
  1194. });
  1195. specify("trying to fulfill a pending promise more than once, delayed", function (done) {
  1196. var d = deferred();
  1197. var timesCalled = 0;
  1198. d.promise.then(function onFulfilled() {
  1199. assert.strictEqual(++timesCalled, 1);
  1200. done();
  1201. });
  1202. setTimeout(function () {
  1203. d.resolve(dummy);
  1204. d.resolve(dummy);
  1205. }, 50);
  1206. });
  1207. specify("trying to fulfill a pending promise more than once, immediately then delayed", function (done) {
  1208. var d = deferred();
  1209. var timesCalled = 0;
  1210. d.promise.then(function onFulfilled() {
  1211. assert.strictEqual(++timesCalled, 1);
  1212. done();
  1213. });
  1214. d.resolve(dummy);
  1215. setTimeout(function () {
  1216. d.resolve(dummy);
  1217. }, 50);
  1218. });
  1219. specify("when multiple `then` calls are made, spaced apart in time", function (done) {
  1220. var d = deferred();
  1221. var timesCalled = [0, 0, 0];
  1222. d.promise.then(function onFulfilled() {
  1223. assert.strictEqual(++timesCalled[0], 1);
  1224. });
  1225. setTimeout(function () {
  1226. d.promise.then(function onFulfilled() {
  1227. assert.strictEqual(++timesCalled[1], 1);
  1228. });
  1229. }, 50);
  1230. setTimeout(function () {
  1231. d.promise.then(function onFulfilled() {
  1232. assert.strictEqual(++timesCalled[2], 1);
  1233. done();
  1234. });
  1235. }, 100);
  1236. setTimeout(function () {
  1237. d.resolve(dummy);
  1238. }, 150);
  1239. });
  1240. specify("when `then` is interleaved with fulfillment", function (done) {
  1241. var d = deferred();
  1242. var timesCalled = [0, 0];
  1243. d.promise.then(function onFulfilled() {
  1244. assert.strictEqual(++timesCalled[0], 1);
  1245. });
  1246. d.resolve(dummy);
  1247. d.promise.then(function onFulfilled() {
  1248. assert.strictEqual(++timesCalled[1], 1);
  1249. done();
  1250. });
  1251. });
  1252. });
  1253. });
  1254. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1255. },{"./helpers/testThreeCases":22,"assert":2}],12:[function(require,module,exports){
  1256. (function (global){
  1257. "use strict";
  1258. var assert = require("assert");
  1259. var testRejected = require("./helpers/testThreeCases").testRejected;
  1260. var adapter = global.adapter;
  1261. var rejected = adapter.rejected;
  1262. var deferred = adapter.deferred;
  1263. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  1264. var sentinel = { sentinel: "sentinel" }; // a sentinel fulfillment value to test for with strict equality
  1265. describe("2.2.3: If `onRejected` is a function,", function () {
  1266. describe("2.2.3.1: it must be called after `promise` is rejected, with `promise`’s rejection reason as its " +
  1267. "first argument.", function () {
  1268. testRejected(sentinel, function (promise, done) {
  1269. promise.then(null, function onRejected(reason) {
  1270. assert.strictEqual(reason, sentinel);
  1271. done();
  1272. });
  1273. });
  1274. });
  1275. describe("2.2.3.2: it must not be called before `promise` is rejected", function () {
  1276. specify("rejected after a delay", function (done) {
  1277. var d = deferred();
  1278. var isRejected = false;
  1279. d.promise.then(null, function onRejected() {
  1280. assert.strictEqual(isRejected, true);
  1281. done();
  1282. });
  1283. setTimeout(function () {
  1284. d.reject(dummy);
  1285. isRejected = true;
  1286. }, 50);
  1287. });
  1288. specify("never rejected", function (done) {
  1289. var d = deferred();
  1290. var onRejectedCalled = false;
  1291. d.promise.then(null, function onRejected() {
  1292. onRejectedCalled = true;
  1293. done();
  1294. });
  1295. setTimeout(function () {
  1296. assert.strictEqual(onRejectedCalled, false);
  1297. done();
  1298. }, 150);
  1299. });
  1300. });
  1301. describe("2.2.3.3: it must not be called more than once.", function () {
  1302. specify("already-rejected", function (done) {
  1303. var timesCalled = 0;
  1304. rejected(dummy).then(null, function onRejected() {
  1305. assert.strictEqual(++timesCalled, 1);
  1306. done();
  1307. });
  1308. });
  1309. specify("trying to reject a pending promise more than once, immediately", function (done) {
  1310. var d = deferred();
  1311. var timesCalled = 0;
  1312. d.promise.then(null, function onRejected() {
  1313. assert.strictEqual(++timesCalled, 1);
  1314. done();
  1315. });
  1316. d.reject(dummy);
  1317. d.reject(dummy);
  1318. });
  1319. specify("trying to reject a pending promise more than once, delayed", function (done) {
  1320. var d = deferred();
  1321. var timesCalled = 0;
  1322. d.promise.then(null, function onRejected() {
  1323. assert.strictEqual(++timesCalled, 1);
  1324. done();
  1325. });
  1326. setTimeout(function () {
  1327. d.reject(dummy);
  1328. d.reject(dummy);
  1329. }, 50);
  1330. });
  1331. specify("trying to reject a pending promise more than once, immediately then delayed", function (done) {
  1332. var d = deferred();
  1333. var timesCalled = 0;
  1334. d.promise.then(null, function onRejected() {
  1335. assert.strictEqual(++timesCalled, 1);
  1336. done();
  1337. });
  1338. d.reject(dummy);
  1339. setTimeout(function () {
  1340. d.reject(dummy);
  1341. }, 50);
  1342. });
  1343. specify("when multiple `then` calls are made, spaced apart in time", function (done) {
  1344. var d = deferred();
  1345. var timesCalled = [0, 0, 0];
  1346. d.promise.then(null, function onRejected() {
  1347. assert.strictEqual(++timesCalled[0], 1);
  1348. });
  1349. setTimeout(function () {
  1350. d.promise.then(null, function onRejected() {
  1351. assert.strictEqual(++timesCalled[1], 1);
  1352. });
  1353. }, 50);
  1354. setTimeout(function () {
  1355. d.promise.then(null, function onRejected() {
  1356. assert.strictEqual(++timesCalled[2], 1);
  1357. done();
  1358. });
  1359. }, 100);
  1360. setTimeout(function () {
  1361. d.reject(dummy);
  1362. }, 150);
  1363. });
  1364. specify("when `then` is interleaved with rejection", function (done) {
  1365. var d = deferred();
  1366. var timesCalled = [0, 0];
  1367. d.promise.then(null, function onRejected() {
  1368. assert.strictEqual(++timesCalled[0], 1);
  1369. });
  1370. d.reject(dummy);
  1371. d.promise.then(null, function onRejected() {
  1372. assert.strictEqual(++timesCalled[1], 1);
  1373. done();
  1374. });
  1375. });
  1376. });
  1377. });
  1378. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1379. },{"./helpers/testThreeCases":22,"assert":2}],13:[function(require,module,exports){
  1380. (function (global){
  1381. "use strict";
  1382. var assert = require("assert");
  1383. var testFulfilled = require("./helpers/testThreeCases").testFulfilled;
  1384. var testRejected = require("./helpers/testThreeCases").testRejected;
  1385. var adapter = global.adapter;
  1386. var resolved = adapter.resolved;
  1387. var rejected = adapter.rejected;
  1388. var deferred = adapter.deferred;
  1389. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  1390. describe("2.2.4: `onFulfilled` or `onRejected` must not be called until the execution context stack contains only " +
  1391. "platform code.", function () {
  1392. describe("`then` returns before the promise becomes fulfilled or rejected", function () {
  1393. testFulfilled(dummy, function (promise, done) {
  1394. var thenHasReturned = false;
  1395. promise.then(function onFulfilled() {
  1396. assert.strictEqual(thenHasReturned, true);
  1397. done();
  1398. });
  1399. thenHasReturned = true;
  1400. });
  1401. testRejected(dummy, function (promise, done) {
  1402. var thenHasReturned = false;
  1403. promise.then(null, function onRejected() {
  1404. assert.strictEqual(thenHasReturned, true);
  1405. done();
  1406. });
  1407. thenHasReturned = true;
  1408. });
  1409. });
  1410. describe("Clean-stack execution ordering tests (fulfillment case)", function () {
  1411. specify("when `onFulfilled` is added immediately before the promise is fulfilled",
  1412. function () {
  1413. var d = deferred();
  1414. var onFulfilledCalled = false;
  1415. d.promise.then(function onFulfilled() {
  1416. onFulfilledCalled = true;
  1417. });
  1418. d.resolve(dummy);
  1419. assert.strictEqual(onFulfilledCalled, false);
  1420. });
  1421. specify("when `onFulfilled` is added immediately after the promise is fulfilled",
  1422. function () {
  1423. var d = deferred();
  1424. var onFulfilledCalled = false;
  1425. d.resolve(dummy);
  1426. d.promise.then(function onFulfilled() {
  1427. onFulfilledCalled = true;
  1428. });
  1429. assert.strictEqual(onFulfilledCalled, false);
  1430. });
  1431. specify("when one `onFulfilled` is added inside another `onFulfilled`", function (done) {
  1432. var promise = resolved();
  1433. var firstOnFulfilledFinished = false;
  1434. promise.then(function () {
  1435. promise.then(function () {
  1436. assert.strictEqual(firstOnFulfilledFinished, true);
  1437. done();
  1438. });
  1439. firstOnFulfilledFinished = true;
  1440. });
  1441. });
  1442. specify("when `onFulfilled` is added inside an `onRejected`", function (done) {
  1443. var promise = rejected();
  1444. var promise2 = resolved();
  1445. var firstOnRejectedFinished = false;
  1446. promise.then(null, function () {
  1447. promise2.then(function () {
  1448. assert.strictEqual(firstOnRejectedFinished, true);
  1449. done();
  1450. });
  1451. firstOnRejectedFinished = true;
  1452. });
  1453. });
  1454. specify("when the promise is fulfilled asynchronously", function (done) {
  1455. var d = deferred();
  1456. var firstStackFinished = false;
  1457. setTimeout(function () {
  1458. d.resolve(dummy);
  1459. firstStackFinished = true;
  1460. }, 0);
  1461. d.promise.then(function () {
  1462. assert.strictEqual(firstStackFinished, true);
  1463. done();
  1464. });
  1465. });
  1466. });
  1467. describe("Clean-stack execution ordering tests (rejection case)", function () {
  1468. specify("when `onRejected` is added immediately before the promise is rejected",
  1469. function () {
  1470. var d = deferred();
  1471. var onRejectedCalled = false;
  1472. d.promise.then(null, function onRejected() {
  1473. onRejectedCalled = true;
  1474. });
  1475. d.reject(dummy);
  1476. assert.strictEqual(onRejectedCalled, false);
  1477. });
  1478. specify("when `onRejected` is added immediately after the promise is rejected",
  1479. function () {
  1480. var d = deferred();
  1481. var onRejectedCalled = false;
  1482. d.reject(dummy);
  1483. d.promise.then(null, function onRejected() {
  1484. onRejectedCalled = true;
  1485. });
  1486. assert.strictEqual(onRejectedCalled, false);
  1487. });
  1488. specify("when `onRejected` is added inside an `onFulfilled`", function (done) {
  1489. var promise = resolved();
  1490. var promise2 = rejected();
  1491. var firstOnFulfilledFinished = false;
  1492. promise.then(function () {
  1493. promise2.then(null, function () {
  1494. assert.strictEqual(firstOnFulfilledFinished, true);
  1495. done();
  1496. });
  1497. firstOnFulfilledFinished = true;
  1498. });
  1499. });
  1500. specify("when one `onRejected` is added inside another `onRejected`", function (done) {
  1501. var promise = rejected();
  1502. var firstOnRejectedFinished = false;
  1503. promise.then(null, function () {
  1504. promise.then(null, function () {
  1505. assert.strictEqual(firstOnRejectedFinished, true);
  1506. done();
  1507. });
  1508. firstOnRejectedFinished = true;
  1509. });
  1510. });
  1511. specify("when the promise is rejected asynchronously", function (done) {
  1512. var d = deferred();
  1513. var firstStackFinished = false;
  1514. setTimeout(function () {
  1515. d.reject(dummy);
  1516. firstStackFinished = true;
  1517. }, 0);
  1518. d.promise.then(null, function () {
  1519. assert.strictEqual(firstStackFinished, true);
  1520. done();
  1521. });
  1522. });
  1523. });
  1524. });
  1525. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1526. },{"./helpers/testThreeCases":22,"assert":2}],14:[function(require,module,exports){
  1527. (function (global){
  1528. /*jshint strict: false */
  1529. var assert = require("assert");
  1530. var adapter = global.adapter;
  1531. var resolved = adapter.resolved;
  1532. var rejected = adapter.rejected;
  1533. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  1534. function impimentsUseStrictCorrectly() {
  1535. "use strict";
  1536. function test() {
  1537. /*jshint validthis:true */
  1538. return !this;
  1539. }
  1540. return test();
  1541. }
  1542. describe("2.2.5 `onFulfilled` and `onRejected` must be called as functions (i.e. with no `this` value).", function () {
  1543. if (impimentsUseStrictCorrectly()) {
  1544. describe("strict mode", function () {
  1545. specify("fulfilled", function (done) {
  1546. resolved(dummy).then(function onFulfilled() {
  1547. "use strict";
  1548. assert.strictEqual(this, undefined);
  1549. done();
  1550. });
  1551. });
  1552. specify("rejected", function (done) {
  1553. rejected(dummy).then(null, function onRejected() {
  1554. "use strict";
  1555. assert.strictEqual(this, undefined);
  1556. done();
  1557. });
  1558. });
  1559. });
  1560. }
  1561. describe("sloppy mode", function () {
  1562. specify("fulfilled", function (done) {
  1563. resolved(dummy).then(function onFulfilled() {
  1564. assert.strictEqual(this, global);
  1565. done();
  1566. });
  1567. });
  1568. specify("rejected", function (done) {
  1569. rejected(dummy).then(null, function onRejected() {
  1570. assert.strictEqual(this, global);
  1571. done();
  1572. });
  1573. });
  1574. });
  1575. });
  1576. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1577. },{"assert":2}],15:[function(require,module,exports){
  1578. "use strict";
  1579. var assert = require("assert");
  1580. var sinon = require("sinon");
  1581. var testFulfilled = require("./helpers/testThreeCases").testFulfilled;
  1582. var testRejected = require("./helpers/testThreeCases").testRejected;
  1583. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  1584. var other = { other: "other" }; // a value we don't want to be strict equal to
  1585. var sentinel = { sentinel: "sentinel" }; // a sentinel fulfillment value to test for with strict equality
  1586. var sentinel2 = { sentinel2: "sentinel2" };
  1587. var sentinel3 = { sentinel3: "sentinel3" };
  1588. function callbackAggregator(times, ultimateCallback) {
  1589. var soFar = 0;
  1590. return function () {
  1591. if (++soFar === times) {
  1592. ultimateCallback();
  1593. }
  1594. };
  1595. }
  1596. describe("2.2.6: `then` may be called multiple times on the same promise.", function () {
  1597. describe("2.2.6.1: If/when `promise` is fulfilled, all respective `onFulfilled` callbacks must execute in the " +
  1598. "order of their originating calls to `then`.", function () {
  1599. describe("multiple boring fulfillment handlers", function () {
  1600. testFulfilled(sentinel, function (promise, done) {
  1601. var handler1 = sinon.stub().returns(other);
  1602. var handler2 = sinon.stub().returns(other);
  1603. var handler3 = sinon.stub().returns(other);
  1604. var spy = sinon.spy();
  1605. promise.then(handler1, spy);
  1606. promise.then(handler2, spy);
  1607. promise.then(handler3, spy);
  1608. promise.then(function (value) {
  1609. assert.strictEqual(value, sentinel);
  1610. sinon.assert.calledWith(handler1, sinon.match.same(sentinel));
  1611. sinon.assert.calledWith(handler2, sinon.match.same(sentinel));
  1612. sinon.assert.calledWith(handler3, sinon.match.same(sentinel));
  1613. sinon.assert.notCalled(spy);
  1614. done();
  1615. });
  1616. });
  1617. });
  1618. describe("multiple fulfillment handlers, one of which throws", function () {
  1619. testFulfilled(sentinel, function (promise, done) {
  1620. var handler1 = sinon.stub().returns(other);
  1621. var handler2 = sinon.stub().throws(other);
  1622. var handler3 = sinon.stub().returns(other);
  1623. var spy = sinon.spy();
  1624. promise.then(handler1, spy);
  1625. promise.then(handler2, spy);
  1626. promise.then(handler3, spy);
  1627. promise.then(function (value) {
  1628. assert.strictEqual(value, sentinel);
  1629. sinon.assert.calledWith(handler1, sinon.match.same(sentinel));
  1630. sinon.assert.calledWith(handler2, sinon.match.same(sentinel));
  1631. sinon.assert.calledWith(handler3, sinon.match.same(sentinel));
  1632. sinon.assert.notCalled(spy);
  1633. done();
  1634. });
  1635. });
  1636. });
  1637. describe("results in multiple branching chains with their own fulfillment values", function () {
  1638. testFulfilled(dummy, function (promise, done) {
  1639. var semiDone = callbackAggregator(3, done);
  1640. promise.then(function () {
  1641. return sentinel;
  1642. }).then(function (value) {
  1643. assert.strictEqual(value, sentinel);
  1644. semiDone();
  1645. });
  1646. promise.then(function () {
  1647. throw sentinel2;
  1648. }).then(null, function (reason) {
  1649. assert.strictEqual(reason, sentinel2);
  1650. semiDone();
  1651. });
  1652. promise.then(function () {
  1653. return sentinel3;
  1654. }).then(function (value) {
  1655. assert.strictEqual(value, sentinel3);
  1656. semiDone();
  1657. });
  1658. });
  1659. });
  1660. describe("`onFulfilled` handlers are called in the original order", function () {
  1661. testFulfilled(dummy, function (promise, done) {
  1662. var handler1 = sinon.spy(function handler1() {});
  1663. var handler2 = sinon.spy(function handler2() {});
  1664. var handler3 = sinon.spy(function handler3() {});
  1665. promise.then(handler1);
  1666. promise.then(handler2);
  1667. promise.then(handler3);
  1668. promise.then(function () {
  1669. sinon.assert.callOrder(handler1, handler2, handler3);
  1670. done();
  1671. });
  1672. });
  1673. describe("even when one handler is added inside another handler", function () {
  1674. testFulfilled(dummy, function (promise, done) {
  1675. var handler1 = sinon.spy(function handler1() {});
  1676. var handler2 = sinon.spy(function handler2() {});
  1677. var handler3 = sinon.spy(function handler3() {});
  1678. promise.then(function () {
  1679. handler1();
  1680. promise.then(handler3);
  1681. });
  1682. promise.then(handler2);
  1683. promise.then(function () {
  1684. // Give implementations a bit of extra time to flush their internal queue, if necessary.
  1685. setTimeout(function () {
  1686. sinon.assert.callOrder(handler1, handler2, handler3);
  1687. done();
  1688. }, 15);
  1689. });
  1690. });
  1691. });
  1692. });
  1693. });
  1694. describe("2.2.6.2: If/when `promise` is rejected, all respective `onRejected` callbacks must execute in the " +
  1695. "order of their originating calls to `then`.", function () {
  1696. describe("multiple boring rejection handlers", function () {
  1697. testRejected(sentinel, function (promise, done) {
  1698. var handler1 = sinon.stub().returns(other);
  1699. var handler2 = sinon.stub().returns(other);
  1700. var handler3 = sinon.stub().returns(other);
  1701. var spy = sinon.spy();
  1702. promise.then(spy, handler1);
  1703. promise.then(spy, handler2);
  1704. promise.then(spy, handler3);
  1705. promise.then(null, function (reason) {
  1706. assert.strictEqual(reason, sentinel);
  1707. sinon.assert.calledWith(handler1, sinon.match.same(sentinel));
  1708. sinon.assert.calledWith(handler2, sinon.match.same(sentinel));
  1709. sinon.assert.calledWith(handler3, sinon.match.same(sentinel));
  1710. sinon.assert.notCalled(spy);
  1711. done();
  1712. });
  1713. });
  1714. });
  1715. describe("multiple rejection handlers, one of which throws", function () {
  1716. testRejected(sentinel, function (promise, done) {
  1717. var handler1 = sinon.stub().returns(other);
  1718. var handler2 = sinon.stub().throws(other);
  1719. var handler3 = sinon.stub().returns(other);
  1720. var spy = sinon.spy();
  1721. promise.then(spy, handler1);
  1722. promise.then(spy, handler2);
  1723. promise.then(spy, handler3);
  1724. promise.then(null, function (reason) {
  1725. assert.strictEqual(reason, sentinel);
  1726. sinon.assert.calledWith(handler1, sinon.match.same(sentinel));
  1727. sinon.assert.calledWith(handler2, sinon.match.same(sentinel));
  1728. sinon.assert.calledWith(handler3, sinon.match.same(sentinel));
  1729. sinon.assert.notCalled(spy);
  1730. done();
  1731. });
  1732. });
  1733. });
  1734. describe("results in multiple branching chains with their own fulfillment values", function () {
  1735. testRejected(sentinel, function (promise, done) {
  1736. var semiDone = callbackAggregator(3, done);
  1737. promise.then(null, function () {
  1738. return sentinel;
  1739. }).then(function (value) {
  1740. assert.strictEqual(value, sentinel);
  1741. semiDone();
  1742. });
  1743. promise.then(null, function () {
  1744. throw sentinel2;
  1745. }).then(null, function (reason) {
  1746. assert.strictEqual(reason, sentinel2);
  1747. semiDone();
  1748. });
  1749. promise.then(null, function () {
  1750. return sentinel3;
  1751. }).then(function (value) {
  1752. assert.strictEqual(value, sentinel3);
  1753. semiDone();
  1754. });
  1755. });
  1756. });
  1757. describe("`onRejected` handlers are called in the original order", function () {
  1758. testRejected(dummy, function (promise, done) {
  1759. var handler1 = sinon.spy(function handler1() {});
  1760. var handler2 = sinon.spy(function handler2() {});
  1761. var handler3 = sinon.spy(function handler3() {});
  1762. promise.then(null, handler1);
  1763. promise.then(null, handler2);
  1764. promise.then(null, handler3);
  1765. promise.then(null, function () {
  1766. sinon.assert.callOrder(handler1, handler2, handler3);
  1767. done();
  1768. });
  1769. });
  1770. describe("even when one handler is added inside another handler", function () {
  1771. testRejected(dummy, function (promise, done) {
  1772. var handler1 = sinon.spy(function handler1() {});
  1773. var handler2 = sinon.spy(function handler2() {});
  1774. var handler3 = sinon.spy(function handler3() {});
  1775. promise.then(null, function () {
  1776. handler1();
  1777. promise.then(null, handler3);
  1778. });
  1779. promise.then(null, handler2);
  1780. promise.then(null, function () {
  1781. // Give implementations a bit of extra time to flush their internal queue, if necessary.
  1782. setTimeout(function () {
  1783. sinon.assert.callOrder(handler1, handler2, handler3);
  1784. done();
  1785. }, 15);
  1786. });
  1787. });
  1788. });
  1789. });
  1790. });
  1791. });
  1792. },{"./helpers/testThreeCases":22,"assert":2,"sinon":24}],16:[function(require,module,exports){
  1793. (function (global){
  1794. "use strict";
  1795. var assert = require("assert");
  1796. var testFulfilled = require("./helpers/testThreeCases").testFulfilled;
  1797. var testRejected = require("./helpers/testThreeCases").testRejected;
  1798. var reasons = require("./helpers/reasons");
  1799. var adapter = global.adapter;
  1800. var deferred = adapter.deferred;
  1801. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  1802. var sentinel = { sentinel: "sentinel" }; // a sentinel fulfillment value to test for with strict equality
  1803. var other = { other: "other" }; // a value we don't want to be strict equal to
  1804. describe("2.2.7: `then` must return a promise: `promise2 = promise1.then(onFulfilled, onRejected)`", function () {
  1805. specify("is a promise", function () {
  1806. var promise1 = deferred().promise;
  1807. var promise2 = promise1.then();
  1808. assert(typeof promise2 === "object" || typeof promise2 === "function");
  1809. assert.notStrictEqual(promise2, null);
  1810. assert.strictEqual(typeof promise2.then, "function");
  1811. });
  1812. describe("2.2.7.1: If either `onFulfilled` or `onRejected` returns a value `x`, run the Promise Resolution " +
  1813. "Procedure `[[Resolve]](promise2, x)`", function () {
  1814. specify("see separate 3.3 tests", function () { });
  1815. });
  1816. describe("2.2.7.2: If either `onFulfilled` or `onRejected` throws an exception `e`, `promise2` must be rejected " +
  1817. "with `e` as the reason.", function () {
  1818. function testReason(expectedReason, stringRepresentation) {
  1819. describe("The reason is " + stringRepresentation, function () {
  1820. testFulfilled(dummy, function (promise1, done) {
  1821. var promise2 = promise1.then(function onFulfilled() {
  1822. throw expectedReason;
  1823. });
  1824. promise2.then(null, function onPromise2Rejected(actualReason) {
  1825. assert.strictEqual(actualReason, expectedReason);
  1826. done();
  1827. });
  1828. });
  1829. testRejected(dummy, function (promise1, done) {
  1830. var promise2 = promise1.then(null, function onRejected() {
  1831. throw expectedReason;
  1832. });
  1833. promise2.then(null, function onPromise2Rejected(actualReason) {
  1834. assert.strictEqual(actualReason, expectedReason);
  1835. done();
  1836. });
  1837. });
  1838. });
  1839. }
  1840. Object.keys(reasons).forEach(function (stringRepresentation) {
  1841. testReason(reasons[stringRepresentation], stringRepresentation);
  1842. });
  1843. });
  1844. describe("2.2.7.3: If `onFulfilled` is not a function and `promise1` is fulfilled, `promise2` must be fulfilled " +
  1845. "with the same value.", function () {
  1846. function testNonFunction(nonFunction, stringRepresentation) {
  1847. describe("`onFulfilled` is " + stringRepresentation, function () {
  1848. testFulfilled(sentinel, function (promise1, done) {
  1849. var promise2 = promise1.then(nonFunction);
  1850. promise2.then(function onPromise2Fulfilled(value) {
  1851. assert.strictEqual(value, sentinel);
  1852. done();
  1853. });
  1854. });
  1855. });
  1856. }
  1857. testNonFunction(undefined, "`undefined`");
  1858. testNonFunction(null, "`null`");
  1859. testNonFunction(false, "`false`");
  1860. testNonFunction(5, "`5`");
  1861. testNonFunction({}, "an object");
  1862. testNonFunction([function () { return other; }], "an array containing a function");
  1863. });
  1864. describe("2.2.7.4: If `onRejected` is not a function and `promise1` is rejected, `promise2` must be rejected " +
  1865. "with the same reason.", function () {
  1866. function testNonFunction(nonFunction, stringRepresentation) {
  1867. describe("`onRejected` is " + stringRepresentation, function () {
  1868. testRejected(sentinel, function (promise1, done) {
  1869. var promise2 = promise1.then(null, nonFunction);
  1870. promise2.then(null, function onPromise2Rejected(reason) {
  1871. assert.strictEqual(reason, sentinel);
  1872. done();
  1873. });
  1874. });
  1875. });
  1876. }
  1877. testNonFunction(undefined, "`undefined`");
  1878. testNonFunction(null, "`null`");
  1879. testNonFunction(false, "`false`");
  1880. testNonFunction(5, "`5`");
  1881. testNonFunction({}, "an object");
  1882. testNonFunction([function () { return other; }], "an array containing a function");
  1883. });
  1884. });
  1885. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1886. },{"./helpers/reasons":21,"./helpers/testThreeCases":22,"assert":2}],17:[function(require,module,exports){
  1887. (function (global){
  1888. "use strict";
  1889. var assert = require("assert");
  1890. var adapter = global.adapter;
  1891. var resolved = adapter.resolved;
  1892. var rejected = adapter.rejected;
  1893. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  1894. describe("2.3.1: If `promise` and `x` refer to the same object, reject `promise` with a `TypeError' as the reason.",
  1895. function () {
  1896. specify("via return from a fulfilled promise", function (done) {
  1897. var promise = resolved(dummy).then(function () {
  1898. return promise;
  1899. });
  1900. promise.then(null, function (reason) {
  1901. assert(reason instanceof TypeError);
  1902. done();
  1903. });
  1904. });
  1905. specify("via return from a rejected promise", function (done) {
  1906. var promise = rejected(dummy).then(null, function () {
  1907. return promise;
  1908. });
  1909. promise.then(null, function (reason) {
  1910. assert(reason instanceof TypeError);
  1911. done();
  1912. });
  1913. });
  1914. });
  1915. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1916. },{"assert":2}],18:[function(require,module,exports){
  1917. (function (global){
  1918. "use strict";
  1919. var assert = require("assert");
  1920. var adapter = global.adapter;
  1921. var resolved = adapter.resolved;
  1922. var rejected = adapter.rejected;
  1923. var deferred = adapter.deferred;
  1924. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  1925. var sentinel = { sentinel: "sentinel" }; // a sentinel fulfillment value to test for with strict equality
  1926. function testPromiseResolution(xFactory, test) {
  1927. specify("via return from a fulfilled promise", function (done) {
  1928. var promise = resolved(dummy).then(function onBasePromiseFulfilled() {
  1929. return xFactory();
  1930. });
  1931. test(promise, done);
  1932. });
  1933. specify("via return from a rejected promise", function (done) {
  1934. var promise = rejected(dummy).then(null, function onBasePromiseRejected() {
  1935. return xFactory();
  1936. });
  1937. test(promise, done);
  1938. });
  1939. }
  1940. describe("2.3.2: If `x` is a promise, adopt its state", function () {
  1941. describe("2.3.2.1: If `x` is pending, `promise` must remain pending until `x` is fulfilled or rejected.",
  1942. function () {
  1943. function xFactory() {
  1944. return deferred().promise;
  1945. }
  1946. testPromiseResolution(xFactory, function (promise, done) {
  1947. var wasFulfilled = false;
  1948. var wasRejected = false;
  1949. promise.then(
  1950. function onPromiseFulfilled() {
  1951. wasFulfilled = true;
  1952. },
  1953. function onPromiseRejected() {
  1954. wasRejected = true;
  1955. }
  1956. );
  1957. setTimeout(function () {
  1958. assert.strictEqual(wasFulfilled, false);
  1959. assert.strictEqual(wasRejected, false);
  1960. done();
  1961. }, 100);
  1962. });
  1963. });
  1964. describe("2.3.2.2: If/when `x` is fulfilled, fulfill `promise` with the same value.", function () {
  1965. describe("`x` is already-fulfilled", function () {
  1966. function xFactory() {
  1967. return resolved(sentinel);
  1968. }
  1969. testPromiseResolution(xFactory, function (promise, done) {
  1970. promise.then(function onPromiseFulfilled(value) {
  1971. assert.strictEqual(value, sentinel);
  1972. done();
  1973. });
  1974. });
  1975. });
  1976. describe("`x` is eventually-fulfilled", function () {
  1977. var d = null;
  1978. function xFactory() {
  1979. d = deferred();
  1980. setTimeout(function () {
  1981. d.resolve(sentinel);
  1982. }, 50);
  1983. return d.promise;
  1984. }
  1985. testPromiseResolution(xFactory, function (promise, done) {
  1986. promise.then(function onPromiseFulfilled(value) {
  1987. assert.strictEqual(value, sentinel);
  1988. done();
  1989. });
  1990. });
  1991. });
  1992. });
  1993. describe("2.3.2.3: If/when `x` is rejected, reject `promise` with the same reason.", function () {
  1994. describe("`x` is already-rejected", function () {
  1995. function xFactory() {
  1996. return rejected(sentinel);
  1997. }
  1998. testPromiseResolution(xFactory, function (promise, done) {
  1999. promise.then(null, function onPromiseRejected(reason) {
  2000. assert.strictEqual(reason, sentinel);
  2001. done();
  2002. });
  2003. });
  2004. });
  2005. describe("`x` is eventually-rejected", function () {
  2006. var d = null;
  2007. function xFactory() {
  2008. d = deferred();
  2009. setTimeout(function () {
  2010. d.reject(sentinel);
  2011. }, 50);
  2012. return d.promise;
  2013. }
  2014. testPromiseResolution(xFactory, function (promise, done) {
  2015. promise.then(null, function onPromiseRejected(reason) {
  2016. assert.strictEqual(reason, sentinel);
  2017. done();
  2018. });
  2019. });
  2020. });
  2021. });
  2022. });
  2023. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2024. },{"assert":2}],19:[function(require,module,exports){
  2025. (function (global){
  2026. "use strict";
  2027. var assert = require("assert");
  2028. var thenables = require("./helpers/thenables");
  2029. var reasons = require("./helpers/reasons");
  2030. var adapter = global.adapter;
  2031. var resolved = adapter.resolved;
  2032. var rejected = adapter.rejected;
  2033. var deferred = adapter.deferred;
  2034. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  2035. var sentinel = { sentinel: "sentinel" }; // a sentinel fulfillment value to test for with strict equality
  2036. var other = { other: "other" }; // a value we don't want to be strict equal to
  2037. var sentinelArray = [sentinel]; // a sentinel fulfillment value to test when we need an array
  2038. function testPromiseResolution(xFactory, test) {
  2039. specify("via return from a fulfilled promise", function (done) {
  2040. var promise = resolved(dummy).then(function onBasePromiseFulfilled() {
  2041. return xFactory();
  2042. });
  2043. test(promise, done);
  2044. });
  2045. specify("via return from a rejected promise", function (done) {
  2046. var promise = rejected(dummy).then(null, function onBasePromiseRejected() {
  2047. return xFactory();
  2048. });
  2049. test(promise, done);
  2050. });
  2051. }
  2052. function testCallingResolvePromise(yFactory, stringRepresentation, test) {
  2053. describe("`y` is " + stringRepresentation, function () {
  2054. describe("`then` calls `resolvePromise` synchronously", function () {
  2055. function xFactory() {
  2056. return {
  2057. then: function (resolvePromise) {
  2058. resolvePromise(yFactory());
  2059. }
  2060. };
  2061. }
  2062. testPromiseResolution(xFactory, test);
  2063. });
  2064. describe("`then` calls `resolvePromise` asynchronously", function () {
  2065. function xFactory() {
  2066. return {
  2067. then: function (resolvePromise) {
  2068. setTimeout(function () {
  2069. resolvePromise(yFactory());
  2070. }, 0);
  2071. }
  2072. };
  2073. }
  2074. testPromiseResolution(xFactory, test);
  2075. });
  2076. });
  2077. }
  2078. function testCallingRejectPromise(r, stringRepresentation, test) {
  2079. describe("`r` is " + stringRepresentation, function () {
  2080. describe("`then` calls `rejectPromise` synchronously", function () {
  2081. function xFactory() {
  2082. return {
  2083. then: function (resolvePromise, rejectPromise) {
  2084. rejectPromise(r);
  2085. }
  2086. };
  2087. }
  2088. testPromiseResolution(xFactory, test);
  2089. });
  2090. describe("`then` calls `rejectPromise` asynchronously", function () {
  2091. function xFactory() {
  2092. return {
  2093. then: function (resolvePromise, rejectPromise) {
  2094. setTimeout(function () {
  2095. rejectPromise(r);
  2096. }, 0);
  2097. }
  2098. };
  2099. }
  2100. testPromiseResolution(xFactory, test);
  2101. });
  2102. });
  2103. }
  2104. function testCallingResolvePromiseFulfillsWith(yFactory, stringRepresentation, fulfillmentValue) {
  2105. testCallingResolvePromise(yFactory, stringRepresentation, function (promise, done) {
  2106. promise.then(function onPromiseFulfilled(value) {
  2107. assert.strictEqual(value, fulfillmentValue);
  2108. done();
  2109. });
  2110. });
  2111. }
  2112. function testCallingResolvePromiseRejectsWith(yFactory, stringRepresentation, rejectionReason) {
  2113. testCallingResolvePromise(yFactory, stringRepresentation, function (promise, done) {
  2114. promise.then(null, function onPromiseRejected(reason) {
  2115. assert.strictEqual(reason, rejectionReason);
  2116. done();
  2117. });
  2118. });
  2119. }
  2120. function testCallingRejectPromiseRejectsWith(reason, stringRepresentation) {
  2121. testCallingRejectPromise(reason, stringRepresentation, function (promise, done) {
  2122. promise.then(null, function onPromiseRejected(rejectionReason) {
  2123. assert.strictEqual(rejectionReason, reason);
  2124. done();
  2125. });
  2126. });
  2127. }
  2128. describe("2.3.3: Otherwise, if `x` is an object or function,", function () {
  2129. describe("2.3.3.1: Let `then` be `x.then`", function () {
  2130. describe("`x` is an object with null prototype", function () {
  2131. var numberOfTimesThenWasRetrieved = null;
  2132. beforeEach(function () {
  2133. numberOfTimesThenWasRetrieved = 0;
  2134. });
  2135. function xFactory() {
  2136. return Object.create(null, {
  2137. then: {
  2138. get: function () {
  2139. ++numberOfTimesThenWasRetrieved;
  2140. return function thenMethodForX(onFulfilled) {
  2141. onFulfilled();
  2142. };
  2143. }
  2144. }
  2145. });
  2146. }
  2147. testPromiseResolution(xFactory, function (promise, done) {
  2148. promise.then(function () {
  2149. assert.strictEqual(numberOfTimesThenWasRetrieved, 1);
  2150. done();
  2151. });
  2152. });
  2153. });
  2154. describe("`x` is an object with normal Object.prototype", function () {
  2155. var numberOfTimesThenWasRetrieved = null;
  2156. beforeEach(function () {
  2157. numberOfTimesThenWasRetrieved = 0;
  2158. });
  2159. function xFactory() {
  2160. return Object.create(Object.prototype, {
  2161. then: {
  2162. get: function () {
  2163. ++numberOfTimesThenWasRetrieved;
  2164. return function thenMethodForX(onFulfilled) {
  2165. onFulfilled();
  2166. };
  2167. }
  2168. }
  2169. });
  2170. }
  2171. testPromiseResolution(xFactory, function (promise, done) {
  2172. promise.then(function () {
  2173. assert.strictEqual(numberOfTimesThenWasRetrieved, 1);
  2174. done();
  2175. });
  2176. });
  2177. });
  2178. describe("`x` is a function", function () {
  2179. var numberOfTimesThenWasRetrieved = null;
  2180. beforeEach(function () {
  2181. numberOfTimesThenWasRetrieved = 0;
  2182. });
  2183. function xFactory() {
  2184. function x() { }
  2185. Object.defineProperty(x, "then", {
  2186. get: function () {
  2187. ++numberOfTimesThenWasRetrieved;
  2188. return function thenMethodForX(onFulfilled) {
  2189. onFulfilled();
  2190. };
  2191. }
  2192. });
  2193. return x;
  2194. }
  2195. testPromiseResolution(xFactory, function (promise, done) {
  2196. promise.then(function () {
  2197. assert.strictEqual(numberOfTimesThenWasRetrieved, 1);
  2198. done();
  2199. });
  2200. });
  2201. });
  2202. });
  2203. describe("2.3.3.2: If retrieving the property `x.then` results in a thrown exception `e`, reject `promise` with " +
  2204. "`e` as the reason.", function () {
  2205. function testRejectionViaThrowingGetter(e, stringRepresentation) {
  2206. function xFactory() {
  2207. return Object.create(Object.prototype, {
  2208. then: {
  2209. get: function () {
  2210. throw e;
  2211. }
  2212. }
  2213. });
  2214. }
  2215. describe("`e` is " + stringRepresentation, function () {
  2216. testPromiseResolution(xFactory, function (promise, done) {
  2217. promise.then(null, function (reason) {
  2218. assert.strictEqual(reason, e);
  2219. done();
  2220. });
  2221. });
  2222. });
  2223. }
  2224. Object.keys(reasons).forEach(function (stringRepresentation) {
  2225. testRejectionViaThrowingGetter(reasons[stringRepresentation], stringRepresentation);
  2226. });
  2227. });
  2228. describe("2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and " +
  2229. "second argument `rejectPromise`", function () {
  2230. describe("Calls with `x` as `this` and two function arguments", function () {
  2231. function xFactory() {
  2232. var x = {
  2233. then: function (onFulfilled, onRejected) {
  2234. assert.strictEqual(this, x);
  2235. assert.strictEqual(typeof onFulfilled, "function");
  2236. assert.strictEqual(typeof onRejected, "function");
  2237. onFulfilled();
  2238. }
  2239. };
  2240. return x;
  2241. }
  2242. testPromiseResolution(xFactory, function (promise, done) {
  2243. promise.then(function () {
  2244. done();
  2245. });
  2246. });
  2247. });
  2248. describe("Uses the original value of `then`", function () {
  2249. var numberOfTimesThenWasRetrieved = null;
  2250. beforeEach(function () {
  2251. numberOfTimesThenWasRetrieved = 0;
  2252. });
  2253. function xFactory() {
  2254. return Object.create(Object.prototype, {
  2255. then: {
  2256. get: function () {
  2257. if (numberOfTimesThenWasRetrieved === 0) {
  2258. return function (onFulfilled) {
  2259. onFulfilled();
  2260. };
  2261. }
  2262. return null;
  2263. }
  2264. }
  2265. });
  2266. }
  2267. testPromiseResolution(xFactory, function (promise, done) {
  2268. promise.then(function () {
  2269. done();
  2270. });
  2271. });
  2272. });
  2273. describe("2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)`",
  2274. function () {
  2275. describe("`y` is not a thenable", function () {
  2276. testCallingResolvePromiseFulfillsWith(function () { return undefined; }, "`undefined`", undefined);
  2277. testCallingResolvePromiseFulfillsWith(function () { return null; }, "`null`", null);
  2278. testCallingResolvePromiseFulfillsWith(function () { return false; }, "`false`", false);
  2279. testCallingResolvePromiseFulfillsWith(function () { return 5; }, "`5`", 5);
  2280. testCallingResolvePromiseFulfillsWith(function () { return sentinel; }, "an object", sentinel);
  2281. testCallingResolvePromiseFulfillsWith(function () { return sentinelArray; }, "an array", sentinelArray);
  2282. });
  2283. describe("`y` is a thenable", function () {
  2284. Object.keys(thenables.fulfilled).forEach(function (stringRepresentation) {
  2285. function yFactory() {
  2286. return thenables.fulfilled[stringRepresentation](sentinel);
  2287. }
  2288. testCallingResolvePromiseFulfillsWith(yFactory, stringRepresentation, sentinel);
  2289. });
  2290. Object.keys(thenables.rejected).forEach(function (stringRepresentation) {
  2291. function yFactory() {
  2292. return thenables.rejected[stringRepresentation](sentinel);
  2293. }
  2294. testCallingResolvePromiseRejectsWith(yFactory, stringRepresentation, sentinel);
  2295. });
  2296. });
  2297. describe("`y` is a thenable for a thenable", function () {
  2298. Object.keys(thenables.fulfilled).forEach(function (outerStringRepresentation) {
  2299. var outerThenableFactory = thenables.fulfilled[outerStringRepresentation];
  2300. Object.keys(thenables.fulfilled).forEach(function (innerStringRepresentation) {
  2301. var innerThenableFactory = thenables.fulfilled[innerStringRepresentation];
  2302. var stringRepresentation = outerStringRepresentation + " for " + innerStringRepresentation;
  2303. function yFactory() {
  2304. return outerThenableFactory(innerThenableFactory(sentinel));
  2305. }
  2306. testCallingResolvePromiseFulfillsWith(yFactory, stringRepresentation, sentinel);
  2307. });
  2308. Object.keys(thenables.rejected).forEach(function (innerStringRepresentation) {
  2309. var innerThenableFactory = thenables.rejected[innerStringRepresentation];
  2310. var stringRepresentation = outerStringRepresentation + " for " + innerStringRepresentation;
  2311. function yFactory() {
  2312. return outerThenableFactory(innerThenableFactory(sentinel));
  2313. }
  2314. testCallingResolvePromiseRejectsWith(yFactory, stringRepresentation, sentinel);
  2315. });
  2316. });
  2317. });
  2318. });
  2319. describe("2.3.3.3.2: If/when `rejectPromise` is called with reason `r`, reject `promise` with `r`",
  2320. function () {
  2321. Object.keys(reasons).forEach(function (stringRepresentation) {
  2322. testCallingRejectPromiseRejectsWith(reasons[stringRepresentation], stringRepresentation);
  2323. });
  2324. });
  2325. describe("2.3.3.3.3: If both `resolvePromise` and `rejectPromise` are called, or multiple calls to the same " +
  2326. "argument are made, the first call takes precedence, and any further calls are ignored.",
  2327. function () {
  2328. describe("calling `resolvePromise` then `rejectPromise`, both synchronously", function () {
  2329. function xFactory() {
  2330. return {
  2331. then: function (resolvePromise, rejectPromise) {
  2332. resolvePromise(sentinel);
  2333. rejectPromise(other);
  2334. }
  2335. };
  2336. }
  2337. testPromiseResolution(xFactory, function (promise, done) {
  2338. promise.then(function (value) {
  2339. assert.strictEqual(value, sentinel);
  2340. done();
  2341. });
  2342. });
  2343. });
  2344. describe("calling `resolvePromise` synchronously then `rejectPromise` asynchronously", function () {
  2345. function xFactory() {
  2346. return {
  2347. then: function (resolvePromise, rejectPromise) {
  2348. resolvePromise(sentinel);
  2349. setTimeout(function () {
  2350. rejectPromise(other);
  2351. }, 0);
  2352. }
  2353. };
  2354. }
  2355. testPromiseResolution(xFactory, function (promise, done) {
  2356. promise.then(function (value) {
  2357. assert.strictEqual(value, sentinel);
  2358. done();
  2359. });
  2360. });
  2361. });
  2362. describe("calling `resolvePromise` then `rejectPromise`, both asynchronously", function () {
  2363. function xFactory() {
  2364. return {
  2365. then: function (resolvePromise, rejectPromise) {
  2366. setTimeout(function () {
  2367. resolvePromise(sentinel);
  2368. }, 0);
  2369. setTimeout(function () {
  2370. rejectPromise(other);
  2371. }, 0);
  2372. }
  2373. };
  2374. }
  2375. testPromiseResolution(xFactory, function (promise, done) {
  2376. promise.then(function (value) {
  2377. assert.strictEqual(value, sentinel);
  2378. done();
  2379. });
  2380. });
  2381. });
  2382. describe("calling `resolvePromise` with an asynchronously-fulfilled promise, then calling " +
  2383. "`rejectPromise`, both synchronously", function () {
  2384. function xFactory() {
  2385. var d = deferred();
  2386. setTimeout(function () {
  2387. d.resolve(sentinel);
  2388. }, 50);
  2389. return {
  2390. then: function (resolvePromise, rejectPromise) {
  2391. resolvePromise(d.promise);
  2392. rejectPromise(other);
  2393. }
  2394. };
  2395. }
  2396. testPromiseResolution(xFactory, function (promise, done) {
  2397. promise.then(function (value) {
  2398. assert.strictEqual(value, sentinel);
  2399. done();
  2400. });
  2401. });
  2402. });
  2403. describe("calling `resolvePromise` with an asynchronously-rejected promise, then calling " +
  2404. "`rejectPromise`, both synchronously", function () {
  2405. function xFactory() {
  2406. var d = deferred();
  2407. setTimeout(function () {
  2408. d.reject(sentinel);
  2409. }, 50);
  2410. return {
  2411. then: function (resolvePromise, rejectPromise) {
  2412. resolvePromise(d.promise);
  2413. rejectPromise(other);
  2414. }
  2415. };
  2416. }
  2417. testPromiseResolution(xFactory, function (promise, done) {
  2418. promise.then(null, function (reason) {
  2419. assert.strictEqual(reason, sentinel);
  2420. done();
  2421. });
  2422. });
  2423. });
  2424. describe("calling `rejectPromise` then `resolvePromise`, both synchronously", function () {
  2425. function xFactory() {
  2426. return {
  2427. then: function (resolvePromise, rejectPromise) {
  2428. rejectPromise(sentinel);
  2429. resolvePromise(other);
  2430. }
  2431. };
  2432. }
  2433. testPromiseResolution(xFactory, function (promise, done) {
  2434. promise.then(null, function (reason) {
  2435. assert.strictEqual(reason, sentinel);
  2436. done();
  2437. });
  2438. });
  2439. });
  2440. describe("calling `rejectPromise` synchronously then `resolvePromise` asynchronously", function () {
  2441. function xFactory() {
  2442. return {
  2443. then: function (resolvePromise, rejectPromise) {
  2444. rejectPromise(sentinel);
  2445. setTimeout(function () {
  2446. resolvePromise(other);
  2447. }, 0);
  2448. }
  2449. };
  2450. }
  2451. testPromiseResolution(xFactory, function (promise, done) {
  2452. promise.then(null, function (reason) {
  2453. assert.strictEqual(reason, sentinel);
  2454. done();
  2455. });
  2456. });
  2457. });
  2458. describe("calling `rejectPromise` then `resolvePromise`, both asynchronously", function () {
  2459. function xFactory() {
  2460. return {
  2461. then: function (resolvePromise, rejectPromise) {
  2462. setTimeout(function () {
  2463. rejectPromise(sentinel);
  2464. }, 0);
  2465. setTimeout(function () {
  2466. resolvePromise(other);
  2467. }, 0);
  2468. }
  2469. };
  2470. }
  2471. testPromiseResolution(xFactory, function (promise, done) {
  2472. promise.then(null, function (reason) {
  2473. assert.strictEqual(reason, sentinel);
  2474. done();
  2475. });
  2476. });
  2477. });
  2478. describe("calling `resolvePromise` twice synchronously", function () {
  2479. function xFactory() {
  2480. return {
  2481. then: function (resolvePromise) {
  2482. resolvePromise(sentinel);
  2483. resolvePromise(other);
  2484. }
  2485. };
  2486. }
  2487. testPromiseResolution(xFactory, function (promise, done) {
  2488. promise.then(function (value) {
  2489. assert.strictEqual(value, sentinel);
  2490. done();
  2491. });
  2492. });
  2493. });
  2494. describe("calling `resolvePromise` twice, first synchronously then asynchronously", function () {
  2495. function xFactory() {
  2496. return {
  2497. then: function (resolvePromise) {
  2498. resolvePromise(sentinel);
  2499. setTimeout(function () {
  2500. resolvePromise(other);
  2501. }, 0);
  2502. }
  2503. };
  2504. }
  2505. testPromiseResolution(xFactory, function (promise, done) {
  2506. promise.then(function (value) {
  2507. assert.strictEqual(value, sentinel);
  2508. done();
  2509. });
  2510. });
  2511. });
  2512. describe("calling `resolvePromise` twice, both times asynchronously", function () {
  2513. function xFactory() {
  2514. return {
  2515. then: function (resolvePromise) {
  2516. setTimeout(function () {
  2517. resolvePromise(sentinel);
  2518. }, 0);
  2519. setTimeout(function () {
  2520. resolvePromise(other);
  2521. }, 0);
  2522. }
  2523. };
  2524. }
  2525. testPromiseResolution(xFactory, function (promise, done) {
  2526. promise.then(function (value) {
  2527. assert.strictEqual(value, sentinel);
  2528. done();
  2529. });
  2530. });
  2531. });
  2532. describe("calling `resolvePromise` with an asynchronously-fulfilled promise, then calling it again, both " +
  2533. "times synchronously", function () {
  2534. function xFactory() {
  2535. var d = deferred();
  2536. setTimeout(function () {
  2537. d.resolve(sentinel);
  2538. }, 50);
  2539. return {
  2540. then: function (resolvePromise) {
  2541. resolvePromise(d.promise);
  2542. resolvePromise(other);
  2543. }
  2544. };
  2545. }
  2546. testPromiseResolution(xFactory, function (promise, done) {
  2547. promise.then(function (value) {
  2548. assert.strictEqual(value, sentinel);
  2549. done();
  2550. });
  2551. });
  2552. });
  2553. describe("calling `resolvePromise` with an asynchronously-rejected promise, then calling it again, both " +
  2554. "times synchronously", function () {
  2555. function xFactory() {
  2556. var d = deferred();
  2557. setTimeout(function () {
  2558. d.reject(sentinel);
  2559. }, 50);
  2560. return {
  2561. then: function (resolvePromise) {
  2562. resolvePromise(d.promise);
  2563. resolvePromise(other);
  2564. }
  2565. };
  2566. }
  2567. testPromiseResolution(xFactory, function (promise, done) {
  2568. promise.then(null, function (reason) {
  2569. assert.strictEqual(reason, sentinel);
  2570. done();
  2571. });
  2572. });
  2573. });
  2574. describe("calling `rejectPromise` twice synchronously", function () {
  2575. function xFactory() {
  2576. return {
  2577. then: function (resolvePromise, rejectPromise) {
  2578. rejectPromise(sentinel);
  2579. rejectPromise(other);
  2580. }
  2581. };
  2582. }
  2583. testPromiseResolution(xFactory, function (promise, done) {
  2584. promise.then(null, function (reason) {
  2585. assert.strictEqual(reason, sentinel);
  2586. done();
  2587. });
  2588. });
  2589. });
  2590. describe("calling `rejectPromise` twice, first synchronously then asynchronously", function () {
  2591. function xFactory() {
  2592. return {
  2593. then: function (resolvePromise, rejectPromise) {
  2594. rejectPromise(sentinel);
  2595. setTimeout(function () {
  2596. rejectPromise(other);
  2597. }, 0);
  2598. }
  2599. };
  2600. }
  2601. testPromiseResolution(xFactory, function (promise, done) {
  2602. promise.then(null, function (reason) {
  2603. assert.strictEqual(reason, sentinel);
  2604. done();
  2605. });
  2606. });
  2607. });
  2608. describe("calling `rejectPromise` twice, both times asynchronously", function () {
  2609. function xFactory() {
  2610. return {
  2611. then: function (resolvePromise, rejectPromise) {
  2612. setTimeout(function () {
  2613. rejectPromise(sentinel);
  2614. }, 0);
  2615. setTimeout(function () {
  2616. rejectPromise(other);
  2617. }, 0);
  2618. }
  2619. };
  2620. }
  2621. testPromiseResolution(xFactory, function (promise, done) {
  2622. promise.then(null, function (reason) {
  2623. assert.strictEqual(reason, sentinel);
  2624. done();
  2625. });
  2626. });
  2627. });
  2628. describe("saving and abusing `resolvePromise` and `rejectPromise`", function () {
  2629. var savedResolvePromise, savedRejectPromise;
  2630. function xFactory() {
  2631. return {
  2632. then: function (resolvePromise, rejectPromise) {
  2633. savedResolvePromise = resolvePromise;
  2634. savedRejectPromise = rejectPromise;
  2635. }
  2636. };
  2637. }
  2638. beforeEach(function () {
  2639. savedResolvePromise = null;
  2640. savedRejectPromise = null;
  2641. });
  2642. testPromiseResolution(xFactory, function (promise, done) {
  2643. var timesFulfilled = 0;
  2644. var timesRejected = 0;
  2645. promise.then(
  2646. function () {
  2647. ++timesFulfilled;
  2648. },
  2649. function () {
  2650. ++timesRejected;
  2651. }
  2652. );
  2653. if (savedResolvePromise && savedRejectPromise) {
  2654. savedResolvePromise(dummy);
  2655. savedResolvePromise(dummy);
  2656. savedRejectPromise(dummy);
  2657. savedRejectPromise(dummy);
  2658. }
  2659. setTimeout(function () {
  2660. savedResolvePromise(dummy);
  2661. savedResolvePromise(dummy);
  2662. savedRejectPromise(dummy);
  2663. savedRejectPromise(dummy);
  2664. }, 50);
  2665. setTimeout(function () {
  2666. assert.strictEqual(timesFulfilled, 1);
  2667. assert.strictEqual(timesRejected, 0);
  2668. done();
  2669. }, 100);
  2670. });
  2671. });
  2672. });
  2673. describe("2.3.3.3.4: If calling `then` throws an exception `e`,", function () {
  2674. describe("2.3.3.3.4.1: If `resolvePromise` or `rejectPromise` have been called, ignore it.", function () {
  2675. describe("`resolvePromise` was called with a non-thenable", function () {
  2676. function xFactory() {
  2677. return {
  2678. then: function (resolvePromise) {
  2679. resolvePromise(sentinel);
  2680. throw other;
  2681. }
  2682. };
  2683. }
  2684. testPromiseResolution(xFactory, function (promise, done) {
  2685. promise.then(function (value) {
  2686. assert.strictEqual(value, sentinel);
  2687. done();
  2688. });
  2689. });
  2690. });
  2691. describe("`resolvePromise` was called with an asynchronously-fulfilled promise", function () {
  2692. function xFactory() {
  2693. var d = deferred();
  2694. setTimeout(function () {
  2695. d.resolve(sentinel);
  2696. }, 50);
  2697. return {
  2698. then: function (resolvePromise) {
  2699. resolvePromise(d.promise);
  2700. throw other;
  2701. }
  2702. };
  2703. }
  2704. testPromiseResolution(xFactory, function (promise, done) {
  2705. promise.then(function (value) {
  2706. assert.strictEqual(value, sentinel);
  2707. done();
  2708. });
  2709. });
  2710. });
  2711. describe("`resolvePromise` was called with an asynchronously-rejected promise", function () {
  2712. function xFactory() {
  2713. var d = deferred();
  2714. setTimeout(function () {
  2715. d.reject(sentinel);
  2716. }, 50);
  2717. return {
  2718. then: function (resolvePromise) {
  2719. resolvePromise(d.promise);
  2720. throw other;
  2721. }
  2722. };
  2723. }
  2724. testPromiseResolution(xFactory, function (promise, done) {
  2725. promise.then(null, function (reason) {
  2726. assert.strictEqual(reason, sentinel);
  2727. done();
  2728. });
  2729. });
  2730. });
  2731. describe("`rejectPromise` was called", function () {
  2732. function xFactory() {
  2733. return {
  2734. then: function (resolvePromise, rejectPromise) {
  2735. rejectPromise(sentinel);
  2736. throw other;
  2737. }
  2738. };
  2739. }
  2740. testPromiseResolution(xFactory, function (promise, done) {
  2741. promise.then(null, function (reason) {
  2742. assert.strictEqual(reason, sentinel);
  2743. done();
  2744. });
  2745. });
  2746. });
  2747. describe("`resolvePromise` then `rejectPromise` were called", function () {
  2748. function xFactory() {
  2749. return {
  2750. then: function (resolvePromise, rejectPromise) {
  2751. resolvePromise(sentinel);
  2752. rejectPromise(other);
  2753. throw other;
  2754. }
  2755. };
  2756. }
  2757. testPromiseResolution(xFactory, function (promise, done) {
  2758. promise.then(function (value) {
  2759. assert.strictEqual(value, sentinel);
  2760. done();
  2761. });
  2762. });
  2763. });
  2764. describe("`rejectPromise` then `resolvePromise` were called", function () {
  2765. function xFactory() {
  2766. return {
  2767. then: function (resolvePromise, rejectPromise) {
  2768. rejectPromise(sentinel);
  2769. resolvePromise(other);
  2770. throw other;
  2771. }
  2772. };
  2773. }
  2774. testPromiseResolution(xFactory, function (promise, done) {
  2775. promise.then(null, function (reason) {
  2776. assert.strictEqual(reason, sentinel);
  2777. done();
  2778. });
  2779. });
  2780. });
  2781. });
  2782. describe("2.3.3.3.4.2: Otherwise, reject `promise` with `e` as the reason.", function () {
  2783. describe("straightforward case", function () {
  2784. function xFactory() {
  2785. return {
  2786. then: function () {
  2787. throw sentinel;
  2788. }
  2789. };
  2790. }
  2791. testPromiseResolution(xFactory, function (promise, done) {
  2792. promise.then(null, function (reason) {
  2793. assert.strictEqual(reason, sentinel);
  2794. done();
  2795. });
  2796. });
  2797. });
  2798. describe("`resolvePromise` is called asynchronously before the `throw`", function () {
  2799. function xFactory() {
  2800. return {
  2801. then: function (resolvePromise) {
  2802. setTimeout(function () {
  2803. resolvePromise(other);
  2804. }, 0);
  2805. throw sentinel;
  2806. }
  2807. };
  2808. }
  2809. testPromiseResolution(xFactory, function (promise, done) {
  2810. promise.then(null, function (reason) {
  2811. assert.strictEqual(reason, sentinel);
  2812. done();
  2813. });
  2814. });
  2815. });
  2816. describe("`rejectPromise` is called asynchronously before the `throw`", function () {
  2817. function xFactory() {
  2818. return {
  2819. then: function (resolvePromise, rejectPromise) {
  2820. setTimeout(function () {
  2821. rejectPromise(other);
  2822. }, 0);
  2823. throw sentinel;
  2824. }
  2825. };
  2826. }
  2827. testPromiseResolution(xFactory, function (promise, done) {
  2828. promise.then(null, function (reason) {
  2829. assert.strictEqual(reason, sentinel);
  2830. done();
  2831. });
  2832. });
  2833. });
  2834. });
  2835. });
  2836. });
  2837. describe("2.3.3.4: If `then` is not a function, fulfill promise with `x`", function () {
  2838. function testFulfillViaNonFunction(then, stringRepresentation) {
  2839. var x = null;
  2840. beforeEach(function () {
  2841. x = { then: then };
  2842. });
  2843. function xFactory() {
  2844. return x;
  2845. }
  2846. describe("`then` is " + stringRepresentation, function () {
  2847. testPromiseResolution(xFactory, function (promise, done) {
  2848. promise.then(function (value) {
  2849. assert.strictEqual(value, x);
  2850. done();
  2851. });
  2852. });
  2853. });
  2854. }
  2855. testFulfillViaNonFunction(5, "`5`");
  2856. testFulfillViaNonFunction({}, "an object");
  2857. testFulfillViaNonFunction([function () { }], "an array containing a function");
  2858. testFulfillViaNonFunction(/a-b/i, "a regular expression");
  2859. testFulfillViaNonFunction(Object.create(Function.prototype), "an object inheriting from `Function.prototype`");
  2860. });
  2861. });
  2862. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2863. },{"./helpers/reasons":21,"./helpers/thenables":23,"assert":2}],20:[function(require,module,exports){
  2864. "use strict";
  2865. var assert = require("assert");
  2866. var testFulfilled = require("./helpers/testThreeCases").testFulfilled;
  2867. var testRejected = require("./helpers/testThreeCases").testRejected;
  2868. var dummy = { dummy: "dummy" }; // we fulfill or reject with this when we don't intend to test against it
  2869. describe("2.3.4: If `x` is not an object or function, fulfill `promise` with `x`", function () {
  2870. function testValue(expectedValue, stringRepresentation, beforeEachHook, afterEachHook) {
  2871. describe("The value is " + stringRepresentation, function () {
  2872. if (typeof beforeEachHook === "function") {
  2873. beforeEach(beforeEachHook);
  2874. }
  2875. if (typeof afterEachHook === "function") {
  2876. afterEach(afterEachHook);
  2877. }
  2878. testFulfilled(dummy, function (promise1, done) {
  2879. var promise2 = promise1.then(function onFulfilled() {
  2880. return expectedValue;
  2881. });
  2882. promise2.then(function onPromise2Fulfilled(actualValue) {
  2883. assert.strictEqual(actualValue, expectedValue);
  2884. done();
  2885. });
  2886. });
  2887. testRejected(dummy, function (promise1, done) {
  2888. var promise2 = promise1.then(null, function onRejected() {
  2889. return expectedValue;
  2890. });
  2891. promise2.then(function onPromise2Fulfilled(actualValue) {
  2892. assert.strictEqual(actualValue, expectedValue);
  2893. done();
  2894. });
  2895. });
  2896. });
  2897. }
  2898. testValue(undefined, "`undefined`");
  2899. testValue(null, "`null`");
  2900. testValue(false, "`false`");
  2901. testValue(true, "`true`");
  2902. testValue(0, "`0`");
  2903. testValue(
  2904. true,
  2905. "`true` with `Boolean.prototype` modified to have a `then` method",
  2906. function () {
  2907. Boolean.prototype.then = function () {};
  2908. },
  2909. function () {
  2910. delete Boolean.prototype.then;
  2911. }
  2912. );
  2913. testValue(
  2914. 1,
  2915. "`1` with `Number.prototype` modified to have a `then` method",
  2916. function () {
  2917. Number.prototype.then = function () {};
  2918. },
  2919. function () {
  2920. delete Number.prototype.then;
  2921. }
  2922. );
  2923. });
  2924. },{"./helpers/testThreeCases":22,"assert":2}],21:[function(require,module,exports){
  2925. (function (global){
  2926. "use strict";
  2927. // This module exports some valid rejection reason factories, keyed by human-readable versions of their names.
  2928. var adapter = global.adapter;
  2929. var resolved = adapter.resolved;
  2930. var rejected = adapter.rejected;
  2931. var dummy = { dummy: "dummy" };
  2932. exports["`undefined`"] = function () {
  2933. return undefined;
  2934. };
  2935. exports["`null`"] = function () {
  2936. return null;
  2937. };
  2938. exports["`false`"] = function () {
  2939. return false;
  2940. };
  2941. exports["`0`"] = function () {
  2942. return 0;
  2943. };
  2944. exports["an error"] = function () {
  2945. return new Error();
  2946. };
  2947. exports["an error without a stack"] = function () {
  2948. var error = new Error();
  2949. delete error.stack;
  2950. return error;
  2951. };
  2952. exports["a date"] = function () {
  2953. return new Date();
  2954. };
  2955. exports["an object"] = function () {
  2956. return {};
  2957. };
  2958. exports["an always-pending thenable"] = function () {
  2959. return { then: function () { } };
  2960. };
  2961. exports["a fulfilled promise"] = function () {
  2962. return resolved(dummy);
  2963. };
  2964. exports["a rejected promise"] = function () {
  2965. return rejected(dummy);
  2966. };
  2967. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2968. },{}],22:[function(require,module,exports){
  2969. (function (global){
  2970. "use strict";
  2971. var adapter = global.adapter;
  2972. var resolved = adapter.resolved;
  2973. var rejected = adapter.rejected;
  2974. var deferred = adapter.deferred;
  2975. exports.testFulfilled = function (value, test) {
  2976. specify("already-fulfilled", function (done) {
  2977. test(resolved(value), done);
  2978. });
  2979. specify("immediately-fulfilled", function (done) {
  2980. var d = deferred();
  2981. test(d.promise, done);
  2982. d.resolve(value);
  2983. });
  2984. specify("eventually-fulfilled", function (done) {
  2985. var d = deferred();
  2986. test(d.promise, done);
  2987. setTimeout(function () {
  2988. d.resolve(value);
  2989. }, 50);
  2990. });
  2991. };
  2992. exports.testRejected = function (reason, test) {
  2993. specify("already-rejected", function (done) {
  2994. test(rejected(reason), done);
  2995. });
  2996. specify("immediately-rejected", function (done) {
  2997. var d = deferred();
  2998. test(d.promise, done);
  2999. d.reject(reason);
  3000. });
  3001. specify("eventually-rejected", function (done) {
  3002. var d = deferred();
  3003. test(d.promise, done);
  3004. setTimeout(function () {
  3005. d.reject(reason);
  3006. }, 50);
  3007. });
  3008. };
  3009. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3010. },{}],23:[function(require,module,exports){
  3011. (function (global){
  3012. "use strict";
  3013. var adapter = global.adapter;
  3014. var resolved = adapter.resolved;
  3015. var rejected = adapter.rejected;
  3016. var deferred = adapter.deferred;
  3017. var other = { other: "other" }; // a value we don't want to be strict equal to
  3018. exports.fulfilled = {
  3019. "a synchronously-fulfilled custom thenable": function (value) {
  3020. return {
  3021. then: function (onFulfilled) {
  3022. onFulfilled(value);
  3023. }
  3024. };
  3025. },
  3026. "an asynchronously-fulfilled custom thenable": function (value) {
  3027. return {
  3028. then: function (onFulfilled) {
  3029. setTimeout(function () {
  3030. onFulfilled(value);
  3031. }, 0);
  3032. }
  3033. };
  3034. },
  3035. "a synchronously-fulfilled one-time thenable": function (value) {
  3036. var numberOfTimesThenRetrieved = 0;
  3037. return Object.create(null, {
  3038. then: {
  3039. get: function () {
  3040. if (numberOfTimesThenRetrieved === 0) {
  3041. ++numberOfTimesThenRetrieved;
  3042. return function (onFulfilled) {
  3043. onFulfilled(value);
  3044. };
  3045. }
  3046. return null;
  3047. }
  3048. }
  3049. });
  3050. },
  3051. "a thenable that tries to fulfill twice": function (value) {
  3052. return {
  3053. then: function (onFulfilled) {
  3054. onFulfilled(value);
  3055. onFulfilled(other);
  3056. }
  3057. };
  3058. },
  3059. "a thenable that fulfills but then throws": function (value) {
  3060. return {
  3061. then: function (onFulfilled) {
  3062. onFulfilled(value);
  3063. throw other;
  3064. }
  3065. };
  3066. },
  3067. "an already-fulfilled promise": function (value) {
  3068. return resolved(value);
  3069. },
  3070. "an eventually-fulfilled promise": function (value) {
  3071. var d = deferred();
  3072. setTimeout(function () {
  3073. d.resolve(value);
  3074. }, 50);
  3075. return d.promise;
  3076. }
  3077. };
  3078. exports.rejected = {
  3079. "a synchronously-rejected custom thenable": function (reason) {
  3080. return {
  3081. then: function (onFulfilled, onRejected) {
  3082. onRejected(reason);
  3083. }
  3084. };
  3085. },
  3086. "an asynchronously-rejected custom thenable": function (reason) {
  3087. return {
  3088. then: function (onFulfilled, onRejected) {
  3089. setTimeout(function () {
  3090. onRejected(reason);
  3091. }, 0);
  3092. }
  3093. };
  3094. },
  3095. "a synchronously-rejected one-time thenable": function (reason) {
  3096. var numberOfTimesThenRetrieved = 0;
  3097. return Object.create(null, {
  3098. then: {
  3099. get: function () {
  3100. if (numberOfTimesThenRetrieved === 0) {
  3101. ++numberOfTimesThenRetrieved;
  3102. return function (onFulfilled, onRejected) {
  3103. onRejected(reason);
  3104. };
  3105. }
  3106. return null;
  3107. }
  3108. }
  3109. });
  3110. },
  3111. "a thenable that immediately throws in `then`": function (reason) {
  3112. return {
  3113. then: function () {
  3114. throw reason;
  3115. }
  3116. };
  3117. },
  3118. "an object with a throwing `then` accessor": function (reason) {
  3119. return Object.create(null, {
  3120. then: {
  3121. get: function () {
  3122. throw reason;
  3123. }
  3124. }
  3125. });
  3126. },
  3127. "an already-rejected promise": function (reason) {
  3128. return rejected(reason);
  3129. },
  3130. "an eventually-rejected promise": function (reason) {
  3131. var d = deferred();
  3132. setTimeout(function () {
  3133. d.reject(reason);
  3134. }, 50);
  3135. return d.promise;
  3136. }
  3137. };
  3138. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3139. },{}],24:[function(require,module,exports){
  3140. /**
  3141. * Sinon core utilities. For internal use only.
  3142. *
  3143. * @author Christian Johansen (christian@cjohansen.no)
  3144. * @license BSD
  3145. *
  3146. * Copyright (c) 2010-2013 Christian Johansen
  3147. */
  3148. "use strict";
  3149. var sinon = (function () {
  3150. var sinon;
  3151. var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
  3152. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  3153. function loadDependencies(require, exports, module) {
  3154. sinon = module.exports = require("./sinon/util/core");
  3155. require("./sinon/extend");
  3156. require("./sinon/typeOf");
  3157. require("./sinon/times_in_words");
  3158. require("./sinon/spy");
  3159. require("./sinon/call");
  3160. require("./sinon/behavior");
  3161. require("./sinon/stub");
  3162. require("./sinon/mock");
  3163. require("./sinon/collection");
  3164. require("./sinon/assert");
  3165. require("./sinon/sandbox");
  3166. require("./sinon/test");
  3167. require("./sinon/test_case");
  3168. require("./sinon/match");
  3169. require("./sinon/format");
  3170. require("./sinon/log_error");
  3171. }
  3172. if (isAMD) {
  3173. define(loadDependencies);
  3174. } else if (isNode) {
  3175. loadDependencies(require, module.exports, module);
  3176. sinon = module.exports;
  3177. } else {
  3178. sinon = {};
  3179. }
  3180. return sinon;
  3181. }());
  3182. },{"./sinon/assert":25,"./sinon/behavior":26,"./sinon/call":27,"./sinon/collection":28,"./sinon/extend":29,"./sinon/format":30,"./sinon/log_error":31,"./sinon/match":32,"./sinon/mock":33,"./sinon/sandbox":34,"./sinon/spy":35,"./sinon/stub":36,"./sinon/test":37,"./sinon/test_case":38,"./sinon/times_in_words":39,"./sinon/typeOf":40,"./sinon/util/core":41}],25:[function(require,module,exports){
  3183. (function (global){
  3184. /**
  3185. * @depend times_in_words.js
  3186. * @depend util/core.js
  3187. * @depend match.js
  3188. * @depend format.js
  3189. */
  3190. /**
  3191. * Assertions matching the test spy retrieval interface.
  3192. *
  3193. * @author Christian Johansen (christian@cjohansen.no)
  3194. * @license BSD
  3195. *
  3196. * Copyright (c) 2010-2013 Christian Johansen
  3197. */
  3198. "use strict";
  3199. (function (sinon, global) {
  3200. var slice = Array.prototype.slice;
  3201. function makeApi(sinon) {
  3202. var assert;
  3203. function verifyIsStub() {
  3204. var method;
  3205. for (var i = 0, l = arguments.length; i < l; ++i) {
  3206. method = arguments[i];
  3207. if (!method) {
  3208. assert.fail("fake is not a spy");
  3209. }
  3210. if (method.proxy) {
  3211. verifyIsStub(method.proxy);
  3212. } else {
  3213. if (typeof method != "function") {
  3214. assert.fail(method + " is not a function");
  3215. }
  3216. if (typeof method.getCall != "function") {
  3217. assert.fail(method + " is not stubbed");
  3218. }
  3219. }
  3220. }
  3221. }
  3222. function failAssertion(object, msg) {
  3223. object = object || global;
  3224. var failMethod = object.fail || assert.fail;
  3225. failMethod.call(object, msg);
  3226. }
  3227. function mirrorPropAsAssertion(name, method, message) {
  3228. if (arguments.length == 2) {
  3229. message = method;
  3230. method = name;
  3231. }
  3232. assert[name] = function (fake) {
  3233. verifyIsStub(fake);
  3234. var args = slice.call(arguments, 1);
  3235. var failed = false;
  3236. if (typeof method == "function") {
  3237. failed = !method(fake);
  3238. } else {
  3239. failed = typeof fake[method] == "function" ?
  3240. !fake[method].apply(fake, args) : !fake[method];
  3241. }
  3242. if (failed) {
  3243. failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, [message].concat(args)));
  3244. } else {
  3245. assert.pass(name);
  3246. }
  3247. };
  3248. }
  3249. function exposedName(prefix, prop) {
  3250. return !prefix || /^fail/.test(prop) ? prop :
  3251. prefix + prop.slice(0, 1).toUpperCase() + prop.slice(1);
  3252. }
  3253. assert = {
  3254. failException: "AssertError",
  3255. fail: function fail(message) {
  3256. var error = new Error(message);
  3257. error.name = this.failException || assert.failException;
  3258. throw error;
  3259. },
  3260. pass: function pass(assertion) {},
  3261. callOrder: function assertCallOrder() {
  3262. verifyIsStub.apply(null, arguments);
  3263. var expected = "", actual = "";
  3264. if (!sinon.calledInOrder(arguments)) {
  3265. try {
  3266. expected = [].join.call(arguments, ", ");
  3267. var calls = slice.call(arguments);
  3268. var i = calls.length;
  3269. while (i) {
  3270. if (!calls[--i].called) {
  3271. calls.splice(i, 1);
  3272. }
  3273. }
  3274. actual = sinon.orderByFirstCall(calls).join(", ");
  3275. } catch (e) {
  3276. // If this fails, we'll just fall back to the blank string
  3277. }
  3278. failAssertion(this, "expected " + expected + " to be " +
  3279. "called in order but were called as " + actual);
  3280. } else {
  3281. assert.pass("callOrder");
  3282. }
  3283. },
  3284. callCount: function assertCallCount(method, count) {
  3285. verifyIsStub(method);
  3286. if (method.callCount != count) {
  3287. var msg = "expected %n to be called " + sinon.timesInWords(count) +
  3288. " but was called %c%C";
  3289. failAssertion(this, method.printf(msg));
  3290. } else {
  3291. assert.pass("callCount");
  3292. }
  3293. },
  3294. expose: function expose(target, options) {
  3295. if (!target) {
  3296. throw new TypeError("target is null or undefined");
  3297. }
  3298. var o = options || {};
  3299. var prefix = typeof o.prefix == "undefined" && "assert" || o.prefix;
  3300. var includeFail = typeof o.includeFail == "undefined" || !!o.includeFail;
  3301. for (var method in this) {
  3302. if (method != "expose" && (includeFail || !/^(fail)/.test(method))) {
  3303. target[exposedName(prefix, method)] = this[method];
  3304. }
  3305. }
  3306. return target;
  3307. },
  3308. match: function match(actual, expectation) {
  3309. var matcher = sinon.match(expectation);
  3310. if (matcher.test(actual)) {
  3311. assert.pass("match");
  3312. } else {
  3313. var formatted = [
  3314. "expected value to match",
  3315. " expected = " + sinon.format(expectation),
  3316. " actual = " + sinon.format(actual)
  3317. ]
  3318. failAssertion(this, formatted.join("\n"));
  3319. }
  3320. }
  3321. };
  3322. mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called");
  3323. mirrorPropAsAssertion("notCalled", function (spy) { return !spy.called; },
  3324. "expected %n to not have been called but was called %c%C");
  3325. mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C");
  3326. mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C");
  3327. mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C");
  3328. mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t");
  3329. mirrorPropAsAssertion("alwaysCalledOn", "expected %n to always be called with %1 as this but was called with %t");
  3330. mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new");
  3331. mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new");
  3332. mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %*%C");
  3333. mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %*%C");
  3334. mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %*%C");
  3335. mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %*%C");
  3336. mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %*%C");
  3337. mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %*%C");
  3338. mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C");
  3339. mirrorPropAsAssertion("neverCalledWithMatch", "expected %n to never be called with match %*%C");
  3340. mirrorPropAsAssertion("threw", "%n did not throw exception%C");
  3341. mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C");
  3342. sinon.assert = assert;
  3343. return assert;
  3344. }
  3345. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  3346. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  3347. function loadDependencies(require, exports, module) {
  3348. var sinon = require("./util/core");
  3349. require("./match");
  3350. require("./format");
  3351. module.exports = makeApi(sinon);
  3352. }
  3353. if (isAMD) {
  3354. define(loadDependencies);
  3355. } else if (isNode) {
  3356. loadDependencies(require, module.exports, module);
  3357. } else if (!sinon) {
  3358. return;
  3359. } else {
  3360. makeApi(sinon);
  3361. }
  3362. }(typeof sinon == "object" && sinon || null, typeof window != "undefined" ? window : (typeof self != "undefined") ? self : global));
  3363. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3364. },{"./format":30,"./match":32,"./util/core":41}],26:[function(require,module,exports){
  3365. (function (process){
  3366. /**
  3367. * @depend util/core.js
  3368. * @depend extend.js
  3369. */
  3370. /**
  3371. * Stub behavior
  3372. *
  3373. * @author Christian Johansen (christian@cjohansen.no)
  3374. * @author Tim Fischbach (mail@timfischbach.de)
  3375. * @license BSD
  3376. *
  3377. * Copyright (c) 2010-2013 Christian Johansen
  3378. */
  3379. "use strict";
  3380. (function (sinon) {
  3381. var slice = Array.prototype.slice;
  3382. var join = Array.prototype.join;
  3383. var useLeftMostCallback = -1;
  3384. var useRightMostCallback = -2;
  3385. var nextTick = (function () {
  3386. if (typeof process === "object" && typeof process.nextTick === "function") {
  3387. return process.nextTick;
  3388. } else if (typeof setImmediate === "function") {
  3389. return setImmediate;
  3390. } else {
  3391. return function (callback) {
  3392. setTimeout(callback, 0);
  3393. };
  3394. }
  3395. })();
  3396. function throwsException(error, message) {
  3397. if (typeof error == "string") {
  3398. this.exception = new Error(message || "");
  3399. this.exception.name = error;
  3400. } else if (!error) {
  3401. this.exception = new Error("Error");
  3402. } else {
  3403. this.exception = error;
  3404. }
  3405. return this;
  3406. }
  3407. function getCallback(behavior, args) {
  3408. var callArgAt = behavior.callArgAt;
  3409. if (callArgAt >= 0) {
  3410. return args[callArgAt];
  3411. }
  3412. var argumentList;
  3413. if (callArgAt === useLeftMostCallback) {
  3414. argumentList = args;
  3415. }
  3416. if (callArgAt === useRightMostCallback) {
  3417. argumentList = slice.call(args).reverse();
  3418. }
  3419. var callArgProp = behavior.callArgProp;
  3420. for (var i = 0, l = argumentList.length; i < l; ++i) {
  3421. if (!callArgProp && typeof argumentList[i] == "function") {
  3422. return argumentList[i];
  3423. }
  3424. if (callArgProp && argumentList[i] &&
  3425. typeof argumentList[i][callArgProp] == "function") {
  3426. return argumentList[i][callArgProp];
  3427. }
  3428. }
  3429. return null;
  3430. }
  3431. function makeApi(sinon) {
  3432. function getCallbackError(behavior, func, args) {
  3433. if (behavior.callArgAt < 0) {
  3434. var msg;
  3435. if (behavior.callArgProp) {
  3436. msg = sinon.functionName(behavior.stub) +
  3437. " expected to yield to '" + behavior.callArgProp +
  3438. "', but no object with such a property was passed.";
  3439. } else {
  3440. msg = sinon.functionName(behavior.stub) +
  3441. " expected to yield, but no callback was passed.";
  3442. }
  3443. if (args.length > 0) {
  3444. msg += " Received [" + join.call(args, ", ") + "]";
  3445. }
  3446. return msg;
  3447. }
  3448. return "argument at index " + behavior.callArgAt + " is not a function: " + func;
  3449. }
  3450. function callCallback(behavior, args) {
  3451. if (typeof behavior.callArgAt == "number") {
  3452. var func = getCallback(behavior, args);
  3453. if (typeof func != "function") {
  3454. throw new TypeError(getCallbackError(behavior, func, args));
  3455. }
  3456. if (behavior.callbackAsync) {
  3457. nextTick(function () {
  3458. func.apply(behavior.callbackContext, behavior.callbackArguments);
  3459. });
  3460. } else {
  3461. func.apply(behavior.callbackContext, behavior.callbackArguments);
  3462. }
  3463. }
  3464. }
  3465. var proto = {
  3466. create: function create(stub) {
  3467. var behavior = sinon.extend({}, sinon.behavior);
  3468. delete behavior.create;
  3469. behavior.stub = stub;
  3470. return behavior;
  3471. },
  3472. isPresent: function isPresent() {
  3473. return (typeof this.callArgAt == "number" ||
  3474. this.exception ||
  3475. typeof this.returnArgAt == "number" ||
  3476. this.returnThis ||
  3477. this.returnValueDefined);
  3478. },
  3479. invoke: function invoke(context, args) {
  3480. callCallback(this, args);
  3481. if (this.exception) {
  3482. throw this.exception;
  3483. } else if (typeof this.returnArgAt == "number") {
  3484. return args[this.returnArgAt];
  3485. } else if (this.returnThis) {
  3486. return context;
  3487. }
  3488. return this.returnValue;
  3489. },
  3490. onCall: function onCall(index) {
  3491. return this.stub.onCall(index);
  3492. },
  3493. onFirstCall: function onFirstCall() {
  3494. return this.stub.onFirstCall();
  3495. },
  3496. onSecondCall: function onSecondCall() {
  3497. return this.stub.onSecondCall();
  3498. },
  3499. onThirdCall: function onThirdCall() {
  3500. return this.stub.onThirdCall();
  3501. },
  3502. withArgs: function withArgs(/* arguments */) {
  3503. throw new Error("Defining a stub by invoking \"stub.onCall(...).withArgs(...)\" is not supported. " +
  3504. "Use \"stub.withArgs(...).onCall(...)\" to define sequential behavior for calls with certain arguments.");
  3505. },
  3506. callsArg: function callsArg(pos) {
  3507. if (typeof pos != "number") {
  3508. throw new TypeError("argument index is not number");
  3509. }
  3510. this.callArgAt = pos;
  3511. this.callbackArguments = [];
  3512. this.callbackContext = undefined;
  3513. this.callArgProp = undefined;
  3514. this.callbackAsync = false;
  3515. return this;
  3516. },
  3517. callsArgOn: function callsArgOn(pos, context) {
  3518. if (typeof pos != "number") {
  3519. throw new TypeError("argument index is not number");
  3520. }
  3521. if (typeof context != "object") {
  3522. throw new TypeError("argument context is not an object");
  3523. }
  3524. this.callArgAt = pos;
  3525. this.callbackArguments = [];
  3526. this.callbackContext = context;
  3527. this.callArgProp = undefined;
  3528. this.callbackAsync = false;
  3529. return this;
  3530. },
  3531. callsArgWith: function callsArgWith(pos) {
  3532. if (typeof pos != "number") {
  3533. throw new TypeError("argument index is not number");
  3534. }
  3535. this.callArgAt = pos;
  3536. this.callbackArguments = slice.call(arguments, 1);
  3537. this.callbackContext = undefined;
  3538. this.callArgProp = undefined;
  3539. this.callbackAsync = false;
  3540. return this;
  3541. },
  3542. callsArgOnWith: function callsArgWith(pos, context) {
  3543. if (typeof pos != "number") {
  3544. throw new TypeError("argument index is not number");
  3545. }
  3546. if (typeof context != "object") {
  3547. throw new TypeError("argument context is not an object");
  3548. }
  3549. this.callArgAt = pos;
  3550. this.callbackArguments = slice.call(arguments, 2);
  3551. this.callbackContext = context;
  3552. this.callArgProp = undefined;
  3553. this.callbackAsync = false;
  3554. return this;
  3555. },
  3556. yields: function () {
  3557. this.callArgAt = useLeftMostCallback;
  3558. this.callbackArguments = slice.call(arguments, 0);
  3559. this.callbackContext = undefined;
  3560. this.callArgProp = undefined;
  3561. this.callbackAsync = false;
  3562. return this;
  3563. },
  3564. yieldsRight: function () {
  3565. this.callArgAt = useRightMostCallback;
  3566. this.callbackArguments = slice.call(arguments, 0);
  3567. this.callbackContext = undefined;
  3568. this.callArgProp = undefined;
  3569. this.callbackAsync = false;
  3570. return this;
  3571. },
  3572. yieldsOn: function (context) {
  3573. if (typeof context != "object") {
  3574. throw new TypeError("argument context is not an object");
  3575. }
  3576. this.callArgAt = useLeftMostCallback;
  3577. this.callbackArguments = slice.call(arguments, 1);
  3578. this.callbackContext = context;
  3579. this.callArgProp = undefined;
  3580. this.callbackAsync = false;
  3581. return this;
  3582. },
  3583. yieldsTo: function (prop) {
  3584. this.callArgAt = useLeftMostCallback;
  3585. this.callbackArguments = slice.call(arguments, 1);
  3586. this.callbackContext = undefined;
  3587. this.callArgProp = prop;
  3588. this.callbackAsync = false;
  3589. return this;
  3590. },
  3591. yieldsToOn: function (prop, context) {
  3592. if (typeof context != "object") {
  3593. throw new TypeError("argument context is not an object");
  3594. }
  3595. this.callArgAt = useLeftMostCallback;
  3596. this.callbackArguments = slice.call(arguments, 2);
  3597. this.callbackContext = context;
  3598. this.callArgProp = prop;
  3599. this.callbackAsync = false;
  3600. return this;
  3601. },
  3602. throws: throwsException,
  3603. throwsException: throwsException,
  3604. returns: function returns(value) {
  3605. this.returnValue = value;
  3606. this.returnValueDefined = true;
  3607. return this;
  3608. },
  3609. returnsArg: function returnsArg(pos) {
  3610. if (typeof pos != "number") {
  3611. throw new TypeError("argument index is not number");
  3612. }
  3613. this.returnArgAt = pos;
  3614. return this;
  3615. },
  3616. returnsThis: function returnsThis() {
  3617. this.returnThis = true;
  3618. return this;
  3619. }
  3620. };
  3621. // create asynchronous versions of callsArg* and yields* methods
  3622. for (var method in proto) {
  3623. // need to avoid creating anotherasync versions of the newly added async methods
  3624. if (proto.hasOwnProperty(method) &&
  3625. method.match(/^(callsArg|yields)/) &&
  3626. !method.match(/Async/)) {
  3627. proto[method + "Async"] = (function (syncFnName) {
  3628. return function () {
  3629. var result = this[syncFnName].apply(this, arguments);
  3630. this.callbackAsync = true;
  3631. return result;
  3632. };
  3633. })(method);
  3634. }
  3635. }
  3636. sinon.behavior = proto;
  3637. return proto;
  3638. }
  3639. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  3640. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  3641. function loadDependencies(require, exports, module) {
  3642. var sinon = require("./util/core");
  3643. require("./extend");
  3644. module.exports = makeApi(sinon);
  3645. }
  3646. if (isAMD) {
  3647. define(loadDependencies);
  3648. } else if (isNode) {
  3649. loadDependencies(require, module.exports, module);
  3650. } else if (!sinon) {
  3651. return;
  3652. } else {
  3653. makeApi(sinon);
  3654. }
  3655. }(typeof sinon == "object" && sinon || null));
  3656. }).call(this,require('_process'))
  3657. },{"./extend":29,"./util/core":41,"_process":4}],27:[function(require,module,exports){
  3658. /**
  3659. * @depend util/core.js
  3660. * @depend match.js
  3661. * @depend format.js
  3662. */
  3663. /**
  3664. * Spy calls
  3665. *
  3666. * @author Christian Johansen (christian@cjohansen.no)
  3667. * @author Maximilian Antoni (mail@maxantoni.de)
  3668. * @license BSD
  3669. *
  3670. * Copyright (c) 2010-2013 Christian Johansen
  3671. * Copyright (c) 2013 Maximilian Antoni
  3672. */
  3673. "use strict";
  3674. (function (sinon) {
  3675. function makeApi(sinon) {
  3676. function throwYieldError(proxy, text, args) {
  3677. var msg = sinon.functionName(proxy) + text;
  3678. if (args.length) {
  3679. msg += " Received [" + slice.call(args).join(", ") + "]";
  3680. }
  3681. throw new Error(msg);
  3682. }
  3683. var slice = Array.prototype.slice;
  3684. var callProto = {
  3685. calledOn: function calledOn(thisValue) {
  3686. if (sinon.match && sinon.match.isMatcher(thisValue)) {
  3687. return thisValue.test(this.thisValue);
  3688. }
  3689. return this.thisValue === thisValue;
  3690. },
  3691. calledWith: function calledWith() {
  3692. var l = arguments.length;
  3693. if (l > this.args.length) {
  3694. return false;
  3695. }
  3696. for (var i = 0; i < l; i += 1) {
  3697. if (!sinon.deepEqual(arguments[i], this.args[i])) {
  3698. return false;
  3699. }
  3700. }
  3701. return true;
  3702. },
  3703. calledWithMatch: function calledWithMatch() {
  3704. var l = arguments.length;
  3705. if (l > this.args.length) {
  3706. return false;
  3707. }
  3708. for (var i = 0; i < l; i += 1) {
  3709. var actual = this.args[i];
  3710. var expectation = arguments[i];
  3711. if (!sinon.match || !sinon.match(expectation).test(actual)) {
  3712. return false;
  3713. }
  3714. }
  3715. return true;
  3716. },
  3717. calledWithExactly: function calledWithExactly() {
  3718. return arguments.length == this.args.length &&
  3719. this.calledWith.apply(this, arguments);
  3720. },
  3721. notCalledWith: function notCalledWith() {
  3722. return !this.calledWith.apply(this, arguments);
  3723. },
  3724. notCalledWithMatch: function notCalledWithMatch() {
  3725. return !this.calledWithMatch.apply(this, arguments);
  3726. },
  3727. returned: function returned(value) {
  3728. return sinon.deepEqual(value, this.returnValue);
  3729. },
  3730. threw: function threw(error) {
  3731. if (typeof error === "undefined" || !this.exception) {
  3732. return !!this.exception;
  3733. }
  3734. return this.exception === error || this.exception.name === error;
  3735. },
  3736. calledWithNew: function calledWithNew() {
  3737. return this.proxy.prototype && this.thisValue instanceof this.proxy;
  3738. },
  3739. calledBefore: function (other) {
  3740. return this.callId < other.callId;
  3741. },
  3742. calledAfter: function (other) {
  3743. return this.callId > other.callId;
  3744. },
  3745. callArg: function (pos) {
  3746. this.args[pos]();
  3747. },
  3748. callArgOn: function (pos, thisValue) {
  3749. this.args[pos].apply(thisValue);
  3750. },
  3751. callArgWith: function (pos) {
  3752. this.callArgOnWith.apply(this, [pos, null].concat(slice.call(arguments, 1)));
  3753. },
  3754. callArgOnWith: function (pos, thisValue) {
  3755. var args = slice.call(arguments, 2);
  3756. this.args[pos].apply(thisValue, args);
  3757. },
  3758. yield: function () {
  3759. this.yieldOn.apply(this, [null].concat(slice.call(arguments, 0)));
  3760. },
  3761. yieldOn: function (thisValue) {
  3762. var args = this.args;
  3763. for (var i = 0, l = args.length; i < l; ++i) {
  3764. if (typeof args[i] === "function") {
  3765. args[i].apply(thisValue, slice.call(arguments, 1));
  3766. return;
  3767. }
  3768. }
  3769. throwYieldError(this.proxy, " cannot yield since no callback was passed.", args);
  3770. },
  3771. yieldTo: function (prop) {
  3772. this.yieldToOn.apply(this, [prop, null].concat(slice.call(arguments, 1)));
  3773. },
  3774. yieldToOn: function (prop, thisValue) {
  3775. var args = this.args;
  3776. for (var i = 0, l = args.length; i < l; ++i) {
  3777. if (args[i] && typeof args[i][prop] === "function") {
  3778. args[i][prop].apply(thisValue, slice.call(arguments, 2));
  3779. return;
  3780. }
  3781. }
  3782. throwYieldError(this.proxy, " cannot yield to '" + prop +
  3783. "' since no callback was passed.", args);
  3784. },
  3785. toString: function () {
  3786. var callStr = this.proxy.toString() + "(";
  3787. var args = [];
  3788. for (var i = 0, l = this.args.length; i < l; ++i) {
  3789. args.push(sinon.format(this.args[i]));
  3790. }
  3791. callStr = callStr + args.join(", ") + ")";
  3792. if (typeof this.returnValue != "undefined") {
  3793. callStr += " => " + sinon.format(this.returnValue);
  3794. }
  3795. if (this.exception) {
  3796. callStr += " !" + this.exception.name;
  3797. if (this.exception.message) {
  3798. callStr += "(" + this.exception.message + ")";
  3799. }
  3800. }
  3801. return callStr;
  3802. }
  3803. };
  3804. callProto.invokeCallback = callProto.yield;
  3805. function createSpyCall(spy, thisValue, args, returnValue, exception, id) {
  3806. if (typeof id !== "number") {
  3807. throw new TypeError("Call id is not a number");
  3808. }
  3809. var proxyCall = sinon.create(callProto);
  3810. proxyCall.proxy = spy;
  3811. proxyCall.thisValue = thisValue;
  3812. proxyCall.args = args;
  3813. proxyCall.returnValue = returnValue;
  3814. proxyCall.exception = exception;
  3815. proxyCall.callId = id;
  3816. return proxyCall;
  3817. }
  3818. createSpyCall.toString = callProto.toString; // used by mocks
  3819. sinon.spyCall = createSpyCall;
  3820. return createSpyCall;
  3821. }
  3822. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  3823. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  3824. function loadDependencies(require, exports, module) {
  3825. var sinon = require("./util/core");
  3826. require("./match");
  3827. require("./format");
  3828. module.exports = makeApi(sinon);
  3829. }
  3830. if (isAMD) {
  3831. define(loadDependencies);
  3832. } else if (isNode) {
  3833. loadDependencies(require, module.exports, module);
  3834. } else if (!sinon) {
  3835. return;
  3836. } else {
  3837. makeApi(sinon);
  3838. }
  3839. }(typeof sinon == "object" && sinon || null));
  3840. },{"./format":30,"./match":32,"./util/core":41}],28:[function(require,module,exports){
  3841. /**
  3842. * @depend util/core.js
  3843. * @depend spy.js
  3844. * @depend stub.js
  3845. * @depend mock.js
  3846. */
  3847. /**
  3848. * Collections of stubs, spies and mocks.
  3849. *
  3850. * @author Christian Johansen (christian@cjohansen.no)
  3851. * @license BSD
  3852. *
  3853. * Copyright (c) 2010-2013 Christian Johansen
  3854. */
  3855. "use strict";
  3856. (function (sinon) {
  3857. var push = [].push;
  3858. var hasOwnProperty = Object.prototype.hasOwnProperty;
  3859. function getFakes(fakeCollection) {
  3860. if (!fakeCollection.fakes) {
  3861. fakeCollection.fakes = [];
  3862. }
  3863. return fakeCollection.fakes;
  3864. }
  3865. function each(fakeCollection, method) {
  3866. var fakes = getFakes(fakeCollection);
  3867. for (var i = 0, l = fakes.length; i < l; i += 1) {
  3868. if (typeof fakes[i][method] == "function") {
  3869. fakes[i][method]();
  3870. }
  3871. }
  3872. }
  3873. function compact(fakeCollection) {
  3874. var fakes = getFakes(fakeCollection);
  3875. var i = 0;
  3876. while (i < fakes.length) {
  3877. fakes.splice(i, 1);
  3878. }
  3879. }
  3880. function makeApi(sinon) {
  3881. var collection = {
  3882. verify: function resolve() {
  3883. each(this, "verify");
  3884. },
  3885. restore: function restore() {
  3886. each(this, "restore");
  3887. compact(this);
  3888. },
  3889. reset: function restore() {
  3890. each(this, "reset");
  3891. },
  3892. verifyAndRestore: function verifyAndRestore() {
  3893. var exception;
  3894. try {
  3895. this.verify();
  3896. } catch (e) {
  3897. exception = e;
  3898. }
  3899. this.restore();
  3900. if (exception) {
  3901. throw exception;
  3902. }
  3903. },
  3904. add: function add(fake) {
  3905. push.call(getFakes(this), fake);
  3906. return fake;
  3907. },
  3908. spy: function spy() {
  3909. return this.add(sinon.spy.apply(sinon, arguments));
  3910. },
  3911. stub: function stub(object, property, value) {
  3912. if (property) {
  3913. var original = object[property];
  3914. if (typeof original != "function") {
  3915. if (!hasOwnProperty.call(object, property)) {
  3916. throw new TypeError("Cannot stub non-existent own property " + property);
  3917. }
  3918. object[property] = value;
  3919. return this.add({
  3920. restore: function () {
  3921. object[property] = original;
  3922. }
  3923. });
  3924. }
  3925. }
  3926. if (!property && !!object && typeof object == "object") {
  3927. var stubbedObj = sinon.stub.apply(sinon, arguments);
  3928. for (var prop in stubbedObj) {
  3929. if (typeof stubbedObj[prop] === "function") {
  3930. this.add(stubbedObj[prop]);
  3931. }
  3932. }
  3933. return stubbedObj;
  3934. }
  3935. return this.add(sinon.stub.apply(sinon, arguments));
  3936. },
  3937. mock: function mock() {
  3938. return this.add(sinon.mock.apply(sinon, arguments));
  3939. },
  3940. inject: function inject(obj) {
  3941. var col = this;
  3942. obj.spy = function () {
  3943. return col.spy.apply(col, arguments);
  3944. };
  3945. obj.stub = function () {
  3946. return col.stub.apply(col, arguments);
  3947. };
  3948. obj.mock = function () {
  3949. return col.mock.apply(col, arguments);
  3950. };
  3951. return obj;
  3952. }
  3953. };
  3954. sinon.collection = collection;
  3955. return collection;
  3956. }
  3957. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  3958. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  3959. function loadDependencies(require, exports, module) {
  3960. var sinon = require("./util/core");
  3961. require("./mock");
  3962. require("./spy");
  3963. require("./stub");
  3964. module.exports = makeApi(sinon);
  3965. }
  3966. if (isAMD) {
  3967. define(loadDependencies);
  3968. } else if (isNode) {
  3969. loadDependencies(require, module.exports, module);
  3970. } else if (!sinon) {
  3971. return;
  3972. } else {
  3973. makeApi(sinon);
  3974. }
  3975. }(typeof sinon == "object" && sinon || null));
  3976. },{"./mock":33,"./spy":35,"./stub":36,"./util/core":41}],29:[function(require,module,exports){
  3977. /**
  3978. * @depend util/core.js
  3979. */
  3980. "use strict";
  3981. (function (sinon) {
  3982. function makeApi(sinon) {
  3983. // Adapted from https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug
  3984. var hasDontEnumBug = (function () {
  3985. var obj = {
  3986. constructor: function () {
  3987. return "0";
  3988. },
  3989. toString: function () {
  3990. return "1";
  3991. },
  3992. valueOf: function () {
  3993. return "2";
  3994. },
  3995. toLocaleString: function () {
  3996. return "3";
  3997. },
  3998. prototype: function () {
  3999. return "4";
  4000. },
  4001. isPrototypeOf: function () {
  4002. return "5";
  4003. },
  4004. propertyIsEnumerable: function () {
  4005. return "6";
  4006. },
  4007. hasOwnProperty: function () {
  4008. return "7";
  4009. },
  4010. length: function () {
  4011. return "8";
  4012. },
  4013. unique: function () {
  4014. return "9"
  4015. }
  4016. };
  4017. var result = [];
  4018. for (var prop in obj) {
  4019. result.push(obj[prop]());
  4020. }
  4021. return result.join("") !== "0123456789";
  4022. })();
  4023. /* Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will
  4024. * override properties in previous sources.
  4025. *
  4026. * target - The Object to extend
  4027. * sources - Objects to copy properties from.
  4028. *
  4029. * Returns the extended target
  4030. */
  4031. function extend(target /*, sources */) {
  4032. var sources = Array.prototype.slice.call(arguments, 1),
  4033. source, i, prop;
  4034. for (i = 0; i < sources.length; i++) {
  4035. source = sources[i];
  4036. for (prop in source) {
  4037. if (source.hasOwnProperty(prop)) {
  4038. target[prop] = source[prop];
  4039. }
  4040. }
  4041. // Make sure we copy (own) toString method even when in JScript with DontEnum bug
  4042. // See https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug
  4043. if (hasDontEnumBug && source.hasOwnProperty("toString") && source.toString !== target.toString) {
  4044. target.toString = source.toString;
  4045. }
  4046. }
  4047. return target;
  4048. };
  4049. sinon.extend = extend;
  4050. return sinon.extend;
  4051. }
  4052. function loadDependencies(require, exports, module) {
  4053. var sinon = require("./util/core");
  4054. module.exports = makeApi(sinon);
  4055. }
  4056. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  4057. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  4058. if (isAMD) {
  4059. define(loadDependencies);
  4060. } else if (isNode) {
  4061. loadDependencies(require, module.exports, module);
  4062. } else if (!sinon) {
  4063. return;
  4064. } else {
  4065. makeApi(sinon);
  4066. }
  4067. }(typeof sinon == "object" && sinon || null));
  4068. },{"./util/core":41}],30:[function(require,module,exports){
  4069. /**
  4070. * @depend util/core.js
  4071. */
  4072. /**
  4073. * Format functions
  4074. *
  4075. * @author Christian Johansen (christian@cjohansen.no)
  4076. * @license BSD
  4077. *
  4078. * Copyright (c) 2010-2014 Christian Johansen
  4079. */
  4080. "use strict";
  4081. (function (sinon, formatio) {
  4082. function makeApi(sinon) {
  4083. function valueFormatter(value) {
  4084. return "" + value;
  4085. }
  4086. function getFormatioFormatter() {
  4087. var formatter = formatio.configure({
  4088. quoteStrings: false,
  4089. limitChildrenCount: 250
  4090. });
  4091. function format() {
  4092. return formatter.ascii.apply(formatter, arguments);
  4093. };
  4094. return format;
  4095. }
  4096. function getNodeFormatter(value) {
  4097. function format(value) {
  4098. return typeof value == "object" && value.toString === Object.prototype.toString ? util.inspect(value) : value;
  4099. };
  4100. try {
  4101. var util = require("util");
  4102. } catch (e) {
  4103. /* Node, but no util module - would be very old, but better safe than sorry */
  4104. }
  4105. return util ? format : valueFormatter;
  4106. }
  4107. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function",
  4108. formatter;
  4109. if (isNode) {
  4110. try {
  4111. formatio = require("formatio");
  4112. } catch (e) {}
  4113. }
  4114. if (formatio) {
  4115. formatter = getFormatioFormatter()
  4116. } else if (isNode) {
  4117. formatter = getNodeFormatter();
  4118. } else {
  4119. formatter = valueFormatter;
  4120. }
  4121. sinon.format = formatter;
  4122. return sinon.format;
  4123. }
  4124. function loadDependencies(require, exports, module) {
  4125. var sinon = require("./util/core");
  4126. module.exports = makeApi(sinon);
  4127. }
  4128. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  4129. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  4130. if (isAMD) {
  4131. define(loadDependencies);
  4132. } else if (isNode) {
  4133. loadDependencies(require, module.exports, module);
  4134. } else if (!sinon) {
  4135. return;
  4136. } else {
  4137. makeApi(sinon);
  4138. }
  4139. }(
  4140. (typeof sinon == "object" && sinon || null),
  4141. (typeof formatio == "object" && formatio)
  4142. ));
  4143. },{"./util/core":41,"formatio":48,"util":6}],31:[function(require,module,exports){
  4144. /**
  4145. * @depend util/core.js
  4146. */
  4147. /**
  4148. * Logs errors
  4149. *
  4150. * @author Christian Johansen (christian@cjohansen.no)
  4151. * @license BSD
  4152. *
  4153. * Copyright (c) 2010-2014 Christian Johansen
  4154. */
  4155. "use strict";
  4156. (function (sinon) {
  4157. // cache a reference to setTimeout, so that our reference won't be stubbed out
  4158. // when using fake timers and errors will still get logged
  4159. // https://github.com/cjohansen/Sinon.JS/issues/381
  4160. var realSetTimeout = setTimeout;
  4161. function makeApi(sinon) {
  4162. function log() {}
  4163. function logError(label, err) {
  4164. var msg = label + " threw exception: ";
  4165. sinon.log(msg + "[" + err.name + "] " + err.message);
  4166. if (err.stack) {
  4167. sinon.log(err.stack);
  4168. }
  4169. logError.setTimeout(function () {
  4170. err.message = msg + err.message;
  4171. throw err;
  4172. }, 0);
  4173. };
  4174. // wrap realSetTimeout with something we can stub in tests
  4175. logError.setTimeout = function (func, timeout) {
  4176. realSetTimeout(func, timeout);
  4177. }
  4178. var exports = {};
  4179. exports.log = sinon.log = log;
  4180. exports.logError = sinon.logError = logError;
  4181. return exports;
  4182. }
  4183. function loadDependencies(require, exports, module) {
  4184. var sinon = require("./util/core");
  4185. module.exports = makeApi(sinon);
  4186. }
  4187. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  4188. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  4189. if (isAMD) {
  4190. define(loadDependencies);
  4191. } else if (isNode) {
  4192. loadDependencies(require, module.exports, module);
  4193. } else if (!sinon) {
  4194. return;
  4195. } else {
  4196. makeApi(sinon);
  4197. }
  4198. }(typeof sinon == "object" && sinon || null));
  4199. },{"./util/core":41}],32:[function(require,module,exports){
  4200. /**
  4201. * @depend util/core.js
  4202. * @depend typeOf.js
  4203. */
  4204. /*jslint eqeqeq: false, onevar: false, plusplus: false*/
  4205. /*global module, require, sinon*/
  4206. /**
  4207. * Match functions
  4208. *
  4209. * @author Maximilian Antoni (mail@maxantoni.de)
  4210. * @license BSD
  4211. *
  4212. * Copyright (c) 2012 Maximilian Antoni
  4213. */
  4214. "use strict";
  4215. (function (sinon) {
  4216. function makeApi(sinon) {
  4217. function assertType(value, type, name) {
  4218. var actual = sinon.typeOf(value);
  4219. if (actual !== type) {
  4220. throw new TypeError("Expected type of " + name + " to be " +
  4221. type + ", but was " + actual);
  4222. }
  4223. }
  4224. var matcher = {
  4225. toString: function () {
  4226. return this.message;
  4227. }
  4228. };
  4229. function isMatcher(object) {
  4230. return matcher.isPrototypeOf(object);
  4231. }
  4232. function matchObject(expectation, actual) {
  4233. if (actual === null || actual === undefined) {
  4234. return false;
  4235. }
  4236. for (var key in expectation) {
  4237. if (expectation.hasOwnProperty(key)) {
  4238. var exp = expectation[key];
  4239. var act = actual[key];
  4240. if (match.isMatcher(exp)) {
  4241. if (!exp.test(act)) {
  4242. return false;
  4243. }
  4244. } else if (sinon.typeOf(exp) === "object") {
  4245. if (!matchObject(exp, act)) {
  4246. return false;
  4247. }
  4248. } else if (!sinon.deepEqual(exp, act)) {
  4249. return false;
  4250. }
  4251. }
  4252. }
  4253. return true;
  4254. }
  4255. matcher.or = function (m2) {
  4256. if (!arguments.length) {
  4257. throw new TypeError("Matcher expected");
  4258. } else if (!isMatcher(m2)) {
  4259. m2 = match(m2);
  4260. }
  4261. var m1 = this;
  4262. var or = sinon.create(matcher);
  4263. or.test = function (actual) {
  4264. return m1.test(actual) || m2.test(actual);
  4265. };
  4266. or.message = m1.message + ".or(" + m2.message + ")";
  4267. return or;
  4268. };
  4269. matcher.and = function (m2) {
  4270. if (!arguments.length) {
  4271. throw new TypeError("Matcher expected");
  4272. } else if (!isMatcher(m2)) {
  4273. m2 = match(m2);
  4274. }
  4275. var m1 = this;
  4276. var and = sinon.create(matcher);
  4277. and.test = function (actual) {
  4278. return m1.test(actual) && m2.test(actual);
  4279. };
  4280. and.message = m1.message + ".and(" + m2.message + ")";
  4281. return and;
  4282. };
  4283. var match = function (expectation, message) {
  4284. var m = sinon.create(matcher);
  4285. var type = sinon.typeOf(expectation);
  4286. switch (type) {
  4287. case "object":
  4288. if (typeof expectation.test === "function") {
  4289. m.test = function (actual) {
  4290. return expectation.test(actual) === true;
  4291. };
  4292. m.message = "match(" + sinon.functionName(expectation.test) + ")";
  4293. return m;
  4294. }
  4295. var str = [];
  4296. for (var key in expectation) {
  4297. if (expectation.hasOwnProperty(key)) {
  4298. str.push(key + ": " + expectation[key]);
  4299. }
  4300. }
  4301. m.test = function (actual) {
  4302. return matchObject(expectation, actual);
  4303. };
  4304. m.message = "match(" + str.join(", ") + ")";
  4305. break;
  4306. case "number":
  4307. m.test = function (actual) {
  4308. return expectation == actual;
  4309. };
  4310. break;
  4311. case "string":
  4312. m.test = function (actual) {
  4313. if (typeof actual !== "string") {
  4314. return false;
  4315. }
  4316. return actual.indexOf(expectation) !== -1;
  4317. };
  4318. m.message = "match(\"" + expectation + "\")";
  4319. break;
  4320. case "regexp":
  4321. m.test = function (actual) {
  4322. if (typeof actual !== "string") {
  4323. return false;
  4324. }
  4325. return expectation.test(actual);
  4326. };
  4327. break;
  4328. case "function":
  4329. m.test = expectation;
  4330. if (message) {
  4331. m.message = message;
  4332. } else {
  4333. m.message = "match(" + sinon.functionName(expectation) + ")";
  4334. }
  4335. break;
  4336. default:
  4337. m.test = function (actual) {
  4338. return sinon.deepEqual(expectation, actual);
  4339. };
  4340. }
  4341. if (!m.message) {
  4342. m.message = "match(" + expectation + ")";
  4343. }
  4344. return m;
  4345. };
  4346. match.isMatcher = isMatcher;
  4347. match.any = match(function () {
  4348. return true;
  4349. }, "any");
  4350. match.defined = match(function (actual) {
  4351. return actual !== null && actual !== undefined;
  4352. }, "defined");
  4353. match.truthy = match(function (actual) {
  4354. return !!actual;
  4355. }, "truthy");
  4356. match.falsy = match(function (actual) {
  4357. return !actual;
  4358. }, "falsy");
  4359. match.same = function (expectation) {
  4360. return match(function (actual) {
  4361. return expectation === actual;
  4362. }, "same(" + expectation + ")");
  4363. };
  4364. match.typeOf = function (type) {
  4365. assertType(type, "string", "type");
  4366. return match(function (actual) {
  4367. return sinon.typeOf(actual) === type;
  4368. }, "typeOf(\"" + type + "\")");
  4369. };
  4370. match.instanceOf = function (type) {
  4371. assertType(type, "function", "type");
  4372. return match(function (actual) {
  4373. return actual instanceof type;
  4374. }, "instanceOf(" + sinon.functionName(type) + ")");
  4375. };
  4376. function createPropertyMatcher(propertyTest, messagePrefix) {
  4377. return function (property, value) {
  4378. assertType(property, "string", "property");
  4379. var onlyProperty = arguments.length === 1;
  4380. var message = messagePrefix + "(\"" + property + "\"";
  4381. if (!onlyProperty) {
  4382. message += ", " + value;
  4383. }
  4384. message += ")";
  4385. return match(function (actual) {
  4386. if (actual === undefined || actual === null ||
  4387. !propertyTest(actual, property)) {
  4388. return false;
  4389. }
  4390. return onlyProperty || sinon.deepEqual(value, actual[property]);
  4391. }, message);
  4392. };
  4393. }
  4394. match.has = createPropertyMatcher(function (actual, property) {
  4395. if (typeof actual === "object") {
  4396. return property in actual;
  4397. }
  4398. return actual[property] !== undefined;
  4399. }, "has");
  4400. match.hasOwn = createPropertyMatcher(function (actual, property) {
  4401. return actual.hasOwnProperty(property);
  4402. }, "hasOwn");
  4403. match.bool = match.typeOf("boolean");
  4404. match.number = match.typeOf("number");
  4405. match.string = match.typeOf("string");
  4406. match.object = match.typeOf("object");
  4407. match.func = match.typeOf("function");
  4408. match.array = match.typeOf("array");
  4409. match.regexp = match.typeOf("regexp");
  4410. match.date = match.typeOf("date");
  4411. sinon.match = match;
  4412. return match;
  4413. }
  4414. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  4415. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  4416. function loadDependencies(require, exports, module) {
  4417. var sinon = require("./util/core");
  4418. require("./typeOf");
  4419. module.exports = makeApi(sinon);
  4420. }
  4421. if (isAMD) {
  4422. define(loadDependencies);
  4423. } else if (isNode) {
  4424. loadDependencies(require, module.exports, module);
  4425. } else if (!sinon) {
  4426. return;
  4427. } else {
  4428. makeApi(sinon);
  4429. }
  4430. }(typeof sinon == "object" && sinon || null));
  4431. },{"./typeOf":40,"./util/core":41}],33:[function(require,module,exports){
  4432. /**
  4433. * @depend times_in_words.js
  4434. * @depend util/core.js
  4435. * @depend call.js
  4436. * @depend extend.js
  4437. * @depend match.js
  4438. * @depend spy.js
  4439. * @depend stub.js
  4440. * @depend format.js
  4441. */
  4442. /**
  4443. * Mock functions.
  4444. *
  4445. * @author Christian Johansen (christian@cjohansen.no)
  4446. * @license BSD
  4447. *
  4448. * Copyright (c) 2010-2013 Christian Johansen
  4449. */
  4450. "use strict";
  4451. (function (sinon) {
  4452. function makeApi(sinon) {
  4453. var push = [].push;
  4454. var match = sinon.match;
  4455. function mock(object) {
  4456. if (!object) {
  4457. return sinon.expectation.create("Anonymous mock");
  4458. }
  4459. return mock.create(object);
  4460. }
  4461. function each(collection, callback) {
  4462. if (!collection) {
  4463. return;
  4464. }
  4465. for (var i = 0, l = collection.length; i < l; i += 1) {
  4466. callback(collection[i]);
  4467. }
  4468. }
  4469. sinon.extend(mock, {
  4470. create: function create(object) {
  4471. if (!object) {
  4472. throw new TypeError("object is null");
  4473. }
  4474. var mockObject = sinon.extend({}, mock);
  4475. mockObject.object = object;
  4476. delete mockObject.create;
  4477. return mockObject;
  4478. },
  4479. expects: function expects(method) {
  4480. if (!method) {
  4481. throw new TypeError("method is falsy");
  4482. }
  4483. if (!this.expectations) {
  4484. this.expectations = {};
  4485. this.proxies = [];
  4486. }
  4487. if (!this.expectations[method]) {
  4488. this.expectations[method] = [];
  4489. var mockObject = this;
  4490. sinon.wrapMethod(this.object, method, function () {
  4491. return mockObject.invokeMethod(method, this, arguments);
  4492. });
  4493. push.call(this.proxies, method);
  4494. }
  4495. var expectation = sinon.expectation.create(method);
  4496. push.call(this.expectations[method], expectation);
  4497. return expectation;
  4498. },
  4499. restore: function restore() {
  4500. var object = this.object;
  4501. each(this.proxies, function (proxy) {
  4502. if (typeof object[proxy].restore == "function") {
  4503. object[proxy].restore();
  4504. }
  4505. });
  4506. },
  4507. verify: function verify() {
  4508. var expectations = this.expectations || {};
  4509. var messages = [], met = [];
  4510. each(this.proxies, function (proxy) {
  4511. each(expectations[proxy], function (expectation) {
  4512. if (!expectation.met()) {
  4513. push.call(messages, expectation.toString());
  4514. } else {
  4515. push.call(met, expectation.toString());
  4516. }
  4517. });
  4518. });
  4519. this.restore();
  4520. if (messages.length > 0) {
  4521. sinon.expectation.fail(messages.concat(met).join("\n"));
  4522. } else if (met.length > 0) {
  4523. sinon.expectation.pass(messages.concat(met).join("\n"));
  4524. }
  4525. return true;
  4526. },
  4527. invokeMethod: function invokeMethod(method, thisValue, args) {
  4528. var expectations = this.expectations && this.expectations[method];
  4529. var length = expectations && expectations.length || 0, i;
  4530. for (i = 0; i < length; i += 1) {
  4531. if (!expectations[i].met() &&
  4532. expectations[i].allowsCall(thisValue, args)) {
  4533. return expectations[i].apply(thisValue, args);
  4534. }
  4535. }
  4536. var messages = [], available, exhausted = 0;
  4537. for (i = 0; i < length; i += 1) {
  4538. if (expectations[i].allowsCall(thisValue, args)) {
  4539. available = available || expectations[i];
  4540. } else {
  4541. exhausted += 1;
  4542. }
  4543. push.call(messages, " " + expectations[i].toString());
  4544. }
  4545. if (exhausted === 0) {
  4546. return available.apply(thisValue, args);
  4547. }
  4548. messages.unshift("Unexpected call: " + sinon.spyCall.toString.call({
  4549. proxy: method,
  4550. args: args
  4551. }));
  4552. sinon.expectation.fail(messages.join("\n"));
  4553. }
  4554. });
  4555. var times = sinon.timesInWords;
  4556. var slice = Array.prototype.slice;
  4557. function callCountInWords(callCount) {
  4558. if (callCount == 0) {
  4559. return "never called";
  4560. } else {
  4561. return "called " + times(callCount);
  4562. }
  4563. }
  4564. function expectedCallCountInWords(expectation) {
  4565. var min = expectation.minCalls;
  4566. var max = expectation.maxCalls;
  4567. if (typeof min == "number" && typeof max == "number") {
  4568. var str = times(min);
  4569. if (min != max) {
  4570. str = "at least " + str + " and at most " + times(max);
  4571. }
  4572. return str;
  4573. }
  4574. if (typeof min == "number") {
  4575. return "at least " + times(min);
  4576. }
  4577. return "at most " + times(max);
  4578. }
  4579. function receivedMinCalls(expectation) {
  4580. var hasMinLimit = typeof expectation.minCalls == "number";
  4581. return !hasMinLimit || expectation.callCount >= expectation.minCalls;
  4582. }
  4583. function receivedMaxCalls(expectation) {
  4584. if (typeof expectation.maxCalls != "number") {
  4585. return false;
  4586. }
  4587. return expectation.callCount == expectation.maxCalls;
  4588. }
  4589. function verifyMatcher(possibleMatcher, arg) {
  4590. if (match && match.isMatcher(possibleMatcher)) {
  4591. return possibleMatcher.test(arg);
  4592. } else {
  4593. return true;
  4594. }
  4595. }
  4596. sinon.expectation = {
  4597. minCalls: 1,
  4598. maxCalls: 1,
  4599. create: function create(methodName) {
  4600. var expectation = sinon.extend(sinon.stub.create(), sinon.expectation);
  4601. delete expectation.create;
  4602. expectation.method = methodName;
  4603. return expectation;
  4604. },
  4605. invoke: function invoke(func, thisValue, args) {
  4606. this.verifyCallAllowed(thisValue, args);
  4607. return sinon.spy.invoke.apply(this, arguments);
  4608. },
  4609. atLeast: function atLeast(num) {
  4610. if (typeof num != "number") {
  4611. throw new TypeError("'" + num + "' is not number");
  4612. }
  4613. if (!this.limitsSet) {
  4614. this.maxCalls = null;
  4615. this.limitsSet = true;
  4616. }
  4617. this.minCalls = num;
  4618. return this;
  4619. },
  4620. atMost: function atMost(num) {
  4621. if (typeof num != "number") {
  4622. throw new TypeError("'" + num + "' is not number");
  4623. }
  4624. if (!this.limitsSet) {
  4625. this.minCalls = null;
  4626. this.limitsSet = true;
  4627. }
  4628. this.maxCalls = num;
  4629. return this;
  4630. },
  4631. never: function never() {
  4632. return this.exactly(0);
  4633. },
  4634. once: function once() {
  4635. return this.exactly(1);
  4636. },
  4637. twice: function twice() {
  4638. return this.exactly(2);
  4639. },
  4640. thrice: function thrice() {
  4641. return this.exactly(3);
  4642. },
  4643. exactly: function exactly(num) {
  4644. if (typeof num != "number") {
  4645. throw new TypeError("'" + num + "' is not a number");
  4646. }
  4647. this.atLeast(num);
  4648. return this.atMost(num);
  4649. },
  4650. met: function met() {
  4651. return !this.failed && receivedMinCalls(this);
  4652. },
  4653. verifyCallAllowed: function verifyCallAllowed(thisValue, args) {
  4654. if (receivedMaxCalls(this)) {
  4655. this.failed = true;
  4656. sinon.expectation.fail(this.method + " already called " + times(this.maxCalls));
  4657. }
  4658. if ("expectedThis" in this && this.expectedThis !== thisValue) {
  4659. sinon.expectation.fail(this.method + " called with " + thisValue + " as thisValue, expected " +
  4660. this.expectedThis);
  4661. }
  4662. if (!("expectedArguments" in this)) {
  4663. return;
  4664. }
  4665. if (!args) {
  4666. sinon.expectation.fail(this.method + " received no arguments, expected " +
  4667. sinon.format(this.expectedArguments));
  4668. }
  4669. if (args.length < this.expectedArguments.length) {
  4670. sinon.expectation.fail(this.method + " received too few arguments (" + sinon.format(args) +
  4671. "), expected " + sinon.format(this.expectedArguments));
  4672. }
  4673. if (this.expectsExactArgCount &&
  4674. args.length != this.expectedArguments.length) {
  4675. sinon.expectation.fail(this.method + " received too many arguments (" + sinon.format(args) +
  4676. "), expected " + sinon.format(this.expectedArguments));
  4677. }
  4678. for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) {
  4679. if (!verifyMatcher(this.expectedArguments[i], args[i])) {
  4680. sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) +
  4681. ", didn't match " + this.expectedArguments.toString());
  4682. }
  4683. if (!sinon.deepEqual(this.expectedArguments[i], args[i])) {
  4684. sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) +
  4685. ", expected " + sinon.format(this.expectedArguments));
  4686. }
  4687. }
  4688. },
  4689. allowsCall: function allowsCall(thisValue, args) {
  4690. if (this.met() && receivedMaxCalls(this)) {
  4691. return false;
  4692. }
  4693. if ("expectedThis" in this && this.expectedThis !== thisValue) {
  4694. return false;
  4695. }
  4696. if (!("expectedArguments" in this)) {
  4697. return true;
  4698. }
  4699. args = args || [];
  4700. if (args.length < this.expectedArguments.length) {
  4701. return false;
  4702. }
  4703. if (this.expectsExactArgCount &&
  4704. args.length != this.expectedArguments.length) {
  4705. return false;
  4706. }
  4707. for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) {
  4708. if (!verifyMatcher(this.expectedArguments[i], args[i])) {
  4709. return false;
  4710. }
  4711. if (!sinon.deepEqual(this.expectedArguments[i], args[i])) {
  4712. return false;
  4713. }
  4714. }
  4715. return true;
  4716. },
  4717. withArgs: function withArgs() {
  4718. this.expectedArguments = slice.call(arguments);
  4719. return this;
  4720. },
  4721. withExactArgs: function withExactArgs() {
  4722. this.withArgs.apply(this, arguments);
  4723. this.expectsExactArgCount = true;
  4724. return this;
  4725. },
  4726. on: function on(thisValue) {
  4727. this.expectedThis = thisValue;
  4728. return this;
  4729. },
  4730. toString: function () {
  4731. var args = (this.expectedArguments || []).slice();
  4732. if (!this.expectsExactArgCount) {
  4733. push.call(args, "[...]");
  4734. }
  4735. var callStr = sinon.spyCall.toString.call({
  4736. proxy: this.method || "anonymous mock expectation",
  4737. args: args
  4738. });
  4739. var message = callStr.replace(", [...", "[, ...") + " " +
  4740. expectedCallCountInWords(this);
  4741. if (this.met()) {
  4742. return "Expectation met: " + message;
  4743. }
  4744. return "Expected " + message + " (" +
  4745. callCountInWords(this.callCount) + ")";
  4746. },
  4747. verify: function verify() {
  4748. if (!this.met()) {
  4749. sinon.expectation.fail(this.toString());
  4750. } else {
  4751. sinon.expectation.pass(this.toString());
  4752. }
  4753. return true;
  4754. },
  4755. pass: function pass(message) {
  4756. sinon.assert.pass(message);
  4757. },
  4758. fail: function fail(message) {
  4759. var exception = new Error(message);
  4760. exception.name = "ExpectationError";
  4761. throw exception;
  4762. }
  4763. };
  4764. sinon.mock = mock;
  4765. return mock;
  4766. }
  4767. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  4768. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  4769. function loadDependencies(require, exports, module) {
  4770. var sinon = require("./util/core");
  4771. require("./times_in_words");
  4772. require("./call");
  4773. require("./extend");
  4774. require("./match");
  4775. require("./spy");
  4776. require("./stub");
  4777. require("./format");
  4778. module.exports = makeApi(sinon);
  4779. }
  4780. if (isAMD) {
  4781. define(loadDependencies);
  4782. } else if (isNode) {
  4783. loadDependencies(require, module.exports, module);
  4784. } else if (!sinon) {
  4785. return;
  4786. } else {
  4787. makeApi(sinon);
  4788. }
  4789. }(typeof sinon == "object" && sinon || null));
  4790. },{"./call":27,"./extend":29,"./format":30,"./match":32,"./spy":35,"./stub":36,"./times_in_words":39,"./util/core":41}],34:[function(require,module,exports){
  4791. /**
  4792. * @depend util/core.js
  4793. * @depend extend.js
  4794. * @depend collection.js
  4795. * @depend util/fake_timers.js
  4796. * @depend util/fake_server_with_clock.js
  4797. */
  4798. /**
  4799. * Manages fake collections as well as fake utilities such as Sinon's
  4800. * timers and fake XHR implementation in one convenient object.
  4801. *
  4802. * @author Christian Johansen (christian@cjohansen.no)
  4803. * @license BSD
  4804. *
  4805. * Copyright (c) 2010-2013 Christian Johansen
  4806. */
  4807. "use strict";
  4808. (function () {
  4809. function makeApi(sinon) {
  4810. var push = [].push;
  4811. function exposeValue(sandbox, config, key, value) {
  4812. if (!value) {
  4813. return;
  4814. }
  4815. if (config.injectInto && !(key in config.injectInto)) {
  4816. config.injectInto[key] = value;
  4817. sandbox.injectedKeys.push(key);
  4818. } else {
  4819. push.call(sandbox.args, value);
  4820. }
  4821. }
  4822. function prepareSandboxFromConfig(config) {
  4823. var sandbox = sinon.create(sinon.sandbox);
  4824. if (config.useFakeServer) {
  4825. if (typeof config.useFakeServer == "object") {
  4826. sandbox.serverPrototype = config.useFakeServer;
  4827. }
  4828. sandbox.useFakeServer();
  4829. }
  4830. if (config.useFakeTimers) {
  4831. if (typeof config.useFakeTimers == "object") {
  4832. sandbox.useFakeTimers.apply(sandbox, config.useFakeTimers);
  4833. } else {
  4834. sandbox.useFakeTimers();
  4835. }
  4836. }
  4837. return sandbox;
  4838. }
  4839. sinon.sandbox = sinon.extend(sinon.create(sinon.collection), {
  4840. useFakeTimers: function useFakeTimers() {
  4841. this.clock = sinon.useFakeTimers.apply(sinon, arguments);
  4842. return this.add(this.clock);
  4843. },
  4844. serverPrototype: sinon.fakeServer,
  4845. useFakeServer: function useFakeServer() {
  4846. var proto = this.serverPrototype || sinon.fakeServer;
  4847. if (!proto || !proto.create) {
  4848. return null;
  4849. }
  4850. this.server = proto.create();
  4851. return this.add(this.server);
  4852. },
  4853. inject: function (obj) {
  4854. sinon.collection.inject.call(this, obj);
  4855. if (this.clock) {
  4856. obj.clock = this.clock;
  4857. }
  4858. if (this.server) {
  4859. obj.server = this.server;
  4860. obj.requests = this.server.requests;
  4861. }
  4862. obj.match = sinon.match;
  4863. return obj;
  4864. },
  4865. restore: function () {
  4866. sinon.collection.restore.apply(this, arguments);
  4867. this.restoreContext();
  4868. },
  4869. restoreContext: function () {
  4870. if (this.injectedKeys) {
  4871. for (var i = 0, j = this.injectedKeys.length; i < j; i++) {
  4872. delete this.injectInto[this.injectedKeys[i]];
  4873. }
  4874. this.injectedKeys = [];
  4875. }
  4876. },
  4877. create: function (config) {
  4878. if (!config) {
  4879. return sinon.create(sinon.sandbox);
  4880. }
  4881. var sandbox = prepareSandboxFromConfig(config);
  4882. sandbox.args = sandbox.args || [];
  4883. sandbox.injectedKeys = [];
  4884. sandbox.injectInto = config.injectInto;
  4885. var prop, value, exposed = sandbox.inject({});
  4886. if (config.properties) {
  4887. for (var i = 0, l = config.properties.length; i < l; i++) {
  4888. prop = config.properties[i];
  4889. value = exposed[prop] || prop == "sandbox" && sandbox;
  4890. exposeValue(sandbox, config, prop, value);
  4891. }
  4892. } else {
  4893. exposeValue(sandbox, config, "sandbox", value);
  4894. }
  4895. return sandbox;
  4896. },
  4897. match: sinon.match
  4898. });
  4899. sinon.sandbox.useFakeXMLHttpRequest = sinon.sandbox.useFakeServer;
  4900. return sinon.sandbox;
  4901. }
  4902. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  4903. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  4904. function loadDependencies(require, exports, module) {
  4905. var sinon = require("./util/core");
  4906. require("./extend");
  4907. require("./util/fake_server_with_clock");
  4908. require("./util/fake_timers");
  4909. require("./collection");
  4910. module.exports = makeApi(sinon);
  4911. }
  4912. if (isAMD) {
  4913. define(loadDependencies);
  4914. } else if (isNode) {
  4915. loadDependencies(require, module.exports, module);
  4916. } else if (!sinon) {
  4917. return;
  4918. } else {
  4919. makeApi(sinon);
  4920. }
  4921. }());
  4922. },{"./collection":28,"./extend":29,"./util/core":41,"./util/fake_server_with_clock":44,"./util/fake_timers":45}],35:[function(require,module,exports){
  4923. /**
  4924. * @depend times_in_words.js
  4925. * @depend util/core.js
  4926. * @depend extend.js
  4927. * @depend call.js
  4928. * @depend format.js
  4929. */
  4930. /**
  4931. * Spy functions
  4932. *
  4933. * @author Christian Johansen (christian@cjohansen.no)
  4934. * @license BSD
  4935. *
  4936. * Copyright (c) 2010-2013 Christian Johansen
  4937. */
  4938. "use strict";
  4939. (function (sinon) {
  4940. function makeApi(sinon) {
  4941. var push = Array.prototype.push;
  4942. var slice = Array.prototype.slice;
  4943. var callId = 0;
  4944. function spy(object, property, types) {
  4945. if (!property && typeof object == "function") {
  4946. return spy.create(object);
  4947. }
  4948. if (!object && !property) {
  4949. return spy.create(function () { });
  4950. }
  4951. if (types) {
  4952. var methodDesc = sinon.getPropertyDescriptor(object, property);
  4953. for (var i = 0; i < types.length; i++) {
  4954. methodDesc[types[i]] = spy.create(methodDesc[types[i]]);
  4955. }
  4956. return sinon.wrapMethod(object, property, methodDesc);
  4957. } else {
  4958. var method = object[property];
  4959. return sinon.wrapMethod(object, property, spy.create(method));
  4960. }
  4961. }
  4962. function matchingFake(fakes, args, strict) {
  4963. if (!fakes) {
  4964. return;
  4965. }
  4966. for (var i = 0, l = fakes.length; i < l; i++) {
  4967. if (fakes[i].matches(args, strict)) {
  4968. return fakes[i];
  4969. }
  4970. }
  4971. }
  4972. function incrementCallCount() {
  4973. this.called = true;
  4974. this.callCount += 1;
  4975. this.notCalled = false;
  4976. this.calledOnce = this.callCount == 1;
  4977. this.calledTwice = this.callCount == 2;
  4978. this.calledThrice = this.callCount == 3;
  4979. }
  4980. function createCallProperties() {
  4981. this.firstCall = this.getCall(0);
  4982. this.secondCall = this.getCall(1);
  4983. this.thirdCall = this.getCall(2);
  4984. this.lastCall = this.getCall(this.callCount - 1);
  4985. }
  4986. var vars = "a,b,c,d,e,f,g,h,i,j,k,l";
  4987. function createProxy(func, proxyLength) {
  4988. // Retain the function length:
  4989. var p;
  4990. if (proxyLength) {
  4991. eval("p = (function proxy(" + vars.substring(0, proxyLength * 2 - 1) +
  4992. ") { return p.invoke(func, this, slice.call(arguments)); });");
  4993. } else {
  4994. p = function proxy() {
  4995. return p.invoke(func, this, slice.call(arguments));
  4996. };
  4997. }
  4998. return p;
  4999. }
  5000. var uuid = 0;
  5001. // Public API
  5002. var spyApi = {
  5003. reset: function () {
  5004. if (this.invoking) {
  5005. var err = new Error("Cannot reset Sinon function while invoking it. " +
  5006. "Move the call to .reset outside of the callback.");
  5007. err.name = "InvalidResetException";
  5008. throw err;
  5009. }
  5010. this.called = false;
  5011. this.notCalled = true;
  5012. this.calledOnce = false;
  5013. this.calledTwice = false;
  5014. this.calledThrice = false;
  5015. this.callCount = 0;
  5016. this.firstCall = null;
  5017. this.secondCall = null;
  5018. this.thirdCall = null;
  5019. this.lastCall = null;
  5020. this.args = [];
  5021. this.returnValues = [];
  5022. this.thisValues = [];
  5023. this.exceptions = [];
  5024. this.callIds = [];
  5025. if (this.fakes) {
  5026. for (var i = 0; i < this.fakes.length; i++) {
  5027. this.fakes[i].reset();
  5028. }
  5029. }
  5030. return this;
  5031. },
  5032. create: function create(func, spyLength) {
  5033. var name;
  5034. if (typeof func != "function") {
  5035. func = function () { };
  5036. } else {
  5037. name = sinon.functionName(func);
  5038. }
  5039. if (!spyLength) {
  5040. spyLength = func.length;
  5041. }
  5042. var proxy = createProxy(func, spyLength);
  5043. sinon.extend(proxy, spy);
  5044. delete proxy.create;
  5045. sinon.extend(proxy, func);
  5046. proxy.reset();
  5047. proxy.prototype = func.prototype;
  5048. proxy.displayName = name || "spy";
  5049. proxy.toString = sinon.functionToString;
  5050. proxy.instantiateFake = sinon.spy.create;
  5051. proxy.id = "spy#" + uuid++;
  5052. return proxy;
  5053. },
  5054. invoke: function invoke(func, thisValue, args) {
  5055. var matching = matchingFake(this.fakes, args);
  5056. var exception, returnValue;
  5057. incrementCallCount.call(this);
  5058. push.call(this.thisValues, thisValue);
  5059. push.call(this.args, args);
  5060. push.call(this.callIds, callId++);
  5061. // Make call properties available from within the spied function:
  5062. createCallProperties.call(this);
  5063. try {
  5064. this.invoking = true;
  5065. if (matching) {
  5066. returnValue = matching.invoke(func, thisValue, args);
  5067. } else {
  5068. returnValue = (this.func || func).apply(thisValue, args);
  5069. }
  5070. var thisCall = this.getCall(this.callCount - 1);
  5071. if (thisCall.calledWithNew() && typeof returnValue !== "object") {
  5072. returnValue = thisValue;
  5073. }
  5074. } catch (e) {
  5075. exception = e;
  5076. } finally {
  5077. delete this.invoking;
  5078. }
  5079. push.call(this.exceptions, exception);
  5080. push.call(this.returnValues, returnValue);
  5081. // Make return value and exception available in the calls:
  5082. createCallProperties.call(this);
  5083. if (exception !== undefined) {
  5084. throw exception;
  5085. }
  5086. return returnValue;
  5087. },
  5088. named: function named(name) {
  5089. this.displayName = name;
  5090. return this;
  5091. },
  5092. getCall: function getCall(i) {
  5093. if (i < 0 || i >= this.callCount) {
  5094. return null;
  5095. }
  5096. return sinon.spyCall(this, this.thisValues[i], this.args[i],
  5097. this.returnValues[i], this.exceptions[i],
  5098. this.callIds[i]);
  5099. },
  5100. getCalls: function () {
  5101. var calls = [];
  5102. var i;
  5103. for (i = 0; i < this.callCount; i++) {
  5104. calls.push(this.getCall(i));
  5105. }
  5106. return calls;
  5107. },
  5108. calledBefore: function calledBefore(spyFn) {
  5109. if (!this.called) {
  5110. return false;
  5111. }
  5112. if (!spyFn.called) {
  5113. return true;
  5114. }
  5115. return this.callIds[0] < spyFn.callIds[spyFn.callIds.length - 1];
  5116. },
  5117. calledAfter: function calledAfter(spyFn) {
  5118. if (!this.called || !spyFn.called) {
  5119. return false;
  5120. }
  5121. return this.callIds[this.callCount - 1] > spyFn.callIds[spyFn.callCount - 1];
  5122. },
  5123. withArgs: function () {
  5124. var args = slice.call(arguments);
  5125. if (this.fakes) {
  5126. var match = matchingFake(this.fakes, args, true);
  5127. if (match) {
  5128. return match;
  5129. }
  5130. } else {
  5131. this.fakes = [];
  5132. }
  5133. var original = this;
  5134. var fake = this.instantiateFake();
  5135. fake.matchingAguments = args;
  5136. fake.parent = this;
  5137. push.call(this.fakes, fake);
  5138. fake.withArgs = function () {
  5139. return original.withArgs.apply(original, arguments);
  5140. };
  5141. for (var i = 0; i < this.args.length; i++) {
  5142. if (fake.matches(this.args[i])) {
  5143. incrementCallCount.call(fake);
  5144. push.call(fake.thisValues, this.thisValues[i]);
  5145. push.call(fake.args, this.args[i]);
  5146. push.call(fake.returnValues, this.returnValues[i]);
  5147. push.call(fake.exceptions, this.exceptions[i]);
  5148. push.call(fake.callIds, this.callIds[i]);
  5149. }
  5150. }
  5151. createCallProperties.call(fake);
  5152. return fake;
  5153. },
  5154. matches: function (args, strict) {
  5155. var margs = this.matchingAguments;
  5156. if (margs.length <= args.length &&
  5157. sinon.deepEqual(margs, args.slice(0, margs.length))) {
  5158. return !strict || margs.length == args.length;
  5159. }
  5160. },
  5161. printf: function (format) {
  5162. var spy = this;
  5163. var args = slice.call(arguments, 1);
  5164. var formatter;
  5165. return (format || "").replace(/%(.)/g, function (match, specifyer) {
  5166. formatter = spyApi.formatters[specifyer];
  5167. if (typeof formatter == "function") {
  5168. return formatter.call(null, spy, args);
  5169. } else if (!isNaN(parseInt(specifyer, 10))) {
  5170. return sinon.format(args[specifyer - 1]);
  5171. }
  5172. return "%" + specifyer;
  5173. });
  5174. }
  5175. };
  5176. function delegateToCalls(method, matchAny, actual, notCalled) {
  5177. spyApi[method] = function () {
  5178. if (!this.called) {
  5179. if (notCalled) {
  5180. return notCalled.apply(this, arguments);
  5181. }
  5182. return false;
  5183. }
  5184. var currentCall;
  5185. var matches = 0;
  5186. for (var i = 0, l = this.callCount; i < l; i += 1) {
  5187. currentCall = this.getCall(i);
  5188. if (currentCall[actual || method].apply(currentCall, arguments)) {
  5189. matches += 1;
  5190. if (matchAny) {
  5191. return true;
  5192. }
  5193. }
  5194. }
  5195. return matches === this.callCount;
  5196. };
  5197. }
  5198. delegateToCalls("calledOn", true);
  5199. delegateToCalls("alwaysCalledOn", false, "calledOn");
  5200. delegateToCalls("calledWith", true);
  5201. delegateToCalls("calledWithMatch", true);
  5202. delegateToCalls("alwaysCalledWith", false, "calledWith");
  5203. delegateToCalls("alwaysCalledWithMatch", false, "calledWithMatch");
  5204. delegateToCalls("calledWithExactly", true);
  5205. delegateToCalls("alwaysCalledWithExactly", false, "calledWithExactly");
  5206. delegateToCalls("neverCalledWith", false, "notCalledWith",
  5207. function () { return true; });
  5208. delegateToCalls("neverCalledWithMatch", false, "notCalledWithMatch",
  5209. function () { return true; });
  5210. delegateToCalls("threw", true);
  5211. delegateToCalls("alwaysThrew", false, "threw");
  5212. delegateToCalls("returned", true);
  5213. delegateToCalls("alwaysReturned", false, "returned");
  5214. delegateToCalls("calledWithNew", true);
  5215. delegateToCalls("alwaysCalledWithNew", false, "calledWithNew");
  5216. delegateToCalls("callArg", false, "callArgWith", function () {
  5217. throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
  5218. });
  5219. spyApi.callArgWith = spyApi.callArg;
  5220. delegateToCalls("callArgOn", false, "callArgOnWith", function () {
  5221. throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
  5222. });
  5223. spyApi.callArgOnWith = spyApi.callArgOn;
  5224. delegateToCalls("yield", false, "yield", function () {
  5225. throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
  5226. });
  5227. // "invokeCallback" is an alias for "yield" since "yield" is invalid in strict mode.
  5228. spyApi.invokeCallback = spyApi.yield;
  5229. delegateToCalls("yieldOn", false, "yieldOn", function () {
  5230. throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
  5231. });
  5232. delegateToCalls("yieldTo", false, "yieldTo", function (property) {
  5233. throw new Error(this.toString() + " cannot yield to '" + property +
  5234. "' since it was not yet invoked.");
  5235. });
  5236. delegateToCalls("yieldToOn", false, "yieldToOn", function (property) {
  5237. throw new Error(this.toString() + " cannot yield to '" + property +
  5238. "' since it was not yet invoked.");
  5239. });
  5240. spyApi.formatters = {
  5241. c: function (spy) {
  5242. return sinon.timesInWords(spy.callCount);
  5243. },
  5244. n: function (spy) {
  5245. return spy.toString();
  5246. },
  5247. C: function (spy) {
  5248. var calls = [];
  5249. for (var i = 0, l = spy.callCount; i < l; ++i) {
  5250. var stringifiedCall = " " + spy.getCall(i).toString();
  5251. if (/\n/.test(calls[i - 1])) {
  5252. stringifiedCall = "\n" + stringifiedCall;
  5253. }
  5254. push.call(calls, stringifiedCall);
  5255. }
  5256. return calls.length > 0 ? "\n" + calls.join("\n") : "";
  5257. },
  5258. t: function (spy) {
  5259. var objects = [];
  5260. for (var i = 0, l = spy.callCount; i < l; ++i) {
  5261. push.call(objects, sinon.format(spy.thisValues[i]));
  5262. }
  5263. return objects.join(", ");
  5264. },
  5265. "*": function (spy, args) {
  5266. var formatted = [];
  5267. for (var i = 0, l = args.length; i < l; ++i) {
  5268. push.call(formatted, sinon.format(args[i]));
  5269. }
  5270. return formatted.join(", ");
  5271. }
  5272. };
  5273. sinon.extend(spy, spyApi);
  5274. spy.spyCall = sinon.spyCall;
  5275. sinon.spy = spy;
  5276. return spy;
  5277. }
  5278. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  5279. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  5280. function loadDependencies(require, exports, module) {
  5281. var sinon = require("./util/core");
  5282. require("./call");
  5283. require("./extend");
  5284. require("./times_in_words");
  5285. require("./format");
  5286. module.exports = makeApi(sinon);
  5287. }
  5288. if (isAMD) {
  5289. define(loadDependencies);
  5290. } else if (isNode) {
  5291. loadDependencies(require, module.exports, module);
  5292. } else if (!sinon) {
  5293. return;
  5294. } else {
  5295. makeApi(sinon);
  5296. }
  5297. }(typeof sinon == "object" && sinon || null));
  5298. },{"./call":27,"./extend":29,"./format":30,"./times_in_words":39,"./util/core":41}],36:[function(require,module,exports){
  5299. /**
  5300. * @depend util/core.js
  5301. * @depend extend.js
  5302. * @depend spy.js
  5303. * @depend behavior.js
  5304. */
  5305. /**
  5306. * Stub functions
  5307. *
  5308. * @author Christian Johansen (christian@cjohansen.no)
  5309. * @license BSD
  5310. *
  5311. * Copyright (c) 2010-2013 Christian Johansen
  5312. */
  5313. "use strict";
  5314. (function (sinon) {
  5315. function makeApi(sinon) {
  5316. function stub(object, property, func) {
  5317. if (!!func && typeof func != "function" && typeof func != "object") {
  5318. throw new TypeError("Custom stub should be a function or a property descriptor");
  5319. }
  5320. var wrapper;
  5321. if (func) {
  5322. if (typeof func == "function") {
  5323. wrapper = sinon.spy && sinon.spy.create ? sinon.spy.create(func) : func;
  5324. } else {
  5325. wrapper = func;
  5326. if (sinon.spy && sinon.spy.create) {
  5327. var types = sinon.objectKeys(wrapper);
  5328. for (var i = 0; i < types.length; i++) {
  5329. wrapper[types[i]] = sinon.spy.create(wrapper[types[i]]);
  5330. }
  5331. }
  5332. }
  5333. } else {
  5334. var stubLength = 0;
  5335. if (typeof object == "object" && typeof object[property] == "function") {
  5336. stubLength = object[property].length;
  5337. }
  5338. wrapper = stub.create(stubLength);
  5339. }
  5340. if (!object && typeof property === "undefined") {
  5341. return sinon.stub.create();
  5342. }
  5343. if (typeof property === "undefined" && typeof object == "object") {
  5344. for (var prop in object) {
  5345. if (typeof object[prop] === "function") {
  5346. stub(object, prop);
  5347. }
  5348. }
  5349. return object;
  5350. }
  5351. return sinon.wrapMethod(object, property, wrapper);
  5352. }
  5353. function getDefaultBehavior(stub) {
  5354. return stub.defaultBehavior || getParentBehaviour(stub) || sinon.behavior.create(stub);
  5355. }
  5356. function getParentBehaviour(stub) {
  5357. return (stub.parent && getCurrentBehavior(stub.parent));
  5358. }
  5359. function getCurrentBehavior(stub) {
  5360. var behavior = stub.behaviors[stub.callCount - 1];
  5361. return behavior && behavior.isPresent() ? behavior : getDefaultBehavior(stub);
  5362. }
  5363. var uuid = 0;
  5364. var proto = {
  5365. create: function create(stubLength) {
  5366. var functionStub = function () {
  5367. return getCurrentBehavior(functionStub).invoke(this, arguments);
  5368. };
  5369. functionStub.id = "stub#" + uuid++;
  5370. var orig = functionStub;
  5371. functionStub = sinon.spy.create(functionStub, stubLength);
  5372. functionStub.func = orig;
  5373. sinon.extend(functionStub, stub);
  5374. functionStub.instantiateFake = sinon.stub.create;
  5375. functionStub.displayName = "stub";
  5376. functionStub.toString = sinon.functionToString;
  5377. functionStub.defaultBehavior = null;
  5378. functionStub.behaviors = [];
  5379. return functionStub;
  5380. },
  5381. resetBehavior: function () {
  5382. var i;
  5383. this.defaultBehavior = null;
  5384. this.behaviors = [];
  5385. delete this.returnValue;
  5386. delete this.returnArgAt;
  5387. this.returnThis = false;
  5388. if (this.fakes) {
  5389. for (i = 0; i < this.fakes.length; i++) {
  5390. this.fakes[i].resetBehavior();
  5391. }
  5392. }
  5393. },
  5394. onCall: function onCall(index) {
  5395. if (!this.behaviors[index]) {
  5396. this.behaviors[index] = sinon.behavior.create(this);
  5397. }
  5398. return this.behaviors[index];
  5399. },
  5400. onFirstCall: function onFirstCall() {
  5401. return this.onCall(0);
  5402. },
  5403. onSecondCall: function onSecondCall() {
  5404. return this.onCall(1);
  5405. },
  5406. onThirdCall: function onThirdCall() {
  5407. return this.onCall(2);
  5408. }
  5409. };
  5410. for (var method in sinon.behavior) {
  5411. if (sinon.behavior.hasOwnProperty(method) &&
  5412. !proto.hasOwnProperty(method) &&
  5413. method != "create" &&
  5414. method != "withArgs" &&
  5415. method != "invoke") {
  5416. proto[method] = (function (behaviorMethod) {
  5417. return function () {
  5418. this.defaultBehavior = this.defaultBehavior || sinon.behavior.create(this);
  5419. this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments);
  5420. return this;
  5421. };
  5422. }(method));
  5423. }
  5424. }
  5425. sinon.extend(stub, proto);
  5426. sinon.stub = stub;
  5427. return stub;
  5428. }
  5429. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  5430. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  5431. function loadDependencies(require, exports, module) {
  5432. var sinon = require("./util/core");
  5433. require("./behavior");
  5434. require("./spy");
  5435. require("./extend");
  5436. module.exports = makeApi(sinon);
  5437. }
  5438. if (isAMD) {
  5439. define(loadDependencies);
  5440. } else if (isNode) {
  5441. loadDependencies(require, module.exports, module);
  5442. } else if (!sinon) {
  5443. return;
  5444. } else {
  5445. makeApi(sinon);
  5446. }
  5447. }(typeof sinon == "object" && sinon || null));
  5448. },{"./behavior":26,"./extend":29,"./spy":35,"./util/core":41}],37:[function(require,module,exports){
  5449. /**
  5450. * @depend util/core.js
  5451. * @depend sandbox.js
  5452. */
  5453. /**
  5454. * Test function, sandboxes fakes
  5455. *
  5456. * @author Christian Johansen (christian@cjohansen.no)
  5457. * @license BSD
  5458. *
  5459. * Copyright (c) 2010-2013 Christian Johansen
  5460. */
  5461. "use strict";
  5462. (function (sinon) {
  5463. function makeApi(sinon) {
  5464. var slice = Array.prototype.slice;
  5465. function test(callback) {
  5466. var type = typeof callback;
  5467. if (type != "function") {
  5468. throw new TypeError("sinon.test needs to wrap a test function, got " + type);
  5469. }
  5470. function sinonSandboxedTest() {
  5471. var config = sinon.getConfig(sinon.config);
  5472. config.injectInto = config.injectIntoThis && this || config.injectInto;
  5473. var sandbox = sinon.sandbox.create(config);
  5474. var args = slice.call(arguments);
  5475. var oldDone = args.length && args[args.length - 1];
  5476. var exception, result;
  5477. if (typeof oldDone == "function") {
  5478. args[args.length - 1] = function sinonDone(result) {
  5479. if (result) {
  5480. sandbox.restore();
  5481. throw exception;
  5482. } else {
  5483. sandbox.verifyAndRestore();
  5484. }
  5485. oldDone(result);
  5486. };
  5487. }
  5488. try {
  5489. result = callback.apply(this, args.concat(sandbox.args));
  5490. } catch (e) {
  5491. exception = e;
  5492. }
  5493. if (typeof oldDone != "function") {
  5494. if (typeof exception !== "undefined") {
  5495. sandbox.restore();
  5496. throw exception;
  5497. } else {
  5498. sandbox.verifyAndRestore();
  5499. }
  5500. }
  5501. return result;
  5502. }
  5503. if (callback.length) {
  5504. return function sinonAsyncSandboxedTest(callback) {
  5505. return sinonSandboxedTest.apply(this, arguments);
  5506. };
  5507. }
  5508. return sinonSandboxedTest;
  5509. }
  5510. test.config = {
  5511. injectIntoThis: true,
  5512. injectInto: null,
  5513. properties: ["spy", "stub", "mock", "clock", "server", "requests"],
  5514. useFakeTimers: true,
  5515. useFakeServer: true
  5516. };
  5517. sinon.test = test;
  5518. return test;
  5519. }
  5520. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  5521. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  5522. function loadDependencies(require, exports, module) {
  5523. var sinon = require("./util/core");
  5524. require("./sandbox");
  5525. module.exports = makeApi(sinon);
  5526. }
  5527. if (isAMD) {
  5528. define(loadDependencies);
  5529. } else if (isNode) {
  5530. loadDependencies(require, module.exports, module);
  5531. } else if (sinon) {
  5532. makeApi(sinon);
  5533. }
  5534. }(typeof sinon == "object" && sinon || null));
  5535. },{"./sandbox":34,"./util/core":41}],38:[function(require,module,exports){
  5536. /**
  5537. * @depend util/core.js
  5538. * @depend test.js
  5539. */
  5540. /**
  5541. * Test case, sandboxes all test functions
  5542. *
  5543. * @author Christian Johansen (christian@cjohansen.no)
  5544. * @license BSD
  5545. *
  5546. * Copyright (c) 2010-2013 Christian Johansen
  5547. */
  5548. "use strict";
  5549. (function (sinon) {
  5550. function createTest(property, setUp, tearDown) {
  5551. return function () {
  5552. if (setUp) {
  5553. setUp.apply(this, arguments);
  5554. }
  5555. var exception, result;
  5556. try {
  5557. result = property.apply(this, arguments);
  5558. } catch (e) {
  5559. exception = e;
  5560. }
  5561. if (tearDown) {
  5562. tearDown.apply(this, arguments);
  5563. }
  5564. if (exception) {
  5565. throw exception;
  5566. }
  5567. return result;
  5568. };
  5569. }
  5570. function makeApi(sinon) {
  5571. function testCase(tests, prefix) {
  5572. /*jsl:ignore*/
  5573. if (!tests || typeof tests != "object") {
  5574. throw new TypeError("sinon.testCase needs an object with test functions");
  5575. }
  5576. /*jsl:end*/
  5577. prefix = prefix || "test";
  5578. var rPrefix = new RegExp("^" + prefix);
  5579. var methods = {}, testName, property, method;
  5580. var setUp = tests.setUp;
  5581. var tearDown = tests.tearDown;
  5582. for (testName in tests) {
  5583. if (tests.hasOwnProperty(testName)) {
  5584. property = tests[testName];
  5585. if (/^(setUp|tearDown)$/.test(testName)) {
  5586. continue;
  5587. }
  5588. if (typeof property == "function" && rPrefix.test(testName)) {
  5589. method = property;
  5590. if (setUp || tearDown) {
  5591. method = createTest(property, setUp, tearDown);
  5592. }
  5593. methods[testName] = sinon.test(method);
  5594. } else {
  5595. methods[testName] = tests[testName];
  5596. }
  5597. }
  5598. }
  5599. return methods;
  5600. }
  5601. sinon.testCase = testCase;
  5602. return testCase;
  5603. }
  5604. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  5605. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  5606. function loadDependencies(require, exports, module) {
  5607. var sinon = require("./util/core");
  5608. require("./test");
  5609. module.exports = makeApi(sinon);
  5610. }
  5611. if (isAMD) {
  5612. define(loadDependencies);
  5613. } else if (isNode) {
  5614. loadDependencies(require, module.exports, module);
  5615. } else if (!sinon) {
  5616. return;
  5617. } else {
  5618. makeApi(sinon);
  5619. }
  5620. }(typeof sinon == "object" && sinon || null));
  5621. },{"./test":37,"./util/core":41}],39:[function(require,module,exports){
  5622. /**
  5623. * @depend util/core.js
  5624. */
  5625. "use strict";
  5626. (function (sinon) {
  5627. function makeApi(sinon) {
  5628. function timesInWords(count) {
  5629. switch (count) {
  5630. case 1:
  5631. return "once";
  5632. case 2:
  5633. return "twice";
  5634. case 3:
  5635. return "thrice";
  5636. default:
  5637. return (count || 0) + " times";
  5638. }
  5639. }
  5640. sinon.timesInWords = timesInWords;
  5641. return sinon.timesInWords;
  5642. }
  5643. function loadDependencies(require, exports, module) {
  5644. var sinon = require("./util/core");
  5645. module.exports = makeApi(sinon);
  5646. }
  5647. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  5648. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  5649. if (isAMD) {
  5650. define(loadDependencies);
  5651. } else if (isNode) {
  5652. loadDependencies(require, module.exports, module);
  5653. } else if (!sinon) {
  5654. return;
  5655. } else {
  5656. makeApi(sinon);
  5657. }
  5658. }(typeof sinon == "object" && sinon || null));
  5659. },{"./util/core":41}],40:[function(require,module,exports){
  5660. /**
  5661. * @depend util/core.js
  5662. */
  5663. /**
  5664. * Format functions
  5665. *
  5666. * @author Christian Johansen (christian@cjohansen.no)
  5667. * @license BSD
  5668. *
  5669. * Copyright (c) 2010-2014 Christian Johansen
  5670. */
  5671. "use strict";
  5672. (function (sinon, formatio) {
  5673. function makeApi(sinon) {
  5674. function typeOf(value) {
  5675. if (value === null) {
  5676. return "null";
  5677. } else if (value === undefined) {
  5678. return "undefined";
  5679. }
  5680. var string = Object.prototype.toString.call(value);
  5681. return string.substring(8, string.length - 1).toLowerCase();
  5682. };
  5683. sinon.typeOf = typeOf;
  5684. return sinon.typeOf;
  5685. }
  5686. function loadDependencies(require, exports, module) {
  5687. var sinon = require("./util/core");
  5688. module.exports = makeApi(sinon);
  5689. }
  5690. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  5691. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  5692. if (isAMD) {
  5693. define(loadDependencies);
  5694. } else if (isNode) {
  5695. loadDependencies(require, module.exports, module);
  5696. } else if (!sinon) {
  5697. return;
  5698. } else {
  5699. makeApi(sinon);
  5700. }
  5701. }(
  5702. (typeof sinon == "object" && sinon || null),
  5703. (typeof formatio == "object" && formatio)
  5704. ));
  5705. },{"./util/core":41}],41:[function(require,module,exports){
  5706. /**
  5707. * @depend ../../sinon.js
  5708. */
  5709. /**
  5710. * Sinon core utilities. For internal use only.
  5711. *
  5712. * @author Christian Johansen (christian@cjohansen.no)
  5713. * @license BSD
  5714. *
  5715. * Copyright (c) 2010-2013 Christian Johansen
  5716. */
  5717. "use strict";
  5718. (function (sinon) {
  5719. var div = typeof document != "undefined" && document.createElement("div");
  5720. var hasOwn = Object.prototype.hasOwnProperty;
  5721. function isDOMNode(obj) {
  5722. var success = false;
  5723. try {
  5724. obj.appendChild(div);
  5725. success = div.parentNode == obj;
  5726. } catch (e) {
  5727. return false;
  5728. } finally {
  5729. try {
  5730. obj.removeChild(div);
  5731. } catch (e) {
  5732. // Remove failed, not much we can do about that
  5733. }
  5734. }
  5735. return success;
  5736. }
  5737. function isElement(obj) {
  5738. return div && obj && obj.nodeType === 1 && isDOMNode(obj);
  5739. }
  5740. function isFunction(obj) {
  5741. return typeof obj === "function" || !!(obj && obj.constructor && obj.call && obj.apply);
  5742. }
  5743. function isReallyNaN(val) {
  5744. return typeof val === "number" && isNaN(val);
  5745. }
  5746. function mirrorProperties(target, source) {
  5747. for (var prop in source) {
  5748. if (!hasOwn.call(target, prop)) {
  5749. target[prop] = source[prop];
  5750. }
  5751. }
  5752. }
  5753. function isRestorable(obj) {
  5754. return typeof obj === "function" && typeof obj.restore === "function" && obj.restore.sinon;
  5755. }
  5756. // Cheap way to detect if we have ES5 support.
  5757. var hasES5Support = "keys" in Object;
  5758. function makeApi(sinon) {
  5759. sinon.wrapMethod = function wrapMethod(object, property, method) {
  5760. if (!object) {
  5761. throw new TypeError("Should wrap property of object");
  5762. }
  5763. if (typeof method != "function" && typeof method != "object") {
  5764. throw new TypeError("Method wrapper should be a function or a property descriptor");
  5765. }
  5766. function checkWrappedMethod(wrappedMethod) {
  5767. if (!isFunction(wrappedMethod)) {
  5768. error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " +
  5769. property + " as function");
  5770. } else if (wrappedMethod.restore && wrappedMethod.restore.sinon) {
  5771. error = new TypeError("Attempted to wrap " + property + " which is already wrapped");
  5772. } else if (wrappedMethod.calledBefore) {
  5773. var verb = !!wrappedMethod.returns ? "stubbed" : "spied on";
  5774. error = new TypeError("Attempted to wrap " + property + " which is already " + verb);
  5775. }
  5776. if (error) {
  5777. if (wrappedMethod && wrappedMethod.stackTrace) {
  5778. error.stack += "\n--------------\n" + wrappedMethod.stackTrace;
  5779. }
  5780. throw error;
  5781. }
  5782. }
  5783. var error, wrappedMethod;
  5784. // IE 8 does not support hasOwnProperty on the window object and Firefox has a problem
  5785. // when using hasOwn.call on objects from other frames.
  5786. var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwn.call(object, property);
  5787. if (hasES5Support) {
  5788. var methodDesc = (typeof method == "function") ? {value: method} : method,
  5789. wrappedMethodDesc = sinon.getPropertyDescriptor(object, property),
  5790. i;
  5791. if (!wrappedMethodDesc) {
  5792. error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " +
  5793. property + " as function");
  5794. } else if (wrappedMethodDesc.restore && wrappedMethodDesc.restore.sinon) {
  5795. error = new TypeError("Attempted to wrap " + property + " which is already wrapped");
  5796. }
  5797. if (error) {
  5798. if (wrappedMethodDesc && wrappedMethodDesc.stackTrace) {
  5799. error.stack += "\n--------------\n" + wrappedMethodDesc.stackTrace;
  5800. }
  5801. throw error;
  5802. }
  5803. var types = sinon.objectKeys(methodDesc);
  5804. for (i = 0; i < types.length; i++) {
  5805. wrappedMethod = wrappedMethodDesc[types[i]];
  5806. checkWrappedMethod(wrappedMethod);
  5807. }
  5808. mirrorProperties(methodDesc, wrappedMethodDesc);
  5809. for (i = 0; i < types.length; i++) {
  5810. mirrorProperties(methodDesc[types[i]], wrappedMethodDesc[types[i]]);
  5811. }
  5812. Object.defineProperty(object, property, methodDesc);
  5813. } else {
  5814. wrappedMethod = object[property];
  5815. checkWrappedMethod(wrappedMethod);
  5816. object[property] = method;
  5817. method.displayName = property;
  5818. }
  5819. method.displayName = property;
  5820. // Set up a stack trace which can be used later to find what line of
  5821. // code the original method was created on.
  5822. method.stackTrace = (new Error("Stack Trace for original")).stack;
  5823. method.restore = function () {
  5824. // For prototype properties try to reset by delete first.
  5825. // If this fails (ex: localStorage on mobile safari) then force a reset
  5826. // via direct assignment.
  5827. if (!owned) {
  5828. try {
  5829. delete object[property];
  5830. } catch (e) {}
  5831. // For native code functions `delete` fails without throwing an error
  5832. // on Chrome < 43, PhantomJS, etc.
  5833. // Use strict equality comparison to check failures then force a reset
  5834. // via direct assignment.
  5835. if (object[property] === method) {
  5836. object[property] = wrappedMethod;
  5837. }
  5838. } else if (hasES5Support) {
  5839. Object.defineProperty(object, property, wrappedMethodDesc);
  5840. }
  5841. if (!hasES5Support && object[property] === method) {
  5842. object[property] = wrappedMethod;
  5843. }
  5844. };
  5845. method.restore.sinon = true;
  5846. if (!hasES5Support) {
  5847. mirrorProperties(method, wrappedMethod);
  5848. }
  5849. return method;
  5850. };
  5851. sinon.create = function create(proto) {
  5852. var F = function () {};
  5853. F.prototype = proto;
  5854. return new F();
  5855. };
  5856. sinon.deepEqual = function deepEqual(a, b) {
  5857. if (sinon.match && sinon.match.isMatcher(a)) {
  5858. return a.test(b);
  5859. }
  5860. if (typeof a != "object" || typeof b != "object") {
  5861. if (isReallyNaN(a) && isReallyNaN(b)) {
  5862. return true;
  5863. } else {
  5864. return a === b;
  5865. }
  5866. }
  5867. if (isElement(a) || isElement(b)) {
  5868. return a === b;
  5869. }
  5870. if (a === b) {
  5871. return true;
  5872. }
  5873. if ((a === null && b !== null) || (a !== null && b === null)) {
  5874. return false;
  5875. }
  5876. if (a instanceof RegExp && b instanceof RegExp) {
  5877. return (a.source === b.source) && (a.global === b.global) &&
  5878. (a.ignoreCase === b.ignoreCase) && (a.multiline === b.multiline);
  5879. }
  5880. var aString = Object.prototype.toString.call(a);
  5881. if (aString != Object.prototype.toString.call(b)) {
  5882. return false;
  5883. }
  5884. if (aString == "[object Date]") {
  5885. return a.valueOf() === b.valueOf();
  5886. }
  5887. var prop, aLength = 0, bLength = 0;
  5888. if (aString == "[object Array]" && a.length !== b.length) {
  5889. return false;
  5890. }
  5891. for (prop in a) {
  5892. aLength += 1;
  5893. if (!(prop in b)) {
  5894. return false;
  5895. }
  5896. if (!deepEqual(a[prop], b[prop])) {
  5897. return false;
  5898. }
  5899. }
  5900. for (prop in b) {
  5901. bLength += 1;
  5902. }
  5903. return aLength == bLength;
  5904. };
  5905. sinon.functionName = function functionName(func) {
  5906. var name = func.displayName || func.name;
  5907. // Use function decomposition as a last resort to get function
  5908. // name. Does not rely on function decomposition to work - if it
  5909. // doesn't debugging will be slightly less informative
  5910. // (i.e. toString will say 'spy' rather than 'myFunc').
  5911. if (!name) {
  5912. var matches = func.toString().match(/function ([^\s\(]+)/);
  5913. name = matches && matches[1];
  5914. }
  5915. return name;
  5916. };
  5917. sinon.functionToString = function toString() {
  5918. if (this.getCall && this.callCount) {
  5919. var thisValue, prop, i = this.callCount;
  5920. while (i--) {
  5921. thisValue = this.getCall(i).thisValue;
  5922. for (prop in thisValue) {
  5923. if (thisValue[prop] === this) {
  5924. return prop;
  5925. }
  5926. }
  5927. }
  5928. }
  5929. return this.displayName || "sinon fake";
  5930. };
  5931. sinon.objectKeys = function objectKeys(obj) {
  5932. if (obj !== Object(obj)) {
  5933. throw new TypeError("sinon.objectKeys called on a non-object");
  5934. }
  5935. var keys = [];
  5936. var key;
  5937. for (key in obj) {
  5938. if (hasOwn.call(obj, key)) {
  5939. keys.push(key);
  5940. }
  5941. }
  5942. return keys;
  5943. };
  5944. sinon.getPropertyDescriptor = function getPropertyDescriptor(object, property) {
  5945. var proto = object, descriptor;
  5946. while (proto && !(descriptor = Object.getOwnPropertyDescriptor(proto, property))) {
  5947. proto = Object.getPrototypeOf(proto);
  5948. }
  5949. return descriptor;
  5950. }
  5951. sinon.getConfig = function (custom) {
  5952. var config = {};
  5953. custom = custom || {};
  5954. var defaults = sinon.defaultConfig;
  5955. for (var prop in defaults) {
  5956. if (defaults.hasOwnProperty(prop)) {
  5957. config[prop] = custom.hasOwnProperty(prop) ? custom[prop] : defaults[prop];
  5958. }
  5959. }
  5960. return config;
  5961. };
  5962. sinon.defaultConfig = {
  5963. injectIntoThis: true,
  5964. injectInto: null,
  5965. properties: ["spy", "stub", "mock", "clock", "server", "requests"],
  5966. useFakeTimers: true,
  5967. useFakeServer: true
  5968. };
  5969. sinon.timesInWords = function timesInWords(count) {
  5970. return count == 1 && "once" ||
  5971. count == 2 && "twice" ||
  5972. count == 3 && "thrice" ||
  5973. (count || 0) + " times";
  5974. };
  5975. sinon.calledInOrder = function (spies) {
  5976. for (var i = 1, l = spies.length; i < l; i++) {
  5977. if (!spies[i - 1].calledBefore(spies[i]) || !spies[i].called) {
  5978. return false;
  5979. }
  5980. }
  5981. return true;
  5982. };
  5983. sinon.orderByFirstCall = function (spies) {
  5984. return spies.sort(function (a, b) {
  5985. // uuid, won't ever be equal
  5986. var aCall = a.getCall(0);
  5987. var bCall = b.getCall(0);
  5988. var aId = aCall && aCall.callId || -1;
  5989. var bId = bCall && bCall.callId || -1;
  5990. return aId < bId ? -1 : 1;
  5991. });
  5992. };
  5993. sinon.createStubInstance = function (constructor) {
  5994. if (typeof constructor !== "function") {
  5995. throw new TypeError("The constructor should be a function.");
  5996. }
  5997. return sinon.stub(sinon.create(constructor.prototype));
  5998. };
  5999. sinon.restore = function (object) {
  6000. if (object !== null && typeof object === "object") {
  6001. for (var prop in object) {
  6002. if (isRestorable(object[prop])) {
  6003. object[prop].restore();
  6004. }
  6005. }
  6006. } else if (isRestorable(object)) {
  6007. object.restore();
  6008. }
  6009. };
  6010. return sinon;
  6011. }
  6012. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  6013. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  6014. function loadDependencies(require, exports) {
  6015. makeApi(exports);
  6016. }
  6017. if (isAMD) {
  6018. define(loadDependencies);
  6019. } else if (isNode) {
  6020. loadDependencies(require, module.exports);
  6021. } else if (!sinon) {
  6022. return;
  6023. } else {
  6024. makeApi(sinon);
  6025. }
  6026. }(typeof sinon == "object" && sinon || null));
  6027. },{}],42:[function(require,module,exports){
  6028. /**
  6029. * Minimal Event interface implementation
  6030. *
  6031. * Original implementation by Sven Fuchs: https://gist.github.com/995028
  6032. * Modifications and tests by Christian Johansen.
  6033. *
  6034. * @author Sven Fuchs (svenfuchs@artweb-design.de)
  6035. * @author Christian Johansen (christian@cjohansen.no)
  6036. * @license BSD
  6037. *
  6038. * Copyright (c) 2011 Sven Fuchs, Christian Johansen
  6039. */
  6040. "use strict";
  6041. if (typeof sinon == "undefined") {
  6042. this.sinon = {};
  6043. }
  6044. (function () {
  6045. var push = [].push;
  6046. function makeApi(sinon) {
  6047. sinon.Event = function Event(type, bubbles, cancelable, target) {
  6048. this.initEvent(type, bubbles, cancelable, target);
  6049. };
  6050. sinon.Event.prototype = {
  6051. initEvent: function (type, bubbles, cancelable, target) {
  6052. this.type = type;
  6053. this.bubbles = bubbles;
  6054. this.cancelable = cancelable;
  6055. this.target = target;
  6056. },
  6057. stopPropagation: function () {},
  6058. preventDefault: function () {
  6059. this.defaultPrevented = true;
  6060. }
  6061. };
  6062. sinon.ProgressEvent = function ProgressEvent(type, progressEventRaw, target) {
  6063. this.initEvent(type, false, false, target);
  6064. this.loaded = progressEventRaw.loaded || null;
  6065. this.total = progressEventRaw.total || null;
  6066. this.lengthComputable = !!progressEventRaw.total;
  6067. };
  6068. sinon.ProgressEvent.prototype = new sinon.Event();
  6069. sinon.ProgressEvent.prototype.constructor = sinon.ProgressEvent;
  6070. sinon.CustomEvent = function CustomEvent(type, customData, target) {
  6071. this.initEvent(type, false, false, target);
  6072. this.detail = customData.detail || null;
  6073. };
  6074. sinon.CustomEvent.prototype = new sinon.Event();
  6075. sinon.CustomEvent.prototype.constructor = sinon.CustomEvent;
  6076. sinon.EventTarget = {
  6077. addEventListener: function addEventListener(event, listener) {
  6078. this.eventListeners = this.eventListeners || {};
  6079. this.eventListeners[event] = this.eventListeners[event] || [];
  6080. push.call(this.eventListeners[event], listener);
  6081. },
  6082. removeEventListener: function removeEventListener(event, listener) {
  6083. var listeners = this.eventListeners && this.eventListeners[event] || [];
  6084. for (var i = 0, l = listeners.length; i < l; ++i) {
  6085. if (listeners[i] == listener) {
  6086. return listeners.splice(i, 1);
  6087. }
  6088. }
  6089. },
  6090. dispatchEvent: function dispatchEvent(event) {
  6091. var type = event.type;
  6092. var listeners = this.eventListeners && this.eventListeners[type] || [];
  6093. for (var i = 0; i < listeners.length; i++) {
  6094. if (typeof listeners[i] == "function") {
  6095. listeners[i].call(this, event);
  6096. } else {
  6097. listeners[i].handleEvent(event);
  6098. }
  6099. }
  6100. return !!event.defaultPrevented;
  6101. }
  6102. };
  6103. }
  6104. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  6105. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  6106. function loadDependencies(require) {
  6107. var sinon = require("./core");
  6108. makeApi(sinon);
  6109. }
  6110. if (isAMD) {
  6111. define(loadDependencies);
  6112. } else if (isNode) {
  6113. loadDependencies(require);
  6114. } else {
  6115. makeApi(sinon);
  6116. }
  6117. }());
  6118. },{"./core":41}],43:[function(require,module,exports){
  6119. /**
  6120. * @depend fake_xdomain_request.js
  6121. * @depend fake_xml_http_request.js
  6122. * @depend ../format.js
  6123. * @depend ../log_error.js
  6124. */
  6125. /**
  6126. * The Sinon "server" mimics a web server that receives requests from
  6127. * sinon.FakeXMLHttpRequest and provides an API to respond to those requests,
  6128. * both synchronously and asynchronously. To respond synchronuously, canned
  6129. * answers have to be provided upfront.
  6130. *
  6131. * @author Christian Johansen (christian@cjohansen.no)
  6132. * @license BSD
  6133. *
  6134. * Copyright (c) 2010-2013 Christian Johansen
  6135. */
  6136. "use strict";
  6137. if (typeof sinon == "undefined") {
  6138. var sinon = {};
  6139. }
  6140. (function () {
  6141. var push = [].push;
  6142. function F() {}
  6143. function create(proto) {
  6144. F.prototype = proto;
  6145. return new F();
  6146. }
  6147. function responseArray(handler) {
  6148. var response = handler;
  6149. if (Object.prototype.toString.call(handler) != "[object Array]") {
  6150. response = [200, {}, handler];
  6151. }
  6152. if (typeof response[2] != "string") {
  6153. throw new TypeError("Fake server response body should be string, but was " +
  6154. typeof response[2]);
  6155. }
  6156. return response;
  6157. }
  6158. var wloc = typeof window !== "undefined" ? window.location : {};
  6159. var rCurrLoc = new RegExp("^" + wloc.protocol + "//" + wloc.host);
  6160. function matchOne(response, reqMethod, reqUrl) {
  6161. var rmeth = response.method;
  6162. var matchMethod = !rmeth || rmeth.toLowerCase() == reqMethod.toLowerCase();
  6163. var url = response.url;
  6164. var matchUrl = !url || url == reqUrl || (typeof url.test == "function" && url.test(reqUrl));
  6165. return matchMethod && matchUrl;
  6166. }
  6167. function match(response, request) {
  6168. var requestUrl = request.url;
  6169. if (!/^https?:\/\//.test(requestUrl) || rCurrLoc.test(requestUrl)) {
  6170. requestUrl = requestUrl.replace(rCurrLoc, "");
  6171. }
  6172. if (matchOne(response, this.getHTTPMethod(request), requestUrl)) {
  6173. if (typeof response.response == "function") {
  6174. var ru = response.url;
  6175. var args = [request].concat(ru && typeof ru.exec == "function" ? ru.exec(requestUrl).slice(1) : []);
  6176. return response.response.apply(response, args);
  6177. }
  6178. return true;
  6179. }
  6180. return false;
  6181. }
  6182. function makeApi(sinon) {
  6183. sinon.fakeServer = {
  6184. create: function () {
  6185. var server = create(this);
  6186. if (!sinon.xhr.supportsCORS) {
  6187. this.xhr = sinon.useFakeXDomainRequest();
  6188. } else {
  6189. this.xhr = sinon.useFakeXMLHttpRequest();
  6190. }
  6191. server.requests = [];
  6192. this.xhr.onCreate = function (xhrObj) {
  6193. server.addRequest(xhrObj);
  6194. };
  6195. return server;
  6196. },
  6197. addRequest: function addRequest(xhrObj) {
  6198. var server = this;
  6199. push.call(this.requests, xhrObj);
  6200. xhrObj.onSend = function () {
  6201. server.handleRequest(this);
  6202. if (server.respondImmediately) {
  6203. server.respond();
  6204. } else if (server.autoRespond && !server.responding) {
  6205. setTimeout(function () {
  6206. server.responding = false;
  6207. server.respond();
  6208. }, server.autoRespondAfter || 10);
  6209. server.responding = true;
  6210. }
  6211. };
  6212. },
  6213. getHTTPMethod: function getHTTPMethod(request) {
  6214. if (this.fakeHTTPMethods && /post/i.test(request.method)) {
  6215. var matches = (request.requestBody || "").match(/_method=([^\b;]+)/);
  6216. return !!matches ? matches[1] : request.method;
  6217. }
  6218. return request.method;
  6219. },
  6220. handleRequest: function handleRequest(xhr) {
  6221. if (xhr.async) {
  6222. if (!this.queue) {
  6223. this.queue = [];
  6224. }
  6225. push.call(this.queue, xhr);
  6226. } else {
  6227. this.processRequest(xhr);
  6228. }
  6229. },
  6230. log: function log(response, request) {
  6231. var str;
  6232. str = "Request:\n" + sinon.format(request) + "\n\n";
  6233. str += "Response:\n" + sinon.format(response) + "\n\n";
  6234. sinon.log(str);
  6235. },
  6236. respondWith: function respondWith(method, url, body) {
  6237. if (arguments.length == 1 && typeof method != "function") {
  6238. this.response = responseArray(method);
  6239. return;
  6240. }
  6241. if (!this.responses) { this.responses = []; }
  6242. if (arguments.length == 1) {
  6243. body = method;
  6244. url = method = null;
  6245. }
  6246. if (arguments.length == 2) {
  6247. body = url;
  6248. url = method;
  6249. method = null;
  6250. }
  6251. push.call(this.responses, {
  6252. method: method,
  6253. url: url,
  6254. response: typeof body == "function" ? body : responseArray(body)
  6255. });
  6256. },
  6257. respond: function respond() {
  6258. if (arguments.length > 0) {
  6259. this.respondWith.apply(this, arguments);
  6260. }
  6261. var queue = this.queue || [];
  6262. var requests = queue.splice(0, queue.length);
  6263. var request;
  6264. while (request = requests.shift()) {
  6265. this.processRequest(request);
  6266. }
  6267. },
  6268. processRequest: function processRequest(request) {
  6269. try {
  6270. if (request.aborted) {
  6271. return;
  6272. }
  6273. var response = this.response || [404, {}, ""];
  6274. if (this.responses) {
  6275. for (var l = this.responses.length, i = l - 1; i >= 0; i--) {
  6276. if (match.call(this, this.responses[i], request)) {
  6277. response = this.responses[i].response;
  6278. break;
  6279. }
  6280. }
  6281. }
  6282. if (request.readyState != 4) {
  6283. this.log(response, request);
  6284. request.respond(response[0], response[1], response[2]);
  6285. }
  6286. } catch (e) {
  6287. sinon.logError("Fake server request processing", e);
  6288. }
  6289. },
  6290. restore: function restore() {
  6291. return this.xhr.restore && this.xhr.restore.apply(this.xhr, arguments);
  6292. }
  6293. };
  6294. }
  6295. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  6296. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  6297. function loadDependencies(require, exports, module) {
  6298. var sinon = require("./core");
  6299. require("./fake_xdomain_request");
  6300. require("./fake_xml_http_request");
  6301. require("../format");
  6302. makeApi(sinon);
  6303. module.exports = sinon;
  6304. }
  6305. if (isAMD) {
  6306. define(loadDependencies);
  6307. } else if (isNode) {
  6308. loadDependencies(require, module.exports, module);
  6309. } else {
  6310. makeApi(sinon);
  6311. }
  6312. }());
  6313. },{"../format":30,"./core":41,"./fake_xdomain_request":46,"./fake_xml_http_request":47}],44:[function(require,module,exports){
  6314. /**
  6315. * @depend fake_server.js
  6316. * @depend fake_timers.js
  6317. */
  6318. /**
  6319. * Add-on for sinon.fakeServer that automatically handles a fake timer along with
  6320. * the FakeXMLHttpRequest. The direct inspiration for this add-on is jQuery
  6321. * 1.3.x, which does not use xhr object's onreadystatehandler at all - instead,
  6322. * it polls the object for completion with setInterval. Dispite the direct
  6323. * motivation, there is nothing jQuery-specific in this file, so it can be used
  6324. * in any environment where the ajax implementation depends on setInterval or
  6325. * setTimeout.
  6326. *
  6327. * @author Christian Johansen (christian@cjohansen.no)
  6328. * @license BSD
  6329. *
  6330. * Copyright (c) 2010-2013 Christian Johansen
  6331. */
  6332. "use strict";
  6333. (function () {
  6334. function makeApi(sinon) {
  6335. function Server() {}
  6336. Server.prototype = sinon.fakeServer;
  6337. sinon.fakeServerWithClock = new Server();
  6338. sinon.fakeServerWithClock.addRequest = function addRequest(xhr) {
  6339. if (xhr.async) {
  6340. if (typeof setTimeout.clock == "object") {
  6341. this.clock = setTimeout.clock;
  6342. } else {
  6343. this.clock = sinon.useFakeTimers();
  6344. this.resetClock = true;
  6345. }
  6346. if (!this.longestTimeout) {
  6347. var clockSetTimeout = this.clock.setTimeout;
  6348. var clockSetInterval = this.clock.setInterval;
  6349. var server = this;
  6350. this.clock.setTimeout = function (fn, timeout) {
  6351. server.longestTimeout = Math.max(timeout, server.longestTimeout || 0);
  6352. return clockSetTimeout.apply(this, arguments);
  6353. };
  6354. this.clock.setInterval = function (fn, timeout) {
  6355. server.longestTimeout = Math.max(timeout, server.longestTimeout || 0);
  6356. return clockSetInterval.apply(this, arguments);
  6357. };
  6358. }
  6359. }
  6360. return sinon.fakeServer.addRequest.call(this, xhr);
  6361. };
  6362. sinon.fakeServerWithClock.respond = function respond() {
  6363. var returnVal = sinon.fakeServer.respond.apply(this, arguments);
  6364. if (this.clock) {
  6365. this.clock.tick(this.longestTimeout || 0);
  6366. this.longestTimeout = 0;
  6367. if (this.resetClock) {
  6368. this.clock.restore();
  6369. this.resetClock = false;
  6370. }
  6371. }
  6372. return returnVal;
  6373. };
  6374. sinon.fakeServerWithClock.restore = function restore() {
  6375. if (this.clock) {
  6376. this.clock.restore();
  6377. }
  6378. return sinon.fakeServer.restore.apply(this, arguments);
  6379. };
  6380. }
  6381. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  6382. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  6383. function loadDependencies(require) {
  6384. var sinon = require("./core");
  6385. require("./fake_server");
  6386. require("./fake_timers");
  6387. makeApi(sinon);
  6388. }
  6389. if (isAMD) {
  6390. define(loadDependencies);
  6391. } else if (isNode) {
  6392. loadDependencies(require);
  6393. } else {
  6394. makeApi(sinon);
  6395. }
  6396. }());
  6397. },{"./core":41,"./fake_server":43,"./fake_timers":45}],45:[function(require,module,exports){
  6398. (function (global){
  6399. /*global lolex */
  6400. /**
  6401. * Fake timer API
  6402. * setTimeout
  6403. * setInterval
  6404. * clearTimeout
  6405. * clearInterval
  6406. * tick
  6407. * reset
  6408. * Date
  6409. *
  6410. * Inspired by jsUnitMockTimeOut from JsUnit
  6411. *
  6412. * @author Christian Johansen (christian@cjohansen.no)
  6413. * @license BSD
  6414. *
  6415. * Copyright (c) 2010-2013 Christian Johansen
  6416. */
  6417. "use strict";
  6418. if (typeof sinon == "undefined") {
  6419. var sinon = {};
  6420. }
  6421. (function (global) {
  6422. function makeApi(sinon, lol) {
  6423. var llx = typeof lolex !== "undefined" ? lolex : lol;
  6424. sinon.useFakeTimers = function () {
  6425. var now, methods = Array.prototype.slice.call(arguments);
  6426. if (typeof methods[0] === "string") {
  6427. now = 0;
  6428. } else {
  6429. now = methods.shift();
  6430. }
  6431. var clock = llx.install(now || 0, methods);
  6432. clock.restore = clock.uninstall;
  6433. return clock;
  6434. };
  6435. sinon.clock = {
  6436. create: function (now) {
  6437. return llx.createClock(now);
  6438. }
  6439. };
  6440. sinon.timers = {
  6441. setTimeout: setTimeout,
  6442. clearTimeout: clearTimeout,
  6443. setImmediate: (typeof setImmediate !== "undefined" ? setImmediate : undefined),
  6444. clearImmediate: (typeof clearImmediate !== "undefined" ? clearImmediate : undefined),
  6445. setInterval: setInterval,
  6446. clearInterval: clearInterval,
  6447. Date: Date
  6448. };
  6449. }
  6450. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  6451. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  6452. function loadDependencies(require, epxorts, module, lolex) {
  6453. var sinon = require("./core");
  6454. makeApi(sinon, lolex);
  6455. module.exports = sinon;
  6456. }
  6457. if (isAMD) {
  6458. define(loadDependencies);
  6459. } else if (isNode) {
  6460. loadDependencies(require, module.exports, module, require("lolex"));
  6461. } else {
  6462. makeApi(sinon);
  6463. }
  6464. }(typeof global != "undefined" && typeof global !== "function" ? global : this));
  6465. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6466. },{"./core":41,"lolex":50}],46:[function(require,module,exports){
  6467. /**
  6468. * @depend core.js
  6469. * @depend ../extend.js
  6470. * @depend event.js
  6471. * @depend ../log_error.js
  6472. */
  6473. /**
  6474. * Fake XDomainRequest object
  6475. */
  6476. "use strict";
  6477. if (typeof sinon == "undefined") {
  6478. this.sinon = {};
  6479. }
  6480. // wrapper for global
  6481. (function (global) {
  6482. var xdr = { XDomainRequest: global.XDomainRequest };
  6483. xdr.GlobalXDomainRequest = global.XDomainRequest;
  6484. xdr.supportsXDR = typeof xdr.GlobalXDomainRequest != "undefined";
  6485. xdr.workingXDR = xdr.supportsXDR ? xdr.GlobalXDomainRequest : false;
  6486. function makeApi(sinon) {
  6487. sinon.xdr = xdr;
  6488. function FakeXDomainRequest() {
  6489. this.readyState = FakeXDomainRequest.UNSENT;
  6490. this.requestBody = null;
  6491. this.requestHeaders = {};
  6492. this.status = 0;
  6493. this.timeout = null;
  6494. if (typeof FakeXDomainRequest.onCreate == "function") {
  6495. FakeXDomainRequest.onCreate(this);
  6496. }
  6497. }
  6498. function verifyState(xdr) {
  6499. if (xdr.readyState !== FakeXDomainRequest.OPENED) {
  6500. throw new Error("INVALID_STATE_ERR");
  6501. }
  6502. if (xdr.sendFlag) {
  6503. throw new Error("INVALID_STATE_ERR");
  6504. }
  6505. }
  6506. function verifyRequestSent(xdr) {
  6507. if (xdr.readyState == FakeXDomainRequest.UNSENT) {
  6508. throw new Error("Request not sent");
  6509. }
  6510. if (xdr.readyState == FakeXDomainRequest.DONE) {
  6511. throw new Error("Request done");
  6512. }
  6513. }
  6514. function verifyResponseBodyType(body) {
  6515. if (typeof body != "string") {
  6516. var error = new Error("Attempted to respond to fake XDomainRequest with " +
  6517. body + ", which is not a string.");
  6518. error.name = "InvalidBodyException";
  6519. throw error;
  6520. }
  6521. }
  6522. sinon.extend(FakeXDomainRequest.prototype, sinon.EventTarget, {
  6523. open: function open(method, url) {
  6524. this.method = method;
  6525. this.url = url;
  6526. this.responseText = null;
  6527. this.sendFlag = false;
  6528. this.readyStateChange(FakeXDomainRequest.OPENED);
  6529. },
  6530. readyStateChange: function readyStateChange(state) {
  6531. this.readyState = state;
  6532. var eventName = "";
  6533. switch (this.readyState) {
  6534. case FakeXDomainRequest.UNSENT:
  6535. break;
  6536. case FakeXDomainRequest.OPENED:
  6537. break;
  6538. case FakeXDomainRequest.LOADING:
  6539. if (this.sendFlag) {
  6540. //raise the progress event
  6541. eventName = "onprogress";
  6542. }
  6543. break;
  6544. case FakeXDomainRequest.DONE:
  6545. if (this.isTimeout) {
  6546. eventName = "ontimeout"
  6547. } else if (this.errorFlag || (this.status < 200 || this.status > 299)) {
  6548. eventName = "onerror";
  6549. } else {
  6550. eventName = "onload"
  6551. }
  6552. break;
  6553. }
  6554. // raising event (if defined)
  6555. if (eventName) {
  6556. if (typeof this[eventName] == "function") {
  6557. try {
  6558. this[eventName]();
  6559. } catch (e) {
  6560. sinon.logError("Fake XHR " + eventName + " handler", e);
  6561. }
  6562. }
  6563. }
  6564. },
  6565. send: function send(data) {
  6566. verifyState(this);
  6567. if (!/^(get|head)$/i.test(this.method)) {
  6568. this.requestBody = data;
  6569. }
  6570. this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8";
  6571. this.errorFlag = false;
  6572. this.sendFlag = true;
  6573. this.readyStateChange(FakeXDomainRequest.OPENED);
  6574. if (typeof this.onSend == "function") {
  6575. this.onSend(this);
  6576. }
  6577. },
  6578. abort: function abort() {
  6579. this.aborted = true;
  6580. this.responseText = null;
  6581. this.errorFlag = true;
  6582. if (this.readyState > sinon.FakeXDomainRequest.UNSENT && this.sendFlag) {
  6583. this.readyStateChange(sinon.FakeXDomainRequest.DONE);
  6584. this.sendFlag = false;
  6585. }
  6586. },
  6587. setResponseBody: function setResponseBody(body) {
  6588. verifyRequestSent(this);
  6589. verifyResponseBodyType(body);
  6590. var chunkSize = this.chunkSize || 10;
  6591. var index = 0;
  6592. this.responseText = "";
  6593. do {
  6594. this.readyStateChange(FakeXDomainRequest.LOADING);
  6595. this.responseText += body.substring(index, index + chunkSize);
  6596. index += chunkSize;
  6597. } while (index < body.length);
  6598. this.readyStateChange(FakeXDomainRequest.DONE);
  6599. },
  6600. respond: function respond(status, contentType, body) {
  6601. // content-type ignored, since XDomainRequest does not carry this
  6602. // we keep the same syntax for respond(...) as for FakeXMLHttpRequest to ease
  6603. // test integration across browsers
  6604. this.status = typeof status == "number" ? status : 200;
  6605. this.setResponseBody(body || "");
  6606. },
  6607. simulatetimeout: function simulatetimeout() {
  6608. this.status = 0;
  6609. this.isTimeout = true;
  6610. // Access to this should actually throw an error
  6611. this.responseText = undefined;
  6612. this.readyStateChange(FakeXDomainRequest.DONE);
  6613. }
  6614. });
  6615. sinon.extend(FakeXDomainRequest, {
  6616. UNSENT: 0,
  6617. OPENED: 1,
  6618. LOADING: 3,
  6619. DONE: 4
  6620. });
  6621. sinon.useFakeXDomainRequest = function useFakeXDomainRequest() {
  6622. sinon.FakeXDomainRequest.restore = function restore(keepOnCreate) {
  6623. if (xdr.supportsXDR) {
  6624. global.XDomainRequest = xdr.GlobalXDomainRequest;
  6625. }
  6626. delete sinon.FakeXDomainRequest.restore;
  6627. if (keepOnCreate !== true) {
  6628. delete sinon.FakeXDomainRequest.onCreate;
  6629. }
  6630. };
  6631. if (xdr.supportsXDR) {
  6632. global.XDomainRequest = sinon.FakeXDomainRequest;
  6633. }
  6634. return sinon.FakeXDomainRequest;
  6635. };
  6636. sinon.FakeXDomainRequest = FakeXDomainRequest;
  6637. }
  6638. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  6639. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  6640. function loadDependencies(require, exports, module) {
  6641. var sinon = require("./core");
  6642. require("../extend");
  6643. require("./event");
  6644. require("../log_error");
  6645. makeApi(sinon);
  6646. module.exports = sinon;
  6647. }
  6648. if (isAMD) {
  6649. define(loadDependencies);
  6650. } else if (isNode) {
  6651. loadDependencies(require, module.exports, module);
  6652. } else {
  6653. makeApi(sinon);
  6654. }
  6655. })(this);
  6656. },{"../extend":29,"../log_error":31,"./core":41,"./event":42}],47:[function(require,module,exports){
  6657. (function (global){
  6658. /**
  6659. * @depend core.js
  6660. * @depend ../extend.js
  6661. * @depend event.js
  6662. * @depend ../log_error.js
  6663. */
  6664. /**
  6665. * Fake XMLHttpRequest object
  6666. *
  6667. * @author Christian Johansen (christian@cjohansen.no)
  6668. * @license BSD
  6669. *
  6670. * Copyright (c) 2010-2013 Christian Johansen
  6671. */
  6672. "use strict";
  6673. (function (global) {
  6674. var supportsProgress = typeof ProgressEvent !== "undefined";
  6675. var supportsCustomEvent = typeof CustomEvent !== "undefined";
  6676. var sinonXhr = { XMLHttpRequest: global.XMLHttpRequest };
  6677. sinonXhr.GlobalXMLHttpRequest = global.XMLHttpRequest;
  6678. sinonXhr.GlobalActiveXObject = global.ActiveXObject;
  6679. sinonXhr.supportsActiveX = typeof sinonXhr.GlobalActiveXObject != "undefined";
  6680. sinonXhr.supportsXHR = typeof sinonXhr.GlobalXMLHttpRequest != "undefined";
  6681. sinonXhr.workingXHR = sinonXhr.supportsXHR ? sinonXhr.GlobalXMLHttpRequest : sinonXhr.supportsActiveX
  6682. ? function () { return new sinonXhr.GlobalActiveXObject("MSXML2.XMLHTTP.3.0") } : false;
  6683. sinonXhr.supportsCORS = sinonXhr.supportsXHR && "withCredentials" in (new sinonXhr.GlobalXMLHttpRequest());
  6684. /*jsl:ignore*/
  6685. var unsafeHeaders = {
  6686. "Accept-Charset": true,
  6687. "Accept-Encoding": true,
  6688. Connection: true,
  6689. "Content-Length": true,
  6690. Cookie: true,
  6691. Cookie2: true,
  6692. "Content-Transfer-Encoding": true,
  6693. Date: true,
  6694. Expect: true,
  6695. Host: true,
  6696. "Keep-Alive": true,
  6697. Referer: true,
  6698. TE: true,
  6699. Trailer: true,
  6700. "Transfer-Encoding": true,
  6701. Upgrade: true,
  6702. "User-Agent": true,
  6703. Via: true
  6704. };
  6705. /*jsl:end*/
  6706. function FakeXMLHttpRequest() {
  6707. this.readyState = FakeXMLHttpRequest.UNSENT;
  6708. this.requestHeaders = {};
  6709. this.requestBody = null;
  6710. this.status = 0;
  6711. this.statusText = "";
  6712. this.upload = new UploadProgress();
  6713. if (sinonXhr.supportsCORS) {
  6714. this.withCredentials = false;
  6715. }
  6716. var xhr = this;
  6717. var events = ["loadstart", "load", "abort", "loadend"];
  6718. function addEventListener(eventName) {
  6719. xhr.addEventListener(eventName, function (event) {
  6720. var listener = xhr["on" + eventName];
  6721. if (listener && typeof listener == "function") {
  6722. listener.call(this, event);
  6723. }
  6724. });
  6725. }
  6726. for (var i = events.length - 1; i >= 0; i--) {
  6727. addEventListener(events[i]);
  6728. }
  6729. if (typeof FakeXMLHttpRequest.onCreate == "function") {
  6730. FakeXMLHttpRequest.onCreate(this);
  6731. }
  6732. }
  6733. // An upload object is created for each
  6734. // FakeXMLHttpRequest and allows upload
  6735. // events to be simulated using uploadProgress
  6736. // and uploadError.
  6737. function UploadProgress() {
  6738. this.eventListeners = {
  6739. progress: [],
  6740. load: [],
  6741. abort: [],
  6742. error: []
  6743. }
  6744. }
  6745. UploadProgress.prototype.addEventListener = function addEventListener(event, listener) {
  6746. this.eventListeners[event].push(listener);
  6747. };
  6748. UploadProgress.prototype.removeEventListener = function removeEventListener(event, listener) {
  6749. var listeners = this.eventListeners[event] || [];
  6750. for (var i = 0, l = listeners.length; i < l; ++i) {
  6751. if (listeners[i] == listener) {
  6752. return listeners.splice(i, 1);
  6753. }
  6754. }
  6755. };
  6756. UploadProgress.prototype.dispatchEvent = function dispatchEvent(event) {
  6757. var listeners = this.eventListeners[event.type] || [];
  6758. for (var i = 0, listener; (listener = listeners[i]) != null; i++) {
  6759. listener(event);
  6760. }
  6761. };
  6762. function verifyState(xhr) {
  6763. if (xhr.readyState !== FakeXMLHttpRequest.OPENED) {
  6764. throw new Error("INVALID_STATE_ERR");
  6765. }
  6766. if (xhr.sendFlag) {
  6767. throw new Error("INVALID_STATE_ERR");
  6768. }
  6769. }
  6770. function getHeader(headers, header) {
  6771. header = header.toLowerCase();
  6772. for (var h in headers) {
  6773. if (h.toLowerCase() == header) {
  6774. return h;
  6775. }
  6776. }
  6777. return null;
  6778. }
  6779. // filtering to enable a white-list version of Sinon FakeXhr,
  6780. // where whitelisted requests are passed through to real XHR
  6781. function each(collection, callback) {
  6782. if (!collection) {
  6783. return;
  6784. }
  6785. for (var i = 0, l = collection.length; i < l; i += 1) {
  6786. callback(collection[i]);
  6787. }
  6788. }
  6789. function some(collection, callback) {
  6790. for (var index = 0; index < collection.length; index++) {
  6791. if (callback(collection[index]) === true) {
  6792. return true;
  6793. }
  6794. }
  6795. return false;
  6796. }
  6797. // largest arity in XHR is 5 - XHR#open
  6798. var apply = function (obj, method, args) {
  6799. switch (args.length) {
  6800. case 0: return obj[method]();
  6801. case 1: return obj[method](args[0]);
  6802. case 2: return obj[method](args[0], args[1]);
  6803. case 3: return obj[method](args[0], args[1], args[2]);
  6804. case 4: return obj[method](args[0], args[1], args[2], args[3]);
  6805. case 5: return obj[method](args[0], args[1], args[2], args[3], args[4]);
  6806. }
  6807. };
  6808. FakeXMLHttpRequest.filters = [];
  6809. FakeXMLHttpRequest.addFilter = function addFilter(fn) {
  6810. this.filters.push(fn)
  6811. };
  6812. var IE6Re = /MSIE 6/;
  6813. FakeXMLHttpRequest.defake = function defake(fakeXhr, xhrArgs) {
  6814. var xhr = new sinonXhr.workingXHR();
  6815. each([
  6816. "open",
  6817. "setRequestHeader",
  6818. "send",
  6819. "abort",
  6820. "getResponseHeader",
  6821. "getAllResponseHeaders",
  6822. "addEventListener",
  6823. "overrideMimeType",
  6824. "removeEventListener"
  6825. ], function (method) {
  6826. fakeXhr[method] = function () {
  6827. return apply(xhr, method, arguments);
  6828. };
  6829. });
  6830. var copyAttrs = function (args) {
  6831. each(args, function (attr) {
  6832. try {
  6833. fakeXhr[attr] = xhr[attr]
  6834. } catch (e) {
  6835. if (!IE6Re.test(navigator.userAgent)) {
  6836. throw e;
  6837. }
  6838. }
  6839. });
  6840. };
  6841. var stateChange = function stateChange() {
  6842. fakeXhr.readyState = xhr.readyState;
  6843. if (xhr.readyState >= FakeXMLHttpRequest.HEADERS_RECEIVED) {
  6844. copyAttrs(["status", "statusText"]);
  6845. }
  6846. if (xhr.readyState >= FakeXMLHttpRequest.LOADING) {
  6847. copyAttrs(["responseText", "response"]);
  6848. }
  6849. if (xhr.readyState === FakeXMLHttpRequest.DONE) {
  6850. copyAttrs(["responseXML"]);
  6851. }
  6852. if (fakeXhr.onreadystatechange) {
  6853. fakeXhr.onreadystatechange.call(fakeXhr, { target: fakeXhr });
  6854. }
  6855. };
  6856. if (xhr.addEventListener) {
  6857. for (var event in fakeXhr.eventListeners) {
  6858. if (fakeXhr.eventListeners.hasOwnProperty(event)) {
  6859. each(fakeXhr.eventListeners[event], function (handler) {
  6860. xhr.addEventListener(event, handler);
  6861. });
  6862. }
  6863. }
  6864. xhr.addEventListener("readystatechange", stateChange);
  6865. } else {
  6866. xhr.onreadystatechange = stateChange;
  6867. }
  6868. apply(xhr, "open", xhrArgs);
  6869. };
  6870. FakeXMLHttpRequest.useFilters = false;
  6871. function verifyRequestOpened(xhr) {
  6872. if (xhr.readyState != FakeXMLHttpRequest.OPENED) {
  6873. throw new Error("INVALID_STATE_ERR - " + xhr.readyState);
  6874. }
  6875. }
  6876. function verifyRequestSent(xhr) {
  6877. if (xhr.readyState == FakeXMLHttpRequest.DONE) {
  6878. throw new Error("Request done");
  6879. }
  6880. }
  6881. function verifyHeadersReceived(xhr) {
  6882. if (xhr.async && xhr.readyState != FakeXMLHttpRequest.HEADERS_RECEIVED) {
  6883. throw new Error("No headers received");
  6884. }
  6885. }
  6886. function verifyResponseBodyType(body) {
  6887. if (typeof body != "string") {
  6888. var error = new Error("Attempted to respond to fake XMLHttpRequest with " +
  6889. body + ", which is not a string.");
  6890. error.name = "InvalidBodyException";
  6891. throw error;
  6892. }
  6893. }
  6894. FakeXMLHttpRequest.parseXML = function parseXML(text) {
  6895. var xmlDoc;
  6896. if (typeof DOMParser != "undefined") {
  6897. var parser = new DOMParser();
  6898. xmlDoc = parser.parseFromString(text, "text/xml");
  6899. } else {
  6900. xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  6901. xmlDoc.async = "false";
  6902. xmlDoc.loadXML(text);
  6903. }
  6904. return xmlDoc;
  6905. };
  6906. FakeXMLHttpRequest.statusCodes = {
  6907. 100: "Continue",
  6908. 101: "Switching Protocols",
  6909. 200: "OK",
  6910. 201: "Created",
  6911. 202: "Accepted",
  6912. 203: "Non-Authoritative Information",
  6913. 204: "No Content",
  6914. 205: "Reset Content",
  6915. 206: "Partial Content",
  6916. 207: "Multi-Status",
  6917. 300: "Multiple Choice",
  6918. 301: "Moved Permanently",
  6919. 302: "Found",
  6920. 303: "See Other",
  6921. 304: "Not Modified",
  6922. 305: "Use Proxy",
  6923. 307: "Temporary Redirect",
  6924. 400: "Bad Request",
  6925. 401: "Unauthorized",
  6926. 402: "Payment Required",
  6927. 403: "Forbidden",
  6928. 404: "Not Found",
  6929. 405: "Method Not Allowed",
  6930. 406: "Not Acceptable",
  6931. 407: "Proxy Authentication Required",
  6932. 408: "Request Timeout",
  6933. 409: "Conflict",
  6934. 410: "Gone",
  6935. 411: "Length Required",
  6936. 412: "Precondition Failed",
  6937. 413: "Request Entity Too Large",
  6938. 414: "Request-URI Too Long",
  6939. 415: "Unsupported Media Type",
  6940. 416: "Requested Range Not Satisfiable",
  6941. 417: "Expectation Failed",
  6942. 422: "Unprocessable Entity",
  6943. 500: "Internal Server Error",
  6944. 501: "Not Implemented",
  6945. 502: "Bad Gateway",
  6946. 503: "Service Unavailable",
  6947. 504: "Gateway Timeout",
  6948. 505: "HTTP Version Not Supported"
  6949. };
  6950. function makeApi(sinon) {
  6951. sinon.xhr = sinonXhr;
  6952. sinon.extend(FakeXMLHttpRequest.prototype, sinon.EventTarget, {
  6953. async: true,
  6954. open: function open(method, url, async, username, password) {
  6955. this.method = method;
  6956. this.url = url;
  6957. this.async = typeof async == "boolean" ? async : true;
  6958. this.username = username;
  6959. this.password = password;
  6960. this.responseText = null;
  6961. this.responseXML = null;
  6962. this.requestHeaders = {};
  6963. this.sendFlag = false;
  6964. if (FakeXMLHttpRequest.useFilters === true) {
  6965. var xhrArgs = arguments;
  6966. var defake = some(FakeXMLHttpRequest.filters, function (filter) {
  6967. return filter.apply(this, xhrArgs)
  6968. });
  6969. if (defake) {
  6970. return FakeXMLHttpRequest.defake(this, arguments);
  6971. }
  6972. }
  6973. this.readyStateChange(FakeXMLHttpRequest.OPENED);
  6974. },
  6975. readyStateChange: function readyStateChange(state) {
  6976. this.readyState = state;
  6977. if (typeof this.onreadystatechange == "function") {
  6978. try {
  6979. this.onreadystatechange();
  6980. } catch (e) {
  6981. sinon.logError("Fake XHR onreadystatechange handler", e);
  6982. }
  6983. }
  6984. this.dispatchEvent(new sinon.Event("readystatechange"));
  6985. switch (this.readyState) {
  6986. case FakeXMLHttpRequest.DONE:
  6987. this.dispatchEvent(new sinon.Event("load", false, false, this));
  6988. this.dispatchEvent(new sinon.Event("loadend", false, false, this));
  6989. this.upload.dispatchEvent(new sinon.Event("load", false, false, this));
  6990. if (supportsProgress) {
  6991. this.upload.dispatchEvent(new sinon.ProgressEvent("progress", {loaded: 100, total: 100}));
  6992. this.dispatchEvent(new sinon.ProgressEvent("progress", {loaded: 100, total: 100}));
  6993. }
  6994. break;
  6995. }
  6996. },
  6997. setRequestHeader: function setRequestHeader(header, value) {
  6998. verifyState(this);
  6999. if (unsafeHeaders[header] || /^(Sec-|Proxy-)/.test(header)) {
  7000. throw new Error("Refused to set unsafe header \"" + header + "\"");
  7001. }
  7002. if (this.requestHeaders[header]) {
  7003. this.requestHeaders[header] += "," + value;
  7004. } else {
  7005. this.requestHeaders[header] = value;
  7006. }
  7007. },
  7008. // Helps testing
  7009. setResponseHeaders: function setResponseHeaders(headers) {
  7010. verifyRequestOpened(this);
  7011. this.responseHeaders = {};
  7012. for (var header in headers) {
  7013. if (headers.hasOwnProperty(header)) {
  7014. this.responseHeaders[header] = headers[header];
  7015. }
  7016. }
  7017. if (this.async) {
  7018. this.readyStateChange(FakeXMLHttpRequest.HEADERS_RECEIVED);
  7019. } else {
  7020. this.readyState = FakeXMLHttpRequest.HEADERS_RECEIVED;
  7021. }
  7022. },
  7023. // Currently treats ALL data as a DOMString (i.e. no Document)
  7024. send: function send(data) {
  7025. verifyState(this);
  7026. if (!/^(get|head)$/i.test(this.method)) {
  7027. var contentType = getHeader(this.requestHeaders, "Content-Type");
  7028. if (this.requestHeaders[contentType]) {
  7029. var value = this.requestHeaders[contentType].split(";");
  7030. this.requestHeaders[contentType] = value[0] + ";charset=utf-8";
  7031. } else if (!(data instanceof FormData)) {
  7032. this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8";
  7033. }
  7034. this.requestBody = data;
  7035. }
  7036. this.errorFlag = false;
  7037. this.sendFlag = this.async;
  7038. this.readyStateChange(FakeXMLHttpRequest.OPENED);
  7039. if (typeof this.onSend == "function") {
  7040. this.onSend(this);
  7041. }
  7042. this.dispatchEvent(new sinon.Event("loadstart", false, false, this));
  7043. },
  7044. abort: function abort() {
  7045. this.aborted = true;
  7046. this.responseText = null;
  7047. this.errorFlag = true;
  7048. this.requestHeaders = {};
  7049. if (this.readyState > FakeXMLHttpRequest.UNSENT && this.sendFlag) {
  7050. this.readyStateChange(FakeXMLHttpRequest.DONE);
  7051. this.sendFlag = false;
  7052. }
  7053. this.readyState = FakeXMLHttpRequest.UNSENT;
  7054. this.dispatchEvent(new sinon.Event("abort", false, false, this));
  7055. this.upload.dispatchEvent(new sinon.Event("abort", false, false, this));
  7056. if (typeof this.onerror === "function") {
  7057. this.onerror();
  7058. }
  7059. },
  7060. getResponseHeader: function getResponseHeader(header) {
  7061. if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) {
  7062. return null;
  7063. }
  7064. if (/^Set-Cookie2?$/i.test(header)) {
  7065. return null;
  7066. }
  7067. header = getHeader(this.responseHeaders, header);
  7068. return this.responseHeaders[header] || null;
  7069. },
  7070. getAllResponseHeaders: function getAllResponseHeaders() {
  7071. if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) {
  7072. return "";
  7073. }
  7074. var headers = "";
  7075. for (var header in this.responseHeaders) {
  7076. if (this.responseHeaders.hasOwnProperty(header) &&
  7077. !/^Set-Cookie2?$/i.test(header)) {
  7078. headers += header + ": " + this.responseHeaders[header] + "\r\n";
  7079. }
  7080. }
  7081. return headers;
  7082. },
  7083. setResponseBody: function setResponseBody(body) {
  7084. verifyRequestSent(this);
  7085. verifyHeadersReceived(this);
  7086. verifyResponseBodyType(body);
  7087. var chunkSize = this.chunkSize || 10;
  7088. var index = 0;
  7089. this.responseText = "";
  7090. do {
  7091. if (this.async) {
  7092. this.readyStateChange(FakeXMLHttpRequest.LOADING);
  7093. }
  7094. this.responseText += body.substring(index, index + chunkSize);
  7095. index += chunkSize;
  7096. } while (index < body.length);
  7097. var type = this.getResponseHeader("Content-Type");
  7098. if (this.responseText &&
  7099. (!type || /(text\/xml)|(application\/xml)|(\+xml)/.test(type))) {
  7100. try {
  7101. this.responseXML = FakeXMLHttpRequest.parseXML(this.responseText);
  7102. } catch (e) {
  7103. // Unable to parse XML - no biggie
  7104. }
  7105. }
  7106. this.readyStateChange(FakeXMLHttpRequest.DONE);
  7107. },
  7108. respond: function respond(status, headers, body) {
  7109. this.status = typeof status == "number" ? status : 200;
  7110. this.statusText = FakeXMLHttpRequest.statusCodes[this.status];
  7111. this.setResponseHeaders(headers || {});
  7112. this.setResponseBody(body || "");
  7113. },
  7114. uploadProgress: function uploadProgress(progressEventRaw) {
  7115. if (supportsProgress) {
  7116. this.upload.dispatchEvent(new sinon.ProgressEvent("progress", progressEventRaw));
  7117. }
  7118. },
  7119. downloadProgress: function downloadProgress(progressEventRaw) {
  7120. if (supportsProgress) {
  7121. this.dispatchEvent(new sinon.ProgressEvent("progress", progressEventRaw));
  7122. }
  7123. },
  7124. uploadError: function uploadError(error) {
  7125. if (supportsCustomEvent) {
  7126. this.upload.dispatchEvent(new sinon.CustomEvent("error", {detail: error}));
  7127. }
  7128. }
  7129. });
  7130. sinon.extend(FakeXMLHttpRequest, {
  7131. UNSENT: 0,
  7132. OPENED: 1,
  7133. HEADERS_RECEIVED: 2,
  7134. LOADING: 3,
  7135. DONE: 4
  7136. });
  7137. sinon.useFakeXMLHttpRequest = function () {
  7138. FakeXMLHttpRequest.restore = function restore(keepOnCreate) {
  7139. if (sinonXhr.supportsXHR) {
  7140. global.XMLHttpRequest = sinonXhr.GlobalXMLHttpRequest;
  7141. }
  7142. if (sinonXhr.supportsActiveX) {
  7143. global.ActiveXObject = sinonXhr.GlobalActiveXObject;
  7144. }
  7145. delete FakeXMLHttpRequest.restore;
  7146. if (keepOnCreate !== true) {
  7147. delete FakeXMLHttpRequest.onCreate;
  7148. }
  7149. };
  7150. if (sinonXhr.supportsXHR) {
  7151. global.XMLHttpRequest = FakeXMLHttpRequest;
  7152. }
  7153. if (sinonXhr.supportsActiveX) {
  7154. global.ActiveXObject = function ActiveXObject(objId) {
  7155. if (objId == "Microsoft.XMLHTTP" || /^Msxml2\.XMLHTTP/i.test(objId)) {
  7156. return new FakeXMLHttpRequest();
  7157. }
  7158. return new sinonXhr.GlobalActiveXObject(objId);
  7159. };
  7160. }
  7161. return FakeXMLHttpRequest;
  7162. };
  7163. sinon.FakeXMLHttpRequest = FakeXMLHttpRequest;
  7164. }
  7165. var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
  7166. var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
  7167. function loadDependencies(require, exports, module) {
  7168. var sinon = require("./core");
  7169. require("../extend");
  7170. require("./event");
  7171. require("../log_error");
  7172. makeApi(sinon);
  7173. module.exports = sinon;
  7174. }
  7175. if (isAMD) {
  7176. define(loadDependencies);
  7177. } else if (isNode) {
  7178. loadDependencies(require, module.exports, module);
  7179. } else if (typeof sinon === "undefined") {
  7180. return;
  7181. } else {
  7182. makeApi(sinon);
  7183. }
  7184. })(typeof global !== "undefined" ? global : this);
  7185. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7186. },{"../extend":29,"../log_error":31,"./core":41,"./event":42}],48:[function(require,module,exports){
  7187. (function (global){
  7188. ((typeof define === "function" && define.amd && function (m) {
  7189. define("formatio", ["samsam"], m);
  7190. }) || (typeof module === "object" && function (m) {
  7191. module.exports = m(require("samsam"));
  7192. }) || function (m) { this.formatio = m(this.samsam); }
  7193. )(function (samsam) {
  7194. "use strict";
  7195. var formatio = {
  7196. excludeConstructors: ["Object", /^.$/],
  7197. quoteStrings: true,
  7198. limitChildrenCount: 0
  7199. };
  7200. var hasOwn = Object.prototype.hasOwnProperty;
  7201. var specialObjects = [];
  7202. if (typeof global !== "undefined") {
  7203. specialObjects.push({ object: global, value: "[object global]" });
  7204. }
  7205. if (typeof document !== "undefined") {
  7206. specialObjects.push({
  7207. object: document,
  7208. value: "[object HTMLDocument]"
  7209. });
  7210. }
  7211. if (typeof window !== "undefined") {
  7212. specialObjects.push({ object: window, value: "[object Window]" });
  7213. }
  7214. function functionName(func) {
  7215. if (!func) { return ""; }
  7216. if (func.displayName) { return func.displayName; }
  7217. if (func.name) { return func.name; }
  7218. var matches = func.toString().match(/function\s+([^\(]+)/m);
  7219. return (matches && matches[1]) || "";
  7220. }
  7221. function constructorName(f, object) {
  7222. var name = functionName(object && object.constructor);
  7223. var excludes = f.excludeConstructors ||
  7224. formatio.excludeConstructors || [];
  7225. var i, l;
  7226. for (i = 0, l = excludes.length; i < l; ++i) {
  7227. if (typeof excludes[i] === "string" && excludes[i] === name) {
  7228. return "";
  7229. } else if (excludes[i].test && excludes[i].test(name)) {
  7230. return "";
  7231. }
  7232. }
  7233. return name;
  7234. }
  7235. function isCircular(object, objects) {
  7236. if (typeof object !== "object") { return false; }
  7237. var i, l;
  7238. for (i = 0, l = objects.length; i < l; ++i) {
  7239. if (objects[i] === object) { return true; }
  7240. }
  7241. return false;
  7242. }
  7243. function ascii(f, object, processed, indent) {
  7244. if (typeof object === "string") {
  7245. var qs = f.quoteStrings;
  7246. var quote = typeof qs !== "boolean" || qs;
  7247. return processed || quote ? '"' + object + '"' : object;
  7248. }
  7249. if (typeof object === "function" && !(object instanceof RegExp)) {
  7250. return ascii.func(object);
  7251. }
  7252. processed = processed || [];
  7253. if (isCircular(object, processed)) { return "[Circular]"; }
  7254. if (Object.prototype.toString.call(object) === "[object Array]") {
  7255. return ascii.array.call(f, object, processed);
  7256. }
  7257. if (!object) { return String((1/object) === -Infinity ? "-0" : object); }
  7258. if (samsam.isElement(object)) { return ascii.element(object); }
  7259. if (typeof object.toString === "function" &&
  7260. object.toString !== Object.prototype.toString) {
  7261. return object.toString();
  7262. }
  7263. var i, l;
  7264. for (i = 0, l = specialObjects.length; i < l; i++) {
  7265. if (object === specialObjects[i].object) {
  7266. return specialObjects[i].value;
  7267. }
  7268. }
  7269. return ascii.object.call(f, object, processed, indent);
  7270. }
  7271. ascii.func = function (func) {
  7272. return "function " + functionName(func) + "() {}";
  7273. };
  7274. ascii.array = function (array, processed) {
  7275. processed = processed || [];
  7276. processed.push(array);
  7277. var pieces = [];
  7278. var i, l;
  7279. l = (this.limitChildrenCount > 0) ?
  7280. Math.min(this.limitChildrenCount, array.length) : array.length;
  7281. for (i = 0; i < l; ++i) {
  7282. pieces.push(ascii(this, array[i], processed));
  7283. }
  7284. if(l < array.length)
  7285. pieces.push("[... " + (array.length - l) + " more elements]");
  7286. return "[" + pieces.join(", ") + "]";
  7287. };
  7288. ascii.object = function (object, processed, indent) {
  7289. processed = processed || [];
  7290. processed.push(object);
  7291. indent = indent || 0;
  7292. var pieces = [], properties = samsam.keys(object).sort();
  7293. var length = 3;
  7294. var prop, str, obj, i, k, l;
  7295. l = (this.limitChildrenCount > 0) ?
  7296. Math.min(this.limitChildrenCount, properties.length) : properties.length;
  7297. for (i = 0; i < l; ++i) {
  7298. prop = properties[i];
  7299. obj = object[prop];
  7300. if (isCircular(obj, processed)) {
  7301. str = "[Circular]";
  7302. } else {
  7303. str = ascii(this, obj, processed, indent + 2);
  7304. }
  7305. str = (/\s/.test(prop) ? '"' + prop + '"' : prop) + ": " + str;
  7306. length += str.length;
  7307. pieces.push(str);
  7308. }
  7309. var cons = constructorName(this, object);
  7310. var prefix = cons ? "[" + cons + "] " : "";
  7311. var is = "";
  7312. for (i = 0, k = indent; i < k; ++i) { is += " "; }
  7313. if(l < properties.length)
  7314. pieces.push("[... " + (properties.length - l) + " more elements]");
  7315. if (length + indent > 80) {
  7316. return prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" +
  7317. is + "}";
  7318. }
  7319. return prefix + "{ " + pieces.join(", ") + " }";
  7320. };
  7321. ascii.element = function (element) {
  7322. var tagName = element.tagName.toLowerCase();
  7323. var attrs = element.attributes, attr, pairs = [], attrName, i, l, val;
  7324. for (i = 0, l = attrs.length; i < l; ++i) {
  7325. attr = attrs.item(i);
  7326. attrName = attr.nodeName.toLowerCase().replace("html:", "");
  7327. val = attr.nodeValue;
  7328. if (attrName !== "contenteditable" || val !== "inherit") {
  7329. if (!!val) { pairs.push(attrName + "=\"" + val + "\""); }
  7330. }
  7331. }
  7332. var formatted = "<" + tagName + (pairs.length > 0 ? " " : "");
  7333. var content = element.innerHTML;
  7334. if (content.length > 20) {
  7335. content = content.substr(0, 20) + "[...]";
  7336. }
  7337. var res = formatted + pairs.join(" ") + ">" + content +
  7338. "</" + tagName + ">";
  7339. return res.replace(/ contentEditable="inherit"/, "");
  7340. };
  7341. function Formatio(options) {
  7342. for (var opt in options) {
  7343. this[opt] = options[opt];
  7344. }
  7345. }
  7346. Formatio.prototype = {
  7347. functionName: functionName,
  7348. configure: function (options) {
  7349. return new Formatio(options);
  7350. },
  7351. constructorName: function (object) {
  7352. return constructorName(this, object);
  7353. },
  7354. ascii: function (object, processed, indent) {
  7355. return ascii(this, object, processed, indent);
  7356. }
  7357. };
  7358. return Formatio.prototype;
  7359. });
  7360. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7361. },{"samsam":49}],49:[function(require,module,exports){
  7362. ((typeof define === "function" && define.amd && function (m) { define("samsam", m); }) ||
  7363. (typeof module === "object" &&
  7364. function (m) { module.exports = m(); }) || // Node
  7365. function (m) { this.samsam = m(); } // Browser globals
  7366. )(function () {
  7367. var o = Object.prototype;
  7368. var div = typeof document !== "undefined" && document.createElement("div");
  7369. function isNaN(value) {
  7370. // Unlike global isNaN, this avoids type coercion
  7371. // typeof check avoids IE host object issues, hat tip to
  7372. // lodash
  7373. var val = value; // JsLint thinks value !== value is "weird"
  7374. return typeof value === "number" && value !== val;
  7375. }
  7376. function getClass(value) {
  7377. // Returns the internal [[Class]] by calling Object.prototype.toString
  7378. // with the provided value as this. Return value is a string, naming the
  7379. // internal class, e.g. "Array"
  7380. return o.toString.call(value).split(/[ \]]/)[1];
  7381. }
  7382. /**
  7383. * @name samsam.isArguments
  7384. * @param Object object
  7385. *
  7386. * Returns ``true`` if ``object`` is an ``arguments`` object,
  7387. * ``false`` otherwise.
  7388. */
  7389. function isArguments(object) {
  7390. if (getClass(object) === 'Arguments') { return true; }
  7391. if (typeof object !== "object" || typeof object.length !== "number" ||
  7392. getClass(object) === "Array") {
  7393. return false;
  7394. }
  7395. if (typeof object.callee == "function") { return true; }
  7396. try {
  7397. object[object.length] = 6;
  7398. delete object[object.length];
  7399. } catch (e) {
  7400. return true;
  7401. }
  7402. return false;
  7403. }
  7404. /**
  7405. * @name samsam.isElement
  7406. * @param Object object
  7407. *
  7408. * Returns ``true`` if ``object`` is a DOM element node. Unlike
  7409. * Underscore.js/lodash, this function will return ``false`` if ``object``
  7410. * is an *element-like* object, i.e. a regular object with a ``nodeType``
  7411. * property that holds the value ``1``.
  7412. */
  7413. function isElement(object) {
  7414. if (!object || object.nodeType !== 1 || !div) { return false; }
  7415. try {
  7416. object.appendChild(div);
  7417. object.removeChild(div);
  7418. } catch (e) {
  7419. return false;
  7420. }
  7421. return true;
  7422. }
  7423. /**
  7424. * @name samsam.keys
  7425. * @param Object object
  7426. *
  7427. * Return an array of own property names.
  7428. */
  7429. function keys(object) {
  7430. var ks = [], prop;
  7431. for (prop in object) {
  7432. if (o.hasOwnProperty.call(object, prop)) { ks.push(prop); }
  7433. }
  7434. return ks;
  7435. }
  7436. /**
  7437. * @name samsam.isDate
  7438. * @param Object value
  7439. *
  7440. * Returns true if the object is a ``Date``, or *date-like*. Duck typing
  7441. * of date objects work by checking that the object has a ``getTime``
  7442. * function whose return value equals the return value from the object's
  7443. * ``valueOf``.
  7444. */
  7445. function isDate(value) {
  7446. return typeof value.getTime == "function" &&
  7447. value.getTime() == value.valueOf();
  7448. }
  7449. /**
  7450. * @name samsam.isNegZero
  7451. * @param Object value
  7452. *
  7453. * Returns ``true`` if ``value`` is ``-0``.
  7454. */
  7455. function isNegZero(value) {
  7456. return value === 0 && 1 / value === -Infinity;
  7457. }
  7458. /**
  7459. * @name samsam.equal
  7460. * @param Object obj1
  7461. * @param Object obj2
  7462. *
  7463. * Returns ``true`` if two objects are strictly equal. Compared to
  7464. * ``===`` there are two exceptions:
  7465. *
  7466. * - NaN is considered equal to NaN
  7467. * - -0 and +0 are not considered equal
  7468. */
  7469. function identical(obj1, obj2) {
  7470. if (obj1 === obj2 || (isNaN(obj1) && isNaN(obj2))) {
  7471. return obj1 !== 0 || isNegZero(obj1) === isNegZero(obj2);
  7472. }
  7473. }
  7474. /**
  7475. * @name samsam.deepEqual
  7476. * @param Object obj1
  7477. * @param Object obj2
  7478. *
  7479. * Deep equal comparison. Two values are "deep equal" if:
  7480. *
  7481. * - They are equal, according to samsam.identical
  7482. * - They are both date objects representing the same time
  7483. * - They are both arrays containing elements that are all deepEqual
  7484. * - They are objects with the same set of properties, and each property
  7485. * in ``obj1`` is deepEqual to the corresponding property in ``obj2``
  7486. *
  7487. * Supports cyclic objects.
  7488. */
  7489. function deepEqualCyclic(obj1, obj2) {
  7490. // used for cyclic comparison
  7491. // contain already visited objects
  7492. var objects1 = [],
  7493. objects2 = [],
  7494. // contain pathes (position in the object structure)
  7495. // of the already visited objects
  7496. // indexes same as in objects arrays
  7497. paths1 = [],
  7498. paths2 = [],
  7499. // contains combinations of already compared objects
  7500. // in the manner: { "$1['ref']$2['ref']": true }
  7501. compared = {};
  7502. /**
  7503. * used to check, if the value of a property is an object
  7504. * (cyclic logic is only needed for objects)
  7505. * only needed for cyclic logic
  7506. */
  7507. function isObject(value) {
  7508. if (typeof value === 'object' && value !== null &&
  7509. !(value instanceof Boolean) &&
  7510. !(value instanceof Date) &&
  7511. !(value instanceof Number) &&
  7512. !(value instanceof RegExp) &&
  7513. !(value instanceof String)) {
  7514. return true;
  7515. }
  7516. return false;
  7517. }
  7518. /**
  7519. * returns the index of the given object in the
  7520. * given objects array, -1 if not contained
  7521. * only needed for cyclic logic
  7522. */
  7523. function getIndex(objects, obj) {
  7524. var i;
  7525. for (i = 0; i < objects.length; i++) {
  7526. if (objects[i] === obj) {
  7527. return i;
  7528. }
  7529. }
  7530. return -1;
  7531. }
  7532. // does the recursion for the deep equal check
  7533. return (function deepEqual(obj1, obj2, path1, path2) {
  7534. var type1 = typeof obj1;
  7535. var type2 = typeof obj2;
  7536. // == null also matches undefined
  7537. if (obj1 === obj2 ||
  7538. isNaN(obj1) || isNaN(obj2) ||
  7539. obj1 == null || obj2 == null ||
  7540. type1 !== "object" || type2 !== "object") {
  7541. return identical(obj1, obj2);
  7542. }
  7543. // Elements are only equal if identical(expected, actual)
  7544. if (isElement(obj1) || isElement(obj2)) { return false; }
  7545. var isDate1 = isDate(obj1), isDate2 = isDate(obj2);
  7546. if (isDate1 || isDate2) {
  7547. if (!isDate1 || !isDate2 || obj1.getTime() !== obj2.getTime()) {
  7548. return false;
  7549. }
  7550. }
  7551. if (obj1 instanceof RegExp && obj2 instanceof RegExp) {
  7552. if (obj1.toString() !== obj2.toString()) { return false; }
  7553. }
  7554. var class1 = getClass(obj1);
  7555. var class2 = getClass(obj2);
  7556. var keys1 = keys(obj1);
  7557. var keys2 = keys(obj2);
  7558. if (isArguments(obj1) || isArguments(obj2)) {
  7559. if (obj1.length !== obj2.length) { return false; }
  7560. } else {
  7561. if (type1 !== type2 || class1 !== class2 ||
  7562. keys1.length !== keys2.length) {
  7563. return false;
  7564. }
  7565. }
  7566. var key, i, l,
  7567. // following vars are used for the cyclic logic
  7568. value1, value2,
  7569. isObject1, isObject2,
  7570. index1, index2,
  7571. newPath1, newPath2;
  7572. for (i = 0, l = keys1.length; i < l; i++) {
  7573. key = keys1[i];
  7574. if (!o.hasOwnProperty.call(obj2, key)) {
  7575. return false;
  7576. }
  7577. // Start of the cyclic logic
  7578. value1 = obj1[key];
  7579. value2 = obj2[key];
  7580. isObject1 = isObject(value1);
  7581. isObject2 = isObject(value2);
  7582. // determine, if the objects were already visited
  7583. // (it's faster to check for isObject first, than to
  7584. // get -1 from getIndex for non objects)
  7585. index1 = isObject1 ? getIndex(objects1, value1) : -1;
  7586. index2 = isObject2 ? getIndex(objects2, value2) : -1;
  7587. // determine the new pathes of the objects
  7588. // - for non cyclic objects the current path will be extended
  7589. // by current property name
  7590. // - for cyclic objects the stored path is taken
  7591. newPath1 = index1 !== -1
  7592. ? paths1[index1]
  7593. : path1 + '[' + JSON.stringify(key) + ']';
  7594. newPath2 = index2 !== -1
  7595. ? paths2[index2]
  7596. : path2 + '[' + JSON.stringify(key) + ']';
  7597. // stop recursion if current objects are already compared
  7598. if (compared[newPath1 + newPath2]) {
  7599. return true;
  7600. }
  7601. // remember the current objects and their pathes
  7602. if (index1 === -1 && isObject1) {
  7603. objects1.push(value1);
  7604. paths1.push(newPath1);
  7605. }
  7606. if (index2 === -1 && isObject2) {
  7607. objects2.push(value2);
  7608. paths2.push(newPath2);
  7609. }
  7610. // remember that the current objects are already compared
  7611. if (isObject1 && isObject2) {
  7612. compared[newPath1 + newPath2] = true;
  7613. }
  7614. // End of cyclic logic
  7615. // neither value1 nor value2 is a cycle
  7616. // continue with next level
  7617. if (!deepEqual(value1, value2, newPath1, newPath2)) {
  7618. return false;
  7619. }
  7620. }
  7621. return true;
  7622. }(obj1, obj2, '$1', '$2'));
  7623. }
  7624. var match;
  7625. function arrayContains(array, subset) {
  7626. if (subset.length === 0) { return true; }
  7627. var i, l, j, k;
  7628. for (i = 0, l = array.length; i < l; ++i) {
  7629. if (match(array[i], subset[0])) {
  7630. for (j = 0, k = subset.length; j < k; ++j) {
  7631. if (!match(array[i + j], subset[j])) { return false; }
  7632. }
  7633. return true;
  7634. }
  7635. }
  7636. return false;
  7637. }
  7638. /**
  7639. * @name samsam.match
  7640. * @param Object object
  7641. * @param Object matcher
  7642. *
  7643. * Compare arbitrary value ``object`` with matcher.
  7644. */
  7645. match = function match(object, matcher) {
  7646. if (matcher && typeof matcher.test === "function") {
  7647. return matcher.test(object);
  7648. }
  7649. if (typeof matcher === "function") {
  7650. return matcher(object) === true;
  7651. }
  7652. if (typeof matcher === "string") {
  7653. matcher = matcher.toLowerCase();
  7654. var notNull = typeof object === "string" || !!object;
  7655. return notNull &&
  7656. (String(object)).toLowerCase().indexOf(matcher) >= 0;
  7657. }
  7658. if (typeof matcher === "number") {
  7659. return matcher === object;
  7660. }
  7661. if (typeof matcher === "boolean") {
  7662. return matcher === object;
  7663. }
  7664. if (typeof(matcher) === "undefined") {
  7665. return typeof(object) === "undefined";
  7666. }
  7667. if (matcher === null) {
  7668. return object === null;
  7669. }
  7670. if (getClass(object) === "Array" && getClass(matcher) === "Array") {
  7671. return arrayContains(object, matcher);
  7672. }
  7673. if (matcher && typeof matcher === "object") {
  7674. if (matcher === object) {
  7675. return true;
  7676. }
  7677. var prop;
  7678. for (prop in matcher) {
  7679. var value = object[prop];
  7680. if (typeof value === "undefined" &&
  7681. typeof object.getAttribute === "function") {
  7682. value = object.getAttribute(prop);
  7683. }
  7684. if (matcher[prop] === null || typeof matcher[prop] === 'undefined') {
  7685. if (value !== matcher[prop]) {
  7686. return false;
  7687. }
  7688. } else if (typeof value === "undefined" || !match(value, matcher[prop])) {
  7689. return false;
  7690. }
  7691. }
  7692. return true;
  7693. }
  7694. throw new Error("Matcher was not a string, a number, a " +
  7695. "function, a boolean or an object");
  7696. };
  7697. return {
  7698. isArguments: isArguments,
  7699. isElement: isElement,
  7700. isDate: isDate,
  7701. isNegZero: isNegZero,
  7702. identical: identical,
  7703. deepEqual: deepEqualCyclic,
  7704. match: match,
  7705. keys: keys
  7706. };
  7707. });
  7708. },{}],50:[function(require,module,exports){
  7709. (function (global){
  7710. /*jslint eqeqeq: false, plusplus: false, evil: true, onevar: false, browser: true, forin: false*/
  7711. /*global global*/
  7712. /**
  7713. * @author Christian Johansen (christian@cjohansen.no) and contributors
  7714. * @license BSD
  7715. *
  7716. * Copyright (c) 2010-2014 Christian Johansen
  7717. */
  7718. "use strict";
  7719. // node expects setTimeout/setInterval to return a fn object w/ .ref()/.unref()
  7720. // browsers, a number.
  7721. // see https://github.com/cjohansen/Sinon.JS/pull/436
  7722. var timeoutResult = setTimeout(function() {}, 0);
  7723. var addTimerReturnsObject = typeof timeoutResult === "object";
  7724. clearTimeout(timeoutResult);
  7725. var NativeDate = Date;
  7726. var id = 1;
  7727. /**
  7728. * Parse strings like "01:10:00" (meaning 1 hour, 10 minutes, 0 seconds) into
  7729. * number of milliseconds. This is used to support human-readable strings passed
  7730. * to clock.tick()
  7731. */
  7732. function parseTime(str) {
  7733. if (!str) {
  7734. return 0;
  7735. }
  7736. var strings = str.split(":");
  7737. var l = strings.length, i = l;
  7738. var ms = 0, parsed;
  7739. if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) {
  7740. throw new Error("tick only understands numbers and 'h:m:s'");
  7741. }
  7742. while (i--) {
  7743. parsed = parseInt(strings[i], 10);
  7744. if (parsed >= 60) {
  7745. throw new Error("Invalid time " + str);
  7746. }
  7747. ms += parsed * Math.pow(60, (l - i - 1));
  7748. }
  7749. return ms * 1000;
  7750. }
  7751. /**
  7752. * Used to grok the `now` parameter to createClock.
  7753. */
  7754. function getEpoch(epoch) {
  7755. if (!epoch) { return 0; }
  7756. if (typeof epoch.getTime === "function") { return epoch.getTime(); }
  7757. if (typeof epoch === "number") { return epoch; }
  7758. throw new TypeError("now should be milliseconds since UNIX epoch");
  7759. }
  7760. function inRange(from, to, timer) {
  7761. return timer && timer.callAt >= from && timer.callAt <= to;
  7762. }
  7763. function mirrorDateProperties(target, source) {
  7764. if (source.now) {
  7765. target.now = function now() {
  7766. return target.clock.now;
  7767. };
  7768. } else {
  7769. delete target.now;
  7770. }
  7771. if (source.toSource) {
  7772. target.toSource = function toSource() {
  7773. return source.toSource();
  7774. };
  7775. } else {
  7776. delete target.toSource;
  7777. }
  7778. target.toString = function toString() {
  7779. return source.toString();
  7780. };
  7781. target.prototype = source.prototype;
  7782. target.parse = source.parse;
  7783. target.UTC = source.UTC;
  7784. target.prototype.toUTCString = source.prototype.toUTCString;
  7785. for (var prop in source) {
  7786. if (source.hasOwnProperty(prop)) {
  7787. target[prop] = source[prop];
  7788. }
  7789. }
  7790. return target;
  7791. }
  7792. function createDate() {
  7793. function ClockDate(year, month, date, hour, minute, second, ms) {
  7794. // Defensive and verbose to avoid potential harm in passing
  7795. // explicit undefined when user does not pass argument
  7796. switch (arguments.length) {
  7797. case 0:
  7798. return new NativeDate(ClockDate.clock.now);
  7799. case 1:
  7800. return new NativeDate(year);
  7801. case 2:
  7802. return new NativeDate(year, month);
  7803. case 3:
  7804. return new NativeDate(year, month, date);
  7805. case 4:
  7806. return new NativeDate(year, month, date, hour);
  7807. case 5:
  7808. return new NativeDate(year, month, date, hour, minute);
  7809. case 6:
  7810. return new NativeDate(year, month, date, hour, minute, second);
  7811. default:
  7812. return new NativeDate(year, month, date, hour, minute, second, ms);
  7813. }
  7814. }
  7815. return mirrorDateProperties(ClockDate, NativeDate);
  7816. }
  7817. function addTimer(clock, timer) {
  7818. if (typeof timer.func === "undefined") {
  7819. throw new Error("Callback must be provided to timer calls");
  7820. }
  7821. if (!clock.timers) {
  7822. clock.timers = {};
  7823. }
  7824. timer.id = id++;
  7825. timer.createdAt = clock.now;
  7826. timer.callAt = clock.now + (timer.delay || 0);
  7827. clock.timers[timer.id] = timer;
  7828. if (addTimerReturnsObject) {
  7829. return {
  7830. id: timer.id,
  7831. ref: function() {},
  7832. unref: function() {}
  7833. };
  7834. }
  7835. else {
  7836. return timer.id;
  7837. }
  7838. }
  7839. function firstTimerInRange(clock, from, to) {
  7840. var timers = clock.timers, timer = null;
  7841. for (var id in timers) {
  7842. if (!inRange(from, to, timers[id])) {
  7843. continue;
  7844. }
  7845. if (!timer || ~compareTimers(timer, timers[id])) {
  7846. timer = timers[id];
  7847. }
  7848. }
  7849. return timer;
  7850. }
  7851. function compareTimers(a, b) {
  7852. // Sort first by absolute timing
  7853. if (a.callAt < b.callAt) {
  7854. return -1;
  7855. }
  7856. if (a.callAt > b.callAt) {
  7857. return 1;
  7858. }
  7859. // Sort next by immediate, immediate timers take precedence
  7860. if (a.immediate && !b.immediate) {
  7861. return -1;
  7862. }
  7863. if (!a.immediate && b.immediate) {
  7864. return 1;
  7865. }
  7866. // Sort next by creation time, earlier-created timers take precedence
  7867. if (a.createdAt < b.createdAt) {
  7868. return -1;
  7869. }
  7870. if (a.createdAt > b.createdAt) {
  7871. return 1;
  7872. }
  7873. // Sort next by id, lower-id timers take precedence
  7874. if (a.id < b.id) {
  7875. return -1;
  7876. }
  7877. if (a.id > b.id) {
  7878. return 1;
  7879. }
  7880. // As timer ids are unique, no fallback `0` is necessary
  7881. }
  7882. function callTimer(clock, timer) {
  7883. if (typeof timer.interval == "number") {
  7884. clock.timers[timer.id].callAt += timer.interval;
  7885. } else {
  7886. delete clock.timers[timer.id];
  7887. }
  7888. try {
  7889. if (typeof timer.func == "function") {
  7890. timer.func.apply(null, timer.args);
  7891. } else {
  7892. eval(timer.func);
  7893. }
  7894. } catch (e) {
  7895. var exception = e;
  7896. }
  7897. if (!clock.timers[timer.id]) {
  7898. if (exception) {
  7899. throw exception;
  7900. }
  7901. return;
  7902. }
  7903. if (exception) {
  7904. throw exception;
  7905. }
  7906. }
  7907. function uninstall(clock, target) {
  7908. var method;
  7909. for (var i = 0, l = clock.methods.length; i < l; i++) {
  7910. method = clock.methods[i];
  7911. if (target[method].hadOwnProperty) {
  7912. target[method] = clock["_" + method];
  7913. } else {
  7914. try {
  7915. delete target[method];
  7916. } catch (e) {}
  7917. }
  7918. }
  7919. // Prevent multiple executions which will completely remove these props
  7920. clock.methods = [];
  7921. }
  7922. function hijackMethod(target, method, clock) {
  7923. clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(target, method);
  7924. clock["_" + method] = target[method];
  7925. if (method == "Date") {
  7926. var date = mirrorDateProperties(clock[method], target[method]);
  7927. target[method] = date;
  7928. } else {
  7929. target[method] = function () {
  7930. return clock[method].apply(clock, arguments);
  7931. };
  7932. for (var prop in clock[method]) {
  7933. if (clock[method].hasOwnProperty(prop)) {
  7934. target[method][prop] = clock[method][prop];
  7935. }
  7936. }
  7937. }
  7938. target[method].clock = clock;
  7939. }
  7940. var timers = {
  7941. setTimeout: setTimeout,
  7942. clearTimeout: clearTimeout,
  7943. setImmediate: (typeof setImmediate !== "undefined" ? setImmediate : undefined),
  7944. clearImmediate: (typeof clearImmediate !== "undefined" ? clearImmediate: undefined),
  7945. setInterval: setInterval,
  7946. clearInterval: clearInterval,
  7947. Date: Date
  7948. };
  7949. var keys = Object.keys || function (obj) {
  7950. var ks = [];
  7951. for (var key in obj) {
  7952. ks.push(key);
  7953. }
  7954. return ks;
  7955. };
  7956. exports.timers = timers;
  7957. var createClock = exports.createClock = function (now) {
  7958. var clock = {
  7959. now: getEpoch(now),
  7960. timeouts: {},
  7961. Date: createDate()
  7962. };
  7963. clock.Date.clock = clock;
  7964. clock.setTimeout = function setTimeout(func, timeout) {
  7965. return addTimer(clock, {
  7966. func: func,
  7967. args: Array.prototype.slice.call(arguments, 2),
  7968. delay: timeout
  7969. });
  7970. };
  7971. clock.clearTimeout = function clearTimeout(timerId) {
  7972. if (!timerId) {
  7973. // null appears to be allowed in most browsers, and appears to be
  7974. // relied upon by some libraries, like Bootstrap carousel
  7975. return;
  7976. }
  7977. if (!clock.timers) {
  7978. clock.timers = [];
  7979. }
  7980. // in Node, timerId is an object with .ref()/.unref(), and
  7981. // its .id field is the actual timer id.
  7982. if (typeof timerId === "object") {
  7983. timerId = timerId.id
  7984. }
  7985. if (timerId in clock.timers) {
  7986. delete clock.timers[timerId];
  7987. }
  7988. };
  7989. clock.setInterval = function setInterval(func, timeout) {
  7990. return addTimer(clock, {
  7991. func: func,
  7992. args: Array.prototype.slice.call(arguments, 2),
  7993. delay: timeout,
  7994. interval: timeout
  7995. });
  7996. };
  7997. clock.clearInterval = function clearInterval(timerId) {
  7998. clock.clearTimeout(timerId);
  7999. };
  8000. clock.setImmediate = function setImmediate(func) {
  8001. return addTimer(clock, {
  8002. func: func,
  8003. args: Array.prototype.slice.call(arguments, 1),
  8004. immediate: true
  8005. });
  8006. };
  8007. clock.clearImmediate = function clearImmediate(timerId) {
  8008. clock.clearTimeout(timerId);
  8009. };
  8010. clock.tick = function tick(ms) {
  8011. ms = typeof ms == "number" ? ms : parseTime(ms);
  8012. var tickFrom = clock.now, tickTo = clock.now + ms, previous = clock.now;
  8013. var timer = firstTimerInRange(clock, tickFrom, tickTo);
  8014. var firstException;
  8015. while (timer && tickFrom <= tickTo) {
  8016. if (clock.timers[timer.id]) {
  8017. tickFrom = clock.now = timer.callAt;
  8018. try {
  8019. callTimer(clock, timer);
  8020. } catch (e) {
  8021. firstException = firstException || e;
  8022. }
  8023. }
  8024. timer = firstTimerInRange(clock, previous, tickTo);
  8025. previous = tickFrom;
  8026. }
  8027. clock.now = tickTo;
  8028. if (firstException) {
  8029. throw firstException;
  8030. }
  8031. return clock.now;
  8032. };
  8033. clock.reset = function reset() {
  8034. clock.timers = {};
  8035. };
  8036. return clock;
  8037. };
  8038. exports.install = function install(target, now, toFake) {
  8039. if (typeof target === "number") {
  8040. toFake = now;
  8041. now = target;
  8042. target = null;
  8043. }
  8044. if (!target) {
  8045. target = global;
  8046. }
  8047. var clock = createClock(now);
  8048. clock.uninstall = function () {
  8049. uninstall(clock, target);
  8050. };
  8051. clock.methods = toFake || [];
  8052. if (clock.methods.length === 0) {
  8053. clock.methods = keys(timers);
  8054. }
  8055. for (var i = 0, l = clock.methods.length; i < l; i++) {
  8056. hijackMethod(target, clock.methods[i], clock);
  8057. }
  8058. return clock;
  8059. };
  8060. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  8061. },{}],51:[function(require,module,exports){
  8062. (function (process,global){
  8063. (function() {
  8064. "use strict";
  8065. function lib$es6$promise$utils$$objectOrFunction(x) {
  8066. return typeof x === 'function' || (typeof x === 'object' && x !== null);
  8067. }
  8068. function lib$es6$promise$utils$$isFunction(x) {
  8069. return typeof x === 'function';
  8070. }
  8071. function lib$es6$promise$utils$$isMaybeThenable(x) {
  8072. return typeof x === 'object' && x !== null;
  8073. }
  8074. var lib$es6$promise$utils$$_isArray;
  8075. if (!Array.isArray) {
  8076. lib$es6$promise$utils$$_isArray = function (x) {
  8077. return Object.prototype.toString.call(x) === '[object Array]';
  8078. };
  8079. } else {
  8080. lib$es6$promise$utils$$_isArray = Array.isArray;
  8081. }
  8082. var lib$es6$promise$utils$$isArray = lib$es6$promise$utils$$_isArray;
  8083. var lib$es6$promise$asap$$len = 0;
  8084. var lib$es6$promise$asap$$toString = {}.toString;
  8085. var lib$es6$promise$asap$$vertxNext;
  8086. var lib$es6$promise$asap$$customSchedulerFn;
  8087. var lib$es6$promise$asap$$asap = function asap(callback, arg) {
  8088. lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len] = callback;
  8089. lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len + 1] = arg;
  8090. lib$es6$promise$asap$$len += 2;
  8091. if (lib$es6$promise$asap$$len === 2) {
  8092. // If len is 2, that means that we need to schedule an async flush.
  8093. // If additional callbacks are queued before the queue is flushed, they
  8094. // will be processed by this flush that we are scheduling.
  8095. if (lib$es6$promise$asap$$customSchedulerFn) {
  8096. lib$es6$promise$asap$$customSchedulerFn(lib$es6$promise$asap$$flush);
  8097. } else {
  8098. lib$es6$promise$asap$$scheduleFlush();
  8099. }
  8100. }
  8101. }
  8102. function lib$es6$promise$asap$$setScheduler(scheduleFn) {
  8103. lib$es6$promise$asap$$customSchedulerFn = scheduleFn;
  8104. }
  8105. function lib$es6$promise$asap$$setAsap(asapFn) {
  8106. lib$es6$promise$asap$$asap = asapFn;
  8107. }
  8108. var lib$es6$promise$asap$$browserWindow = (typeof window !== 'undefined') ? window : undefined;
  8109. var lib$es6$promise$asap$$browserGlobal = lib$es6$promise$asap$$browserWindow || {};
  8110. var lib$es6$promise$asap$$BrowserMutationObserver = lib$es6$promise$asap$$browserGlobal.MutationObserver || lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver;
  8111. var lib$es6$promise$asap$$isNode = typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
  8112. // test for web worker but not in IE10
  8113. var lib$es6$promise$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' &&
  8114. typeof importScripts !== 'undefined' &&
  8115. typeof MessageChannel !== 'undefined';
  8116. // node
  8117. function lib$es6$promise$asap$$useNextTick() {
  8118. var nextTick = process.nextTick;
  8119. // node version 0.10.x displays a deprecation warning when nextTick is used recursively
  8120. // setImmediate should be used instead instead
  8121. var version = process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/);
  8122. if (Array.isArray(version) && version[1] === '0' && version[2] === '10') {
  8123. nextTick = setImmediate;
  8124. }
  8125. return function() {
  8126. nextTick(lib$es6$promise$asap$$flush);
  8127. };
  8128. }
  8129. // vertx
  8130. function lib$es6$promise$asap$$useVertxTimer() {
  8131. return function() {
  8132. lib$es6$promise$asap$$vertxNext(lib$es6$promise$asap$$flush);
  8133. };
  8134. }
  8135. function lib$es6$promise$asap$$useMutationObserver() {
  8136. var iterations = 0;
  8137. var observer = new lib$es6$promise$asap$$BrowserMutationObserver(lib$es6$promise$asap$$flush);
  8138. var node = document.createTextNode('');
  8139. observer.observe(node, { characterData: true });
  8140. return function() {
  8141. node.data = (iterations = ++iterations % 2);
  8142. };
  8143. }
  8144. // web worker
  8145. function lib$es6$promise$asap$$useMessageChannel() {
  8146. var channel = new MessageChannel();
  8147. channel.port1.onmessage = lib$es6$promise$asap$$flush;
  8148. return function () {
  8149. channel.port2.postMessage(0);
  8150. };
  8151. }
  8152. function lib$es6$promise$asap$$useSetTimeout() {
  8153. return function() {
  8154. setTimeout(lib$es6$promise$asap$$flush, 1);
  8155. };
  8156. }
  8157. var lib$es6$promise$asap$$queue = new Array(1000);
  8158. function lib$es6$promise$asap$$flush() {
  8159. for (var i = 0; i < lib$es6$promise$asap$$len; i+=2) {
  8160. var callback = lib$es6$promise$asap$$queue[i];
  8161. var arg = lib$es6$promise$asap$$queue[i+1];
  8162. callback(arg);
  8163. lib$es6$promise$asap$$queue[i] = undefined;
  8164. lib$es6$promise$asap$$queue[i+1] = undefined;
  8165. }
  8166. lib$es6$promise$asap$$len = 0;
  8167. }
  8168. function lib$es6$promise$asap$$attemptVertex() {
  8169. try {
  8170. var r = require;
  8171. var vertx = r('vertx');
  8172. lib$es6$promise$asap$$vertxNext = vertx.runOnLoop || vertx.runOnContext;
  8173. return lib$es6$promise$asap$$useVertxTimer();
  8174. } catch(e) {
  8175. return lib$es6$promise$asap$$useSetTimeout();
  8176. }
  8177. }
  8178. var lib$es6$promise$asap$$scheduleFlush;
  8179. // Decide what async method to use to triggering processing of queued callbacks:
  8180. if (lib$es6$promise$asap$$isNode) {
  8181. lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useNextTick();
  8182. } else if (lib$es6$promise$asap$$BrowserMutationObserver) {
  8183. lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMutationObserver();
  8184. } else if (lib$es6$promise$asap$$isWorker) {
  8185. lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMessageChannel();
  8186. } else if (lib$es6$promise$asap$$browserWindow === undefined && typeof require === 'function') {
  8187. lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$attemptVertex();
  8188. } else {
  8189. lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useSetTimeout();
  8190. }
  8191. function lib$es6$promise$$internal$$noop() {}
  8192. var lib$es6$promise$$internal$$PENDING = void 0;
  8193. var lib$es6$promise$$internal$$FULFILLED = 1;
  8194. var lib$es6$promise$$internal$$REJECTED = 2;
  8195. var lib$es6$promise$$internal$$GET_THEN_ERROR = new lib$es6$promise$$internal$$ErrorObject();
  8196. function lib$es6$promise$$internal$$selfFullfillment() {
  8197. return new TypeError("You cannot resolve a promise with itself");
  8198. }
  8199. function lib$es6$promise$$internal$$cannotReturnOwn() {
  8200. return new TypeError('A promises callback cannot return that same promise.');
  8201. }
  8202. function lib$es6$promise$$internal$$getThen(promise) {
  8203. try {
  8204. return promise.then;
  8205. } catch(error) {
  8206. lib$es6$promise$$internal$$GET_THEN_ERROR.error = error;
  8207. return lib$es6$promise$$internal$$GET_THEN_ERROR;
  8208. }
  8209. }
  8210. function lib$es6$promise$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) {
  8211. try {
  8212. then.call(value, fulfillmentHandler, rejectionHandler);
  8213. } catch(e) {
  8214. return e;
  8215. }
  8216. }
  8217. function lib$es6$promise$$internal$$handleForeignThenable(promise, thenable, then) {
  8218. lib$es6$promise$asap$$asap(function(promise) {
  8219. var sealed = false;
  8220. var error = lib$es6$promise$$internal$$tryThen(then, thenable, function(value) {
  8221. if (sealed) { return; }
  8222. sealed = true;
  8223. if (thenable !== value) {
  8224. lib$es6$promise$$internal$$resolve(promise, value);
  8225. } else {
  8226. lib$es6$promise$$internal$$fulfill(promise, value);
  8227. }
  8228. }, function(reason) {
  8229. if (sealed) { return; }
  8230. sealed = true;
  8231. lib$es6$promise$$internal$$reject(promise, reason);
  8232. }, 'Settle: ' + (promise._label || ' unknown promise'));
  8233. if (!sealed && error) {
  8234. sealed = true;
  8235. lib$es6$promise$$internal$$reject(promise, error);
  8236. }
  8237. }, promise);
  8238. }
  8239. function lib$es6$promise$$internal$$handleOwnThenable(promise, thenable) {
  8240. if (thenable._state === lib$es6$promise$$internal$$FULFILLED) {
  8241. lib$es6$promise$$internal$$fulfill(promise, thenable._result);
  8242. } else if (thenable._state === lib$es6$promise$$internal$$REJECTED) {
  8243. lib$es6$promise$$internal$$reject(promise, thenable._result);
  8244. } else {
  8245. lib$es6$promise$$internal$$subscribe(thenable, undefined, function(value) {
  8246. lib$es6$promise$$internal$$resolve(promise, value);
  8247. }, function(reason) {
  8248. lib$es6$promise$$internal$$reject(promise, reason);
  8249. });
  8250. }
  8251. }
  8252. function lib$es6$promise$$internal$$handleMaybeThenable(promise, maybeThenable) {
  8253. if (maybeThenable.constructor === promise.constructor) {
  8254. lib$es6$promise$$internal$$handleOwnThenable(promise, maybeThenable);
  8255. } else {
  8256. var then = lib$es6$promise$$internal$$getThen(maybeThenable);
  8257. if (then === lib$es6$promise$$internal$$GET_THEN_ERROR) {
  8258. lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$GET_THEN_ERROR.error);
  8259. } else if (then === undefined) {
  8260. lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
  8261. } else if (lib$es6$promise$utils$$isFunction(then)) {
  8262. lib$es6$promise$$internal$$handleForeignThenable(promise, maybeThenable, then);
  8263. } else {
  8264. lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
  8265. }
  8266. }
  8267. }
  8268. function lib$es6$promise$$internal$$resolve(promise, value) {
  8269. if (promise === value) {
  8270. lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$selfFullfillment());
  8271. } else if (lib$es6$promise$utils$$objectOrFunction(value)) {
  8272. lib$es6$promise$$internal$$handleMaybeThenable(promise, value);
  8273. } else {
  8274. lib$es6$promise$$internal$$fulfill(promise, value);
  8275. }
  8276. }
  8277. function lib$es6$promise$$internal$$publishRejection(promise) {
  8278. if (promise._onerror) {
  8279. promise._onerror(promise._result);
  8280. }
  8281. lib$es6$promise$$internal$$publish(promise);
  8282. }
  8283. function lib$es6$promise$$internal$$fulfill(promise, value) {
  8284. if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
  8285. promise._result = value;
  8286. promise._state = lib$es6$promise$$internal$$FULFILLED;
  8287. if (promise._subscribers.length !== 0) {
  8288. lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, promise);
  8289. }
  8290. }
  8291. function lib$es6$promise$$internal$$reject(promise, reason) {
  8292. if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
  8293. promise._state = lib$es6$promise$$internal$$REJECTED;
  8294. promise._result = reason;
  8295. lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publishRejection, promise);
  8296. }
  8297. function lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection) {
  8298. var subscribers = parent._subscribers;
  8299. var length = subscribers.length;
  8300. parent._onerror = null;
  8301. subscribers[length] = child;
  8302. subscribers[length + lib$es6$promise$$internal$$FULFILLED] = onFulfillment;
  8303. subscribers[length + lib$es6$promise$$internal$$REJECTED] = onRejection;
  8304. if (length === 0 && parent._state) {
  8305. lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, parent);
  8306. }
  8307. }
  8308. function lib$es6$promise$$internal$$publish(promise) {
  8309. var subscribers = promise._subscribers;
  8310. var settled = promise._state;
  8311. if (subscribers.length === 0) { return; }
  8312. var child, callback, detail = promise._result;
  8313. for (var i = 0; i < subscribers.length; i += 3) {
  8314. child = subscribers[i];
  8315. callback = subscribers[i + settled];
  8316. if (child) {
  8317. lib$es6$promise$$internal$$invokeCallback(settled, child, callback, detail);
  8318. } else {
  8319. callback(detail);
  8320. }
  8321. }
  8322. promise._subscribers.length = 0;
  8323. }
  8324. function lib$es6$promise$$internal$$ErrorObject() {
  8325. this.error = null;
  8326. }
  8327. var lib$es6$promise$$internal$$TRY_CATCH_ERROR = new lib$es6$promise$$internal$$ErrorObject();
  8328. function lib$es6$promise$$internal$$tryCatch(callback, detail) {
  8329. try {
  8330. return callback(detail);
  8331. } catch(e) {
  8332. lib$es6$promise$$internal$$TRY_CATCH_ERROR.error = e;
  8333. return lib$es6$promise$$internal$$TRY_CATCH_ERROR;
  8334. }
  8335. }
  8336. function lib$es6$promise$$internal$$invokeCallback(settled, promise, callback, detail) {
  8337. var hasCallback = lib$es6$promise$utils$$isFunction(callback),
  8338. value, error, succeeded, failed;
  8339. if (hasCallback) {
  8340. value = lib$es6$promise$$internal$$tryCatch(callback, detail);
  8341. if (value === lib$es6$promise$$internal$$TRY_CATCH_ERROR) {
  8342. failed = true;
  8343. error = value.error;
  8344. value = null;
  8345. } else {
  8346. succeeded = true;
  8347. }
  8348. if (promise === value) {
  8349. lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$cannotReturnOwn());
  8350. return;
  8351. }
  8352. } else {
  8353. value = detail;
  8354. succeeded = true;
  8355. }
  8356. if (promise._state !== lib$es6$promise$$internal$$PENDING) {
  8357. // noop
  8358. } else if (hasCallback && succeeded) {
  8359. lib$es6$promise$$internal$$resolve(promise, value);
  8360. } else if (failed) {
  8361. lib$es6$promise$$internal$$reject(promise, error);
  8362. } else if (settled === lib$es6$promise$$internal$$FULFILLED) {
  8363. lib$es6$promise$$internal$$fulfill(promise, value);
  8364. } else if (settled === lib$es6$promise$$internal$$REJECTED) {
  8365. lib$es6$promise$$internal$$reject(promise, value);
  8366. }
  8367. }
  8368. function lib$es6$promise$$internal$$initializePromise(promise, resolver) {
  8369. try {
  8370. resolver(function resolvePromise(value){
  8371. lib$es6$promise$$internal$$resolve(promise, value);
  8372. }, function rejectPromise(reason) {
  8373. lib$es6$promise$$internal$$reject(promise, reason);
  8374. });
  8375. } catch(e) {
  8376. lib$es6$promise$$internal$$reject(promise, e);
  8377. }
  8378. }
  8379. function lib$es6$promise$enumerator$$Enumerator(Constructor, input) {
  8380. var enumerator = this;
  8381. enumerator._instanceConstructor = Constructor;
  8382. enumerator.promise = new Constructor(lib$es6$promise$$internal$$noop);
  8383. if (enumerator._validateInput(input)) {
  8384. enumerator._input = input;
  8385. enumerator.length = input.length;
  8386. enumerator._remaining = input.length;
  8387. enumerator._init();
  8388. if (enumerator.length === 0) {
  8389. lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result);
  8390. } else {
  8391. enumerator.length = enumerator.length || 0;
  8392. enumerator._enumerate();
  8393. if (enumerator._remaining === 0) {
  8394. lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result);
  8395. }
  8396. }
  8397. } else {
  8398. lib$es6$promise$$internal$$reject(enumerator.promise, enumerator._validationError());
  8399. }
  8400. }
  8401. lib$es6$promise$enumerator$$Enumerator.prototype._validateInput = function(input) {
  8402. return lib$es6$promise$utils$$isArray(input);
  8403. };
  8404. lib$es6$promise$enumerator$$Enumerator.prototype._validationError = function() {
  8405. return new Error('Array Methods must be provided an Array');
  8406. };
  8407. lib$es6$promise$enumerator$$Enumerator.prototype._init = function() {
  8408. this._result = new Array(this.length);
  8409. };
  8410. var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator;
  8411. lib$es6$promise$enumerator$$Enumerator.prototype._enumerate = function() {
  8412. var enumerator = this;
  8413. var length = enumerator.length;
  8414. var promise = enumerator.promise;
  8415. var input = enumerator._input;
  8416. for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
  8417. enumerator._eachEntry(input[i], i);
  8418. }
  8419. };
  8420. lib$es6$promise$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) {
  8421. var enumerator = this;
  8422. var c = enumerator._instanceConstructor;
  8423. if (lib$es6$promise$utils$$isMaybeThenable(entry)) {
  8424. if (entry.constructor === c && entry._state !== lib$es6$promise$$internal$$PENDING) {
  8425. entry._onerror = null;
  8426. enumerator._settledAt(entry._state, i, entry._result);
  8427. } else {
  8428. enumerator._willSettleAt(c.resolve(entry), i);
  8429. }
  8430. } else {
  8431. enumerator._remaining--;
  8432. enumerator._result[i] = entry;
  8433. }
  8434. };
  8435. lib$es6$promise$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) {
  8436. var enumerator = this;
  8437. var promise = enumerator.promise;
  8438. if (promise._state === lib$es6$promise$$internal$$PENDING) {
  8439. enumerator._remaining--;
  8440. if (state === lib$es6$promise$$internal$$REJECTED) {
  8441. lib$es6$promise$$internal$$reject(promise, value);
  8442. } else {
  8443. enumerator._result[i] = value;
  8444. }
  8445. }
  8446. if (enumerator._remaining === 0) {
  8447. lib$es6$promise$$internal$$fulfill(promise, enumerator._result);
  8448. }
  8449. };
  8450. lib$es6$promise$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) {
  8451. var enumerator = this;
  8452. lib$es6$promise$$internal$$subscribe(promise, undefined, function(value) {
  8453. enumerator._settledAt(lib$es6$promise$$internal$$FULFILLED, i, value);
  8454. }, function(reason) {
  8455. enumerator._settledAt(lib$es6$promise$$internal$$REJECTED, i, reason);
  8456. });
  8457. };
  8458. function lib$es6$promise$promise$all$$all(entries) {
  8459. return new lib$es6$promise$enumerator$$default(this, entries).promise;
  8460. }
  8461. var lib$es6$promise$promise$all$$default = lib$es6$promise$promise$all$$all;
  8462. function lib$es6$promise$promise$race$$race(entries) {
  8463. /*jshint validthis:true */
  8464. var Constructor = this;
  8465. var promise = new Constructor(lib$es6$promise$$internal$$noop);
  8466. if (!lib$es6$promise$utils$$isArray(entries)) {
  8467. lib$es6$promise$$internal$$reject(promise, new TypeError('You must pass an array to race.'));
  8468. return promise;
  8469. }
  8470. var length = entries.length;
  8471. function onFulfillment(value) {
  8472. lib$es6$promise$$internal$$resolve(promise, value);
  8473. }
  8474. function onRejection(reason) {
  8475. lib$es6$promise$$internal$$reject(promise, reason);
  8476. }
  8477. for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
  8478. lib$es6$promise$$internal$$subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection);
  8479. }
  8480. return promise;
  8481. }
  8482. var lib$es6$promise$promise$race$$default = lib$es6$promise$promise$race$$race;
  8483. function lib$es6$promise$promise$resolve$$resolve(object) {
  8484. /*jshint validthis:true */
  8485. var Constructor = this;
  8486. if (object && typeof object === 'object' && object.constructor === Constructor) {
  8487. return object;
  8488. }
  8489. var promise = new Constructor(lib$es6$promise$$internal$$noop);
  8490. lib$es6$promise$$internal$$resolve(promise, object);
  8491. return promise;
  8492. }
  8493. var lib$es6$promise$promise$resolve$$default = lib$es6$promise$promise$resolve$$resolve;
  8494. function lib$es6$promise$promise$reject$$reject(reason) {
  8495. /*jshint validthis:true */
  8496. var Constructor = this;
  8497. var promise = new Constructor(lib$es6$promise$$internal$$noop);
  8498. lib$es6$promise$$internal$$reject(promise, reason);
  8499. return promise;
  8500. }
  8501. var lib$es6$promise$promise$reject$$default = lib$es6$promise$promise$reject$$reject;
  8502. var lib$es6$promise$promise$$counter = 0;
  8503. function lib$es6$promise$promise$$needsResolver() {
  8504. throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
  8505. }
  8506. function lib$es6$promise$promise$$needsNew() {
  8507. throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
  8508. }
  8509. var lib$es6$promise$promise$$default = lib$es6$promise$promise$$Promise;
  8510. /**
  8511. Promise objects represent the eventual result of an asynchronous operation. The
  8512. primary way of interacting with a promise is through its `then` method, which
  8513. registers callbacks to receive either a promise's eventual value or the reason
  8514. why the promise cannot be fulfilled.
  8515. Terminology
  8516. -----------
  8517. - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
  8518. - `thenable` is an object or function that defines a `then` method.
  8519. - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
  8520. - `exception` is a value that is thrown using the throw statement.
  8521. - `reason` is a value that indicates why a promise was rejected.
  8522. - `settled` the final resting state of a promise, fulfilled or rejected.
  8523. A promise can be in one of three states: pending, fulfilled, or rejected.
  8524. Promises that are fulfilled have a fulfillment value and are in the fulfilled
  8525. state. Promises that are rejected have a rejection reason and are in the
  8526. rejected state. A fulfillment value is never a thenable.
  8527. Promises can also be said to *resolve* a value. If this value is also a
  8528. promise, then the original promise's settled state will match the value's
  8529. settled state. So a promise that *resolves* a promise that rejects will
  8530. itself reject, and a promise that *resolves* a promise that fulfills will
  8531. itself fulfill.
  8532. Basic Usage:
  8533. ------------
  8534. ```js
  8535. var promise = new Promise(function(resolve, reject) {
  8536. // on success
  8537. resolve(value);
  8538. // on failure
  8539. reject(reason);
  8540. });
  8541. promise.then(function(value) {
  8542. // on fulfillment
  8543. }, function(reason) {
  8544. // on rejection
  8545. });
  8546. ```
  8547. Advanced Usage:
  8548. ---------------
  8549. Promises shine when abstracting away asynchronous interactions such as
  8550. `XMLHttpRequest`s.
  8551. ```js
  8552. function getJSON(url) {
  8553. return new Promise(function(resolve, reject){
  8554. var xhr = new XMLHttpRequest();
  8555. xhr.open('GET', url);
  8556. xhr.onreadystatechange = handler;
  8557. xhr.responseType = 'json';
  8558. xhr.setRequestHeader('Accept', 'application/json');
  8559. xhr.send();
  8560. function handler() {
  8561. if (this.readyState === this.DONE) {
  8562. if (this.status === 200) {
  8563. resolve(this.response);
  8564. } else {
  8565. reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
  8566. }
  8567. }
  8568. };
  8569. });
  8570. }
  8571. getJSON('/posts.json').then(function(json) {
  8572. // on fulfillment
  8573. }, function(reason) {
  8574. // on rejection
  8575. });
  8576. ```
  8577. Unlike callbacks, promises are great composable primitives.
  8578. ```js
  8579. Promise.all([
  8580. getJSON('/posts'),
  8581. getJSON('/comments')
  8582. ]).then(function(values){
  8583. values[0] // => postsJSON
  8584. values[1] // => commentsJSON
  8585. return values;
  8586. });
  8587. ```
  8588. @class Promise
  8589. @param {function} resolver
  8590. Useful for tooling.
  8591. @constructor
  8592. */
  8593. function lib$es6$promise$promise$$Promise(resolver) {
  8594. this._id = lib$es6$promise$promise$$counter++;
  8595. this._state = undefined;
  8596. this._result = undefined;
  8597. this._subscribers = [];
  8598. if (lib$es6$promise$$internal$$noop !== resolver) {
  8599. if (!lib$es6$promise$utils$$isFunction(resolver)) {
  8600. lib$es6$promise$promise$$needsResolver();
  8601. }
  8602. if (!(this instanceof lib$es6$promise$promise$$Promise)) {
  8603. lib$es6$promise$promise$$needsNew();
  8604. }
  8605. lib$es6$promise$$internal$$initializePromise(this, resolver);
  8606. }
  8607. }
  8608. lib$es6$promise$promise$$Promise.all = lib$es6$promise$promise$all$$default;
  8609. lib$es6$promise$promise$$Promise.race = lib$es6$promise$promise$race$$default;
  8610. lib$es6$promise$promise$$Promise.resolve = lib$es6$promise$promise$resolve$$default;
  8611. lib$es6$promise$promise$$Promise.reject = lib$es6$promise$promise$reject$$default;
  8612. lib$es6$promise$promise$$Promise._setScheduler = lib$es6$promise$asap$$setScheduler;
  8613. lib$es6$promise$promise$$Promise._setAsap = lib$es6$promise$asap$$setAsap;
  8614. lib$es6$promise$promise$$Promise._asap = lib$es6$promise$asap$$asap;
  8615. lib$es6$promise$promise$$Promise.prototype = {
  8616. constructor: lib$es6$promise$promise$$Promise,
  8617. /**
  8618. The primary way of interacting with a promise is through its `then` method,
  8619. which registers callbacks to receive either a promise's eventual value or the
  8620. reason why the promise cannot be fulfilled.
  8621. ```js
  8622. findUser().then(function(user){
  8623. // user is available
  8624. }, function(reason){
  8625. // user is unavailable, and you are given the reason why
  8626. });
  8627. ```
  8628. Chaining
  8629. --------
  8630. The return value of `then` is itself a promise. This second, 'downstream'
  8631. promise is resolved with the return value of the first promise's fulfillment
  8632. or rejection handler, or rejected if the handler throws an exception.
  8633. ```js
  8634. findUser().then(function (user) {
  8635. return user.name;
  8636. }, function (reason) {
  8637. return 'default name';
  8638. }).then(function (userName) {
  8639. // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
  8640. // will be `'default name'`
  8641. });
  8642. findUser().then(function (user) {
  8643. throw new Error('Found user, but still unhappy');
  8644. }, function (reason) {
  8645. throw new Error('`findUser` rejected and we're unhappy');
  8646. }).then(function (value) {
  8647. // never reached
  8648. }, function (reason) {
  8649. // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
  8650. // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
  8651. });
  8652. ```
  8653. If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
  8654. ```js
  8655. findUser().then(function (user) {
  8656. throw new PedagogicalException('Upstream error');
  8657. }).then(function (value) {
  8658. // never reached
  8659. }).then(function (value) {
  8660. // never reached
  8661. }, function (reason) {
  8662. // The `PedgagocialException` is propagated all the way down to here
  8663. });
  8664. ```
  8665. Assimilation
  8666. ------------
  8667. Sometimes the value you want to propagate to a downstream promise can only be
  8668. retrieved asynchronously. This can be achieved by returning a promise in the
  8669. fulfillment or rejection handler. The downstream promise will then be pending
  8670. until the returned promise is settled. This is called *assimilation*.
  8671. ```js
  8672. findUser().then(function (user) {
  8673. return findCommentsByAuthor(user);
  8674. }).then(function (comments) {
  8675. // The user's comments are now available
  8676. });
  8677. ```
  8678. If the assimliated promise rejects, then the downstream promise will also reject.
  8679. ```js
  8680. findUser().then(function (user) {
  8681. return findCommentsByAuthor(user);
  8682. }).then(function (comments) {
  8683. // If `findCommentsByAuthor` fulfills, we'll have the value here
  8684. }, function (reason) {
  8685. // If `findCommentsByAuthor` rejects, we'll have the reason here
  8686. });
  8687. ```
  8688. Simple Example
  8689. --------------
  8690. Synchronous Example
  8691. ```javascript
  8692. var result;
  8693. try {
  8694. result = findResult();
  8695. // success
  8696. } catch(reason) {
  8697. // failure
  8698. }
  8699. ```
  8700. Errback Example
  8701. ```js
  8702. findResult(function(result, err){
  8703. if (err) {
  8704. // failure
  8705. } else {
  8706. // success
  8707. }
  8708. });
  8709. ```
  8710. Promise Example;
  8711. ```javascript
  8712. findResult().then(function(result){
  8713. // success
  8714. }, function(reason){
  8715. // failure
  8716. });
  8717. ```
  8718. Advanced Example
  8719. --------------
  8720. Synchronous Example
  8721. ```javascript
  8722. var author, books;
  8723. try {
  8724. author = findAuthor();
  8725. books = findBooksByAuthor(author);
  8726. // success
  8727. } catch(reason) {
  8728. // failure
  8729. }
  8730. ```
  8731. Errback Example
  8732. ```js
  8733. function foundBooks(books) {
  8734. }
  8735. function failure(reason) {
  8736. }
  8737. findAuthor(function(author, err){
  8738. if (err) {
  8739. failure(err);
  8740. // failure
  8741. } else {
  8742. try {
  8743. findBoooksByAuthor(author, function(books, err) {
  8744. if (err) {
  8745. failure(err);
  8746. } else {
  8747. try {
  8748. foundBooks(books);
  8749. } catch(reason) {
  8750. failure(reason);
  8751. }
  8752. }
  8753. });
  8754. } catch(error) {
  8755. failure(err);
  8756. }
  8757. // success
  8758. }
  8759. });
  8760. ```
  8761. Promise Example;
  8762. ```javascript
  8763. findAuthor().
  8764. then(findBooksByAuthor).
  8765. then(function(books){
  8766. // found books
  8767. }).catch(function(reason){
  8768. // something went wrong
  8769. });
  8770. ```
  8771. @method then
  8772. @param {Function} onFulfilled
  8773. @param {Function} onRejected
  8774. Useful for tooling.
  8775. @return {Promise}
  8776. */
  8777. then: function(onFulfillment, onRejection) {
  8778. var parent = this;
  8779. var state = parent._state;
  8780. if (state === lib$es6$promise$$internal$$FULFILLED && !onFulfillment || state === lib$es6$promise$$internal$$REJECTED && !onRejection) {
  8781. return this;
  8782. }
  8783. var child = new this.constructor(lib$es6$promise$$internal$$noop);
  8784. var result = parent._result;
  8785. if (state) {
  8786. var callback = arguments[state - 1];
  8787. lib$es6$promise$asap$$asap(function(){
  8788. lib$es6$promise$$internal$$invokeCallback(state, child, callback, result);
  8789. });
  8790. } else {
  8791. lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection);
  8792. }
  8793. return child;
  8794. },
  8795. /**
  8796. `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
  8797. as the catch block of a try/catch statement.
  8798. ```js
  8799. function findAuthor(){
  8800. throw new Error('couldn't find that author');
  8801. }
  8802. // synchronous
  8803. try {
  8804. findAuthor();
  8805. } catch(reason) {
  8806. // something went wrong
  8807. }
  8808. // async with promises
  8809. findAuthor().catch(function(reason){
  8810. // something went wrong
  8811. });
  8812. ```
  8813. @method catch
  8814. @param {Function} onRejection
  8815. Useful for tooling.
  8816. @return {Promise}
  8817. */
  8818. 'catch': function(onRejection) {
  8819. return this.then(null, onRejection);
  8820. }
  8821. };
  8822. function lib$es6$promise$polyfill$$polyfill() {
  8823. var local;
  8824. if (typeof global !== 'undefined') {
  8825. local = global;
  8826. } else if (typeof self !== 'undefined') {
  8827. local = self;
  8828. } else {
  8829. try {
  8830. local = Function('return this')();
  8831. } catch (e) {
  8832. throw new Error('polyfill failed because global object is unavailable in this environment');
  8833. }
  8834. }
  8835. var P = local.Promise;
  8836. if (P && Object.prototype.toString.call(P.resolve()) === '[object Promise]' && !P.cast) {
  8837. return;
  8838. }
  8839. local.Promise = lib$es6$promise$promise$$default;
  8840. }
  8841. var lib$es6$promise$polyfill$$default = lib$es6$promise$polyfill$$polyfill;
  8842. var lib$es6$promise$umd$$ES6Promise = {
  8843. 'Promise': lib$es6$promise$promise$$default,
  8844. 'polyfill': lib$es6$promise$polyfill$$default
  8845. };
  8846. /* global define:true module:true window: true */
  8847. if (typeof define === 'function' && define['amd']) {
  8848. define(function() { return lib$es6$promise$umd$$ES6Promise; });
  8849. } else if (typeof module !== 'undefined' && module['exports']) {
  8850. module['exports'] = lib$es6$promise$umd$$ES6Promise;
  8851. } else if (typeof this !== 'undefined') {
  8852. this['ES6Promise'] = lib$es6$promise$umd$$ES6Promise;
  8853. }
  8854. lib$es6$promise$polyfill$$default();
  8855. }).call(this);
  8856. //# sourceMappingURL=es6-promise.js.map
  8857. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  8858. },{"_process":4}],52:[function(require,module,exports){
  8859. (function (global){
  8860. /*global describe, specify, it, assert */
  8861. if (typeof Object.getPrototypeOf !== "function") {
  8862. Object.getPrototypeOf = "".__proto__ === String.prototype
  8863. ? function (object) {
  8864. return object.__proto__;
  8865. }
  8866. : function (object) {
  8867. // May break if the constructor has been tampered with
  8868. return object.constructor.prototype;
  8869. };
  8870. }
  8871. function keysOf(object) {
  8872. var results = [];
  8873. for (var key in object) {
  8874. if (object.hasOwnProperty(key)) {
  8875. results.push(key);
  8876. }
  8877. }
  8878. return results;
  8879. }
  8880. var g = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this;
  8881. var Promise = g.adapter.Promise;
  8882. var assert = require('assert');
  8883. function objectEquals(obj1, obj2) {
  8884. for (var i in obj1) {
  8885. if (obj1.hasOwnProperty(i)) {
  8886. if (!obj2.hasOwnProperty(i)) return false;
  8887. if (obj1[i] != obj2[i]) return false;
  8888. }
  8889. }
  8890. for (var i in obj2) {
  8891. if (obj2.hasOwnProperty(i)) {
  8892. if (!obj1.hasOwnProperty(i)) return false;
  8893. if (obj1[i] != obj2[i]) return false;
  8894. }
  8895. }
  8896. return true;
  8897. }
  8898. describe("extensions", function() {
  8899. describe("Promise constructor", function() {
  8900. it('should exist and have length 1', function() {
  8901. assert(Promise);
  8902. assert.equal(Promise.length, 1);
  8903. });
  8904. it('should fulfill if `resolve` is called with a value', function(done) {
  8905. var promise = new Promise(function(resolve) { resolve('value'); });
  8906. promise.then(function(value) {
  8907. assert.equal(value, 'value');
  8908. done();
  8909. });
  8910. });
  8911. it('should reject if `reject` is called with a reason', function(done) {
  8912. var promise = new Promise(function(resolve, reject) { reject('reason'); });
  8913. promise.then(function() {
  8914. assert(false);
  8915. done();
  8916. }, function(reason) {
  8917. assert.equal(reason, 'reason');
  8918. done();
  8919. });
  8920. });
  8921. it('should be a constructor', function() {
  8922. var promise = new Promise(function() {});
  8923. assert.equal(Object.getPrototypeOf(promise), Promise.prototype, '[[Prototype]] equals Promise.prototype');
  8924. assert.equal(promise.constructor, Promise, 'constructor property of instances is set correctly');
  8925. assert.equal(Promise.prototype.constructor, Promise, 'constructor property of prototype is set correctly');
  8926. });
  8927. it('should NOT work without `new`', function() {
  8928. assert.throws(function(){
  8929. Promise(function(resolve) { resolve('value'); });
  8930. }, TypeError)
  8931. });
  8932. it('should throw a `TypeError` if not given a function', function() {
  8933. assert.throws(function () {
  8934. new Promise();
  8935. }, TypeError);
  8936. assert.throws(function () {
  8937. new Promise({});
  8938. }, TypeError);
  8939. assert.throws(function () {
  8940. new Promise('boo!');
  8941. }, TypeError);
  8942. });
  8943. it('should reject on resolver exception', function(done) {
  8944. new Promise(function() {
  8945. throw 'error';
  8946. }).then(null, function(e) {
  8947. assert.equal(e, 'error');
  8948. done();
  8949. });
  8950. });
  8951. it('should not resolve multiple times', function(done) {
  8952. var resolver, rejector, fulfilled = 0, rejected = 0;
  8953. var thenable = {
  8954. then: function(resolve, reject) {
  8955. resolver = resolve;
  8956. rejector = reject;
  8957. }
  8958. };
  8959. var promise = new Promise(function(resolve) {
  8960. resolve(1);
  8961. });
  8962. promise.then(function(value){
  8963. return thenable;
  8964. }).then(function(value){
  8965. fulfilled++;
  8966. }, function(reason) {
  8967. rejected++;
  8968. });
  8969. setTimeout(function() {
  8970. resolver(1);
  8971. resolver(1);
  8972. rejector(1);
  8973. rejector(1);
  8974. setTimeout(function() {
  8975. assert.equal(fulfilled, 1);
  8976. assert.equal(rejected, 0);
  8977. done();
  8978. }, 20);
  8979. }, 20);
  8980. });
  8981. describe('assimilation', function() {
  8982. it('should assimilate if `resolve` is called with a fulfilled promise', function(done) {
  8983. var originalPromise = new Promise(function(resolve) { resolve('original value'); });
  8984. var promise = new Promise(function(resolve) { resolve(originalPromise); });
  8985. promise.then(function(value) {
  8986. assert.equal(value, 'original value');
  8987. done();
  8988. });
  8989. });
  8990. it('should assimilate if `resolve` is called with a rejected promise', function(done) {
  8991. var originalPromise = new Promise(function(resolve, reject) { reject('original reason'); });
  8992. var promise = new Promise(function(resolve) { resolve(originalPromise); });
  8993. promise.then(function() {
  8994. assert(false);
  8995. done();
  8996. }, function(reason) {
  8997. assert.equal(reason, 'original reason');
  8998. done();
  8999. });
  9000. });
  9001. it('should assimilate if `resolve` is called with a fulfilled thenable', function(done) {
  9002. var originalThenable = {
  9003. then: function (onFulfilled) {
  9004. setTimeout(function() { onFulfilled('original value'); }, 0);
  9005. }
  9006. };
  9007. var promise = new Promise(function(resolve) { resolve(originalThenable); });
  9008. promise.then(function(value) {
  9009. assert.equal(value, 'original value');
  9010. done();
  9011. });
  9012. });
  9013. it('should assimilate if `resolve` is called with a rejected thenable', function(done) {
  9014. var originalThenable = {
  9015. then: function (onFulfilled, onRejected) {
  9016. setTimeout(function() { onRejected('original reason'); }, 0);
  9017. }
  9018. };
  9019. var promise = new Promise(function(resolve) { resolve(originalThenable); });
  9020. promise.then(function() {
  9021. assert(false);
  9022. done();
  9023. }, function(reason) {
  9024. assert.equal(reason, 'original reason');
  9025. done();
  9026. });
  9027. });
  9028. it('should assimilate two levels deep, for fulfillment of self fulfilling promises', function(done) {
  9029. var originalPromise, promise;
  9030. originalPromise = new Promise(function(resolve) {
  9031. setTimeout(function() {
  9032. resolve(originalPromise);
  9033. }, 0)
  9034. });
  9035. promise = new Promise(function(resolve) {
  9036. setTimeout(function() {
  9037. resolve(originalPromise);
  9038. }, 0);
  9039. });
  9040. promise.then(function(value) {
  9041. assert(false);
  9042. done();
  9043. })['catch'](function(reason) {
  9044. assert.equal(reason.message, "You cannot resolve a promise with itself");
  9045. assert(reason instanceof TypeError);
  9046. done();
  9047. });
  9048. });
  9049. it('should assimilate two levels deep, for fulfillment', function(done) {
  9050. var originalPromise = new Promise(function(resolve) { resolve('original value'); });
  9051. var nextPromise = new Promise(function(resolve) { resolve(originalPromise); });
  9052. var promise = new Promise(function(resolve) { resolve(nextPromise); });
  9053. promise.then(function(value) {
  9054. assert.equal(value, 'original value');
  9055. done();
  9056. });
  9057. });
  9058. it('should assimilate two levels deep, for rejection', function(done) {
  9059. var originalPromise = new Promise(function(resolve, reject) { reject('original reason'); });
  9060. var nextPromise = new Promise(function(resolve) { resolve(originalPromise); });
  9061. var promise = new Promise(function(resolve) { resolve(nextPromise); });
  9062. promise.then(function() {
  9063. assert(false);
  9064. done();
  9065. }, function(reason) {
  9066. assert.equal(reason, 'original reason');
  9067. done();
  9068. });
  9069. });
  9070. it('should assimilate three levels deep, mixing thenables and promises (fulfilled case)', function(done) {
  9071. var originalPromise = new Promise(function(resolve) { resolve('original value'); });
  9072. var intermediateThenable = {
  9073. then: function (onFulfilled) {
  9074. setTimeout(function() { onFulfilled(originalPromise); }, 0);
  9075. }
  9076. };
  9077. var promise = new Promise(function(resolve) { resolve(intermediateThenable); });
  9078. promise.then(function(value) {
  9079. assert.equal(value, 'original value');
  9080. done();
  9081. });
  9082. });
  9083. it('should assimilate three levels deep, mixing thenables and promises (rejected case)', function(done) {
  9084. var originalPromise = new Promise(function(resolve, reject) { reject('original reason'); });
  9085. var intermediateThenable = {
  9086. then: function (onFulfilled) {
  9087. setTimeout(function() { onFulfilled(originalPromise); }, 0);
  9088. }
  9089. };
  9090. var promise = new Promise(function(resolve) { resolve(intermediateThenable); });
  9091. promise.then(function() {
  9092. assert(false);
  9093. done();
  9094. }, function(reason) {
  9095. assert.equal(reason, 'original reason');
  9096. done();
  9097. });
  9098. });
  9099. });
  9100. });
  9101. describe("Promise.all", function() {
  9102. testAll(function(){
  9103. return Promise.all.apply(Promise, arguments);
  9104. });
  9105. });
  9106. function testAll(all) {
  9107. it('should exist', function() {
  9108. assert(all);
  9109. });
  9110. it('throws when not passed an array', function(done) {
  9111. var nothing = assertRejection(all());
  9112. var string = assertRejection(all(''));
  9113. var object = assertRejection(all({}));
  9114. Promise.all([
  9115. nothing,
  9116. string,
  9117. object
  9118. ]).then(function(){ done(); });
  9119. });
  9120. specify('fulfilled only after all of the other promises are fulfilled', function(done) {
  9121. var firstResolved, secondResolved, firstResolver, secondResolver;
  9122. var first = new Promise(function(resolve) {
  9123. firstResolver = resolve;
  9124. });
  9125. first.then(function() {
  9126. firstResolved = true;
  9127. });
  9128. var second = new Promise(function(resolve) {
  9129. secondResolver = resolve;
  9130. });
  9131. second.then(function() {
  9132. secondResolved = true;
  9133. });
  9134. setTimeout(function() {
  9135. firstResolver(true);
  9136. }, 0);
  9137. setTimeout(function() {
  9138. secondResolver(true);
  9139. }, 0);
  9140. all([first, second]).then(function() {
  9141. assert(firstResolved);
  9142. assert(secondResolved);
  9143. done();
  9144. });
  9145. });
  9146. specify('rejected as soon as a promise is rejected', function(done) {
  9147. var firstResolver, secondResolver;
  9148. var first = new Promise(function(resolve, reject) {
  9149. firstResolver = { resolve: resolve, reject: reject };
  9150. });
  9151. var second = new Promise(function(resolve, reject) {
  9152. secondResolver = { resolve: resolve, reject: reject };
  9153. });
  9154. setTimeout(function() {
  9155. firstResolver.reject({});
  9156. }, 0);
  9157. var firstWasRejected, secondCompleted;
  9158. first['catch'](function(){
  9159. firstWasRejected = true;
  9160. });
  9161. second.then(function(){
  9162. secondCompleted = true;
  9163. }, function() {
  9164. secondCompleted = true;
  9165. });
  9166. all([first, second]).then(function() {
  9167. assert(false);
  9168. }, function() {
  9169. assert(firstWasRejected);
  9170. assert(!secondCompleted);
  9171. done();
  9172. });
  9173. });
  9174. specify('passes the resolved values of each promise to the callback in the correct order', function(done) {
  9175. var firstResolver, secondResolver, thirdResolver;
  9176. var first = new Promise(function(resolve, reject) {
  9177. firstResolver = { resolve: resolve, reject: reject };
  9178. });
  9179. var second = new Promise(function(resolve, reject) {
  9180. secondResolver = { resolve: resolve, reject: reject };
  9181. });
  9182. var third = new Promise(function(resolve, reject) {
  9183. thirdResolver = { resolve: resolve, reject: reject };
  9184. });
  9185. thirdResolver.resolve(3);
  9186. firstResolver.resolve(1);
  9187. secondResolver.resolve(2);
  9188. all([first, second, third]).then(function(results) {
  9189. assert(results.length === 3);
  9190. assert(results[0] === 1);
  9191. assert(results[1] === 2);
  9192. assert(results[2] === 3);
  9193. done();
  9194. });
  9195. });
  9196. specify('resolves an empty array passed to all()', function(done) {
  9197. all([]).then(function(results) {
  9198. assert(results.length === 0);
  9199. done();
  9200. });
  9201. });
  9202. specify('works with null', function(done) {
  9203. all([null]).then(function(results) {
  9204. assert.equal(results[0], null);
  9205. done();
  9206. });
  9207. });
  9208. specify('works with a mix of promises and thenables and non-promises', function(done) {
  9209. var promise = new Promise(function(resolve) { resolve(1); });
  9210. var syncThenable = { then: function (onFulfilled) { onFulfilled(2); } };
  9211. var asyncThenable = { then: function (onFulfilled) { setTimeout(function() { onFulfilled(3); }, 0); } };
  9212. var nonPromise = 4;
  9213. all([promise, syncThenable, asyncThenable, nonPromise]).then(function(results) {
  9214. assert(objectEquals(results, [1, 2, 3, 4]));
  9215. done();
  9216. })['catch'](done);
  9217. });
  9218. }
  9219. describe("reject", function(){
  9220. specify("it should exist", function(){
  9221. assert(Promise.reject);
  9222. });
  9223. describe('it rejects', function(){
  9224. var reason = 'the reason',
  9225. promise = Promise.reject(reason);
  9226. promise.then(function(){
  9227. assert(false, 'should not fulfill');
  9228. }, function(actualReason){
  9229. assert.equal(reason, actualReason);
  9230. });
  9231. });
  9232. });
  9233. function assertRejection(promise) {
  9234. return promise.then(function(){
  9235. assert(false, 'expected rejection, but got fulfillment');
  9236. }, function(reason){
  9237. assert(reason instanceof Error);
  9238. });
  9239. }
  9240. describe('race', function() {
  9241. it("should exist", function() {
  9242. assert(Promise.race);
  9243. });
  9244. it("throws when not passed an array", function(done) {
  9245. var nothing = assertRejection(Promise.race());
  9246. var string = assertRejection(Promise.race(''));
  9247. var object = assertRejection(Promise.race({}));
  9248. Promise.all([
  9249. nothing,
  9250. string,
  9251. object
  9252. ]).then(function(){ done(); });
  9253. });
  9254. specify('fulfilled after one of the other promises are fulfilled', function(done) {
  9255. var firstResolved, secondResolved, firstResolver, secondResolver;
  9256. var first = new Promise(function(resolve) {
  9257. firstResolver = resolve;
  9258. });
  9259. first.then(function() {
  9260. firstResolved = true;
  9261. });
  9262. var second = new Promise(function(resolve) {
  9263. secondResolver = resolve;
  9264. });
  9265. second.then(function() {
  9266. secondResolved = true;
  9267. });
  9268. setTimeout(function() {
  9269. firstResolver(true);
  9270. }, 100);
  9271. setTimeout(function() {
  9272. secondResolver(true);
  9273. }, 0);
  9274. Promise.race([first, second]).then(function() {
  9275. assert(secondResolved);
  9276. assert.equal(firstResolved, undefined);
  9277. done();
  9278. });
  9279. });
  9280. specify('the race begins on nextTurn and prioritized by array entry', function(done) {
  9281. var firstResolver, secondResolver, nonPromise = 5;
  9282. var first = new Promise(function(resolve, reject) {
  9283. resolve(true);
  9284. });
  9285. var second = new Promise(function(resolve, reject) {
  9286. resolve(false);
  9287. });
  9288. Promise.race([first, second, nonPromise]).then(function(value) {
  9289. assert.equal(value, true);
  9290. done();
  9291. });
  9292. });
  9293. specify('rejected as soon as a promise is rejected', function(done) {
  9294. var firstResolver, secondResolver;
  9295. var first = new Promise(function(resolve, reject) {
  9296. firstResolver = { resolve: resolve, reject: reject };
  9297. });
  9298. var second = new Promise(function(resolve, reject) {
  9299. secondResolver = { resolve: resolve, reject: reject };
  9300. });
  9301. setTimeout(function() {
  9302. firstResolver.reject({});
  9303. }, 0);
  9304. var firstWasRejected, secondCompleted;
  9305. first['catch'](function(){
  9306. firstWasRejected = true;
  9307. });
  9308. second.then(function(){
  9309. secondCompleted = true;
  9310. }, function() {
  9311. secondCompleted = true;
  9312. });
  9313. Promise.race([first, second]).then(function() {
  9314. assert(false);
  9315. }, function() {
  9316. assert(firstWasRejected);
  9317. assert(!secondCompleted);
  9318. done();
  9319. });
  9320. });
  9321. specify('resolves an empty array to forever pending Promise', function(done) {
  9322. var foreverPendingPromise = Promise.race([]),
  9323. wasSettled = false;
  9324. foreverPendingPromise.then(function() {
  9325. wasSettled = true;
  9326. }, function() {
  9327. wasSettled = true;
  9328. });
  9329. setTimeout(function() {
  9330. assert(!wasSettled);
  9331. done();
  9332. }, 100);
  9333. });
  9334. specify('works with a mix of promises and thenables', function(done) {
  9335. var promise = new Promise(function(resolve) { setTimeout(function() { resolve(1); }, 10); }),
  9336. syncThenable = { then: function (onFulfilled) { onFulfilled(2); } };
  9337. Promise.race([promise, syncThenable]).then(function(result) {
  9338. assert(result, 2);
  9339. done();
  9340. });
  9341. });
  9342. specify('works with a mix of thenables and non-promises', function (done) {
  9343. var asyncThenable = { then: function (onFulfilled) { setTimeout(function() { onFulfilled(3); }, 0); } },
  9344. nonPromise = 4;
  9345. Promise.race([asyncThenable, nonPromise]).then(function(result) {
  9346. assert(result, 4);
  9347. done();
  9348. });
  9349. });
  9350. });
  9351. describe("resolve", function(){
  9352. specify("it should exist", function(){
  9353. assert(Promise.resolve);
  9354. });
  9355. describe("1. If x is a promise, adopt its state ", function(){
  9356. specify("1.1 If x is pending, promise must remain pending until x is fulfilled or rejected.", function(done){
  9357. var expectedValue, resolver, thenable, wrapped;
  9358. expectedValue = 'the value';
  9359. thenable = {
  9360. then: function(resolve, reject){
  9361. resolver = resolve;
  9362. }
  9363. };
  9364. wrapped = Promise.resolve(thenable);
  9365. wrapped.then(function(value){
  9366. assert(value === expectedValue);
  9367. done();
  9368. });
  9369. setTimeout(function(){
  9370. resolver(expectedValue);
  9371. }, 10);
  9372. });
  9373. specify("1.2 If/when x is fulfilled, fulfill promise with the same value.", function(done){
  9374. var expectedValue, thenable, wrapped;
  9375. expectedValue = 'the value';
  9376. thenable = {
  9377. then: function(resolve, reject){
  9378. resolve(expectedValue);
  9379. }
  9380. };
  9381. wrapped = Promise.resolve(thenable);
  9382. wrapped.then(function(value){
  9383. assert(value === expectedValue);
  9384. done();
  9385. })
  9386. });
  9387. specify("1.3 If/when x is rejected, reject promise with the same reason.", function(done){
  9388. var expectedError, thenable, wrapped;
  9389. expectedError = new Error();
  9390. thenable = {
  9391. then: function(resolve, reject){
  9392. reject(expectedError);
  9393. }
  9394. };
  9395. wrapped = Promise.resolve(thenable);
  9396. wrapped.then(null, function(error){
  9397. assert(error === expectedError);
  9398. done();
  9399. });
  9400. });
  9401. });
  9402. describe("2. Otherwise, if x is an object or function,", function(){
  9403. specify("2.1 Let then x.then", function(done){
  9404. var accessCount, resolver, wrapped, thenable;
  9405. accessCount = 0;
  9406. thenable = { };
  9407. // we likely don't need to test this, if the browser doesn't support it
  9408. if (typeof Object.defineProperty !== "function") { done(); return; }
  9409. Object.defineProperty(thenable, 'then', {
  9410. get: function(){
  9411. accessCount++;
  9412. if (accessCount > 1) {
  9413. throw new Error();
  9414. }
  9415. return function(){ };
  9416. }
  9417. });
  9418. assert(accessCount === 0);
  9419. wrapped = Promise.resolve(thenable);
  9420. assert(accessCount === 1);
  9421. done();
  9422. });
  9423. specify("2.2 If retrieving the property x.then results in a thrown exception e, reject promise with e as the reason.", function(done){
  9424. var wrapped, thenable, expectedError;
  9425. expectedError = new Error();
  9426. thenable = { };
  9427. // we likely don't need to test this, if the browser doesn't support it
  9428. if (typeof Object.defineProperty !== "function") { done(); return; }
  9429. Object.defineProperty(thenable, 'then', {
  9430. get: function(){
  9431. throw expectedError;
  9432. }
  9433. });
  9434. wrapped = Promise.resolve(thenable);
  9435. wrapped.then(null, function(error){
  9436. assert(error === expectedError, 'incorrect exception was thrown');
  9437. done();
  9438. });
  9439. });
  9440. describe('2.3. If then is a function, call it with x as this, first argument resolvePromise, and second argument rejectPromise, where', function(){
  9441. specify('2.3.1 If/when resolvePromise is called with a value y, run Resolve(promise, y)', function(done){
  9442. var expectedSuccess, resolver, rejector, thenable, wrapped, calledThis;
  9443. thenable = {
  9444. then: function(resolve, reject){
  9445. calledThis = this;
  9446. resolver = resolve;
  9447. rejector = reject;
  9448. }
  9449. };
  9450. expectedSuccess = 'success';
  9451. wrapped = Promise.resolve(thenable);
  9452. wrapped.then(function(success){
  9453. assert(calledThis === thenable, 'this must be the thenable');
  9454. assert(success === expectedSuccess, 'rejected promise with x');
  9455. done();
  9456. });
  9457. setTimeout(function() {
  9458. resolver(expectedSuccess);
  9459. }, 20);
  9460. });
  9461. specify('2.3.2 If/when rejectPromise is called with a reason r, reject promise with r.', function(done){
  9462. var expectedError, resolver, rejector, thenable, wrapped, calledThis;
  9463. thenable = {
  9464. then: function(resolve, reject){
  9465. calledThis = this;
  9466. resolver = resolve;
  9467. rejector = reject;
  9468. }
  9469. };
  9470. expectedError = new Error();
  9471. wrapped = Promise.resolve(thenable);
  9472. wrapped.then(null, function(error){
  9473. assert(error === expectedError, 'rejected promise with x');
  9474. done();
  9475. });
  9476. setTimeout(function() {
  9477. rejector(expectedError);
  9478. }, 20);
  9479. });
  9480. specify("2.3.3 If both resolvePromise and rejectPromise are called, or multiple calls to the same argument are made, the first call takes precedence, and any further calls are ignored", function(done){
  9481. var expectedError, expectedSuccess, resolver, rejector, thenable, wrapped, calledThis,
  9482. calledRejected, calledResolved;
  9483. calledRejected = 0;
  9484. calledResolved = 0;
  9485. thenable = {
  9486. then: function(resolve, reject){
  9487. calledThis = this;
  9488. resolver = resolve;
  9489. rejector = reject;
  9490. }
  9491. };
  9492. expectedError = new Error();
  9493. wrapped = Promise.resolve(thenable);
  9494. wrapped.then(function(){
  9495. calledResolved++;
  9496. }, function(error){
  9497. calledRejected++;
  9498. assert(calledResolved === 0, 'never resolved');
  9499. assert(calledRejected === 1, 'rejected only once');
  9500. assert(error === expectedError, 'rejected promise with x');
  9501. });
  9502. setTimeout(function() {
  9503. rejector(expectedError);
  9504. rejector(expectedError);
  9505. rejector('foo');
  9506. resolver('bar');
  9507. resolver('baz');
  9508. }, 20);
  9509. setTimeout(function(){
  9510. assert(calledRejected === 1, 'only rejected once');
  9511. assert(calledResolved === 0, 'never resolved');
  9512. done();
  9513. }, 50);
  9514. });
  9515. describe("2.3.4 If calling then throws an exception e", function(){
  9516. specify("2.3.4.1 If resolvePromise or rejectPromise have been called, ignore it.", function(done){
  9517. var expectedSuccess, resolver, rejector, thenable, wrapped, calledThis,
  9518. calledRejected, calledResolved;
  9519. expectedSuccess = 'success';
  9520. thenable = {
  9521. then: function(resolve, reject){
  9522. resolve(expectedSuccess);
  9523. throw expectedError;
  9524. }
  9525. };
  9526. wrapped = Promise.resolve(thenable);
  9527. wrapped.then(function(success){
  9528. assert(success === expectedSuccess, 'resolved not errored');
  9529. done();
  9530. });
  9531. });
  9532. specify("2.3.4.2 Otherwise, reject promise with e as the reason.", function(done) {
  9533. var expectedError, resolver, rejector, thenable, wrapped, calledThis, callCount;
  9534. expectedError = new Error();
  9535. callCount = 0;
  9536. thenable = { then: function() { throw expectedError; } };
  9537. wrapped = Promise.resolve(thenable);
  9538. wrapped.then(null, function(error){
  9539. callCount++;
  9540. assert(expectedError === error, 'expected the correct error to be rejected');
  9541. done();
  9542. });
  9543. assert(callCount === 0, 'expected async, was sync');
  9544. });
  9545. });
  9546. });
  9547. specify("2.4 If then is not a function, fulfill promise with x", function(done){
  9548. var expectedError, resolver, rejector, thenable, wrapped, calledThis, callCount;
  9549. thenable = { then: 3 };
  9550. callCount = 0;
  9551. wrapped = Promise.resolve(thenable);
  9552. wrapped.then(function(success){
  9553. callCount++;
  9554. assert(thenable === success, 'fulfilled promise with x');
  9555. done();
  9556. });
  9557. assert(callCount === 0, 'expected async, was sync');
  9558. });
  9559. });
  9560. describe("3. If x is not an object or function, ", function(){
  9561. specify("fulfill promise with x.", function(done){
  9562. var thenable, callCount, wrapped;
  9563. thenable = null;
  9564. callCount = 0;
  9565. wrapped = Promise.resolve(thenable);
  9566. wrapped.then(function(success){
  9567. callCount++;
  9568. assert(success === thenable, 'fulfilled promise with x');
  9569. done();
  9570. }, function(a){
  9571. assert(false, 'should not also reject');
  9572. });
  9573. assert(callCount === 0, 'expected async, was sync');
  9574. });
  9575. });
  9576. });
  9577. if (typeof Worker !== 'undefined') {
  9578. describe('web worker', function () {
  9579. it('should work', function (done) {
  9580. this.timeout(2000);
  9581. var worker = new Worker('worker.js');
  9582. worker.addEventListener('error', function(reason) {
  9583. done(new Error("Test failed:" + reason));
  9584. });
  9585. worker.addEventListener('message', function (e) {
  9586. worker.terminate();
  9587. assert.equal(e.data, 'pong');
  9588. done();
  9589. });
  9590. worker.postMessage('ping');
  9591. });
  9592. });
  9593. }
  9594. });
  9595. // thanks to @wizardwerdna for the test case -> https://github.com/tildeio/rsvp.js/issues/66
  9596. // Only run these tests in node (phantomjs cannot handle them)
  9597. if (typeof module !== 'undefined' && module.exports) {
  9598. describe("using reduce to sum integers using promises", function(){
  9599. it("should build the promise pipeline without error", function(){
  9600. var array, iters, pZero, i;
  9601. array = [];
  9602. iters = 1000;
  9603. for (i=1; i<=iters; i++) {
  9604. array.push(i);
  9605. }
  9606. pZero = Promise.resolve(0);
  9607. array.reduce(function(promise, nextVal) {
  9608. return promise.then(function(currentVal) {
  9609. return Promise.resolve(currentVal + nextVal);
  9610. });
  9611. }, pZero);
  9612. });
  9613. it("should get correct answer without blowing the nextTick stack", function(done){
  9614. var pZero, array, iters, result, i;
  9615. pZero = Promise.resolve(0);
  9616. array = [];
  9617. iters = 1000;
  9618. for (i=1; i<=iters; i++) {
  9619. array.push(i);
  9620. }
  9621. result = array.reduce(function(promise, nextVal) {
  9622. return promise.then(function(currentVal) {
  9623. return Promise.resolve(currentVal + nextVal);
  9624. });
  9625. }, pZero);
  9626. result.then(function(value){
  9627. assert.equal(value, (iters*(iters+1)/2));
  9628. done();
  9629. });
  9630. });
  9631. });
  9632. }
  9633. // Kudos to @Octane at https://github.com/getify/native-promise-only/issues/5 for this, and @getify for pinging me.
  9634. describe("Thenables should not be able to run code during assimilation", function () {
  9635. specify("resolving to a thenable", function () {
  9636. var thenCalled = false;
  9637. var thenable = {
  9638. then: function () {
  9639. thenCalled = true;
  9640. }
  9641. };
  9642. Promise.resolve(thenable);
  9643. assert.strictEqual(thenCalled, false);
  9644. });
  9645. specify("resolving to an evil promise", function () {
  9646. var thenCalled = false;
  9647. var evilPromise = Promise.resolve();
  9648. evilPromise.then = function () {
  9649. thenCalled = true;
  9650. };
  9651. Promise.resolve(evilPromise);
  9652. assert.strictEqual(thenCalled, false);
  9653. });
  9654. });
  9655. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  9656. },{"assert":2}],53:[function(require,module,exports){
  9657. (function (global){
  9658. /*global describe, it, assert */
  9659. var g = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this;
  9660. var Promise = g.adapter.Promise;
  9661. var assert = require('assert');
  9662. describe('scheduler', function() {
  9663. afterEach(function() {
  9664. // make sure the es6-promise scheduler is restored after each test
  9665. Promise._setScheduler(void 0);
  9666. });
  9667. describe('Promise._setScheduler', function() {
  9668. it('should allow overriding the default scheduling mechanism', function(done) {
  9669. // Wrapped in a setTimeout() to make sure that the microtask queue is empty
  9670. // Otherwise we would have len > 2 and the overriden scheduling mechanism would not
  9671. // be used.
  9672. // This is required because the test library uses Promise.
  9673. setTimeout(function() {
  9674. var microtasks = [];
  9675. var resolvedWith = null;
  9676. Promise._setScheduler(function(fn) {
  9677. microtasks.push(fn);
  9678. });
  9679. Promise.resolve('value').then(function(v) {
  9680. resolvedWith = v;
  9681. });
  9682. assert.equal(resolvedWith, null);
  9683. assert.equal(microtasks.length, 1);
  9684. while (microtasks.length) {
  9685. microtasks.shift()();
  9686. }
  9687. assert.equal(resolvedWith, 'value');
  9688. // restore the original scheduler
  9689. Promise._setScheduler(void 0);
  9690. done();
  9691. });
  9692. });
  9693. });
  9694. describe('Promise._asap', function() {
  9695. it('should allow enqueuing microtasks', function(done) {
  9696. Promise._asap(function(arg) {
  9697. assert.equal(arg, 'arg');
  9698. done();
  9699. }, 'arg');
  9700. });
  9701. });
  9702. describe('Promise._setAsap', function() {
  9703. it('should allow overriding asap', function(done) {
  9704. var called = false;
  9705. Promise._setAsap(function(fn, arg) {
  9706. called = true;
  9707. // call the original implementation
  9708. Promise._asap(fn, arg);
  9709. // restore the original implementation
  9710. Promise._setAsap(Promise._asap);
  9711. });
  9712. Promise.resolve('value').then(function(v) {
  9713. resolvedWith = v;
  9714. assert.equal(v, 'value');
  9715. assert.equal(called, true);
  9716. done();
  9717. });
  9718. });
  9719. });
  9720. });
  9721. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  9722. },{"assert":2}],54:[function(require,module,exports){
  9723. (function (global){
  9724. var assert = require('assert');
  9725. var g = typeof window !== 'undefined' ?
  9726. window : typeof global !== 'undefined' ? global : this;
  9727. var Promise = g.ES6Promise || require('./es6-promise').Promise;
  9728. function defer() {
  9729. var deferred = {};
  9730. deferred.promise = new Promise(function(resolve, reject) {
  9731. deferred.resolve = resolve;
  9732. deferred.reject = reject;
  9733. });
  9734. return deferred;
  9735. }
  9736. var resolve = Promise.resolve;
  9737. var reject = Promise.reject;
  9738. module.exports = g.adapter = {
  9739. resolved: function(a) { return Promise.resolve(a); },
  9740. rejected: function(a) { return Promise.reject(a); },
  9741. deferred: defer,
  9742. Promise: Promise
  9743. };
  9744. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  9745. },{"./es6-promise":51,"assert":2}]},{},[1]);