bluebird.js 169 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140
  1. /**
  2. * bluebird build version 1.0.8
  3. * Features enabled: core, timers, race, any, call_get, filter, generators, map, nodeify, promisify, props, reduce, settle, some, progress, cancel, synchronous_inspection
  4. */
  5. /**
  6. * @preserve Copyright (c) 2014 Petka Antonov
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:</p>
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. !function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Promise=e():"undefined"!=typeof global?global.Promise=e():"undefined"!=typeof self&&(self.Promise=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof 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){
  28. /**
  29. * Copyright (c) 2014 Petka Antonov
  30. *
  31. * Permission is hereby granted, free of charge, to any person obtaining a copy
  32. * of this software and associated documentation files (the "Software"), to deal
  33. * in the Software without restriction, including without limitation the rights
  34. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  35. * copies of the Software, and to permit persons to whom the Software is
  36. * furnished to do so, subject to the following conditions:</p>
  37. *
  38. * The above copyright notice and this permission notice shall be included in
  39. * all copies or substantial portions of the Software.
  40. *
  41. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  42. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  43. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  44. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  45. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  46. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  47. * THE SOFTWARE.
  48. *
  49. */
  50. "use strict";
  51. module.exports = function(Promise, Promise$_CreatePromiseArray, PromiseArray) {
  52. var SomePromiseArray = require("./some_promise_array.js")(PromiseArray);
  53. var ASSERT = require("./assert.js");
  54. function Promise$_Any(promises, useBound, caller) {
  55. var ret = Promise$_CreatePromiseArray(
  56. promises,
  57. SomePromiseArray,
  58. caller,
  59. useBound === true && promises._isBound()
  60. ? promises._boundTo
  61. : void 0
  62. );
  63. var promise = ret.promise();
  64. if (promise.isRejected()) {
  65. return promise;
  66. }
  67. ret.setHowMany(1);
  68. ret.setUnwrap();
  69. ret.init();
  70. return promise;
  71. }
  72. Promise.any = function Promise$Any(promises) {
  73. return Promise$_Any(promises, false, Promise.any);
  74. };
  75. Promise.prototype.any = function Promise$any() {
  76. return Promise$_Any(this, true, this.any);
  77. };
  78. };
  79. },{"./assert.js":2,"./some_promise_array.js":35}],2:[function(require,module,exports){
  80. /**
  81. * Copyright (c) 2014 Petka Antonov
  82. *
  83. * Permission is hereby granted, free of charge, to any person obtaining a copy
  84. * of this software and associated documentation files (the "Software"), to deal
  85. * in the Software without restriction, including without limitation the rights
  86. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  87. * copies of the Software, and to permit persons to whom the Software is
  88. * furnished to do so, subject to the following conditions:</p>
  89. *
  90. * The above copyright notice and this permission notice shall be included in
  91. * all copies or substantial portions of the Software.
  92. *
  93. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  94. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  95. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  96. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  97. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  98. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  99. * THE SOFTWARE.
  100. *
  101. */
  102. "use strict";
  103. module.exports = (function(){
  104. var AssertionError = (function() {
  105. function AssertionError(a) {
  106. this.constructor$(a);
  107. this.message = a;
  108. this.name = "AssertionError";
  109. }
  110. AssertionError.prototype = new Error();
  111. AssertionError.prototype.constructor = AssertionError;
  112. AssertionError.prototype.constructor$ = Error;
  113. return AssertionError;
  114. })();
  115. return function assert(boolExpr, message) {
  116. if (boolExpr === true) return;
  117. var ret = new AssertionError(message);
  118. if (Error.captureStackTrace) {
  119. Error.captureStackTrace(ret, assert);
  120. }
  121. if (console && console.error) {
  122. console.error(ret.stack + "");
  123. }
  124. throw ret;
  125. };
  126. })();
  127. },{}],3:[function(require,module,exports){
  128. /**
  129. * Copyright (c) 2014 Petka Antonov
  130. *
  131. * Permission is hereby granted, free of charge, to any person obtaining a copy
  132. * of this software and associated documentation files (the "Software"), to deal
  133. * in the Software without restriction, including without limitation the rights
  134. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  135. * copies of the Software, and to permit persons to whom the Software is
  136. * furnished to do so, subject to the following conditions:</p>
  137. *
  138. * The above copyright notice and this permission notice shall be included in
  139. * all copies or substantial portions of the Software.
  140. *
  141. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  142. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  143. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  144. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  145. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  146. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  147. * THE SOFTWARE.
  148. *
  149. */
  150. "use strict";
  151. var ASSERT = require("./assert.js");
  152. var schedule = require("./schedule.js");
  153. var Queue = require("./queue.js");
  154. var errorObj = require("./util.js").errorObj;
  155. var tryCatch1 = require("./util.js").tryCatch1;
  156. function Async() {
  157. this._isTickUsed = false;
  158. this._length = 0;
  159. this._lateBuffer = new Queue();
  160. this._functionBuffer = new Queue(25000 * 3);
  161. var self = this;
  162. this.consumeFunctionBuffer = function Async$consumeFunctionBuffer() {
  163. self._consumeFunctionBuffer();
  164. };
  165. }
  166. Async.prototype.haveItemsQueued = function Async$haveItemsQueued() {
  167. return this._length > 0;
  168. };
  169. Async.prototype.invokeLater = function Async$invokeLater(fn, receiver, arg) {
  170. this._lateBuffer.push(fn, receiver, arg);
  171. this._queueTick();
  172. };
  173. Async.prototype.invoke = function Async$invoke(fn, receiver, arg) {
  174. var functionBuffer = this._functionBuffer;
  175. functionBuffer.push(fn, receiver, arg);
  176. this._length = functionBuffer.length();
  177. this._queueTick();
  178. };
  179. Async.prototype._consumeFunctionBuffer =
  180. function Async$_consumeFunctionBuffer() {
  181. var functionBuffer = this._functionBuffer;
  182. while(functionBuffer.length() > 0) {
  183. var fn = functionBuffer.shift();
  184. var receiver = functionBuffer.shift();
  185. var arg = functionBuffer.shift();
  186. fn.call(receiver, arg);
  187. }
  188. this._reset();
  189. this._consumeLateBuffer();
  190. };
  191. Async.prototype._consumeLateBuffer = function Async$_consumeLateBuffer() {
  192. var buffer = this._lateBuffer;
  193. while(buffer.length() > 0) {
  194. var fn = buffer.shift();
  195. var receiver = buffer.shift();
  196. var arg = buffer.shift();
  197. var res = tryCatch1(fn, receiver, arg);
  198. if (res === errorObj) {
  199. this._queueTick();
  200. throw res.e;
  201. }
  202. }
  203. };
  204. Async.prototype._queueTick = function Async$_queue() {
  205. if (!this._isTickUsed) {
  206. schedule(this.consumeFunctionBuffer);
  207. this._isTickUsed = true;
  208. }
  209. };
  210. Async.prototype._reset = function Async$_reset() {
  211. this._isTickUsed = false;
  212. this._length = 0;
  213. };
  214. module.exports = new Async();
  215. },{"./assert.js":2,"./queue.js":28,"./schedule.js":31,"./util.js":39}],4:[function(require,module,exports){
  216. /**
  217. * Copyright (c) 2014 Petka Antonov
  218. *
  219. * Permission is hereby granted, free of charge, to any person obtaining a copy
  220. * of this software and associated documentation files (the "Software"), to deal
  221. * in the Software without restriction, including without limitation the rights
  222. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  223. * copies of the Software, and to permit persons to whom the Software is
  224. * furnished to do so, subject to the following conditions:</p>
  225. *
  226. * The above copyright notice and this permission notice shall be included in
  227. * all copies or substantial portions of the Software.
  228. *
  229. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  230. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  231. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  232. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  233. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  234. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  235. * THE SOFTWARE.
  236. *
  237. */
  238. "use strict";
  239. var Promise = require("./promise.js")();
  240. module.exports = Promise;
  241. },{"./promise.js":20}],5:[function(require,module,exports){
  242. /**
  243. * Copyright (c) 2014 Petka Antonov
  244. *
  245. * Permission is hereby granted, free of charge, to any person obtaining a copy
  246. * of this software and associated documentation files (the "Software"), to deal
  247. * in the Software without restriction, including without limitation the rights
  248. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  249. * copies of the Software, and to permit persons to whom the Software is
  250. * furnished to do so, subject to the following conditions:</p>
  251. *
  252. * The above copyright notice and this permission notice shall be included in
  253. * all copies or substantial portions of the Software.
  254. *
  255. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  256. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  257. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  258. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  259. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  260. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  261. * THE SOFTWARE.
  262. *
  263. */
  264. "use strict";
  265. module.exports = function(Promise) {
  266. Promise.prototype.call = function Promise$call(propertyName) {
  267. var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
  268. return this._then(function(obj) {
  269. return obj[propertyName].apply(obj, args);
  270. },
  271. void 0,
  272. void 0,
  273. void 0,
  274. void 0,
  275. this.call
  276. );
  277. };
  278. function Promise$getter(obj) {
  279. var prop = typeof this === "string"
  280. ? this
  281. : ("" + this);
  282. return obj[prop];
  283. }
  284. Promise.prototype.get = function Promise$get(propertyName) {
  285. return this._then(
  286. Promise$getter,
  287. void 0,
  288. void 0,
  289. propertyName,
  290. void 0,
  291. this.get
  292. );
  293. };
  294. };
  295. },{}],6:[function(require,module,exports){
  296. /**
  297. * Copyright (c) 2014 Petka Antonov
  298. *
  299. * Permission is hereby granted, free of charge, to any person obtaining a copy
  300. * of this software and associated documentation files (the "Software"), to deal
  301. * in the Software without restriction, including without limitation the rights
  302. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  303. * copies of the Software, and to permit persons to whom the Software is
  304. * furnished to do so, subject to the following conditions:</p>
  305. *
  306. * The above copyright notice and this permission notice shall be included in
  307. * all copies or substantial portions of the Software.
  308. *
  309. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  310. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  311. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  312. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  313. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  314. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  315. * THE SOFTWARE.
  316. *
  317. */
  318. "use strict";
  319. module.exports = function(Promise, INTERNAL) {
  320. var errors = require("./errors.js");
  321. var async = require("./async.js");
  322. var ASSERT = require("./assert.js");
  323. var CancellationError = errors.CancellationError;
  324. var SYNC_TOKEN = {};
  325. Promise.prototype._cancel = function Promise$_cancel() {
  326. if (!this.isCancellable()) return this;
  327. var parent;
  328. if ((parent = this._cancellationParent) !== void 0 &&
  329. parent.isCancellable()) {
  330. parent.cancel(SYNC_TOKEN);
  331. return;
  332. }
  333. var err = new CancellationError();
  334. this._attachExtraTrace(err);
  335. this._rejectUnchecked(err);
  336. };
  337. Promise.prototype.cancel = function Promise$cancel(token) {
  338. if (!this.isCancellable()) return this;
  339. if (token === SYNC_TOKEN) {
  340. this._cancel();
  341. return this;
  342. }
  343. async.invokeLater(this._cancel, this, void 0);
  344. return this;
  345. };
  346. Promise.prototype.cancellable = function Promise$cancellable() {
  347. if (this._cancellable()) return this;
  348. this._setCancellable();
  349. this._cancellationParent = void 0;
  350. return this;
  351. };
  352. Promise.prototype.uncancellable = function Promise$uncancellable() {
  353. var ret = new Promise(INTERNAL);
  354. ret._setTrace(this.uncancellable, this);
  355. ret._follow(this);
  356. ret._unsetCancellable();
  357. if (this._isBound()) ret._setBoundTo(this._boundTo);
  358. return ret;
  359. };
  360. Promise.prototype.fork =
  361. function Promise$fork(didFulfill, didReject, didProgress) {
  362. var ret = this._then(didFulfill, didReject, didProgress,
  363. void 0, void 0, this.fork);
  364. ret._setCancellable();
  365. ret._cancellationParent = void 0;
  366. return ret;
  367. };
  368. };
  369. },{"./assert.js":2,"./async.js":3,"./errors.js":10}],7:[function(require,module,exports){
  370. /**
  371. * Copyright (c) 2014 Petka Antonov
  372. *
  373. * Permission is hereby granted, free of charge, to any person obtaining a copy
  374. * of this software and associated documentation files (the "Software"), to deal
  375. * in the Software without restriction, including without limitation the rights
  376. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  377. * copies of the Software, and to permit persons to whom the Software is
  378. * furnished to do so, subject to the following conditions:</p>
  379. *
  380. * The above copyright notice and this permission notice shall be included in
  381. * all copies or substantial portions of the Software.
  382. *
  383. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  384. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  385. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  386. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  387. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  388. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  389. * THE SOFTWARE.
  390. *
  391. */
  392. "use strict";
  393. module.exports = function() {
  394. var ASSERT = require("./assert.js");
  395. var inherits = require("./util.js").inherits;
  396. var defineProperty = require("./es5.js").defineProperty;
  397. var rignore = new RegExp(
  398. "\\b(?:[\\w.]*Promise(?:Array|Spawn)?\\$_\\w+|" +
  399. "tryCatch(?:1|2|Apply)|new \\w*PromiseArray|" +
  400. "\\w*PromiseArray\\.\\w*PromiseArray|" +
  401. "setTimeout|CatchFilter\\$_\\w+|makeNodePromisified|processImmediate|" +
  402. "process._tickCallback|nextTick|Async\\$\\w+)\\b"
  403. );
  404. var rtraceline = null;
  405. var formatStack = null;
  406. var areNamesMangled = false;
  407. function formatNonError(obj) {
  408. var str;
  409. if (typeof obj === "function") {
  410. str = "[function " +
  411. (obj.name || "anonymous") +
  412. "]";
  413. }
  414. else {
  415. str = obj.toString();
  416. var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
  417. if (ruselessToString.test(str)) {
  418. try {
  419. var newStr = JSON.stringify(obj);
  420. str = newStr;
  421. }
  422. catch(e) {
  423. }
  424. }
  425. if (str.length === 0) {
  426. str = "(empty array)";
  427. }
  428. }
  429. return ("(<" + snip(str) + ">, no stack trace)");
  430. }
  431. function snip(str) {
  432. var maxChars = 41;
  433. if (str.length < maxChars) {
  434. return str;
  435. }
  436. return str.substr(0, maxChars - 3) + "...";
  437. }
  438. function CapturedTrace(ignoreUntil, isTopLevel) {
  439. if (!areNamesMangled) {
  440. }
  441. this.captureStackTrace(ignoreUntil, isTopLevel);
  442. }
  443. inherits(CapturedTrace, Error);
  444. CapturedTrace.prototype.captureStackTrace =
  445. function CapturedTrace$captureStackTrace(ignoreUntil, isTopLevel) {
  446. captureStackTrace(this, ignoreUntil, isTopLevel);
  447. };
  448. CapturedTrace.possiblyUnhandledRejection =
  449. function CapturedTrace$PossiblyUnhandledRejection(reason) {
  450. if (typeof console === "object") {
  451. var message;
  452. if (typeof reason === "object" || typeof reason === "function") {
  453. var stack = reason.stack;
  454. message = "Possibly unhandled " + formatStack(stack, reason);
  455. }
  456. else {
  457. message = "Possibly unhandled " + String(reason);
  458. }
  459. if (typeof console.error === "function" ||
  460. typeof console.error === "object") {
  461. console.error(message);
  462. }
  463. else if (typeof console.log === "function" ||
  464. typeof console.error === "object") {
  465. console.log(message);
  466. }
  467. }
  468. };
  469. areNamesMangled = CapturedTrace.prototype.captureStackTrace.name !==
  470. "CapturedTrace$captureStackTrace";
  471. CapturedTrace.combine = function CapturedTrace$Combine(current, prev) {
  472. var curLast = current.length - 1;
  473. for (var i = prev.length - 1; i >= 0; --i) {
  474. var line = prev[i];
  475. if (current[curLast] === line) {
  476. current.pop();
  477. curLast--;
  478. }
  479. else {
  480. break;
  481. }
  482. }
  483. current.push("From previous event:");
  484. var lines = current.concat(prev);
  485. var ret = [];
  486. for (var i = 0, len = lines.length; i < len; ++i) {
  487. if ((rignore.test(lines[i]) ||
  488. (i > 0 && !rtraceline.test(lines[i])) &&
  489. lines[i] !== "From previous event:")
  490. ) {
  491. continue;
  492. }
  493. ret.push(lines[i]);
  494. }
  495. return ret;
  496. };
  497. CapturedTrace.isSupported = function CapturedTrace$IsSupported() {
  498. return typeof captureStackTrace === "function";
  499. };
  500. var captureStackTrace = (function stackDetection() {
  501. if (typeof Error.stackTraceLimit === "number" &&
  502. typeof Error.captureStackTrace === "function") {
  503. rtraceline = /^\s*at\s*/;
  504. formatStack = function(stack, error) {
  505. if (typeof stack === "string") return stack;
  506. if (error.name !== void 0 &&
  507. error.message !== void 0) {
  508. return error.name + ". " + error.message;
  509. }
  510. return formatNonError(error);
  511. };
  512. var captureStackTrace = Error.captureStackTrace;
  513. return function CapturedTrace$_captureStackTrace(
  514. receiver, ignoreUntil) {
  515. captureStackTrace(receiver, ignoreUntil);
  516. };
  517. }
  518. var err = new Error();
  519. if (!areNamesMangled && typeof err.stack === "string" &&
  520. typeof "".startsWith === "function" &&
  521. (err.stack.startsWith("stackDetection@")) &&
  522. stackDetection.name === "stackDetection") {
  523. defineProperty(Error, "stackTraceLimit", {
  524. writable: true,
  525. enumerable: false,
  526. configurable: false,
  527. value: 25
  528. });
  529. rtraceline = /@/;
  530. var rline = /[@\n]/;
  531. formatStack = function(stack, error) {
  532. if (typeof stack === "string") {
  533. return (error.name + ". " + error.message + "\n" + stack);
  534. }
  535. if (error.name !== void 0 &&
  536. error.message !== void 0) {
  537. return error.name + ". " + error.message;
  538. }
  539. return formatNonError(error);
  540. };
  541. return function captureStackTrace(o, fn) {
  542. var name = fn.name;
  543. var stack = new Error().stack;
  544. var split = stack.split(rline);
  545. var i, len = split.length;
  546. for (i = 0; i < len; i += 2) {
  547. if (split[i] === name) {
  548. break;
  549. }
  550. }
  551. split = split.slice(i + 2);
  552. len = split.length - 2;
  553. var ret = "";
  554. for (i = 0; i < len; i += 2) {
  555. ret += split[i];
  556. ret += "@";
  557. ret += split[i + 1];
  558. ret += "\n";
  559. }
  560. o.stack = ret;
  561. };
  562. }
  563. else {
  564. formatStack = function(stack, error) {
  565. if (typeof stack === "string") return stack;
  566. if ((typeof error === "object" ||
  567. typeof error === "function") &&
  568. error.name !== void 0 &&
  569. error.message !== void 0) {
  570. return error.name + ". " + error.message;
  571. }
  572. return formatNonError(error);
  573. };
  574. return null;
  575. }
  576. })();
  577. return CapturedTrace;
  578. };
  579. },{"./assert.js":2,"./es5.js":12,"./util.js":39}],8:[function(require,module,exports){
  580. /**
  581. * Copyright (c) 2014 Petka Antonov
  582. *
  583. * Permission is hereby granted, free of charge, to any person obtaining a copy
  584. * of this software and associated documentation files (the "Software"), to deal
  585. * in the Software without restriction, including without limitation the rights
  586. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  587. * copies of the Software, and to permit persons to whom the Software is
  588. * furnished to do so, subject to the following conditions:</p>
  589. *
  590. * The above copyright notice and this permission notice shall be included in
  591. * all copies or substantial portions of the Software.
  592. *
  593. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  594. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  595. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  596. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  597. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  598. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  599. * THE SOFTWARE.
  600. *
  601. */
  602. "use strict";
  603. module.exports = function(NEXT_FILTER) {
  604. var util = require("./util.js");
  605. var errors = require("./errors.js");
  606. var tryCatch1 = util.tryCatch1;
  607. var errorObj = util.errorObj;
  608. var keys = require("./es5.js").keys;
  609. function CatchFilter(instances, callback, promise) {
  610. this._instances = instances;
  611. this._callback = callback;
  612. this._promise = promise;
  613. }
  614. function CatchFilter$_safePredicate(predicate, e) {
  615. var safeObject = {};
  616. var retfilter = tryCatch1(predicate, safeObject, e);
  617. if (retfilter === errorObj) return retfilter;
  618. var safeKeys = keys(safeObject);
  619. if (safeKeys.length) {
  620. errorObj.e = new TypeError(
  621. "Catch filter must inherit from Error "
  622. + "or be a simple predicate function");
  623. return errorObj;
  624. }
  625. return retfilter;
  626. }
  627. CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) {
  628. var cb = this._callback;
  629. var promise = this._promise;
  630. var boundTo = promise._isBound() ? promise._boundTo : void 0;
  631. for (var i = 0, len = this._instances.length; i < len; ++i) {
  632. var item = this._instances[i];
  633. var itemIsErrorType = item === Error ||
  634. (item != null && item.prototype instanceof Error);
  635. if (itemIsErrorType && e instanceof item) {
  636. var ret = tryCatch1(cb, boundTo, e);
  637. if (ret === errorObj) {
  638. NEXT_FILTER.e = ret.e;
  639. return NEXT_FILTER;
  640. }
  641. return ret;
  642. } else if (typeof item === "function" && !itemIsErrorType) {
  643. var shouldHandle = CatchFilter$_safePredicate(item, e);
  644. if (shouldHandle === errorObj) {
  645. var trace = errors.canAttach(errorObj.e)
  646. ? errorObj.e
  647. : new Error(errorObj.e + "");
  648. this._promise._attachExtraTrace(trace);
  649. e = errorObj.e;
  650. break;
  651. } else if (shouldHandle) {
  652. var ret = tryCatch1(cb, boundTo, e);
  653. if (ret === errorObj) {
  654. NEXT_FILTER.e = ret.e;
  655. return NEXT_FILTER;
  656. }
  657. return ret;
  658. }
  659. }
  660. }
  661. NEXT_FILTER.e = e;
  662. return NEXT_FILTER;
  663. };
  664. return CatchFilter;
  665. };
  666. },{"./errors.js":10,"./es5.js":12,"./util.js":39}],9:[function(require,module,exports){
  667. /**
  668. * Copyright (c) 2014 Petka Antonov
  669. *
  670. * Permission is hereby granted, free of charge, to any person obtaining a copy
  671. * of this software and associated documentation files (the "Software"), to deal
  672. * in the Software without restriction, including without limitation the rights
  673. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  674. * copies of the Software, and to permit persons to whom the Software is
  675. * furnished to do so, subject to the following conditions:</p>
  676. *
  677. * The above copyright notice and this permission notice shall be included in
  678. * all copies or substantial portions of the Software.
  679. *
  680. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  681. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  682. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  683. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  684. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  685. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  686. * THE SOFTWARE.
  687. *
  688. */
  689. "use strict";
  690. var util = require("./util.js");
  691. var ASSERT = require("./assert.js");
  692. var isPrimitive = util.isPrimitive;
  693. var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
  694. module.exports = function(Promise) {
  695. var returner = function Promise$_returner() {
  696. return this;
  697. };
  698. var thrower = function Promise$_thrower() {
  699. throw this;
  700. };
  701. var wrapper = function Promise$_wrapper(value, action) {
  702. if (action === 1) {
  703. return function Promise$_thrower() {
  704. throw value;
  705. };
  706. }
  707. else if (action === 2) {
  708. return function Promise$_returner() {
  709. return value;
  710. };
  711. }
  712. };
  713. Promise.prototype["return"] =
  714. Promise.prototype.thenReturn =
  715. function Promise$thenReturn(value) {
  716. if (wrapsPrimitiveReceiver && isPrimitive(value)) {
  717. return this._then(
  718. wrapper(value, 2),
  719. void 0,
  720. void 0,
  721. void 0,
  722. void 0,
  723. this.thenReturn
  724. );
  725. }
  726. return this._then(returner, void 0, void 0,
  727. value, void 0, this.thenReturn);
  728. };
  729. Promise.prototype["throw"] =
  730. Promise.prototype.thenThrow =
  731. function Promise$thenThrow(reason) {
  732. if (wrapsPrimitiveReceiver && isPrimitive(reason)) {
  733. return this._then(
  734. wrapper(reason, 1),
  735. void 0,
  736. void 0,
  737. void 0,
  738. void 0,
  739. this.thenThrow
  740. );
  741. }
  742. return this._then(thrower, void 0, void 0,
  743. reason, void 0, this.thenThrow);
  744. };
  745. };
  746. },{"./assert.js":2,"./util.js":39}],10:[function(require,module,exports){
  747. /**
  748. * Copyright (c) 2014 Petka Antonov
  749. *
  750. * Permission is hereby granted, free of charge, to any person obtaining a copy
  751. * of this software and associated documentation files (the "Software"), to deal
  752. * in the Software without restriction, including without limitation the rights
  753. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  754. * copies of the Software, and to permit persons to whom the Software is
  755. * furnished to do so, subject to the following conditions:</p>
  756. *
  757. * The above copyright notice and this permission notice shall be included in
  758. * all copies or substantial portions of the Software.
  759. *
  760. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  761. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  762. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  763. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  764. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  765. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  766. * THE SOFTWARE.
  767. *
  768. */
  769. "use strict";
  770. var global = require("./global.js");
  771. var Objectfreeze = require("./es5.js").freeze;
  772. var util = require("./util.js");
  773. var inherits = util.inherits;
  774. var notEnumerableProp = util.notEnumerableProp;
  775. var Error = global.Error;
  776. function markAsOriginatingFromRejection(e) {
  777. try {
  778. notEnumerableProp(e, "isAsync", true);
  779. }
  780. catch(ignore) {}
  781. }
  782. function originatesFromRejection(e) {
  783. if (e == null) return false;
  784. return ((e instanceof RejectionError) ||
  785. e["isAsync"] === true);
  786. }
  787. function isError(obj) {
  788. return obj instanceof Error;
  789. }
  790. function canAttach(obj) {
  791. return isError(obj);
  792. }
  793. function subError(nameProperty, defaultMessage) {
  794. function SubError(message) {
  795. if (!(this instanceof SubError)) return new SubError(message);
  796. this.message = typeof message === "string" ? message : defaultMessage;
  797. this.name = nameProperty;
  798. if (Error.captureStackTrace) {
  799. Error.captureStackTrace(this, this.constructor);
  800. }
  801. }
  802. inherits(SubError, Error);
  803. return SubError;
  804. }
  805. var TypeError = global.TypeError;
  806. if (typeof TypeError !== "function") {
  807. TypeError = subError("TypeError", "type error");
  808. }
  809. var RangeError = global.RangeError;
  810. if (typeof RangeError !== "function") {
  811. RangeError = subError("RangeError", "range error");
  812. }
  813. var CancellationError = subError("CancellationError", "cancellation error");
  814. var TimeoutError = subError("TimeoutError", "timeout error");
  815. function RejectionError(message) {
  816. this.name = "RejectionError";
  817. this.message = message;
  818. this.cause = message;
  819. this.isAsync = true;
  820. if (message instanceof Error) {
  821. this.message = message.message;
  822. this.stack = message.stack;
  823. }
  824. else if (Error.captureStackTrace) {
  825. Error.captureStackTrace(this, this.constructor);
  826. }
  827. }
  828. inherits(RejectionError, Error);
  829. var key = "__BluebirdErrorTypes__";
  830. var errorTypes = global[key];
  831. if (!errorTypes) {
  832. errorTypes = Objectfreeze({
  833. CancellationError: CancellationError,
  834. TimeoutError: TimeoutError,
  835. RejectionError: RejectionError
  836. });
  837. notEnumerableProp(global, key, errorTypes);
  838. }
  839. module.exports = {
  840. Error: Error,
  841. TypeError: TypeError,
  842. RangeError: RangeError,
  843. CancellationError: errorTypes.CancellationError,
  844. RejectionError: errorTypes.RejectionError,
  845. TimeoutError: errorTypes.TimeoutError,
  846. originatesFromRejection: originatesFromRejection,
  847. markAsOriginatingFromRejection: markAsOriginatingFromRejection,
  848. canAttach: canAttach
  849. };
  850. },{"./es5.js":12,"./global.js":16,"./util.js":39}],11:[function(require,module,exports){
  851. /**
  852. * Copyright (c) 2014 Petka Antonov
  853. *
  854. * Permission is hereby granted, free of charge, to any person obtaining a copy
  855. * of this software and associated documentation files (the "Software"), to deal
  856. * in the Software without restriction, including without limitation the rights
  857. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  858. * copies of the Software, and to permit persons to whom the Software is
  859. * furnished to do so, subject to the following conditions:</p>
  860. *
  861. * The above copyright notice and this permission notice shall be included in
  862. * all copies or substantial portions of the Software.
  863. *
  864. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  865. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  866. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  867. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  868. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  869. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  870. * THE SOFTWARE.
  871. *
  872. */
  873. "use strict";
  874. module.exports = function(Promise) {
  875. var TypeError = require('./errors.js').TypeError;
  876. function apiRejection(msg) {
  877. var error = new TypeError(msg);
  878. var ret = Promise.rejected(error);
  879. var parent = ret._peekContext();
  880. if (parent != null) {
  881. parent._attachExtraTrace(error);
  882. }
  883. return ret;
  884. }
  885. return apiRejection;
  886. };
  887. },{"./errors.js":10}],12:[function(require,module,exports){
  888. /**
  889. * Copyright (c) 2014 Petka Antonov
  890. *
  891. * Permission is hereby granted, free of charge, to any person obtaining a copy
  892. * of this software and associated documentation files (the "Software"), to deal
  893. * in the Software without restriction, including without limitation the rights
  894. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  895. * copies of the Software, and to permit persons to whom the Software is
  896. * furnished to do so, subject to the following conditions:</p>
  897. *
  898. * The above copyright notice and this permission notice shall be included in
  899. * all copies or substantial portions of the Software.
  900. *
  901. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  902. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  903. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  904. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  905. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  906. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  907. * THE SOFTWARE.
  908. *
  909. */
  910. var isES5 = (function(){
  911. "use strict";
  912. return this === void 0;
  913. })();
  914. if (isES5) {
  915. module.exports = {
  916. freeze: Object.freeze,
  917. defineProperty: Object.defineProperty,
  918. keys: Object.keys,
  919. getPrototypeOf: Object.getPrototypeOf,
  920. isArray: Array.isArray,
  921. isES5: isES5
  922. };
  923. }
  924. else {
  925. var has = {}.hasOwnProperty;
  926. var str = {}.toString;
  927. var proto = {}.constructor.prototype;
  928. function ObjectKeys(o) {
  929. var ret = [];
  930. for (var key in o) {
  931. if (has.call(o, key)) {
  932. ret.push(key);
  933. }
  934. }
  935. return ret;
  936. }
  937. function ObjectDefineProperty(o, key, desc) {
  938. o[key] = desc.value;
  939. return o;
  940. }
  941. function ObjectFreeze(obj) {
  942. return obj;
  943. }
  944. function ObjectGetPrototypeOf(obj) {
  945. try {
  946. return Object(obj).constructor.prototype;
  947. }
  948. catch (e) {
  949. return proto;
  950. }
  951. }
  952. function ArrayIsArray(obj) {
  953. try {
  954. return str.call(obj) === "[object Array]";
  955. }
  956. catch(e) {
  957. return false;
  958. }
  959. }
  960. module.exports = {
  961. isArray: ArrayIsArray,
  962. keys: ObjectKeys,
  963. defineProperty: ObjectDefineProperty,
  964. freeze: ObjectFreeze,
  965. getPrototypeOf: ObjectGetPrototypeOf,
  966. isES5: isES5
  967. };
  968. }
  969. },{}],13:[function(require,module,exports){
  970. /**
  971. * Copyright (c) 2014 Petka Antonov
  972. *
  973. * Permission is hereby granted, free of charge, to any person obtaining a copy
  974. * of this software and associated documentation files (the "Software"), to deal
  975. * in the Software without restriction, including without limitation the rights
  976. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  977. * copies of the Software, and to permit persons to whom the Software is
  978. * furnished to do so, subject to the following conditions:</p>
  979. *
  980. * The above copyright notice and this permission notice shall be included in
  981. * all copies or substantial portions of the Software.
  982. *
  983. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  984. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  985. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  986. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  987. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  988. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  989. * THE SOFTWARE.
  990. *
  991. */
  992. "use strict";
  993. module.exports = function(Promise) {
  994. var ASSERT = require("./assert.js");
  995. var isArray = require("./util.js").isArray;
  996. function Promise$_filter(booleans) {
  997. var values = this._settledValue;
  998. var len = values.length;
  999. var ret = new Array(len);
  1000. var j = 0;
  1001. for (var i = 0; i < len; ++i) {
  1002. if (booleans[i]) ret[j++] = values[i];
  1003. }
  1004. ret.length = j;
  1005. return ret;
  1006. }
  1007. var ref = {ref: null};
  1008. Promise.filter = function Promise$Filter(promises, fn) {
  1009. return Promise.map(promises, fn, ref)
  1010. ._then(Promise$_filter, void 0, void 0,
  1011. ref.ref, void 0, Promise.filter);
  1012. };
  1013. Promise.prototype.filter = function Promise$filter(fn) {
  1014. return this.map(fn, ref)
  1015. ._then(Promise$_filter, void 0, void 0,
  1016. ref.ref, void 0, this.filter);
  1017. };
  1018. };
  1019. },{"./assert.js":2,"./util.js":39}],14:[function(require,module,exports){
  1020. /**
  1021. * Copyright (c) 2014 Petka Antonov
  1022. *
  1023. * Permission is hereby granted, free of charge, to any person obtaining a copy
  1024. * of this software and associated documentation files (the "Software"), to deal
  1025. * in the Software without restriction, including without limitation the rights
  1026. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1027. * copies of the Software, and to permit persons to whom the Software is
  1028. * furnished to do so, subject to the following conditions:</p>
  1029. *
  1030. * The above copyright notice and this permission notice shall be included in
  1031. * all copies or substantial portions of the Software.
  1032. *
  1033. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1034. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1035. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1036. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1037. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1038. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  1039. * THE SOFTWARE.
  1040. *
  1041. */
  1042. module.exports = function(Promise, NEXT_FILTER) {
  1043. var util = require("./util.js");
  1044. var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
  1045. var isPrimitive = util.isPrimitive;
  1046. var thrower = util.thrower;
  1047. function returnThis() {
  1048. return this;
  1049. }
  1050. function throwThis() {
  1051. throw this;
  1052. }
  1053. function makeReturner(r) {
  1054. return function Promise$_returner() {
  1055. return r;
  1056. };
  1057. }
  1058. function makeThrower(r) {
  1059. return function Promise$_thrower() {
  1060. throw r;
  1061. };
  1062. }
  1063. function promisedFinally(ret, reasonOrValue, isFulfilled) {
  1064. var useConstantFunction =
  1065. wrapsPrimitiveReceiver && isPrimitive(reasonOrValue);
  1066. if (isFulfilled) {
  1067. return ret._then(
  1068. useConstantFunction
  1069. ? returnThis
  1070. : makeReturner(reasonOrValue),
  1071. thrower, void 0, reasonOrValue, void 0, promisedFinally);
  1072. }
  1073. else {
  1074. return ret._then(
  1075. useConstantFunction
  1076. ? throwThis
  1077. : makeThrower(reasonOrValue),
  1078. thrower, void 0, reasonOrValue, void 0, promisedFinally);
  1079. }
  1080. }
  1081. function finallyHandler(reasonOrValue) {
  1082. var promise = this.promise;
  1083. var handler = this.handler;
  1084. var ret = promise._isBound()
  1085. ? handler.call(promise._boundTo)
  1086. : handler();
  1087. if (ret !== void 0) {
  1088. var maybePromise = Promise._cast(ret, finallyHandler, void 0);
  1089. if (Promise.is(maybePromise)) {
  1090. return promisedFinally(maybePromise, reasonOrValue,
  1091. promise.isFulfilled());
  1092. }
  1093. }
  1094. if (promise.isRejected()) {
  1095. NEXT_FILTER.e = reasonOrValue;
  1096. return NEXT_FILTER;
  1097. }
  1098. else {
  1099. return reasonOrValue;
  1100. }
  1101. }
  1102. Promise.prototype.lastly = Promise.prototype["finally"] =
  1103. function Promise$finally(handler) {
  1104. if (typeof handler !== "function") return this.then();
  1105. var promiseAndHandler = {
  1106. promise: this,
  1107. handler: handler
  1108. };
  1109. return this._then(finallyHandler, finallyHandler, void 0,
  1110. promiseAndHandler, void 0, this.lastly);
  1111. };
  1112. };
  1113. },{"./util.js":39}],15:[function(require,module,exports){
  1114. /**
  1115. * Copyright (c) 2014 Petka Antonov
  1116. *
  1117. * Permission is hereby granted, free of charge, to any person obtaining a copy
  1118. * of this software and associated documentation files (the "Software"), to deal
  1119. * in the Software without restriction, including without limitation the rights
  1120. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1121. * copies of the Software, and to permit persons to whom the Software is
  1122. * furnished to do so, subject to the following conditions:</p>
  1123. *
  1124. * The above copyright notice and this permission notice shall be included in
  1125. * all copies or substantial portions of the Software.
  1126. *
  1127. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1128. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1129. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1130. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1131. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1132. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  1133. * THE SOFTWARE.
  1134. *
  1135. */
  1136. "use strict";
  1137. module.exports = function(Promise, apiRejection, INTERNAL) {
  1138. var PromiseSpawn = require("./promise_spawn.js")(Promise, INTERNAL);
  1139. var errors = require("./errors.js");
  1140. var TypeError = errors.TypeError;
  1141. var deprecated = require("./util.js").deprecated;
  1142. Promise.coroutine = function Promise$Coroutine(generatorFunction) {
  1143. if (typeof generatorFunction !== "function") {
  1144. throw new TypeError("generatorFunction must be a function");
  1145. }
  1146. var PromiseSpawn$ = PromiseSpawn;
  1147. return function anonymous() {
  1148. var generator = generatorFunction.apply(this, arguments);
  1149. var spawn = new PromiseSpawn$(void 0, void 0, anonymous);
  1150. spawn._generator = generator;
  1151. spawn._next(void 0);
  1152. return spawn.promise();
  1153. };
  1154. };
  1155. Promise.coroutine.addYieldHandler = PromiseSpawn.addYieldHandler;
  1156. Promise.spawn = function Promise$Spawn(generatorFunction) {
  1157. deprecated("Promise.spawn is deprecated. Use Promise.coroutine instead.");
  1158. if (typeof generatorFunction !== "function") {
  1159. return apiRejection("generatorFunction must be a function");
  1160. }
  1161. var spawn = new PromiseSpawn(generatorFunction, this, Promise.spawn);
  1162. var ret = spawn.promise();
  1163. spawn._run(Promise.spawn);
  1164. return ret;
  1165. };
  1166. };
  1167. },{"./errors.js":10,"./promise_spawn.js":24,"./util.js":39}],16:[function(require,module,exports){
  1168. /**
  1169. * Copyright (c) 2014 Petka Antonov
  1170. *
  1171. * Permission is hereby granted, free of charge, to any person obtaining a copy
  1172. * of this software and associated documentation files (the "Software"), to deal
  1173. * in the Software without restriction, including without limitation the rights
  1174. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1175. * copies of the Software, and to permit persons to whom the Software is
  1176. * furnished to do so, subject to the following conditions:</p>
  1177. *
  1178. * The above copyright notice and this permission notice shall be included in
  1179. * all copies or substantial portions of the Software.
  1180. *
  1181. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1182. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1183. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1184. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1185. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1186. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  1187. * THE SOFTWARE.
  1188. *
  1189. */
  1190. "use strict";
  1191. module.exports = (function(){
  1192. if (typeof this !== "undefined") {
  1193. return this;
  1194. }
  1195. if (typeof process !== "undefined" &&
  1196. typeof global !== "undefined" &&
  1197. typeof process.execPath === "string") {
  1198. return global;
  1199. }
  1200. if (typeof window !== "undefined" &&
  1201. typeof document !== "undefined" &&
  1202. typeof navigator !== "undefined" && navigator !== null &&
  1203. typeof navigator.appName === "string") {
  1204. if(window.wrappedJSObject !== undefined){
  1205. return window.wrappedJSObject;
  1206. }
  1207. return window;
  1208. }
  1209. })();
  1210. },{}],17:[function(require,module,exports){
  1211. /**
  1212. * Copyright (c) 2014 Petka Antonov
  1213. *
  1214. * Permission is hereby granted, free of charge, to any person obtaining a copy
  1215. * of this software and associated documentation files (the "Software"), to deal
  1216. * in the Software without restriction, including without limitation the rights
  1217. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1218. * copies of the Software, and to permit persons to whom the Software is
  1219. * furnished to do so, subject to the following conditions:</p>
  1220. *
  1221. * The above copyright notice and this permission notice shall be included in
  1222. * all copies or substantial portions of the Software.
  1223. *
  1224. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1225. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1226. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1227. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1228. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1229. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  1230. * THE SOFTWARE.
  1231. *
  1232. */
  1233. "use strict";
  1234. module.exports = function(
  1235. Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection) {
  1236. var ASSERT = require("./assert.js");
  1237. function Promise$_mapper(values) {
  1238. var fn = this;
  1239. var receiver = void 0;
  1240. if (typeof fn !== "function") {
  1241. receiver = fn.receiver;
  1242. fn = fn.fn;
  1243. }
  1244. var shouldDefer = false;
  1245. var ret = new Array(values.length);
  1246. if (receiver === void 0) {
  1247. for (var i = 0, len = values.length; i < len; ++i) {
  1248. var value = fn(values[i], i, len);
  1249. if (!shouldDefer) {
  1250. var maybePromise = Promise._cast(value,
  1251. Promise$_mapper, void 0);
  1252. if (maybePromise instanceof Promise) {
  1253. if (maybePromise.isFulfilled()) {
  1254. ret[i] = maybePromise._settledValue;
  1255. continue;
  1256. }
  1257. else {
  1258. shouldDefer = true;
  1259. }
  1260. value = maybePromise;
  1261. }
  1262. }
  1263. ret[i] = value;
  1264. }
  1265. }
  1266. else {
  1267. for (var i = 0, len = values.length; i < len; ++i) {
  1268. var value = fn.call(receiver, values[i], i, len);
  1269. if (!shouldDefer) {
  1270. var maybePromise = Promise._cast(value,
  1271. Promise$_mapper, void 0);
  1272. if (maybePromise instanceof Promise) {
  1273. if (maybePromise.isFulfilled()) {
  1274. ret[i] = maybePromise._settledValue;
  1275. continue;
  1276. }
  1277. else {
  1278. shouldDefer = true;
  1279. }
  1280. value = maybePromise;
  1281. }
  1282. }
  1283. ret[i] = value;
  1284. }
  1285. }
  1286. return shouldDefer
  1287. ? Promise$_CreatePromiseArray(ret, PromiseArray,
  1288. Promise$_mapper, void 0).promise()
  1289. : ret;
  1290. }
  1291. function Promise$_Map(promises, fn, useBound, caller, ref) {
  1292. if (typeof fn !== "function") {
  1293. return apiRejection("fn must be a function");
  1294. }
  1295. if (useBound === true && promises._isBound()) {
  1296. fn = {
  1297. fn: fn,
  1298. receiver: promises._boundTo
  1299. };
  1300. }
  1301. var ret = Promise$_CreatePromiseArray(
  1302. promises,
  1303. PromiseArray,
  1304. caller,
  1305. useBound === true && promises._isBound()
  1306. ? promises._boundTo
  1307. : void 0
  1308. ).promise();
  1309. if (ref !== void 0) {
  1310. ref.ref = ret;
  1311. }
  1312. return ret._then(
  1313. Promise$_mapper,
  1314. void 0,
  1315. void 0,
  1316. fn,
  1317. void 0,
  1318. caller
  1319. );
  1320. }
  1321. Promise.prototype.map = function Promise$map(fn, ref) {
  1322. return Promise$_Map(this, fn, true, this.map, ref);
  1323. };
  1324. Promise.map = function Promise$Map(promises, fn, ref) {
  1325. return Promise$_Map(promises, fn, false, Promise.map, ref);
  1326. };
  1327. };
  1328. },{"./assert.js":2}],18:[function(require,module,exports){
  1329. /**
  1330. * Copyright (c) 2014 Petka Antonov
  1331. *
  1332. * Permission is hereby granted, free of charge, to any person obtaining a copy
  1333. * of this software and associated documentation files (the "Software"), to deal
  1334. * in the Software without restriction, including without limitation the rights
  1335. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1336. * copies of the Software, and to permit persons to whom the Software is
  1337. * furnished to do so, subject to the following conditions:</p>
  1338. *
  1339. * The above copyright notice and this permission notice shall be included in
  1340. * all copies or substantial portions of the Software.
  1341. *
  1342. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1343. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1344. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1345. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1346. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1347. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  1348. * THE SOFTWARE.
  1349. *
  1350. */
  1351. "use strict";
  1352. module.exports = function(Promise) {
  1353. var util = require("./util.js");
  1354. var async = require("./async.js");
  1355. var ASSERT = require("./assert.js");
  1356. var tryCatch2 = util.tryCatch2;
  1357. var tryCatch1 = util.tryCatch1;
  1358. var errorObj = util.errorObj;
  1359. function thrower(r) {
  1360. throw r;
  1361. }
  1362. function Promise$_successAdapter(val, receiver) {
  1363. var nodeback = this;
  1364. var ret = tryCatch2(nodeback, receiver, null, val);
  1365. if (ret === errorObj) {
  1366. async.invokeLater(thrower, void 0, ret.e);
  1367. }
  1368. }
  1369. function Promise$_errorAdapter(reason, receiver) {
  1370. var nodeback = this;
  1371. var ret = tryCatch1(nodeback, receiver, reason);
  1372. if (ret === errorObj) {
  1373. async.invokeLater(thrower, void 0, ret.e);
  1374. }
  1375. }
  1376. Promise.prototype.nodeify = function Promise$nodeify(nodeback) {
  1377. if (typeof nodeback == "function") {
  1378. this._then(
  1379. Promise$_successAdapter,
  1380. Promise$_errorAdapter,
  1381. void 0,
  1382. nodeback,
  1383. this._isBound() ? this._boundTo : null,
  1384. this.nodeify
  1385. );
  1386. }
  1387. return this;
  1388. };
  1389. };
  1390. },{"./assert.js":2,"./async.js":3,"./util.js":39}],19:[function(require,module,exports){
  1391. /**
  1392. * Copyright (c) 2014 Petka Antonov
  1393. *
  1394. * Permission is hereby granted, free of charge, to any person obtaining a copy
  1395. * of this software and associated documentation files (the "Software"), to deal
  1396. * in the Software without restriction, including without limitation the rights
  1397. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1398. * copies of the Software, and to permit persons to whom the Software is
  1399. * furnished to do so, subject to the following conditions:</p>
  1400. *
  1401. * The above copyright notice and this permission notice shall be included in
  1402. * all copies or substantial portions of the Software.
  1403. *
  1404. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1405. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1406. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1407. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1408. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1409. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  1410. * THE SOFTWARE.
  1411. *
  1412. */
  1413. "use strict";
  1414. module.exports = function(Promise, isPromiseArrayProxy) {
  1415. var ASSERT = require("./assert.js");
  1416. var util = require("./util.js");
  1417. var async = require("./async.js");
  1418. var errors = require("./errors.js");
  1419. var tryCatch1 = util.tryCatch1;
  1420. var errorObj = util.errorObj;
  1421. Promise.prototype.progressed = function Promise$progressed(handler) {
  1422. return this._then(void 0, void 0, handler,
  1423. void 0, void 0, this.progressed);
  1424. };
  1425. Promise.prototype._progress = function Promise$_progress(progressValue) {
  1426. if (this._isFollowingOrFulfilledOrRejected()) return;
  1427. this._progressUnchecked(progressValue);
  1428. };
  1429. Promise.prototype._progressHandlerAt =
  1430. function Promise$_progressHandlerAt(index) {
  1431. if (index === 0) return this._progressHandler0;
  1432. return this[index + 2 - 5];
  1433. };
  1434. Promise.prototype._doProgressWith =
  1435. function Promise$_doProgressWith(progression) {
  1436. var progressValue = progression.value;
  1437. var handler = progression.handler;
  1438. var promise = progression.promise;
  1439. var receiver = progression.receiver;
  1440. this._pushContext();
  1441. var ret = tryCatch1(handler, receiver, progressValue);
  1442. this._popContext();
  1443. if (ret === errorObj) {
  1444. if (ret.e != null &&
  1445. ret.e.name !== "StopProgressPropagation") {
  1446. var trace = errors.canAttach(ret.e)
  1447. ? ret.e : new Error(ret.e + "");
  1448. promise._attachExtraTrace(trace);
  1449. promise._progress(ret.e);
  1450. }
  1451. }
  1452. else if (Promise.is(ret)) {
  1453. ret._then(promise._progress, null, null, promise, void 0,
  1454. this._progress);
  1455. }
  1456. else {
  1457. promise._progress(ret);
  1458. }
  1459. };
  1460. Promise.prototype._progressUnchecked =
  1461. function Promise$_progressUnchecked(progressValue) {
  1462. if (!this.isPending()) return;
  1463. var len = this._length();
  1464. for (var i = 0; i < len; i += 5) {
  1465. var handler = this._progressHandlerAt(i);
  1466. var promise = this._promiseAt(i);
  1467. if (!Promise.is(promise)) {
  1468. var receiver = this._receiverAt(i);
  1469. if (typeof handler === "function") {
  1470. handler.call(receiver, progressValue, promise);
  1471. }
  1472. else if (Promise.is(receiver) && receiver._isProxied()) {
  1473. receiver._progressUnchecked(progressValue);
  1474. }
  1475. else if (isPromiseArrayProxy(receiver, promise)) {
  1476. receiver._promiseProgressed(progressValue, promise);
  1477. }
  1478. continue;
  1479. }
  1480. if (typeof handler === "function") {
  1481. async.invoke(this._doProgressWith, this, {
  1482. handler: handler,
  1483. promise: promise,
  1484. receiver: this._receiverAt(i),
  1485. value: progressValue
  1486. });
  1487. }
  1488. else {
  1489. async.invoke(promise._progress, promise, progressValue);
  1490. }
  1491. }
  1492. };
  1493. };
  1494. },{"./assert.js":2,"./async.js":3,"./errors.js":10,"./util.js":39}],20:[function(require,module,exports){
  1495. /**
  1496. * Copyright (c) 2014 Petka Antonov
  1497. *
  1498. * Permission is hereby granted, free of charge, to any person obtaining a copy
  1499. * of this software and associated documentation files (the "Software"), to deal
  1500. * in the Software without restriction, including without limitation the rights
  1501. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1502. * copies of the Software, and to permit persons to whom the Software is
  1503. * furnished to do so, subject to the following conditions:</p>
  1504. *
  1505. * The above copyright notice and this permission notice shall be included in
  1506. * all copies or substantial portions of the Software.
  1507. *
  1508. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1509. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1510. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1511. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1512. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1513. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  1514. * THE SOFTWARE.
  1515. *
  1516. */
  1517. "use strict";
  1518. module.exports = function() {
  1519. var global = require("./global.js");
  1520. var ASSERT = require("./assert.js");
  1521. var util = require("./util.js");
  1522. var async = require("./async.js");
  1523. var errors = require("./errors.js");
  1524. var INTERNAL = function(){};
  1525. var APPLY = {};
  1526. var NEXT_FILTER = {e: null};
  1527. var PromiseArray = require("./promise_array.js")(Promise, INTERNAL);
  1528. var CapturedTrace = require("./captured_trace.js")();
  1529. var CatchFilter = require("./catch_filter.js")(NEXT_FILTER);
  1530. var PromiseResolver = require("./promise_resolver.js");
  1531. var isArray = util.isArray;
  1532. var errorObj = util.errorObj;
  1533. var tryCatch1 = util.tryCatch1;
  1534. var tryCatch2 = util.tryCatch2;
  1535. var tryCatchApply = util.tryCatchApply;
  1536. var RangeError = errors.RangeError;
  1537. var TypeError = errors.TypeError;
  1538. var CancellationError = errors.CancellationError;
  1539. var TimeoutError = errors.TimeoutError;
  1540. var RejectionError = errors.RejectionError;
  1541. var originatesFromRejection = errors.originatesFromRejection;
  1542. var markAsOriginatingFromRejection = errors.markAsOriginatingFromRejection;
  1543. var canAttach = errors.canAttach;
  1544. var thrower = util.thrower;
  1545. var apiRejection = require("./errors_api_rejection")(Promise);
  1546. var makeSelfResolutionError = function Promise$_makeSelfResolutionError() {
  1547. return new TypeError("circular promise resolution chain");
  1548. };
  1549. function isPromise(obj) {
  1550. if (obj === void 0) return false;
  1551. return obj instanceof Promise;
  1552. }
  1553. function isPromiseArrayProxy(receiver, promiseSlotValue) {
  1554. if (receiver instanceof PromiseArray) {
  1555. return promiseSlotValue >= 0;
  1556. }
  1557. return false;
  1558. }
  1559. function Promise(resolver) {
  1560. if (typeof resolver !== "function") {
  1561. throw new TypeError("the promise constructor requires a resolver function");
  1562. }
  1563. if (this.constructor !== Promise) {
  1564. throw new TypeError("the promise constructor cannot be invoked directly");
  1565. }
  1566. this._bitField = 0;
  1567. this._fulfillmentHandler0 = void 0;
  1568. this._rejectionHandler0 = void 0;
  1569. this._promise0 = void 0;
  1570. this._receiver0 = void 0;
  1571. this._settledValue = void 0;
  1572. this._boundTo = void 0;
  1573. if (resolver !== INTERNAL) this._resolveFromResolver(resolver);
  1574. }
  1575. Promise.prototype.bind = function Promise$bind(thisArg) {
  1576. var ret = new Promise(INTERNAL);
  1577. if (debugging) ret._setTrace(this.bind, this);
  1578. ret._follow(this);
  1579. ret._setBoundTo(thisArg);
  1580. if (this._cancellable()) {
  1581. ret._setCancellable();
  1582. ret._cancellationParent = this;
  1583. }
  1584. return ret;
  1585. };
  1586. Promise.prototype.toString = function Promise$toString() {
  1587. return "[object Promise]";
  1588. };
  1589. Promise.prototype.caught = Promise.prototype["catch"] =
  1590. function Promise$catch(fn) {
  1591. var len = arguments.length;
  1592. if (len > 1) {
  1593. var catchInstances = new Array(len - 1),
  1594. j = 0, i;
  1595. for (i = 0; i < len - 1; ++i) {
  1596. var item = arguments[i];
  1597. if (typeof item === "function") {
  1598. catchInstances[j++] = item;
  1599. }
  1600. else {
  1601. var catchFilterTypeError =
  1602. new TypeError(
  1603. "A catch filter must be an error constructor "
  1604. + "or a filter function");
  1605. this._attachExtraTrace(catchFilterTypeError);
  1606. async.invoke(this._reject, this, catchFilterTypeError);
  1607. return;
  1608. }
  1609. }
  1610. catchInstances.length = j;
  1611. fn = arguments[i];
  1612. this._resetTrace(this.caught);
  1613. var catchFilter = new CatchFilter(catchInstances, fn, this);
  1614. return this._then(void 0, catchFilter.doFilter, void 0,
  1615. catchFilter, void 0, this.caught);
  1616. }
  1617. return this._then(void 0, fn, void 0, void 0, void 0, this.caught);
  1618. };
  1619. Promise.prototype.then =
  1620. function Promise$then(didFulfill, didReject, didProgress) {
  1621. return this._then(didFulfill, didReject, didProgress,
  1622. void 0, void 0, this.then);
  1623. };
  1624. Promise.prototype.done =
  1625. function Promise$done(didFulfill, didReject, didProgress) {
  1626. var promise = this._then(didFulfill, didReject, didProgress,
  1627. void 0, void 0, this.done);
  1628. promise._setIsFinal();
  1629. };
  1630. Promise.prototype.spread = function Promise$spread(didFulfill, didReject) {
  1631. return this._then(didFulfill, didReject, void 0,
  1632. APPLY, void 0, this.spread);
  1633. };
  1634. Promise.prototype.isFulfilled = function Promise$isFulfilled() {
  1635. return (this._bitField & 268435456) > 0;
  1636. };
  1637. Promise.prototype.isRejected = function Promise$isRejected() {
  1638. return (this._bitField & 134217728) > 0;
  1639. };
  1640. Promise.prototype.isPending = function Promise$isPending() {
  1641. return !this.isResolved();
  1642. };
  1643. Promise.prototype.isResolved = function Promise$isResolved() {
  1644. return (this._bitField & 402653184) > 0;
  1645. };
  1646. Promise.prototype.isCancellable = function Promise$isCancellable() {
  1647. return !this.isResolved() &&
  1648. this._cancellable();
  1649. };
  1650. Promise.prototype.toJSON = function Promise$toJSON() {
  1651. var ret = {
  1652. isFulfilled: false,
  1653. isRejected: false,
  1654. fulfillmentValue: void 0,
  1655. rejectionReason: void 0
  1656. };
  1657. if (this.isFulfilled()) {
  1658. ret.fulfillmentValue = this._settledValue;
  1659. ret.isFulfilled = true;
  1660. }
  1661. else if (this.isRejected()) {
  1662. ret.rejectionReason = this._settledValue;
  1663. ret.isRejected = true;
  1664. }
  1665. return ret;
  1666. };
  1667. Promise.prototype.all = function Promise$all() {
  1668. return Promise$_all(this, true, this.all);
  1669. };
  1670. Promise.is = isPromise;
  1671. function Promise$_all(promises, useBound, caller) {
  1672. return Promise$_CreatePromiseArray(
  1673. promises,
  1674. PromiseArray,
  1675. caller,
  1676. useBound === true && promises._isBound()
  1677. ? promises._boundTo
  1678. : void 0
  1679. ).promise();
  1680. }
  1681. Promise.all = function Promise$All(promises) {
  1682. return Promise$_all(promises, false, Promise.all);
  1683. };
  1684. Promise.join = function Promise$Join() {
  1685. var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
  1686. return Promise$_CreatePromiseArray(
  1687. args, PromiseArray, Promise.join, void 0).promise();
  1688. };
  1689. Promise.resolve = Promise.fulfilled =
  1690. function Promise$Resolve(value, caller) {
  1691. var ret = new Promise(INTERNAL);
  1692. if (debugging) ret._setTrace(typeof caller === "function"
  1693. ? caller
  1694. : Promise.resolve, void 0);
  1695. if (ret._tryFollow(value)) {
  1696. return ret;
  1697. }
  1698. ret._cleanValues();
  1699. ret._setFulfilled();
  1700. ret._settledValue = value;
  1701. return ret;
  1702. };
  1703. Promise.reject = Promise.rejected = function Promise$Reject(reason) {
  1704. var ret = new Promise(INTERNAL);
  1705. if (debugging) ret._setTrace(Promise.reject, void 0);
  1706. markAsOriginatingFromRejection(reason);
  1707. ret._cleanValues();
  1708. ret._setRejected();
  1709. ret._settledValue = reason;
  1710. if (!canAttach(reason)) {
  1711. var trace = new Error(reason + "");
  1712. ret._setCarriedStackTrace(trace);
  1713. }
  1714. ret._ensurePossibleRejectionHandled();
  1715. return ret;
  1716. };
  1717. Promise.prototype.error = function Promise$_error(fn) {
  1718. return this.caught(originatesFromRejection, fn);
  1719. };
  1720. Promise.prototype._resolveFromSyncValue =
  1721. function Promise$_resolveFromSyncValue(value, caller) {
  1722. if (value === errorObj) {
  1723. this._cleanValues();
  1724. this._setRejected();
  1725. this._settledValue = value.e;
  1726. this._ensurePossibleRejectionHandled();
  1727. }
  1728. else {
  1729. var maybePromise = Promise._cast(value, caller, void 0);
  1730. if (maybePromise instanceof Promise) {
  1731. this._follow(maybePromise);
  1732. }
  1733. else {
  1734. this._cleanValues();
  1735. this._setFulfilled();
  1736. this._settledValue = value;
  1737. }
  1738. }
  1739. };
  1740. Promise.method = function Promise$_Method(fn) {
  1741. if (typeof fn !== "function") {
  1742. throw new TypeError("fn must be a function");
  1743. }
  1744. return function Promise$_method() {
  1745. var value;
  1746. switch(arguments.length) {
  1747. case 0: value = tryCatch1(fn, this, void 0); break;
  1748. case 1: value = tryCatch1(fn, this, arguments[0]); break;
  1749. case 2: value = tryCatch2(fn, this, arguments[0], arguments[1]); break;
  1750. default:
  1751. var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
  1752. value = tryCatchApply(fn, args, this); break;
  1753. }
  1754. var ret = new Promise(INTERNAL);
  1755. if (debugging) ret._setTrace(Promise$_method, void 0);
  1756. ret._resolveFromSyncValue(value, Promise$_method);
  1757. return ret;
  1758. };
  1759. };
  1760. Promise.attempt = Promise["try"] = function Promise$_Try(fn, args, ctx) {
  1761. if (typeof fn !== "function") {
  1762. return apiRejection("fn must be a function");
  1763. }
  1764. var value = isArray(args)
  1765. ? tryCatchApply(fn, args, ctx)
  1766. : tryCatch1(fn, ctx, args);
  1767. var ret = new Promise(INTERNAL);
  1768. if (debugging) ret._setTrace(Promise.attempt, void 0);
  1769. ret._resolveFromSyncValue(value, Promise.attempt);
  1770. return ret;
  1771. };
  1772. Promise.defer = Promise.pending = function Promise$Defer(caller) {
  1773. var promise = new Promise(INTERNAL);
  1774. if (debugging) promise._setTrace(typeof caller === "function"
  1775. ? caller : Promise.defer, void 0);
  1776. return new PromiseResolver(promise);
  1777. };
  1778. Promise.bind = function Promise$Bind(thisArg) {
  1779. var ret = new Promise(INTERNAL);
  1780. if (debugging) ret._setTrace(Promise.bind, void 0);
  1781. ret._setFulfilled();
  1782. ret._setBoundTo(thisArg);
  1783. return ret;
  1784. };
  1785. Promise.cast = function Promise$_Cast(obj, caller) {
  1786. if (typeof caller !== "function") {
  1787. caller = Promise.cast;
  1788. }
  1789. var ret = Promise._cast(obj, caller, void 0);
  1790. if (!(ret instanceof Promise)) {
  1791. return Promise.resolve(ret, caller);
  1792. }
  1793. return ret;
  1794. };
  1795. Promise.onPossiblyUnhandledRejection =
  1796. function Promise$OnPossiblyUnhandledRejection(fn) {
  1797. if (typeof fn === "function") {
  1798. CapturedTrace.possiblyUnhandledRejection = fn;
  1799. }
  1800. else {
  1801. CapturedTrace.possiblyUnhandledRejection = void 0;
  1802. }
  1803. };
  1804. var debugging = false || !!(
  1805. typeof process !== "undefined" &&
  1806. typeof process.execPath === "string" &&
  1807. typeof process.env === "object" &&
  1808. (process.env["BLUEBIRD_DEBUG"] ||
  1809. process.env["NODE_ENV"] === "development")
  1810. );
  1811. Promise.longStackTraces = function Promise$LongStackTraces() {
  1812. if (async.haveItemsQueued() &&
  1813. debugging === false
  1814. ) {
  1815. throw new Error("cannot enable long stack traces after promises have been created");
  1816. }
  1817. debugging = CapturedTrace.isSupported();
  1818. };
  1819. Promise.hasLongStackTraces = function Promise$HasLongStackTraces() {
  1820. return debugging && CapturedTrace.isSupported();
  1821. };
  1822. Promise.prototype._setProxyHandlers =
  1823. function Promise$_setProxyHandlers(receiver, promiseSlotValue) {
  1824. var index = this._length();
  1825. if (index >= 1048575 - 5) {
  1826. index = 0;
  1827. this._setLength(0);
  1828. }
  1829. if (index === 0) {
  1830. this._promise0 = promiseSlotValue;
  1831. this._receiver0 = receiver;
  1832. }
  1833. else {
  1834. var i = index - 5;
  1835. this[i + 3] = promiseSlotValue;
  1836. this[i + 4] = receiver;
  1837. this[i + 0] =
  1838. this[i + 1] =
  1839. this[i + 2] = void 0;
  1840. }
  1841. this._setLength(index + 5);
  1842. };
  1843. Promise.prototype._proxyPromiseArray =
  1844. function Promise$_proxyPromiseArray(promiseArray, index) {
  1845. this._setProxyHandlers(promiseArray, index);
  1846. };
  1847. Promise.prototype._proxyPromise = function Promise$_proxyPromise(promise) {
  1848. promise._setProxied();
  1849. this._setProxyHandlers(promise, -1);
  1850. };
  1851. Promise.prototype._then =
  1852. function Promise$_then(
  1853. didFulfill,
  1854. didReject,
  1855. didProgress,
  1856. receiver,
  1857. internalData,
  1858. caller
  1859. ) {
  1860. var haveInternalData = internalData !== void 0;
  1861. var ret = haveInternalData ? internalData : new Promise(INTERNAL);
  1862. if (debugging && !haveInternalData) {
  1863. var haveSameContext = this._peekContext() === this._traceParent;
  1864. ret._traceParent = haveSameContext ? this._traceParent : this;
  1865. ret._setTrace(typeof caller === "function"
  1866. ? caller
  1867. : this._then, this);
  1868. }
  1869. if (!haveInternalData && this._isBound()) {
  1870. ret._setBoundTo(this._boundTo);
  1871. }
  1872. var callbackIndex =
  1873. this._addCallbacks(didFulfill, didReject, didProgress, ret, receiver);
  1874. if (!haveInternalData && this._cancellable()) {
  1875. ret._setCancellable();
  1876. ret._cancellationParent = this;
  1877. }
  1878. if (this.isResolved()) {
  1879. async.invoke(this._queueSettleAt, this, callbackIndex);
  1880. }
  1881. return ret;
  1882. };
  1883. Promise.prototype._length = function Promise$_length() {
  1884. return this._bitField & 1048575;
  1885. };
  1886. Promise.prototype._isFollowingOrFulfilledOrRejected =
  1887. function Promise$_isFollowingOrFulfilledOrRejected() {
  1888. return (this._bitField & 939524096) > 0;
  1889. };
  1890. Promise.prototype._isFollowing = function Promise$_isFollowing() {
  1891. return (this._bitField & 536870912) === 536870912;
  1892. };
  1893. Promise.prototype._setLength = function Promise$_setLength(len) {
  1894. this._bitField = (this._bitField & -1048576) |
  1895. (len & 1048575);
  1896. };
  1897. Promise.prototype._setFulfilled = function Promise$_setFulfilled() {
  1898. this._bitField = this._bitField | 268435456;
  1899. };
  1900. Promise.prototype._setRejected = function Promise$_setRejected() {
  1901. this._bitField = this._bitField | 134217728;
  1902. };
  1903. Promise.prototype._setFollowing = function Promise$_setFollowing() {
  1904. this._bitField = this._bitField | 536870912;
  1905. };
  1906. Promise.prototype._setIsFinal = function Promise$_setIsFinal() {
  1907. this._bitField = this._bitField | 33554432;
  1908. };
  1909. Promise.prototype._isFinal = function Promise$_isFinal() {
  1910. return (this._bitField & 33554432) > 0;
  1911. };
  1912. Promise.prototype._cancellable = function Promise$_cancellable() {
  1913. return (this._bitField & 67108864) > 0;
  1914. };
  1915. Promise.prototype._setCancellable = function Promise$_setCancellable() {
  1916. this._bitField = this._bitField | 67108864;
  1917. };
  1918. Promise.prototype._unsetCancellable = function Promise$_unsetCancellable() {
  1919. this._bitField = this._bitField & (~67108864);
  1920. };
  1921. Promise.prototype._setRejectionIsUnhandled =
  1922. function Promise$_setRejectionIsUnhandled() {
  1923. this._bitField = this._bitField | 2097152;
  1924. };
  1925. Promise.prototype._unsetRejectionIsUnhandled =
  1926. function Promise$_unsetRejectionIsUnhandled() {
  1927. this._bitField = this._bitField & (~2097152);
  1928. };
  1929. Promise.prototype._isRejectionUnhandled =
  1930. function Promise$_isRejectionUnhandled() {
  1931. return (this._bitField & 2097152) > 0;
  1932. };
  1933. Promise.prototype._setCarriedStackTrace =
  1934. function Promise$_setCarriedStackTrace(capturedTrace) {
  1935. this._bitField = this._bitField | 1048576;
  1936. this._fulfillmentHandler0 = capturedTrace;
  1937. };
  1938. Promise.prototype._unsetCarriedStackTrace =
  1939. function Promise$_unsetCarriedStackTrace() {
  1940. this._bitField = this._bitField & (~1048576);
  1941. this._fulfillmentHandler0 = void 0;
  1942. };
  1943. Promise.prototype._isCarryingStackTrace =
  1944. function Promise$_isCarryingStackTrace() {
  1945. return (this._bitField & 1048576) > 0;
  1946. };
  1947. Promise.prototype._getCarriedStackTrace =
  1948. function Promise$_getCarriedStackTrace() {
  1949. return this._isCarryingStackTrace()
  1950. ? this._fulfillmentHandler0
  1951. : void 0;
  1952. };
  1953. Promise.prototype._receiverAt = function Promise$_receiverAt(index) {
  1954. var ret;
  1955. if (index === 0) {
  1956. ret = this._receiver0;
  1957. }
  1958. else {
  1959. ret = this[index + 4 - 5];
  1960. }
  1961. if (this._isBound() && ret === void 0) {
  1962. return this._boundTo;
  1963. }
  1964. return ret;
  1965. };
  1966. Promise.prototype._promiseAt = function Promise$_promiseAt(index) {
  1967. if (index === 0) return this._promise0;
  1968. return this[index + 3 - 5];
  1969. };
  1970. Promise.prototype._fulfillmentHandlerAt =
  1971. function Promise$_fulfillmentHandlerAt(index) {
  1972. if (index === 0) return this._fulfillmentHandler0;
  1973. return this[index + 0 - 5];
  1974. };
  1975. Promise.prototype._rejectionHandlerAt =
  1976. function Promise$_rejectionHandlerAt(index) {
  1977. if (index === 0) return this._rejectionHandler0;
  1978. return this[index + 1 - 5];
  1979. };
  1980. Promise.prototype._unsetAt = function Promise$_unsetAt(index) {
  1981. if (index === 0) {
  1982. this._rejectionHandler0 =
  1983. this._progressHandler0 =
  1984. this._promise0 =
  1985. this._receiver0 = void 0;
  1986. if (!this._isCarryingStackTrace()) {
  1987. this._fulfillmentHandler0 = void 0;
  1988. }
  1989. }
  1990. else {
  1991. this[index - 5 + 0] =
  1992. this[index - 5 + 1] =
  1993. this[index - 5 + 2] =
  1994. this[index - 5 + 3] =
  1995. this[index - 5 + 4] = void 0;
  1996. }
  1997. };
  1998. Promise.prototype._resolveFromResolver =
  1999. function Promise$_resolveFromResolver(resolver) {
  2000. var promise = this;
  2001. var localDebugging = debugging;
  2002. if (localDebugging) {
  2003. this._setTrace(this._resolveFromResolver, void 0);
  2004. this._pushContext();
  2005. }
  2006. function Promise$_resolver(val) {
  2007. if (promise._tryFollow(val)) {
  2008. return;
  2009. }
  2010. promise._fulfill(val);
  2011. }
  2012. function Promise$_rejecter(val) {
  2013. var trace = canAttach(val) ? val : new Error(val + "");
  2014. promise._attachExtraTrace(trace);
  2015. markAsOriginatingFromRejection(val);
  2016. promise._reject(val, trace === val ? void 0 : trace);
  2017. }
  2018. var r = tryCatch2(resolver, void 0, Promise$_resolver, Promise$_rejecter);
  2019. if (localDebugging) this._popContext();
  2020. if (r !== void 0 && r === errorObj) {
  2021. var trace = canAttach(r.e) ? r.e : new Error(r.e + "");
  2022. promise._reject(r.e, trace);
  2023. }
  2024. };
  2025. Promise.prototype._addCallbacks = function Promise$_addCallbacks(
  2026. fulfill,
  2027. reject,
  2028. progress,
  2029. promise,
  2030. receiver
  2031. ) {
  2032. var index = this._length();
  2033. if (index >= 1048575 - 5) {
  2034. index = 0;
  2035. this._setLength(0);
  2036. }
  2037. if (index === 0) {
  2038. this._promise0 = promise;
  2039. if (receiver !== void 0) this._receiver0 = receiver;
  2040. if (typeof fulfill === "function" && !this._isCarryingStackTrace())
  2041. this._fulfillmentHandler0 = fulfill;
  2042. if (typeof reject === "function") this._rejectionHandler0 = reject;
  2043. if (typeof progress === "function") this._progressHandler0 = progress;
  2044. }
  2045. else {
  2046. var i = index - 5;
  2047. this[i + 3] = promise;
  2048. this[i + 4] = receiver;
  2049. this[i + 0] = typeof fulfill === "function"
  2050. ? fulfill : void 0;
  2051. this[i + 1] = typeof reject === "function"
  2052. ? reject : void 0;
  2053. this[i + 2] = typeof progress === "function"
  2054. ? progress : void 0;
  2055. }
  2056. this._setLength(index + 5);
  2057. return index;
  2058. };
  2059. Promise.prototype._setBoundTo = function Promise$_setBoundTo(obj) {
  2060. if (obj !== void 0) {
  2061. this._bitField = this._bitField | 8388608;
  2062. this._boundTo = obj;
  2063. }
  2064. else {
  2065. this._bitField = this._bitField & (~8388608);
  2066. }
  2067. };
  2068. Promise.prototype._isBound = function Promise$_isBound() {
  2069. return (this._bitField & 8388608) === 8388608;
  2070. };
  2071. Promise.prototype._spreadSlowCase =
  2072. function Promise$_spreadSlowCase(targetFn, promise, values, boundTo) {
  2073. var promiseForAll =
  2074. Promise$_CreatePromiseArray
  2075. (values, PromiseArray, this._spreadSlowCase, boundTo)
  2076. .promise()
  2077. ._then(function() {
  2078. return targetFn.apply(boundTo, arguments);
  2079. }, void 0, void 0, APPLY, void 0, this._spreadSlowCase);
  2080. promise._follow(promiseForAll);
  2081. };
  2082. Promise.prototype._callSpread =
  2083. function Promise$_callSpread(handler, promise, value, localDebugging) {
  2084. var boundTo = this._isBound() ? this._boundTo : void 0;
  2085. if (isArray(value)) {
  2086. var caller = this._settlePromiseFromHandler;
  2087. for (var i = 0, len = value.length; i < len; ++i) {
  2088. if (isPromise(Promise._cast(value[i], caller, void 0))) {
  2089. this._spreadSlowCase(handler, promise, value, boundTo);
  2090. return;
  2091. }
  2092. }
  2093. }
  2094. if (localDebugging) promise._pushContext();
  2095. return tryCatchApply(handler, value, boundTo);
  2096. };
  2097. Promise.prototype._callHandler =
  2098. function Promise$_callHandler(
  2099. handler, receiver, promise, value, localDebugging) {
  2100. var x;
  2101. if (receiver === APPLY && !this.isRejected()) {
  2102. x = this._callSpread(handler, promise, value, localDebugging);
  2103. }
  2104. else {
  2105. if (localDebugging) promise._pushContext();
  2106. x = tryCatch1(handler, receiver, value);
  2107. }
  2108. if (localDebugging) promise._popContext();
  2109. return x;
  2110. };
  2111. Promise.prototype._settlePromiseFromHandler =
  2112. function Promise$_settlePromiseFromHandler(
  2113. handler, receiver, value, promise
  2114. ) {
  2115. if (!isPromise(promise)) {
  2116. handler.call(receiver, value, promise);
  2117. return;
  2118. }
  2119. var localDebugging = debugging;
  2120. var x = this._callHandler(handler, receiver,
  2121. promise, value, localDebugging);
  2122. if (promise._isFollowing()) return;
  2123. if (x === errorObj || x === promise || x === NEXT_FILTER) {
  2124. var err = x === promise
  2125. ? makeSelfResolutionError()
  2126. : x.e;
  2127. var trace = canAttach(err) ? err : new Error(err + "");
  2128. if (x !== NEXT_FILTER) promise._attachExtraTrace(trace);
  2129. promise._rejectUnchecked(err, trace);
  2130. }
  2131. else {
  2132. var castValue = Promise._cast(x,
  2133. localDebugging ? this._settlePromiseFromHandler : void 0,
  2134. promise);
  2135. if (isPromise(castValue)) {
  2136. if (castValue.isRejected() &&
  2137. !castValue._isCarryingStackTrace() &&
  2138. !canAttach(castValue._settledValue)) {
  2139. var trace = new Error(castValue._settledValue + "");
  2140. promise._attachExtraTrace(trace);
  2141. castValue._setCarriedStackTrace(trace);
  2142. }
  2143. promise._follow(castValue);
  2144. if (castValue._cancellable()) {
  2145. promise._cancellationParent = castValue;
  2146. promise._setCancellable();
  2147. }
  2148. }
  2149. else {
  2150. promise._fulfillUnchecked(x);
  2151. }
  2152. }
  2153. };
  2154. Promise.prototype._follow =
  2155. function Promise$_follow(promise) {
  2156. this._setFollowing();
  2157. if (promise.isPending()) {
  2158. if (promise._cancellable() ) {
  2159. this._cancellationParent = promise;
  2160. this._setCancellable();
  2161. }
  2162. promise._proxyPromise(this);
  2163. }
  2164. else if (promise.isFulfilled()) {
  2165. this._fulfillUnchecked(promise._settledValue);
  2166. }
  2167. else {
  2168. this._rejectUnchecked(promise._settledValue,
  2169. promise._getCarriedStackTrace());
  2170. }
  2171. if (promise._isRejectionUnhandled()) promise._unsetRejectionIsUnhandled();
  2172. if (debugging &&
  2173. promise._traceParent == null) {
  2174. promise._traceParent = this;
  2175. }
  2176. };
  2177. Promise.prototype._tryFollow =
  2178. function Promise$_tryFollow(value) {
  2179. if (this._isFollowingOrFulfilledOrRejected() ||
  2180. value === this) {
  2181. return false;
  2182. }
  2183. var maybePromise = Promise._cast(value, this._tryFollow, void 0);
  2184. if (!isPromise(maybePromise)) {
  2185. return false;
  2186. }
  2187. this._follow(maybePromise);
  2188. return true;
  2189. };
  2190. Promise.prototype._resetTrace = function Promise$_resetTrace(caller) {
  2191. if (debugging) {
  2192. var context = this._peekContext();
  2193. var isTopLevel = context === void 0;
  2194. this._trace = new CapturedTrace(
  2195. typeof caller === "function"
  2196. ? caller
  2197. : this._resetTrace,
  2198. isTopLevel
  2199. );
  2200. }
  2201. };
  2202. Promise.prototype._setTrace = function Promise$_setTrace(caller, parent) {
  2203. if (debugging) {
  2204. var context = this._peekContext();
  2205. this._traceParent = context;
  2206. var isTopLevel = context === void 0;
  2207. if (parent !== void 0 &&
  2208. parent._traceParent === context) {
  2209. this._trace = parent._trace;
  2210. }
  2211. else {
  2212. this._trace = new CapturedTrace(
  2213. typeof caller === "function"
  2214. ? caller
  2215. : this._setTrace,
  2216. isTopLevel
  2217. );
  2218. }
  2219. }
  2220. return this;
  2221. };
  2222. Promise.prototype._attachExtraTrace =
  2223. function Promise$_attachExtraTrace(error) {
  2224. if (debugging) {
  2225. var promise = this;
  2226. var stack = error.stack;
  2227. stack = typeof stack === "string"
  2228. ? stack.split("\n") : [];
  2229. var headerLineCount = 1;
  2230. while(promise != null &&
  2231. promise._trace != null) {
  2232. stack = CapturedTrace.combine(
  2233. stack,
  2234. promise._trace.stack.split("\n")
  2235. );
  2236. promise = promise._traceParent;
  2237. }
  2238. var max = Error.stackTraceLimit + headerLineCount;
  2239. var len = stack.length;
  2240. if (len > max) {
  2241. stack.length = max;
  2242. }
  2243. if (stack.length <= headerLineCount) {
  2244. error.stack = "(No stack trace)";
  2245. }
  2246. else {
  2247. error.stack = stack.join("\n");
  2248. }
  2249. }
  2250. };
  2251. Promise.prototype._cleanValues = function Promise$_cleanValues() {
  2252. if (this._cancellable()) {
  2253. this._cancellationParent = void 0;
  2254. }
  2255. };
  2256. Promise.prototype._fulfill = function Promise$_fulfill(value) {
  2257. if (this._isFollowingOrFulfilledOrRejected()) return;
  2258. this._fulfillUnchecked(value);
  2259. };
  2260. Promise.prototype._reject =
  2261. function Promise$_reject(reason, carriedStackTrace) {
  2262. if (this._isFollowingOrFulfilledOrRejected()) return;
  2263. this._rejectUnchecked(reason, carriedStackTrace);
  2264. };
  2265. Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) {
  2266. var handler = this.isFulfilled()
  2267. ? this._fulfillmentHandlerAt(index)
  2268. : this._rejectionHandlerAt(index);
  2269. var value = this._settledValue;
  2270. var receiver = this._receiverAt(index);
  2271. var promise = this._promiseAt(index);
  2272. if (typeof handler === "function") {
  2273. this._settlePromiseFromHandler(handler, receiver, value, promise);
  2274. }
  2275. else {
  2276. var done = false;
  2277. var isFulfilled = this.isFulfilled();
  2278. if (receiver !== void 0) {
  2279. if (receiver instanceof Promise &&
  2280. receiver._isProxied()) {
  2281. receiver._unsetProxied();
  2282. if (isFulfilled) receiver._fulfillUnchecked(value);
  2283. else receiver._rejectUnchecked(value,
  2284. this._getCarriedStackTrace());
  2285. done = true;
  2286. }
  2287. else if (isPromiseArrayProxy(receiver, promise)) {
  2288. if (isFulfilled) receiver._promiseFulfilled(value, promise);
  2289. else receiver._promiseRejected(value, promise);
  2290. done = true;
  2291. }
  2292. }
  2293. if (!done) {
  2294. if (isFulfilled) promise._fulfill(value);
  2295. else promise._reject(value, this._getCarriedStackTrace());
  2296. }
  2297. }
  2298. if (index >= 256) {
  2299. this._queueGC();
  2300. }
  2301. };
  2302. Promise.prototype._isProxied = function Promise$_isProxied() {
  2303. return (this._bitField & 4194304) === 4194304;
  2304. };
  2305. Promise.prototype._setProxied = function Promise$_setProxied() {
  2306. this._bitField = this._bitField | 4194304;
  2307. };
  2308. Promise.prototype._unsetProxied = function Promise$_unsetProxied() {
  2309. this._bitField = this._bitField & (~4194304);
  2310. };
  2311. Promise.prototype._isGcQueued = function Promise$_isGcQueued() {
  2312. return (this._bitField & -1073741824) === -1073741824;
  2313. };
  2314. Promise.prototype._setGcQueued = function Promise$_setGcQueued() {
  2315. this._bitField = this._bitField | -1073741824;
  2316. };
  2317. Promise.prototype._unsetGcQueued = function Promise$_unsetGcQueued() {
  2318. this._bitField = this._bitField & (~-1073741824);
  2319. };
  2320. Promise.prototype._queueGC = function Promise$_queueGC() {
  2321. if (this._isGcQueued()) return;
  2322. this._setGcQueued();
  2323. async.invokeLater(this._gc, this, void 0);
  2324. };
  2325. Promise.prototype._gc = function Promise$gc() {
  2326. var len = this._length();
  2327. this._unsetAt(0);
  2328. for (var i = 0; i < len; i++) {
  2329. delete this[i];
  2330. }
  2331. this._setLength(0);
  2332. this._unsetGcQueued();
  2333. };
  2334. Promise.prototype._queueSettleAt = function Promise$_queueSettleAt(index) {
  2335. if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled();
  2336. async.invoke(this._settlePromiseAt, this, index);
  2337. };
  2338. Promise.prototype._fulfillUnchecked =
  2339. function Promise$_fulfillUnchecked(value) {
  2340. if (!this.isPending()) return;
  2341. if (value === this) {
  2342. var err = makeSelfResolutionError();
  2343. this._attachExtraTrace(err);
  2344. return this._rejectUnchecked(err, void 0);
  2345. }
  2346. this._cleanValues();
  2347. this._setFulfilled();
  2348. this._settledValue = value;
  2349. var len = this._length();
  2350. if (len > 0) {
  2351. async.invoke(this._fulfillPromises, this, len);
  2352. }
  2353. };
  2354. Promise.prototype._rejectUncheckedCheckError =
  2355. function Promise$_rejectUncheckedCheckError(reason) {
  2356. var trace = canAttach(reason) ? reason : new Error(reason + "");
  2357. this._rejectUnchecked(reason, trace === reason ? void 0 : trace);
  2358. };
  2359. Promise.prototype._rejectUnchecked =
  2360. function Promise$_rejectUnchecked(reason, trace) {
  2361. if (!this.isPending()) return;
  2362. if (reason === this) {
  2363. var err = makeSelfResolutionError();
  2364. this._attachExtraTrace(err);
  2365. return this._rejectUnchecked(err);
  2366. }
  2367. this._cleanValues();
  2368. this._setRejected();
  2369. this._settledValue = reason;
  2370. if (this._isFinal()) {
  2371. async.invokeLater(thrower, void 0, trace === void 0 ? reason : trace);
  2372. return;
  2373. }
  2374. var len = this._length();
  2375. if (trace !== void 0) this._setCarriedStackTrace(trace);
  2376. if (len > 0) {
  2377. async.invoke(this._rejectPromises, this, len);
  2378. }
  2379. else {
  2380. this._ensurePossibleRejectionHandled();
  2381. }
  2382. };
  2383. Promise.prototype._rejectPromises = function Promise$_rejectPromises(len) {
  2384. len = this._length();
  2385. for (var i = 0; i < len; i+= 5) {
  2386. this._settlePromiseAt(i);
  2387. }
  2388. this._unsetCarriedStackTrace();
  2389. };
  2390. Promise.prototype._fulfillPromises = function Promise$_fulfillPromises(len) {
  2391. len = this._length();
  2392. for (var i = 0; i < len; i+= 5) {
  2393. this._settlePromiseAt(i);
  2394. }
  2395. };
  2396. Promise.prototype._ensurePossibleRejectionHandled =
  2397. function Promise$_ensurePossibleRejectionHandled() {
  2398. this._setRejectionIsUnhandled();
  2399. if (CapturedTrace.possiblyUnhandledRejection !== void 0) {
  2400. async.invokeLater(this._notifyUnhandledRejection, this, void 0);
  2401. }
  2402. };
  2403. Promise.prototype._notifyUnhandledRejection =
  2404. function Promise$_notifyUnhandledRejection() {
  2405. if (this._isRejectionUnhandled()) {
  2406. var reason = this._settledValue;
  2407. var trace = this._getCarriedStackTrace();
  2408. this._unsetRejectionIsUnhandled();
  2409. if (trace !== void 0) {
  2410. this._unsetCarriedStackTrace();
  2411. reason = trace;
  2412. }
  2413. if (typeof CapturedTrace.possiblyUnhandledRejection === "function") {
  2414. CapturedTrace.possiblyUnhandledRejection(reason, this);
  2415. }
  2416. }
  2417. };
  2418. var contextStack = [];
  2419. Promise.prototype._peekContext = function Promise$_peekContext() {
  2420. var lastIndex = contextStack.length - 1;
  2421. if (lastIndex >= 0) {
  2422. return contextStack[lastIndex];
  2423. }
  2424. return void 0;
  2425. };
  2426. Promise.prototype._pushContext = function Promise$_pushContext() {
  2427. if (!debugging) return;
  2428. contextStack.push(this);
  2429. };
  2430. Promise.prototype._popContext = function Promise$_popContext() {
  2431. if (!debugging) return;
  2432. contextStack.pop();
  2433. };
  2434. function Promise$_CreatePromiseArray(
  2435. promises, PromiseArrayConstructor, caller, boundTo) {
  2436. var list = null;
  2437. if (isArray(promises)) {
  2438. list = promises;
  2439. }
  2440. else {
  2441. list = Promise._cast(promises, caller, void 0);
  2442. if (list !== promises) {
  2443. list._setBoundTo(boundTo);
  2444. }
  2445. else if (!isPromise(list)) {
  2446. list = null;
  2447. }
  2448. }
  2449. if (list !== null) {
  2450. return new PromiseArrayConstructor(
  2451. list,
  2452. typeof caller === "function"
  2453. ? caller
  2454. : Promise$_CreatePromiseArray,
  2455. boundTo
  2456. );
  2457. }
  2458. return {
  2459. promise: function() {return apiRejection("expecting an array, a promise or a thenable");}
  2460. };
  2461. }
  2462. var old = global.Promise;
  2463. Promise.noConflict = function() {
  2464. if (global.Promise === Promise) {
  2465. global.Promise = old;
  2466. }
  2467. return Promise;
  2468. };
  2469. if (!CapturedTrace.isSupported()) {
  2470. Promise.longStackTraces = function(){};
  2471. debugging = false;
  2472. }
  2473. Promise._makeSelfResolutionError = makeSelfResolutionError;
  2474. require("./finally.js")(Promise, NEXT_FILTER);
  2475. require("./direct_resolve.js")(Promise);
  2476. require("./thenables.js")(Promise, INTERNAL);
  2477. Promise.RangeError = RangeError;
  2478. Promise.CancellationError = CancellationError;
  2479. Promise.TimeoutError = TimeoutError;
  2480. Promise.TypeError = TypeError;
  2481. Promise.RejectionError = RejectionError;
  2482. require('./timers.js')(Promise,INTERNAL);
  2483. require('./synchronous_inspection.js')(Promise);
  2484. require('./any.js')(Promise,Promise$_CreatePromiseArray,PromiseArray);
  2485. require('./race.js')(Promise,INTERNAL);
  2486. require('./call_get.js')(Promise);
  2487. require('./filter.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection);
  2488. require('./generators.js')(Promise,apiRejection,INTERNAL);
  2489. require('./map.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection);
  2490. require('./nodeify.js')(Promise);
  2491. require('./promisify.js')(Promise,INTERNAL);
  2492. require('./props.js')(Promise,PromiseArray);
  2493. require('./reduce.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection,INTERNAL);
  2494. require('./settle.js')(Promise,Promise$_CreatePromiseArray,PromiseArray);
  2495. require('./some.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection);
  2496. require('./progress.js')(Promise,isPromiseArrayProxy);
  2497. require('./cancel.js')(Promise,INTERNAL);
  2498. Promise.prototype = Promise.prototype;
  2499. return Promise;
  2500. };
  2501. },{"./any.js":1,"./assert.js":2,"./async.js":3,"./call_get.js":5,"./cancel.js":6,"./captured_trace.js":7,"./catch_filter.js":8,"./direct_resolve.js":9,"./errors.js":10,"./errors_api_rejection":11,"./filter.js":13,"./finally.js":14,"./generators.js":15,"./global.js":16,"./map.js":17,"./nodeify.js":18,"./progress.js":19,"./promise_array.js":21,"./promise_resolver.js":23,"./promisify.js":25,"./props.js":27,"./race.js":29,"./reduce.js":30,"./settle.js":32,"./some.js":34,"./synchronous_inspection.js":36,"./thenables.js":37,"./timers.js":38,"./util.js":39}],21:[function(require,module,exports){
  2502. /**
  2503. * Copyright (c) 2014 Petka Antonov
  2504. *
  2505. * Permission is hereby granted, free of charge, to any person obtaining a copy
  2506. * of this software and associated documentation files (the "Software"), to deal
  2507. * in the Software without restriction, including without limitation the rights
  2508. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  2509. * copies of the Software, and to permit persons to whom the Software is
  2510. * furnished to do so, subject to the following conditions:</p>
  2511. *
  2512. * The above copyright notice and this permission notice shall be included in
  2513. * all copies or substantial portions of the Software.
  2514. *
  2515. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  2516. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2517. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  2518. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  2519. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2520. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  2521. * THE SOFTWARE.
  2522. *
  2523. */
  2524. "use strict";
  2525. module.exports = function(Promise, INTERNAL) {
  2526. var ASSERT = require("./assert.js");
  2527. var canAttach = require("./errors.js").canAttach;
  2528. var util = require("./util.js");
  2529. var async = require("./async.js");
  2530. var hasOwn = {}.hasOwnProperty;
  2531. var isArray = util.isArray;
  2532. function toResolutionValue(val) {
  2533. switch(val) {
  2534. case -1: return void 0;
  2535. case -2: return [];
  2536. case -3: return {};
  2537. }
  2538. }
  2539. function PromiseArray(values, caller, boundTo) {
  2540. var promise = this._promise = new Promise(INTERNAL);
  2541. var parent = void 0;
  2542. if (Promise.is(values)) {
  2543. parent = values;
  2544. if (values._cancellable()) {
  2545. promise._setCancellable();
  2546. promise._cancellationParent = values;
  2547. }
  2548. if (values._isBound()) {
  2549. promise._setBoundTo(boundTo);
  2550. }
  2551. }
  2552. promise._setTrace(caller, parent);
  2553. this._values = values;
  2554. this._length = 0;
  2555. this._totalResolved = 0;
  2556. this._init(void 0, -2);
  2557. }
  2558. PromiseArray.PropertiesPromiseArray = function() {};
  2559. PromiseArray.prototype.length = function PromiseArray$length() {
  2560. return this._length;
  2561. };
  2562. PromiseArray.prototype.promise = function PromiseArray$promise() {
  2563. return this._promise;
  2564. };
  2565. PromiseArray.prototype._init =
  2566. function PromiseArray$_init(_, resolveValueIfEmpty) {
  2567. var values = this._values;
  2568. if (Promise.is(values)) {
  2569. if (values.isFulfilled()) {
  2570. values = values._settledValue;
  2571. if (!isArray(values)) {
  2572. var err = new Promise.TypeError("expecting an array, a promise or a thenable");
  2573. this.__hardReject__(err);
  2574. return;
  2575. }
  2576. this._values = values;
  2577. }
  2578. else if (values.isPending()) {
  2579. values._then(
  2580. this._init,
  2581. this._reject,
  2582. void 0,
  2583. this,
  2584. resolveValueIfEmpty,
  2585. this.constructor
  2586. );
  2587. return;
  2588. }
  2589. else {
  2590. this._reject(values._settledValue);
  2591. return;
  2592. }
  2593. }
  2594. if (values.length === 0) {
  2595. this._resolve(toResolutionValue(resolveValueIfEmpty));
  2596. return;
  2597. }
  2598. var len = values.length;
  2599. var newLen = len;
  2600. var newValues;
  2601. if (this instanceof PromiseArray.PropertiesPromiseArray) {
  2602. newValues = this._values;
  2603. }
  2604. else {
  2605. newValues = new Array(len);
  2606. }
  2607. var isDirectScanNeeded = false;
  2608. for (var i = 0; i < len; ++i) {
  2609. var promise = values[i];
  2610. if (promise === void 0 && !hasOwn.call(values, i)) {
  2611. newLen--;
  2612. continue;
  2613. }
  2614. var maybePromise = Promise._cast(promise, void 0, void 0);
  2615. if (maybePromise instanceof Promise &&
  2616. maybePromise.isPending()) {
  2617. maybePromise._proxyPromiseArray(this, i);
  2618. }
  2619. else {
  2620. isDirectScanNeeded = true;
  2621. }
  2622. newValues[i] = maybePromise;
  2623. }
  2624. if (newLen === 0) {
  2625. if (resolveValueIfEmpty === -2) {
  2626. this._resolve(newValues);
  2627. }
  2628. else {
  2629. this._resolve(toResolutionValue(resolveValueIfEmpty));
  2630. }
  2631. return;
  2632. }
  2633. this._values = newValues;
  2634. this._length = newLen;
  2635. if (isDirectScanNeeded) {
  2636. var scanMethod = newLen === len
  2637. ? this._scanDirectValues
  2638. : this._scanDirectValuesHoled;
  2639. async.invoke(scanMethod, this, len);
  2640. }
  2641. };
  2642. PromiseArray.prototype._settlePromiseAt =
  2643. function PromiseArray$_settlePromiseAt(index) {
  2644. var value = this._values[index];
  2645. if (!Promise.is(value)) {
  2646. this._promiseFulfilled(value, index);
  2647. }
  2648. else if (value.isFulfilled()) {
  2649. this._promiseFulfilled(value._settledValue, index);
  2650. }
  2651. else if (value.isRejected()) {
  2652. this._promiseRejected(value._settledValue, index);
  2653. }
  2654. };
  2655. PromiseArray.prototype._scanDirectValuesHoled =
  2656. function PromiseArray$_scanDirectValuesHoled(len) {
  2657. for (var i = 0; i < len; ++i) {
  2658. if (this._isResolved()) {
  2659. break;
  2660. }
  2661. if (hasOwn.call(this._values, i)) {
  2662. this._settlePromiseAt(i);
  2663. }
  2664. }
  2665. };
  2666. PromiseArray.prototype._scanDirectValues =
  2667. function PromiseArray$_scanDirectValues(len) {
  2668. for (var i = 0; i < len; ++i) {
  2669. if (this._isResolved()) {
  2670. break;
  2671. }
  2672. this._settlePromiseAt(i);
  2673. }
  2674. };
  2675. PromiseArray.prototype._isResolved = function PromiseArray$_isResolved() {
  2676. return this._values === null;
  2677. };
  2678. PromiseArray.prototype._resolve = function PromiseArray$_resolve(value) {
  2679. this._values = null;
  2680. this._promise._fulfill(value);
  2681. };
  2682. PromiseArray.prototype.__hardReject__ =
  2683. PromiseArray.prototype._reject = function PromiseArray$_reject(reason) {
  2684. this._values = null;
  2685. var trace = canAttach(reason) ? reason : new Error(reason + "");
  2686. this._promise._attachExtraTrace(trace);
  2687. this._promise._reject(reason, trace);
  2688. };
  2689. PromiseArray.prototype._promiseProgressed =
  2690. function PromiseArray$_promiseProgressed(progressValue, index) {
  2691. if (this._isResolved()) return;
  2692. this._promise._progress({
  2693. index: index,
  2694. value: progressValue
  2695. });
  2696. };
  2697. PromiseArray.prototype._promiseFulfilled =
  2698. function PromiseArray$_promiseFulfilled(value, index) {
  2699. if (this._isResolved()) return;
  2700. this._values[index] = value;
  2701. var totalResolved = ++this._totalResolved;
  2702. if (totalResolved >= this._length) {
  2703. this._resolve(this._values);
  2704. }
  2705. };
  2706. PromiseArray.prototype._promiseRejected =
  2707. function PromiseArray$_promiseRejected(reason, index) {
  2708. if (this._isResolved()) return;
  2709. this._totalResolved++;
  2710. this._reject(reason);
  2711. };
  2712. return PromiseArray;
  2713. };
  2714. },{"./assert.js":2,"./async.js":3,"./errors.js":10,"./util.js":39}],22:[function(require,module,exports){
  2715. /**
  2716. * Copyright (c) 2014 Petka Antonov
  2717. *
  2718. * Permission is hereby granted, free of charge, to any person obtaining a copy
  2719. * of this software and associated documentation files (the "Software"), to deal
  2720. * in the Software without restriction, including without limitation the rights
  2721. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  2722. * copies of the Software, and to permit persons to whom the Software is
  2723. * furnished to do so, subject to the following conditions:</p>
  2724. *
  2725. * The above copyright notice and this permission notice shall be included in
  2726. * all copies or substantial portions of the Software.
  2727. *
  2728. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  2729. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2730. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  2731. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  2732. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2733. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  2734. * THE SOFTWARE.
  2735. *
  2736. */
  2737. "use strict";
  2738. var TypeError = require("./errors.js").TypeError;
  2739. function PromiseInspection(promise) {
  2740. if (promise !== void 0) {
  2741. this._bitField = promise._bitField;
  2742. this._settledValue = promise.isResolved()
  2743. ? promise._settledValue
  2744. : void 0;
  2745. }
  2746. else {
  2747. this._bitField = 0;
  2748. this._settledValue = void 0;
  2749. }
  2750. }
  2751. PromiseInspection.prototype.isFulfilled =
  2752. function PromiseInspection$isFulfilled() {
  2753. return (this._bitField & 268435456) > 0;
  2754. };
  2755. PromiseInspection.prototype.isRejected =
  2756. function PromiseInspection$isRejected() {
  2757. return (this._bitField & 134217728) > 0;
  2758. };
  2759. PromiseInspection.prototype.isPending = function PromiseInspection$isPending() {
  2760. return (this._bitField & 402653184) === 0;
  2761. };
  2762. PromiseInspection.prototype.value = function PromiseInspection$value() {
  2763. if (!this.isFulfilled()) {
  2764. throw new TypeError("cannot get fulfillment value of a non-fulfilled promise");
  2765. }
  2766. return this._settledValue;
  2767. };
  2768. PromiseInspection.prototype.error = function PromiseInspection$error() {
  2769. if (!this.isRejected()) {
  2770. throw new TypeError("cannot get rejection reason of a non-rejected promise");
  2771. }
  2772. return this._settledValue;
  2773. };
  2774. module.exports = PromiseInspection;
  2775. },{"./errors.js":10}],23:[function(require,module,exports){
  2776. /**
  2777. * Copyright (c) 2014 Petka Antonov
  2778. *
  2779. * Permission is hereby granted, free of charge, to any person obtaining a copy
  2780. * of this software and associated documentation files (the "Software"), to deal
  2781. * in the Software without restriction, including without limitation the rights
  2782. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  2783. * copies of the Software, and to permit persons to whom the Software is
  2784. * furnished to do so, subject to the following conditions:</p>
  2785. *
  2786. * The above copyright notice and this permission notice shall be included in
  2787. * all copies or substantial portions of the Software.
  2788. *
  2789. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  2790. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2791. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  2792. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  2793. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2794. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  2795. * THE SOFTWARE.
  2796. *
  2797. */
  2798. "use strict";
  2799. var util = require("./util.js");
  2800. var maybeWrapAsError = util.maybeWrapAsError;
  2801. var errors = require("./errors.js");
  2802. var TimeoutError = errors.TimeoutError;
  2803. var RejectionError = errors.RejectionError;
  2804. var async = require("./async.js");
  2805. var haveGetters = util.haveGetters;
  2806. var es5 = require("./es5.js");
  2807. function isUntypedError(obj) {
  2808. return obj instanceof Error &&
  2809. es5.getPrototypeOf(obj) === Error.prototype;
  2810. }
  2811. function wrapAsRejectionError(obj) {
  2812. var ret;
  2813. if (isUntypedError(obj)) {
  2814. ret = new RejectionError(obj);
  2815. }
  2816. else {
  2817. ret = obj;
  2818. }
  2819. errors.markAsOriginatingFromRejection(ret);
  2820. return ret;
  2821. }
  2822. function nodebackForPromise(promise) {
  2823. function PromiseResolver$_callback(err, value) {
  2824. if (promise === null) return;
  2825. if (err) {
  2826. var wrapped = wrapAsRejectionError(maybeWrapAsError(err));
  2827. promise._attachExtraTrace(wrapped);
  2828. promise._reject(wrapped);
  2829. }
  2830. else {
  2831. if (arguments.length > 2) {
  2832. var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
  2833. promise._fulfill(args);
  2834. }
  2835. else {
  2836. promise._fulfill(value);
  2837. }
  2838. }
  2839. promise = null;
  2840. }
  2841. return PromiseResolver$_callback;
  2842. }
  2843. var PromiseResolver;
  2844. if (!haveGetters) {
  2845. PromiseResolver = function PromiseResolver(promise) {
  2846. this.promise = promise;
  2847. this.asCallback = nodebackForPromise(promise);
  2848. this.callback = this.asCallback;
  2849. };
  2850. }
  2851. else {
  2852. PromiseResolver = function PromiseResolver(promise) {
  2853. this.promise = promise;
  2854. };
  2855. }
  2856. if (haveGetters) {
  2857. var prop = {
  2858. get: function() {
  2859. return nodebackForPromise(this.promise);
  2860. }
  2861. };
  2862. es5.defineProperty(PromiseResolver.prototype, "asCallback", prop);
  2863. es5.defineProperty(PromiseResolver.prototype, "callback", prop);
  2864. }
  2865. PromiseResolver._nodebackForPromise = nodebackForPromise;
  2866. PromiseResolver.prototype.toString = function PromiseResolver$toString() {
  2867. return "[object PromiseResolver]";
  2868. };
  2869. PromiseResolver.prototype.resolve =
  2870. PromiseResolver.prototype.fulfill = function PromiseResolver$resolve(value) {
  2871. var promise = this.promise;
  2872. if (promise._tryFollow(value)) {
  2873. return;
  2874. }
  2875. async.invoke(promise._fulfill, promise, value);
  2876. };
  2877. PromiseResolver.prototype.reject = function PromiseResolver$reject(reason) {
  2878. var promise = this.promise;
  2879. errors.markAsOriginatingFromRejection(reason);
  2880. var trace = errors.canAttach(reason) ? reason : new Error(reason + "");
  2881. promise._attachExtraTrace(trace);
  2882. async.invoke(promise._reject, promise, reason);
  2883. if (trace !== reason) {
  2884. async.invoke(this._setCarriedStackTrace, this, trace);
  2885. }
  2886. };
  2887. PromiseResolver.prototype.progress =
  2888. function PromiseResolver$progress(value) {
  2889. async.invoke(this.promise._progress, this.promise, value);
  2890. };
  2891. PromiseResolver.prototype.cancel = function PromiseResolver$cancel() {
  2892. async.invoke(this.promise.cancel, this.promise, void 0);
  2893. };
  2894. PromiseResolver.prototype.timeout = function PromiseResolver$timeout() {
  2895. this.reject(new TimeoutError("timeout"));
  2896. };
  2897. PromiseResolver.prototype.isResolved = function PromiseResolver$isResolved() {
  2898. return this.promise.isResolved();
  2899. };
  2900. PromiseResolver.prototype.toJSON = function PromiseResolver$toJSON() {
  2901. return this.promise.toJSON();
  2902. };
  2903. PromiseResolver.prototype._setCarriedStackTrace =
  2904. function PromiseResolver$_setCarriedStackTrace(trace) {
  2905. if (this.promise.isRejected()) {
  2906. this.promise._setCarriedStackTrace(trace);
  2907. }
  2908. };
  2909. module.exports = PromiseResolver;
  2910. },{"./async.js":3,"./errors.js":10,"./es5.js":12,"./util.js":39}],24:[function(require,module,exports){
  2911. /**
  2912. * Copyright (c) 2014 Petka Antonov
  2913. *
  2914. * Permission is hereby granted, free of charge, to any person obtaining a copy
  2915. * of this software and associated documentation files (the "Software"), to deal
  2916. * in the Software without restriction, including without limitation the rights
  2917. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  2918. * copies of the Software, and to permit persons to whom the Software is
  2919. * furnished to do so, subject to the following conditions:</p>
  2920. *
  2921. * The above copyright notice and this permission notice shall be included in
  2922. * all copies or substantial portions of the Software.
  2923. *
  2924. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  2925. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2926. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  2927. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  2928. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2929. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  2930. * THE SOFTWARE.
  2931. *
  2932. */
  2933. "use strict";
  2934. module.exports = function(Promise, INTERNAL) {
  2935. var errors = require("./errors.js");
  2936. var ASSERT = require("./assert.js");
  2937. var TypeError = errors.TypeError;
  2938. var util = require("./util.js");
  2939. var isArray = util.isArray;
  2940. var errorObj = util.errorObj;
  2941. var tryCatch1 = util.tryCatch1;
  2942. var yieldHandlers = [];
  2943. function promiseFromYieldHandler(value) {
  2944. var _yieldHandlers = yieldHandlers;
  2945. var _errorObj = errorObj;
  2946. var _Promise = Promise;
  2947. var len = _yieldHandlers.length;
  2948. for (var i = 0; i < len; ++i) {
  2949. var result = tryCatch1(_yieldHandlers[i], void 0, value);
  2950. if (result === _errorObj) {
  2951. return _Promise.reject(_errorObj.e);
  2952. }
  2953. var maybePromise = _Promise._cast(result,
  2954. promiseFromYieldHandler, void 0);
  2955. if (maybePromise instanceof _Promise) return maybePromise;
  2956. }
  2957. return null;
  2958. }
  2959. function PromiseSpawn(generatorFunction, receiver, caller) {
  2960. var promise = this._promise = new Promise(INTERNAL);
  2961. promise._setTrace(caller, void 0);
  2962. this._generatorFunction = generatorFunction;
  2963. this._receiver = receiver;
  2964. this._generator = void 0;
  2965. }
  2966. PromiseSpawn.prototype.promise = function PromiseSpawn$promise() {
  2967. return this._promise;
  2968. };
  2969. PromiseSpawn.prototype._run = function PromiseSpawn$_run() {
  2970. this._generator = this._generatorFunction.call(this._receiver);
  2971. this._receiver =
  2972. this._generatorFunction = void 0;
  2973. this._next(void 0);
  2974. };
  2975. PromiseSpawn.prototype._continue = function PromiseSpawn$_continue(result) {
  2976. if (result === errorObj) {
  2977. this._generator = void 0;
  2978. var trace = errors.canAttach(result.e)
  2979. ? result.e : new Error(result.e + "");
  2980. this._promise._attachExtraTrace(trace);
  2981. this._promise._reject(result.e, trace);
  2982. return;
  2983. }
  2984. var value = result.value;
  2985. if (result.done === true) {
  2986. this._generator = void 0;
  2987. if (!this._promise._tryFollow(value)) {
  2988. this._promise._fulfill(value);
  2989. }
  2990. }
  2991. else {
  2992. var maybePromise = Promise._cast(value, PromiseSpawn$_continue, void 0);
  2993. if (!(maybePromise instanceof Promise)) {
  2994. if (isArray(maybePromise)) {
  2995. maybePromise = Promise.all(maybePromise);
  2996. }
  2997. else {
  2998. maybePromise = promiseFromYieldHandler(maybePromise);
  2999. }
  3000. if (maybePromise === null) {
  3001. this._throw(new TypeError("A value was yielded that could not be treated as a promise"));
  3002. return;
  3003. }
  3004. }
  3005. maybePromise._then(
  3006. this._next,
  3007. this._throw,
  3008. void 0,
  3009. this,
  3010. null,
  3011. void 0
  3012. );
  3013. }
  3014. };
  3015. PromiseSpawn.prototype._throw = function PromiseSpawn$_throw(reason) {
  3016. if (errors.canAttach(reason))
  3017. this._promise._attachExtraTrace(reason);
  3018. this._continue(
  3019. tryCatch1(this._generator["throw"], this._generator, reason)
  3020. );
  3021. };
  3022. PromiseSpawn.prototype._next = function PromiseSpawn$_next(value) {
  3023. this._continue(
  3024. tryCatch1(this._generator.next, this._generator, value)
  3025. );
  3026. };
  3027. PromiseSpawn.addYieldHandler = function PromiseSpawn$AddYieldHandler(fn) {
  3028. if (typeof fn !== "function") throw new TypeError("fn must be a function");
  3029. yieldHandlers.push(fn);
  3030. };
  3031. return PromiseSpawn;
  3032. };
  3033. },{"./assert.js":2,"./errors.js":10,"./util.js":39}],25:[function(require,module,exports){
  3034. /**
  3035. * Copyright (c) 2014 Petka Antonov
  3036. *
  3037. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3038. * of this software and associated documentation files (the "Software"), to deal
  3039. * in the Software without restriction, including without limitation the rights
  3040. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3041. * copies of the Software, and to permit persons to whom the Software is
  3042. * furnished to do so, subject to the following conditions:</p>
  3043. *
  3044. * The above copyright notice and this permission notice shall be included in
  3045. * all copies or substantial portions of the Software.
  3046. *
  3047. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3048. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3049. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3050. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3051. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3052. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3053. * THE SOFTWARE.
  3054. *
  3055. */
  3056. "use strict";
  3057. module.exports = function(Promise, INTERNAL) {
  3058. var THIS = {};
  3059. var util = require("./util.js");
  3060. var es5 = require("./es5.js");
  3061. var nodebackForPromise = require("./promise_resolver.js")
  3062. ._nodebackForPromise;
  3063. var withAppended = util.withAppended;
  3064. var maybeWrapAsError = util.maybeWrapAsError;
  3065. var canEvaluate = util.canEvaluate;
  3066. var notEnumerableProp = util.notEnumerableProp;
  3067. var deprecated = util.deprecated;
  3068. var ASSERT = require("./assert.js");
  3069. var roriginal = new RegExp("__beforePromisified__" + "$");
  3070. var hasProp = {}.hasOwnProperty;
  3071. function isPromisified(fn) {
  3072. return fn.__isPromisified__ === true;
  3073. }
  3074. var inheritedMethods = (function() {
  3075. if (es5.isES5) {
  3076. var create = Object.create;
  3077. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  3078. return function(cur) {
  3079. var original = cur;
  3080. var ret = [];
  3081. var visitedKeys = create(null);
  3082. while (cur !== null) {
  3083. var keys = es5.keys(cur);
  3084. for (var i = 0, len = keys.length; i < len; ++i) {
  3085. var key = keys[i];
  3086. if (visitedKeys[key] ||
  3087. roriginal.test(key) ||
  3088. hasProp.call(original, key + "__beforePromisified__")
  3089. ) {
  3090. continue;
  3091. }
  3092. visitedKeys[key] = true;
  3093. var desc = getOwnPropertyDescriptor(cur, key);
  3094. if (desc != null &&
  3095. typeof desc.value === "function" &&
  3096. !isPromisified(desc.value)) {
  3097. ret.push(key, desc.value);
  3098. }
  3099. }
  3100. cur = es5.getPrototypeOf(cur);
  3101. }
  3102. return ret;
  3103. };
  3104. }
  3105. else {
  3106. return function(obj) {
  3107. var ret = [];
  3108. /*jshint forin:false */
  3109. for (var key in obj) {
  3110. if (roriginal.test(key) ||
  3111. hasProp.call(obj, key + "__beforePromisified__")) {
  3112. continue;
  3113. }
  3114. var fn = obj[key];
  3115. if (typeof fn === "function" &&
  3116. !isPromisified(fn)) {
  3117. ret.push(key, fn);
  3118. }
  3119. }
  3120. return ret;
  3121. };
  3122. }
  3123. })();
  3124. function switchCaseArgumentOrder(likelyArgumentCount) {
  3125. var ret = [likelyArgumentCount];
  3126. var min = Math.max(0, likelyArgumentCount - 1 - 5);
  3127. for(var i = likelyArgumentCount - 1; i >= min; --i) {
  3128. if (i === likelyArgumentCount) continue;
  3129. ret.push(i);
  3130. }
  3131. for(var i = likelyArgumentCount + 1; i <= 5; ++i) {
  3132. ret.push(i);
  3133. }
  3134. return ret;
  3135. }
  3136. function parameterDeclaration(parameterCount) {
  3137. var ret = new Array(parameterCount);
  3138. for(var i = 0; i < ret.length; ++i) {
  3139. ret[i] = "_arg" + i;
  3140. }
  3141. return ret.join(", ");
  3142. }
  3143. function parameterCount(fn) {
  3144. if (typeof fn.length === "number") {
  3145. return Math.max(Math.min(fn.length, 1023 + 1), 0);
  3146. }
  3147. return 0;
  3148. }
  3149. function propertyAccess(id) {
  3150. var rident = /^[a-z$_][a-z$_0-9]*$/i;
  3151. if (rident.test(id)) {
  3152. return "." + id;
  3153. }
  3154. else return "['" + id.replace(/(['\\])/g, "\\$1") + "']";
  3155. }
  3156. function makeNodePromisifiedEval(callback, receiver, originalName, fn) {
  3157. var newParameterCount = Math.max(0, parameterCount(fn) - 1);
  3158. var argumentOrder = switchCaseArgumentOrder(newParameterCount);
  3159. var callbackName = (typeof originalName === "string" ?
  3160. originalName + "Async" :
  3161. "promisified");
  3162. function generateCallForArgumentCount(count) {
  3163. var args = new Array(count);
  3164. for (var i = 0, len = args.length; i < len; ++i) {
  3165. args[i] = "arguments[" + i + "]";
  3166. }
  3167. var comma = count > 0 ? "," : "";
  3168. if (typeof callback === "string" &&
  3169. receiver === THIS) {
  3170. return "this" + propertyAccess(callback) + "("+args.join(",") +
  3171. comma +" fn);"+
  3172. "break;";
  3173. }
  3174. return (receiver === void 0
  3175. ? "callback("+args.join(",")+ comma +" fn);"
  3176. : "callback.call("+(receiver === THIS
  3177. ? "this"
  3178. : "receiver")+", "+args.join(",") + comma + " fn);") +
  3179. "break;";
  3180. }
  3181. function generateArgumentSwitchCase() {
  3182. var ret = "";
  3183. for(var i = 0; i < argumentOrder.length; ++i) {
  3184. ret += "case " + argumentOrder[i] +":" +
  3185. generateCallForArgumentCount(argumentOrder[i]);
  3186. }
  3187. ret += "default: var args = new Array(len + 1);" +
  3188. "var i = 0;" +
  3189. "for (var i = 0; i < len; ++i) { " +
  3190. " args[i] = arguments[i];" +
  3191. "}" +
  3192. "args[i] = fn;" +
  3193. (typeof callback === "string"
  3194. ? "this" + propertyAccess(callback) + ".apply("
  3195. : "callback.apply(") +
  3196. (receiver === THIS ? "this" : "receiver") +
  3197. ", args); break;";
  3198. return ret;
  3199. }
  3200. return new Function("Promise", "callback", "receiver",
  3201. "withAppended", "maybeWrapAsError", "nodebackForPromise",
  3202. "INTERNAL",
  3203. "var ret = function " + callbackName +
  3204. "(" + parameterDeclaration(newParameterCount) + ") {\"use strict\";" +
  3205. "var len = arguments.length;" +
  3206. "var promise = new Promise(INTERNAL);"+
  3207. "promise._setTrace(" + callbackName + ", void 0);" +
  3208. "var fn = nodebackForPromise(promise);"+
  3209. "try {" +
  3210. "switch(len) {" +
  3211. generateArgumentSwitchCase() +
  3212. "}" +
  3213. "}" +
  3214. "catch(e){ " +
  3215. "var wrapped = maybeWrapAsError(e);" +
  3216. "promise._attachExtraTrace(wrapped);" +
  3217. "promise._reject(wrapped);" +
  3218. "}" +
  3219. "return promise;" +
  3220. "" +
  3221. "}; ret.__isPromisified__ = true; return ret;"
  3222. )(Promise, callback, receiver, withAppended,
  3223. maybeWrapAsError, nodebackForPromise, INTERNAL);
  3224. }
  3225. function makeNodePromisifiedClosure(callback, receiver) {
  3226. function promisified() {
  3227. var _receiver = receiver;
  3228. if (receiver === THIS) _receiver = this;
  3229. if (typeof callback === "string") {
  3230. callback = _receiver[callback];
  3231. }
  3232. var promise = new Promise(INTERNAL);
  3233. promise._setTrace(promisified, void 0);
  3234. var fn = nodebackForPromise(promise);
  3235. try {
  3236. callback.apply(_receiver, withAppended(arguments, fn));
  3237. }
  3238. catch(e) {
  3239. var wrapped = maybeWrapAsError(e);
  3240. promise._attachExtraTrace(wrapped);
  3241. promise._reject(wrapped);
  3242. }
  3243. return promise;
  3244. }
  3245. promisified.__isPromisified__ = true;
  3246. return promisified;
  3247. }
  3248. var makeNodePromisified = canEvaluate
  3249. ? makeNodePromisifiedEval
  3250. : makeNodePromisifiedClosure;
  3251. function f(){}
  3252. function _promisify(callback, receiver, isAll) {
  3253. if (isAll) {
  3254. var methods = inheritedMethods(callback);
  3255. for (var i = 0, len = methods.length; i < len; i+= 2) {
  3256. var key = methods[i];
  3257. var fn = methods[i+1];
  3258. var originalKey = key + "__beforePromisified__";
  3259. var promisifiedKey = key + "Async";
  3260. notEnumerableProp(callback, originalKey, fn);
  3261. callback[promisifiedKey] =
  3262. makeNodePromisified(originalKey, THIS,
  3263. key, fn);
  3264. }
  3265. if (methods.length > 16) f.prototype = callback;
  3266. return callback;
  3267. }
  3268. else {
  3269. return makeNodePromisified(callback, receiver, void 0, callback);
  3270. }
  3271. }
  3272. Promise.promisify = function Promise$Promisify(fn, receiver) {
  3273. if (typeof fn === "object" && fn !== null) {
  3274. deprecated("Promise.promisify for promisifying entire objects is deprecated. Use Promise.promisifyAll instead.");
  3275. return _promisify(fn, receiver, true);
  3276. }
  3277. if (typeof fn !== "function") {
  3278. throw new TypeError("fn must be a function");
  3279. }
  3280. if (isPromisified(fn)) {
  3281. return fn;
  3282. }
  3283. return _promisify(
  3284. fn,
  3285. arguments.length < 2 ? THIS : receiver,
  3286. false);
  3287. };
  3288. Promise.promisifyAll = function Promise$PromisifyAll(target) {
  3289. if (typeof target !== "function" && typeof target !== "object") {
  3290. throw new TypeError("the target of promisifyAll must be an object or a function");
  3291. }
  3292. return _promisify(target, void 0, true);
  3293. };
  3294. };
  3295. },{"./assert.js":2,"./es5.js":12,"./promise_resolver.js":23,"./util.js":39}],26:[function(require,module,exports){
  3296. /**
  3297. * Copyright (c) 2014 Petka Antonov
  3298. *
  3299. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3300. * of this software and associated documentation files (the "Software"), to deal
  3301. * in the Software without restriction, including without limitation the rights
  3302. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3303. * copies of the Software, and to permit persons to whom the Software is
  3304. * furnished to do so, subject to the following conditions:</p>
  3305. *
  3306. * The above copyright notice and this permission notice shall be included in
  3307. * all copies or substantial portions of the Software.
  3308. *
  3309. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3310. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3311. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3312. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3313. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3314. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3315. * THE SOFTWARE.
  3316. *
  3317. */
  3318. "use strict";
  3319. module.exports = function(Promise, PromiseArray) {
  3320. var ASSERT = require("./assert.js");
  3321. var util = require("./util.js");
  3322. var inherits = util.inherits;
  3323. var es5 = require("./es5.js");
  3324. function PropertiesPromiseArray(obj, caller, boundTo) {
  3325. var keys = es5.keys(obj);
  3326. var values = new Array(keys.length);
  3327. for (var i = 0, len = values.length; i < len; ++i) {
  3328. values[i] = obj[keys[i]];
  3329. }
  3330. this.constructor$(values, caller, boundTo);
  3331. if (!this._isResolved()) {
  3332. for (var i = 0, len = keys.length; i < len; ++i) {
  3333. values.push(keys[i]);
  3334. }
  3335. }
  3336. }
  3337. inherits(PropertiesPromiseArray, PromiseArray);
  3338. PropertiesPromiseArray.prototype._init =
  3339. function PropertiesPromiseArray$_init() {
  3340. this._init$(void 0, -3) ;
  3341. };
  3342. PropertiesPromiseArray.prototype._promiseFulfilled =
  3343. function PropertiesPromiseArray$_promiseFulfilled(value, index) {
  3344. if (this._isResolved()) return;
  3345. this._values[index] = value;
  3346. var totalResolved = ++this._totalResolved;
  3347. if (totalResolved >= this._length) {
  3348. var val = {};
  3349. var keyOffset = this.length();
  3350. for (var i = 0, len = this.length(); i < len; ++i) {
  3351. val[this._values[i + keyOffset]] = this._values[i];
  3352. }
  3353. this._resolve(val);
  3354. }
  3355. };
  3356. PropertiesPromiseArray.prototype._promiseProgressed =
  3357. function PropertiesPromiseArray$_promiseProgressed(value, index) {
  3358. if (this._isResolved()) return;
  3359. this._promise._progress({
  3360. key: this._values[index + this.length()],
  3361. value: value
  3362. });
  3363. };
  3364. PromiseArray.PropertiesPromiseArray = PropertiesPromiseArray;
  3365. return PropertiesPromiseArray;
  3366. };
  3367. },{"./assert.js":2,"./es5.js":12,"./util.js":39}],27:[function(require,module,exports){
  3368. /**
  3369. * Copyright (c) 2014 Petka Antonov
  3370. *
  3371. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3372. * of this software and associated documentation files (the "Software"), to deal
  3373. * in the Software without restriction, including without limitation the rights
  3374. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3375. * copies of the Software, and to permit persons to whom the Software is
  3376. * furnished to do so, subject to the following conditions:</p>
  3377. *
  3378. * The above copyright notice and this permission notice shall be included in
  3379. * all copies or substantial portions of the Software.
  3380. *
  3381. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3382. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3383. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3384. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3385. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3386. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3387. * THE SOFTWARE.
  3388. *
  3389. */
  3390. "use strict";
  3391. module.exports = function(Promise, PromiseArray) {
  3392. var PropertiesPromiseArray = require("./properties_promise_array.js")(
  3393. Promise, PromiseArray);
  3394. var util = require("./util.js");
  3395. var apiRejection = require("./errors_api_rejection")(Promise);
  3396. var isObject = util.isObject;
  3397. function Promise$_Props(promises, useBound, caller) {
  3398. var ret;
  3399. var castValue = Promise._cast(promises, caller, void 0);
  3400. if (!isObject(castValue)) {
  3401. return apiRejection("cannot await properties of a non-object");
  3402. }
  3403. else if (Promise.is(castValue)) {
  3404. ret = castValue._then(Promise.props, void 0, void 0,
  3405. void 0, void 0, caller);
  3406. }
  3407. else {
  3408. ret = new PropertiesPromiseArray(
  3409. castValue,
  3410. caller,
  3411. useBound === true && castValue._isBound()
  3412. ? castValue._boundTo
  3413. : void 0
  3414. ).promise();
  3415. useBound = false;
  3416. }
  3417. if (useBound === true && castValue._isBound()) {
  3418. ret._setBoundTo(castValue._boundTo);
  3419. }
  3420. return ret;
  3421. }
  3422. Promise.prototype.props = function Promise$props() {
  3423. return Promise$_Props(this, true, this.props);
  3424. };
  3425. Promise.props = function Promise$Props(promises) {
  3426. return Promise$_Props(promises, false, Promise.props);
  3427. };
  3428. };
  3429. },{"./errors_api_rejection":11,"./properties_promise_array.js":26,"./util.js":39}],28:[function(require,module,exports){
  3430. /**
  3431. * Copyright (c) 2014 Petka Antonov
  3432. *
  3433. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3434. * of this software and associated documentation files (the "Software"), to deal
  3435. * in the Software without restriction, including without limitation the rights
  3436. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3437. * copies of the Software, and to permit persons to whom the Software is
  3438. * furnished to do so, subject to the following conditions:</p>
  3439. *
  3440. * The above copyright notice and this permission notice shall be included in
  3441. * all copies or substantial portions of the Software.
  3442. *
  3443. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3444. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3445. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3446. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3447. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3448. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3449. * THE SOFTWARE.
  3450. *
  3451. */
  3452. "use strict";
  3453. var ASSERT = require("./assert.js");
  3454. function arrayCopy(src, srcIndex, dst, dstIndex, len) {
  3455. for (var j = 0; j < len; ++j) {
  3456. dst[j + dstIndex] = src[j + srcIndex];
  3457. }
  3458. }
  3459. function pow2AtLeast(n) {
  3460. n = n >>> 0;
  3461. n = n - 1;
  3462. n = n | (n >> 1);
  3463. n = n | (n >> 2);
  3464. n = n | (n >> 4);
  3465. n = n | (n >> 8);
  3466. n = n | (n >> 16);
  3467. return n + 1;
  3468. }
  3469. function getCapacity(capacity) {
  3470. if (typeof capacity !== "number") return 16;
  3471. return pow2AtLeast(
  3472. Math.min(
  3473. Math.max(16, capacity), 1073741824)
  3474. );
  3475. }
  3476. function Queue(capacity) {
  3477. this._capacity = getCapacity(capacity);
  3478. this._length = 0;
  3479. this._front = 0;
  3480. this._makeCapacity();
  3481. }
  3482. Queue.prototype._willBeOverCapacity =
  3483. function Queue$_willBeOverCapacity(size) {
  3484. return this._capacity < size;
  3485. };
  3486. Queue.prototype._pushOne = function Queue$_pushOne(arg) {
  3487. var length = this.length();
  3488. this._checkCapacity(length + 1);
  3489. var i = (this._front + length) & (this._capacity - 1);
  3490. this[i] = arg;
  3491. this._length = length + 1;
  3492. };
  3493. Queue.prototype.push = function Queue$push(fn, receiver, arg) {
  3494. var length = this.length() + 3;
  3495. if (this._willBeOverCapacity(length)) {
  3496. this._pushOne(fn);
  3497. this._pushOne(receiver);
  3498. this._pushOne(arg);
  3499. return;
  3500. }
  3501. var j = this._front + length - 3;
  3502. this._checkCapacity(length);
  3503. var wrapMask = this._capacity - 1;
  3504. this[(j + 0) & wrapMask] = fn;
  3505. this[(j + 1) & wrapMask] = receiver;
  3506. this[(j + 2) & wrapMask] = arg;
  3507. this._length = length;
  3508. };
  3509. Queue.prototype.shift = function Queue$shift() {
  3510. var front = this._front,
  3511. ret = this[front];
  3512. this[front] = void 0;
  3513. this._front = (front + 1) & (this._capacity - 1);
  3514. this._length--;
  3515. return ret;
  3516. };
  3517. Queue.prototype.length = function Queue$length() {
  3518. return this._length;
  3519. };
  3520. Queue.prototype._makeCapacity = function Queue$_makeCapacity() {
  3521. var len = this._capacity;
  3522. for (var i = 0; i < len; ++i) {
  3523. this[i] = void 0;
  3524. }
  3525. };
  3526. Queue.prototype._checkCapacity = function Queue$_checkCapacity(size) {
  3527. if (this._capacity < size) {
  3528. this._resizeTo(this._capacity << 3);
  3529. }
  3530. };
  3531. Queue.prototype._resizeTo = function Queue$_resizeTo(capacity) {
  3532. var oldFront = this._front;
  3533. var oldCapacity = this._capacity;
  3534. var oldQueue = new Array(oldCapacity);
  3535. var length = this.length();
  3536. arrayCopy(this, 0, oldQueue, 0, oldCapacity);
  3537. this._capacity = capacity;
  3538. this._makeCapacity();
  3539. this._front = 0;
  3540. if (oldFront + length <= oldCapacity) {
  3541. arrayCopy(oldQueue, oldFront, this, 0, length);
  3542. }
  3543. else { var lengthBeforeWrapping =
  3544. length - ((oldFront + length) & (oldCapacity - 1));
  3545. arrayCopy(oldQueue, oldFront, this, 0, lengthBeforeWrapping);
  3546. arrayCopy(oldQueue, 0, this, lengthBeforeWrapping,
  3547. length - lengthBeforeWrapping);
  3548. }
  3549. };
  3550. module.exports = Queue;
  3551. },{"./assert.js":2}],29:[function(require,module,exports){
  3552. /**
  3553. * Copyright (c) 2014 Petka Antonov
  3554. *
  3555. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3556. * of this software and associated documentation files (the "Software"), to deal
  3557. * in the Software without restriction, including without limitation the rights
  3558. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3559. * copies of the Software, and to permit persons to whom the Software is
  3560. * furnished to do so, subject to the following conditions:</p>
  3561. *
  3562. * The above copyright notice and this permission notice shall be included in
  3563. * all copies or substantial portions of the Software.
  3564. *
  3565. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3566. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3567. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3568. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3569. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3570. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3571. * THE SOFTWARE.
  3572. *
  3573. */
  3574. "use strict";
  3575. module.exports = function(Promise, INTERNAL) {
  3576. var apiRejection = require("./errors_api_rejection.js")(Promise);
  3577. var isArray = require("./util.js").isArray;
  3578. var raceLater = function Promise$_raceLater(promise) {
  3579. return promise.then(function Promise$_lateRacer(array) {
  3580. return Promise$_Race(array, Promise$_lateRacer, promise);
  3581. });
  3582. };
  3583. var hasOwn = {}.hasOwnProperty;
  3584. function Promise$_Race(promises, caller, parent) {
  3585. var maybePromise = Promise._cast(promises, caller, void 0);
  3586. if (Promise.is(maybePromise)) {
  3587. return raceLater(maybePromise);
  3588. }
  3589. else if (!isArray(promises)) {
  3590. return apiRejection("expecting an array, a promise or a thenable");
  3591. }
  3592. var ret = new Promise(INTERNAL);
  3593. ret._setTrace(caller, parent);
  3594. if (parent !== void 0) {
  3595. if (parent._isBound()) {
  3596. ret._setBoundTo(parent._boundTo);
  3597. }
  3598. if (parent._cancellable()) {
  3599. ret._setCancellable();
  3600. ret._cancellationParent = parent;
  3601. }
  3602. }
  3603. var fulfill = ret._fulfill;
  3604. var reject = ret._reject;
  3605. for (var i = 0, len = promises.length; i < len; ++i) {
  3606. var val = promises[i];
  3607. if (val === void 0 && !(hasOwn.call(promises, i))) {
  3608. continue;
  3609. }
  3610. Promise.cast(val)._then(
  3611. fulfill,
  3612. reject,
  3613. void 0,
  3614. ret,
  3615. null,
  3616. caller
  3617. );
  3618. }
  3619. return ret;
  3620. }
  3621. Promise.race = function Promise$Race(promises) {
  3622. return Promise$_Race(promises, Promise.race, void 0);
  3623. };
  3624. Promise.prototype.race = function Promise$race() {
  3625. return Promise$_Race(this, this.race, void 0);
  3626. };
  3627. };
  3628. },{"./errors_api_rejection.js":11,"./util.js":39}],30:[function(require,module,exports){
  3629. /**
  3630. * Copyright (c) 2014 Petka Antonov
  3631. *
  3632. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3633. * of this software and associated documentation files (the "Software"), to deal
  3634. * in the Software without restriction, including without limitation the rights
  3635. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3636. * copies of the Software, and to permit persons to whom the Software is
  3637. * furnished to do so, subject to the following conditions:</p>
  3638. *
  3639. * The above copyright notice and this permission notice shall be included in
  3640. * all copies or substantial portions of the Software.
  3641. *
  3642. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3643. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3644. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3645. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3646. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3647. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3648. * THE SOFTWARE.
  3649. *
  3650. */
  3651. "use strict";
  3652. module.exports = function(
  3653. Promise, Promise$_CreatePromiseArray,
  3654. PromiseArray, apiRejection, INTERNAL) {
  3655. var ASSERT = require("./assert.js");
  3656. function Reduction(callback, index, accum, items, receiver) {
  3657. this.promise = new Promise(INTERNAL);
  3658. this.index = index;
  3659. this.length = items.length;
  3660. this.items = items;
  3661. this.callback = callback;
  3662. this.receiver = receiver;
  3663. this.accum = accum;
  3664. }
  3665. Reduction.prototype.reject = function Reduction$reject(e) {
  3666. this.promise._reject(e);
  3667. };
  3668. Reduction.prototype.fulfill = function Reduction$fulfill(value, index) {
  3669. this.accum = value;
  3670. this.index = index + 1;
  3671. this.iterate();
  3672. };
  3673. Reduction.prototype.iterate = function Reduction$iterate() {
  3674. var i = this.index;
  3675. var len = this.length;
  3676. var items = this.items;
  3677. var result = this.accum;
  3678. var receiver = this.receiver;
  3679. var callback = this.callback;
  3680. var iterate = this.iterate;
  3681. for(; i < len; ++i) {
  3682. result = Promise._cast(
  3683. callback.call(
  3684. receiver,
  3685. result,
  3686. items[i],
  3687. i,
  3688. len
  3689. ),
  3690. iterate,
  3691. void 0
  3692. );
  3693. if (result instanceof Promise) {
  3694. result._then(
  3695. this.fulfill, this.reject, void 0, this, i, iterate);
  3696. return;
  3697. }
  3698. }
  3699. this.promise._fulfill(result);
  3700. };
  3701. function Promise$_reducer(fulfilleds, initialValue) {
  3702. var fn = this;
  3703. var receiver = void 0;
  3704. if (typeof fn !== "function") {
  3705. receiver = fn.receiver;
  3706. fn = fn.fn;
  3707. }
  3708. var len = fulfilleds.length;
  3709. var accum = void 0;
  3710. var startIndex = 0;
  3711. if (initialValue !== void 0) {
  3712. accum = initialValue;
  3713. startIndex = 0;
  3714. }
  3715. else {
  3716. startIndex = 1;
  3717. if (len > 0) accum = fulfilleds[0];
  3718. }
  3719. var i = startIndex;
  3720. if (i >= len) {
  3721. return accum;
  3722. }
  3723. var reduction = new Reduction(fn, i, accum, fulfilleds, receiver);
  3724. reduction.iterate();
  3725. return reduction.promise;
  3726. }
  3727. function Promise$_unpackReducer(fulfilleds) {
  3728. var fn = this.fn;
  3729. var initialValue = this.initialValue;
  3730. return Promise$_reducer.call(fn, fulfilleds, initialValue);
  3731. }
  3732. function Promise$_slowReduce(
  3733. promises, fn, initialValue, useBound, caller) {
  3734. return initialValue._then(function callee(initialValue) {
  3735. return Promise$_Reduce(
  3736. promises, fn, initialValue, useBound, callee);
  3737. }, void 0, void 0, void 0, void 0, caller);
  3738. }
  3739. function Promise$_Reduce(promises, fn, initialValue, useBound, caller) {
  3740. if (typeof fn !== "function") {
  3741. return apiRejection("fn must be a function");
  3742. }
  3743. if (useBound === true && promises._isBound()) {
  3744. fn = {
  3745. fn: fn,
  3746. receiver: promises._boundTo
  3747. };
  3748. }
  3749. if (initialValue !== void 0) {
  3750. if (Promise.is(initialValue)) {
  3751. if (initialValue.isFulfilled()) {
  3752. initialValue = initialValue._settledValue;
  3753. }
  3754. else {
  3755. return Promise$_slowReduce(promises,
  3756. fn, initialValue, useBound, caller);
  3757. }
  3758. }
  3759. return Promise$_CreatePromiseArray(promises, PromiseArray, caller,
  3760. useBound === true && promises._isBound()
  3761. ? promises._boundTo
  3762. : void 0)
  3763. .promise()
  3764. ._then(Promise$_unpackReducer, void 0, void 0, {
  3765. fn: fn,
  3766. initialValue: initialValue
  3767. }, void 0, Promise.reduce);
  3768. }
  3769. return Promise$_CreatePromiseArray(promises, PromiseArray, caller,
  3770. useBound === true && promises._isBound()
  3771. ? promises._boundTo
  3772. : void 0).promise()
  3773. ._then(Promise$_reducer, void 0, void 0, fn, void 0, caller);
  3774. }
  3775. Promise.reduce = function Promise$Reduce(promises, fn, initialValue) {
  3776. return Promise$_Reduce(promises, fn,
  3777. initialValue, false, Promise.reduce);
  3778. };
  3779. Promise.prototype.reduce = function Promise$reduce(fn, initialValue) {
  3780. return Promise$_Reduce(this, fn, initialValue,
  3781. true, this.reduce);
  3782. };
  3783. };
  3784. },{"./assert.js":2}],31:[function(require,module,exports){
  3785. /**
  3786. * Copyright (c) 2014 Petka Antonov
  3787. *
  3788. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3789. * of this software and associated documentation files (the "Software"), to deal
  3790. * in the Software without restriction, including without limitation the rights
  3791. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3792. * copies of the Software, and to permit persons to whom the Software is
  3793. * furnished to do so, subject to the following conditions:</p>
  3794. *
  3795. * The above copyright notice and this permission notice shall be included in
  3796. * all copies or substantial portions of the Software.
  3797. *
  3798. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3799. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3800. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3801. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3802. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3803. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3804. * THE SOFTWARE.
  3805. *
  3806. */
  3807. "use strict";
  3808. var global = require("./global.js");
  3809. var ASSERT = require("./assert.js");
  3810. var schedule;
  3811. if (typeof process !== "undefined" && process !== null &&
  3812. typeof process.cwd === "function" &&
  3813. typeof process.nextTick === "function" &&
  3814. typeof process.version === "string") {
  3815. schedule = function Promise$_Scheduler(fn) {
  3816. process.nextTick(fn);
  3817. };
  3818. }
  3819. else if ((typeof global.MutationObserver === "function" ||
  3820. typeof global.WebkitMutationObserver === "function" ||
  3821. typeof global.WebKitMutationObserver === "function") &&
  3822. typeof document !== "undefined" &&
  3823. typeof document.createElement === "function") {
  3824. schedule = (function(){
  3825. var MutationObserver = global.MutationObserver ||
  3826. global.WebkitMutationObserver ||
  3827. global.WebKitMutationObserver;
  3828. var div = document.createElement("div");
  3829. var queuedFn = void 0;
  3830. var observer = new MutationObserver(
  3831. function Promise$_Scheduler() {
  3832. var fn = queuedFn;
  3833. queuedFn = void 0;
  3834. fn();
  3835. }
  3836. );
  3837. observer.observe(div, {
  3838. attributes: true
  3839. });
  3840. return function Promise$_Scheduler(fn) {
  3841. queuedFn = fn;
  3842. div.setAttribute("class", "foo");
  3843. };
  3844. })();
  3845. }
  3846. else if (typeof global.postMessage === "function" &&
  3847. typeof global.importScripts !== "function" &&
  3848. typeof global.addEventListener === "function" &&
  3849. typeof global.removeEventListener === "function") {
  3850. var MESSAGE_KEY = "bluebird_message_key_" + Math.random();
  3851. schedule = (function(){
  3852. var queuedFn = void 0;
  3853. function Promise$_Scheduler(e) {
  3854. if (e.source === global &&
  3855. e.data === MESSAGE_KEY) {
  3856. var fn = queuedFn;
  3857. queuedFn = void 0;
  3858. fn();
  3859. }
  3860. }
  3861. global.addEventListener("message", Promise$_Scheduler, false);
  3862. return function Promise$_Scheduler(fn) {
  3863. queuedFn = fn;
  3864. global.postMessage(
  3865. MESSAGE_KEY, "*"
  3866. );
  3867. };
  3868. })();
  3869. }
  3870. else if (typeof global.MessageChannel === "function") {
  3871. schedule = (function(){
  3872. var queuedFn = void 0;
  3873. var channel = new global.MessageChannel();
  3874. channel.port1.onmessage = function Promise$_Scheduler() {
  3875. var fn = queuedFn;
  3876. queuedFn = void 0;
  3877. fn();
  3878. };
  3879. return function Promise$_Scheduler(fn) {
  3880. queuedFn = fn;
  3881. channel.port2.postMessage(null);
  3882. };
  3883. })();
  3884. }
  3885. else if (global.setTimeout) {
  3886. schedule = function Promise$_Scheduler(fn) {
  3887. setTimeout(fn, 4);
  3888. };
  3889. }
  3890. else {
  3891. schedule = function Promise$_Scheduler(fn) {
  3892. fn();
  3893. };
  3894. }
  3895. module.exports = schedule;
  3896. },{"./assert.js":2,"./global.js":16}],32:[function(require,module,exports){
  3897. /**
  3898. * Copyright (c) 2014 Petka Antonov
  3899. *
  3900. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3901. * of this software and associated documentation files (the "Software"), to deal
  3902. * in the Software without restriction, including without limitation the rights
  3903. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3904. * copies of the Software, and to permit persons to whom the Software is
  3905. * furnished to do so, subject to the following conditions:</p>
  3906. *
  3907. * The above copyright notice and this permission notice shall be included in
  3908. * all copies or substantial portions of the Software.
  3909. *
  3910. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3911. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3912. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3913. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3914. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3915. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3916. * THE SOFTWARE.
  3917. *
  3918. */
  3919. "use strict";
  3920. module.exports =
  3921. function(Promise, Promise$_CreatePromiseArray, PromiseArray) {
  3922. var SettledPromiseArray = require("./settled_promise_array.js")(
  3923. Promise, PromiseArray);
  3924. function Promise$_Settle(promises, useBound, caller) {
  3925. return Promise$_CreatePromiseArray(
  3926. promises,
  3927. SettledPromiseArray,
  3928. caller,
  3929. useBound === true && promises._isBound()
  3930. ? promises._boundTo
  3931. : void 0
  3932. ).promise();
  3933. }
  3934. Promise.settle = function Promise$Settle(promises) {
  3935. return Promise$_Settle(promises, false, Promise.settle);
  3936. };
  3937. Promise.prototype.settle = function Promise$settle() {
  3938. return Promise$_Settle(this, true, this.settle);
  3939. };
  3940. };
  3941. },{"./settled_promise_array.js":33}],33:[function(require,module,exports){
  3942. /**
  3943. * Copyright (c) 2014 Petka Antonov
  3944. *
  3945. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3946. * of this software and associated documentation files (the "Software"), to deal
  3947. * in the Software without restriction, including without limitation the rights
  3948. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3949. * copies of the Software, and to permit persons to whom the Software is
  3950. * furnished to do so, subject to the following conditions:</p>
  3951. *
  3952. * The above copyright notice and this permission notice shall be included in
  3953. * all copies or substantial portions of the Software.
  3954. *
  3955. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3956. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3957. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3958. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3959. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3960. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3961. * THE SOFTWARE.
  3962. *
  3963. */
  3964. "use strict";
  3965. module.exports = function(Promise, PromiseArray) {
  3966. var ASSERT = require("./assert.js");
  3967. var PromiseInspection = require("./promise_inspection.js");
  3968. var util = require("./util.js");
  3969. var inherits = util.inherits;
  3970. function SettledPromiseArray(values, caller, boundTo) {
  3971. this.constructor$(values, caller, boundTo);
  3972. }
  3973. inherits(SettledPromiseArray, PromiseArray);
  3974. SettledPromiseArray.prototype._promiseResolved =
  3975. function SettledPromiseArray$_promiseResolved(index, inspection) {
  3976. this._values[index] = inspection;
  3977. var totalResolved = ++this._totalResolved;
  3978. if (totalResolved >= this._length) {
  3979. this._resolve(this._values);
  3980. }
  3981. };
  3982. SettledPromiseArray.prototype._promiseFulfilled =
  3983. function SettledPromiseArray$_promiseFulfilled(value, index) {
  3984. if (this._isResolved()) return;
  3985. var ret = new PromiseInspection();
  3986. ret._bitField = 268435456;
  3987. ret._settledValue = value;
  3988. this._promiseResolved(index, ret);
  3989. };
  3990. SettledPromiseArray.prototype._promiseRejected =
  3991. function SettledPromiseArray$_promiseRejected(reason, index) {
  3992. if (this._isResolved()) return;
  3993. var ret = new PromiseInspection();
  3994. ret._bitField = 134217728;
  3995. ret._settledValue = reason;
  3996. this._promiseResolved(index, ret);
  3997. };
  3998. return SettledPromiseArray;
  3999. };
  4000. },{"./assert.js":2,"./promise_inspection.js":22,"./util.js":39}],34:[function(require,module,exports){
  4001. /**
  4002. * Copyright (c) 2014 Petka Antonov
  4003. *
  4004. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4005. * of this software and associated documentation files (the "Software"), to deal
  4006. * in the Software without restriction, including without limitation the rights
  4007. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4008. * copies of the Software, and to permit persons to whom the Software is
  4009. * furnished to do so, subject to the following conditions:</p>
  4010. *
  4011. * The above copyright notice and this permission notice shall be included in
  4012. * all copies or substantial portions of the Software.
  4013. *
  4014. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4015. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4016. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4017. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4018. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4019. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4020. * THE SOFTWARE.
  4021. *
  4022. */
  4023. "use strict";
  4024. module.exports =
  4025. function(Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection) {
  4026. var SomePromiseArray = require("./some_promise_array.js")(PromiseArray);
  4027. var ASSERT = require("./assert.js");
  4028. function Promise$_Some(promises, howMany, useBound, caller) {
  4029. if ((howMany | 0) !== howMany || howMany < 0) {
  4030. return apiRejection("expecting a positive integer");
  4031. }
  4032. var ret = Promise$_CreatePromiseArray(
  4033. promises,
  4034. SomePromiseArray,
  4035. caller,
  4036. useBound === true && promises._isBound()
  4037. ? promises._boundTo
  4038. : void 0
  4039. );
  4040. var promise = ret.promise();
  4041. if (promise.isRejected()) {
  4042. return promise;
  4043. }
  4044. ret.setHowMany(howMany);
  4045. ret.init();
  4046. return promise;
  4047. }
  4048. Promise.some = function Promise$Some(promises, howMany) {
  4049. return Promise$_Some(promises, howMany, false, Promise.some);
  4050. };
  4051. Promise.prototype.some = function Promise$some(count) {
  4052. return Promise$_Some(this, count, true, this.some);
  4053. };
  4054. };
  4055. },{"./assert.js":2,"./some_promise_array.js":35}],35:[function(require,module,exports){
  4056. /**
  4057. * Copyright (c) 2014 Petka Antonov
  4058. *
  4059. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4060. * of this software and associated documentation files (the "Software"), to deal
  4061. * in the Software without restriction, including without limitation the rights
  4062. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4063. * copies of the Software, and to permit persons to whom the Software is
  4064. * furnished to do so, subject to the following conditions:</p>
  4065. *
  4066. * The above copyright notice and this permission notice shall be included in
  4067. * all copies or substantial portions of the Software.
  4068. *
  4069. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4070. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4071. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4072. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4073. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4074. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4075. * THE SOFTWARE.
  4076. *
  4077. */
  4078. "use strict";
  4079. module.exports = function (PromiseArray) {
  4080. var util = require("./util.js");
  4081. var RangeError = require("./errors.js").RangeError;
  4082. var inherits = util.inherits;
  4083. var isArray = util.isArray;
  4084. function SomePromiseArray(values, caller, boundTo) {
  4085. this.constructor$(values, caller, boundTo);
  4086. this._howMany = 0;
  4087. this._unwrap = false;
  4088. this._initialized = false;
  4089. }
  4090. inherits(SomePromiseArray, PromiseArray);
  4091. SomePromiseArray.prototype._init = function SomePromiseArray$_init() {
  4092. if (!this._initialized) {
  4093. return;
  4094. }
  4095. if (this._howMany === 0) {
  4096. this._resolve([]);
  4097. return;
  4098. }
  4099. this._init$(void 0, -2);
  4100. var isArrayResolved = isArray(this._values);
  4101. this._holes = isArrayResolved ? this._values.length - this.length() : 0;
  4102. if (!this._isResolved() &&
  4103. isArrayResolved &&
  4104. this._howMany > this._canPossiblyFulfill()) {
  4105. var message = "(Promise.some) input array contains less than " +
  4106. this._howMany + " promises";
  4107. this._reject(new RangeError(message));
  4108. }
  4109. };
  4110. SomePromiseArray.prototype.init = function SomePromiseArray$init() {
  4111. this._initialized = true;
  4112. this._init();
  4113. };
  4114. SomePromiseArray.prototype.setUnwrap = function SomePromiseArray$setUnwrap() {
  4115. this._unwrap = true;
  4116. };
  4117. SomePromiseArray.prototype.howMany = function SomePromiseArray$howMany() {
  4118. return this._howMany;
  4119. };
  4120. SomePromiseArray.prototype.setHowMany =
  4121. function SomePromiseArray$setHowMany(count) {
  4122. if (this._isResolved()) return;
  4123. this._howMany = count;
  4124. };
  4125. SomePromiseArray.prototype._promiseFulfilled =
  4126. function SomePromiseArray$_promiseFulfilled(value) {
  4127. if (this._isResolved()) return;
  4128. this._addFulfilled(value);
  4129. if (this._fulfilled() === this.howMany()) {
  4130. this._values.length = this.howMany();
  4131. if (this.howMany() === 1 && this._unwrap) {
  4132. this._resolve(this._values[0]);
  4133. }
  4134. else {
  4135. this._resolve(this._values);
  4136. }
  4137. }
  4138. };
  4139. SomePromiseArray.prototype._promiseRejected =
  4140. function SomePromiseArray$_promiseRejected(reason) {
  4141. if (this._isResolved()) return;
  4142. this._addRejected(reason);
  4143. if (this.howMany() > this._canPossiblyFulfill()) {
  4144. if (this._values.length === this.length()) {
  4145. this._reject([]);
  4146. }
  4147. else {
  4148. this._reject(this._values.slice(this.length() + this._holes));
  4149. }
  4150. }
  4151. };
  4152. SomePromiseArray.prototype._fulfilled = function SomePromiseArray$_fulfilled() {
  4153. return this._totalResolved;
  4154. };
  4155. SomePromiseArray.prototype._rejected = function SomePromiseArray$_rejected() {
  4156. return this._values.length - this.length() - this._holes;
  4157. };
  4158. SomePromiseArray.prototype._addRejected =
  4159. function SomePromiseArray$_addRejected(reason) {
  4160. this._values.push(reason);
  4161. };
  4162. SomePromiseArray.prototype._addFulfilled =
  4163. function SomePromiseArray$_addFulfilled(value) {
  4164. this._values[this._totalResolved++] = value;
  4165. };
  4166. SomePromiseArray.prototype._canPossiblyFulfill =
  4167. function SomePromiseArray$_canPossiblyFulfill() {
  4168. return this.length() - this._rejected();
  4169. };
  4170. return SomePromiseArray;
  4171. };
  4172. },{"./errors.js":10,"./util.js":39}],36:[function(require,module,exports){
  4173. /**
  4174. * Copyright (c) 2014 Petka Antonov
  4175. *
  4176. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4177. * of this software and associated documentation files (the "Software"), to deal
  4178. * in the Software without restriction, including without limitation the rights
  4179. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4180. * copies of the Software, and to permit persons to whom the Software is
  4181. * furnished to do so, subject to the following conditions:</p>
  4182. *
  4183. * The above copyright notice and this permission notice shall be included in
  4184. * all copies or substantial portions of the Software.
  4185. *
  4186. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4187. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4188. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4189. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4190. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4191. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4192. * THE SOFTWARE.
  4193. *
  4194. */
  4195. "use strict";
  4196. module.exports = function(Promise) {
  4197. var PromiseInspection = require("./promise_inspection.js");
  4198. Promise.prototype.inspect = function Promise$inspect() {
  4199. return new PromiseInspection(this);
  4200. };
  4201. };
  4202. },{"./promise_inspection.js":22}],37:[function(require,module,exports){
  4203. /**
  4204. * Copyright (c) 2014 Petka Antonov
  4205. *
  4206. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4207. * of this software and associated documentation files (the "Software"), to deal
  4208. * in the Software without restriction, including without limitation the rights
  4209. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4210. * copies of the Software, and to permit persons to whom the Software is
  4211. * furnished to do so, subject to the following conditions:</p>
  4212. *
  4213. * The above copyright notice and this permission notice shall be included in
  4214. * all copies or substantial portions of the Software.
  4215. *
  4216. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4217. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4218. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4219. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4220. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4221. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4222. * THE SOFTWARE.
  4223. *
  4224. */
  4225. "use strict";
  4226. module.exports = function(Promise, INTERNAL) {
  4227. var ASSERT = require("./assert.js");
  4228. var util = require("./util.js");
  4229. var canAttach = require("./errors.js").canAttach;
  4230. var errorObj = util.errorObj;
  4231. var isObject = util.isObject;
  4232. function getThen(obj) {
  4233. try {
  4234. return obj.then;
  4235. }
  4236. catch(e) {
  4237. errorObj.e = e;
  4238. return errorObj;
  4239. }
  4240. }
  4241. function Promise$_Cast(obj, caller, originalPromise) {
  4242. if (isObject(obj)) {
  4243. if (obj instanceof Promise) {
  4244. return obj;
  4245. }
  4246. else if (isAnyBluebirdPromise(obj)) {
  4247. var ret = new Promise(INTERNAL);
  4248. ret._setTrace(caller, void 0);
  4249. obj._then(
  4250. ret._fulfillUnchecked,
  4251. ret._rejectUncheckedCheckError,
  4252. ret._progressUnchecked,
  4253. ret,
  4254. null,
  4255. void 0
  4256. );
  4257. ret._setFollowing();
  4258. return ret;
  4259. }
  4260. var then = getThen(obj);
  4261. if (then === errorObj) {
  4262. caller = typeof caller === "function" ? caller : Promise$_Cast;
  4263. if (originalPromise !== void 0 && canAttach(then.e)) {
  4264. originalPromise._attachExtraTrace(then.e);
  4265. }
  4266. return Promise.reject(then.e, caller);
  4267. }
  4268. else if (typeof then === "function") {
  4269. caller = typeof caller === "function" ? caller : Promise$_Cast;
  4270. return Promise$_doThenable(obj, then, caller, originalPromise);
  4271. }
  4272. }
  4273. return obj;
  4274. }
  4275. var hasProp = {}.hasOwnProperty;
  4276. function isAnyBluebirdPromise(obj) {
  4277. return hasProp.call(obj, "_promise0");
  4278. }
  4279. function Promise$_doThenable(x, then, caller, originalPromise) {
  4280. var resolver = Promise.defer(caller);
  4281. var called = false;
  4282. try {
  4283. then.call(
  4284. x,
  4285. Promise$_resolveFromThenable,
  4286. Promise$_rejectFromThenable,
  4287. Promise$_progressFromThenable
  4288. );
  4289. }
  4290. catch(e) {
  4291. if (!called) {
  4292. called = true;
  4293. var trace = canAttach(e) ? e : new Error(e + "");
  4294. if (originalPromise !== void 0) {
  4295. originalPromise._attachExtraTrace(trace);
  4296. }
  4297. resolver.promise._reject(e, trace);
  4298. }
  4299. }
  4300. return resolver.promise;
  4301. function Promise$_resolveFromThenable(y) {
  4302. if (called) return;
  4303. called = true;
  4304. if (x === y) {
  4305. var e = Promise._makeSelfResolutionError();
  4306. if (originalPromise !== void 0) {
  4307. originalPromise._attachExtraTrace(e);
  4308. }
  4309. resolver.promise._reject(e, void 0);
  4310. return;
  4311. }
  4312. resolver.resolve(y);
  4313. }
  4314. function Promise$_rejectFromThenable(r) {
  4315. if (called) return;
  4316. called = true;
  4317. var trace = canAttach(r) ? r : new Error(r + "");
  4318. if (originalPromise !== void 0) {
  4319. originalPromise._attachExtraTrace(trace);
  4320. }
  4321. resolver.promise._reject(r, trace);
  4322. }
  4323. function Promise$_progressFromThenable(v) {
  4324. if (called) return;
  4325. var promise = resolver.promise;
  4326. if (typeof promise._progress === "function") {
  4327. promise._progress(v);
  4328. }
  4329. }
  4330. }
  4331. Promise._cast = Promise$_Cast;
  4332. };
  4333. },{"./assert.js":2,"./errors.js":10,"./util.js":39}],38:[function(require,module,exports){
  4334. /**
  4335. * Copyright (c) 2014 Petka Antonov
  4336. *
  4337. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4338. * of this software and associated documentation files (the "Software"), to deal
  4339. * in the Software without restriction, including without limitation the rights
  4340. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4341. * copies of the Software, and to permit persons to whom the Software is
  4342. * furnished to do so, subject to the following conditions:</p>
  4343. *
  4344. * The above copyright notice and this permission notice shall be included in
  4345. * all copies or substantial portions of the Software.
  4346. *
  4347. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4348. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4349. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4350. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4351. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4352. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4353. * THE SOFTWARE.
  4354. *
  4355. */
  4356. "use strict";
  4357. var global = require("./global.js");
  4358. var setTimeout = function(fn, time) {
  4359. var $_len = arguments.length;var args = new Array($_len - 2); for(var $_i = 2; $_i < $_len; ++$_i) {args[$_i - 2] = arguments[$_i];}
  4360. global.setTimeout(function() {
  4361. fn.apply(void 0, args);
  4362. }, time);
  4363. };
  4364. var pass = {};
  4365. global.setTimeout( function(_) {
  4366. if(_ === pass) {
  4367. setTimeout = global.setTimeout;
  4368. }
  4369. }, 1, pass);
  4370. module.exports = function(Promise, INTERNAL) {
  4371. var util = require("./util.js");
  4372. var ASSERT = require("./assert.js");
  4373. var errors = require("./errors.js");
  4374. var apiRejection = require("./errors_api_rejection")(Promise);
  4375. var TimeoutError = Promise.TimeoutError;
  4376. var afterTimeout = function Promise$_afterTimeout(promise, message, ms) {
  4377. if (!promise.isPending()) return;
  4378. if (typeof message !== "string") {
  4379. message = "operation timed out after" + " " + ms + " ms"
  4380. }
  4381. var err = new TimeoutError(message);
  4382. errors.markAsOriginatingFromRejection(err);
  4383. promise._attachExtraTrace(err);
  4384. promise._rejectUnchecked(err);
  4385. };
  4386. var afterDelay = function Promise$_afterDelay(value, promise) {
  4387. promise._fulfill(value);
  4388. };
  4389. Promise.delay = function Promise$Delay(value, ms, caller) {
  4390. if (ms === void 0) {
  4391. ms = value;
  4392. value = void 0;
  4393. }
  4394. ms = +ms;
  4395. if (typeof caller !== "function") {
  4396. caller = Promise.delay;
  4397. }
  4398. var maybePromise = Promise._cast(value, caller, void 0);
  4399. var promise = new Promise(INTERNAL);
  4400. if (Promise.is(maybePromise)) {
  4401. if (maybePromise._isBound()) {
  4402. promise._setBoundTo(maybePromise._boundTo);
  4403. }
  4404. if (maybePromise._cancellable()) {
  4405. promise._setCancellable();
  4406. promise._cancellationParent = maybePromise;
  4407. }
  4408. promise._setTrace(caller, maybePromise);
  4409. promise._follow(maybePromise);
  4410. return promise.then(function(value) {
  4411. return Promise.delay(value, ms);
  4412. });
  4413. }
  4414. else {
  4415. promise._setTrace(caller, void 0);
  4416. setTimeout(afterDelay, ms, value, promise);
  4417. }
  4418. return promise;
  4419. };
  4420. Promise.prototype.delay = function Promise$delay(ms) {
  4421. return Promise.delay(this, ms, this.delay);
  4422. };
  4423. Promise.prototype.timeout = function Promise$timeout(ms, message) {
  4424. ms = +ms;
  4425. var ret = new Promise(INTERNAL);
  4426. ret._setTrace(this.timeout, this);
  4427. if (this._isBound()) ret._setBoundTo(this._boundTo);
  4428. if (this._cancellable()) {
  4429. ret._setCancellable();
  4430. ret._cancellationParent = this;
  4431. }
  4432. ret._follow(this);
  4433. setTimeout(afterTimeout, ms, ret, message, ms);
  4434. return ret;
  4435. };
  4436. };
  4437. },{"./assert.js":2,"./errors.js":10,"./errors_api_rejection":11,"./global.js":16,"./util.js":39}],39:[function(require,module,exports){
  4438. /**
  4439. * Copyright (c) 2014 Petka Antonov
  4440. *
  4441. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4442. * of this software and associated documentation files (the "Software"), to deal
  4443. * in the Software without restriction, including without limitation the rights
  4444. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4445. * copies of the Software, and to permit persons to whom the Software is
  4446. * furnished to do so, subject to the following conditions:</p>
  4447. *
  4448. * The above copyright notice and this permission notice shall be included in
  4449. * all copies or substantial portions of the Software.
  4450. *
  4451. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4452. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4453. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4454. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4455. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4456. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4457. * THE SOFTWARE.
  4458. *
  4459. */
  4460. "use strict";
  4461. var global = require("./global.js");
  4462. var ASSERT = require("./assert.js");
  4463. var es5 = require("./es5.js");
  4464. var haveGetters = (function(){
  4465. try {
  4466. var o = {};
  4467. es5.defineProperty(o, "f", {
  4468. get: function () {
  4469. return 3;
  4470. }
  4471. });
  4472. return o.f === 3;
  4473. }
  4474. catch (e) {
  4475. return false;
  4476. }
  4477. })();
  4478. var canEvaluate = (function() {
  4479. if (typeof window !== "undefined" && window !== null &&
  4480. typeof window.document !== "undefined" &&
  4481. typeof navigator !== "undefined" && navigator !== null &&
  4482. typeof navigator.appName === "string" &&
  4483. window === global) {
  4484. return false;
  4485. }
  4486. return true;
  4487. })();
  4488. function deprecated(msg) {
  4489. if (typeof console !== "undefined" && console !== null &&
  4490. typeof console.warn === "function") {
  4491. console.warn("Bluebird: " + msg);
  4492. }
  4493. }
  4494. var errorObj = {e: {}};
  4495. function tryCatch1(fn, receiver, arg) {
  4496. try {
  4497. return fn.call(receiver, arg);
  4498. }
  4499. catch (e) {
  4500. errorObj.e = e;
  4501. return errorObj;
  4502. }
  4503. }
  4504. function tryCatch2(fn, receiver, arg, arg2) {
  4505. try {
  4506. return fn.call(receiver, arg, arg2);
  4507. }
  4508. catch (e) {
  4509. errorObj.e = e;
  4510. return errorObj;
  4511. }
  4512. }
  4513. function tryCatchApply(fn, args, receiver) {
  4514. try {
  4515. return fn.apply(receiver, args);
  4516. }
  4517. catch (e) {
  4518. errorObj.e = e;
  4519. return errorObj;
  4520. }
  4521. }
  4522. var inherits = function(Child, Parent) {
  4523. var hasProp = {}.hasOwnProperty;
  4524. function T() {
  4525. this.constructor = Child;
  4526. this.constructor$ = Parent;
  4527. for (var propertyName in Parent.prototype) {
  4528. if (hasProp.call(Parent.prototype, propertyName) &&
  4529. propertyName.charAt(propertyName.length-1) !== "$"
  4530. ) {
  4531. this[propertyName + "$"] = Parent.prototype[propertyName];
  4532. }
  4533. }
  4534. }
  4535. T.prototype = Parent.prototype;
  4536. Child.prototype = new T();
  4537. return Child.prototype;
  4538. };
  4539. function asString(val) {
  4540. return typeof val === "string" ? val : ("" + val);
  4541. }
  4542. function isPrimitive(val) {
  4543. return val == null || val === true || val === false ||
  4544. typeof val === "string" || typeof val === "number";
  4545. }
  4546. function isObject(value) {
  4547. return !isPrimitive(value);
  4548. }
  4549. function maybeWrapAsError(maybeError) {
  4550. if (!isPrimitive(maybeError)) return maybeError;
  4551. return new Error(asString(maybeError));
  4552. }
  4553. function withAppended(target, appendee) {
  4554. var len = target.length;
  4555. var ret = new Array(len + 1);
  4556. var i;
  4557. for (i = 0; i < len; ++i) {
  4558. ret[i] = target[i];
  4559. }
  4560. ret[i] = appendee;
  4561. return ret;
  4562. }
  4563. function notEnumerableProp(obj, name, value) {
  4564. var descriptor = {
  4565. value: value,
  4566. configurable: true,
  4567. enumerable: false,
  4568. writable: true
  4569. };
  4570. es5.defineProperty(obj, name, descriptor);
  4571. return obj;
  4572. }
  4573. var wrapsPrimitiveReceiver = (function() {
  4574. return this !== "string";
  4575. }).call("string");
  4576. function thrower(r) {
  4577. throw r;
  4578. }
  4579. var ret = {
  4580. thrower: thrower,
  4581. isArray: es5.isArray,
  4582. haveGetters: haveGetters,
  4583. notEnumerableProp: notEnumerableProp,
  4584. isPrimitive: isPrimitive,
  4585. isObject: isObject,
  4586. canEvaluate: canEvaluate,
  4587. deprecated: deprecated,
  4588. errorObj: errorObj,
  4589. tryCatch1: tryCatch1,
  4590. tryCatch2: tryCatch2,
  4591. tryCatchApply: tryCatchApply,
  4592. inherits: inherits,
  4593. withAppended: withAppended,
  4594. asString: asString,
  4595. maybeWrapAsError: maybeWrapAsError,
  4596. wrapsPrimitiveReceiver: wrapsPrimitiveReceiver
  4597. };
  4598. module.exports = ret;
  4599. },{"./assert.js":2,"./es5.js":12,"./global.js":16}]},{},[4])
  4600. (4)
  4601. });
  4602. ;