1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140 |
- /**
- * bluebird build version 1.0.8
- * Features enabled: core, timers, race, any, call_get, filter, generators, map, nodeify, promisify, props, reduce, settle, some, progress, cancel, synchronous_inspection
- */
- /**
- * @preserve Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- !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){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise, Promise$_CreatePromiseArray, PromiseArray) {
- var SomePromiseArray = require("./some_promise_array.js")(PromiseArray);
- var ASSERT = require("./assert.js");
- function Promise$_Any(promises, useBound, caller) {
- var ret = Promise$_CreatePromiseArray(
- promises,
- SomePromiseArray,
- caller,
- useBound === true && promises._isBound()
- ? promises._boundTo
- : void 0
- );
- var promise = ret.promise();
- if (promise.isRejected()) {
- return promise;
- }
- ret.setHowMany(1);
- ret.setUnwrap();
- ret.init();
- return promise;
- }
- Promise.any = function Promise$Any(promises) {
- return Promise$_Any(promises, false, Promise.any);
- };
- Promise.prototype.any = function Promise$any() {
- return Promise$_Any(this, true, this.any);
- };
- };
- },{"./assert.js":2,"./some_promise_array.js":35}],2:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = (function(){
- var AssertionError = (function() {
- function AssertionError(a) {
- this.constructor$(a);
- this.message = a;
- this.name = "AssertionError";
- }
- AssertionError.prototype = new Error();
- AssertionError.prototype.constructor = AssertionError;
- AssertionError.prototype.constructor$ = Error;
- return AssertionError;
- })();
- return function assert(boolExpr, message) {
- if (boolExpr === true) return;
- var ret = new AssertionError(message);
- if (Error.captureStackTrace) {
- Error.captureStackTrace(ret, assert);
- }
- if (console && console.error) {
- console.error(ret.stack + "");
- }
- throw ret;
- };
- })();
- },{}],3:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- var ASSERT = require("./assert.js");
- var schedule = require("./schedule.js");
- var Queue = require("./queue.js");
- var errorObj = require("./util.js").errorObj;
- var tryCatch1 = require("./util.js").tryCatch1;
- function Async() {
- this._isTickUsed = false;
- this._length = 0;
- this._lateBuffer = new Queue();
- this._functionBuffer = new Queue(25000 * 3);
- var self = this;
- this.consumeFunctionBuffer = function Async$consumeFunctionBuffer() {
- self._consumeFunctionBuffer();
- };
- }
- Async.prototype.haveItemsQueued = function Async$haveItemsQueued() {
- return this._length > 0;
- };
- Async.prototype.invokeLater = function Async$invokeLater(fn, receiver, arg) {
- this._lateBuffer.push(fn, receiver, arg);
- this._queueTick();
- };
- Async.prototype.invoke = function Async$invoke(fn, receiver, arg) {
- var functionBuffer = this._functionBuffer;
- functionBuffer.push(fn, receiver, arg);
- this._length = functionBuffer.length();
- this._queueTick();
- };
- Async.prototype._consumeFunctionBuffer =
- function Async$_consumeFunctionBuffer() {
- var functionBuffer = this._functionBuffer;
- while(functionBuffer.length() > 0) {
- var fn = functionBuffer.shift();
- var receiver = functionBuffer.shift();
- var arg = functionBuffer.shift();
- fn.call(receiver, arg);
- }
- this._reset();
- this._consumeLateBuffer();
- };
- Async.prototype._consumeLateBuffer = function Async$_consumeLateBuffer() {
- var buffer = this._lateBuffer;
- while(buffer.length() > 0) {
- var fn = buffer.shift();
- var receiver = buffer.shift();
- var arg = buffer.shift();
- var res = tryCatch1(fn, receiver, arg);
- if (res === errorObj) {
- this._queueTick();
- throw res.e;
- }
- }
- };
- Async.prototype._queueTick = function Async$_queue() {
- if (!this._isTickUsed) {
- schedule(this.consumeFunctionBuffer);
- this._isTickUsed = true;
- }
- };
- Async.prototype._reset = function Async$_reset() {
- this._isTickUsed = false;
- this._length = 0;
- };
- module.exports = new Async();
- },{"./assert.js":2,"./queue.js":28,"./schedule.js":31,"./util.js":39}],4:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- var Promise = require("./promise.js")();
- module.exports = Promise;
- },{"./promise.js":20}],5:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise) {
- Promise.prototype.call = function Promise$call(propertyName) {
- var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
- return this._then(function(obj) {
- return obj[propertyName].apply(obj, args);
- },
- void 0,
- void 0,
- void 0,
- void 0,
- this.call
- );
- };
- function Promise$getter(obj) {
- var prop = typeof this === "string"
- ? this
- : ("" + this);
- return obj[prop];
- }
- Promise.prototype.get = function Promise$get(propertyName) {
- return this._then(
- Promise$getter,
- void 0,
- void 0,
- propertyName,
- void 0,
- this.get
- );
- };
- };
- },{}],6:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var errors = require("./errors.js");
- var async = require("./async.js");
- var ASSERT = require("./assert.js");
- var CancellationError = errors.CancellationError;
- var SYNC_TOKEN = {};
- Promise.prototype._cancel = function Promise$_cancel() {
- if (!this.isCancellable()) return this;
- var parent;
- if ((parent = this._cancellationParent) !== void 0 &&
- parent.isCancellable()) {
- parent.cancel(SYNC_TOKEN);
- return;
- }
- var err = new CancellationError();
- this._attachExtraTrace(err);
- this._rejectUnchecked(err);
- };
- Promise.prototype.cancel = function Promise$cancel(token) {
- if (!this.isCancellable()) return this;
- if (token === SYNC_TOKEN) {
- this._cancel();
- return this;
- }
- async.invokeLater(this._cancel, this, void 0);
- return this;
- };
- Promise.prototype.cancellable = function Promise$cancellable() {
- if (this._cancellable()) return this;
- this._setCancellable();
- this._cancellationParent = void 0;
- return this;
- };
- Promise.prototype.uncancellable = function Promise$uncancellable() {
- var ret = new Promise(INTERNAL);
- ret._setTrace(this.uncancellable, this);
- ret._follow(this);
- ret._unsetCancellable();
- if (this._isBound()) ret._setBoundTo(this._boundTo);
- return ret;
- };
- Promise.prototype.fork =
- function Promise$fork(didFulfill, didReject, didProgress) {
- var ret = this._then(didFulfill, didReject, didProgress,
- void 0, void 0, this.fork);
- ret._setCancellable();
- ret._cancellationParent = void 0;
- return ret;
- };
- };
- },{"./assert.js":2,"./async.js":3,"./errors.js":10}],7:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function() {
- var ASSERT = require("./assert.js");
- var inherits = require("./util.js").inherits;
- var defineProperty = require("./es5.js").defineProperty;
- var rignore = new RegExp(
- "\\b(?:[\\w.]*Promise(?:Array|Spawn)?\\$_\\w+|" +
- "tryCatch(?:1|2|Apply)|new \\w*PromiseArray|" +
- "\\w*PromiseArray\\.\\w*PromiseArray|" +
- "setTimeout|CatchFilter\\$_\\w+|makeNodePromisified|processImmediate|" +
- "process._tickCallback|nextTick|Async\\$\\w+)\\b"
- );
- var rtraceline = null;
- var formatStack = null;
- var areNamesMangled = false;
- function formatNonError(obj) {
- var str;
- if (typeof obj === "function") {
- str = "[function " +
- (obj.name || "anonymous") +
- "]";
- }
- else {
- str = obj.toString();
- var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
- if (ruselessToString.test(str)) {
- try {
- var newStr = JSON.stringify(obj);
- str = newStr;
- }
- catch(e) {
- }
- }
- if (str.length === 0) {
- str = "(empty array)";
- }
- }
- return ("(<" + snip(str) + ">, no stack trace)");
- }
- function snip(str) {
- var maxChars = 41;
- if (str.length < maxChars) {
- return str;
- }
- return str.substr(0, maxChars - 3) + "...";
- }
- function CapturedTrace(ignoreUntil, isTopLevel) {
- if (!areNamesMangled) {
- }
- this.captureStackTrace(ignoreUntil, isTopLevel);
- }
- inherits(CapturedTrace, Error);
- CapturedTrace.prototype.captureStackTrace =
- function CapturedTrace$captureStackTrace(ignoreUntil, isTopLevel) {
- captureStackTrace(this, ignoreUntil, isTopLevel);
- };
- CapturedTrace.possiblyUnhandledRejection =
- function CapturedTrace$PossiblyUnhandledRejection(reason) {
- if (typeof console === "object") {
- var message;
- if (typeof reason === "object" || typeof reason === "function") {
- var stack = reason.stack;
- message = "Possibly unhandled " + formatStack(stack, reason);
- }
- else {
- message = "Possibly unhandled " + String(reason);
- }
- if (typeof console.error === "function" ||
- typeof console.error === "object") {
- console.error(message);
- }
- else if (typeof console.log === "function" ||
- typeof console.error === "object") {
- console.log(message);
- }
- }
- };
- areNamesMangled = CapturedTrace.prototype.captureStackTrace.name !==
- "CapturedTrace$captureStackTrace";
- CapturedTrace.combine = function CapturedTrace$Combine(current, prev) {
- var curLast = current.length - 1;
- for (var i = prev.length - 1; i >= 0; --i) {
- var line = prev[i];
- if (current[curLast] === line) {
- current.pop();
- curLast--;
- }
- else {
- break;
- }
- }
- current.push("From previous event:");
- var lines = current.concat(prev);
- var ret = [];
- for (var i = 0, len = lines.length; i < len; ++i) {
- if ((rignore.test(lines[i]) ||
- (i > 0 && !rtraceline.test(lines[i])) &&
- lines[i] !== "From previous event:")
- ) {
- continue;
- }
- ret.push(lines[i]);
- }
- return ret;
- };
- CapturedTrace.isSupported = function CapturedTrace$IsSupported() {
- return typeof captureStackTrace === "function";
- };
- var captureStackTrace = (function stackDetection() {
- if (typeof Error.stackTraceLimit === "number" &&
- typeof Error.captureStackTrace === "function") {
- rtraceline = /^\s*at\s*/;
- formatStack = function(stack, error) {
- if (typeof stack === "string") return stack;
- if (error.name !== void 0 &&
- error.message !== void 0) {
- return error.name + ". " + error.message;
- }
- return formatNonError(error);
- };
- var captureStackTrace = Error.captureStackTrace;
- return function CapturedTrace$_captureStackTrace(
- receiver, ignoreUntil) {
- captureStackTrace(receiver, ignoreUntil);
- };
- }
- var err = new Error();
- if (!areNamesMangled && typeof err.stack === "string" &&
- typeof "".startsWith === "function" &&
- (err.stack.startsWith("stackDetection@")) &&
- stackDetection.name === "stackDetection") {
- defineProperty(Error, "stackTraceLimit", {
- writable: true,
- enumerable: false,
- configurable: false,
- value: 25
- });
- rtraceline = /@/;
- var rline = /[@\n]/;
- formatStack = function(stack, error) {
- if (typeof stack === "string") {
- return (error.name + ". " + error.message + "\n" + stack);
- }
- if (error.name !== void 0 &&
- error.message !== void 0) {
- return error.name + ". " + error.message;
- }
- return formatNonError(error);
- };
- return function captureStackTrace(o, fn) {
- var name = fn.name;
- var stack = new Error().stack;
- var split = stack.split(rline);
- var i, len = split.length;
- for (i = 0; i < len; i += 2) {
- if (split[i] === name) {
- break;
- }
- }
- split = split.slice(i + 2);
- len = split.length - 2;
- var ret = "";
- for (i = 0; i < len; i += 2) {
- ret += split[i];
- ret += "@";
- ret += split[i + 1];
- ret += "\n";
- }
- o.stack = ret;
- };
- }
- else {
- formatStack = function(stack, error) {
- if (typeof stack === "string") return stack;
- if ((typeof error === "object" ||
- typeof error === "function") &&
- error.name !== void 0 &&
- error.message !== void 0) {
- return error.name + ". " + error.message;
- }
- return formatNonError(error);
- };
- return null;
- }
- })();
- return CapturedTrace;
- };
- },{"./assert.js":2,"./es5.js":12,"./util.js":39}],8:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(NEXT_FILTER) {
- var util = require("./util.js");
- var errors = require("./errors.js");
- var tryCatch1 = util.tryCatch1;
- var errorObj = util.errorObj;
- var keys = require("./es5.js").keys;
- function CatchFilter(instances, callback, promise) {
- this._instances = instances;
- this._callback = callback;
- this._promise = promise;
- }
- function CatchFilter$_safePredicate(predicate, e) {
- var safeObject = {};
- var retfilter = tryCatch1(predicate, safeObject, e);
- if (retfilter === errorObj) return retfilter;
- var safeKeys = keys(safeObject);
- if (safeKeys.length) {
- errorObj.e = new TypeError(
- "Catch filter must inherit from Error "
- + "or be a simple predicate function");
- return errorObj;
- }
- return retfilter;
- }
- CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) {
- var cb = this._callback;
- var promise = this._promise;
- var boundTo = promise._isBound() ? promise._boundTo : void 0;
- for (var i = 0, len = this._instances.length; i < len; ++i) {
- var item = this._instances[i];
- var itemIsErrorType = item === Error ||
- (item != null && item.prototype instanceof Error);
- if (itemIsErrorType && e instanceof item) {
- var ret = tryCatch1(cb, boundTo, e);
- if (ret === errorObj) {
- NEXT_FILTER.e = ret.e;
- return NEXT_FILTER;
- }
- return ret;
- } else if (typeof item === "function" && !itemIsErrorType) {
- var shouldHandle = CatchFilter$_safePredicate(item, e);
- if (shouldHandle === errorObj) {
- var trace = errors.canAttach(errorObj.e)
- ? errorObj.e
- : new Error(errorObj.e + "");
- this._promise._attachExtraTrace(trace);
- e = errorObj.e;
- break;
- } else if (shouldHandle) {
- var ret = tryCatch1(cb, boundTo, e);
- if (ret === errorObj) {
- NEXT_FILTER.e = ret.e;
- return NEXT_FILTER;
- }
- return ret;
- }
- }
- }
- NEXT_FILTER.e = e;
- return NEXT_FILTER;
- };
- return CatchFilter;
- };
- },{"./errors.js":10,"./es5.js":12,"./util.js":39}],9:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- var util = require("./util.js");
- var ASSERT = require("./assert.js");
- var isPrimitive = util.isPrimitive;
- var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
- module.exports = function(Promise) {
- var returner = function Promise$_returner() {
- return this;
- };
- var thrower = function Promise$_thrower() {
- throw this;
- };
- var wrapper = function Promise$_wrapper(value, action) {
- if (action === 1) {
- return function Promise$_thrower() {
- throw value;
- };
- }
- else if (action === 2) {
- return function Promise$_returner() {
- return value;
- };
- }
- };
- Promise.prototype["return"] =
- Promise.prototype.thenReturn =
- function Promise$thenReturn(value) {
- if (wrapsPrimitiveReceiver && isPrimitive(value)) {
- return this._then(
- wrapper(value, 2),
- void 0,
- void 0,
- void 0,
- void 0,
- this.thenReturn
- );
- }
- return this._then(returner, void 0, void 0,
- value, void 0, this.thenReturn);
- };
- Promise.prototype["throw"] =
- Promise.prototype.thenThrow =
- function Promise$thenThrow(reason) {
- if (wrapsPrimitiveReceiver && isPrimitive(reason)) {
- return this._then(
- wrapper(reason, 1),
- void 0,
- void 0,
- void 0,
- void 0,
- this.thenThrow
- );
- }
- return this._then(thrower, void 0, void 0,
- reason, void 0, this.thenThrow);
- };
- };
- },{"./assert.js":2,"./util.js":39}],10:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- var global = require("./global.js");
- var Objectfreeze = require("./es5.js").freeze;
- var util = require("./util.js");
- var inherits = util.inherits;
- var notEnumerableProp = util.notEnumerableProp;
- var Error = global.Error;
- function markAsOriginatingFromRejection(e) {
- try {
- notEnumerableProp(e, "isAsync", true);
- }
- catch(ignore) {}
- }
- function originatesFromRejection(e) {
- if (e == null) return false;
- return ((e instanceof RejectionError) ||
- e["isAsync"] === true);
- }
- function isError(obj) {
- return obj instanceof Error;
- }
- function canAttach(obj) {
- return isError(obj);
- }
- function subError(nameProperty, defaultMessage) {
- function SubError(message) {
- if (!(this instanceof SubError)) return new SubError(message);
- this.message = typeof message === "string" ? message : defaultMessage;
- this.name = nameProperty;
- if (Error.captureStackTrace) {
- Error.captureStackTrace(this, this.constructor);
- }
- }
- inherits(SubError, Error);
- return SubError;
- }
- var TypeError = global.TypeError;
- if (typeof TypeError !== "function") {
- TypeError = subError("TypeError", "type error");
- }
- var RangeError = global.RangeError;
- if (typeof RangeError !== "function") {
- RangeError = subError("RangeError", "range error");
- }
- var CancellationError = subError("CancellationError", "cancellation error");
- var TimeoutError = subError("TimeoutError", "timeout error");
- function RejectionError(message) {
- this.name = "RejectionError";
- this.message = message;
- this.cause = message;
- this.isAsync = true;
- if (message instanceof Error) {
- this.message = message.message;
- this.stack = message.stack;
- }
- else if (Error.captureStackTrace) {
- Error.captureStackTrace(this, this.constructor);
- }
- }
- inherits(RejectionError, Error);
- var key = "__BluebirdErrorTypes__";
- var errorTypes = global[key];
- if (!errorTypes) {
- errorTypes = Objectfreeze({
- CancellationError: CancellationError,
- TimeoutError: TimeoutError,
- RejectionError: RejectionError
- });
- notEnumerableProp(global, key, errorTypes);
- }
- module.exports = {
- Error: Error,
- TypeError: TypeError,
- RangeError: RangeError,
- CancellationError: errorTypes.CancellationError,
- RejectionError: errorTypes.RejectionError,
- TimeoutError: errorTypes.TimeoutError,
- originatesFromRejection: originatesFromRejection,
- markAsOriginatingFromRejection: markAsOriginatingFromRejection,
- canAttach: canAttach
- };
- },{"./es5.js":12,"./global.js":16,"./util.js":39}],11:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise) {
- var TypeError = require('./errors.js').TypeError;
- function apiRejection(msg) {
- var error = new TypeError(msg);
- var ret = Promise.rejected(error);
- var parent = ret._peekContext();
- if (parent != null) {
- parent._attachExtraTrace(error);
- }
- return ret;
- }
- return apiRejection;
- };
- },{"./errors.js":10}],12:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- var isES5 = (function(){
- "use strict";
- return this === void 0;
- })();
- if (isES5) {
- module.exports = {
- freeze: Object.freeze,
- defineProperty: Object.defineProperty,
- keys: Object.keys,
- getPrototypeOf: Object.getPrototypeOf,
- isArray: Array.isArray,
- isES5: isES5
- };
- }
- else {
- var has = {}.hasOwnProperty;
- var str = {}.toString;
- var proto = {}.constructor.prototype;
- function ObjectKeys(o) {
- var ret = [];
- for (var key in o) {
- if (has.call(o, key)) {
- ret.push(key);
- }
- }
- return ret;
- }
- function ObjectDefineProperty(o, key, desc) {
- o[key] = desc.value;
- return o;
- }
- function ObjectFreeze(obj) {
- return obj;
- }
- function ObjectGetPrototypeOf(obj) {
- try {
- return Object(obj).constructor.prototype;
- }
- catch (e) {
- return proto;
- }
- }
- function ArrayIsArray(obj) {
- try {
- return str.call(obj) === "[object Array]";
- }
- catch(e) {
- return false;
- }
- }
- module.exports = {
- isArray: ArrayIsArray,
- keys: ObjectKeys,
- defineProperty: ObjectDefineProperty,
- freeze: ObjectFreeze,
- getPrototypeOf: ObjectGetPrototypeOf,
- isES5: isES5
- };
- }
- },{}],13:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise) {
- var ASSERT = require("./assert.js");
- var isArray = require("./util.js").isArray;
- function Promise$_filter(booleans) {
- var values = this._settledValue;
- var len = values.length;
- var ret = new Array(len);
- var j = 0;
- for (var i = 0; i < len; ++i) {
- if (booleans[i]) ret[j++] = values[i];
- }
- ret.length = j;
- return ret;
- }
- var ref = {ref: null};
- Promise.filter = function Promise$Filter(promises, fn) {
- return Promise.map(promises, fn, ref)
- ._then(Promise$_filter, void 0, void 0,
- ref.ref, void 0, Promise.filter);
- };
- Promise.prototype.filter = function Promise$filter(fn) {
- return this.map(fn, ref)
- ._then(Promise$_filter, void 0, void 0,
- ref.ref, void 0, this.filter);
- };
- };
- },{"./assert.js":2,"./util.js":39}],14:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- module.exports = function(Promise, NEXT_FILTER) {
- var util = require("./util.js");
- var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
- var isPrimitive = util.isPrimitive;
- var thrower = util.thrower;
- function returnThis() {
- return this;
- }
- function throwThis() {
- throw this;
- }
- function makeReturner(r) {
- return function Promise$_returner() {
- return r;
- };
- }
- function makeThrower(r) {
- return function Promise$_thrower() {
- throw r;
- };
- }
- function promisedFinally(ret, reasonOrValue, isFulfilled) {
- var useConstantFunction =
- wrapsPrimitiveReceiver && isPrimitive(reasonOrValue);
- if (isFulfilled) {
- return ret._then(
- useConstantFunction
- ? returnThis
- : makeReturner(reasonOrValue),
- thrower, void 0, reasonOrValue, void 0, promisedFinally);
- }
- else {
- return ret._then(
- useConstantFunction
- ? throwThis
- : makeThrower(reasonOrValue),
- thrower, void 0, reasonOrValue, void 0, promisedFinally);
- }
- }
- function finallyHandler(reasonOrValue) {
- var promise = this.promise;
- var handler = this.handler;
- var ret = promise._isBound()
- ? handler.call(promise._boundTo)
- : handler();
- if (ret !== void 0) {
- var maybePromise = Promise._cast(ret, finallyHandler, void 0);
- if (Promise.is(maybePromise)) {
- return promisedFinally(maybePromise, reasonOrValue,
- promise.isFulfilled());
- }
- }
- if (promise.isRejected()) {
- NEXT_FILTER.e = reasonOrValue;
- return NEXT_FILTER;
- }
- else {
- return reasonOrValue;
- }
- }
- Promise.prototype.lastly = Promise.prototype["finally"] =
- function Promise$finally(handler) {
- if (typeof handler !== "function") return this.then();
- var promiseAndHandler = {
- promise: this,
- handler: handler
- };
- return this._then(finallyHandler, finallyHandler, void 0,
- promiseAndHandler, void 0, this.lastly);
- };
- };
- },{"./util.js":39}],15:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise, apiRejection, INTERNAL) {
- var PromiseSpawn = require("./promise_spawn.js")(Promise, INTERNAL);
- var errors = require("./errors.js");
- var TypeError = errors.TypeError;
- var deprecated = require("./util.js").deprecated;
- Promise.coroutine = function Promise$Coroutine(generatorFunction) {
- if (typeof generatorFunction !== "function") {
- throw new TypeError("generatorFunction must be a function");
- }
- var PromiseSpawn$ = PromiseSpawn;
- return function anonymous() {
- var generator = generatorFunction.apply(this, arguments);
- var spawn = new PromiseSpawn$(void 0, void 0, anonymous);
- spawn._generator = generator;
- spawn._next(void 0);
- return spawn.promise();
- };
- };
- Promise.coroutine.addYieldHandler = PromiseSpawn.addYieldHandler;
- Promise.spawn = function Promise$Spawn(generatorFunction) {
- deprecated("Promise.spawn is deprecated. Use Promise.coroutine instead.");
- if (typeof generatorFunction !== "function") {
- return apiRejection("generatorFunction must be a function");
- }
- var spawn = new PromiseSpawn(generatorFunction, this, Promise.spawn);
- var ret = spawn.promise();
- spawn._run(Promise.spawn);
- return ret;
- };
- };
- },{"./errors.js":10,"./promise_spawn.js":24,"./util.js":39}],16:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = (function(){
- if (typeof this !== "undefined") {
- return this;
- }
- if (typeof process !== "undefined" &&
- typeof global !== "undefined" &&
- typeof process.execPath === "string") {
- return global;
- }
- if (typeof window !== "undefined" &&
- typeof document !== "undefined" &&
- typeof navigator !== "undefined" && navigator !== null &&
- typeof navigator.appName === "string") {
- if(window.wrappedJSObject !== undefined){
- return window.wrappedJSObject;
- }
- return window;
- }
- })();
- },{}],17:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(
- Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection) {
- var ASSERT = require("./assert.js");
- function Promise$_mapper(values) {
- var fn = this;
- var receiver = void 0;
- if (typeof fn !== "function") {
- receiver = fn.receiver;
- fn = fn.fn;
- }
- var shouldDefer = false;
- var ret = new Array(values.length);
- if (receiver === void 0) {
- for (var i = 0, len = values.length; i < len; ++i) {
- var value = fn(values[i], i, len);
- if (!shouldDefer) {
- var maybePromise = Promise._cast(value,
- Promise$_mapper, void 0);
- if (maybePromise instanceof Promise) {
- if (maybePromise.isFulfilled()) {
- ret[i] = maybePromise._settledValue;
- continue;
- }
- else {
- shouldDefer = true;
- }
- value = maybePromise;
- }
- }
- ret[i] = value;
- }
- }
- else {
- for (var i = 0, len = values.length; i < len; ++i) {
- var value = fn.call(receiver, values[i], i, len);
- if (!shouldDefer) {
- var maybePromise = Promise._cast(value,
- Promise$_mapper, void 0);
- if (maybePromise instanceof Promise) {
- if (maybePromise.isFulfilled()) {
- ret[i] = maybePromise._settledValue;
- continue;
- }
- else {
- shouldDefer = true;
- }
- value = maybePromise;
- }
- }
- ret[i] = value;
- }
- }
- return shouldDefer
- ? Promise$_CreatePromiseArray(ret, PromiseArray,
- Promise$_mapper, void 0).promise()
- : ret;
- }
- function Promise$_Map(promises, fn, useBound, caller, ref) {
- if (typeof fn !== "function") {
- return apiRejection("fn must be a function");
- }
- if (useBound === true && promises._isBound()) {
- fn = {
- fn: fn,
- receiver: promises._boundTo
- };
- }
- var ret = Promise$_CreatePromiseArray(
- promises,
- PromiseArray,
- caller,
- useBound === true && promises._isBound()
- ? promises._boundTo
- : void 0
- ).promise();
- if (ref !== void 0) {
- ref.ref = ret;
- }
- return ret._then(
- Promise$_mapper,
- void 0,
- void 0,
- fn,
- void 0,
- caller
- );
- }
- Promise.prototype.map = function Promise$map(fn, ref) {
- return Promise$_Map(this, fn, true, this.map, ref);
- };
- Promise.map = function Promise$Map(promises, fn, ref) {
- return Promise$_Map(promises, fn, false, Promise.map, ref);
- };
- };
- },{"./assert.js":2}],18:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise) {
- var util = require("./util.js");
- var async = require("./async.js");
- var ASSERT = require("./assert.js");
- var tryCatch2 = util.tryCatch2;
- var tryCatch1 = util.tryCatch1;
- var errorObj = util.errorObj;
- function thrower(r) {
- throw r;
- }
- function Promise$_successAdapter(val, receiver) {
- var nodeback = this;
- var ret = tryCatch2(nodeback, receiver, null, val);
- if (ret === errorObj) {
- async.invokeLater(thrower, void 0, ret.e);
- }
- }
- function Promise$_errorAdapter(reason, receiver) {
- var nodeback = this;
- var ret = tryCatch1(nodeback, receiver, reason);
- if (ret === errorObj) {
- async.invokeLater(thrower, void 0, ret.e);
- }
- }
- Promise.prototype.nodeify = function Promise$nodeify(nodeback) {
- if (typeof nodeback == "function") {
- this._then(
- Promise$_successAdapter,
- Promise$_errorAdapter,
- void 0,
- nodeback,
- this._isBound() ? this._boundTo : null,
- this.nodeify
- );
- }
- return this;
- };
- };
- },{"./assert.js":2,"./async.js":3,"./util.js":39}],19:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise, isPromiseArrayProxy) {
- var ASSERT = require("./assert.js");
- var util = require("./util.js");
- var async = require("./async.js");
- var errors = require("./errors.js");
- var tryCatch1 = util.tryCatch1;
- var errorObj = util.errorObj;
- Promise.prototype.progressed = function Promise$progressed(handler) {
- return this._then(void 0, void 0, handler,
- void 0, void 0, this.progressed);
- };
- Promise.prototype._progress = function Promise$_progress(progressValue) {
- if (this._isFollowingOrFulfilledOrRejected()) return;
- this._progressUnchecked(progressValue);
- };
- Promise.prototype._progressHandlerAt =
- function Promise$_progressHandlerAt(index) {
- if (index === 0) return this._progressHandler0;
- return this[index + 2 - 5];
- };
- Promise.prototype._doProgressWith =
- function Promise$_doProgressWith(progression) {
- var progressValue = progression.value;
- var handler = progression.handler;
- var promise = progression.promise;
- var receiver = progression.receiver;
- this._pushContext();
- var ret = tryCatch1(handler, receiver, progressValue);
- this._popContext();
- if (ret === errorObj) {
- if (ret.e != null &&
- ret.e.name !== "StopProgressPropagation") {
- var trace = errors.canAttach(ret.e)
- ? ret.e : new Error(ret.e + "");
- promise._attachExtraTrace(trace);
- promise._progress(ret.e);
- }
- }
- else if (Promise.is(ret)) {
- ret._then(promise._progress, null, null, promise, void 0,
- this._progress);
- }
- else {
- promise._progress(ret);
- }
- };
- Promise.prototype._progressUnchecked =
- function Promise$_progressUnchecked(progressValue) {
- if (!this.isPending()) return;
- var len = this._length();
- for (var i = 0; i < len; i += 5) {
- var handler = this._progressHandlerAt(i);
- var promise = this._promiseAt(i);
- if (!Promise.is(promise)) {
- var receiver = this._receiverAt(i);
- if (typeof handler === "function") {
- handler.call(receiver, progressValue, promise);
- }
- else if (Promise.is(receiver) && receiver._isProxied()) {
- receiver._progressUnchecked(progressValue);
- }
- else if (isPromiseArrayProxy(receiver, promise)) {
- receiver._promiseProgressed(progressValue, promise);
- }
- continue;
- }
- if (typeof handler === "function") {
- async.invoke(this._doProgressWith, this, {
- handler: handler,
- promise: promise,
- receiver: this._receiverAt(i),
- value: progressValue
- });
- }
- else {
- async.invoke(promise._progress, promise, progressValue);
- }
- }
- };
- };
- },{"./assert.js":2,"./async.js":3,"./errors.js":10,"./util.js":39}],20:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function() {
- var global = require("./global.js");
- var ASSERT = require("./assert.js");
- var util = require("./util.js");
- var async = require("./async.js");
- var errors = require("./errors.js");
- var INTERNAL = function(){};
- var APPLY = {};
- var NEXT_FILTER = {e: null};
- var PromiseArray = require("./promise_array.js")(Promise, INTERNAL);
- var CapturedTrace = require("./captured_trace.js")();
- var CatchFilter = require("./catch_filter.js")(NEXT_FILTER);
- var PromiseResolver = require("./promise_resolver.js");
- var isArray = util.isArray;
- var errorObj = util.errorObj;
- var tryCatch1 = util.tryCatch1;
- var tryCatch2 = util.tryCatch2;
- var tryCatchApply = util.tryCatchApply;
- var RangeError = errors.RangeError;
- var TypeError = errors.TypeError;
- var CancellationError = errors.CancellationError;
- var TimeoutError = errors.TimeoutError;
- var RejectionError = errors.RejectionError;
- var originatesFromRejection = errors.originatesFromRejection;
- var markAsOriginatingFromRejection = errors.markAsOriginatingFromRejection;
- var canAttach = errors.canAttach;
- var thrower = util.thrower;
- var apiRejection = require("./errors_api_rejection")(Promise);
- var makeSelfResolutionError = function Promise$_makeSelfResolutionError() {
- return new TypeError("circular promise resolution chain");
- };
- function isPromise(obj) {
- if (obj === void 0) return false;
- return obj instanceof Promise;
- }
- function isPromiseArrayProxy(receiver, promiseSlotValue) {
- if (receiver instanceof PromiseArray) {
- return promiseSlotValue >= 0;
- }
- return false;
- }
- function Promise(resolver) {
- if (typeof resolver !== "function") {
- throw new TypeError("the promise constructor requires a resolver function");
- }
- if (this.constructor !== Promise) {
- throw new TypeError("the promise constructor cannot be invoked directly");
- }
- this._bitField = 0;
- this._fulfillmentHandler0 = void 0;
- this._rejectionHandler0 = void 0;
- this._promise0 = void 0;
- this._receiver0 = void 0;
- this._settledValue = void 0;
- this._boundTo = void 0;
- if (resolver !== INTERNAL) this._resolveFromResolver(resolver);
- }
- Promise.prototype.bind = function Promise$bind(thisArg) {
- var ret = new Promise(INTERNAL);
- if (debugging) ret._setTrace(this.bind, this);
- ret._follow(this);
- ret._setBoundTo(thisArg);
- if (this._cancellable()) {
- ret._setCancellable();
- ret._cancellationParent = this;
- }
- return ret;
- };
- Promise.prototype.toString = function Promise$toString() {
- return "[object Promise]";
- };
- Promise.prototype.caught = Promise.prototype["catch"] =
- function Promise$catch(fn) {
- var len = arguments.length;
- if (len > 1) {
- var catchInstances = new Array(len - 1),
- j = 0, i;
- for (i = 0; i < len - 1; ++i) {
- var item = arguments[i];
- if (typeof item === "function") {
- catchInstances[j++] = item;
- }
- else {
- var catchFilterTypeError =
- new TypeError(
- "A catch filter must be an error constructor "
- + "or a filter function");
- this._attachExtraTrace(catchFilterTypeError);
- async.invoke(this._reject, this, catchFilterTypeError);
- return;
- }
- }
- catchInstances.length = j;
- fn = arguments[i];
- this._resetTrace(this.caught);
- var catchFilter = new CatchFilter(catchInstances, fn, this);
- return this._then(void 0, catchFilter.doFilter, void 0,
- catchFilter, void 0, this.caught);
- }
- return this._then(void 0, fn, void 0, void 0, void 0, this.caught);
- };
- Promise.prototype.then =
- function Promise$then(didFulfill, didReject, didProgress) {
- return this._then(didFulfill, didReject, didProgress,
- void 0, void 0, this.then);
- };
- Promise.prototype.done =
- function Promise$done(didFulfill, didReject, didProgress) {
- var promise = this._then(didFulfill, didReject, didProgress,
- void 0, void 0, this.done);
- promise._setIsFinal();
- };
- Promise.prototype.spread = function Promise$spread(didFulfill, didReject) {
- return this._then(didFulfill, didReject, void 0,
- APPLY, void 0, this.spread);
- };
- Promise.prototype.isFulfilled = function Promise$isFulfilled() {
- return (this._bitField & 268435456) > 0;
- };
- Promise.prototype.isRejected = function Promise$isRejected() {
- return (this._bitField & 134217728) > 0;
- };
- Promise.prototype.isPending = function Promise$isPending() {
- return !this.isResolved();
- };
- Promise.prototype.isResolved = function Promise$isResolved() {
- return (this._bitField & 402653184) > 0;
- };
- Promise.prototype.isCancellable = function Promise$isCancellable() {
- return !this.isResolved() &&
- this._cancellable();
- };
- Promise.prototype.toJSON = function Promise$toJSON() {
- var ret = {
- isFulfilled: false,
- isRejected: false,
- fulfillmentValue: void 0,
- rejectionReason: void 0
- };
- if (this.isFulfilled()) {
- ret.fulfillmentValue = this._settledValue;
- ret.isFulfilled = true;
- }
- else if (this.isRejected()) {
- ret.rejectionReason = this._settledValue;
- ret.isRejected = true;
- }
- return ret;
- };
- Promise.prototype.all = function Promise$all() {
- return Promise$_all(this, true, this.all);
- };
- Promise.is = isPromise;
- function Promise$_all(promises, useBound, caller) {
- return Promise$_CreatePromiseArray(
- promises,
- PromiseArray,
- caller,
- useBound === true && promises._isBound()
- ? promises._boundTo
- : void 0
- ).promise();
- }
- Promise.all = function Promise$All(promises) {
- return Promise$_all(promises, false, Promise.all);
- };
- Promise.join = function Promise$Join() {
- var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
- return Promise$_CreatePromiseArray(
- args, PromiseArray, Promise.join, void 0).promise();
- };
- Promise.resolve = Promise.fulfilled =
- function Promise$Resolve(value, caller) {
- var ret = new Promise(INTERNAL);
- if (debugging) ret._setTrace(typeof caller === "function"
- ? caller
- : Promise.resolve, void 0);
- if (ret._tryFollow(value)) {
- return ret;
- }
- ret._cleanValues();
- ret._setFulfilled();
- ret._settledValue = value;
- return ret;
- };
- Promise.reject = Promise.rejected = function Promise$Reject(reason) {
- var ret = new Promise(INTERNAL);
- if (debugging) ret._setTrace(Promise.reject, void 0);
- markAsOriginatingFromRejection(reason);
- ret._cleanValues();
- ret._setRejected();
- ret._settledValue = reason;
- if (!canAttach(reason)) {
- var trace = new Error(reason + "");
- ret._setCarriedStackTrace(trace);
- }
- ret._ensurePossibleRejectionHandled();
- return ret;
- };
- Promise.prototype.error = function Promise$_error(fn) {
- return this.caught(originatesFromRejection, fn);
- };
- Promise.prototype._resolveFromSyncValue =
- function Promise$_resolveFromSyncValue(value, caller) {
- if (value === errorObj) {
- this._cleanValues();
- this._setRejected();
- this._settledValue = value.e;
- this._ensurePossibleRejectionHandled();
- }
- else {
- var maybePromise = Promise._cast(value, caller, void 0);
- if (maybePromise instanceof Promise) {
- this._follow(maybePromise);
- }
- else {
- this._cleanValues();
- this._setFulfilled();
- this._settledValue = value;
- }
- }
- };
- Promise.method = function Promise$_Method(fn) {
- if (typeof fn !== "function") {
- throw new TypeError("fn must be a function");
- }
- return function Promise$_method() {
- var value;
- switch(arguments.length) {
- case 0: value = tryCatch1(fn, this, void 0); break;
- case 1: value = tryCatch1(fn, this, arguments[0]); break;
- case 2: value = tryCatch2(fn, this, arguments[0], arguments[1]); break;
- default:
- var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
- value = tryCatchApply(fn, args, this); break;
- }
- var ret = new Promise(INTERNAL);
- if (debugging) ret._setTrace(Promise$_method, void 0);
- ret._resolveFromSyncValue(value, Promise$_method);
- return ret;
- };
- };
- Promise.attempt = Promise["try"] = function Promise$_Try(fn, args, ctx) {
- if (typeof fn !== "function") {
- return apiRejection("fn must be a function");
- }
- var value = isArray(args)
- ? tryCatchApply(fn, args, ctx)
- : tryCatch1(fn, ctx, args);
- var ret = new Promise(INTERNAL);
- if (debugging) ret._setTrace(Promise.attempt, void 0);
- ret._resolveFromSyncValue(value, Promise.attempt);
- return ret;
- };
- Promise.defer = Promise.pending = function Promise$Defer(caller) {
- var promise = new Promise(INTERNAL);
- if (debugging) promise._setTrace(typeof caller === "function"
- ? caller : Promise.defer, void 0);
- return new PromiseResolver(promise);
- };
- Promise.bind = function Promise$Bind(thisArg) {
- var ret = new Promise(INTERNAL);
- if (debugging) ret._setTrace(Promise.bind, void 0);
- ret._setFulfilled();
- ret._setBoundTo(thisArg);
- return ret;
- };
- Promise.cast = function Promise$_Cast(obj, caller) {
- if (typeof caller !== "function") {
- caller = Promise.cast;
- }
- var ret = Promise._cast(obj, caller, void 0);
- if (!(ret instanceof Promise)) {
- return Promise.resolve(ret, caller);
- }
- return ret;
- };
- Promise.onPossiblyUnhandledRejection =
- function Promise$OnPossiblyUnhandledRejection(fn) {
- if (typeof fn === "function") {
- CapturedTrace.possiblyUnhandledRejection = fn;
- }
- else {
- CapturedTrace.possiblyUnhandledRejection = void 0;
- }
- };
- var debugging = false || !!(
- typeof process !== "undefined" &&
- typeof process.execPath === "string" &&
- typeof process.env === "object" &&
- (process.env["BLUEBIRD_DEBUG"] ||
- process.env["NODE_ENV"] === "development")
- );
- Promise.longStackTraces = function Promise$LongStackTraces() {
- if (async.haveItemsQueued() &&
- debugging === false
- ) {
- throw new Error("cannot enable long stack traces after promises have been created");
- }
- debugging = CapturedTrace.isSupported();
- };
- Promise.hasLongStackTraces = function Promise$HasLongStackTraces() {
- return debugging && CapturedTrace.isSupported();
- };
- Promise.prototype._setProxyHandlers =
- function Promise$_setProxyHandlers(receiver, promiseSlotValue) {
- var index = this._length();
- if (index >= 1048575 - 5) {
- index = 0;
- this._setLength(0);
- }
- if (index === 0) {
- this._promise0 = promiseSlotValue;
- this._receiver0 = receiver;
- }
- else {
- var i = index - 5;
- this[i + 3] = promiseSlotValue;
- this[i + 4] = receiver;
- this[i + 0] =
- this[i + 1] =
- this[i + 2] = void 0;
- }
- this._setLength(index + 5);
- };
- Promise.prototype._proxyPromiseArray =
- function Promise$_proxyPromiseArray(promiseArray, index) {
- this._setProxyHandlers(promiseArray, index);
- };
- Promise.prototype._proxyPromise = function Promise$_proxyPromise(promise) {
- promise._setProxied();
- this._setProxyHandlers(promise, -1);
- };
- Promise.prototype._then =
- function Promise$_then(
- didFulfill,
- didReject,
- didProgress,
- receiver,
- internalData,
- caller
- ) {
- var haveInternalData = internalData !== void 0;
- var ret = haveInternalData ? internalData : new Promise(INTERNAL);
- if (debugging && !haveInternalData) {
- var haveSameContext = this._peekContext() === this._traceParent;
- ret._traceParent = haveSameContext ? this._traceParent : this;
- ret._setTrace(typeof caller === "function"
- ? caller
- : this._then, this);
- }
- if (!haveInternalData && this._isBound()) {
- ret._setBoundTo(this._boundTo);
- }
- var callbackIndex =
- this._addCallbacks(didFulfill, didReject, didProgress, ret, receiver);
- if (!haveInternalData && this._cancellable()) {
- ret._setCancellable();
- ret._cancellationParent = this;
- }
- if (this.isResolved()) {
- async.invoke(this._queueSettleAt, this, callbackIndex);
- }
- return ret;
- };
- Promise.prototype._length = function Promise$_length() {
- return this._bitField & 1048575;
- };
- Promise.prototype._isFollowingOrFulfilledOrRejected =
- function Promise$_isFollowingOrFulfilledOrRejected() {
- return (this._bitField & 939524096) > 0;
- };
- Promise.prototype._isFollowing = function Promise$_isFollowing() {
- return (this._bitField & 536870912) === 536870912;
- };
- Promise.prototype._setLength = function Promise$_setLength(len) {
- this._bitField = (this._bitField & -1048576) |
- (len & 1048575);
- };
- Promise.prototype._setFulfilled = function Promise$_setFulfilled() {
- this._bitField = this._bitField | 268435456;
- };
- Promise.prototype._setRejected = function Promise$_setRejected() {
- this._bitField = this._bitField | 134217728;
- };
- Promise.prototype._setFollowing = function Promise$_setFollowing() {
- this._bitField = this._bitField | 536870912;
- };
- Promise.prototype._setIsFinal = function Promise$_setIsFinal() {
- this._bitField = this._bitField | 33554432;
- };
- Promise.prototype._isFinal = function Promise$_isFinal() {
- return (this._bitField & 33554432) > 0;
- };
- Promise.prototype._cancellable = function Promise$_cancellable() {
- return (this._bitField & 67108864) > 0;
- };
- Promise.prototype._setCancellable = function Promise$_setCancellable() {
- this._bitField = this._bitField | 67108864;
- };
- Promise.prototype._unsetCancellable = function Promise$_unsetCancellable() {
- this._bitField = this._bitField & (~67108864);
- };
- Promise.prototype._setRejectionIsUnhandled =
- function Promise$_setRejectionIsUnhandled() {
- this._bitField = this._bitField | 2097152;
- };
- Promise.prototype._unsetRejectionIsUnhandled =
- function Promise$_unsetRejectionIsUnhandled() {
- this._bitField = this._bitField & (~2097152);
- };
- Promise.prototype._isRejectionUnhandled =
- function Promise$_isRejectionUnhandled() {
- return (this._bitField & 2097152) > 0;
- };
- Promise.prototype._setCarriedStackTrace =
- function Promise$_setCarriedStackTrace(capturedTrace) {
- this._bitField = this._bitField | 1048576;
- this._fulfillmentHandler0 = capturedTrace;
- };
- Promise.prototype._unsetCarriedStackTrace =
- function Promise$_unsetCarriedStackTrace() {
- this._bitField = this._bitField & (~1048576);
- this._fulfillmentHandler0 = void 0;
- };
- Promise.prototype._isCarryingStackTrace =
- function Promise$_isCarryingStackTrace() {
- return (this._bitField & 1048576) > 0;
- };
- Promise.prototype._getCarriedStackTrace =
- function Promise$_getCarriedStackTrace() {
- return this._isCarryingStackTrace()
- ? this._fulfillmentHandler0
- : void 0;
- };
- Promise.prototype._receiverAt = function Promise$_receiverAt(index) {
- var ret;
- if (index === 0) {
- ret = this._receiver0;
- }
- else {
- ret = this[index + 4 - 5];
- }
- if (this._isBound() && ret === void 0) {
- return this._boundTo;
- }
- return ret;
- };
- Promise.prototype._promiseAt = function Promise$_promiseAt(index) {
- if (index === 0) return this._promise0;
- return this[index + 3 - 5];
- };
- Promise.prototype._fulfillmentHandlerAt =
- function Promise$_fulfillmentHandlerAt(index) {
- if (index === 0) return this._fulfillmentHandler0;
- return this[index + 0 - 5];
- };
- Promise.prototype._rejectionHandlerAt =
- function Promise$_rejectionHandlerAt(index) {
- if (index === 0) return this._rejectionHandler0;
- return this[index + 1 - 5];
- };
- Promise.prototype._unsetAt = function Promise$_unsetAt(index) {
- if (index === 0) {
- this._rejectionHandler0 =
- this._progressHandler0 =
- this._promise0 =
- this._receiver0 = void 0;
- if (!this._isCarryingStackTrace()) {
- this._fulfillmentHandler0 = void 0;
- }
- }
- else {
- this[index - 5 + 0] =
- this[index - 5 + 1] =
- this[index - 5 + 2] =
- this[index - 5 + 3] =
- this[index - 5 + 4] = void 0;
- }
- };
- Promise.prototype._resolveFromResolver =
- function Promise$_resolveFromResolver(resolver) {
- var promise = this;
- var localDebugging = debugging;
- if (localDebugging) {
- this._setTrace(this._resolveFromResolver, void 0);
- this._pushContext();
- }
- function Promise$_resolver(val) {
- if (promise._tryFollow(val)) {
- return;
- }
- promise._fulfill(val);
- }
- function Promise$_rejecter(val) {
- var trace = canAttach(val) ? val : new Error(val + "");
- promise._attachExtraTrace(trace);
- markAsOriginatingFromRejection(val);
- promise._reject(val, trace === val ? void 0 : trace);
- }
- var r = tryCatch2(resolver, void 0, Promise$_resolver, Promise$_rejecter);
- if (localDebugging) this._popContext();
- if (r !== void 0 && r === errorObj) {
- var trace = canAttach(r.e) ? r.e : new Error(r.e + "");
- promise._reject(r.e, trace);
- }
- };
- Promise.prototype._addCallbacks = function Promise$_addCallbacks(
- fulfill,
- reject,
- progress,
- promise,
- receiver
- ) {
- var index = this._length();
- if (index >= 1048575 - 5) {
- index = 0;
- this._setLength(0);
- }
- if (index === 0) {
- this._promise0 = promise;
- if (receiver !== void 0) this._receiver0 = receiver;
- if (typeof fulfill === "function" && !this._isCarryingStackTrace())
- this._fulfillmentHandler0 = fulfill;
- if (typeof reject === "function") this._rejectionHandler0 = reject;
- if (typeof progress === "function") this._progressHandler0 = progress;
- }
- else {
- var i = index - 5;
- this[i + 3] = promise;
- this[i + 4] = receiver;
- this[i + 0] = typeof fulfill === "function"
- ? fulfill : void 0;
- this[i + 1] = typeof reject === "function"
- ? reject : void 0;
- this[i + 2] = typeof progress === "function"
- ? progress : void 0;
- }
- this._setLength(index + 5);
- return index;
- };
- Promise.prototype._setBoundTo = function Promise$_setBoundTo(obj) {
- if (obj !== void 0) {
- this._bitField = this._bitField | 8388608;
- this._boundTo = obj;
- }
- else {
- this._bitField = this._bitField & (~8388608);
- }
- };
- Promise.prototype._isBound = function Promise$_isBound() {
- return (this._bitField & 8388608) === 8388608;
- };
- Promise.prototype._spreadSlowCase =
- function Promise$_spreadSlowCase(targetFn, promise, values, boundTo) {
- var promiseForAll =
- Promise$_CreatePromiseArray
- (values, PromiseArray, this._spreadSlowCase, boundTo)
- .promise()
- ._then(function() {
- return targetFn.apply(boundTo, arguments);
- }, void 0, void 0, APPLY, void 0, this._spreadSlowCase);
- promise._follow(promiseForAll);
- };
- Promise.prototype._callSpread =
- function Promise$_callSpread(handler, promise, value, localDebugging) {
- var boundTo = this._isBound() ? this._boundTo : void 0;
- if (isArray(value)) {
- var caller = this._settlePromiseFromHandler;
- for (var i = 0, len = value.length; i < len; ++i) {
- if (isPromise(Promise._cast(value[i], caller, void 0))) {
- this._spreadSlowCase(handler, promise, value, boundTo);
- return;
- }
- }
- }
- if (localDebugging) promise._pushContext();
- return tryCatchApply(handler, value, boundTo);
- };
- Promise.prototype._callHandler =
- function Promise$_callHandler(
- handler, receiver, promise, value, localDebugging) {
- var x;
- if (receiver === APPLY && !this.isRejected()) {
- x = this._callSpread(handler, promise, value, localDebugging);
- }
- else {
- if (localDebugging) promise._pushContext();
- x = tryCatch1(handler, receiver, value);
- }
- if (localDebugging) promise._popContext();
- return x;
- };
- Promise.prototype._settlePromiseFromHandler =
- function Promise$_settlePromiseFromHandler(
- handler, receiver, value, promise
- ) {
- if (!isPromise(promise)) {
- handler.call(receiver, value, promise);
- return;
- }
- var localDebugging = debugging;
- var x = this._callHandler(handler, receiver,
- promise, value, localDebugging);
- if (promise._isFollowing()) return;
- if (x === errorObj || x === promise || x === NEXT_FILTER) {
- var err = x === promise
- ? makeSelfResolutionError()
- : x.e;
- var trace = canAttach(err) ? err : new Error(err + "");
- if (x !== NEXT_FILTER) promise._attachExtraTrace(trace);
- promise._rejectUnchecked(err, trace);
- }
- else {
- var castValue = Promise._cast(x,
- localDebugging ? this._settlePromiseFromHandler : void 0,
- promise);
- if (isPromise(castValue)) {
- if (castValue.isRejected() &&
- !castValue._isCarryingStackTrace() &&
- !canAttach(castValue._settledValue)) {
- var trace = new Error(castValue._settledValue + "");
- promise._attachExtraTrace(trace);
- castValue._setCarriedStackTrace(trace);
- }
- promise._follow(castValue);
- if (castValue._cancellable()) {
- promise._cancellationParent = castValue;
- promise._setCancellable();
- }
- }
- else {
- promise._fulfillUnchecked(x);
- }
- }
- };
- Promise.prototype._follow =
- function Promise$_follow(promise) {
- this._setFollowing();
- if (promise.isPending()) {
- if (promise._cancellable() ) {
- this._cancellationParent = promise;
- this._setCancellable();
- }
- promise._proxyPromise(this);
- }
- else if (promise.isFulfilled()) {
- this._fulfillUnchecked(promise._settledValue);
- }
- else {
- this._rejectUnchecked(promise._settledValue,
- promise._getCarriedStackTrace());
- }
- if (promise._isRejectionUnhandled()) promise._unsetRejectionIsUnhandled();
- if (debugging &&
- promise._traceParent == null) {
- promise._traceParent = this;
- }
- };
- Promise.prototype._tryFollow =
- function Promise$_tryFollow(value) {
- if (this._isFollowingOrFulfilledOrRejected() ||
- value === this) {
- return false;
- }
- var maybePromise = Promise._cast(value, this._tryFollow, void 0);
- if (!isPromise(maybePromise)) {
- return false;
- }
- this._follow(maybePromise);
- return true;
- };
- Promise.prototype._resetTrace = function Promise$_resetTrace(caller) {
- if (debugging) {
- var context = this._peekContext();
- var isTopLevel = context === void 0;
- this._trace = new CapturedTrace(
- typeof caller === "function"
- ? caller
- : this._resetTrace,
- isTopLevel
- );
- }
- };
- Promise.prototype._setTrace = function Promise$_setTrace(caller, parent) {
- if (debugging) {
- var context = this._peekContext();
- this._traceParent = context;
- var isTopLevel = context === void 0;
- if (parent !== void 0 &&
- parent._traceParent === context) {
- this._trace = parent._trace;
- }
- else {
- this._trace = new CapturedTrace(
- typeof caller === "function"
- ? caller
- : this._setTrace,
- isTopLevel
- );
- }
- }
- return this;
- };
- Promise.prototype._attachExtraTrace =
- function Promise$_attachExtraTrace(error) {
- if (debugging) {
- var promise = this;
- var stack = error.stack;
- stack = typeof stack === "string"
- ? stack.split("\n") : [];
- var headerLineCount = 1;
- while(promise != null &&
- promise._trace != null) {
- stack = CapturedTrace.combine(
- stack,
- promise._trace.stack.split("\n")
- );
- promise = promise._traceParent;
- }
- var max = Error.stackTraceLimit + headerLineCount;
- var len = stack.length;
- if (len > max) {
- stack.length = max;
- }
- if (stack.length <= headerLineCount) {
- error.stack = "(No stack trace)";
- }
- else {
- error.stack = stack.join("\n");
- }
- }
- };
- Promise.prototype._cleanValues = function Promise$_cleanValues() {
- if (this._cancellable()) {
- this._cancellationParent = void 0;
- }
- };
- Promise.prototype._fulfill = function Promise$_fulfill(value) {
- if (this._isFollowingOrFulfilledOrRejected()) return;
- this._fulfillUnchecked(value);
- };
- Promise.prototype._reject =
- function Promise$_reject(reason, carriedStackTrace) {
- if (this._isFollowingOrFulfilledOrRejected()) return;
- this._rejectUnchecked(reason, carriedStackTrace);
- };
- Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) {
- var handler = this.isFulfilled()
- ? this._fulfillmentHandlerAt(index)
- : this._rejectionHandlerAt(index);
- var value = this._settledValue;
- var receiver = this._receiverAt(index);
- var promise = this._promiseAt(index);
- if (typeof handler === "function") {
- this._settlePromiseFromHandler(handler, receiver, value, promise);
- }
- else {
- var done = false;
- var isFulfilled = this.isFulfilled();
- if (receiver !== void 0) {
- if (receiver instanceof Promise &&
- receiver._isProxied()) {
- receiver._unsetProxied();
- if (isFulfilled) receiver._fulfillUnchecked(value);
- else receiver._rejectUnchecked(value,
- this._getCarriedStackTrace());
- done = true;
- }
- else if (isPromiseArrayProxy(receiver, promise)) {
- if (isFulfilled) receiver._promiseFulfilled(value, promise);
- else receiver._promiseRejected(value, promise);
- done = true;
- }
- }
- if (!done) {
- if (isFulfilled) promise._fulfill(value);
- else promise._reject(value, this._getCarriedStackTrace());
- }
- }
- if (index >= 256) {
- this._queueGC();
- }
- };
- Promise.prototype._isProxied = function Promise$_isProxied() {
- return (this._bitField & 4194304) === 4194304;
- };
- Promise.prototype._setProxied = function Promise$_setProxied() {
- this._bitField = this._bitField | 4194304;
- };
- Promise.prototype._unsetProxied = function Promise$_unsetProxied() {
- this._bitField = this._bitField & (~4194304);
- };
- Promise.prototype._isGcQueued = function Promise$_isGcQueued() {
- return (this._bitField & -1073741824) === -1073741824;
- };
- Promise.prototype._setGcQueued = function Promise$_setGcQueued() {
- this._bitField = this._bitField | -1073741824;
- };
- Promise.prototype._unsetGcQueued = function Promise$_unsetGcQueued() {
- this._bitField = this._bitField & (~-1073741824);
- };
- Promise.prototype._queueGC = function Promise$_queueGC() {
- if (this._isGcQueued()) return;
- this._setGcQueued();
- async.invokeLater(this._gc, this, void 0);
- };
- Promise.prototype._gc = function Promise$gc() {
- var len = this._length();
- this._unsetAt(0);
- for (var i = 0; i < len; i++) {
- delete this[i];
- }
- this._setLength(0);
- this._unsetGcQueued();
- };
- Promise.prototype._queueSettleAt = function Promise$_queueSettleAt(index) {
- if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled();
- async.invoke(this._settlePromiseAt, this, index);
- };
- Promise.prototype._fulfillUnchecked =
- function Promise$_fulfillUnchecked(value) {
- if (!this.isPending()) return;
- if (value === this) {
- var err = makeSelfResolutionError();
- this._attachExtraTrace(err);
- return this._rejectUnchecked(err, void 0);
- }
- this._cleanValues();
- this._setFulfilled();
- this._settledValue = value;
- var len = this._length();
- if (len > 0) {
- async.invoke(this._fulfillPromises, this, len);
- }
- };
- Promise.prototype._rejectUncheckedCheckError =
- function Promise$_rejectUncheckedCheckError(reason) {
- var trace = canAttach(reason) ? reason : new Error(reason + "");
- this._rejectUnchecked(reason, trace === reason ? void 0 : trace);
- };
- Promise.prototype._rejectUnchecked =
- function Promise$_rejectUnchecked(reason, trace) {
- if (!this.isPending()) return;
- if (reason === this) {
- var err = makeSelfResolutionError();
- this._attachExtraTrace(err);
- return this._rejectUnchecked(err);
- }
- this._cleanValues();
- this._setRejected();
- this._settledValue = reason;
- if (this._isFinal()) {
- async.invokeLater(thrower, void 0, trace === void 0 ? reason : trace);
- return;
- }
- var len = this._length();
- if (trace !== void 0) this._setCarriedStackTrace(trace);
- if (len > 0) {
- async.invoke(this._rejectPromises, this, len);
- }
- else {
- this._ensurePossibleRejectionHandled();
- }
- };
- Promise.prototype._rejectPromises = function Promise$_rejectPromises(len) {
- len = this._length();
- for (var i = 0; i < len; i+= 5) {
- this._settlePromiseAt(i);
- }
- this._unsetCarriedStackTrace();
- };
- Promise.prototype._fulfillPromises = function Promise$_fulfillPromises(len) {
- len = this._length();
- for (var i = 0; i < len; i+= 5) {
- this._settlePromiseAt(i);
- }
- };
- Promise.prototype._ensurePossibleRejectionHandled =
- function Promise$_ensurePossibleRejectionHandled() {
- this._setRejectionIsUnhandled();
- if (CapturedTrace.possiblyUnhandledRejection !== void 0) {
- async.invokeLater(this._notifyUnhandledRejection, this, void 0);
- }
- };
- Promise.prototype._notifyUnhandledRejection =
- function Promise$_notifyUnhandledRejection() {
- if (this._isRejectionUnhandled()) {
- var reason = this._settledValue;
- var trace = this._getCarriedStackTrace();
- this._unsetRejectionIsUnhandled();
- if (trace !== void 0) {
- this._unsetCarriedStackTrace();
- reason = trace;
- }
- if (typeof CapturedTrace.possiblyUnhandledRejection === "function") {
- CapturedTrace.possiblyUnhandledRejection(reason, this);
- }
- }
- };
- var contextStack = [];
- Promise.prototype._peekContext = function Promise$_peekContext() {
- var lastIndex = contextStack.length - 1;
- if (lastIndex >= 0) {
- return contextStack[lastIndex];
- }
- return void 0;
- };
- Promise.prototype._pushContext = function Promise$_pushContext() {
- if (!debugging) return;
- contextStack.push(this);
- };
- Promise.prototype._popContext = function Promise$_popContext() {
- if (!debugging) return;
- contextStack.pop();
- };
- function Promise$_CreatePromiseArray(
- promises, PromiseArrayConstructor, caller, boundTo) {
- var list = null;
- if (isArray(promises)) {
- list = promises;
- }
- else {
- list = Promise._cast(promises, caller, void 0);
- if (list !== promises) {
- list._setBoundTo(boundTo);
- }
- else if (!isPromise(list)) {
- list = null;
- }
- }
- if (list !== null) {
- return new PromiseArrayConstructor(
- list,
- typeof caller === "function"
- ? caller
- : Promise$_CreatePromiseArray,
- boundTo
- );
- }
- return {
- promise: function() {return apiRejection("expecting an array, a promise or a thenable");}
- };
- }
- var old = global.Promise;
- Promise.noConflict = function() {
- if (global.Promise === Promise) {
- global.Promise = old;
- }
- return Promise;
- };
- if (!CapturedTrace.isSupported()) {
- Promise.longStackTraces = function(){};
- debugging = false;
- }
- Promise._makeSelfResolutionError = makeSelfResolutionError;
- require("./finally.js")(Promise, NEXT_FILTER);
- require("./direct_resolve.js")(Promise);
- require("./thenables.js")(Promise, INTERNAL);
- Promise.RangeError = RangeError;
- Promise.CancellationError = CancellationError;
- Promise.TimeoutError = TimeoutError;
- Promise.TypeError = TypeError;
- Promise.RejectionError = RejectionError;
- require('./timers.js')(Promise,INTERNAL);
- require('./synchronous_inspection.js')(Promise);
- require('./any.js')(Promise,Promise$_CreatePromiseArray,PromiseArray);
- require('./race.js')(Promise,INTERNAL);
- require('./call_get.js')(Promise);
- require('./filter.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection);
- require('./generators.js')(Promise,apiRejection,INTERNAL);
- require('./map.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection);
- require('./nodeify.js')(Promise);
- require('./promisify.js')(Promise,INTERNAL);
- require('./props.js')(Promise,PromiseArray);
- require('./reduce.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection,INTERNAL);
- require('./settle.js')(Promise,Promise$_CreatePromiseArray,PromiseArray);
- require('./some.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection);
- require('./progress.js')(Promise,isPromiseArrayProxy);
- require('./cancel.js')(Promise,INTERNAL);
- Promise.prototype = Promise.prototype;
- return Promise;
- };
- },{"./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){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var ASSERT = require("./assert.js");
- var canAttach = require("./errors.js").canAttach;
- var util = require("./util.js");
- var async = require("./async.js");
- var hasOwn = {}.hasOwnProperty;
- var isArray = util.isArray;
- function toResolutionValue(val) {
- switch(val) {
- case -1: return void 0;
- case -2: return [];
- case -3: return {};
- }
- }
- function PromiseArray(values, caller, boundTo) {
- var promise = this._promise = new Promise(INTERNAL);
- var parent = void 0;
- if (Promise.is(values)) {
- parent = values;
- if (values._cancellable()) {
- promise._setCancellable();
- promise._cancellationParent = values;
- }
- if (values._isBound()) {
- promise._setBoundTo(boundTo);
- }
- }
- promise._setTrace(caller, parent);
- this._values = values;
- this._length = 0;
- this._totalResolved = 0;
- this._init(void 0, -2);
- }
- PromiseArray.PropertiesPromiseArray = function() {};
- PromiseArray.prototype.length = function PromiseArray$length() {
- return this._length;
- };
- PromiseArray.prototype.promise = function PromiseArray$promise() {
- return this._promise;
- };
- PromiseArray.prototype._init =
- function PromiseArray$_init(_, resolveValueIfEmpty) {
- var values = this._values;
- if (Promise.is(values)) {
- if (values.isFulfilled()) {
- values = values._settledValue;
- if (!isArray(values)) {
- var err = new Promise.TypeError("expecting an array, a promise or a thenable");
- this.__hardReject__(err);
- return;
- }
- this._values = values;
- }
- else if (values.isPending()) {
- values._then(
- this._init,
- this._reject,
- void 0,
- this,
- resolveValueIfEmpty,
- this.constructor
- );
- return;
- }
- else {
- this._reject(values._settledValue);
- return;
- }
- }
- if (values.length === 0) {
- this._resolve(toResolutionValue(resolveValueIfEmpty));
- return;
- }
- var len = values.length;
- var newLen = len;
- var newValues;
- if (this instanceof PromiseArray.PropertiesPromiseArray) {
- newValues = this._values;
- }
- else {
- newValues = new Array(len);
- }
- var isDirectScanNeeded = false;
- for (var i = 0; i < len; ++i) {
- var promise = values[i];
- if (promise === void 0 && !hasOwn.call(values, i)) {
- newLen--;
- continue;
- }
- var maybePromise = Promise._cast(promise, void 0, void 0);
- if (maybePromise instanceof Promise &&
- maybePromise.isPending()) {
- maybePromise._proxyPromiseArray(this, i);
- }
- else {
- isDirectScanNeeded = true;
- }
- newValues[i] = maybePromise;
- }
- if (newLen === 0) {
- if (resolveValueIfEmpty === -2) {
- this._resolve(newValues);
- }
- else {
- this._resolve(toResolutionValue(resolveValueIfEmpty));
- }
- return;
- }
- this._values = newValues;
- this._length = newLen;
- if (isDirectScanNeeded) {
- var scanMethod = newLen === len
- ? this._scanDirectValues
- : this._scanDirectValuesHoled;
- async.invoke(scanMethod, this, len);
- }
- };
- PromiseArray.prototype._settlePromiseAt =
- function PromiseArray$_settlePromiseAt(index) {
- var value = this._values[index];
- if (!Promise.is(value)) {
- this._promiseFulfilled(value, index);
- }
- else if (value.isFulfilled()) {
- this._promiseFulfilled(value._settledValue, index);
- }
- else if (value.isRejected()) {
- this._promiseRejected(value._settledValue, index);
- }
- };
- PromiseArray.prototype._scanDirectValuesHoled =
- function PromiseArray$_scanDirectValuesHoled(len) {
- for (var i = 0; i < len; ++i) {
- if (this._isResolved()) {
- break;
- }
- if (hasOwn.call(this._values, i)) {
- this._settlePromiseAt(i);
- }
- }
- };
- PromiseArray.prototype._scanDirectValues =
- function PromiseArray$_scanDirectValues(len) {
- for (var i = 0; i < len; ++i) {
- if (this._isResolved()) {
- break;
- }
- this._settlePromiseAt(i);
- }
- };
- PromiseArray.prototype._isResolved = function PromiseArray$_isResolved() {
- return this._values === null;
- };
- PromiseArray.prototype._resolve = function PromiseArray$_resolve(value) {
- this._values = null;
- this._promise._fulfill(value);
- };
- PromiseArray.prototype.__hardReject__ =
- PromiseArray.prototype._reject = function PromiseArray$_reject(reason) {
- this._values = null;
- var trace = canAttach(reason) ? reason : new Error(reason + "");
- this._promise._attachExtraTrace(trace);
- this._promise._reject(reason, trace);
- };
- PromiseArray.prototype._promiseProgressed =
- function PromiseArray$_promiseProgressed(progressValue, index) {
- if (this._isResolved()) return;
- this._promise._progress({
- index: index,
- value: progressValue
- });
- };
- PromiseArray.prototype._promiseFulfilled =
- function PromiseArray$_promiseFulfilled(value, index) {
- if (this._isResolved()) return;
- this._values[index] = value;
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= this._length) {
- this._resolve(this._values);
- }
- };
- PromiseArray.prototype._promiseRejected =
- function PromiseArray$_promiseRejected(reason, index) {
- if (this._isResolved()) return;
- this._totalResolved++;
- this._reject(reason);
- };
- return PromiseArray;
- };
- },{"./assert.js":2,"./async.js":3,"./errors.js":10,"./util.js":39}],22:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- var TypeError = require("./errors.js").TypeError;
- function PromiseInspection(promise) {
- if (promise !== void 0) {
- this._bitField = promise._bitField;
- this._settledValue = promise.isResolved()
- ? promise._settledValue
- : void 0;
- }
- else {
- this._bitField = 0;
- this._settledValue = void 0;
- }
- }
- PromiseInspection.prototype.isFulfilled =
- function PromiseInspection$isFulfilled() {
- return (this._bitField & 268435456) > 0;
- };
- PromiseInspection.prototype.isRejected =
- function PromiseInspection$isRejected() {
- return (this._bitField & 134217728) > 0;
- };
- PromiseInspection.prototype.isPending = function PromiseInspection$isPending() {
- return (this._bitField & 402653184) === 0;
- };
- PromiseInspection.prototype.value = function PromiseInspection$value() {
- if (!this.isFulfilled()) {
- throw new TypeError("cannot get fulfillment value of a non-fulfilled promise");
- }
- return this._settledValue;
- };
- PromiseInspection.prototype.error = function PromiseInspection$error() {
- if (!this.isRejected()) {
- throw new TypeError("cannot get rejection reason of a non-rejected promise");
- }
- return this._settledValue;
- };
- module.exports = PromiseInspection;
- },{"./errors.js":10}],23:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- var util = require("./util.js");
- var maybeWrapAsError = util.maybeWrapAsError;
- var errors = require("./errors.js");
- var TimeoutError = errors.TimeoutError;
- var RejectionError = errors.RejectionError;
- var async = require("./async.js");
- var haveGetters = util.haveGetters;
- var es5 = require("./es5.js");
- function isUntypedError(obj) {
- return obj instanceof Error &&
- es5.getPrototypeOf(obj) === Error.prototype;
- }
- function wrapAsRejectionError(obj) {
- var ret;
- if (isUntypedError(obj)) {
- ret = new RejectionError(obj);
- }
- else {
- ret = obj;
- }
- errors.markAsOriginatingFromRejection(ret);
- return ret;
- }
- function nodebackForPromise(promise) {
- function PromiseResolver$_callback(err, value) {
- if (promise === null) return;
- if (err) {
- var wrapped = wrapAsRejectionError(maybeWrapAsError(err));
- promise._attachExtraTrace(wrapped);
- promise._reject(wrapped);
- }
- else {
- if (arguments.length > 2) {
- var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
- promise._fulfill(args);
- }
- else {
- promise._fulfill(value);
- }
- }
- promise = null;
- }
- return PromiseResolver$_callback;
- }
- var PromiseResolver;
- if (!haveGetters) {
- PromiseResolver = function PromiseResolver(promise) {
- this.promise = promise;
- this.asCallback = nodebackForPromise(promise);
- this.callback = this.asCallback;
- };
- }
- else {
- PromiseResolver = function PromiseResolver(promise) {
- this.promise = promise;
- };
- }
- if (haveGetters) {
- var prop = {
- get: function() {
- return nodebackForPromise(this.promise);
- }
- };
- es5.defineProperty(PromiseResolver.prototype, "asCallback", prop);
- es5.defineProperty(PromiseResolver.prototype, "callback", prop);
- }
- PromiseResolver._nodebackForPromise = nodebackForPromise;
- PromiseResolver.prototype.toString = function PromiseResolver$toString() {
- return "[object PromiseResolver]";
- };
- PromiseResolver.prototype.resolve =
- PromiseResolver.prototype.fulfill = function PromiseResolver$resolve(value) {
- var promise = this.promise;
- if (promise._tryFollow(value)) {
- return;
- }
- async.invoke(promise._fulfill, promise, value);
- };
- PromiseResolver.prototype.reject = function PromiseResolver$reject(reason) {
- var promise = this.promise;
- errors.markAsOriginatingFromRejection(reason);
- var trace = errors.canAttach(reason) ? reason : new Error(reason + "");
- promise._attachExtraTrace(trace);
- async.invoke(promise._reject, promise, reason);
- if (trace !== reason) {
- async.invoke(this._setCarriedStackTrace, this, trace);
- }
- };
- PromiseResolver.prototype.progress =
- function PromiseResolver$progress(value) {
- async.invoke(this.promise._progress, this.promise, value);
- };
- PromiseResolver.prototype.cancel = function PromiseResolver$cancel() {
- async.invoke(this.promise.cancel, this.promise, void 0);
- };
- PromiseResolver.prototype.timeout = function PromiseResolver$timeout() {
- this.reject(new TimeoutError("timeout"));
- };
- PromiseResolver.prototype.isResolved = function PromiseResolver$isResolved() {
- return this.promise.isResolved();
- };
- PromiseResolver.prototype.toJSON = function PromiseResolver$toJSON() {
- return this.promise.toJSON();
- };
- PromiseResolver.prototype._setCarriedStackTrace =
- function PromiseResolver$_setCarriedStackTrace(trace) {
- if (this.promise.isRejected()) {
- this.promise._setCarriedStackTrace(trace);
- }
- };
- module.exports = PromiseResolver;
- },{"./async.js":3,"./errors.js":10,"./es5.js":12,"./util.js":39}],24:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var errors = require("./errors.js");
- var ASSERT = require("./assert.js");
- var TypeError = errors.TypeError;
- var util = require("./util.js");
- var isArray = util.isArray;
- var errorObj = util.errorObj;
- var tryCatch1 = util.tryCatch1;
- var yieldHandlers = [];
- function promiseFromYieldHandler(value) {
- var _yieldHandlers = yieldHandlers;
- var _errorObj = errorObj;
- var _Promise = Promise;
- var len = _yieldHandlers.length;
- for (var i = 0; i < len; ++i) {
- var result = tryCatch1(_yieldHandlers[i], void 0, value);
- if (result === _errorObj) {
- return _Promise.reject(_errorObj.e);
- }
- var maybePromise = _Promise._cast(result,
- promiseFromYieldHandler, void 0);
- if (maybePromise instanceof _Promise) return maybePromise;
- }
- return null;
- }
- function PromiseSpawn(generatorFunction, receiver, caller) {
- var promise = this._promise = new Promise(INTERNAL);
- promise._setTrace(caller, void 0);
- this._generatorFunction = generatorFunction;
- this._receiver = receiver;
- this._generator = void 0;
- }
- PromiseSpawn.prototype.promise = function PromiseSpawn$promise() {
- return this._promise;
- };
- PromiseSpawn.prototype._run = function PromiseSpawn$_run() {
- this._generator = this._generatorFunction.call(this._receiver);
- this._receiver =
- this._generatorFunction = void 0;
- this._next(void 0);
- };
- PromiseSpawn.prototype._continue = function PromiseSpawn$_continue(result) {
- if (result === errorObj) {
- this._generator = void 0;
- var trace = errors.canAttach(result.e)
- ? result.e : new Error(result.e + "");
- this._promise._attachExtraTrace(trace);
- this._promise._reject(result.e, trace);
- return;
- }
- var value = result.value;
- if (result.done === true) {
- this._generator = void 0;
- if (!this._promise._tryFollow(value)) {
- this._promise._fulfill(value);
- }
- }
- else {
- var maybePromise = Promise._cast(value, PromiseSpawn$_continue, void 0);
- if (!(maybePromise instanceof Promise)) {
- if (isArray(maybePromise)) {
- maybePromise = Promise.all(maybePromise);
- }
- else {
- maybePromise = promiseFromYieldHandler(maybePromise);
- }
- if (maybePromise === null) {
- this._throw(new TypeError("A value was yielded that could not be treated as a promise"));
- return;
- }
- }
- maybePromise._then(
- this._next,
- this._throw,
- void 0,
- this,
- null,
- void 0
- );
- }
- };
- PromiseSpawn.prototype._throw = function PromiseSpawn$_throw(reason) {
- if (errors.canAttach(reason))
- this._promise._attachExtraTrace(reason);
- this._continue(
- tryCatch1(this._generator["throw"], this._generator, reason)
- );
- };
- PromiseSpawn.prototype._next = function PromiseSpawn$_next(value) {
- this._continue(
- tryCatch1(this._generator.next, this._generator, value)
- );
- };
- PromiseSpawn.addYieldHandler = function PromiseSpawn$AddYieldHandler(fn) {
- if (typeof fn !== "function") throw new TypeError("fn must be a function");
- yieldHandlers.push(fn);
- };
- return PromiseSpawn;
- };
- },{"./assert.js":2,"./errors.js":10,"./util.js":39}],25:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var THIS = {};
- var util = require("./util.js");
- var es5 = require("./es5.js");
- var nodebackForPromise = require("./promise_resolver.js")
- ._nodebackForPromise;
- var withAppended = util.withAppended;
- var maybeWrapAsError = util.maybeWrapAsError;
- var canEvaluate = util.canEvaluate;
- var notEnumerableProp = util.notEnumerableProp;
- var deprecated = util.deprecated;
- var ASSERT = require("./assert.js");
- var roriginal = new RegExp("__beforePromisified__" + "$");
- var hasProp = {}.hasOwnProperty;
- function isPromisified(fn) {
- return fn.__isPromisified__ === true;
- }
- var inheritedMethods = (function() {
- if (es5.isES5) {
- var create = Object.create;
- var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
- return function(cur) {
- var original = cur;
- var ret = [];
- var visitedKeys = create(null);
- while (cur !== null) {
- var keys = es5.keys(cur);
- for (var i = 0, len = keys.length; i < len; ++i) {
- var key = keys[i];
- if (visitedKeys[key] ||
- roriginal.test(key) ||
- hasProp.call(original, key + "__beforePromisified__")
- ) {
- continue;
- }
- visitedKeys[key] = true;
- var desc = getOwnPropertyDescriptor(cur, key);
- if (desc != null &&
- typeof desc.value === "function" &&
- !isPromisified(desc.value)) {
- ret.push(key, desc.value);
- }
- }
- cur = es5.getPrototypeOf(cur);
- }
- return ret;
- };
- }
- else {
- return function(obj) {
- var ret = [];
- /*jshint forin:false */
- for (var key in obj) {
- if (roriginal.test(key) ||
- hasProp.call(obj, key + "__beforePromisified__")) {
- continue;
- }
- var fn = obj[key];
- if (typeof fn === "function" &&
- !isPromisified(fn)) {
- ret.push(key, fn);
- }
- }
- return ret;
- };
- }
- })();
- function switchCaseArgumentOrder(likelyArgumentCount) {
- var ret = [likelyArgumentCount];
- var min = Math.max(0, likelyArgumentCount - 1 - 5);
- for(var i = likelyArgumentCount - 1; i >= min; --i) {
- if (i === likelyArgumentCount) continue;
- ret.push(i);
- }
- for(var i = likelyArgumentCount + 1; i <= 5; ++i) {
- ret.push(i);
- }
- return ret;
- }
- function parameterDeclaration(parameterCount) {
- var ret = new Array(parameterCount);
- for(var i = 0; i < ret.length; ++i) {
- ret[i] = "_arg" + i;
- }
- return ret.join(", ");
- }
- function parameterCount(fn) {
- if (typeof fn.length === "number") {
- return Math.max(Math.min(fn.length, 1023 + 1), 0);
- }
- return 0;
- }
- function propertyAccess(id) {
- var rident = /^[a-z$_][a-z$_0-9]*$/i;
- if (rident.test(id)) {
- return "." + id;
- }
- else return "['" + id.replace(/(['\\])/g, "\\$1") + "']";
- }
- function makeNodePromisifiedEval(callback, receiver, originalName, fn) {
- var newParameterCount = Math.max(0, parameterCount(fn) - 1);
- var argumentOrder = switchCaseArgumentOrder(newParameterCount);
- var callbackName = (typeof originalName === "string" ?
- originalName + "Async" :
- "promisified");
- function generateCallForArgumentCount(count) {
- var args = new Array(count);
- for (var i = 0, len = args.length; i < len; ++i) {
- args[i] = "arguments[" + i + "]";
- }
- var comma = count > 0 ? "," : "";
- if (typeof callback === "string" &&
- receiver === THIS) {
- return "this" + propertyAccess(callback) + "("+args.join(",") +
- comma +" fn);"+
- "break;";
- }
- return (receiver === void 0
- ? "callback("+args.join(",")+ comma +" fn);"
- : "callback.call("+(receiver === THIS
- ? "this"
- : "receiver")+", "+args.join(",") + comma + " fn);") +
- "break;";
- }
- function generateArgumentSwitchCase() {
- var ret = "";
- for(var i = 0; i < argumentOrder.length; ++i) {
- ret += "case " + argumentOrder[i] +":" +
- generateCallForArgumentCount(argumentOrder[i]);
- }
- ret += "default: var args = new Array(len + 1);" +
- "var i = 0;" +
- "for (var i = 0; i < len; ++i) { " +
- " args[i] = arguments[i];" +
- "}" +
- "args[i] = fn;" +
- (typeof callback === "string"
- ? "this" + propertyAccess(callback) + ".apply("
- : "callback.apply(") +
- (receiver === THIS ? "this" : "receiver") +
- ", args); break;";
- return ret;
- }
- return new Function("Promise", "callback", "receiver",
- "withAppended", "maybeWrapAsError", "nodebackForPromise",
- "INTERNAL",
- "var ret = function " + callbackName +
- "(" + parameterDeclaration(newParameterCount) + ") {\"use strict\";" +
- "var len = arguments.length;" +
- "var promise = new Promise(INTERNAL);"+
- "promise._setTrace(" + callbackName + ", void 0);" +
- "var fn = nodebackForPromise(promise);"+
- "try {" +
- "switch(len) {" +
- generateArgumentSwitchCase() +
- "}" +
- "}" +
- "catch(e){ " +
- "var wrapped = maybeWrapAsError(e);" +
- "promise._attachExtraTrace(wrapped);" +
- "promise._reject(wrapped);" +
- "}" +
- "return promise;" +
- "" +
- "}; ret.__isPromisified__ = true; return ret;"
- )(Promise, callback, receiver, withAppended,
- maybeWrapAsError, nodebackForPromise, INTERNAL);
- }
- function makeNodePromisifiedClosure(callback, receiver) {
- function promisified() {
- var _receiver = receiver;
- if (receiver === THIS) _receiver = this;
- if (typeof callback === "string") {
- callback = _receiver[callback];
- }
- var promise = new Promise(INTERNAL);
- promise._setTrace(promisified, void 0);
- var fn = nodebackForPromise(promise);
- try {
- callback.apply(_receiver, withAppended(arguments, fn));
- }
- catch(e) {
- var wrapped = maybeWrapAsError(e);
- promise._attachExtraTrace(wrapped);
- promise._reject(wrapped);
- }
- return promise;
- }
- promisified.__isPromisified__ = true;
- return promisified;
- }
- var makeNodePromisified = canEvaluate
- ? makeNodePromisifiedEval
- : makeNodePromisifiedClosure;
- function f(){}
- function _promisify(callback, receiver, isAll) {
- if (isAll) {
- var methods = inheritedMethods(callback);
- for (var i = 0, len = methods.length; i < len; i+= 2) {
- var key = methods[i];
- var fn = methods[i+1];
- var originalKey = key + "__beforePromisified__";
- var promisifiedKey = key + "Async";
- notEnumerableProp(callback, originalKey, fn);
- callback[promisifiedKey] =
- makeNodePromisified(originalKey, THIS,
- key, fn);
- }
- if (methods.length > 16) f.prototype = callback;
- return callback;
- }
- else {
- return makeNodePromisified(callback, receiver, void 0, callback);
- }
- }
- Promise.promisify = function Promise$Promisify(fn, receiver) {
- if (typeof fn === "object" && fn !== null) {
- deprecated("Promise.promisify for promisifying entire objects is deprecated. Use Promise.promisifyAll instead.");
- return _promisify(fn, receiver, true);
- }
- if (typeof fn !== "function") {
- throw new TypeError("fn must be a function");
- }
- if (isPromisified(fn)) {
- return fn;
- }
- return _promisify(
- fn,
- arguments.length < 2 ? THIS : receiver,
- false);
- };
- Promise.promisifyAll = function Promise$PromisifyAll(target) {
- if (typeof target !== "function" && typeof target !== "object") {
- throw new TypeError("the target of promisifyAll must be an object or a function");
- }
- return _promisify(target, void 0, true);
- };
- };
- },{"./assert.js":2,"./es5.js":12,"./promise_resolver.js":23,"./util.js":39}],26:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise, PromiseArray) {
- var ASSERT = require("./assert.js");
- var util = require("./util.js");
- var inherits = util.inherits;
- var es5 = require("./es5.js");
- function PropertiesPromiseArray(obj, caller, boundTo) {
- var keys = es5.keys(obj);
- var values = new Array(keys.length);
- for (var i = 0, len = values.length; i < len; ++i) {
- values[i] = obj[keys[i]];
- }
- this.constructor$(values, caller, boundTo);
- if (!this._isResolved()) {
- for (var i = 0, len = keys.length; i < len; ++i) {
- values.push(keys[i]);
- }
- }
- }
- inherits(PropertiesPromiseArray, PromiseArray);
- PropertiesPromiseArray.prototype._init =
- function PropertiesPromiseArray$_init() {
- this._init$(void 0, -3) ;
- };
- PropertiesPromiseArray.prototype._promiseFulfilled =
- function PropertiesPromiseArray$_promiseFulfilled(value, index) {
- if (this._isResolved()) return;
- this._values[index] = value;
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= this._length) {
- var val = {};
- var keyOffset = this.length();
- for (var i = 0, len = this.length(); i < len; ++i) {
- val[this._values[i + keyOffset]] = this._values[i];
- }
- this._resolve(val);
- }
- };
- PropertiesPromiseArray.prototype._promiseProgressed =
- function PropertiesPromiseArray$_promiseProgressed(value, index) {
- if (this._isResolved()) return;
- this._promise._progress({
- key: this._values[index + this.length()],
- value: value
- });
- };
- PromiseArray.PropertiesPromiseArray = PropertiesPromiseArray;
- return PropertiesPromiseArray;
- };
- },{"./assert.js":2,"./es5.js":12,"./util.js":39}],27:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise, PromiseArray) {
- var PropertiesPromiseArray = require("./properties_promise_array.js")(
- Promise, PromiseArray);
- var util = require("./util.js");
- var apiRejection = require("./errors_api_rejection")(Promise);
- var isObject = util.isObject;
- function Promise$_Props(promises, useBound, caller) {
- var ret;
- var castValue = Promise._cast(promises, caller, void 0);
- if (!isObject(castValue)) {
- return apiRejection("cannot await properties of a non-object");
- }
- else if (Promise.is(castValue)) {
- ret = castValue._then(Promise.props, void 0, void 0,
- void 0, void 0, caller);
- }
- else {
- ret = new PropertiesPromiseArray(
- castValue,
- caller,
- useBound === true && castValue._isBound()
- ? castValue._boundTo
- : void 0
- ).promise();
- useBound = false;
- }
- if (useBound === true && castValue._isBound()) {
- ret._setBoundTo(castValue._boundTo);
- }
- return ret;
- }
- Promise.prototype.props = function Promise$props() {
- return Promise$_Props(this, true, this.props);
- };
- Promise.props = function Promise$Props(promises) {
- return Promise$_Props(promises, false, Promise.props);
- };
- };
- },{"./errors_api_rejection":11,"./properties_promise_array.js":26,"./util.js":39}],28:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- var ASSERT = require("./assert.js");
- function arrayCopy(src, srcIndex, dst, dstIndex, len) {
- for (var j = 0; j < len; ++j) {
- dst[j + dstIndex] = src[j + srcIndex];
- }
- }
- function pow2AtLeast(n) {
- n = n >>> 0;
- n = n - 1;
- n = n | (n >> 1);
- n = n | (n >> 2);
- n = n | (n >> 4);
- n = n | (n >> 8);
- n = n | (n >> 16);
- return n + 1;
- }
- function getCapacity(capacity) {
- if (typeof capacity !== "number") return 16;
- return pow2AtLeast(
- Math.min(
- Math.max(16, capacity), 1073741824)
- );
- }
- function Queue(capacity) {
- this._capacity = getCapacity(capacity);
- this._length = 0;
- this._front = 0;
- this._makeCapacity();
- }
- Queue.prototype._willBeOverCapacity =
- function Queue$_willBeOverCapacity(size) {
- return this._capacity < size;
- };
- Queue.prototype._pushOne = function Queue$_pushOne(arg) {
- var length = this.length();
- this._checkCapacity(length + 1);
- var i = (this._front + length) & (this._capacity - 1);
- this[i] = arg;
- this._length = length + 1;
- };
- Queue.prototype.push = function Queue$push(fn, receiver, arg) {
- var length = this.length() + 3;
- if (this._willBeOverCapacity(length)) {
- this._pushOne(fn);
- this._pushOne(receiver);
- this._pushOne(arg);
- return;
- }
- var j = this._front + length - 3;
- this._checkCapacity(length);
- var wrapMask = this._capacity - 1;
- this[(j + 0) & wrapMask] = fn;
- this[(j + 1) & wrapMask] = receiver;
- this[(j + 2) & wrapMask] = arg;
- this._length = length;
- };
- Queue.prototype.shift = function Queue$shift() {
- var front = this._front,
- ret = this[front];
- this[front] = void 0;
- this._front = (front + 1) & (this._capacity - 1);
- this._length--;
- return ret;
- };
- Queue.prototype.length = function Queue$length() {
- return this._length;
- };
- Queue.prototype._makeCapacity = function Queue$_makeCapacity() {
- var len = this._capacity;
- for (var i = 0; i < len; ++i) {
- this[i] = void 0;
- }
- };
- Queue.prototype._checkCapacity = function Queue$_checkCapacity(size) {
- if (this._capacity < size) {
- this._resizeTo(this._capacity << 3);
- }
- };
- Queue.prototype._resizeTo = function Queue$_resizeTo(capacity) {
- var oldFront = this._front;
- var oldCapacity = this._capacity;
- var oldQueue = new Array(oldCapacity);
- var length = this.length();
- arrayCopy(this, 0, oldQueue, 0, oldCapacity);
- this._capacity = capacity;
- this._makeCapacity();
- this._front = 0;
- if (oldFront + length <= oldCapacity) {
- arrayCopy(oldQueue, oldFront, this, 0, length);
- }
- else { var lengthBeforeWrapping =
- length - ((oldFront + length) & (oldCapacity - 1));
- arrayCopy(oldQueue, oldFront, this, 0, lengthBeforeWrapping);
- arrayCopy(oldQueue, 0, this, lengthBeforeWrapping,
- length - lengthBeforeWrapping);
- }
- };
- module.exports = Queue;
- },{"./assert.js":2}],29:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var apiRejection = require("./errors_api_rejection.js")(Promise);
- var isArray = require("./util.js").isArray;
- var raceLater = function Promise$_raceLater(promise) {
- return promise.then(function Promise$_lateRacer(array) {
- return Promise$_Race(array, Promise$_lateRacer, promise);
- });
- };
- var hasOwn = {}.hasOwnProperty;
- function Promise$_Race(promises, caller, parent) {
- var maybePromise = Promise._cast(promises, caller, void 0);
- if (Promise.is(maybePromise)) {
- return raceLater(maybePromise);
- }
- else if (!isArray(promises)) {
- return apiRejection("expecting an array, a promise or a thenable");
- }
- var ret = new Promise(INTERNAL);
- ret._setTrace(caller, parent);
- if (parent !== void 0) {
- if (parent._isBound()) {
- ret._setBoundTo(parent._boundTo);
- }
- if (parent._cancellable()) {
- ret._setCancellable();
- ret._cancellationParent = parent;
- }
- }
- var fulfill = ret._fulfill;
- var reject = ret._reject;
- for (var i = 0, len = promises.length; i < len; ++i) {
- var val = promises[i];
- if (val === void 0 && !(hasOwn.call(promises, i))) {
- continue;
- }
- Promise.cast(val)._then(
- fulfill,
- reject,
- void 0,
- ret,
- null,
- caller
- );
- }
- return ret;
- }
- Promise.race = function Promise$Race(promises) {
- return Promise$_Race(promises, Promise.race, void 0);
- };
- Promise.prototype.race = function Promise$race() {
- return Promise$_Race(this, this.race, void 0);
- };
- };
- },{"./errors_api_rejection.js":11,"./util.js":39}],30:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(
- Promise, Promise$_CreatePromiseArray,
- PromiseArray, apiRejection, INTERNAL) {
- var ASSERT = require("./assert.js");
- function Reduction(callback, index, accum, items, receiver) {
- this.promise = new Promise(INTERNAL);
- this.index = index;
- this.length = items.length;
- this.items = items;
- this.callback = callback;
- this.receiver = receiver;
- this.accum = accum;
- }
- Reduction.prototype.reject = function Reduction$reject(e) {
- this.promise._reject(e);
- };
- Reduction.prototype.fulfill = function Reduction$fulfill(value, index) {
- this.accum = value;
- this.index = index + 1;
- this.iterate();
- };
- Reduction.prototype.iterate = function Reduction$iterate() {
- var i = this.index;
- var len = this.length;
- var items = this.items;
- var result = this.accum;
- var receiver = this.receiver;
- var callback = this.callback;
- var iterate = this.iterate;
- for(; i < len; ++i) {
- result = Promise._cast(
- callback.call(
- receiver,
- result,
- items[i],
- i,
- len
- ),
- iterate,
- void 0
- );
- if (result instanceof Promise) {
- result._then(
- this.fulfill, this.reject, void 0, this, i, iterate);
- return;
- }
- }
- this.promise._fulfill(result);
- };
- function Promise$_reducer(fulfilleds, initialValue) {
- var fn = this;
- var receiver = void 0;
- if (typeof fn !== "function") {
- receiver = fn.receiver;
- fn = fn.fn;
- }
- var len = fulfilleds.length;
- var accum = void 0;
- var startIndex = 0;
- if (initialValue !== void 0) {
- accum = initialValue;
- startIndex = 0;
- }
- else {
- startIndex = 1;
- if (len > 0) accum = fulfilleds[0];
- }
- var i = startIndex;
- if (i >= len) {
- return accum;
- }
- var reduction = new Reduction(fn, i, accum, fulfilleds, receiver);
- reduction.iterate();
- return reduction.promise;
- }
- function Promise$_unpackReducer(fulfilleds) {
- var fn = this.fn;
- var initialValue = this.initialValue;
- return Promise$_reducer.call(fn, fulfilleds, initialValue);
- }
- function Promise$_slowReduce(
- promises, fn, initialValue, useBound, caller) {
- return initialValue._then(function callee(initialValue) {
- return Promise$_Reduce(
- promises, fn, initialValue, useBound, callee);
- }, void 0, void 0, void 0, void 0, caller);
- }
- function Promise$_Reduce(promises, fn, initialValue, useBound, caller) {
- if (typeof fn !== "function") {
- return apiRejection("fn must be a function");
- }
- if (useBound === true && promises._isBound()) {
- fn = {
- fn: fn,
- receiver: promises._boundTo
- };
- }
- if (initialValue !== void 0) {
- if (Promise.is(initialValue)) {
- if (initialValue.isFulfilled()) {
- initialValue = initialValue._settledValue;
- }
- else {
- return Promise$_slowReduce(promises,
- fn, initialValue, useBound, caller);
- }
- }
- return Promise$_CreatePromiseArray(promises, PromiseArray, caller,
- useBound === true && promises._isBound()
- ? promises._boundTo
- : void 0)
- .promise()
- ._then(Promise$_unpackReducer, void 0, void 0, {
- fn: fn,
- initialValue: initialValue
- }, void 0, Promise.reduce);
- }
- return Promise$_CreatePromiseArray(promises, PromiseArray, caller,
- useBound === true && promises._isBound()
- ? promises._boundTo
- : void 0).promise()
- ._then(Promise$_reducer, void 0, void 0, fn, void 0, caller);
- }
- Promise.reduce = function Promise$Reduce(promises, fn, initialValue) {
- return Promise$_Reduce(promises, fn,
- initialValue, false, Promise.reduce);
- };
- Promise.prototype.reduce = function Promise$reduce(fn, initialValue) {
- return Promise$_Reduce(this, fn, initialValue,
- true, this.reduce);
- };
- };
- },{"./assert.js":2}],31:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- var global = require("./global.js");
- var ASSERT = require("./assert.js");
- var schedule;
- if (typeof process !== "undefined" && process !== null &&
- typeof process.cwd === "function" &&
- typeof process.nextTick === "function" &&
- typeof process.version === "string") {
- schedule = function Promise$_Scheduler(fn) {
- process.nextTick(fn);
- };
- }
- else if ((typeof global.MutationObserver === "function" ||
- typeof global.WebkitMutationObserver === "function" ||
- typeof global.WebKitMutationObserver === "function") &&
- typeof document !== "undefined" &&
- typeof document.createElement === "function") {
- schedule = (function(){
- var MutationObserver = global.MutationObserver ||
- global.WebkitMutationObserver ||
- global.WebKitMutationObserver;
- var div = document.createElement("div");
- var queuedFn = void 0;
- var observer = new MutationObserver(
- function Promise$_Scheduler() {
- var fn = queuedFn;
- queuedFn = void 0;
- fn();
- }
- );
- observer.observe(div, {
- attributes: true
- });
- return function Promise$_Scheduler(fn) {
- queuedFn = fn;
- div.setAttribute("class", "foo");
- };
- })();
- }
- else if (typeof global.postMessage === "function" &&
- typeof global.importScripts !== "function" &&
- typeof global.addEventListener === "function" &&
- typeof global.removeEventListener === "function") {
- var MESSAGE_KEY = "bluebird_message_key_" + Math.random();
- schedule = (function(){
- var queuedFn = void 0;
- function Promise$_Scheduler(e) {
- if (e.source === global &&
- e.data === MESSAGE_KEY) {
- var fn = queuedFn;
- queuedFn = void 0;
- fn();
- }
- }
- global.addEventListener("message", Promise$_Scheduler, false);
- return function Promise$_Scheduler(fn) {
- queuedFn = fn;
- global.postMessage(
- MESSAGE_KEY, "*"
- );
- };
- })();
- }
- else if (typeof global.MessageChannel === "function") {
- schedule = (function(){
- var queuedFn = void 0;
- var channel = new global.MessageChannel();
- channel.port1.onmessage = function Promise$_Scheduler() {
- var fn = queuedFn;
- queuedFn = void 0;
- fn();
- };
- return function Promise$_Scheduler(fn) {
- queuedFn = fn;
- channel.port2.postMessage(null);
- };
- })();
- }
- else if (global.setTimeout) {
- schedule = function Promise$_Scheduler(fn) {
- setTimeout(fn, 4);
- };
- }
- else {
- schedule = function Promise$_Scheduler(fn) {
- fn();
- };
- }
- module.exports = schedule;
- },{"./assert.js":2,"./global.js":16}],32:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports =
- function(Promise, Promise$_CreatePromiseArray, PromiseArray) {
- var SettledPromiseArray = require("./settled_promise_array.js")(
- Promise, PromiseArray);
- function Promise$_Settle(promises, useBound, caller) {
- return Promise$_CreatePromiseArray(
- promises,
- SettledPromiseArray,
- caller,
- useBound === true && promises._isBound()
- ? promises._boundTo
- : void 0
- ).promise();
- }
- Promise.settle = function Promise$Settle(promises) {
- return Promise$_Settle(promises, false, Promise.settle);
- };
- Promise.prototype.settle = function Promise$settle() {
- return Promise$_Settle(this, true, this.settle);
- };
- };
- },{"./settled_promise_array.js":33}],33:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise, PromiseArray) {
- var ASSERT = require("./assert.js");
- var PromiseInspection = require("./promise_inspection.js");
- var util = require("./util.js");
- var inherits = util.inherits;
- function SettledPromiseArray(values, caller, boundTo) {
- this.constructor$(values, caller, boundTo);
- }
- inherits(SettledPromiseArray, PromiseArray);
- SettledPromiseArray.prototype._promiseResolved =
- function SettledPromiseArray$_promiseResolved(index, inspection) {
- this._values[index] = inspection;
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= this._length) {
- this._resolve(this._values);
- }
- };
- SettledPromiseArray.prototype._promiseFulfilled =
- function SettledPromiseArray$_promiseFulfilled(value, index) {
- if (this._isResolved()) return;
- var ret = new PromiseInspection();
- ret._bitField = 268435456;
- ret._settledValue = value;
- this._promiseResolved(index, ret);
- };
- SettledPromiseArray.prototype._promiseRejected =
- function SettledPromiseArray$_promiseRejected(reason, index) {
- if (this._isResolved()) return;
- var ret = new PromiseInspection();
- ret._bitField = 134217728;
- ret._settledValue = reason;
- this._promiseResolved(index, ret);
- };
- return SettledPromiseArray;
- };
- },{"./assert.js":2,"./promise_inspection.js":22,"./util.js":39}],34:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports =
- function(Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection) {
- var SomePromiseArray = require("./some_promise_array.js")(PromiseArray);
- var ASSERT = require("./assert.js");
- function Promise$_Some(promises, howMany, useBound, caller) {
- if ((howMany | 0) !== howMany || howMany < 0) {
- return apiRejection("expecting a positive integer");
- }
- var ret = Promise$_CreatePromiseArray(
- promises,
- SomePromiseArray,
- caller,
- useBound === true && promises._isBound()
- ? promises._boundTo
- : void 0
- );
- var promise = ret.promise();
- if (promise.isRejected()) {
- return promise;
- }
- ret.setHowMany(howMany);
- ret.init();
- return promise;
- }
- Promise.some = function Promise$Some(promises, howMany) {
- return Promise$_Some(promises, howMany, false, Promise.some);
- };
- Promise.prototype.some = function Promise$some(count) {
- return Promise$_Some(this, count, true, this.some);
- };
- };
- },{"./assert.js":2,"./some_promise_array.js":35}],35:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function (PromiseArray) {
- var util = require("./util.js");
- var RangeError = require("./errors.js").RangeError;
- var inherits = util.inherits;
- var isArray = util.isArray;
- function SomePromiseArray(values, caller, boundTo) {
- this.constructor$(values, caller, boundTo);
- this._howMany = 0;
- this._unwrap = false;
- this._initialized = false;
- }
- inherits(SomePromiseArray, PromiseArray);
- SomePromiseArray.prototype._init = function SomePromiseArray$_init() {
- if (!this._initialized) {
- return;
- }
- if (this._howMany === 0) {
- this._resolve([]);
- return;
- }
- this._init$(void 0, -2);
- var isArrayResolved = isArray(this._values);
- this._holes = isArrayResolved ? this._values.length - this.length() : 0;
- if (!this._isResolved() &&
- isArrayResolved &&
- this._howMany > this._canPossiblyFulfill()) {
- var message = "(Promise.some) input array contains less than " +
- this._howMany + " promises";
- this._reject(new RangeError(message));
- }
- };
- SomePromiseArray.prototype.init = function SomePromiseArray$init() {
- this._initialized = true;
- this._init();
- };
- SomePromiseArray.prototype.setUnwrap = function SomePromiseArray$setUnwrap() {
- this._unwrap = true;
- };
- SomePromiseArray.prototype.howMany = function SomePromiseArray$howMany() {
- return this._howMany;
- };
- SomePromiseArray.prototype.setHowMany =
- function SomePromiseArray$setHowMany(count) {
- if (this._isResolved()) return;
- this._howMany = count;
- };
- SomePromiseArray.prototype._promiseFulfilled =
- function SomePromiseArray$_promiseFulfilled(value) {
- if (this._isResolved()) return;
- this._addFulfilled(value);
- if (this._fulfilled() === this.howMany()) {
- this._values.length = this.howMany();
- if (this.howMany() === 1 && this._unwrap) {
- this._resolve(this._values[0]);
- }
- else {
- this._resolve(this._values);
- }
- }
- };
- SomePromiseArray.prototype._promiseRejected =
- function SomePromiseArray$_promiseRejected(reason) {
- if (this._isResolved()) return;
- this._addRejected(reason);
- if (this.howMany() > this._canPossiblyFulfill()) {
- if (this._values.length === this.length()) {
- this._reject([]);
- }
- else {
- this._reject(this._values.slice(this.length() + this._holes));
- }
- }
- };
- SomePromiseArray.prototype._fulfilled = function SomePromiseArray$_fulfilled() {
- return this._totalResolved;
- };
- SomePromiseArray.prototype._rejected = function SomePromiseArray$_rejected() {
- return this._values.length - this.length() - this._holes;
- };
- SomePromiseArray.prototype._addRejected =
- function SomePromiseArray$_addRejected(reason) {
- this._values.push(reason);
- };
- SomePromiseArray.prototype._addFulfilled =
- function SomePromiseArray$_addFulfilled(value) {
- this._values[this._totalResolved++] = value;
- };
- SomePromiseArray.prototype._canPossiblyFulfill =
- function SomePromiseArray$_canPossiblyFulfill() {
- return this.length() - this._rejected();
- };
- return SomePromiseArray;
- };
- },{"./errors.js":10,"./util.js":39}],36:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise) {
- var PromiseInspection = require("./promise_inspection.js");
- Promise.prototype.inspect = function Promise$inspect() {
- return new PromiseInspection(this);
- };
- };
- },{"./promise_inspection.js":22}],37:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var ASSERT = require("./assert.js");
- var util = require("./util.js");
- var canAttach = require("./errors.js").canAttach;
- var errorObj = util.errorObj;
- var isObject = util.isObject;
- function getThen(obj) {
- try {
- return obj.then;
- }
- catch(e) {
- errorObj.e = e;
- return errorObj;
- }
- }
- function Promise$_Cast(obj, caller, originalPromise) {
- if (isObject(obj)) {
- if (obj instanceof Promise) {
- return obj;
- }
- else if (isAnyBluebirdPromise(obj)) {
- var ret = new Promise(INTERNAL);
- ret._setTrace(caller, void 0);
- obj._then(
- ret._fulfillUnchecked,
- ret._rejectUncheckedCheckError,
- ret._progressUnchecked,
- ret,
- null,
- void 0
- );
- ret._setFollowing();
- return ret;
- }
- var then = getThen(obj);
- if (then === errorObj) {
- caller = typeof caller === "function" ? caller : Promise$_Cast;
- if (originalPromise !== void 0 && canAttach(then.e)) {
- originalPromise._attachExtraTrace(then.e);
- }
- return Promise.reject(then.e, caller);
- }
- else if (typeof then === "function") {
- caller = typeof caller === "function" ? caller : Promise$_Cast;
- return Promise$_doThenable(obj, then, caller, originalPromise);
- }
- }
- return obj;
- }
- var hasProp = {}.hasOwnProperty;
- function isAnyBluebirdPromise(obj) {
- return hasProp.call(obj, "_promise0");
- }
- function Promise$_doThenable(x, then, caller, originalPromise) {
- var resolver = Promise.defer(caller);
- var called = false;
- try {
- then.call(
- x,
- Promise$_resolveFromThenable,
- Promise$_rejectFromThenable,
- Promise$_progressFromThenable
- );
- }
- catch(e) {
- if (!called) {
- called = true;
- var trace = canAttach(e) ? e : new Error(e + "");
- if (originalPromise !== void 0) {
- originalPromise._attachExtraTrace(trace);
- }
- resolver.promise._reject(e, trace);
- }
- }
- return resolver.promise;
- function Promise$_resolveFromThenable(y) {
- if (called) return;
- called = true;
- if (x === y) {
- var e = Promise._makeSelfResolutionError();
- if (originalPromise !== void 0) {
- originalPromise._attachExtraTrace(e);
- }
- resolver.promise._reject(e, void 0);
- return;
- }
- resolver.resolve(y);
- }
- function Promise$_rejectFromThenable(r) {
- if (called) return;
- called = true;
- var trace = canAttach(r) ? r : new Error(r + "");
- if (originalPromise !== void 0) {
- originalPromise._attachExtraTrace(trace);
- }
- resolver.promise._reject(r, trace);
- }
- function Promise$_progressFromThenable(v) {
- if (called) return;
- var promise = resolver.promise;
- if (typeof promise._progress === "function") {
- promise._progress(v);
- }
- }
- }
- Promise._cast = Promise$_Cast;
- };
- },{"./assert.js":2,"./errors.js":10,"./util.js":39}],38:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- var global = require("./global.js");
- var setTimeout = function(fn, time) {
- var $_len = arguments.length;var args = new Array($_len - 2); for(var $_i = 2; $_i < $_len; ++$_i) {args[$_i - 2] = arguments[$_i];}
- global.setTimeout(function() {
- fn.apply(void 0, args);
- }, time);
- };
- var pass = {};
- global.setTimeout( function(_) {
- if(_ === pass) {
- setTimeout = global.setTimeout;
- }
- }, 1, pass);
- module.exports = function(Promise, INTERNAL) {
- var util = require("./util.js");
- var ASSERT = require("./assert.js");
- var errors = require("./errors.js");
- var apiRejection = require("./errors_api_rejection")(Promise);
- var TimeoutError = Promise.TimeoutError;
- var afterTimeout = function Promise$_afterTimeout(promise, message, ms) {
- if (!promise.isPending()) return;
- if (typeof message !== "string") {
- message = "operation timed out after" + " " + ms + " ms"
- }
- var err = new TimeoutError(message);
- errors.markAsOriginatingFromRejection(err);
- promise._attachExtraTrace(err);
- promise._rejectUnchecked(err);
- };
- var afterDelay = function Promise$_afterDelay(value, promise) {
- promise._fulfill(value);
- };
- Promise.delay = function Promise$Delay(value, ms, caller) {
- if (ms === void 0) {
- ms = value;
- value = void 0;
- }
- ms = +ms;
- if (typeof caller !== "function") {
- caller = Promise.delay;
- }
- var maybePromise = Promise._cast(value, caller, void 0);
- var promise = new Promise(INTERNAL);
- if (Promise.is(maybePromise)) {
- if (maybePromise._isBound()) {
- promise._setBoundTo(maybePromise._boundTo);
- }
- if (maybePromise._cancellable()) {
- promise._setCancellable();
- promise._cancellationParent = maybePromise;
- }
- promise._setTrace(caller, maybePromise);
- promise._follow(maybePromise);
- return promise.then(function(value) {
- return Promise.delay(value, ms);
- });
- }
- else {
- promise._setTrace(caller, void 0);
- setTimeout(afterDelay, ms, value, promise);
- }
- return promise;
- };
- Promise.prototype.delay = function Promise$delay(ms) {
- return Promise.delay(this, ms, this.delay);
- };
- Promise.prototype.timeout = function Promise$timeout(ms, message) {
- ms = +ms;
- var ret = new Promise(INTERNAL);
- ret._setTrace(this.timeout, this);
- if (this._isBound()) ret._setBoundTo(this._boundTo);
- if (this._cancellable()) {
- ret._setCancellable();
- ret._cancellationParent = this;
- }
- ret._follow(this);
- setTimeout(afterTimeout, ms, ret, message, ms);
- return ret;
- };
- };
- },{"./assert.js":2,"./errors.js":10,"./errors_api_rejection":11,"./global.js":16,"./util.js":39}],39:[function(require,module,exports){
- /**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:</p>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- "use strict";
- var global = require("./global.js");
- var ASSERT = require("./assert.js");
- var es5 = require("./es5.js");
- var haveGetters = (function(){
- try {
- var o = {};
- es5.defineProperty(o, "f", {
- get: function () {
- return 3;
- }
- });
- return o.f === 3;
- }
- catch (e) {
- return false;
- }
- })();
- var canEvaluate = (function() {
- if (typeof window !== "undefined" && window !== null &&
- typeof window.document !== "undefined" &&
- typeof navigator !== "undefined" && navigator !== null &&
- typeof navigator.appName === "string" &&
- window === global) {
- return false;
- }
- return true;
- })();
- function deprecated(msg) {
- if (typeof console !== "undefined" && console !== null &&
- typeof console.warn === "function") {
- console.warn("Bluebird: " + msg);
- }
- }
- var errorObj = {e: {}};
- function tryCatch1(fn, receiver, arg) {
- try {
- return fn.call(receiver, arg);
- }
- catch (e) {
- errorObj.e = e;
- return errorObj;
- }
- }
- function tryCatch2(fn, receiver, arg, arg2) {
- try {
- return fn.call(receiver, arg, arg2);
- }
- catch (e) {
- errorObj.e = e;
- return errorObj;
- }
- }
- function tryCatchApply(fn, args, receiver) {
- try {
- return fn.apply(receiver, args);
- }
- catch (e) {
- errorObj.e = e;
- return errorObj;
- }
- }
- var inherits = function(Child, Parent) {
- var hasProp = {}.hasOwnProperty;
- function T() {
- this.constructor = Child;
- this.constructor$ = Parent;
- for (var propertyName in Parent.prototype) {
- if (hasProp.call(Parent.prototype, propertyName) &&
- propertyName.charAt(propertyName.length-1) !== "$"
- ) {
- this[propertyName + "$"] = Parent.prototype[propertyName];
- }
- }
- }
- T.prototype = Parent.prototype;
- Child.prototype = new T();
- return Child.prototype;
- };
- function asString(val) {
- return typeof val === "string" ? val : ("" + val);
- }
- function isPrimitive(val) {
- return val == null || val === true || val === false ||
- typeof val === "string" || typeof val === "number";
- }
- function isObject(value) {
- return !isPrimitive(value);
- }
- function maybeWrapAsError(maybeError) {
- if (!isPrimitive(maybeError)) return maybeError;
- return new Error(asString(maybeError));
- }
- function withAppended(target, appendee) {
- var len = target.length;
- var ret = new Array(len + 1);
- var i;
- for (i = 0; i < len; ++i) {
- ret[i] = target[i];
- }
- ret[i] = appendee;
- return ret;
- }
- function notEnumerableProp(obj, name, value) {
- var descriptor = {
- value: value,
- configurable: true,
- enumerable: false,
- writable: true
- };
- es5.defineProperty(obj, name, descriptor);
- return obj;
- }
- var wrapsPrimitiveReceiver = (function() {
- return this !== "string";
- }).call("string");
- function thrower(r) {
- throw r;
- }
- var ret = {
- thrower: thrower,
- isArray: es5.isArray,
- haveGetters: haveGetters,
- notEnumerableProp: notEnumerableProp,
- isPrimitive: isPrimitive,
- isObject: isObject,
- canEvaluate: canEvaluate,
- deprecated: deprecated,
- errorObj: errorObj,
- tryCatch1: tryCatch1,
- tryCatch2: tryCatch2,
- tryCatchApply: tryCatchApply,
- inherits: inherits,
- withAppended: withAppended,
- asString: asString,
- maybeWrapAsError: maybeWrapAsError,
- wrapsPrimitiveReceiver: wrapsPrimitiveReceiver
- };
- module.exports = ret;
- },{"./assert.js":2,"./es5.js":12,"./global.js":16}]},{},[4])
- (4)
- });
- ;
|