browser-test.js 167 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028
  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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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. /**
  3. * The buffer module from node.js, for the browser.
  4. *
  5. * Author: Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  6. * License: MIT
  7. *
  8. * `npm install buffer`
  9. */
  10. var base64 = require('base64-js')
  11. var ieee754 = require('ieee754')
  12. exports.Buffer = Buffer
  13. exports.SlowBuffer = Buffer
  14. exports.INSPECT_MAX_BYTES = 50
  15. Buffer.poolSize = 8192
  16. /**
  17. * If `Buffer._useTypedArrays`:
  18. * === true Use Uint8Array implementation (fastest)
  19. * === false Use Object implementation (compatible down to IE6)
  20. */
  21. Buffer._useTypedArrays = (function () {
  22. // Detect if browser supports Typed Arrays. Supported browsers are IE 10+,
  23. // Firefox 4+, Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+.
  24. if (typeof Uint8Array === 'undefined' || typeof ArrayBuffer === 'undefined')
  25. return false
  26. // Does the browser support adding properties to `Uint8Array` instances? If
  27. // not, then that's the same as no `Uint8Array` support. We need to be able to
  28. // add all the node Buffer API methods.
  29. // Relevant Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=695438
  30. try {
  31. var arr = new Uint8Array(0)
  32. arr.foo = function () { return 42 }
  33. return 42 === arr.foo() &&
  34. typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray`
  35. } catch (e) {
  36. return false
  37. }
  38. })()
  39. /**
  40. * Class: Buffer
  41. * =============
  42. *
  43. * The Buffer constructor returns instances of `Uint8Array` that are augmented
  44. * with function properties for all the node `Buffer` API functions. We use
  45. * `Uint8Array` so that square bracket notation works as expected -- it returns
  46. * a single octet.
  47. *
  48. * By augmenting the instances, we can avoid modifying the `Uint8Array`
  49. * prototype.
  50. */
  51. function Buffer (subject, encoding, noZero) {
  52. if (!(this instanceof Buffer))
  53. return new Buffer(subject, encoding, noZero)
  54. var type = typeof subject
  55. // Workaround: node's base64 implementation allows for non-padded strings
  56. // while base64-js does not.
  57. if (encoding === 'base64' && type === 'string') {
  58. subject = stringtrim(subject)
  59. while (subject.length % 4 !== 0) {
  60. subject = subject + '='
  61. }
  62. }
  63. // Find the length
  64. var length
  65. if (type === 'number')
  66. length = coerce(subject)
  67. else if (type === 'string')
  68. length = Buffer.byteLength(subject, encoding)
  69. else if (type === 'object')
  70. length = coerce(subject.length) // Assume object is an array
  71. else
  72. throw new Error('First argument needs to be a number, array or string.')
  73. var buf
  74. if (Buffer._useTypedArrays) {
  75. // Preferred: Return an augmented `Uint8Array` instance for best performance
  76. buf = augment(new Uint8Array(length))
  77. } else {
  78. // Fallback: Return THIS instance of Buffer (created by `new`)
  79. buf = this
  80. buf.length = length
  81. buf._isBuffer = true
  82. }
  83. var i
  84. if (Buffer._useTypedArrays && typeof Uint8Array === 'function' &&
  85. subject instanceof Uint8Array) {
  86. // Speed optimization -- use set if we're copying from a Uint8Array
  87. buf._set(subject)
  88. } else if (isArrayish(subject)) {
  89. // Treat array-ish objects as a byte array
  90. for (i = 0; i < length; i++) {
  91. if (Buffer.isBuffer(subject))
  92. buf[i] = subject.readUInt8(i)
  93. else
  94. buf[i] = subject[i]
  95. }
  96. } else if (type === 'string') {
  97. buf.write(subject, 0, encoding)
  98. } else if (type === 'number' && !Buffer._useTypedArrays && !noZero) {
  99. for (i = 0; i < length; i++) {
  100. buf[i] = 0
  101. }
  102. }
  103. return buf
  104. }
  105. // STATIC METHODS
  106. // ==============
  107. Buffer.isEncoding = function (encoding) {
  108. switch (String(encoding).toLowerCase()) {
  109. case 'hex':
  110. case 'utf8':
  111. case 'utf-8':
  112. case 'ascii':
  113. case 'binary':
  114. case 'base64':
  115. case 'raw':
  116. case 'ucs2':
  117. case 'ucs-2':
  118. case 'utf16le':
  119. case 'utf-16le':
  120. return true
  121. default:
  122. return false
  123. }
  124. }
  125. Buffer.isBuffer = function (b) {
  126. return !!(b !== null && b !== undefined && b._isBuffer)
  127. }
  128. Buffer.byteLength = function (str, encoding) {
  129. var ret
  130. str = str + ''
  131. switch (encoding || 'utf8') {
  132. case 'hex':
  133. ret = str.length / 2
  134. break
  135. case 'utf8':
  136. case 'utf-8':
  137. ret = utf8ToBytes(str).length
  138. break
  139. case 'ascii':
  140. case 'binary':
  141. case 'raw':
  142. ret = str.length
  143. break
  144. case 'base64':
  145. ret = base64ToBytes(str).length
  146. break
  147. case 'ucs2':
  148. case 'ucs-2':
  149. case 'utf16le':
  150. case 'utf-16le':
  151. ret = str.length * 2
  152. break
  153. default:
  154. throw new Error('Unknown encoding')
  155. }
  156. return ret
  157. }
  158. Buffer.concat = function (list, totalLength) {
  159. assert(isArray(list), 'Usage: Buffer.concat(list, [totalLength])\n' +
  160. 'list should be an Array.')
  161. if (list.length === 0) {
  162. return new Buffer(0)
  163. } else if (list.length === 1) {
  164. return list[0]
  165. }
  166. var i
  167. if (typeof totalLength !== 'number') {
  168. totalLength = 0
  169. for (i = 0; i < list.length; i++) {
  170. totalLength += list[i].length
  171. }
  172. }
  173. var buf = new Buffer(totalLength)
  174. var pos = 0
  175. for (i = 0; i < list.length; i++) {
  176. var item = list[i]
  177. item.copy(buf, pos)
  178. pos += item.length
  179. }
  180. return buf
  181. }
  182. // BUFFER INSTANCE METHODS
  183. // =======================
  184. function _hexWrite (buf, string, offset, length) {
  185. offset = Number(offset) || 0
  186. var remaining = buf.length - offset
  187. if (!length) {
  188. length = remaining
  189. } else {
  190. length = Number(length)
  191. if (length > remaining) {
  192. length = remaining
  193. }
  194. }
  195. // must be an even number of digits
  196. var strLen = string.length
  197. assert(strLen % 2 === 0, 'Invalid hex string')
  198. if (length > strLen / 2) {
  199. length = strLen / 2
  200. }
  201. for (var i = 0; i < length; i++) {
  202. var byte = parseInt(string.substr(i * 2, 2), 16)
  203. assert(!isNaN(byte), 'Invalid hex string')
  204. buf[offset + i] = byte
  205. }
  206. Buffer._charsWritten = i * 2
  207. return i
  208. }
  209. function _utf8Write (buf, string, offset, length) {
  210. var charsWritten = Buffer._charsWritten =
  211. blitBuffer(utf8ToBytes(string), buf, offset, length)
  212. return charsWritten
  213. }
  214. function _asciiWrite (buf, string, offset, length) {
  215. var charsWritten = Buffer._charsWritten =
  216. blitBuffer(asciiToBytes(string), buf, offset, length)
  217. return charsWritten
  218. }
  219. function _binaryWrite (buf, string, offset, length) {
  220. return _asciiWrite(buf, string, offset, length)
  221. }
  222. function _base64Write (buf, string, offset, length) {
  223. var charsWritten = Buffer._charsWritten =
  224. blitBuffer(base64ToBytes(string), buf, offset, length)
  225. return charsWritten
  226. }
  227. function _utf16leWrite (buf, string, offset, length) {
  228. var charsWritten = Buffer._charsWritten =
  229. blitBuffer(utf16leToBytes(string), buf, offset, length)
  230. return charsWritten
  231. }
  232. Buffer.prototype.write = function (string, offset, length, encoding) {
  233. // Support both (string, offset, length, encoding)
  234. // and the legacy (string, encoding, offset, length)
  235. if (isFinite(offset)) {
  236. if (!isFinite(length)) {
  237. encoding = length
  238. length = undefined
  239. }
  240. } else { // legacy
  241. var swap = encoding
  242. encoding = offset
  243. offset = length
  244. length = swap
  245. }
  246. offset = Number(offset) || 0
  247. var remaining = this.length - offset
  248. if (!length) {
  249. length = remaining
  250. } else {
  251. length = Number(length)
  252. if (length > remaining) {
  253. length = remaining
  254. }
  255. }
  256. encoding = String(encoding || 'utf8').toLowerCase()
  257. var ret
  258. switch (encoding) {
  259. case 'hex':
  260. ret = _hexWrite(this, string, offset, length)
  261. break
  262. case 'utf8':
  263. case 'utf-8':
  264. ret = _utf8Write(this, string, offset, length)
  265. break
  266. case 'ascii':
  267. ret = _asciiWrite(this, string, offset, length)
  268. break
  269. case 'binary':
  270. ret = _binaryWrite(this, string, offset, length)
  271. break
  272. case 'base64':
  273. ret = _base64Write(this, string, offset, length)
  274. break
  275. case 'ucs2':
  276. case 'ucs-2':
  277. case 'utf16le':
  278. case 'utf-16le':
  279. ret = _utf16leWrite(this, string, offset, length)
  280. break
  281. default:
  282. throw new Error('Unknown encoding')
  283. }
  284. return ret
  285. }
  286. Buffer.prototype.toString = function (encoding, start, end) {
  287. var self = this
  288. encoding = String(encoding || 'utf8').toLowerCase()
  289. start = Number(start) || 0
  290. end = (end !== undefined)
  291. ? Number(end)
  292. : end = self.length
  293. // Fastpath empty strings
  294. if (end === start)
  295. return ''
  296. var ret
  297. switch (encoding) {
  298. case 'hex':
  299. ret = _hexSlice(self, start, end)
  300. break
  301. case 'utf8':
  302. case 'utf-8':
  303. ret = _utf8Slice(self, start, end)
  304. break
  305. case 'ascii':
  306. ret = _asciiSlice(self, start, end)
  307. break
  308. case 'binary':
  309. ret = _binarySlice(self, start, end)
  310. break
  311. case 'base64':
  312. ret = _base64Slice(self, start, end)
  313. break
  314. case 'ucs2':
  315. case 'ucs-2':
  316. case 'utf16le':
  317. case 'utf-16le':
  318. ret = _utf16leSlice(self, start, end)
  319. break
  320. default:
  321. throw new Error('Unknown encoding')
  322. }
  323. return ret
  324. }
  325. Buffer.prototype.toJSON = function () {
  326. return {
  327. type: 'Buffer',
  328. data: Array.prototype.slice.call(this._arr || this, 0)
  329. }
  330. }
  331. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  332. Buffer.prototype.copy = function (target, target_start, start, end) {
  333. var source = this
  334. if (!start) start = 0
  335. if (!end && end !== 0) end = this.length
  336. if (!target_start) target_start = 0
  337. // Copy 0 bytes; we're done
  338. if (end === start) return
  339. if (target.length === 0 || source.length === 0) return
  340. // Fatal error conditions
  341. assert(end >= start, 'sourceEnd < sourceStart')
  342. assert(target_start >= 0 && target_start < target.length,
  343. 'targetStart out of bounds')
  344. assert(start >= 0 && start < source.length, 'sourceStart out of bounds')
  345. assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds')
  346. // Are we oob?
  347. if (end > this.length)
  348. end = this.length
  349. if (target.length - target_start < end - start)
  350. end = target.length - target_start + start
  351. // copy!
  352. for (var i = 0; i < end - start; i++)
  353. target[i + target_start] = this[i + start]
  354. }
  355. function _base64Slice (buf, start, end) {
  356. if (start === 0 && end === buf.length) {
  357. return base64.fromByteArray(buf)
  358. } else {
  359. return base64.fromByteArray(buf.slice(start, end))
  360. }
  361. }
  362. function _utf8Slice (buf, start, end) {
  363. var res = ''
  364. var tmp = ''
  365. end = Math.min(buf.length, end)
  366. for (var i = start; i < end; i++) {
  367. if (buf[i] <= 0x7F) {
  368. res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
  369. tmp = ''
  370. } else {
  371. tmp += '%' + buf[i].toString(16)
  372. }
  373. }
  374. return res + decodeUtf8Char(tmp)
  375. }
  376. function _asciiSlice (buf, start, end) {
  377. var ret = ''
  378. end = Math.min(buf.length, end)
  379. for (var i = start; i < end; i++)
  380. ret += String.fromCharCode(buf[i])
  381. return ret
  382. }
  383. function _binarySlice (buf, start, end) {
  384. return _asciiSlice(buf, start, end)
  385. }
  386. function _hexSlice (buf, start, end) {
  387. var len = buf.length
  388. if (!start || start < 0) start = 0
  389. if (!end || end < 0 || end > len) end = len
  390. var out = ''
  391. for (var i = start; i < end; i++) {
  392. out += toHex(buf[i])
  393. }
  394. return out
  395. }
  396. function _utf16leSlice (buf, start, end) {
  397. var bytes = buf.slice(start, end)
  398. var res = ''
  399. for (var i = 0; i < bytes.length; i += 2) {
  400. res += String.fromCharCode(bytes[i] + bytes[i+1] * 256)
  401. }
  402. return res
  403. }
  404. Buffer.prototype.slice = function (start, end) {
  405. var len = this.length
  406. start = clamp(start, len, 0)
  407. end = clamp(end, len, len)
  408. if (Buffer._useTypedArrays) {
  409. return augment(this.subarray(start, end))
  410. } else {
  411. var sliceLen = end - start
  412. var newBuf = new Buffer(sliceLen, undefined, true)
  413. for (var i = 0; i < sliceLen; i++) {
  414. newBuf[i] = this[i + start]
  415. }
  416. return newBuf
  417. }
  418. }
  419. // `get` will be removed in Node 0.13+
  420. Buffer.prototype.get = function (offset) {
  421. console.log('.get() is deprecated. Access using array indexes instead.')
  422. return this.readUInt8(offset)
  423. }
  424. // `set` will be removed in Node 0.13+
  425. Buffer.prototype.set = function (v, offset) {
  426. console.log('.set() is deprecated. Access using array indexes instead.')
  427. return this.writeUInt8(v, offset)
  428. }
  429. Buffer.prototype.readUInt8 = function (offset, noAssert) {
  430. if (!noAssert) {
  431. assert(offset !== undefined && offset !== null, 'missing offset')
  432. assert(offset < this.length, 'Trying to read beyond buffer length')
  433. }
  434. if (offset >= this.length)
  435. return
  436. return this[offset]
  437. }
  438. function _readUInt16 (buf, offset, littleEndian, noAssert) {
  439. if (!noAssert) {
  440. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  441. assert(offset !== undefined && offset !== null, 'missing offset')
  442. assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
  443. }
  444. var len = buf.length
  445. if (offset >= len)
  446. return
  447. var val
  448. if (littleEndian) {
  449. val = buf[offset]
  450. if (offset + 1 < len)
  451. val |= buf[offset + 1] << 8
  452. } else {
  453. val = buf[offset] << 8
  454. if (offset + 1 < len)
  455. val |= buf[offset + 1]
  456. }
  457. return val
  458. }
  459. Buffer.prototype.readUInt16LE = function (offset, noAssert) {
  460. return _readUInt16(this, offset, true, noAssert)
  461. }
  462. Buffer.prototype.readUInt16BE = function (offset, noAssert) {
  463. return _readUInt16(this, offset, false, noAssert)
  464. }
  465. function _readUInt32 (buf, offset, littleEndian, noAssert) {
  466. if (!noAssert) {
  467. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  468. assert(offset !== undefined && offset !== null, 'missing offset')
  469. assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
  470. }
  471. var len = buf.length
  472. if (offset >= len)
  473. return
  474. var val
  475. if (littleEndian) {
  476. if (offset + 2 < len)
  477. val = buf[offset + 2] << 16
  478. if (offset + 1 < len)
  479. val |= buf[offset + 1] << 8
  480. val |= buf[offset]
  481. if (offset + 3 < len)
  482. val = val + (buf[offset + 3] << 24 >>> 0)
  483. } else {
  484. if (offset + 1 < len)
  485. val = buf[offset + 1] << 16
  486. if (offset + 2 < len)
  487. val |= buf[offset + 2] << 8
  488. if (offset + 3 < len)
  489. val |= buf[offset + 3]
  490. val = val + (buf[offset] << 24 >>> 0)
  491. }
  492. return val
  493. }
  494. Buffer.prototype.readUInt32LE = function (offset, noAssert) {
  495. return _readUInt32(this, offset, true, noAssert)
  496. }
  497. Buffer.prototype.readUInt32BE = function (offset, noAssert) {
  498. return _readUInt32(this, offset, false, noAssert)
  499. }
  500. Buffer.prototype.readInt8 = function (offset, noAssert) {
  501. if (!noAssert) {
  502. assert(offset !== undefined && offset !== null,
  503. 'missing offset')
  504. assert(offset < this.length, 'Trying to read beyond buffer length')
  505. }
  506. if (offset >= this.length)
  507. return
  508. var neg = this[offset] & 0x80
  509. if (neg)
  510. return (0xff - this[offset] + 1) * -1
  511. else
  512. return this[offset]
  513. }
  514. function _readInt16 (buf, offset, littleEndian, noAssert) {
  515. if (!noAssert) {
  516. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  517. assert(offset !== undefined && offset !== null, 'missing offset')
  518. assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
  519. }
  520. var len = buf.length
  521. if (offset >= len)
  522. return
  523. var val = _readUInt16(buf, offset, littleEndian, true)
  524. var neg = val & 0x8000
  525. if (neg)
  526. return (0xffff - val + 1) * -1
  527. else
  528. return val
  529. }
  530. Buffer.prototype.readInt16LE = function (offset, noAssert) {
  531. return _readInt16(this, offset, true, noAssert)
  532. }
  533. Buffer.prototype.readInt16BE = function (offset, noAssert) {
  534. return _readInt16(this, offset, false, noAssert)
  535. }
  536. function _readInt32 (buf, offset, littleEndian, noAssert) {
  537. if (!noAssert) {
  538. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  539. assert(offset !== undefined && offset !== null, 'missing offset')
  540. assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
  541. }
  542. var len = buf.length
  543. if (offset >= len)
  544. return
  545. var val = _readUInt32(buf, offset, littleEndian, true)
  546. var neg = val & 0x80000000
  547. if (neg)
  548. return (0xffffffff - val + 1) * -1
  549. else
  550. return val
  551. }
  552. Buffer.prototype.readInt32LE = function (offset, noAssert) {
  553. return _readInt32(this, offset, true, noAssert)
  554. }
  555. Buffer.prototype.readInt32BE = function (offset, noAssert) {
  556. return _readInt32(this, offset, false, noAssert)
  557. }
  558. function _readFloat (buf, offset, littleEndian, noAssert) {
  559. if (!noAssert) {
  560. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  561. assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
  562. }
  563. return ieee754.read(buf, offset, littleEndian, 23, 4)
  564. }
  565. Buffer.prototype.readFloatLE = function (offset, noAssert) {
  566. return _readFloat(this, offset, true, noAssert)
  567. }
  568. Buffer.prototype.readFloatBE = function (offset, noAssert) {
  569. return _readFloat(this, offset, false, noAssert)
  570. }
  571. function _readDouble (buf, offset, littleEndian, noAssert) {
  572. if (!noAssert) {
  573. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  574. assert(offset + 7 < buf.length, 'Trying to read beyond buffer length')
  575. }
  576. return ieee754.read(buf, offset, littleEndian, 52, 8)
  577. }
  578. Buffer.prototype.readDoubleLE = function (offset, noAssert) {
  579. return _readDouble(this, offset, true, noAssert)
  580. }
  581. Buffer.prototype.readDoubleBE = function (offset, noAssert) {
  582. return _readDouble(this, offset, false, noAssert)
  583. }
  584. Buffer.prototype.writeUInt8 = function (value, offset, noAssert) {
  585. if (!noAssert) {
  586. assert(value !== undefined && value !== null, 'missing value')
  587. assert(offset !== undefined && offset !== null, 'missing offset')
  588. assert(offset < this.length, 'trying to write beyond buffer length')
  589. verifuint(value, 0xff)
  590. }
  591. if (offset >= this.length) return
  592. this[offset] = value
  593. }
  594. function _writeUInt16 (buf, value, offset, littleEndian, noAssert) {
  595. if (!noAssert) {
  596. assert(value !== undefined && value !== null, 'missing value')
  597. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  598. assert(offset !== undefined && offset !== null, 'missing offset')
  599. assert(offset + 1 < buf.length, 'trying to write beyond buffer length')
  600. verifuint(value, 0xffff)
  601. }
  602. var len = buf.length
  603. if (offset >= len)
  604. return
  605. for (var i = 0, j = Math.min(len - offset, 2); i < j; i++) {
  606. buf[offset + i] =
  607. (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  608. (littleEndian ? i : 1 - i) * 8
  609. }
  610. }
  611. Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) {
  612. _writeUInt16(this, value, offset, true, noAssert)
  613. }
  614. Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) {
  615. _writeUInt16(this, value, offset, false, noAssert)
  616. }
  617. function _writeUInt32 (buf, value, offset, littleEndian, noAssert) {
  618. if (!noAssert) {
  619. assert(value !== undefined && value !== null, 'missing value')
  620. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  621. assert(offset !== undefined && offset !== null, 'missing offset')
  622. assert(offset + 3 < buf.length, 'trying to write beyond buffer length')
  623. verifuint(value, 0xffffffff)
  624. }
  625. var len = buf.length
  626. if (offset >= len)
  627. return
  628. for (var i = 0, j = Math.min(len - offset, 4); i < j; i++) {
  629. buf[offset + i] =
  630. (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  631. }
  632. }
  633. Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) {
  634. _writeUInt32(this, value, offset, true, noAssert)
  635. }
  636. Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) {
  637. _writeUInt32(this, value, offset, false, noAssert)
  638. }
  639. Buffer.prototype.writeInt8 = function (value, offset, noAssert) {
  640. if (!noAssert) {
  641. assert(value !== undefined && value !== null, 'missing value')
  642. assert(offset !== undefined && offset !== null, 'missing offset')
  643. assert(offset < this.length, 'Trying to write beyond buffer length')
  644. verifsint(value, 0x7f, -0x80)
  645. }
  646. if (offset >= this.length)
  647. return
  648. if (value >= 0)
  649. this.writeUInt8(value, offset, noAssert)
  650. else
  651. this.writeUInt8(0xff + value + 1, offset, noAssert)
  652. }
  653. function _writeInt16 (buf, value, offset, littleEndian, noAssert) {
  654. if (!noAssert) {
  655. assert(value !== undefined && value !== null, 'missing value')
  656. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  657. assert(offset !== undefined && offset !== null, 'missing offset')
  658. assert(offset + 1 < buf.length, 'Trying to write beyond buffer length')
  659. verifsint(value, 0x7fff, -0x8000)
  660. }
  661. var len = buf.length
  662. if (offset >= len)
  663. return
  664. if (value >= 0)
  665. _writeUInt16(buf, value, offset, littleEndian, noAssert)
  666. else
  667. _writeUInt16(buf, 0xffff + value + 1, offset, littleEndian, noAssert)
  668. }
  669. Buffer.prototype.writeInt16LE = function (value, offset, noAssert) {
  670. _writeInt16(this, value, offset, true, noAssert)
  671. }
  672. Buffer.prototype.writeInt16BE = function (value, offset, noAssert) {
  673. _writeInt16(this, value, offset, false, noAssert)
  674. }
  675. function _writeInt32 (buf, value, offset, littleEndian, noAssert) {
  676. if (!noAssert) {
  677. assert(value !== undefined && value !== null, 'missing value')
  678. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  679. assert(offset !== undefined && offset !== null, 'missing offset')
  680. assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
  681. verifsint(value, 0x7fffffff, -0x80000000)
  682. }
  683. var len = buf.length
  684. if (offset >= len)
  685. return
  686. if (value >= 0)
  687. _writeUInt32(buf, value, offset, littleEndian, noAssert)
  688. else
  689. _writeUInt32(buf, 0xffffffff + value + 1, offset, littleEndian, noAssert)
  690. }
  691. Buffer.prototype.writeInt32LE = function (value, offset, noAssert) {
  692. _writeInt32(this, value, offset, true, noAssert)
  693. }
  694. Buffer.prototype.writeInt32BE = function (value, offset, noAssert) {
  695. _writeInt32(this, value, offset, false, noAssert)
  696. }
  697. function _writeFloat (buf, value, offset, littleEndian, noAssert) {
  698. if (!noAssert) {
  699. assert(value !== undefined && value !== null, 'missing value')
  700. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  701. assert(offset !== undefined && offset !== null, 'missing offset')
  702. assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
  703. verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38)
  704. }
  705. var len = buf.length
  706. if (offset >= len)
  707. return
  708. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  709. }
  710. Buffer.prototype.writeFloatLE = function (value, offset, noAssert) {
  711. _writeFloat(this, value, offset, true, noAssert)
  712. }
  713. Buffer.prototype.writeFloatBE = function (value, offset, noAssert) {
  714. _writeFloat(this, value, offset, false, noAssert)
  715. }
  716. function _writeDouble (buf, value, offset, littleEndian, noAssert) {
  717. if (!noAssert) {
  718. assert(value !== undefined && value !== null, 'missing value')
  719. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  720. assert(offset !== undefined && offset !== null, 'missing offset')
  721. assert(offset + 7 < buf.length,
  722. 'Trying to write beyond buffer length')
  723. verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308)
  724. }
  725. var len = buf.length
  726. if (offset >= len)
  727. return
  728. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  729. }
  730. Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) {
  731. _writeDouble(this, value, offset, true, noAssert)
  732. }
  733. Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) {
  734. _writeDouble(this, value, offset, false, noAssert)
  735. }
  736. // fill(value, start=0, end=buffer.length)
  737. Buffer.prototype.fill = function (value, start, end) {
  738. if (!value) value = 0
  739. if (!start) start = 0
  740. if (!end) end = this.length
  741. if (typeof value === 'string') {
  742. value = value.charCodeAt(0)
  743. }
  744. assert(typeof value === 'number' && !isNaN(value), 'value is not a number')
  745. assert(end >= start, 'end < start')
  746. // Fill 0 bytes; we're done
  747. if (end === start) return
  748. if (this.length === 0) return
  749. assert(start >= 0 && start < this.length, 'start out of bounds')
  750. assert(end >= 0 && end <= this.length, 'end out of bounds')
  751. for (var i = start; i < end; i++) {
  752. this[i] = value
  753. }
  754. }
  755. Buffer.prototype.inspect = function () {
  756. var out = []
  757. var len = this.length
  758. for (var i = 0; i < len; i++) {
  759. out[i] = toHex(this[i])
  760. if (i === exports.INSPECT_MAX_BYTES) {
  761. out[i + 1] = '...'
  762. break
  763. }
  764. }
  765. return '<Buffer ' + out.join(' ') + '>'
  766. }
  767. /**
  768. * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
  769. * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
  770. */
  771. Buffer.prototype.toArrayBuffer = function () {
  772. if (typeof Uint8Array === 'function') {
  773. if (Buffer._useTypedArrays) {
  774. return (new Buffer(this)).buffer
  775. } else {
  776. var buf = new Uint8Array(this.length)
  777. for (var i = 0, len = buf.length; i < len; i += 1)
  778. buf[i] = this[i]
  779. return buf.buffer
  780. }
  781. } else {
  782. throw new Error('Buffer.toArrayBuffer not supported in this browser')
  783. }
  784. }
  785. // HELPER FUNCTIONS
  786. // ================
  787. function stringtrim (str) {
  788. if (str.trim) return str.trim()
  789. return str.replace(/^\s+|\s+$/g, '')
  790. }
  791. var BP = Buffer.prototype
  792. /**
  793. * Augment the Uint8Array *instance* (not the class!) with Buffer methods
  794. */
  795. function augment (arr) {
  796. arr._isBuffer = true
  797. // save reference to original Uint8Array get/set methods before overwriting
  798. arr._get = arr.get
  799. arr._set = arr.set
  800. // deprecated, will be removed in node 0.13+
  801. arr.get = BP.get
  802. arr.set = BP.set
  803. arr.write = BP.write
  804. arr.toString = BP.toString
  805. arr.toLocaleString = BP.toString
  806. arr.toJSON = BP.toJSON
  807. arr.copy = BP.copy
  808. arr.slice = BP.slice
  809. arr.readUInt8 = BP.readUInt8
  810. arr.readUInt16LE = BP.readUInt16LE
  811. arr.readUInt16BE = BP.readUInt16BE
  812. arr.readUInt32LE = BP.readUInt32LE
  813. arr.readUInt32BE = BP.readUInt32BE
  814. arr.readInt8 = BP.readInt8
  815. arr.readInt16LE = BP.readInt16LE
  816. arr.readInt16BE = BP.readInt16BE
  817. arr.readInt32LE = BP.readInt32LE
  818. arr.readInt32BE = BP.readInt32BE
  819. arr.readFloatLE = BP.readFloatLE
  820. arr.readFloatBE = BP.readFloatBE
  821. arr.readDoubleLE = BP.readDoubleLE
  822. arr.readDoubleBE = BP.readDoubleBE
  823. arr.writeUInt8 = BP.writeUInt8
  824. arr.writeUInt16LE = BP.writeUInt16LE
  825. arr.writeUInt16BE = BP.writeUInt16BE
  826. arr.writeUInt32LE = BP.writeUInt32LE
  827. arr.writeUInt32BE = BP.writeUInt32BE
  828. arr.writeInt8 = BP.writeInt8
  829. arr.writeInt16LE = BP.writeInt16LE
  830. arr.writeInt16BE = BP.writeInt16BE
  831. arr.writeInt32LE = BP.writeInt32LE
  832. arr.writeInt32BE = BP.writeInt32BE
  833. arr.writeFloatLE = BP.writeFloatLE
  834. arr.writeFloatBE = BP.writeFloatBE
  835. arr.writeDoubleLE = BP.writeDoubleLE
  836. arr.writeDoubleBE = BP.writeDoubleBE
  837. arr.fill = BP.fill
  838. arr.inspect = BP.inspect
  839. arr.toArrayBuffer = BP.toArrayBuffer
  840. return arr
  841. }
  842. // slice(start, end)
  843. function clamp (index, len, defaultValue) {
  844. if (typeof index !== 'number') return defaultValue
  845. index = ~~index; // Coerce to integer.
  846. if (index >= len) return len
  847. if (index >= 0) return index
  848. index += len
  849. if (index >= 0) return index
  850. return 0
  851. }
  852. function coerce (length) {
  853. // Coerce length to a number (possibly NaN), round up
  854. // in case it's fractional (e.g. 123.456) then do a
  855. // double negate to coerce a NaN to 0. Easy, right?
  856. length = ~~Math.ceil(+length)
  857. return length < 0 ? 0 : length
  858. }
  859. function isArray (subject) {
  860. return (Array.isArray || function (subject) {
  861. return Object.prototype.toString.call(subject) === '[object Array]'
  862. })(subject)
  863. }
  864. function isArrayish (subject) {
  865. return isArray(subject) || Buffer.isBuffer(subject) ||
  866. subject && typeof subject === 'object' &&
  867. typeof subject.length === 'number'
  868. }
  869. function toHex (n) {
  870. if (n < 16) return '0' + n.toString(16)
  871. return n.toString(16)
  872. }
  873. function utf8ToBytes (str) {
  874. var byteArray = []
  875. for (var i = 0; i < str.length; i++) {
  876. var b = str.charCodeAt(i)
  877. if (b <= 0x7F)
  878. byteArray.push(str.charCodeAt(i))
  879. else {
  880. var start = i
  881. if (b >= 0xD800 && b <= 0xDFFF) i++
  882. var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%')
  883. for (var j = 0; j < h.length; j++)
  884. byteArray.push(parseInt(h[j], 16))
  885. }
  886. }
  887. return byteArray
  888. }
  889. function asciiToBytes (str) {
  890. var byteArray = []
  891. for (var i = 0; i < str.length; i++) {
  892. // Node's code seems to be doing this and not & 0x7F..
  893. byteArray.push(str.charCodeAt(i) & 0xFF)
  894. }
  895. return byteArray
  896. }
  897. function utf16leToBytes (str) {
  898. var c, hi, lo
  899. var byteArray = []
  900. for (var i = 0; i < str.length; i++) {
  901. c = str.charCodeAt(i)
  902. hi = c >> 8
  903. lo = c % 256
  904. byteArray.push(lo)
  905. byteArray.push(hi)
  906. }
  907. return byteArray
  908. }
  909. function base64ToBytes (str) {
  910. return base64.toByteArray(str)
  911. }
  912. function blitBuffer (src, dst, offset, length) {
  913. var pos
  914. for (var i = 0; i < length; i++) {
  915. if ((i + offset >= dst.length) || (i >= src.length))
  916. break
  917. dst[i + offset] = src[i]
  918. }
  919. return i
  920. }
  921. function decodeUtf8Char (str) {
  922. try {
  923. return decodeURIComponent(str)
  924. } catch (err) {
  925. return String.fromCharCode(0xFFFD) // UTF 8 invalid char
  926. }
  927. }
  928. /*
  929. * We have to make sure that the value is a valid integer. This means that it
  930. * is non-negative. It has no fractional component and that it does not
  931. * exceed the maximum allowed value.
  932. */
  933. function verifuint (value, max) {
  934. assert(typeof value === 'number', 'cannot write a non-number as a number')
  935. assert(value >= 0,
  936. 'specified a negative value for writing an unsigned value')
  937. assert(value <= max, 'value is larger than maximum value for type')
  938. assert(Math.floor(value) === value, 'value has a fractional component')
  939. }
  940. function verifsint (value, max, min) {
  941. assert(typeof value === 'number', 'cannot write a non-number as a number')
  942. assert(value <= max, 'value larger than maximum allowed value')
  943. assert(value >= min, 'value smaller than minimum allowed value')
  944. assert(Math.floor(value) === value, 'value has a fractional component')
  945. }
  946. function verifIEEE754 (value, max, min) {
  947. assert(typeof value === 'number', 'cannot write a non-number as a number')
  948. assert(value <= max, 'value larger than maximum allowed value')
  949. assert(value >= min, 'value smaller than minimum allowed value')
  950. }
  951. function assert (test, message) {
  952. if (!test) throw new Error(message || 'Failed assertion')
  953. }
  954. },{"base64-js":2,"ieee754":3}],2:[function(require,module,exports){
  955. var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  956. ;(function (exports) {
  957. 'use strict';
  958. var Arr = (typeof Uint8Array !== 'undefined')
  959. ? Uint8Array
  960. : Array
  961. var ZERO = '0'.charCodeAt(0)
  962. var PLUS = '+'.charCodeAt(0)
  963. var SLASH = '/'.charCodeAt(0)
  964. var NUMBER = '0'.charCodeAt(0)
  965. var LOWER = 'a'.charCodeAt(0)
  966. var UPPER = 'A'.charCodeAt(0)
  967. function decode (elt) {
  968. var code = elt.charCodeAt(0)
  969. if (code === PLUS)
  970. return 62 // '+'
  971. if (code === SLASH)
  972. return 63 // '/'
  973. if (code < NUMBER)
  974. return -1 //no match
  975. if (code < NUMBER + 10)
  976. return code - NUMBER + 26 + 26
  977. if (code < UPPER + 26)
  978. return code - UPPER
  979. if (code < LOWER + 26)
  980. return code - LOWER + 26
  981. }
  982. function b64ToByteArray (b64) {
  983. var i, j, l, tmp, placeHolders, arr
  984. if (b64.length % 4 > 0) {
  985. throw new Error('Invalid string. Length must be a multiple of 4')
  986. }
  987. // the number of equal signs (place holders)
  988. // if there are two placeholders, than the two characters before it
  989. // represent one byte
  990. // if there is only one, then the three characters before it represent 2 bytes
  991. // this is just a cheap hack to not do indexOf twice
  992. var len = b64.length
  993. placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
  994. // base64 is 4/3 + up to two characters of the original data
  995. arr = new Arr(b64.length * 3 / 4 - placeHolders)
  996. // if there are placeholders, only get up to the last complete 4 chars
  997. l = placeHolders > 0 ? b64.length - 4 : b64.length
  998. var L = 0
  999. function push (v) {
  1000. arr[L++] = v
  1001. }
  1002. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  1003. tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
  1004. push((tmp & 0xFF0000) >> 16)
  1005. push((tmp & 0xFF00) >> 8)
  1006. push(tmp & 0xFF)
  1007. }
  1008. if (placeHolders === 2) {
  1009. tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
  1010. push(tmp & 0xFF)
  1011. } else if (placeHolders === 1) {
  1012. tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
  1013. push((tmp >> 8) & 0xFF)
  1014. push(tmp & 0xFF)
  1015. }
  1016. return arr
  1017. }
  1018. function uint8ToBase64 (uint8) {
  1019. var i,
  1020. extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
  1021. output = "",
  1022. temp, length
  1023. function encode (num) {
  1024. return lookup.charAt(num)
  1025. }
  1026. function tripletToBase64 (num) {
  1027. return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
  1028. }
  1029. // go through the array every three bytes, we'll deal with trailing stuff later
  1030. for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
  1031. temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  1032. output += tripletToBase64(temp)
  1033. }
  1034. // pad the end with zeros, but make sure to not forget the extra bytes
  1035. switch (extraBytes) {
  1036. case 1:
  1037. temp = uint8[uint8.length - 1]
  1038. output += encode(temp >> 2)
  1039. output += encode((temp << 4) & 0x3F)
  1040. output += '=='
  1041. break
  1042. case 2:
  1043. temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
  1044. output += encode(temp >> 10)
  1045. output += encode((temp >> 4) & 0x3F)
  1046. output += encode((temp << 2) & 0x3F)
  1047. output += '='
  1048. break
  1049. }
  1050. return output
  1051. }
  1052. module.exports.toByteArray = b64ToByteArray
  1053. module.exports.fromByteArray = uint8ToBase64
  1054. }())
  1055. },{}],3:[function(require,module,exports){
  1056. exports.read = function(buffer, offset, isLE, mLen, nBytes) {
  1057. var e, m,
  1058. eLen = nBytes * 8 - mLen - 1,
  1059. eMax = (1 << eLen) - 1,
  1060. eBias = eMax >> 1,
  1061. nBits = -7,
  1062. i = isLE ? (nBytes - 1) : 0,
  1063. d = isLE ? -1 : 1,
  1064. s = buffer[offset + i];
  1065. i += d;
  1066. e = s & ((1 << (-nBits)) - 1);
  1067. s >>= (-nBits);
  1068. nBits += eLen;
  1069. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
  1070. m = e & ((1 << (-nBits)) - 1);
  1071. e >>= (-nBits);
  1072. nBits += mLen;
  1073. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
  1074. if (e === 0) {
  1075. e = 1 - eBias;
  1076. } else if (e === eMax) {
  1077. return m ? NaN : ((s ? -1 : 1) * Infinity);
  1078. } else {
  1079. m = m + Math.pow(2, mLen);
  1080. e = e - eBias;
  1081. }
  1082. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  1083. };
  1084. exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
  1085. var e, m, c,
  1086. eLen = nBytes * 8 - mLen - 1,
  1087. eMax = (1 << eLen) - 1,
  1088. eBias = eMax >> 1,
  1089. rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
  1090. i = isLE ? 0 : (nBytes - 1),
  1091. d = isLE ? 1 : -1,
  1092. s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  1093. value = Math.abs(value);
  1094. if (isNaN(value) || value === Infinity) {
  1095. m = isNaN(value) ? 1 : 0;
  1096. e = eMax;
  1097. } else {
  1098. e = Math.floor(Math.log(value) / Math.LN2);
  1099. if (value * (c = Math.pow(2, -e)) < 1) {
  1100. e--;
  1101. c *= 2;
  1102. }
  1103. if (e + eBias >= 1) {
  1104. value += rt / c;
  1105. } else {
  1106. value += rt * Math.pow(2, 1 - eBias);
  1107. }
  1108. if (value * c >= 2) {
  1109. e++;
  1110. c /= 2;
  1111. }
  1112. if (e + eBias >= eMax) {
  1113. m = 0;
  1114. e = eMax;
  1115. } else if (e + eBias >= 1) {
  1116. m = (value * c - 1) * Math.pow(2, mLen);
  1117. e = e + eBias;
  1118. } else {
  1119. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  1120. e = 0;
  1121. }
  1122. }
  1123. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
  1124. e = (e << mLen) | m;
  1125. eLen += mLen;
  1126. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
  1127. buffer[offset + i - d] |= s * 128;
  1128. };
  1129. },{}],4:[function(require,module,exports){
  1130. // Copyright Joyent, Inc. and other Node contributors.
  1131. //
  1132. // Permission is hereby granted, free of charge, to any person obtaining a
  1133. // copy of this software and associated documentation files (the
  1134. // "Software"), to deal in the Software without restriction, including
  1135. // without limitation the rights to use, copy, modify, merge, publish,
  1136. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1137. // persons to whom the Software is furnished to do so, subject to the
  1138. // following conditions:
  1139. //
  1140. // The above copyright notice and this permission notice shall be included
  1141. // in all copies or substantial portions of the Software.
  1142. //
  1143. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1144. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1145. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1146. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1147. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1148. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1149. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1150. function EventEmitter() {
  1151. this._events = this._events || {};
  1152. this._maxListeners = this._maxListeners || undefined;
  1153. }
  1154. module.exports = EventEmitter;
  1155. // Backwards-compat with node 0.10.x
  1156. EventEmitter.EventEmitter = EventEmitter;
  1157. EventEmitter.prototype._events = undefined;
  1158. EventEmitter.prototype._maxListeners = undefined;
  1159. // By default EventEmitters will print a warning if more than 10 listeners are
  1160. // added to it. This is a useful default which helps finding memory leaks.
  1161. EventEmitter.defaultMaxListeners = 10;
  1162. // Obviously not all Emitters should be limited to 10. This function allows
  1163. // that to be increased. Set to zero for unlimited.
  1164. EventEmitter.prototype.setMaxListeners = function(n) {
  1165. if (!isNumber(n) || n < 0 || isNaN(n))
  1166. throw TypeError('n must be a positive number');
  1167. this._maxListeners = n;
  1168. return this;
  1169. };
  1170. EventEmitter.prototype.emit = function(type) {
  1171. var er, handler, len, args, i, listeners;
  1172. if (!this._events)
  1173. this._events = {};
  1174. // If there is no 'error' event listener then throw.
  1175. if (type === 'error') {
  1176. if (!this._events.error ||
  1177. (isObject(this._events.error) && !this._events.error.length)) {
  1178. er = arguments[1];
  1179. if (er instanceof Error) {
  1180. throw er; // Unhandled 'error' event
  1181. } else {
  1182. throw TypeError('Uncaught, unspecified "error" event.');
  1183. }
  1184. return false;
  1185. }
  1186. }
  1187. handler = this._events[type];
  1188. if (isUndefined(handler))
  1189. return false;
  1190. if (isFunction(handler)) {
  1191. switch (arguments.length) {
  1192. // fast cases
  1193. case 1:
  1194. handler.call(this);
  1195. break;
  1196. case 2:
  1197. handler.call(this, arguments[1]);
  1198. break;
  1199. case 3:
  1200. handler.call(this, arguments[1], arguments[2]);
  1201. break;
  1202. // slower
  1203. default:
  1204. len = arguments.length;
  1205. args = new Array(len - 1);
  1206. for (i = 1; i < len; i++)
  1207. args[i - 1] = arguments[i];
  1208. handler.apply(this, args);
  1209. }
  1210. } else if (isObject(handler)) {
  1211. len = arguments.length;
  1212. args = new Array(len - 1);
  1213. for (i = 1; i < len; i++)
  1214. args[i - 1] = arguments[i];
  1215. listeners = handler.slice();
  1216. len = listeners.length;
  1217. for (i = 0; i < len; i++)
  1218. listeners[i].apply(this, args);
  1219. }
  1220. return true;
  1221. };
  1222. EventEmitter.prototype.addListener = function(type, listener) {
  1223. var m;
  1224. if (!isFunction(listener))
  1225. throw TypeError('listener must be a function');
  1226. if (!this._events)
  1227. this._events = {};
  1228. // To avoid recursion in the case that type === "newListener"! Before
  1229. // adding it to the listeners, first emit "newListener".
  1230. if (this._events.newListener)
  1231. this.emit('newListener', type,
  1232. isFunction(listener.listener) ?
  1233. listener.listener : listener);
  1234. if (!this._events[type])
  1235. // Optimize the case of one listener. Don't need the extra array object.
  1236. this._events[type] = listener;
  1237. else if (isObject(this._events[type]))
  1238. // If we've already got an array, just append.
  1239. this._events[type].push(listener);
  1240. else
  1241. // Adding the second element, need to change to array.
  1242. this._events[type] = [this._events[type], listener];
  1243. // Check for listener leak
  1244. if (isObject(this._events[type]) && !this._events[type].warned) {
  1245. var m;
  1246. if (!isUndefined(this._maxListeners)) {
  1247. m = this._maxListeners;
  1248. } else {
  1249. m = EventEmitter.defaultMaxListeners;
  1250. }
  1251. if (m && m > 0 && this._events[type].length > m) {
  1252. this._events[type].warned = true;
  1253. console.error('(node) warning: possible EventEmitter memory ' +
  1254. 'leak detected. %d listeners added. ' +
  1255. 'Use emitter.setMaxListeners() to increase limit.',
  1256. this._events[type].length);
  1257. console.trace();
  1258. }
  1259. }
  1260. return this;
  1261. };
  1262. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  1263. EventEmitter.prototype.once = function(type, listener) {
  1264. if (!isFunction(listener))
  1265. throw TypeError('listener must be a function');
  1266. var fired = false;
  1267. function g() {
  1268. this.removeListener(type, g);
  1269. if (!fired) {
  1270. fired = true;
  1271. listener.apply(this, arguments);
  1272. }
  1273. }
  1274. g.listener = listener;
  1275. this.on(type, g);
  1276. return this;
  1277. };
  1278. // emits a 'removeListener' event iff the listener was removed
  1279. EventEmitter.prototype.removeListener = function(type, listener) {
  1280. var list, position, length, i;
  1281. if (!isFunction(listener))
  1282. throw TypeError('listener must be a function');
  1283. if (!this._events || !this._events[type])
  1284. return this;
  1285. list = this._events[type];
  1286. length = list.length;
  1287. position = -1;
  1288. if (list === listener ||
  1289. (isFunction(list.listener) && list.listener === listener)) {
  1290. delete this._events[type];
  1291. if (this._events.removeListener)
  1292. this.emit('removeListener', type, listener);
  1293. } else if (isObject(list)) {
  1294. for (i = length; i-- > 0;) {
  1295. if (list[i] === listener ||
  1296. (list[i].listener && list[i].listener === listener)) {
  1297. position = i;
  1298. break;
  1299. }
  1300. }
  1301. if (position < 0)
  1302. return this;
  1303. if (list.length === 1) {
  1304. list.length = 0;
  1305. delete this._events[type];
  1306. } else {
  1307. list.splice(position, 1);
  1308. }
  1309. if (this._events.removeListener)
  1310. this.emit('removeListener', type, listener);
  1311. }
  1312. return this;
  1313. };
  1314. EventEmitter.prototype.removeAllListeners = function(type) {
  1315. var key, listeners;
  1316. if (!this._events)
  1317. return this;
  1318. // not listening for removeListener, no need to emit
  1319. if (!this._events.removeListener) {
  1320. if (arguments.length === 0)
  1321. this._events = {};
  1322. else if (this._events[type])
  1323. delete this._events[type];
  1324. return this;
  1325. }
  1326. // emit removeListener for all listeners on all events
  1327. if (arguments.length === 0) {
  1328. for (key in this._events) {
  1329. if (key === 'removeListener') continue;
  1330. this.removeAllListeners(key);
  1331. }
  1332. this.removeAllListeners('removeListener');
  1333. this._events = {};
  1334. return this;
  1335. }
  1336. listeners = this._events[type];
  1337. if (isFunction(listeners)) {
  1338. this.removeListener(type, listeners);
  1339. } else {
  1340. // LIFO order
  1341. while (listeners.length)
  1342. this.removeListener(type, listeners[listeners.length - 1]);
  1343. }
  1344. delete this._events[type];
  1345. return this;
  1346. };
  1347. EventEmitter.prototype.listeners = function(type) {
  1348. var ret;
  1349. if (!this._events || !this._events[type])
  1350. ret = [];
  1351. else if (isFunction(this._events[type]))
  1352. ret = [this._events[type]];
  1353. else
  1354. ret = this._events[type].slice();
  1355. return ret;
  1356. };
  1357. EventEmitter.listenerCount = function(emitter, type) {
  1358. var ret;
  1359. if (!emitter._events || !emitter._events[type])
  1360. ret = 0;
  1361. else if (isFunction(emitter._events[type]))
  1362. ret = 1;
  1363. else
  1364. ret = emitter._events[type].length;
  1365. return ret;
  1366. };
  1367. function isFunction(arg) {
  1368. return typeof arg === 'function';
  1369. }
  1370. function isNumber(arg) {
  1371. return typeof arg === 'number';
  1372. }
  1373. function isObject(arg) {
  1374. return typeof arg === 'object' && arg !== null;
  1375. }
  1376. function isUndefined(arg) {
  1377. return arg === void 0;
  1378. }
  1379. },{}],5:[function(require,module,exports){
  1380. if (typeof Object.create === 'function') {
  1381. // implementation from standard node.js 'util' module
  1382. module.exports = function inherits(ctor, superCtor) {
  1383. ctor.super_ = superCtor
  1384. ctor.prototype = Object.create(superCtor.prototype, {
  1385. constructor: {
  1386. value: ctor,
  1387. enumerable: false,
  1388. writable: true,
  1389. configurable: true
  1390. }
  1391. });
  1392. };
  1393. } else {
  1394. // old school shim for old browsers
  1395. module.exports = function inherits(ctor, superCtor) {
  1396. ctor.super_ = superCtor
  1397. var TempCtor = function () {}
  1398. TempCtor.prototype = superCtor.prototype
  1399. ctor.prototype = new TempCtor()
  1400. ctor.prototype.constructor = ctor
  1401. }
  1402. }
  1403. },{}],6:[function(require,module,exports){
  1404. // shim for using process in browser
  1405. var process = module.exports = {};
  1406. process.nextTick = (function () {
  1407. var canSetImmediate = typeof window !== 'undefined'
  1408. && window.setImmediate;
  1409. var canPost = typeof window !== 'undefined'
  1410. && window.postMessage && window.addEventListener
  1411. ;
  1412. if (canSetImmediate) {
  1413. return function (f) { return window.setImmediate(f) };
  1414. }
  1415. if (canPost) {
  1416. var queue = [];
  1417. window.addEventListener('message', function (ev) {
  1418. var source = ev.source;
  1419. if ((source === window || source === null) && ev.data === 'process-tick') {
  1420. ev.stopPropagation();
  1421. if (queue.length > 0) {
  1422. var fn = queue.shift();
  1423. fn();
  1424. }
  1425. }
  1426. }, true);
  1427. return function nextTick(fn) {
  1428. queue.push(fn);
  1429. window.postMessage('process-tick', '*');
  1430. };
  1431. }
  1432. return function nextTick(fn) {
  1433. setTimeout(fn, 0);
  1434. };
  1435. })();
  1436. process.title = 'browser';
  1437. process.browser = true;
  1438. process.env = {};
  1439. process.argv = [];
  1440. process.binding = function (name) {
  1441. throw new Error('process.binding is not supported');
  1442. }
  1443. // TODO(shtylman)
  1444. process.cwd = function () { return '/' };
  1445. process.chdir = function (dir) {
  1446. throw new Error('process.chdir is not supported');
  1447. };
  1448. },{}],7:[function(require,module,exports){
  1449. (function (process){
  1450. // Copyright Joyent, Inc. and other Node contributors.
  1451. //
  1452. // Permission is hereby granted, free of charge, to any person obtaining a
  1453. // copy of this software and associated documentation files (the
  1454. // "Software"), to deal in the Software without restriction, including
  1455. // without limitation the rights to use, copy, modify, merge, publish,
  1456. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1457. // persons to whom the Software is furnished to do so, subject to the
  1458. // following conditions:
  1459. //
  1460. // The above copyright notice and this permission notice shall be included
  1461. // in all copies or substantial portions of the Software.
  1462. //
  1463. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1464. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1465. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1466. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1467. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1468. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1469. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1470. // resolves . and .. elements in a path array with directory names there
  1471. // must be no slashes, empty elements, or device names (c:\) in the array
  1472. // (so also no leading and trailing slashes - it does not distinguish
  1473. // relative and absolute paths)
  1474. function normalizeArray(parts, allowAboveRoot) {
  1475. // if the path tries to go above the root, `up` ends up > 0
  1476. var up = 0;
  1477. for (var i = parts.length - 1; i >= 0; i--) {
  1478. var last = parts[i];
  1479. if (last === '.') {
  1480. parts.splice(i, 1);
  1481. } else if (last === '..') {
  1482. parts.splice(i, 1);
  1483. up++;
  1484. } else if (up) {
  1485. parts.splice(i, 1);
  1486. up--;
  1487. }
  1488. }
  1489. // if the path is allowed to go above the root, restore leading ..s
  1490. if (allowAboveRoot) {
  1491. for (; up--; up) {
  1492. parts.unshift('..');
  1493. }
  1494. }
  1495. return parts;
  1496. }
  1497. // Split a filename into [root, dir, basename, ext], unix version
  1498. // 'root' is just a slash, or nothing.
  1499. var splitPathRe =
  1500. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  1501. var splitPath = function(filename) {
  1502. return splitPathRe.exec(filename).slice(1);
  1503. };
  1504. // path.resolve([from ...], to)
  1505. // posix version
  1506. exports.resolve = function() {
  1507. var resolvedPath = '',
  1508. resolvedAbsolute = false;
  1509. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  1510. var path = (i >= 0) ? arguments[i] : process.cwd();
  1511. // Skip empty and invalid entries
  1512. if (typeof path !== 'string') {
  1513. throw new TypeError('Arguments to path.resolve must be strings');
  1514. } else if (!path) {
  1515. continue;
  1516. }
  1517. resolvedPath = path + '/' + resolvedPath;
  1518. resolvedAbsolute = path.charAt(0) === '/';
  1519. }
  1520. // At this point the path should be resolved to a full absolute path, but
  1521. // handle relative paths to be safe (might happen when process.cwd() fails)
  1522. // Normalize the path
  1523. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  1524. return !!p;
  1525. }), !resolvedAbsolute).join('/');
  1526. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  1527. };
  1528. // path.normalize(path)
  1529. // posix version
  1530. exports.normalize = function(path) {
  1531. var isAbsolute = exports.isAbsolute(path),
  1532. trailingSlash = substr(path, -1) === '/';
  1533. // Normalize the path
  1534. path = normalizeArray(filter(path.split('/'), function(p) {
  1535. return !!p;
  1536. }), !isAbsolute).join('/');
  1537. if (!path && !isAbsolute) {
  1538. path = '.';
  1539. }
  1540. if (path && trailingSlash) {
  1541. path += '/';
  1542. }
  1543. return (isAbsolute ? '/' : '') + path;
  1544. };
  1545. // posix version
  1546. exports.isAbsolute = function(path) {
  1547. return path.charAt(0) === '/';
  1548. };
  1549. // posix version
  1550. exports.join = function() {
  1551. var paths = Array.prototype.slice.call(arguments, 0);
  1552. return exports.normalize(filter(paths, function(p, index) {
  1553. if (typeof p !== 'string') {
  1554. throw new TypeError('Arguments to path.join must be strings');
  1555. }
  1556. return p;
  1557. }).join('/'));
  1558. };
  1559. // path.relative(from, to)
  1560. // posix version
  1561. exports.relative = function(from, to) {
  1562. from = exports.resolve(from).substr(1);
  1563. to = exports.resolve(to).substr(1);
  1564. function trim(arr) {
  1565. var start = 0;
  1566. for (; start < arr.length; start++) {
  1567. if (arr[start] !== '') break;
  1568. }
  1569. var end = arr.length - 1;
  1570. for (; end >= 0; end--) {
  1571. if (arr[end] !== '') break;
  1572. }
  1573. if (start > end) return [];
  1574. return arr.slice(start, end - start + 1);
  1575. }
  1576. var fromParts = trim(from.split('/'));
  1577. var toParts = trim(to.split('/'));
  1578. var length = Math.min(fromParts.length, toParts.length);
  1579. var samePartsLength = length;
  1580. for (var i = 0; i < length; i++) {
  1581. if (fromParts[i] !== toParts[i]) {
  1582. samePartsLength = i;
  1583. break;
  1584. }
  1585. }
  1586. var outputParts = [];
  1587. for (var i = samePartsLength; i < fromParts.length; i++) {
  1588. outputParts.push('..');
  1589. }
  1590. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  1591. return outputParts.join('/');
  1592. };
  1593. exports.sep = '/';
  1594. exports.delimiter = ':';
  1595. exports.dirname = function(path) {
  1596. var result = splitPath(path),
  1597. root = result[0],
  1598. dir = result[1];
  1599. if (!root && !dir) {
  1600. // No dirname whatsoever
  1601. return '.';
  1602. }
  1603. if (dir) {
  1604. // It has a dirname, strip trailing slash
  1605. dir = dir.substr(0, dir.length - 1);
  1606. }
  1607. return root + dir;
  1608. };
  1609. exports.basename = function(path, ext) {
  1610. var f = splitPath(path)[2];
  1611. // TODO: make this comparison case-insensitive on windows?
  1612. if (ext && f.substr(-1 * ext.length) === ext) {
  1613. f = f.substr(0, f.length - ext.length);
  1614. }
  1615. return f;
  1616. };
  1617. exports.extname = function(path) {
  1618. return splitPath(path)[3];
  1619. };
  1620. function filter (xs, f) {
  1621. if (xs.filter) return xs.filter(f);
  1622. var res = [];
  1623. for (var i = 0; i < xs.length; i++) {
  1624. if (f(xs[i], i, xs)) res.push(xs[i]);
  1625. }
  1626. return res;
  1627. }
  1628. // String.prototype.substr - negative index don't work in IE8
  1629. var substr = 'ab'.substr(-1) === 'b'
  1630. ? function (str, start, len) { return str.substr(start, len) }
  1631. : function (str, start, len) {
  1632. if (start < 0) start = str.length + start;
  1633. return str.substr(start, len);
  1634. }
  1635. ;
  1636. }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
  1637. },{"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6}],8:[function(require,module,exports){
  1638. // Copyright Joyent, Inc. and other Node contributors.
  1639. //
  1640. // Permission is hereby granted, free of charge, to any person obtaining a
  1641. // copy of this software and associated documentation files (the
  1642. // "Software"), to deal in the Software without restriction, including
  1643. // without limitation the rights to use, copy, modify, merge, publish,
  1644. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1645. // persons to whom the Software is furnished to do so, subject to the
  1646. // following conditions:
  1647. //
  1648. // The above copyright notice and this permission notice shall be included
  1649. // in all copies or substantial portions of the Software.
  1650. //
  1651. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1652. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1653. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1654. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1655. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1656. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1657. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1658. // a duplex stream is just a stream that is both readable and writable.
  1659. // Since JS doesn't have multiple prototypal inheritance, this class
  1660. // prototypally inherits from Readable, and then parasitically from
  1661. // Writable.
  1662. module.exports = Duplex;
  1663. var inherits = require('inherits');
  1664. var setImmediate = require('process/browser.js').nextTick;
  1665. var Readable = require('./readable.js');
  1666. var Writable = require('./writable.js');
  1667. inherits(Duplex, Readable);
  1668. Duplex.prototype.write = Writable.prototype.write;
  1669. Duplex.prototype.end = Writable.prototype.end;
  1670. Duplex.prototype._write = Writable.prototype._write;
  1671. function Duplex(options) {
  1672. if (!(this instanceof Duplex))
  1673. return new Duplex(options);
  1674. Readable.call(this, options);
  1675. Writable.call(this, options);
  1676. if (options && options.readable === false)
  1677. this.readable = false;
  1678. if (options && options.writable === false)
  1679. this.writable = false;
  1680. this.allowHalfOpen = true;
  1681. if (options && options.allowHalfOpen === false)
  1682. this.allowHalfOpen = false;
  1683. this.once('end', onend);
  1684. }
  1685. // the no-half-open enforcer
  1686. function onend() {
  1687. // if we allow half-open state, or if the writable side ended,
  1688. // then we're ok.
  1689. if (this.allowHalfOpen || this._writableState.ended)
  1690. return;
  1691. // no more data can be written.
  1692. // But allow more writes to happen in this tick.
  1693. var self = this;
  1694. setImmediate(function () {
  1695. self.end();
  1696. });
  1697. }
  1698. },{"./readable.js":12,"./writable.js":14,"inherits":5,"process/browser.js":10}],9:[function(require,module,exports){
  1699. // Copyright Joyent, Inc. and other Node contributors.
  1700. //
  1701. // Permission is hereby granted, free of charge, to any person obtaining a
  1702. // copy of this software and associated documentation files (the
  1703. // "Software"), to deal in the Software without restriction, including
  1704. // without limitation the rights to use, copy, modify, merge, publish,
  1705. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1706. // persons to whom the Software is furnished to do so, subject to the
  1707. // following conditions:
  1708. //
  1709. // The above copyright notice and this permission notice shall be included
  1710. // in all copies or substantial portions of the Software.
  1711. //
  1712. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1713. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1714. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1715. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1716. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1717. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1718. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1719. module.exports = Stream;
  1720. var EE = require('events').EventEmitter;
  1721. var inherits = require('inherits');
  1722. inherits(Stream, EE);
  1723. Stream.Readable = require('./readable.js');
  1724. Stream.Writable = require('./writable.js');
  1725. Stream.Duplex = require('./duplex.js');
  1726. Stream.Transform = require('./transform.js');
  1727. Stream.PassThrough = require('./passthrough.js');
  1728. // Backwards-compat with node 0.4.x
  1729. Stream.Stream = Stream;
  1730. // old-style streams. Note that the pipe method (the only relevant
  1731. // part of this class) is overridden in the Readable class.
  1732. function Stream() {
  1733. EE.call(this);
  1734. }
  1735. Stream.prototype.pipe = function(dest, options) {
  1736. var source = this;
  1737. function ondata(chunk) {
  1738. if (dest.writable) {
  1739. if (false === dest.write(chunk) && source.pause) {
  1740. source.pause();
  1741. }
  1742. }
  1743. }
  1744. source.on('data', ondata);
  1745. function ondrain() {
  1746. if (source.readable && source.resume) {
  1747. source.resume();
  1748. }
  1749. }
  1750. dest.on('drain', ondrain);
  1751. // If the 'end' option is not supplied, dest.end() will be called when
  1752. // source gets the 'end' or 'close' events. Only dest.end() once.
  1753. if (!dest._isStdio && (!options || options.end !== false)) {
  1754. source.on('end', onend);
  1755. source.on('close', onclose);
  1756. }
  1757. var didOnEnd = false;
  1758. function onend() {
  1759. if (didOnEnd) return;
  1760. didOnEnd = true;
  1761. dest.end();
  1762. }
  1763. function onclose() {
  1764. if (didOnEnd) return;
  1765. didOnEnd = true;
  1766. if (typeof dest.destroy === 'function') dest.destroy();
  1767. }
  1768. // don't leave dangling pipes when there are errors.
  1769. function onerror(er) {
  1770. cleanup();
  1771. if (EE.listenerCount(this, 'error') === 0) {
  1772. throw er; // Unhandled stream error in pipe.
  1773. }
  1774. }
  1775. source.on('error', onerror);
  1776. dest.on('error', onerror);
  1777. // remove all the event listeners that were added.
  1778. function cleanup() {
  1779. source.removeListener('data', ondata);
  1780. dest.removeListener('drain', ondrain);
  1781. source.removeListener('end', onend);
  1782. source.removeListener('close', onclose);
  1783. source.removeListener('error', onerror);
  1784. dest.removeListener('error', onerror);
  1785. source.removeListener('end', cleanup);
  1786. source.removeListener('close', cleanup);
  1787. dest.removeListener('close', cleanup);
  1788. }
  1789. source.on('end', cleanup);
  1790. source.on('close', cleanup);
  1791. dest.on('close', cleanup);
  1792. dest.emit('pipe', source);
  1793. // Allow for unix-like usage: A.pipe(B).pipe(C)
  1794. return dest;
  1795. };
  1796. },{"./duplex.js":8,"./passthrough.js":11,"./readable.js":12,"./transform.js":13,"./writable.js":14,"events":4,"inherits":5}],10:[function(require,module,exports){
  1797. module.exports=require(6)
  1798. },{}],11:[function(require,module,exports){
  1799. // Copyright Joyent, Inc. and other Node contributors.
  1800. //
  1801. // Permission is hereby granted, free of charge, to any person obtaining a
  1802. // copy of this software and associated documentation files (the
  1803. // "Software"), to deal in the Software without restriction, including
  1804. // without limitation the rights to use, copy, modify, merge, publish,
  1805. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1806. // persons to whom the Software is furnished to do so, subject to the
  1807. // following conditions:
  1808. //
  1809. // The above copyright notice and this permission notice shall be included
  1810. // in all copies or substantial portions of the Software.
  1811. //
  1812. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1813. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1814. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1815. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1816. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1817. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1818. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1819. // a passthrough stream.
  1820. // basically just the most minimal sort of Transform stream.
  1821. // Every written chunk gets output as-is.
  1822. module.exports = PassThrough;
  1823. var Transform = require('./transform.js');
  1824. var inherits = require('inherits');
  1825. inherits(PassThrough, Transform);
  1826. function PassThrough(options) {
  1827. if (!(this instanceof PassThrough))
  1828. return new PassThrough(options);
  1829. Transform.call(this, options);
  1830. }
  1831. PassThrough.prototype._transform = function(chunk, encoding, cb) {
  1832. cb(null, chunk);
  1833. };
  1834. },{"./transform.js":13,"inherits":5}],12:[function(require,module,exports){
  1835. (function (process){
  1836. // Copyright Joyent, Inc. and other Node contributors.
  1837. //
  1838. // Permission is hereby granted, free of charge, to any person obtaining a
  1839. // copy of this software and associated documentation files (the
  1840. // "Software"), to deal in the Software without restriction, including
  1841. // without limitation the rights to use, copy, modify, merge, publish,
  1842. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1843. // persons to whom the Software is furnished to do so, subject to the
  1844. // following conditions:
  1845. //
  1846. // The above copyright notice and this permission notice shall be included
  1847. // in all copies or substantial portions of the Software.
  1848. //
  1849. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1850. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1851. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1852. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1853. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1854. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1855. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1856. module.exports = Readable;
  1857. Readable.ReadableState = ReadableState;
  1858. var EE = require('events').EventEmitter;
  1859. var Stream = require('./index.js');
  1860. var Buffer = require('buffer').Buffer;
  1861. var setImmediate = require('process/browser.js').nextTick;
  1862. var StringDecoder;
  1863. var inherits = require('inherits');
  1864. inherits(Readable, Stream);
  1865. function ReadableState(options, stream) {
  1866. options = options || {};
  1867. // the point at which it stops calling _read() to fill the buffer
  1868. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  1869. var hwm = options.highWaterMark;
  1870. this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
  1871. // cast to ints.
  1872. this.highWaterMark = ~~this.highWaterMark;
  1873. this.buffer = [];
  1874. this.length = 0;
  1875. this.pipes = null;
  1876. this.pipesCount = 0;
  1877. this.flowing = false;
  1878. this.ended = false;
  1879. this.endEmitted = false;
  1880. this.reading = false;
  1881. // In streams that never have any data, and do push(null) right away,
  1882. // the consumer can miss the 'end' event if they do some I/O before
  1883. // consuming the stream. So, we don't emit('end') until some reading
  1884. // happens.
  1885. this.calledRead = false;
  1886. // a flag to be able to tell if the onwrite cb is called immediately,
  1887. // or on a later tick. We set this to true at first, becuase any
  1888. // actions that shouldn't happen until "later" should generally also
  1889. // not happen before the first write call.
  1890. this.sync = true;
  1891. // whenever we return null, then we set a flag to say
  1892. // that we're awaiting a 'readable' event emission.
  1893. this.needReadable = false;
  1894. this.emittedReadable = false;
  1895. this.readableListening = false;
  1896. // object stream flag. Used to make read(n) ignore n and to
  1897. // make all the buffer merging and length checks go away
  1898. this.objectMode = !!options.objectMode;
  1899. // Crypto is kind of old and crusty. Historically, its default string
  1900. // encoding is 'binary' so we have to make this configurable.
  1901. // Everything else in the universe uses 'utf8', though.
  1902. this.defaultEncoding = options.defaultEncoding || 'utf8';
  1903. // when piping, we only care about 'readable' events that happen
  1904. // after read()ing all the bytes and not getting any pushback.
  1905. this.ranOut = false;
  1906. // the number of writers that are awaiting a drain event in .pipe()s
  1907. this.awaitDrain = 0;
  1908. // if true, a maybeReadMore has been scheduled
  1909. this.readingMore = false;
  1910. this.decoder = null;
  1911. this.encoding = null;
  1912. if (options.encoding) {
  1913. if (!StringDecoder)
  1914. StringDecoder = require('string_decoder').StringDecoder;
  1915. this.decoder = new StringDecoder(options.encoding);
  1916. this.encoding = options.encoding;
  1917. }
  1918. }
  1919. function Readable(options) {
  1920. if (!(this instanceof Readable))
  1921. return new Readable(options);
  1922. this._readableState = new ReadableState(options, this);
  1923. // legacy
  1924. this.readable = true;
  1925. Stream.call(this);
  1926. }
  1927. // Manually shove something into the read() buffer.
  1928. // This returns true if the highWaterMark has not been hit yet,
  1929. // similar to how Writable.write() returns true if you should
  1930. // write() some more.
  1931. Readable.prototype.push = function(chunk, encoding) {
  1932. var state = this._readableState;
  1933. if (typeof chunk === 'string' && !state.objectMode) {
  1934. encoding = encoding || state.defaultEncoding;
  1935. if (encoding !== state.encoding) {
  1936. chunk = new Buffer(chunk, encoding);
  1937. encoding = '';
  1938. }
  1939. }
  1940. return readableAddChunk(this, state, chunk, encoding, false);
  1941. };
  1942. // Unshift should *always* be something directly out of read()
  1943. Readable.prototype.unshift = function(chunk) {
  1944. var state = this._readableState;
  1945. return readableAddChunk(this, state, chunk, '', true);
  1946. };
  1947. function readableAddChunk(stream, state, chunk, encoding, addToFront) {
  1948. var er = chunkInvalid(state, chunk);
  1949. if (er) {
  1950. stream.emit('error', er);
  1951. } else if (chunk === null || chunk === undefined) {
  1952. state.reading = false;
  1953. if (!state.ended)
  1954. onEofChunk(stream, state);
  1955. } else if (state.objectMode || chunk && chunk.length > 0) {
  1956. if (state.ended && !addToFront) {
  1957. var e = new Error('stream.push() after EOF');
  1958. stream.emit('error', e);
  1959. } else if (state.endEmitted && addToFront) {
  1960. var e = new Error('stream.unshift() after end event');
  1961. stream.emit('error', e);
  1962. } else {
  1963. if (state.decoder && !addToFront && !encoding)
  1964. chunk = state.decoder.write(chunk);
  1965. // update the buffer info.
  1966. state.length += state.objectMode ? 1 : chunk.length;
  1967. if (addToFront) {
  1968. state.buffer.unshift(chunk);
  1969. } else {
  1970. state.reading = false;
  1971. state.buffer.push(chunk);
  1972. }
  1973. if (state.needReadable)
  1974. emitReadable(stream);
  1975. maybeReadMore(stream, state);
  1976. }
  1977. } else if (!addToFront) {
  1978. state.reading = false;
  1979. }
  1980. return needMoreData(state);
  1981. }
  1982. // if it's past the high water mark, we can push in some more.
  1983. // Also, if we have no data yet, we can stand some
  1984. // more bytes. This is to work around cases where hwm=0,
  1985. // such as the repl. Also, if the push() triggered a
  1986. // readable event, and the user called read(largeNumber) such that
  1987. // needReadable was set, then we ought to push more, so that another
  1988. // 'readable' event will be triggered.
  1989. function needMoreData(state) {
  1990. return !state.ended &&
  1991. (state.needReadable ||
  1992. state.length < state.highWaterMark ||
  1993. state.length === 0);
  1994. }
  1995. // backwards compatibility.
  1996. Readable.prototype.setEncoding = function(enc) {
  1997. if (!StringDecoder)
  1998. StringDecoder = require('string_decoder').StringDecoder;
  1999. this._readableState.decoder = new StringDecoder(enc);
  2000. this._readableState.encoding = enc;
  2001. };
  2002. // Don't raise the hwm > 128MB
  2003. var MAX_HWM = 0x800000;
  2004. function roundUpToNextPowerOf2(n) {
  2005. if (n >= MAX_HWM) {
  2006. n = MAX_HWM;
  2007. } else {
  2008. // Get the next highest power of 2
  2009. n--;
  2010. for (var p = 1; p < 32; p <<= 1) n |= n >> p;
  2011. n++;
  2012. }
  2013. return n;
  2014. }
  2015. function howMuchToRead(n, state) {
  2016. if (state.length === 0 && state.ended)
  2017. return 0;
  2018. if (state.objectMode)
  2019. return n === 0 ? 0 : 1;
  2020. if (isNaN(n) || n === null) {
  2021. // only flow one buffer at a time
  2022. if (state.flowing && state.buffer.length)
  2023. return state.buffer[0].length;
  2024. else
  2025. return state.length;
  2026. }
  2027. if (n <= 0)
  2028. return 0;
  2029. // If we're asking for more than the target buffer level,
  2030. // then raise the water mark. Bump up to the next highest
  2031. // power of 2, to prevent increasing it excessively in tiny
  2032. // amounts.
  2033. if (n > state.highWaterMark)
  2034. state.highWaterMark = roundUpToNextPowerOf2(n);
  2035. // don't have that much. return null, unless we've ended.
  2036. if (n > state.length) {
  2037. if (!state.ended) {
  2038. state.needReadable = true;
  2039. return 0;
  2040. } else
  2041. return state.length;
  2042. }
  2043. return n;
  2044. }
  2045. // you can override either this method, or the async _read(n) below.
  2046. Readable.prototype.read = function(n) {
  2047. var state = this._readableState;
  2048. state.calledRead = true;
  2049. var nOrig = n;
  2050. if (typeof n !== 'number' || n > 0)
  2051. state.emittedReadable = false;
  2052. // if we're doing read(0) to trigger a readable event, but we
  2053. // already have a bunch of data in the buffer, then just trigger
  2054. // the 'readable' event and move on.
  2055. if (n === 0 &&
  2056. state.needReadable &&
  2057. (state.length >= state.highWaterMark || state.ended)) {
  2058. emitReadable(this);
  2059. return null;
  2060. }
  2061. n = howMuchToRead(n, state);
  2062. // if we've ended, and we're now clear, then finish it up.
  2063. if (n === 0 && state.ended) {
  2064. if (state.length === 0)
  2065. endReadable(this);
  2066. return null;
  2067. }
  2068. // All the actual chunk generation logic needs to be
  2069. // *below* the call to _read. The reason is that in certain
  2070. // synthetic stream cases, such as passthrough streams, _read
  2071. // may be a completely synchronous operation which may change
  2072. // the state of the read buffer, providing enough data when
  2073. // before there was *not* enough.
  2074. //
  2075. // So, the steps are:
  2076. // 1. Figure out what the state of things will be after we do
  2077. // a read from the buffer.
  2078. //
  2079. // 2. If that resulting state will trigger a _read, then call _read.
  2080. // Note that this may be asynchronous, or synchronous. Yes, it is
  2081. // deeply ugly to write APIs this way, but that still doesn't mean
  2082. // that the Readable class should behave improperly, as streams are
  2083. // designed to be sync/async agnostic.
  2084. // Take note if the _read call is sync or async (ie, if the read call
  2085. // has returned yet), so that we know whether or not it's safe to emit
  2086. // 'readable' etc.
  2087. //
  2088. // 3. Actually pull the requested chunks out of the buffer and return.
  2089. // if we need a readable event, then we need to do some reading.
  2090. var doRead = state.needReadable;
  2091. // if we currently have less than the highWaterMark, then also read some
  2092. if (state.length - n <= state.highWaterMark)
  2093. doRead = true;
  2094. // however, if we've ended, then there's no point, and if we're already
  2095. // reading, then it's unnecessary.
  2096. if (state.ended || state.reading)
  2097. doRead = false;
  2098. if (doRead) {
  2099. state.reading = true;
  2100. state.sync = true;
  2101. // if the length is currently zero, then we *need* a readable event.
  2102. if (state.length === 0)
  2103. state.needReadable = true;
  2104. // call internal read method
  2105. this._read(state.highWaterMark);
  2106. state.sync = false;
  2107. }
  2108. // If _read called its callback synchronously, then `reading`
  2109. // will be false, and we need to re-evaluate how much data we
  2110. // can return to the user.
  2111. if (doRead && !state.reading)
  2112. n = howMuchToRead(nOrig, state);
  2113. var ret;
  2114. if (n > 0)
  2115. ret = fromList(n, state);
  2116. else
  2117. ret = null;
  2118. if (ret === null) {
  2119. state.needReadable = true;
  2120. n = 0;
  2121. }
  2122. state.length -= n;
  2123. // If we have nothing in the buffer, then we want to know
  2124. // as soon as we *do* get something into the buffer.
  2125. if (state.length === 0 && !state.ended)
  2126. state.needReadable = true;
  2127. // If we happened to read() exactly the remaining amount in the
  2128. // buffer, and the EOF has been seen at this point, then make sure
  2129. // that we emit 'end' on the very next tick.
  2130. if (state.ended && !state.endEmitted && state.length === 0)
  2131. endReadable(this);
  2132. return ret;
  2133. };
  2134. function chunkInvalid(state, chunk) {
  2135. var er = null;
  2136. if (!Buffer.isBuffer(chunk) &&
  2137. 'string' !== typeof chunk &&
  2138. chunk !== null &&
  2139. chunk !== undefined &&
  2140. !state.objectMode &&
  2141. !er) {
  2142. er = new TypeError('Invalid non-string/buffer chunk');
  2143. }
  2144. return er;
  2145. }
  2146. function onEofChunk(stream, state) {
  2147. if (state.decoder && !state.ended) {
  2148. var chunk = state.decoder.end();
  2149. if (chunk && chunk.length) {
  2150. state.buffer.push(chunk);
  2151. state.length += state.objectMode ? 1 : chunk.length;
  2152. }
  2153. }
  2154. state.ended = true;
  2155. // if we've ended and we have some data left, then emit
  2156. // 'readable' now to make sure it gets picked up.
  2157. if (state.length > 0)
  2158. emitReadable(stream);
  2159. else
  2160. endReadable(stream);
  2161. }
  2162. // Don't emit readable right away in sync mode, because this can trigger
  2163. // another read() call => stack overflow. This way, it might trigger
  2164. // a nextTick recursion warning, but that's not so bad.
  2165. function emitReadable(stream) {
  2166. var state = stream._readableState;
  2167. state.needReadable = false;
  2168. if (state.emittedReadable)
  2169. return;
  2170. state.emittedReadable = true;
  2171. if (state.sync)
  2172. setImmediate(function() {
  2173. emitReadable_(stream);
  2174. });
  2175. else
  2176. emitReadable_(stream);
  2177. }
  2178. function emitReadable_(stream) {
  2179. stream.emit('readable');
  2180. }
  2181. // at this point, the user has presumably seen the 'readable' event,
  2182. // and called read() to consume some data. that may have triggered
  2183. // in turn another _read(n) call, in which case reading = true if
  2184. // it's in progress.
  2185. // However, if we're not ended, or reading, and the length < hwm,
  2186. // then go ahead and try to read some more preemptively.
  2187. function maybeReadMore(stream, state) {
  2188. if (!state.readingMore) {
  2189. state.readingMore = true;
  2190. setImmediate(function() {
  2191. maybeReadMore_(stream, state);
  2192. });
  2193. }
  2194. }
  2195. function maybeReadMore_(stream, state) {
  2196. var len = state.length;
  2197. while (!state.reading && !state.flowing && !state.ended &&
  2198. state.length < state.highWaterMark) {
  2199. stream.read(0);
  2200. if (len === state.length)
  2201. // didn't get any data, stop spinning.
  2202. break;
  2203. else
  2204. len = state.length;
  2205. }
  2206. state.readingMore = false;
  2207. }
  2208. // abstract method. to be overridden in specific implementation classes.
  2209. // call cb(er, data) where data is <= n in length.
  2210. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  2211. // arbitrary, and perhaps not very meaningful.
  2212. Readable.prototype._read = function(n) {
  2213. this.emit('error', new Error('not implemented'));
  2214. };
  2215. Readable.prototype.pipe = function(dest, pipeOpts) {
  2216. var src = this;
  2217. var state = this._readableState;
  2218. switch (state.pipesCount) {
  2219. case 0:
  2220. state.pipes = dest;
  2221. break;
  2222. case 1:
  2223. state.pipes = [state.pipes, dest];
  2224. break;
  2225. default:
  2226. state.pipes.push(dest);
  2227. break;
  2228. }
  2229. state.pipesCount += 1;
  2230. var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
  2231. dest !== process.stdout &&
  2232. dest !== process.stderr;
  2233. var endFn = doEnd ? onend : cleanup;
  2234. if (state.endEmitted)
  2235. setImmediate(endFn);
  2236. else
  2237. src.once('end', endFn);
  2238. dest.on('unpipe', onunpipe);
  2239. function onunpipe(readable) {
  2240. if (readable !== src) return;
  2241. cleanup();
  2242. }
  2243. function onend() {
  2244. dest.end();
  2245. }
  2246. // when the dest drains, it reduces the awaitDrain counter
  2247. // on the source. This would be more elegant with a .once()
  2248. // handler in flow(), but adding and removing repeatedly is
  2249. // too slow.
  2250. var ondrain = pipeOnDrain(src);
  2251. dest.on('drain', ondrain);
  2252. function cleanup() {
  2253. // cleanup event handlers once the pipe is broken
  2254. dest.removeListener('close', onclose);
  2255. dest.removeListener('finish', onfinish);
  2256. dest.removeListener('drain', ondrain);
  2257. dest.removeListener('error', onerror);
  2258. dest.removeListener('unpipe', onunpipe);
  2259. src.removeListener('end', onend);
  2260. src.removeListener('end', cleanup);
  2261. // if the reader is waiting for a drain event from this
  2262. // specific writer, then it would cause it to never start
  2263. // flowing again.
  2264. // So, if this is awaiting a drain, then we just call it now.
  2265. // If we don't know, then assume that we are waiting for one.
  2266. if (!dest._writableState || dest._writableState.needDrain)
  2267. ondrain();
  2268. }
  2269. // if the dest has an error, then stop piping into it.
  2270. // however, don't suppress the throwing behavior for this.
  2271. // check for listeners before emit removes one-time listeners.
  2272. var errListeners = EE.listenerCount(dest, 'error');
  2273. function onerror(er) {
  2274. unpipe();
  2275. if (errListeners === 0 && EE.listenerCount(dest, 'error') === 0)
  2276. dest.emit('error', er);
  2277. }
  2278. dest.once('error', onerror);
  2279. // Both close and finish should trigger unpipe, but only once.
  2280. function onclose() {
  2281. dest.removeListener('finish', onfinish);
  2282. unpipe();
  2283. }
  2284. dest.once('close', onclose);
  2285. function onfinish() {
  2286. dest.removeListener('close', onclose);
  2287. unpipe();
  2288. }
  2289. dest.once('finish', onfinish);
  2290. function unpipe() {
  2291. src.unpipe(dest);
  2292. }
  2293. // tell the dest that it's being piped to
  2294. dest.emit('pipe', src);
  2295. // start the flow if it hasn't been started already.
  2296. if (!state.flowing) {
  2297. // the handler that waits for readable events after all
  2298. // the data gets sucked out in flow.
  2299. // This would be easier to follow with a .once() handler
  2300. // in flow(), but that is too slow.
  2301. this.on('readable', pipeOnReadable);
  2302. state.flowing = true;
  2303. setImmediate(function() {
  2304. flow(src);
  2305. });
  2306. }
  2307. return dest;
  2308. };
  2309. function pipeOnDrain(src) {
  2310. return function() {
  2311. var dest = this;
  2312. var state = src._readableState;
  2313. state.awaitDrain--;
  2314. if (state.awaitDrain === 0)
  2315. flow(src);
  2316. };
  2317. }
  2318. function flow(src) {
  2319. var state = src._readableState;
  2320. var chunk;
  2321. state.awaitDrain = 0;
  2322. function write(dest, i, list) {
  2323. var written = dest.write(chunk);
  2324. if (false === written) {
  2325. state.awaitDrain++;
  2326. }
  2327. }
  2328. while (state.pipesCount && null !== (chunk = src.read())) {
  2329. if (state.pipesCount === 1)
  2330. write(state.pipes, 0, null);
  2331. else
  2332. forEach(state.pipes, write);
  2333. src.emit('data', chunk);
  2334. // if anyone needs a drain, then we have to wait for that.
  2335. if (state.awaitDrain > 0)
  2336. return;
  2337. }
  2338. // if every destination was unpiped, either before entering this
  2339. // function, or in the while loop, then stop flowing.
  2340. //
  2341. // NB: This is a pretty rare edge case.
  2342. if (state.pipesCount === 0) {
  2343. state.flowing = false;
  2344. // if there were data event listeners added, then switch to old mode.
  2345. if (EE.listenerCount(src, 'data') > 0)
  2346. emitDataEvents(src);
  2347. return;
  2348. }
  2349. // at this point, no one needed a drain, so we just ran out of data
  2350. // on the next readable event, start it over again.
  2351. state.ranOut = true;
  2352. }
  2353. function pipeOnReadable() {
  2354. if (this._readableState.ranOut) {
  2355. this._readableState.ranOut = false;
  2356. flow(this);
  2357. }
  2358. }
  2359. Readable.prototype.unpipe = function(dest) {
  2360. var state = this._readableState;
  2361. // if we're not piping anywhere, then do nothing.
  2362. if (state.pipesCount === 0)
  2363. return this;
  2364. // just one destination. most common case.
  2365. if (state.pipesCount === 1) {
  2366. // passed in one, but it's not the right one.
  2367. if (dest && dest !== state.pipes)
  2368. return this;
  2369. if (!dest)
  2370. dest = state.pipes;
  2371. // got a match.
  2372. state.pipes = null;
  2373. state.pipesCount = 0;
  2374. this.removeListener('readable', pipeOnReadable);
  2375. state.flowing = false;
  2376. if (dest)
  2377. dest.emit('unpipe', this);
  2378. return this;
  2379. }
  2380. // slow case. multiple pipe destinations.
  2381. if (!dest) {
  2382. // remove all.
  2383. var dests = state.pipes;
  2384. var len = state.pipesCount;
  2385. state.pipes = null;
  2386. state.pipesCount = 0;
  2387. this.removeListener('readable', pipeOnReadable);
  2388. state.flowing = false;
  2389. for (var i = 0; i < len; i++)
  2390. dests[i].emit('unpipe', this);
  2391. return this;
  2392. }
  2393. // try to find the right one.
  2394. var i = indexOf(state.pipes, dest);
  2395. if (i === -1)
  2396. return this;
  2397. state.pipes.splice(i, 1);
  2398. state.pipesCount -= 1;
  2399. if (state.pipesCount === 1)
  2400. state.pipes = state.pipes[0];
  2401. dest.emit('unpipe', this);
  2402. return this;
  2403. };
  2404. // set up data events if they are asked for
  2405. // Ensure readable listeners eventually get something
  2406. Readable.prototype.on = function(ev, fn) {
  2407. var res = Stream.prototype.on.call(this, ev, fn);
  2408. if (ev === 'data' && !this._readableState.flowing)
  2409. emitDataEvents(this);
  2410. if (ev === 'readable' && this.readable) {
  2411. var state = this._readableState;
  2412. if (!state.readableListening) {
  2413. state.readableListening = true;
  2414. state.emittedReadable = false;
  2415. state.needReadable = true;
  2416. if (!state.reading) {
  2417. this.read(0);
  2418. } else if (state.length) {
  2419. emitReadable(this, state);
  2420. }
  2421. }
  2422. }
  2423. return res;
  2424. };
  2425. Readable.prototype.addListener = Readable.prototype.on;
  2426. // pause() and resume() are remnants of the legacy readable stream API
  2427. // If the user uses them, then switch into old mode.
  2428. Readable.prototype.resume = function() {
  2429. emitDataEvents(this);
  2430. this.read(0);
  2431. this.emit('resume');
  2432. };
  2433. Readable.prototype.pause = function() {
  2434. emitDataEvents(this, true);
  2435. this.emit('pause');
  2436. };
  2437. function emitDataEvents(stream, startPaused) {
  2438. var state = stream._readableState;
  2439. if (state.flowing) {
  2440. // https://github.com/isaacs/readable-stream/issues/16
  2441. throw new Error('Cannot switch to old mode now.');
  2442. }
  2443. var paused = startPaused || false;
  2444. var readable = false;
  2445. // convert to an old-style stream.
  2446. stream.readable = true;
  2447. stream.pipe = Stream.prototype.pipe;
  2448. stream.on = stream.addListener = Stream.prototype.on;
  2449. stream.on('readable', function() {
  2450. readable = true;
  2451. var c;
  2452. while (!paused && (null !== (c = stream.read())))
  2453. stream.emit('data', c);
  2454. if (c === null) {
  2455. readable = false;
  2456. stream._readableState.needReadable = true;
  2457. }
  2458. });
  2459. stream.pause = function() {
  2460. paused = true;
  2461. this.emit('pause');
  2462. };
  2463. stream.resume = function() {
  2464. paused = false;
  2465. if (readable)
  2466. setImmediate(function() {
  2467. stream.emit('readable');
  2468. });
  2469. else
  2470. this.read(0);
  2471. this.emit('resume');
  2472. };
  2473. // now make it start, just in case it hadn't already.
  2474. stream.emit('readable');
  2475. }
  2476. // wrap an old-style stream as the async data source.
  2477. // This is *not* part of the readable stream interface.
  2478. // It is an ugly unfortunate mess of history.
  2479. Readable.prototype.wrap = function(stream) {
  2480. var state = this._readableState;
  2481. var paused = false;
  2482. var self = this;
  2483. stream.on('end', function() {
  2484. if (state.decoder && !state.ended) {
  2485. var chunk = state.decoder.end();
  2486. if (chunk && chunk.length)
  2487. self.push(chunk);
  2488. }
  2489. self.push(null);
  2490. });
  2491. stream.on('data', function(chunk) {
  2492. if (state.decoder)
  2493. chunk = state.decoder.write(chunk);
  2494. if (!chunk || !state.objectMode && !chunk.length)
  2495. return;
  2496. var ret = self.push(chunk);
  2497. if (!ret) {
  2498. paused = true;
  2499. stream.pause();
  2500. }
  2501. });
  2502. // proxy all the other methods.
  2503. // important when wrapping filters and duplexes.
  2504. for (var i in stream) {
  2505. if (typeof stream[i] === 'function' &&
  2506. typeof this[i] === 'undefined') {
  2507. this[i] = function(method) { return function() {
  2508. return stream[method].apply(stream, arguments);
  2509. }}(i);
  2510. }
  2511. }
  2512. // proxy certain important events.
  2513. var events = ['error', 'close', 'destroy', 'pause', 'resume'];
  2514. forEach(events, function(ev) {
  2515. stream.on(ev, function (x) {
  2516. return self.emit.apply(self, ev, x);
  2517. });
  2518. });
  2519. // when we try to consume some more bytes, simply unpause the
  2520. // underlying stream.
  2521. self._read = function(n) {
  2522. if (paused) {
  2523. paused = false;
  2524. stream.resume();
  2525. }
  2526. };
  2527. return self;
  2528. };
  2529. // exposed for testing purposes only.
  2530. Readable._fromList = fromList;
  2531. // Pluck off n bytes from an array of buffers.
  2532. // Length is the combined lengths of all the buffers in the list.
  2533. function fromList(n, state) {
  2534. var list = state.buffer;
  2535. var length = state.length;
  2536. var stringMode = !!state.decoder;
  2537. var objectMode = !!state.objectMode;
  2538. var ret;
  2539. // nothing in the list, definitely empty.
  2540. if (list.length === 0)
  2541. return null;
  2542. if (length === 0)
  2543. ret = null;
  2544. else if (objectMode)
  2545. ret = list.shift();
  2546. else if (!n || n >= length) {
  2547. // read it all, truncate the array.
  2548. if (stringMode)
  2549. ret = list.join('');
  2550. else
  2551. ret = Buffer.concat(list, length);
  2552. list.length = 0;
  2553. } else {
  2554. // read just some of it.
  2555. if (n < list[0].length) {
  2556. // just take a part of the first list item.
  2557. // slice is the same for buffers and strings.
  2558. var buf = list[0];
  2559. ret = buf.slice(0, n);
  2560. list[0] = buf.slice(n);
  2561. } else if (n === list[0].length) {
  2562. // first list is a perfect match
  2563. ret = list.shift();
  2564. } else {
  2565. // complex case.
  2566. // we have enough to cover it, but it spans past the first buffer.
  2567. if (stringMode)
  2568. ret = '';
  2569. else
  2570. ret = new Buffer(n);
  2571. var c = 0;
  2572. for (var i = 0, l = list.length; i < l && c < n; i++) {
  2573. var buf = list[0];
  2574. var cpy = Math.min(n - c, buf.length);
  2575. if (stringMode)
  2576. ret += buf.slice(0, cpy);
  2577. else
  2578. buf.copy(ret, c, 0, cpy);
  2579. if (cpy < buf.length)
  2580. list[0] = buf.slice(cpy);
  2581. else
  2582. list.shift();
  2583. c += cpy;
  2584. }
  2585. }
  2586. }
  2587. return ret;
  2588. }
  2589. function endReadable(stream) {
  2590. var state = stream._readableState;
  2591. // If we get here before consuming all the bytes, then that is a
  2592. // bug in node. Should never happen.
  2593. if (state.length > 0)
  2594. throw new Error('endReadable called on non-empty stream');
  2595. if (!state.endEmitted && state.calledRead) {
  2596. state.ended = true;
  2597. setImmediate(function() {
  2598. // Check that we didn't get one last unshift.
  2599. if (!state.endEmitted && state.length === 0) {
  2600. state.endEmitted = true;
  2601. stream.readable = false;
  2602. stream.emit('end');
  2603. }
  2604. });
  2605. }
  2606. }
  2607. function forEach (xs, f) {
  2608. for (var i = 0, l = xs.length; i < l; i++) {
  2609. f(xs[i], i);
  2610. }
  2611. }
  2612. function indexOf (xs, x) {
  2613. for (var i = 0, l = xs.length; i < l; i++) {
  2614. if (xs[i] === x) return i;
  2615. }
  2616. return -1;
  2617. }
  2618. }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
  2619. },{"./index.js":9,"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"buffer":1,"events":4,"inherits":5,"process/browser.js":10,"string_decoder":15}],13:[function(require,module,exports){
  2620. // Copyright Joyent, Inc. and other Node contributors.
  2621. //
  2622. // Permission is hereby granted, free of charge, to any person obtaining a
  2623. // copy of this software and associated documentation files (the
  2624. // "Software"), to deal in the Software without restriction, including
  2625. // without limitation the rights to use, copy, modify, merge, publish,
  2626. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2627. // persons to whom the Software is furnished to do so, subject to the
  2628. // following conditions:
  2629. //
  2630. // The above copyright notice and this permission notice shall be included
  2631. // in all copies or substantial portions of the Software.
  2632. //
  2633. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2634. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2635. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2636. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2637. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2638. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2639. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2640. // a transform stream is a readable/writable stream where you do
  2641. // something with the data. Sometimes it's called a "filter",
  2642. // but that's not a great name for it, since that implies a thing where
  2643. // some bits pass through, and others are simply ignored. (That would
  2644. // be a valid example of a transform, of course.)
  2645. //
  2646. // While the output is causally related to the input, it's not a
  2647. // necessarily symmetric or synchronous transformation. For example,
  2648. // a zlib stream might take multiple plain-text writes(), and then
  2649. // emit a single compressed chunk some time in the future.
  2650. //
  2651. // Here's how this works:
  2652. //
  2653. // The Transform stream has all the aspects of the readable and writable
  2654. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  2655. // internally, and returns false if there's a lot of pending writes
  2656. // buffered up. When you call read(), that calls _read(n) until
  2657. // there's enough pending readable data buffered up.
  2658. //
  2659. // In a transform stream, the written data is placed in a buffer. When
  2660. // _read(n) is called, it transforms the queued up data, calling the
  2661. // buffered _write cb's as it consumes chunks. If consuming a single
  2662. // written chunk would result in multiple output chunks, then the first
  2663. // outputted bit calls the readcb, and subsequent chunks just go into
  2664. // the read buffer, and will cause it to emit 'readable' if necessary.
  2665. //
  2666. // This way, back-pressure is actually determined by the reading side,
  2667. // since _read has to be called to start processing a new chunk. However,
  2668. // a pathological inflate type of transform can cause excessive buffering
  2669. // here. For example, imagine a stream where every byte of input is
  2670. // interpreted as an integer from 0-255, and then results in that many
  2671. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  2672. // 1kb of data being output. In this case, you could write a very small
  2673. // amount of input, and end up with a very large amount of output. In
  2674. // such a pathological inflating mechanism, there'd be no way to tell
  2675. // the system to stop doing the transform. A single 4MB write could
  2676. // cause the system to run out of memory.
  2677. //
  2678. // However, even in such a pathological case, only a single written chunk
  2679. // would be consumed, and then the rest would wait (un-transformed) until
  2680. // the results of the previous transformed chunk were consumed.
  2681. module.exports = Transform;
  2682. var Duplex = require('./duplex.js');
  2683. var inherits = require('inherits');
  2684. inherits(Transform, Duplex);
  2685. function TransformState(options, stream) {
  2686. this.afterTransform = function(er, data) {
  2687. return afterTransform(stream, er, data);
  2688. };
  2689. this.needTransform = false;
  2690. this.transforming = false;
  2691. this.writecb = null;
  2692. this.writechunk = null;
  2693. }
  2694. function afterTransform(stream, er, data) {
  2695. var ts = stream._transformState;
  2696. ts.transforming = false;
  2697. var cb = ts.writecb;
  2698. if (!cb)
  2699. return stream.emit('error', new Error('no writecb in Transform class'));
  2700. ts.writechunk = null;
  2701. ts.writecb = null;
  2702. if (data !== null && data !== undefined)
  2703. stream.push(data);
  2704. if (cb)
  2705. cb(er);
  2706. var rs = stream._readableState;
  2707. rs.reading = false;
  2708. if (rs.needReadable || rs.length < rs.highWaterMark) {
  2709. stream._read(rs.highWaterMark);
  2710. }
  2711. }
  2712. function Transform(options) {
  2713. if (!(this instanceof Transform))
  2714. return new Transform(options);
  2715. Duplex.call(this, options);
  2716. var ts = this._transformState = new TransformState(options, this);
  2717. // when the writable side finishes, then flush out anything remaining.
  2718. var stream = this;
  2719. // start out asking for a readable event once data is transformed.
  2720. this._readableState.needReadable = true;
  2721. // we have implemented the _read method, and done the other things
  2722. // that Readable wants before the first _read call, so unset the
  2723. // sync guard flag.
  2724. this._readableState.sync = false;
  2725. this.once('finish', function() {
  2726. if ('function' === typeof this._flush)
  2727. this._flush(function(er) {
  2728. done(stream, er);
  2729. });
  2730. else
  2731. done(stream);
  2732. });
  2733. }
  2734. Transform.prototype.push = function(chunk, encoding) {
  2735. this._transformState.needTransform = false;
  2736. return Duplex.prototype.push.call(this, chunk, encoding);
  2737. };
  2738. // This is the part where you do stuff!
  2739. // override this function in implementation classes.
  2740. // 'chunk' is an input chunk.
  2741. //
  2742. // Call `push(newChunk)` to pass along transformed output
  2743. // to the readable side. You may call 'push' zero or more times.
  2744. //
  2745. // Call `cb(err)` when you are done with this chunk. If you pass
  2746. // an error, then that'll put the hurt on the whole operation. If you
  2747. // never call cb(), then you'll never get another chunk.
  2748. Transform.prototype._transform = function(chunk, encoding, cb) {
  2749. throw new Error('not implemented');
  2750. };
  2751. Transform.prototype._write = function(chunk, encoding, cb) {
  2752. var ts = this._transformState;
  2753. ts.writecb = cb;
  2754. ts.writechunk = chunk;
  2755. ts.writeencoding = encoding;
  2756. if (!ts.transforming) {
  2757. var rs = this._readableState;
  2758. if (ts.needTransform ||
  2759. rs.needReadable ||
  2760. rs.length < rs.highWaterMark)
  2761. this._read(rs.highWaterMark);
  2762. }
  2763. };
  2764. // Doesn't matter what the args are here.
  2765. // _transform does all the work.
  2766. // That we got here means that the readable side wants more data.
  2767. Transform.prototype._read = function(n) {
  2768. var ts = this._transformState;
  2769. if (ts.writechunk && ts.writecb && !ts.transforming) {
  2770. ts.transforming = true;
  2771. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  2772. } else {
  2773. // mark that we need a transform, so that any data that comes in
  2774. // will get processed, now that we've asked for it.
  2775. ts.needTransform = true;
  2776. }
  2777. };
  2778. function done(stream, er) {
  2779. if (er)
  2780. return stream.emit('error', er);
  2781. // if there's nothing in the write buffer, then that means
  2782. // that nothing more will ever be provided
  2783. var ws = stream._writableState;
  2784. var rs = stream._readableState;
  2785. var ts = stream._transformState;
  2786. if (ws.length)
  2787. throw new Error('calling transform done when ws.length != 0');
  2788. if (ts.transforming)
  2789. throw new Error('calling transform done when still transforming');
  2790. return stream.push(null);
  2791. }
  2792. },{"./duplex.js":8,"inherits":5}],14:[function(require,module,exports){
  2793. // Copyright Joyent, Inc. and other Node contributors.
  2794. //
  2795. // Permission is hereby granted, free of charge, to any person obtaining a
  2796. // copy of this software and associated documentation files (the
  2797. // "Software"), to deal in the Software without restriction, including
  2798. // without limitation the rights to use, copy, modify, merge, publish,
  2799. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2800. // persons to whom the Software is furnished to do so, subject to the
  2801. // following conditions:
  2802. //
  2803. // The above copyright notice and this permission notice shall be included
  2804. // in all copies or substantial portions of the Software.
  2805. //
  2806. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2807. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2808. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2809. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2810. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2811. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2812. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2813. // A bit simpler than readable streams.
  2814. // Implement an async ._write(chunk, cb), and it'll handle all
  2815. // the drain event emission and buffering.
  2816. module.exports = Writable;
  2817. Writable.WritableState = WritableState;
  2818. var isUint8Array = typeof Uint8Array !== 'undefined'
  2819. ? function (x) { return x instanceof Uint8Array }
  2820. : function (x) {
  2821. return x && x.constructor && x.constructor.name === 'Uint8Array'
  2822. }
  2823. ;
  2824. var isArrayBuffer = typeof ArrayBuffer !== 'undefined'
  2825. ? function (x) { return x instanceof ArrayBuffer }
  2826. : function (x) {
  2827. return x && x.constructor && x.constructor.name === 'ArrayBuffer'
  2828. }
  2829. ;
  2830. var inherits = require('inherits');
  2831. var Stream = require('./index.js');
  2832. var setImmediate = require('process/browser.js').nextTick;
  2833. var Buffer = require('buffer').Buffer;
  2834. inherits(Writable, Stream);
  2835. function WriteReq(chunk, encoding, cb) {
  2836. this.chunk = chunk;
  2837. this.encoding = encoding;
  2838. this.callback = cb;
  2839. }
  2840. function WritableState(options, stream) {
  2841. options = options || {};
  2842. // the point at which write() starts returning false
  2843. // Note: 0 is a valid value, means that we always return false if
  2844. // the entire buffer is not flushed immediately on write()
  2845. var hwm = options.highWaterMark;
  2846. this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
  2847. // object stream flag to indicate whether or not this stream
  2848. // contains buffers or objects.
  2849. this.objectMode = !!options.objectMode;
  2850. // cast to ints.
  2851. this.highWaterMark = ~~this.highWaterMark;
  2852. this.needDrain = false;
  2853. // at the start of calling end()
  2854. this.ending = false;
  2855. // when end() has been called, and returned
  2856. this.ended = false;
  2857. // when 'finish' is emitted
  2858. this.finished = false;
  2859. // should we decode strings into buffers before passing to _write?
  2860. // this is here so that some node-core streams can optimize string
  2861. // handling at a lower level.
  2862. var noDecode = options.decodeStrings === false;
  2863. this.decodeStrings = !noDecode;
  2864. // Crypto is kind of old and crusty. Historically, its default string
  2865. // encoding is 'binary' so we have to make this configurable.
  2866. // Everything else in the universe uses 'utf8', though.
  2867. this.defaultEncoding = options.defaultEncoding || 'utf8';
  2868. // not an actual buffer we keep track of, but a measurement
  2869. // of how much we're waiting to get pushed to some underlying
  2870. // socket or file.
  2871. this.length = 0;
  2872. // a flag to see when we're in the middle of a write.
  2873. this.writing = false;
  2874. // a flag to be able to tell if the onwrite cb is called immediately,
  2875. // or on a later tick. We set this to true at first, becuase any
  2876. // actions that shouldn't happen until "later" should generally also
  2877. // not happen before the first write call.
  2878. this.sync = true;
  2879. // a flag to know if we're processing previously buffered items, which
  2880. // may call the _write() callback in the same tick, so that we don't
  2881. // end up in an overlapped onwrite situation.
  2882. this.bufferProcessing = false;
  2883. // the callback that's passed to _write(chunk,cb)
  2884. this.onwrite = function(er) {
  2885. onwrite(stream, er);
  2886. };
  2887. // the callback that the user supplies to write(chunk,encoding,cb)
  2888. this.writecb = null;
  2889. // the amount that is being written when _write is called.
  2890. this.writelen = 0;
  2891. this.buffer = [];
  2892. }
  2893. function Writable(options) {
  2894. // Writable ctor is applied to Duplexes, though they're not
  2895. // instanceof Writable, they're instanceof Readable.
  2896. if (!(this instanceof Writable) && !(this instanceof Stream.Duplex))
  2897. return new Writable(options);
  2898. this._writableState = new WritableState(options, this);
  2899. // legacy.
  2900. this.writable = true;
  2901. Stream.call(this);
  2902. }
  2903. // Otherwise people can pipe Writable streams, which is just wrong.
  2904. Writable.prototype.pipe = function() {
  2905. this.emit('error', new Error('Cannot pipe. Not readable.'));
  2906. };
  2907. function writeAfterEnd(stream, state, cb) {
  2908. var er = new Error('write after end');
  2909. // TODO: defer error events consistently everywhere, not just the cb
  2910. stream.emit('error', er);
  2911. setImmediate(function() {
  2912. cb(er);
  2913. });
  2914. }
  2915. // If we get something that is not a buffer, string, null, or undefined,
  2916. // and we're not in objectMode, then that's an error.
  2917. // Otherwise stream chunks are all considered to be of length=1, and the
  2918. // watermarks determine how many objects to keep in the buffer, rather than
  2919. // how many bytes or characters.
  2920. function validChunk(stream, state, chunk, cb) {
  2921. var valid = true;
  2922. if (!Buffer.isBuffer(chunk) &&
  2923. 'string' !== typeof chunk &&
  2924. chunk !== null &&
  2925. chunk !== undefined &&
  2926. !state.objectMode) {
  2927. var er = new TypeError('Invalid non-string/buffer chunk');
  2928. stream.emit('error', er);
  2929. setImmediate(function() {
  2930. cb(er);
  2931. });
  2932. valid = false;
  2933. }
  2934. return valid;
  2935. }
  2936. Writable.prototype.write = function(chunk, encoding, cb) {
  2937. var state = this._writableState;
  2938. var ret = false;
  2939. if (typeof encoding === 'function') {
  2940. cb = encoding;
  2941. encoding = null;
  2942. }
  2943. if (!Buffer.isBuffer(chunk) && isUint8Array(chunk))
  2944. chunk = new Buffer(chunk);
  2945. if (isArrayBuffer(chunk) && typeof Uint8Array !== 'undefined')
  2946. chunk = new Buffer(new Uint8Array(chunk));
  2947. if (Buffer.isBuffer(chunk))
  2948. encoding = 'buffer';
  2949. else if (!encoding)
  2950. encoding = state.defaultEncoding;
  2951. if (typeof cb !== 'function')
  2952. cb = function() {};
  2953. if (state.ended)
  2954. writeAfterEnd(this, state, cb);
  2955. else if (validChunk(this, state, chunk, cb))
  2956. ret = writeOrBuffer(this, state, chunk, encoding, cb);
  2957. return ret;
  2958. };
  2959. function decodeChunk(state, chunk, encoding) {
  2960. if (!state.objectMode &&
  2961. state.decodeStrings !== false &&
  2962. typeof chunk === 'string') {
  2963. chunk = new Buffer(chunk, encoding);
  2964. }
  2965. return chunk;
  2966. }
  2967. // if we're already writing something, then just put this
  2968. // in the queue, and wait our turn. Otherwise, call _write
  2969. // If we return false, then we need a drain event, so set that flag.
  2970. function writeOrBuffer(stream, state, chunk, encoding, cb) {
  2971. chunk = decodeChunk(state, chunk, encoding);
  2972. var len = state.objectMode ? 1 : chunk.length;
  2973. state.length += len;
  2974. var ret = state.length < state.highWaterMark;
  2975. state.needDrain = !ret;
  2976. if (state.writing)
  2977. state.buffer.push(new WriteReq(chunk, encoding, cb));
  2978. else
  2979. doWrite(stream, state, len, chunk, encoding, cb);
  2980. return ret;
  2981. }
  2982. function doWrite(stream, state, len, chunk, encoding, cb) {
  2983. state.writelen = len;
  2984. state.writecb = cb;
  2985. state.writing = true;
  2986. state.sync = true;
  2987. stream._write(chunk, encoding, state.onwrite);
  2988. state.sync = false;
  2989. }
  2990. function onwriteError(stream, state, sync, er, cb) {
  2991. if (sync)
  2992. setImmediate(function() {
  2993. cb(er);
  2994. });
  2995. else
  2996. cb(er);
  2997. stream.emit('error', er);
  2998. }
  2999. function onwriteStateUpdate(state) {
  3000. state.writing = false;
  3001. state.writecb = null;
  3002. state.length -= state.writelen;
  3003. state.writelen = 0;
  3004. }
  3005. function onwrite(stream, er) {
  3006. var state = stream._writableState;
  3007. var sync = state.sync;
  3008. var cb = state.writecb;
  3009. onwriteStateUpdate(state);
  3010. if (er)
  3011. onwriteError(stream, state, sync, er, cb);
  3012. else {
  3013. // Check if we're actually ready to finish, but don't emit yet
  3014. var finished = needFinish(stream, state);
  3015. if (!finished && !state.bufferProcessing && state.buffer.length)
  3016. clearBuffer(stream, state);
  3017. if (sync) {
  3018. setImmediate(function() {
  3019. afterWrite(stream, state, finished, cb);
  3020. });
  3021. } else {
  3022. afterWrite(stream, state, finished, cb);
  3023. }
  3024. }
  3025. }
  3026. function afterWrite(stream, state, finished, cb) {
  3027. if (!finished)
  3028. onwriteDrain(stream, state);
  3029. cb();
  3030. if (finished)
  3031. finishMaybe(stream, state);
  3032. }
  3033. // Must force callback to be called on nextTick, so that we don't
  3034. // emit 'drain' before the write() consumer gets the 'false' return
  3035. // value, and has a chance to attach a 'drain' listener.
  3036. function onwriteDrain(stream, state) {
  3037. if (state.length === 0 && state.needDrain) {
  3038. state.needDrain = false;
  3039. stream.emit('drain');
  3040. }
  3041. }
  3042. // if there's something in the buffer waiting, then process it
  3043. function clearBuffer(stream, state) {
  3044. state.bufferProcessing = true;
  3045. for (var c = 0; c < state.buffer.length; c++) {
  3046. var entry = state.buffer[c];
  3047. var chunk = entry.chunk;
  3048. var encoding = entry.encoding;
  3049. var cb = entry.callback;
  3050. var len = state.objectMode ? 1 : chunk.length;
  3051. doWrite(stream, state, len, chunk, encoding, cb);
  3052. // if we didn't call the onwrite immediately, then
  3053. // it means that we need to wait until it does.
  3054. // also, that means that the chunk and cb are currently
  3055. // being processed, so move the buffer counter past them.
  3056. if (state.writing) {
  3057. c++;
  3058. break;
  3059. }
  3060. }
  3061. state.bufferProcessing = false;
  3062. if (c < state.buffer.length)
  3063. state.buffer = state.buffer.slice(c);
  3064. else
  3065. state.buffer.length = 0;
  3066. }
  3067. Writable.prototype._write = function(chunk, encoding, cb) {
  3068. cb(new Error('not implemented'));
  3069. };
  3070. Writable.prototype.end = function(chunk, encoding, cb) {
  3071. var state = this._writableState;
  3072. if (typeof chunk === 'function') {
  3073. cb = chunk;
  3074. chunk = null;
  3075. encoding = null;
  3076. } else if (typeof encoding === 'function') {
  3077. cb = encoding;
  3078. encoding = null;
  3079. }
  3080. if (typeof chunk !== 'undefined' && chunk !== null)
  3081. this.write(chunk, encoding);
  3082. // ignore unnecessary end() calls.
  3083. if (!state.ending && !state.finished)
  3084. endWritable(this, state, cb);
  3085. };
  3086. function needFinish(stream, state) {
  3087. return (state.ending &&
  3088. state.length === 0 &&
  3089. !state.finished &&
  3090. !state.writing);
  3091. }
  3092. function finishMaybe(stream, state) {
  3093. var need = needFinish(stream, state);
  3094. if (need) {
  3095. state.finished = true;
  3096. stream.emit('finish');
  3097. }
  3098. return need;
  3099. }
  3100. function endWritable(stream, state, cb) {
  3101. state.ending = true;
  3102. finishMaybe(stream, state);
  3103. if (cb) {
  3104. if (state.finished)
  3105. setImmediate(cb);
  3106. else
  3107. stream.once('finish', cb);
  3108. }
  3109. state.ended = true;
  3110. }
  3111. },{"./index.js":9,"buffer":1,"inherits":5,"process/browser.js":10}],15:[function(require,module,exports){
  3112. // Copyright Joyent, Inc. and other Node contributors.
  3113. //
  3114. // Permission is hereby granted, free of charge, to any person obtaining a
  3115. // copy of this software and associated documentation files (the
  3116. // "Software"), to deal in the Software without restriction, including
  3117. // without limitation the rights to use, copy, modify, merge, publish,
  3118. // distribute, sublicense, and/or sell copies of the Software, and to permit
  3119. // persons to whom the Software is furnished to do so, subject to the
  3120. // following conditions:
  3121. //
  3122. // The above copyright notice and this permission notice shall be included
  3123. // in all copies or substantial portions of the Software.
  3124. //
  3125. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3126. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3127. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  3128. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  3129. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  3130. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  3131. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  3132. var Buffer = require('buffer').Buffer;
  3133. function assertEncoding(encoding) {
  3134. if (encoding && !Buffer.isEncoding(encoding)) {
  3135. throw new Error('Unknown encoding: ' + encoding);
  3136. }
  3137. }
  3138. var StringDecoder = exports.StringDecoder = function(encoding) {
  3139. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  3140. assertEncoding(encoding);
  3141. switch (this.encoding) {
  3142. case 'utf8':
  3143. // CESU-8 represents each of Surrogate Pair by 3-bytes
  3144. this.surrogateSize = 3;
  3145. break;
  3146. case 'ucs2':
  3147. case 'utf16le':
  3148. // UTF-16 represents each of Surrogate Pair by 2-bytes
  3149. this.surrogateSize = 2;
  3150. this.detectIncompleteChar = utf16DetectIncompleteChar;
  3151. break;
  3152. case 'base64':
  3153. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  3154. this.surrogateSize = 3;
  3155. this.detectIncompleteChar = base64DetectIncompleteChar;
  3156. break;
  3157. default:
  3158. this.write = passThroughWrite;
  3159. return;
  3160. }
  3161. this.charBuffer = new Buffer(6);
  3162. this.charReceived = 0;
  3163. this.charLength = 0;
  3164. };
  3165. StringDecoder.prototype.write = function(buffer) {
  3166. var charStr = '';
  3167. var offset = 0;
  3168. // if our last write ended with an incomplete multibyte character
  3169. while (this.charLength) {
  3170. // determine how many remaining bytes this buffer has to offer for this char
  3171. var i = (buffer.length >= this.charLength - this.charReceived) ?
  3172. this.charLength - this.charReceived :
  3173. buffer.length;
  3174. // add the new bytes to the char buffer
  3175. buffer.copy(this.charBuffer, this.charReceived, offset, i);
  3176. this.charReceived += (i - offset);
  3177. offset = i;
  3178. if (this.charReceived < this.charLength) {
  3179. // still not enough chars in this buffer? wait for more ...
  3180. return '';
  3181. }
  3182. // get the character that was split
  3183. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  3184. // lead surrogate (D800-DBFF) is also the incomplete character
  3185. var charCode = charStr.charCodeAt(charStr.length - 1);
  3186. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  3187. this.charLength += this.surrogateSize;
  3188. charStr = '';
  3189. continue;
  3190. }
  3191. this.charReceived = this.charLength = 0;
  3192. // if there are no more bytes in this buffer, just emit our char
  3193. if (i == buffer.length) return charStr;
  3194. // otherwise cut off the characters end from the beginning of this buffer
  3195. buffer = buffer.slice(i, buffer.length);
  3196. break;
  3197. }
  3198. var lenIncomplete = this.detectIncompleteChar(buffer);
  3199. var end = buffer.length;
  3200. if (this.charLength) {
  3201. // buffer the incomplete character bytes we got
  3202. buffer.copy(this.charBuffer, 0, buffer.length - lenIncomplete, end);
  3203. this.charReceived = lenIncomplete;
  3204. end -= lenIncomplete;
  3205. }
  3206. charStr += buffer.toString(this.encoding, 0, end);
  3207. var end = charStr.length - 1;
  3208. var charCode = charStr.charCodeAt(end);
  3209. // lead surrogate (D800-DBFF) is also the incomplete character
  3210. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  3211. var size = this.surrogateSize;
  3212. this.charLength += size;
  3213. this.charReceived += size;
  3214. this.charBuffer.copy(this.charBuffer, size, 0, size);
  3215. this.charBuffer.write(charStr.charAt(charStr.length - 1), this.encoding);
  3216. return charStr.substring(0, end);
  3217. }
  3218. // or just emit the charStr
  3219. return charStr;
  3220. };
  3221. StringDecoder.prototype.detectIncompleteChar = function(buffer) {
  3222. // determine how many bytes we have to check at the end of this buffer
  3223. var i = (buffer.length >= 3) ? 3 : buffer.length;
  3224. // Figure out if one of the last i bytes of our buffer announces an
  3225. // incomplete char.
  3226. for (; i > 0; i--) {
  3227. var c = buffer[buffer.length - i];
  3228. // See http://en.wikipedia.org/wiki/UTF-8#Description
  3229. // 110XXXXX
  3230. if (i == 1 && c >> 5 == 0x06) {
  3231. this.charLength = 2;
  3232. break;
  3233. }
  3234. // 1110XXXX
  3235. if (i <= 2 && c >> 4 == 0x0E) {
  3236. this.charLength = 3;
  3237. break;
  3238. }
  3239. // 11110XXX
  3240. if (i <= 3 && c >> 3 == 0x1E) {
  3241. this.charLength = 4;
  3242. break;
  3243. }
  3244. }
  3245. return i;
  3246. };
  3247. StringDecoder.prototype.end = function(buffer) {
  3248. var res = '';
  3249. if (buffer && buffer.length)
  3250. res = this.write(buffer);
  3251. if (this.charReceived) {
  3252. var cr = this.charReceived;
  3253. var buf = this.charBuffer;
  3254. var enc = this.encoding;
  3255. res += buf.slice(0, cr).toString(enc);
  3256. }
  3257. return res;
  3258. };
  3259. function passThroughWrite(buffer) {
  3260. return buffer.toString(this.encoding);
  3261. }
  3262. function utf16DetectIncompleteChar(buffer) {
  3263. var incomplete = this.charReceived = buffer.length % 2;
  3264. this.charLength = incomplete ? 2 : 0;
  3265. return incomplete;
  3266. }
  3267. function base64DetectIncompleteChar(buffer) {
  3268. var incomplete = this.charReceived = buffer.length % 3;
  3269. this.charLength = incomplete ? 3 : 0;
  3270. return incomplete;
  3271. }
  3272. },{"buffer":1}],16:[function(require,module,exports){
  3273. module.exports = function isBuffer(arg) {
  3274. return arg && typeof arg === 'object'
  3275. && typeof arg.copy === 'function'
  3276. && typeof arg.fill === 'function'
  3277. && typeof arg.readUInt8 === 'function';
  3278. }
  3279. },{}],17:[function(require,module,exports){
  3280. (function (process,global){
  3281. // Copyright Joyent, Inc. and other Node contributors.
  3282. //
  3283. // Permission is hereby granted, free of charge, to any person obtaining a
  3284. // copy of this software and associated documentation files (the
  3285. // "Software"), to deal in the Software without restriction, including
  3286. // without limitation the rights to use, copy, modify, merge, publish,
  3287. // distribute, sublicense, and/or sell copies of the Software, and to permit
  3288. // persons to whom the Software is furnished to do so, subject to the
  3289. // following conditions:
  3290. //
  3291. // The above copyright notice and this permission notice shall be included
  3292. // in all copies or substantial portions of the Software.
  3293. //
  3294. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3295. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3296. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  3297. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  3298. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  3299. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  3300. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  3301. var formatRegExp = /%[sdj%]/g;
  3302. exports.format = function(f) {
  3303. if (!isString(f)) {
  3304. var objects = [];
  3305. for (var i = 0; i < arguments.length; i++) {
  3306. objects.push(inspect(arguments[i]));
  3307. }
  3308. return objects.join(' ');
  3309. }
  3310. var i = 1;
  3311. var args = arguments;
  3312. var len = args.length;
  3313. var str = String(f).replace(formatRegExp, function(x) {
  3314. if (x === '%%') return '%';
  3315. if (i >= len) return x;
  3316. switch (x) {
  3317. case '%s': return String(args[i++]);
  3318. case '%d': return Number(args[i++]);
  3319. case '%j':
  3320. try {
  3321. return JSON.stringify(args[i++]);
  3322. } catch (_) {
  3323. return '[Circular]';
  3324. }
  3325. default:
  3326. return x;
  3327. }
  3328. });
  3329. for (var x = args[i]; i < len; x = args[++i]) {
  3330. if (isNull(x) || !isObject(x)) {
  3331. str += ' ' + x;
  3332. } else {
  3333. str += ' ' + inspect(x);
  3334. }
  3335. }
  3336. return str;
  3337. };
  3338. // Mark that a method should not be used.
  3339. // Returns a modified function which warns once by default.
  3340. // If --no-deprecation is set, then it is a no-op.
  3341. exports.deprecate = function(fn, msg) {
  3342. // Allow for deprecating things in the process of starting up.
  3343. if (isUndefined(global.process)) {
  3344. return function() {
  3345. return exports.deprecate(fn, msg).apply(this, arguments);
  3346. };
  3347. }
  3348. if (process.noDeprecation === true) {
  3349. return fn;
  3350. }
  3351. var warned = false;
  3352. function deprecated() {
  3353. if (!warned) {
  3354. if (process.throwDeprecation) {
  3355. throw new Error(msg);
  3356. } else if (process.traceDeprecation) {
  3357. console.trace(msg);
  3358. } else {
  3359. console.error(msg);
  3360. }
  3361. warned = true;
  3362. }
  3363. return fn.apply(this, arguments);
  3364. }
  3365. return deprecated;
  3366. };
  3367. var debugs = {};
  3368. var debugEnviron;
  3369. exports.debuglog = function(set) {
  3370. if (isUndefined(debugEnviron))
  3371. debugEnviron = process.env.NODE_DEBUG || '';
  3372. set = set.toUpperCase();
  3373. if (!debugs[set]) {
  3374. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  3375. var pid = process.pid;
  3376. debugs[set] = function() {
  3377. var msg = exports.format.apply(exports, arguments);
  3378. console.error('%s %d: %s', set, pid, msg);
  3379. };
  3380. } else {
  3381. debugs[set] = function() {};
  3382. }
  3383. }
  3384. return debugs[set];
  3385. };
  3386. /**
  3387. * Echos the value of a value. Trys to print the value out
  3388. * in the best way possible given the different types.
  3389. *
  3390. * @param {Object} obj The object to print out.
  3391. * @param {Object} opts Optional options object that alters the output.
  3392. */
  3393. /* legacy: obj, showHidden, depth, colors*/
  3394. function inspect(obj, opts) {
  3395. // default options
  3396. var ctx = {
  3397. seen: [],
  3398. stylize: stylizeNoColor
  3399. };
  3400. // legacy...
  3401. if (arguments.length >= 3) ctx.depth = arguments[2];
  3402. if (arguments.length >= 4) ctx.colors = arguments[3];
  3403. if (isBoolean(opts)) {
  3404. // legacy...
  3405. ctx.showHidden = opts;
  3406. } else if (opts) {
  3407. // got an "options" object
  3408. exports._extend(ctx, opts);
  3409. }
  3410. // set default options
  3411. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  3412. if (isUndefined(ctx.depth)) ctx.depth = 2;
  3413. if (isUndefined(ctx.colors)) ctx.colors = false;
  3414. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  3415. if (ctx.colors) ctx.stylize = stylizeWithColor;
  3416. return formatValue(ctx, obj, ctx.depth);
  3417. }
  3418. exports.inspect = inspect;
  3419. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  3420. inspect.colors = {
  3421. 'bold' : [1, 22],
  3422. 'italic' : [3, 23],
  3423. 'underline' : [4, 24],
  3424. 'inverse' : [7, 27],
  3425. 'white' : [37, 39],
  3426. 'grey' : [90, 39],
  3427. 'black' : [30, 39],
  3428. 'blue' : [34, 39],
  3429. 'cyan' : [36, 39],
  3430. 'green' : [32, 39],
  3431. 'magenta' : [35, 39],
  3432. 'red' : [31, 39],
  3433. 'yellow' : [33, 39]
  3434. };
  3435. // Don't use 'blue' not visible on cmd.exe
  3436. inspect.styles = {
  3437. 'special': 'cyan',
  3438. 'number': 'yellow',
  3439. 'boolean': 'yellow',
  3440. 'undefined': 'grey',
  3441. 'null': 'bold',
  3442. 'string': 'green',
  3443. 'date': 'magenta',
  3444. // "name": intentionally not styling
  3445. 'regexp': 'red'
  3446. };
  3447. function stylizeWithColor(str, styleType) {
  3448. var style = inspect.styles[styleType];
  3449. if (style) {
  3450. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  3451. '\u001b[' + inspect.colors[style][1] + 'm';
  3452. } else {
  3453. return str;
  3454. }
  3455. }
  3456. function stylizeNoColor(str, styleType) {
  3457. return str;
  3458. }
  3459. function arrayToHash(array) {
  3460. var hash = {};
  3461. array.forEach(function(val, idx) {
  3462. hash[val] = true;
  3463. });
  3464. return hash;
  3465. }
  3466. function formatValue(ctx, value, recurseTimes) {
  3467. // Provide a hook for user-specified inspect functions.
  3468. // Check that value is an object with an inspect function on it
  3469. if (ctx.customInspect &&
  3470. value &&
  3471. isFunction(value.inspect) &&
  3472. // Filter out the util module, it's inspect function is special
  3473. value.inspect !== exports.inspect &&
  3474. // Also filter out any prototype objects using the circular check.
  3475. !(value.constructor && value.constructor.prototype === value)) {
  3476. var ret = value.inspect(recurseTimes, ctx);
  3477. if (!isString(ret)) {
  3478. ret = formatValue(ctx, ret, recurseTimes);
  3479. }
  3480. return ret;
  3481. }
  3482. // Primitive types cannot have properties
  3483. var primitive = formatPrimitive(ctx, value);
  3484. if (primitive) {
  3485. return primitive;
  3486. }
  3487. // Look up the keys of the object.
  3488. var keys = Object.keys(value);
  3489. var visibleKeys = arrayToHash(keys);
  3490. if (ctx.showHidden) {
  3491. keys = Object.getOwnPropertyNames(value);
  3492. }
  3493. // IE doesn't make error fields non-enumerable
  3494. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  3495. if (isError(value)
  3496. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  3497. return formatError(value);
  3498. }
  3499. // Some type of object without properties can be shortcutted.
  3500. if (keys.length === 0) {
  3501. if (isFunction(value)) {
  3502. var name = value.name ? ': ' + value.name : '';
  3503. return ctx.stylize('[Function' + name + ']', 'special');
  3504. }
  3505. if (isRegExp(value)) {
  3506. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  3507. }
  3508. if (isDate(value)) {
  3509. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  3510. }
  3511. if (isError(value)) {
  3512. return formatError(value);
  3513. }
  3514. }
  3515. var base = '', array = false, braces = ['{', '}'];
  3516. // Make Array say that they are Array
  3517. if (isArray(value)) {
  3518. array = true;
  3519. braces = ['[', ']'];
  3520. }
  3521. // Make functions say that they are functions
  3522. if (isFunction(value)) {
  3523. var n = value.name ? ': ' + value.name : '';
  3524. base = ' [Function' + n + ']';
  3525. }
  3526. // Make RegExps say that they are RegExps
  3527. if (isRegExp(value)) {
  3528. base = ' ' + RegExp.prototype.toString.call(value);
  3529. }
  3530. // Make dates with properties first say the date
  3531. if (isDate(value)) {
  3532. base = ' ' + Date.prototype.toUTCString.call(value);
  3533. }
  3534. // Make error with message first say the error
  3535. if (isError(value)) {
  3536. base = ' ' + formatError(value);
  3537. }
  3538. if (keys.length === 0 && (!array || value.length == 0)) {
  3539. return braces[0] + base + braces[1];
  3540. }
  3541. if (recurseTimes < 0) {
  3542. if (isRegExp(value)) {
  3543. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  3544. } else {
  3545. return ctx.stylize('[Object]', 'special');
  3546. }
  3547. }
  3548. ctx.seen.push(value);
  3549. var output;
  3550. if (array) {
  3551. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  3552. } else {
  3553. output = keys.map(function(key) {
  3554. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  3555. });
  3556. }
  3557. ctx.seen.pop();
  3558. return reduceToSingleString(output, base, braces);
  3559. }
  3560. function formatPrimitive(ctx, value) {
  3561. if (isUndefined(value))
  3562. return ctx.stylize('undefined', 'undefined');
  3563. if (isString(value)) {
  3564. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  3565. .replace(/'/g, "\\'")
  3566. .replace(/\\"/g, '"') + '\'';
  3567. return ctx.stylize(simple, 'string');
  3568. }
  3569. if (isNumber(value))
  3570. return ctx.stylize('' + value, 'number');
  3571. if (isBoolean(value))
  3572. return ctx.stylize('' + value, 'boolean');
  3573. // For some reason typeof null is "object", so special case here.
  3574. if (isNull(value))
  3575. return ctx.stylize('null', 'null');
  3576. }
  3577. function formatError(value) {
  3578. return '[' + Error.prototype.toString.call(value) + ']';
  3579. }
  3580. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  3581. var output = [];
  3582. for (var i = 0, l = value.length; i < l; ++i) {
  3583. if (hasOwnProperty(value, String(i))) {
  3584. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  3585. String(i), true));
  3586. } else {
  3587. output.push('');
  3588. }
  3589. }
  3590. keys.forEach(function(key) {
  3591. if (!key.match(/^\d+$/)) {
  3592. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  3593. key, true));
  3594. }
  3595. });
  3596. return output;
  3597. }
  3598. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  3599. var name, str, desc;
  3600. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  3601. if (desc.get) {
  3602. if (desc.set) {
  3603. str = ctx.stylize('[Getter/Setter]', 'special');
  3604. } else {
  3605. str = ctx.stylize('[Getter]', 'special');
  3606. }
  3607. } else {
  3608. if (desc.set) {
  3609. str = ctx.stylize('[Setter]', 'special');
  3610. }
  3611. }
  3612. if (!hasOwnProperty(visibleKeys, key)) {
  3613. name = '[' + key + ']';
  3614. }
  3615. if (!str) {
  3616. if (ctx.seen.indexOf(desc.value) < 0) {
  3617. if (isNull(recurseTimes)) {
  3618. str = formatValue(ctx, desc.value, null);
  3619. } else {
  3620. str = formatValue(ctx, desc.value, recurseTimes - 1);
  3621. }
  3622. if (str.indexOf('\n') > -1) {
  3623. if (array) {
  3624. str = str.split('\n').map(function(line) {
  3625. return ' ' + line;
  3626. }).join('\n').substr(2);
  3627. } else {
  3628. str = '\n' + str.split('\n').map(function(line) {
  3629. return ' ' + line;
  3630. }).join('\n');
  3631. }
  3632. }
  3633. } else {
  3634. str = ctx.stylize('[Circular]', 'special');
  3635. }
  3636. }
  3637. if (isUndefined(name)) {
  3638. if (array && key.match(/^\d+$/)) {
  3639. return str;
  3640. }
  3641. name = JSON.stringify('' + key);
  3642. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  3643. name = name.substr(1, name.length - 2);
  3644. name = ctx.stylize(name, 'name');
  3645. } else {
  3646. name = name.replace(/'/g, "\\'")
  3647. .replace(/\\"/g, '"')
  3648. .replace(/(^"|"$)/g, "'");
  3649. name = ctx.stylize(name, 'string');
  3650. }
  3651. }
  3652. return name + ': ' + str;
  3653. }
  3654. function reduceToSingleString(output, base, braces) {
  3655. var numLinesEst = 0;
  3656. var length = output.reduce(function(prev, cur) {
  3657. numLinesEst++;
  3658. if (cur.indexOf('\n') >= 0) numLinesEst++;
  3659. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  3660. }, 0);
  3661. if (length > 60) {
  3662. return braces[0] +
  3663. (base === '' ? '' : base + '\n ') +
  3664. ' ' +
  3665. output.join(',\n ') +
  3666. ' ' +
  3667. braces[1];
  3668. }
  3669. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  3670. }
  3671. // NOTE: These type checking functions intentionally don't use `instanceof`
  3672. // because it is fragile and can be easily faked with `Object.create()`.
  3673. function isArray(ar) {
  3674. return Array.isArray(ar);
  3675. }
  3676. exports.isArray = isArray;
  3677. function isBoolean(arg) {
  3678. return typeof arg === 'boolean';
  3679. }
  3680. exports.isBoolean = isBoolean;
  3681. function isNull(arg) {
  3682. return arg === null;
  3683. }
  3684. exports.isNull = isNull;
  3685. function isNullOrUndefined(arg) {
  3686. return arg == null;
  3687. }
  3688. exports.isNullOrUndefined = isNullOrUndefined;
  3689. function isNumber(arg) {
  3690. return typeof arg === 'number';
  3691. }
  3692. exports.isNumber = isNumber;
  3693. function isString(arg) {
  3694. return typeof arg === 'string';
  3695. }
  3696. exports.isString = isString;
  3697. function isSymbol(arg) {
  3698. return typeof arg === 'symbol';
  3699. }
  3700. exports.isSymbol = isSymbol;
  3701. function isUndefined(arg) {
  3702. return arg === void 0;
  3703. }
  3704. exports.isUndefined = isUndefined;
  3705. function isRegExp(re) {
  3706. return isObject(re) && objectToString(re) === '[object RegExp]';
  3707. }
  3708. exports.isRegExp = isRegExp;
  3709. function isObject(arg) {
  3710. return typeof arg === 'object' && arg !== null;
  3711. }
  3712. exports.isObject = isObject;
  3713. function isDate(d) {
  3714. return isObject(d) && objectToString(d) === '[object Date]';
  3715. }
  3716. exports.isDate = isDate;
  3717. function isError(e) {
  3718. return isObject(e) &&
  3719. (objectToString(e) === '[object Error]' || e instanceof Error);
  3720. }
  3721. exports.isError = isError;
  3722. function isFunction(arg) {
  3723. return typeof arg === 'function';
  3724. }
  3725. exports.isFunction = isFunction;
  3726. function isPrimitive(arg) {
  3727. return arg === null ||
  3728. typeof arg === 'boolean' ||
  3729. typeof arg === 'number' ||
  3730. typeof arg === 'string' ||
  3731. typeof arg === 'symbol' || // ES6 symbol
  3732. typeof arg === 'undefined';
  3733. }
  3734. exports.isPrimitive = isPrimitive;
  3735. exports.isBuffer = require('./support/isBuffer');
  3736. function objectToString(o) {
  3737. return Object.prototype.toString.call(o);
  3738. }
  3739. function pad(n) {
  3740. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  3741. }
  3742. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  3743. 'Oct', 'Nov', 'Dec'];
  3744. // 26 Feb 16:19:34
  3745. function timestamp() {
  3746. var d = new Date();
  3747. var time = [pad(d.getHours()),
  3748. pad(d.getMinutes()),
  3749. pad(d.getSeconds())].join(':');
  3750. return [d.getDate(), months[d.getMonth()], time].join(' ');
  3751. }
  3752. // log is just a thin wrapper to console.log that prepends a timestamp
  3753. exports.log = function() {
  3754. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  3755. };
  3756. /**
  3757. * Inherit the prototype methods from one constructor into another.
  3758. *
  3759. * The Function.prototype.inherits from lang.js rewritten as a standalone
  3760. * function (not on Function.prototype). NOTE: If this file is to be loaded
  3761. * during bootstrapping this function needs to be rewritten using some native
  3762. * functions as prototype setup using normal JavaScript does not work as
  3763. * expected during bootstrapping (see mirror.js in r114903).
  3764. *
  3765. * @param {function} ctor Constructor function which needs to inherit the
  3766. * prototype.
  3767. * @param {function} superCtor Constructor function to inherit prototype from.
  3768. */
  3769. exports.inherits = require('inherits');
  3770. exports._extend = function(origin, add) {
  3771. // Don't do anything if add isn't an object
  3772. if (!add || !isObject(add)) return origin;
  3773. var keys = Object.keys(add);
  3774. var i = keys.length;
  3775. while (i--) {
  3776. origin[keys[i]] = add[keys[i]];
  3777. }
  3778. return origin;
  3779. };
  3780. function hasOwnProperty(obj, prop) {
  3781. return Object.prototype.hasOwnProperty.call(obj, prop);
  3782. }
  3783. }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3784. },{"./support/isBuffer":16,"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"inherits":5}],18:[function(require,module,exports){
  3785. module.exports = isFunction
  3786. var toString = Object.prototype.toString
  3787. function isFunction (fn) {
  3788. var string = toString.call(fn)
  3789. return string === '[object Function]' ||
  3790. (typeof fn === 'function' && string !== '[object RegExp]') ||
  3791. (typeof window !== 'undefined' &&
  3792. // IE8 and below
  3793. (fn === window.setTimeout ||
  3794. fn === window.alert ||
  3795. fn === window.confirm ||
  3796. fn === window.prompt))
  3797. };
  3798. },{}],19:[function(require,module,exports){
  3799. (function (process){
  3800. var defined = require('defined');
  3801. var createDefaultStream = require('./lib/default_stream');
  3802. var Test = require('./lib/test');
  3803. var createResult = require('./lib/results');
  3804. var canEmitExit = typeof process !== 'undefined' && process
  3805. && typeof process.on === 'function'
  3806. ;
  3807. var canExit = typeof process !== 'undefined' && process
  3808. && typeof process.exit === 'function'
  3809. ;
  3810. var nextTick = typeof setImmediate !== 'undefined'
  3811. ? setImmediate
  3812. : process.nextTick
  3813. ;
  3814. exports = module.exports = (function () {
  3815. var harness;
  3816. var lazyLoad = function () {
  3817. if (!harness) harness = createExitHarness({
  3818. autoclose: !canEmitExit
  3819. });
  3820. return harness.apply(this, arguments);
  3821. };
  3822. lazyLoad.only = function () {
  3823. if (!harness) harness = createExitHarness({
  3824. autoclose: !canEmitExit
  3825. });
  3826. return harness.only.apply(this, arguments);
  3827. }
  3828. return lazyLoad
  3829. })();
  3830. function createExitHarness (conf) {
  3831. if (!conf) conf = {};
  3832. var harness = createHarness({
  3833. autoclose: defined(conf.autoclose, false)
  3834. });
  3835. var stream = harness.createStream();
  3836. var es = stream.pipe(createDefaultStream());
  3837. if (canEmitExit) {
  3838. es.on('error', function (err) { harness._exitCode = 1 });
  3839. }
  3840. var ended = false;
  3841. stream.on('end', function () { ended = true });
  3842. if (conf.exit === false) return harness;
  3843. if (!canEmitExit || !canExit) return harness;
  3844. var _error;
  3845. process.on('uncaughtException', function (err) {
  3846. if (err && err.code === 'EPIPE' && err.errno === 'EPIPE'
  3847. && err.syscall === 'write') return;
  3848. _error = err
  3849. throw err
  3850. })
  3851. process.on('exit', function (code) {
  3852. if (_error) {
  3853. return
  3854. }
  3855. if (!ended) {
  3856. for (var i = 0; i < harness._tests.length; i++) {
  3857. var t = harness._tests[i];
  3858. t._exit();
  3859. }
  3860. }
  3861. harness.close();
  3862. process.exit(code || harness._exitCode);
  3863. });
  3864. return harness;
  3865. }
  3866. exports.createHarness = createHarness;
  3867. exports.Test = Test;
  3868. exports.test = exports; // tap compat
  3869. var exitInterval;
  3870. function createHarness (conf_) {
  3871. if (!conf_) conf_ = {};
  3872. var results = createResult();
  3873. if (conf_.autoclose !== false) {
  3874. results.once('done', function () { results.close() });
  3875. }
  3876. var test = function (name, conf, cb) {
  3877. var t = new Test(name, conf, cb);
  3878. test._tests.push(t);
  3879. (function inspectCode (st) {
  3880. st.on('test', function sub (st_) {
  3881. inspectCode(st_);
  3882. });
  3883. st.on('result', function (r) {
  3884. if (!r.ok) test._exitCode = 1
  3885. });
  3886. })(t);
  3887. results.push(t);
  3888. return t;
  3889. };
  3890. test._tests = [];
  3891. test.createStream = function () {
  3892. return results.createStream();
  3893. };
  3894. var only = false;
  3895. test.only = function (name) {
  3896. if (only) throw new Error('there can only be one only test');
  3897. results.only(name);
  3898. only = true;
  3899. return test.apply(null, arguments);
  3900. };
  3901. test._exitCode = 0;
  3902. test.close = function () { results.close() };
  3903. return test;
  3904. }
  3905. }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
  3906. },{"./lib/default_stream":20,"./lib/results":21,"./lib/test":22,"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"defined":26}],20:[function(require,module,exports){
  3907. var through = require('through');
  3908. module.exports = function () {
  3909. var line = '';
  3910. var stream = through(write, flush);
  3911. return stream;
  3912. function write (buf) {
  3913. for (var i = 0; i < buf.length; i++) {
  3914. var c = typeof buf === 'string'
  3915. ? buf.charAt(i)
  3916. : String.fromCharCode(buf[i])
  3917. ;
  3918. if (c === '\n') flush();
  3919. else line += c;
  3920. }
  3921. }
  3922. function flush () {
  3923. try { console.log(line); }
  3924. catch (e) { stream.emit('error', e) }
  3925. line = '';
  3926. }
  3927. };
  3928. },{"through":32}],21:[function(require,module,exports){
  3929. (function (process){
  3930. var Stream = require('stream');
  3931. var EventEmitter = require('events').EventEmitter;
  3932. var inherits = require('inherits');
  3933. var json = typeof JSON === 'object' ? JSON : require('jsonify');
  3934. var through = require('through');
  3935. var resumer = require('resumer');
  3936. var nextTick = typeof setImmediate !== 'undefined'
  3937. ? setImmediate
  3938. : process.nextTick
  3939. ;
  3940. module.exports = Results;
  3941. inherits(Results, EventEmitter);
  3942. function Results () {
  3943. if (!(this instanceof Results)) return new Results;
  3944. this.count = 0;
  3945. this.fail = 0;
  3946. this.pass = 0;
  3947. this._stream = through();
  3948. this.tests = [];
  3949. }
  3950. Results.prototype.createStream = function () {
  3951. var self = this;
  3952. var output = resumer();
  3953. output.queue('TAP version 13\n');
  3954. nextTick(function () {
  3955. var t = getNextTest(self);
  3956. if (t) t.run()
  3957. else self.emit('done')
  3958. });
  3959. self._stream.pipe(output);
  3960. return output;
  3961. };
  3962. Results.prototype.push = function (t) {
  3963. var self = this;
  3964. self.tests.push(t);
  3965. self._watch(t);
  3966. t.once('end', function () {
  3967. var nt = getNextTest(self);
  3968. if (nt) nt.run()
  3969. else self.emit('done')
  3970. });
  3971. };
  3972. Results.prototype.only = function (name) {
  3973. if (this._only) {
  3974. self.count ++;
  3975. self.fail ++;
  3976. write('not ok ' + self.count + ' already called .only()\n');
  3977. }
  3978. this._only = name;
  3979. };
  3980. Results.prototype._watch = function (t) {
  3981. var self = this;
  3982. var write = function (s) { self._stream.queue(s) };
  3983. t.once('prerun', function () {
  3984. write('# ' + t.name + '\n');
  3985. });
  3986. t.on('result', function (res) {
  3987. if (typeof res === 'string') {
  3988. write('# ' + res + '\n');
  3989. return;
  3990. }
  3991. write(encodeResult(res, self.count + 1));
  3992. self.count ++;
  3993. if (res.ok) self.pass ++
  3994. else self.fail ++
  3995. });
  3996. t.on('test', function (st) { self._watch(st) });
  3997. };
  3998. Results.prototype.close = function () {
  3999. var self = this;
  4000. if (self.closed) self._stream.emit('error', new Error('ALREADY CLOSED'));
  4001. self.closed = true;
  4002. var write = function (s) { self._stream.queue(s) };
  4003. write('\n1..' + self.count + '\n');
  4004. write('# tests ' + self.count + '\n');
  4005. write('# pass ' + self.pass + '\n');
  4006. if (self.fail) write('# fail ' + self.fail + '\n')
  4007. else write('\n# ok\n')
  4008. self._stream.queue(null);
  4009. };
  4010. function encodeResult (res, count) {
  4011. var output = '';
  4012. output += (res.ok ? 'ok ' : 'not ok ') + count;
  4013. output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : '';
  4014. if (res.skip) output += ' # SKIP';
  4015. else if (res.todo) output += ' # TODO';
  4016. output += '\n';
  4017. if (res.ok) return output;
  4018. var outer = ' ';
  4019. var inner = outer + ' ';
  4020. output += outer + '---\n';
  4021. output += inner + 'operator: ' + res.operator + '\n';
  4022. var ex = json.stringify(res.expected, getSerialize()) || '';
  4023. var ac = json.stringify(res.actual, getSerialize()) || '';
  4024. if (Math.max(ex.length, ac.length) > 65) {
  4025. output += inner + 'expected:\n' + inner + ' ' + ex + '\n';
  4026. output += inner + 'actual:\n' + inner + ' ' + ac + '\n';
  4027. }
  4028. else {
  4029. output += inner + 'expected: ' + ex + '\n';
  4030. output += inner + 'actual: ' + ac + '\n';
  4031. }
  4032. if (res.at) {
  4033. output += inner + 'at: ' + res.at + '\n';
  4034. }
  4035. if (res.operator === 'error' && res.actual && res.actual.stack) {
  4036. var lines = String(res.actual.stack).split('\n');
  4037. output += inner + 'stack:\n';
  4038. output += inner + ' ' + lines[0] + '\n';
  4039. for (var i = 1; i < lines.length; i++) {
  4040. output += inner + lines[i] + '\n';
  4041. }
  4042. }
  4043. output += outer + '...\n';
  4044. return output;
  4045. }
  4046. function getSerialize () {
  4047. var seen = [];
  4048. return function (key, value) {
  4049. var ret = value;
  4050. if (typeof value === 'object' && value) {
  4051. var found = false;
  4052. for (var i = 0; i < seen.length; i++) {
  4053. if (seen[i] === value) {
  4054. found = true
  4055. break;
  4056. }
  4057. }
  4058. if (found) ret = '[Circular]'
  4059. else seen.push(value)
  4060. }
  4061. return ret;
  4062. };
  4063. }
  4064. function getNextTest(results) {
  4065. if (!results._only) {
  4066. return results.tests.shift();
  4067. }
  4068. do {
  4069. var t = results.tests.shift();
  4070. if (!t) {
  4071. return null;
  4072. }
  4073. if (results._only === t.name) {
  4074. return t;
  4075. }
  4076. } while (results.tests.length !== 0)
  4077. }
  4078. }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
  4079. },{"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"events":4,"inherits":27,"jsonify":28,"resumer":31,"stream":9,"through":32}],22:[function(require,module,exports){
  4080. (function (process,__dirname){
  4081. var Stream = require('stream');
  4082. var deepEqual = require('deep-equal');
  4083. var defined = require('defined');
  4084. var path = require('path');
  4085. var inherits = require('util').inherits;
  4086. var EventEmitter = require('events').EventEmitter;
  4087. module.exports = Test;
  4088. var nextTick = typeof setImmediate !== 'undefined'
  4089. ? setImmediate
  4090. : process.nextTick
  4091. ;
  4092. inherits(Test, EventEmitter);
  4093. function Test (name_, opts_, cb_) {
  4094. var self = this;
  4095. var name = '(anonymous)';
  4096. var opts = {};
  4097. var cb;
  4098. for (var i = 0; i < arguments.length; i++) {
  4099. switch (typeof arguments[i]) {
  4100. case 'string':
  4101. name = arguments[i];
  4102. break;
  4103. case 'object':
  4104. opts = arguments[i] || opts;
  4105. break;
  4106. case 'function':
  4107. cb = arguments[i];
  4108. }
  4109. }
  4110. this.readable = true;
  4111. this.name = name || '(anonymous)';
  4112. this.assertCount = 0;
  4113. this.pendingCount = 0;
  4114. this._skip = opts.skip || false;
  4115. this._plan = undefined;
  4116. this._cb = cb;
  4117. this._progeny = [];
  4118. this._ok = true;
  4119. }
  4120. Test.prototype.run = function () {
  4121. if (this._skip) {
  4122. return this.end();
  4123. }
  4124. this.emit('prerun');
  4125. try {
  4126. this._cb(this);
  4127. }
  4128. catch (err) {
  4129. this.error(err);
  4130. this.end();
  4131. return;
  4132. }
  4133. this.emit('run');
  4134. };
  4135. Test.prototype.test = function (name, opts, cb) {
  4136. var self = this;
  4137. var t = new Test(name, opts, cb);
  4138. this._progeny.push(t);
  4139. this.pendingCount++;
  4140. this.emit('test', t);
  4141. t.on('prerun', function () {
  4142. self.assertCount++;
  4143. })
  4144. if (!self._pendingAsserts()) {
  4145. nextTick(function () {
  4146. self.end();
  4147. });
  4148. }
  4149. nextTick(function() {
  4150. if (!self._plan && self.pendingCount == self._progeny.length) {
  4151. self.end();
  4152. }
  4153. });
  4154. };
  4155. Test.prototype.comment = function (msg) {
  4156. this.emit('result', msg.trim().replace(/^#\s*/, ''));
  4157. };
  4158. Test.prototype.plan = function (n) {
  4159. this._plan = n;
  4160. this.emit('plan', n);
  4161. };
  4162. Test.prototype.end = function () {
  4163. var self = this;
  4164. if (this._progeny.length) {
  4165. var t = this._progeny.shift();
  4166. t.on('end', function () {
  4167. self.end();
  4168. });
  4169. t.run();
  4170. return;
  4171. }
  4172. if (!this.ended) this.emit('end');
  4173. var pendingAsserts = this._pendingAsserts();
  4174. if (!this._planError && this._plan !== undefined && pendingAsserts) {
  4175. this._planError = true;
  4176. this.fail('plan != count', {
  4177. expected : this._plan,
  4178. actual : this.assertCount
  4179. });
  4180. }
  4181. this.ended = true;
  4182. };
  4183. Test.prototype._exit = function () {
  4184. if (this._plan !== undefined &&
  4185. !this._planError && this.assertCount !== this._plan) {
  4186. this._planError = true;
  4187. this.fail('plan != count', {
  4188. expected : this._plan,
  4189. actual : this.assertCount,
  4190. exiting : true
  4191. });
  4192. }
  4193. else if (!this.ended) {
  4194. this.fail('test exited without ending', {
  4195. exiting: true
  4196. });
  4197. }
  4198. };
  4199. Test.prototype._pendingAsserts = function () {
  4200. if (this._plan === undefined) {
  4201. return 1;
  4202. } else {
  4203. return this._plan -
  4204. (this._progeny.length + this.assertCount);
  4205. }
  4206. }
  4207. Test.prototype._assert = function assert (ok, opts) {
  4208. var self = this;
  4209. var extra = opts.extra || {};
  4210. var res = {
  4211. id : self.assertCount ++,
  4212. ok : Boolean(ok),
  4213. skip : defined(extra.skip, opts.skip),
  4214. name : defined(extra.message, opts.message, '(unnamed assert)'),
  4215. operator : defined(extra.operator, opts.operator),
  4216. actual : defined(extra.actual, opts.actual),
  4217. expected : defined(extra.expected, opts.expected)
  4218. };
  4219. this._ok = Boolean(this._ok && ok);
  4220. if (!ok) {
  4221. res.error = defined(extra.error, opts.error, new Error(res.name));
  4222. }
  4223. var e = new Error('exception');
  4224. var err = (e.stack || '').split('\n');
  4225. var dir = path.dirname(__dirname) + '/';
  4226. for (var i = 0; i < err.length; i++) {
  4227. var m = /^\s*\bat\s+(.+)/.exec(err[i]);
  4228. if (!m) continue;
  4229. var s = m[1].split(/\s+/);
  4230. var filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[1]);
  4231. if (!filem) {
  4232. filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[3]);
  4233. if (!filem) continue;
  4234. }
  4235. if (filem[1].slice(0, dir.length) === dir) continue;
  4236. res.functionName = s[0];
  4237. res.file = filem[1];
  4238. res.line = Number(filem[2]);
  4239. if (filem[3]) res.column = filem[3];
  4240. res.at = m[1];
  4241. break;
  4242. }
  4243. self.emit('result', res);
  4244. var pendingAsserts = self._pendingAsserts();
  4245. if (!pendingAsserts) {
  4246. if (extra.exiting) {
  4247. self.end();
  4248. } else {
  4249. nextTick(function () {
  4250. self.end();
  4251. });
  4252. }
  4253. }
  4254. if (!self._planError && pendingAsserts < 0) {
  4255. self._planError = true;
  4256. self.fail('plan != count', {
  4257. expected : self._plan,
  4258. actual : self._plan - pendingAsserts
  4259. });
  4260. }
  4261. };
  4262. Test.prototype.fail = function (msg, extra) {
  4263. this._assert(false, {
  4264. message : msg,
  4265. operator : 'fail',
  4266. extra : extra
  4267. });
  4268. };
  4269. Test.prototype.pass = function (msg, extra) {
  4270. this._assert(true, {
  4271. message : msg,
  4272. operator : 'pass',
  4273. extra : extra
  4274. });
  4275. };
  4276. Test.prototype.skip = function (msg, extra) {
  4277. this._assert(true, {
  4278. message : msg,
  4279. operator : 'skip',
  4280. skip : true,
  4281. extra : extra
  4282. });
  4283. };
  4284. Test.prototype.ok
  4285. = Test.prototype['true']
  4286. = Test.prototype.assert
  4287. = function (value, msg, extra) {
  4288. this._assert(value, {
  4289. message : msg,
  4290. operator : 'ok',
  4291. expected : true,
  4292. actual : value,
  4293. extra : extra
  4294. });
  4295. };
  4296. Test.prototype.notOk
  4297. = Test.prototype['false']
  4298. = Test.prototype.notok
  4299. = function (value, msg, extra) {
  4300. this._assert(!value, {
  4301. message : msg,
  4302. operator : 'notOk',
  4303. expected : false,
  4304. actual : value,
  4305. extra : extra
  4306. });
  4307. };
  4308. Test.prototype.error
  4309. = Test.prototype.ifError
  4310. = Test.prototype.ifErr
  4311. = Test.prototype.iferror
  4312. = function (err, msg, extra) {
  4313. this._assert(!err, {
  4314. message : defined(msg, String(err)),
  4315. operator : 'error',
  4316. actual : err,
  4317. extra : extra
  4318. });
  4319. };
  4320. Test.prototype.equal
  4321. = Test.prototype.equals
  4322. = Test.prototype.isEqual
  4323. = Test.prototype.is
  4324. = Test.prototype.strictEqual
  4325. = Test.prototype.strictEquals
  4326. = function (a, b, msg, extra) {
  4327. this._assert(a === b, {
  4328. message : defined(msg, 'should be equal'),
  4329. operator : 'equal',
  4330. actual : a,
  4331. expected : b,
  4332. extra : extra
  4333. });
  4334. };
  4335. Test.prototype.notEqual
  4336. = Test.prototype.notEquals
  4337. = Test.prototype.notStrictEqual
  4338. = Test.prototype.notStrictEquals
  4339. = Test.prototype.isNotEqual
  4340. = Test.prototype.isNot
  4341. = Test.prototype.not
  4342. = Test.prototype.doesNotEqual
  4343. = Test.prototype.isInequal
  4344. = function (a, b, msg, extra) {
  4345. this._assert(a !== b, {
  4346. message : defined(msg, 'should not be equal'),
  4347. operator : 'notEqual',
  4348. actual : a,
  4349. notExpected : b,
  4350. extra : extra
  4351. });
  4352. };
  4353. Test.prototype.deepEqual
  4354. = Test.prototype.deepEquals
  4355. = Test.prototype.isEquivalent
  4356. = Test.prototype.same
  4357. = function (a, b, msg, extra) {
  4358. this._assert(deepEqual(a, b, { strict: true }), {
  4359. message : defined(msg, 'should be equivalent'),
  4360. operator : 'deepEqual',
  4361. actual : a,
  4362. expected : b,
  4363. extra : extra
  4364. });
  4365. };
  4366. Test.prototype.deepLooseEqual
  4367. = Test.prototype.looseEqual
  4368. = Test.prototype.looseEquals
  4369. = function (a, b, msg, extra) {
  4370. this._assert(deepEqual(a, b), {
  4371. message : defined(msg, 'should be equivalent'),
  4372. operator : 'deepLooseEqual',
  4373. actual : a,
  4374. expected : b,
  4375. extra : extra
  4376. });
  4377. };
  4378. Test.prototype.notDeepEqual
  4379. = Test.prototype.notEquivalent
  4380. = Test.prototype.notDeeply
  4381. = Test.prototype.notSame
  4382. = Test.prototype.isNotDeepEqual
  4383. = Test.prototype.isNotDeeply
  4384. = Test.prototype.isNotEquivalent
  4385. = Test.prototype.isInequivalent
  4386. = function (a, b, msg, extra) {
  4387. this._assert(!deepEqual(a, b, { strict: true }), {
  4388. message : defined(msg, 'should not be equivalent'),
  4389. operator : 'notDeepEqual',
  4390. actual : a,
  4391. notExpected : b,
  4392. extra : extra
  4393. });
  4394. };
  4395. Test.prototype.notDeepLooseEqual
  4396. = Test.prototype.notLooseEqual
  4397. = Test.prototype.notLooseEquals
  4398. = function (a, b, msg, extra) {
  4399. this._assert(deepEqual(a, b), {
  4400. message : defined(msg, 'should be equivalent'),
  4401. operator : 'notDeepLooseEqual',
  4402. actual : a,
  4403. expected : b,
  4404. extra : extra
  4405. });
  4406. };
  4407. Test.prototype['throws'] = function (fn, expected, msg, extra) {
  4408. if (typeof expected === 'string') {
  4409. msg = expected;
  4410. expected = undefined;
  4411. }
  4412. var caught = undefined;
  4413. try {
  4414. fn();
  4415. }
  4416. catch (err) {
  4417. caught = { error : err };
  4418. var message = err.message;
  4419. delete err.message;
  4420. err.message = message;
  4421. }
  4422. var passed = caught;
  4423. if (expected instanceof RegExp) {
  4424. passed = expected.test(caught && caught.error);
  4425. expected = String(expected);
  4426. }
  4427. this._assert(passed, {
  4428. message : defined(msg, 'should throw'),
  4429. operator : 'throws',
  4430. actual : caught && caught.error,
  4431. expected : expected,
  4432. error: !passed && caught && caught.error,
  4433. extra : extra
  4434. });
  4435. };
  4436. Test.prototype.doesNotThrow = function (fn, expected, msg, extra) {
  4437. if (typeof expected === 'string') {
  4438. msg = expected;
  4439. expected = undefined;
  4440. }
  4441. var caught = undefined;
  4442. try {
  4443. fn();
  4444. }
  4445. catch (err) {
  4446. caught = { error : err };
  4447. }
  4448. this._assert(!caught, {
  4449. message : defined(msg, 'should throw'),
  4450. operator : 'throws',
  4451. actual : caught && caught.error,
  4452. expected : expected,
  4453. error : caught && caught.error,
  4454. extra : extra
  4455. });
  4456. };
  4457. // vim: set softtabstop=4 shiftwidth=4:
  4458. }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),"/node_modules/tape/lib")
  4459. },{"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"deep-equal":23,"defined":26,"events":4,"path":7,"stream":9,"util":17}],23:[function(require,module,exports){
  4460. var pSlice = Array.prototype.slice;
  4461. var objectKeys = require('./lib/keys.js');
  4462. var isArguments = require('./lib/is_arguments.js');
  4463. var deepEqual = module.exports = function (actual, expected, opts) {
  4464. if (!opts) opts = {};
  4465. // 7.1. All identical values are equivalent, as determined by ===.
  4466. if (actual === expected) {
  4467. return true;
  4468. } else if (actual instanceof Date && expected instanceof Date) {
  4469. return actual.getTime() === expected.getTime();
  4470. // 7.3. Other pairs that do not both pass typeof value == 'object',
  4471. // equivalence is determined by ==.
  4472. } else if (typeof actual != 'object' && typeof expected != 'object') {
  4473. return opts.strict ? actual === expected : actual == expected;
  4474. // 7.4. For all other Object pairs, including Array objects, equivalence is
  4475. // determined by having the same number of owned properties (as verified
  4476. // with Object.prototype.hasOwnProperty.call), the same set of keys
  4477. // (although not necessarily the same order), equivalent values for every
  4478. // corresponding key, and an identical 'prototype' property. Note: this
  4479. // accounts for both named and indexed properties on Arrays.
  4480. } else {
  4481. return objEquiv(actual, expected, opts);
  4482. }
  4483. }
  4484. function isUndefinedOrNull(value) {
  4485. return value === null || value === undefined;
  4486. }
  4487. function objEquiv(a, b, opts) {
  4488. if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
  4489. return false;
  4490. // an identical 'prototype' property.
  4491. if (a.prototype !== b.prototype) return false;
  4492. //~~~I've managed to break Object.keys through screwy arguments passing.
  4493. // Converting to array solves the problem.
  4494. if (isArguments(a)) {
  4495. if (!isArguments(b)) {
  4496. return false;
  4497. }
  4498. a = pSlice.call(a);
  4499. b = pSlice.call(b);
  4500. return deepEqual(a, b, opts);
  4501. }
  4502. try {
  4503. var ka = objectKeys(a),
  4504. kb = objectKeys(b),
  4505. key, i;
  4506. } catch (e) {//happens when one is a string literal and the other isn't
  4507. return false;
  4508. }
  4509. // having the same number of owned properties (keys incorporates
  4510. // hasOwnProperty)
  4511. if (ka.length != kb.length)
  4512. return false;
  4513. //the same set of keys (although not necessarily the same order),
  4514. ka.sort();
  4515. kb.sort();
  4516. //~~~cheap key test
  4517. for (i = ka.length - 1; i >= 0; i--) {
  4518. if (ka[i] != kb[i])
  4519. return false;
  4520. }
  4521. //equivalent values for every corresponding key, and
  4522. //~~~possibly expensive deep test
  4523. for (i = ka.length - 1; i >= 0; i--) {
  4524. key = ka[i];
  4525. if (!deepEqual(a[key], b[key], opts)) return false;
  4526. }
  4527. return true;
  4528. }
  4529. },{"./lib/is_arguments.js":24,"./lib/keys.js":25}],24:[function(require,module,exports){
  4530. var supportsArgumentsClass = (function(){
  4531. return Object.prototype.toString.call(arguments)
  4532. })() == '[object Arguments]';
  4533. exports = module.exports = supportsArgumentsClass ? supported : unsupported;
  4534. exports.supported = supported;
  4535. function supported(object) {
  4536. return Object.prototype.toString.call(object) == '[object Arguments]';
  4537. };
  4538. exports.unsupported = unsupported;
  4539. function unsupported(object){
  4540. return object &&
  4541. typeof object == 'object' &&
  4542. typeof object.length == 'number' &&
  4543. Object.prototype.hasOwnProperty.call(object, 'callee') &&
  4544. !Object.prototype.propertyIsEnumerable.call(object, 'callee') ||
  4545. false;
  4546. };
  4547. },{}],25:[function(require,module,exports){
  4548. exports = module.exports = typeof Object.keys === 'function'
  4549. ? Object.keys : shim;
  4550. exports.shim = shim;
  4551. function shim (obj) {
  4552. var keys = [];
  4553. for (var key in obj) keys.push(key);
  4554. return keys;
  4555. }
  4556. },{}],26:[function(require,module,exports){
  4557. module.exports = function () {
  4558. for (var i = 0; i < arguments.length; i++) {
  4559. if (arguments[i] !== undefined) return arguments[i];
  4560. }
  4561. };
  4562. },{}],27:[function(require,module,exports){
  4563. module.exports=require(5)
  4564. },{}],28:[function(require,module,exports){
  4565. exports.parse = require('./lib/parse');
  4566. exports.stringify = require('./lib/stringify');
  4567. },{"./lib/parse":29,"./lib/stringify":30}],29:[function(require,module,exports){
  4568. var at, // The index of the current character
  4569. ch, // The current character
  4570. escapee = {
  4571. '"': '"',
  4572. '\\': '\\',
  4573. '/': '/',
  4574. b: '\b',
  4575. f: '\f',
  4576. n: '\n',
  4577. r: '\r',
  4578. t: '\t'
  4579. },
  4580. text,
  4581. error = function (m) {
  4582. // Call error when something is wrong.
  4583. throw {
  4584. name: 'SyntaxError',
  4585. message: m,
  4586. at: at,
  4587. text: text
  4588. };
  4589. },
  4590. next = function (c) {
  4591. // If a c parameter is provided, verify that it matches the current character.
  4592. if (c && c !== ch) {
  4593. error("Expected '" + c + "' instead of '" + ch + "'");
  4594. }
  4595. // Get the next character. When there are no more characters,
  4596. // return the empty string.
  4597. ch = text.charAt(at);
  4598. at += 1;
  4599. return ch;
  4600. },
  4601. number = function () {
  4602. // Parse a number value.
  4603. var number,
  4604. string = '';
  4605. if (ch === '-') {
  4606. string = '-';
  4607. next('-');
  4608. }
  4609. while (ch >= '0' && ch <= '9') {
  4610. string += ch;
  4611. next();
  4612. }
  4613. if (ch === '.') {
  4614. string += '.';
  4615. while (next() && ch >= '0' && ch <= '9') {
  4616. string += ch;
  4617. }
  4618. }
  4619. if (ch === 'e' || ch === 'E') {
  4620. string += ch;
  4621. next();
  4622. if (ch === '-' || ch === '+') {
  4623. string += ch;
  4624. next();
  4625. }
  4626. while (ch >= '0' && ch <= '9') {
  4627. string += ch;
  4628. next();
  4629. }
  4630. }
  4631. number = +string;
  4632. if (!isFinite(number)) {
  4633. error("Bad number");
  4634. } else {
  4635. return number;
  4636. }
  4637. },
  4638. string = function () {
  4639. // Parse a string value.
  4640. var hex,
  4641. i,
  4642. string = '',
  4643. uffff;
  4644. // When parsing for string values, we must look for " and \ characters.
  4645. if (ch === '"') {
  4646. while (next()) {
  4647. if (ch === '"') {
  4648. next();
  4649. return string;
  4650. } else if (ch === '\\') {
  4651. next();
  4652. if (ch === 'u') {
  4653. uffff = 0;
  4654. for (i = 0; i < 4; i += 1) {
  4655. hex = parseInt(next(), 16);
  4656. if (!isFinite(hex)) {
  4657. break;
  4658. }
  4659. uffff = uffff * 16 + hex;
  4660. }
  4661. string += String.fromCharCode(uffff);
  4662. } else if (typeof escapee[ch] === 'string') {
  4663. string += escapee[ch];
  4664. } else {
  4665. break;
  4666. }
  4667. } else {
  4668. string += ch;
  4669. }
  4670. }
  4671. }
  4672. error("Bad string");
  4673. },
  4674. white = function () {
  4675. // Skip whitespace.
  4676. while (ch && ch <= ' ') {
  4677. next();
  4678. }
  4679. },
  4680. word = function () {
  4681. // true, false, or null.
  4682. switch (ch) {
  4683. case 't':
  4684. next('t');
  4685. next('r');
  4686. next('u');
  4687. next('e');
  4688. return true;
  4689. case 'f':
  4690. next('f');
  4691. next('a');
  4692. next('l');
  4693. next('s');
  4694. next('e');
  4695. return false;
  4696. case 'n':
  4697. next('n');
  4698. next('u');
  4699. next('l');
  4700. next('l');
  4701. return null;
  4702. }
  4703. error("Unexpected '" + ch + "'");
  4704. },
  4705. value, // Place holder for the value function.
  4706. array = function () {
  4707. // Parse an array value.
  4708. var array = [];
  4709. if (ch === '[') {
  4710. next('[');
  4711. white();
  4712. if (ch === ']') {
  4713. next(']');
  4714. return array; // empty array
  4715. }
  4716. while (ch) {
  4717. array.push(value());
  4718. white();
  4719. if (ch === ']') {
  4720. next(']');
  4721. return array;
  4722. }
  4723. next(',');
  4724. white();
  4725. }
  4726. }
  4727. error("Bad array");
  4728. },
  4729. object = function () {
  4730. // Parse an object value.
  4731. var key,
  4732. object = {};
  4733. if (ch === '{') {
  4734. next('{');
  4735. white();
  4736. if (ch === '}') {
  4737. next('}');
  4738. return object; // empty object
  4739. }
  4740. while (ch) {
  4741. key = string();
  4742. white();
  4743. next(':');
  4744. if (Object.hasOwnProperty.call(object, key)) {
  4745. error('Duplicate key "' + key + '"');
  4746. }
  4747. object[key] = value();
  4748. white();
  4749. if (ch === '}') {
  4750. next('}');
  4751. return object;
  4752. }
  4753. next(',');
  4754. white();
  4755. }
  4756. }
  4757. error("Bad object");
  4758. };
  4759. value = function () {
  4760. // Parse a JSON value. It could be an object, an array, a string, a number,
  4761. // or a word.
  4762. white();
  4763. switch (ch) {
  4764. case '{':
  4765. return object();
  4766. case '[':
  4767. return array();
  4768. case '"':
  4769. return string();
  4770. case '-':
  4771. return number();
  4772. default:
  4773. return ch >= '0' && ch <= '9' ? number() : word();
  4774. }
  4775. };
  4776. // Return the json_parse function. It will have access to all of the above
  4777. // functions and variables.
  4778. module.exports = function (source, reviver) {
  4779. var result;
  4780. text = source;
  4781. at = 0;
  4782. ch = ' ';
  4783. result = value();
  4784. white();
  4785. if (ch) {
  4786. error("Syntax error");
  4787. }
  4788. // If there is a reviver function, we recursively walk the new structure,
  4789. // passing each name/value pair to the reviver function for possible
  4790. // transformation, starting with a temporary root object that holds the result
  4791. // in an empty key. If there is not a reviver function, we simply return the
  4792. // result.
  4793. return typeof reviver === 'function' ? (function walk(holder, key) {
  4794. var k, v, value = holder[key];
  4795. if (value && typeof value === 'object') {
  4796. for (k in value) {
  4797. if (Object.prototype.hasOwnProperty.call(value, k)) {
  4798. v = walk(value, k);
  4799. if (v !== undefined) {
  4800. value[k] = v;
  4801. } else {
  4802. delete value[k];
  4803. }
  4804. }
  4805. }
  4806. }
  4807. return reviver.call(holder, key, value);
  4808. }({'': result}, '')) : result;
  4809. };
  4810. },{}],30:[function(require,module,exports){
  4811. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  4812. escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  4813. gap,
  4814. indent,
  4815. meta = { // table of character substitutions
  4816. '\b': '\\b',
  4817. '\t': '\\t',
  4818. '\n': '\\n',
  4819. '\f': '\\f',
  4820. '\r': '\\r',
  4821. '"' : '\\"',
  4822. '\\': '\\\\'
  4823. },
  4824. rep;
  4825. function quote(string) {
  4826. // If the string contains no control characters, no quote characters, and no
  4827. // backslash characters, then we can safely slap some quotes around it.
  4828. // Otherwise we must also replace the offending characters with safe escape
  4829. // sequences.
  4830. escapable.lastIndex = 0;
  4831. return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
  4832. var c = meta[a];
  4833. return typeof c === 'string' ? c :
  4834. '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  4835. }) + '"' : '"' + string + '"';
  4836. }
  4837. function str(key, holder) {
  4838. // Produce a string from holder[key].
  4839. var i, // The loop counter.
  4840. k, // The member key.
  4841. v, // The member value.
  4842. length,
  4843. mind = gap,
  4844. partial,
  4845. value = holder[key];
  4846. // If the value has a toJSON method, call it to obtain a replacement value.
  4847. if (value && typeof value === 'object' &&
  4848. typeof value.toJSON === 'function') {
  4849. value = value.toJSON(key);
  4850. }
  4851. // If we were called with a replacer function, then call the replacer to
  4852. // obtain a replacement value.
  4853. if (typeof rep === 'function') {
  4854. value = rep.call(holder, key, value);
  4855. }
  4856. // What happens next depends on the value's type.
  4857. switch (typeof value) {
  4858. case 'string':
  4859. return quote(value);
  4860. case 'number':
  4861. // JSON numbers must be finite. Encode non-finite numbers as null.
  4862. return isFinite(value) ? String(value) : 'null';
  4863. case 'boolean':
  4864. case 'null':
  4865. // If the value is a boolean or null, convert it to a string. Note:
  4866. // typeof null does not produce 'null'. The case is included here in
  4867. // the remote chance that this gets fixed someday.
  4868. return String(value);
  4869. case 'object':
  4870. if (!value) return 'null';
  4871. gap += indent;
  4872. partial = [];
  4873. // Array.isArray
  4874. if (Object.prototype.toString.apply(value) === '[object Array]') {
  4875. length = value.length;
  4876. for (i = 0; i < length; i += 1) {
  4877. partial[i] = str(i, value) || 'null';
  4878. }
  4879. // Join all of the elements together, separated with commas, and
  4880. // wrap them in brackets.
  4881. v = partial.length === 0 ? '[]' : gap ?
  4882. '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
  4883. '[' + partial.join(',') + ']';
  4884. gap = mind;
  4885. return v;
  4886. }
  4887. // If the replacer is an array, use it to select the members to be
  4888. // stringified.
  4889. if (rep && typeof rep === 'object') {
  4890. length = rep.length;
  4891. for (i = 0; i < length; i += 1) {
  4892. k = rep[i];
  4893. if (typeof k === 'string') {
  4894. v = str(k, value);
  4895. if (v) {
  4896. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  4897. }
  4898. }
  4899. }
  4900. }
  4901. else {
  4902. // Otherwise, iterate through all of the keys in the object.
  4903. for (k in value) {
  4904. if (Object.prototype.hasOwnProperty.call(value, k)) {
  4905. v = str(k, value);
  4906. if (v) {
  4907. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  4908. }
  4909. }
  4910. }
  4911. }
  4912. // Join all of the member texts together, separated with commas,
  4913. // and wrap them in braces.
  4914. v = partial.length === 0 ? '{}' : gap ?
  4915. '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
  4916. '{' + partial.join(',') + '}';
  4917. gap = mind;
  4918. return v;
  4919. }
  4920. }
  4921. module.exports = function (value, replacer, space) {
  4922. var i;
  4923. gap = '';
  4924. indent = '';
  4925. // If the space parameter is a number, make an indent string containing that
  4926. // many spaces.
  4927. if (typeof space === 'number') {
  4928. for (i = 0; i < space; i += 1) {
  4929. indent += ' ';
  4930. }
  4931. }
  4932. // If the space parameter is a string, it will be used as the indent string.
  4933. else if (typeof space === 'string') {
  4934. indent = space;
  4935. }
  4936. // If there is a replacer, it must be a function or an array.
  4937. // Otherwise, throw an error.
  4938. rep = replacer;
  4939. if (replacer && typeof replacer !== 'function'
  4940. && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
  4941. throw new Error('JSON.stringify');
  4942. }
  4943. // Make a fake root object containing our value under the key of ''.
  4944. // Return the result of stringifying the value.
  4945. return str('', {'': value});
  4946. };
  4947. },{}],31:[function(require,module,exports){
  4948. (function (process){
  4949. var through = require('through');
  4950. var nextTick = typeof setImmediate !== 'undefined'
  4951. ? setImmediate
  4952. : process.nextTick
  4953. ;
  4954. module.exports = function (write, end) {
  4955. var tr = through(write, end);
  4956. tr.pause();
  4957. var resume = tr.resume;
  4958. var pause = tr.pause;
  4959. var paused = false;
  4960. tr.pause = function () {
  4961. paused = true;
  4962. return pause.apply(this, arguments);
  4963. };
  4964. tr.resume = function () {
  4965. paused = false;
  4966. return resume.apply(this, arguments);
  4967. };
  4968. nextTick(function () {
  4969. if (!paused) tr.resume();
  4970. });
  4971. return tr;
  4972. };
  4973. }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
  4974. },{"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"through":32}],32:[function(require,module,exports){
  4975. (function (process){
  4976. var Stream = require('stream')
  4977. // through
  4978. //
  4979. // a stream that does nothing but re-emit the input.
  4980. // useful for aggregating a series of changing but not ending streams into one stream)
  4981. exports = module.exports = through
  4982. through.through = through
  4983. //create a readable writable stream.
  4984. function through (write, end, opts) {
  4985. write = write || function (data) { this.queue(data) }
  4986. end = end || function () { this.queue(null) }
  4987. var ended = false, destroyed = false, buffer = [], _ended = false
  4988. var stream = new Stream()
  4989. stream.readable = stream.writable = true
  4990. stream.paused = false
  4991. // stream.autoPause = !(opts && opts.autoPause === false)
  4992. stream.autoDestroy = !(opts && opts.autoDestroy === false)
  4993. stream.write = function (data) {
  4994. write.call(this, data)
  4995. return !stream.paused
  4996. }
  4997. function drain() {
  4998. while(buffer.length && !stream.paused) {
  4999. var data = buffer.shift()
  5000. if(null === data)
  5001. return stream.emit('end')
  5002. else
  5003. stream.emit('data', data)
  5004. }
  5005. }
  5006. stream.queue = stream.push = function (data) {
  5007. // console.error(ended)
  5008. if(_ended) return stream
  5009. if(data == null) _ended = true
  5010. buffer.push(data)
  5011. drain()
  5012. return stream
  5013. }
  5014. //this will be registered as the first 'end' listener
  5015. //must call destroy next tick, to make sure we're after any
  5016. //stream piped from here.
  5017. //this is only a problem if end is not emitted synchronously.
  5018. //a nicer way to do this is to make sure this is the last listener for 'end'
  5019. stream.on('end', function () {
  5020. stream.readable = false
  5021. if(!stream.writable && stream.autoDestroy)
  5022. process.nextTick(function () {
  5023. stream.destroy()
  5024. })
  5025. })
  5026. function _end () {
  5027. stream.writable = false
  5028. end.call(stream)
  5029. if(!stream.readable && stream.autoDestroy)
  5030. stream.destroy()
  5031. }
  5032. stream.end = function (data) {
  5033. if(ended) return
  5034. ended = true
  5035. if(arguments.length) stream.write(data)
  5036. _end() // will emit or queue
  5037. return stream
  5038. }
  5039. stream.destroy = function () {
  5040. if(destroyed) return
  5041. destroyed = true
  5042. ended = true
  5043. buffer.length = 0
  5044. stream.writable = stream.readable = false
  5045. stream.emit('close')
  5046. return stream
  5047. }
  5048. stream.pause = function () {
  5049. if(stream.paused) return
  5050. stream.paused = true
  5051. return stream
  5052. }
  5053. stream.resume = function () {
  5054. if(stream.paused) {
  5055. stream.paused = false
  5056. stream.emit('resume')
  5057. }
  5058. drain()
  5059. //may have become paused again,
  5060. //as drain emits 'data'.
  5061. if(!stream.paused)
  5062. stream.emit('drain')
  5063. return stream
  5064. }
  5065. return stream
  5066. }
  5067. }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
  5068. },{"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"stream":9}],33:[function(require,module,exports){
  5069. var test = require('tape')
  5070. var isFunction = require('./index.js')
  5071. test('isFunction', function (t) {
  5072. t.ok(!isFunction(), 'undefined is not a function')
  5073. t.ok(!isFunction(null), 'null is not a function')
  5074. t.ok(!isFunction(''), 'string is not a function')
  5075. t.ok(!isFunction(/a/), 'regex is not a function')
  5076. t.ok(!isFunction(true), 'true is not a function')
  5077. t.ok(!isFunction(false), 'false is not a function')
  5078. t.ok(!isFunction(NaN), 'NaN is not a function')
  5079. t.ok(!isFunction(42), '42 is not a function')
  5080. t.ok(isFunction(function () {}), 'function is a function')
  5081. t.ok(isFunction(setTimeout), 'setTimeout is a function')
  5082. t.end()
  5083. })
  5084. if (typeof window !== 'undefined') {
  5085. test('browser quirks', function (t) {
  5086. t.plan(2)
  5087. t.ok(isFunction(window.alert), 'alert is a function')
  5088. window.testRegExpFromIframe = function (regexp) {
  5089. t.ok(!isFunction(regexp))
  5090. }
  5091. var iframe = document.createElement('iframe')
  5092. document.body.appendChild(iframe)
  5093. iframe.contentWindow.document.write([
  5094. "<html><body><script type=\"text/javascript\">",
  5095. "parent.testRegExpFromIframe(/a/)",
  5096. "</script></body></html>"
  5097. ].join("\n"));
  5098. })
  5099. }
  5100. },{"./index.js":18,"tape":19}]},{},[33])