12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105 |
- /* @preserve
- * The MIT License (MIT)
- *
- * 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.
- *
- */
- /**
- * bluebird build version 2.9.26
- * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, cancel, using, filter, any, each, timers
- */
- !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Promise=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof _dereq_=="function"&&_dereq_;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise) {
- var SomePromiseArray = Promise._SomePromiseArray;
- function any(promises) {
- var ret = new SomePromiseArray(promises);
- var promise = ret.promise();
- ret.setHowMany(1);
- ret.setUnwrap();
- ret.init();
- return promise;
- }
- Promise.any = function (promises) {
- return any(promises);
- };
- Promise.prototype.any = function () {
- return any(this);
- };
- };
- },{}],2:[function(_dereq_,module,exports){
- "use strict";
- var firstLineError;
- try {throw new Error(); } catch (e) {firstLineError = e;}
- var schedule = _dereq_("./schedule.js");
- var Queue = _dereq_("./queue.js");
- var util = _dereq_("./util.js");
- function Async() {
- this._isTickUsed = false;
- this._lateQueue = new Queue(16);
- this._normalQueue = new Queue(16);
- this._trampolineEnabled = true;
- var self = this;
- this.drainQueues = function () {
- self._drainQueues();
- };
- this._schedule =
- schedule.isStatic ? schedule(this.drainQueues) : schedule;
- }
- Async.prototype.disableTrampolineIfNecessary = function() {
- if (util.hasDevTools) {
- this._trampolineEnabled = false;
- }
- };
- Async.prototype.enableTrampoline = function() {
- if (!this._trampolineEnabled) {
- this._trampolineEnabled = true;
- this._schedule = function(fn) {
- setTimeout(fn, 0);
- };
- }
- };
- Async.prototype.haveItemsQueued = function () {
- return this._normalQueue.length() > 0;
- };
- Async.prototype.throwLater = function(fn, arg) {
- if (arguments.length === 1) {
- arg = fn;
- fn = function () { throw arg; };
- }
- var domain = this._getDomain();
- if (domain !== undefined) fn = domain.bind(fn);
- if (typeof setTimeout !== "undefined") {
- setTimeout(function() {
- fn(arg);
- }, 0);
- } else try {
- this._schedule(function() {
- fn(arg);
- });
- } catch (e) {
- throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/m3OTXk\u000a");
- }
- };
- Async.prototype._getDomain = function() {};
- if (!true) {
- if (util.isNode) {
- var EventsModule = _dereq_("events");
- var domainGetter = function() {
- var domain = process.domain;
- if (domain === null) return undefined;
- return domain;
- };
- if (EventsModule.usingDomains) {
- Async.prototype._getDomain = domainGetter;
- } else {
- var descriptor =
- Object.getOwnPropertyDescriptor(EventsModule, "usingDomains");
- if (descriptor) {
- if (!descriptor.configurable) {
- process.on("domainsActivated", function() {
- Async.prototype._getDomain = domainGetter;
- });
- } else {
- var usingDomains = false;
- Object.defineProperty(EventsModule, "usingDomains", {
- configurable: false,
- enumerable: true,
- get: function() {
- return usingDomains;
- },
- set: function(value) {
- if (usingDomains || !value) return;
- usingDomains = true;
- Async.prototype._getDomain = domainGetter;
- util.toFastProperties(process);
- process.emit("domainsActivated");
- }
- });
- }
- }
- }
- }
- }
- function AsyncInvokeLater(fn, receiver, arg) {
- var domain = this._getDomain();
- if (domain !== undefined) fn = domain.bind(fn);
- this._lateQueue.push(fn, receiver, arg);
- this._queueTick();
- }
- function AsyncInvoke(fn, receiver, arg) {
- var domain = this._getDomain();
- if (domain !== undefined) fn = domain.bind(fn);
- this._normalQueue.push(fn, receiver, arg);
- this._queueTick();
- }
- function AsyncSettlePromises(promise) {
- var domain = this._getDomain();
- if (domain !== undefined) {
- var fn = domain.bind(promise._settlePromises);
- this._normalQueue.push(fn, promise, undefined);
- } else {
- this._normalQueue._pushOne(promise);
- }
- this._queueTick();
- }
- if (!util.hasDevTools) {
- Async.prototype.invokeLater = AsyncInvokeLater;
- Async.prototype.invoke = AsyncInvoke;
- Async.prototype.settlePromises = AsyncSettlePromises;
- } else {
- Async.prototype.invokeLater = function (fn, receiver, arg) {
- if (this._trampolineEnabled) {
- AsyncInvokeLater.call(this, fn, receiver, arg);
- } else {
- setTimeout(function() {
- fn.call(receiver, arg);
- }, 100);
- }
- };
- Async.prototype.invoke = function (fn, receiver, arg) {
- if (this._trampolineEnabled) {
- AsyncInvoke.call(this, fn, receiver, arg);
- } else {
- setTimeout(function() {
- fn.call(receiver, arg);
- }, 0);
- }
- };
- Async.prototype.settlePromises = function(promise) {
- if (this._trampolineEnabled) {
- AsyncSettlePromises.call(this, promise);
- } else {
- setTimeout(function() {
- promise._settlePromises();
- }, 0);
- }
- };
- }
- Async.prototype.invokeFirst = function (fn, receiver, arg) {
- var domain = this._getDomain();
- if (domain !== undefined) fn = domain.bind(fn);
- this._normalQueue.unshift(fn, receiver, arg);
- this._queueTick();
- };
- Async.prototype._drainQueue = function(queue) {
- while (queue.length() > 0) {
- var fn = queue.shift();
- if (typeof fn !== "function") {
- fn._settlePromises();
- continue;
- }
- var receiver = queue.shift();
- var arg = queue.shift();
- fn.call(receiver, arg);
- }
- };
- Async.prototype._drainQueues = function () {
- this._drainQueue(this._normalQueue);
- this._reset();
- this._drainQueue(this._lateQueue);
- };
- Async.prototype._queueTick = function () {
- if (!this._isTickUsed) {
- this._isTickUsed = true;
- this._schedule(this.drainQueues);
- }
- };
- Async.prototype._reset = function () {
- this._isTickUsed = false;
- };
- module.exports = new Async();
- module.exports.firstLineError = firstLineError;
- },{"./queue.js":28,"./schedule.js":31,"./util.js":38,"events":39}],3:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL, tryConvertToPromise) {
- var rejectThis = function(_, e) {
- this._reject(e);
- };
- var targetRejected = function(e, context) {
- context.promiseRejectionQueued = true;
- context.bindingPromise._then(rejectThis, rejectThis, null, this, e);
- };
- var bindingResolved = function(thisArg, context) {
- this._setBoundTo(thisArg);
- if (this._isPending()) {
- this._resolveCallback(context.target);
- }
- };
- var bindingRejected = function(e, context) {
- if (!context.promiseRejectionQueued) this._reject(e);
- };
- Promise.prototype.bind = function (thisArg) {
- var maybePromise = tryConvertToPromise(thisArg);
- var ret = new Promise(INTERNAL);
- ret._propagateFrom(this, 1);
- var target = this._target();
- if (maybePromise instanceof Promise) {
- var context = {
- promiseRejectionQueued: false,
- promise: ret,
- target: target,
- bindingPromise: maybePromise
- };
- target._then(INTERNAL, targetRejected, ret._progress, ret, context);
- maybePromise._then(
- bindingResolved, bindingRejected, ret._progress, ret, context);
- } else {
- ret._setBoundTo(thisArg);
- ret._resolveCallback(target);
- }
- return ret;
- };
- Promise.prototype._setBoundTo = function (obj) {
- if (obj !== undefined) {
- this._bitField = this._bitField | 131072;
- this._boundTo = obj;
- } else {
- this._bitField = this._bitField & (~131072);
- }
- };
- Promise.prototype._isBound = function () {
- return (this._bitField & 131072) === 131072;
- };
- Promise.bind = function (thisArg, value) {
- var maybePromise = tryConvertToPromise(thisArg);
- var ret = new Promise(INTERNAL);
- if (maybePromise instanceof Promise) {
- maybePromise._then(function(thisArg) {
- ret._setBoundTo(thisArg);
- ret._resolveCallback(value);
- }, ret._reject, ret._progress, ret, null);
- } else {
- ret._setBoundTo(thisArg);
- ret._resolveCallback(value);
- }
- return ret;
- };
- };
- },{}],4:[function(_dereq_,module,exports){
- "use strict";
- var old;
- if (typeof Promise !== "undefined") old = Promise;
- function noConflict() {
- try { if (Promise === bluebird) Promise = old; }
- catch (e) {}
- return bluebird;
- }
- var bluebird = _dereq_("./promise.js")();
- bluebird.noConflict = noConflict;
- module.exports = bluebird;
- },{"./promise.js":23}],5:[function(_dereq_,module,exports){
- "use strict";
- var cr = Object.create;
- if (cr) {
- var callerCache = cr(null);
- var getterCache = cr(null);
- callerCache[" size"] = getterCache[" size"] = 0;
- }
- module.exports = function(Promise) {
- var util = _dereq_("./util.js");
- var canEvaluate = util.canEvaluate;
- var isIdentifier = util.isIdentifier;
- var getMethodCaller;
- var getGetter;
- if (!true) {
- var makeMethodCaller = function (methodName) {
- return new Function("ensureMethod", " \n\
- return function(obj) { \n\
- 'use strict' \n\
- var len = this.length; \n\
- ensureMethod(obj, 'methodName'); \n\
- switch(len) { \n\
- case 1: return obj.methodName(this[0]); \n\
- case 2: return obj.methodName(this[0], this[1]); \n\
- case 3: return obj.methodName(this[0], this[1], this[2]); \n\
- case 0: return obj.methodName(); \n\
- default: \n\
- return obj.methodName.apply(obj, this); \n\
- } \n\
- }; \n\
- ".replace(/methodName/g, methodName))(ensureMethod);
- };
- var makeGetter = function (propertyName) {
- return new Function("obj", " \n\
- 'use strict'; \n\
- return obj.propertyName; \n\
- ".replace("propertyName", propertyName));
- };
- var getCompiled = function(name, compiler, cache) {
- var ret = cache[name];
- if (typeof ret !== "function") {
- if (!isIdentifier(name)) {
- return null;
- }
- ret = compiler(name);
- cache[name] = ret;
- cache[" size"]++;
- if (cache[" size"] > 512) {
- var keys = Object.keys(cache);
- for (var i = 0; i < 256; ++i) delete cache[keys[i]];
- cache[" size"] = keys.length - 256;
- }
- }
- return ret;
- };
- getMethodCaller = function(name) {
- return getCompiled(name, makeMethodCaller, callerCache);
- };
- getGetter = function(name) {
- return getCompiled(name, makeGetter, getterCache);
- };
- }
- function ensureMethod(obj, methodName) {
- var fn;
- if (obj != null) fn = obj[methodName];
- if (typeof fn !== "function") {
- var message = "Object " + util.classString(obj) + " has no method '" +
- util.toString(methodName) + "'";
- throw new Promise.TypeError(message);
- }
- return fn;
- }
- function caller(obj) {
- var methodName = this.pop();
- var fn = ensureMethod(obj, methodName);
- return fn.apply(obj, this);
- }
- Promise.prototype.call = function (methodName) {
- var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
- if (!true) {
- if (canEvaluate) {
- var maybeCaller = getMethodCaller(methodName);
- if (maybeCaller !== null) {
- return this._then(
- maybeCaller, undefined, undefined, args, undefined);
- }
- }
- }
- args.push(methodName);
- return this._then(caller, undefined, undefined, args, undefined);
- };
- function namedGetter(obj) {
- return obj[this];
- }
- function indexedGetter(obj) {
- var index = +this;
- if (index < 0) index = Math.max(0, index + obj.length);
- return obj[index];
- }
- Promise.prototype.get = function (propertyName) {
- var isIndex = (typeof propertyName === "number");
- var getter;
- if (!isIndex) {
- if (canEvaluate) {
- var maybeGetter = getGetter(propertyName);
- getter = maybeGetter !== null ? maybeGetter : namedGetter;
- } else {
- getter = namedGetter;
- }
- } else {
- getter = indexedGetter;
- }
- return this._then(getter, undefined, undefined, propertyName, undefined);
- };
- };
- },{"./util.js":38}],6:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise) {
- var errors = _dereq_("./errors.js");
- var async = _dereq_("./async.js");
- var CancellationError = errors.CancellationError;
- Promise.prototype._cancel = function (reason) {
- if (!this.isCancellable()) return this;
- var parent;
- var promiseToReject = this;
- while ((parent = promiseToReject._cancellationParent) !== undefined &&
- parent.isCancellable()) {
- promiseToReject = parent;
- }
- this._unsetCancellable();
- promiseToReject._target()._rejectCallback(reason, false, true);
- };
- Promise.prototype.cancel = function (reason) {
- if (!this.isCancellable()) return this;
- if (reason === undefined) reason = new CancellationError();
- async.invokeLater(this._cancel, this, reason);
- return this;
- };
- Promise.prototype.cancellable = function () {
- if (this._cancellable()) return this;
- async.enableTrampoline();
- this._setCancellable();
- this._cancellationParent = undefined;
- return this;
- };
- Promise.prototype.uncancellable = function () {
- var ret = this.then();
- ret._unsetCancellable();
- return ret;
- };
- Promise.prototype.fork = function (didFulfill, didReject, didProgress) {
- var ret = this._then(didFulfill, didReject, didProgress,
- undefined, undefined);
- ret._setCancellable();
- ret._cancellationParent = undefined;
- return ret;
- };
- };
- },{"./async.js":2,"./errors.js":13}],7:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function() {
- var async = _dereq_("./async.js");
- var util = _dereq_("./util.js");
- var bluebirdFramePattern =
- /[\\\/]bluebird[\\\/]js[\\\/](main|debug|zalgo|instrumented)/;
- var stackFramePattern = null;
- var formatStack = null;
- var indentStackFrames = false;
- var warn;
- function CapturedTrace(parent) {
- this._parent = parent;
- var length = this._length = 1 + (parent === undefined ? 0 : parent._length);
- captureStackTrace(this, CapturedTrace);
- if (length > 32) this.uncycle();
- }
- util.inherits(CapturedTrace, Error);
- CapturedTrace.prototype.uncycle = function() {
- var length = this._length;
- if (length < 2) return;
- var nodes = [];
- var stackToIndex = {};
- for (var i = 0, node = this; node !== undefined; ++i) {
- nodes.push(node);
- node = node._parent;
- }
- length = this._length = i;
- for (var i = length - 1; i >= 0; --i) {
- var stack = nodes[i].stack;
- if (stackToIndex[stack] === undefined) {
- stackToIndex[stack] = i;
- }
- }
- for (var i = 0; i < length; ++i) {
- var currentStack = nodes[i].stack;
- var index = stackToIndex[currentStack];
- if (index !== undefined && index !== i) {
- if (index > 0) {
- nodes[index - 1]._parent = undefined;
- nodes[index - 1]._length = 1;
- }
- nodes[i]._parent = undefined;
- nodes[i]._length = 1;
- var cycleEdgeNode = i > 0 ? nodes[i - 1] : this;
- if (index < length - 1) {
- cycleEdgeNode._parent = nodes[index + 1];
- cycleEdgeNode._parent.uncycle();
- cycleEdgeNode._length =
- cycleEdgeNode._parent._length + 1;
- } else {
- cycleEdgeNode._parent = undefined;
- cycleEdgeNode._length = 1;
- }
- var currentChildLength = cycleEdgeNode._length + 1;
- for (var j = i - 2; j >= 0; --j) {
- nodes[j]._length = currentChildLength;
- currentChildLength++;
- }
- return;
- }
- }
- };
- CapturedTrace.prototype.parent = function() {
- return this._parent;
- };
- CapturedTrace.prototype.hasParent = function() {
- return this._parent !== undefined;
- };
- CapturedTrace.prototype.attachExtraTrace = function(error) {
- if (error.__stackCleaned__) return;
- this.uncycle();
- var parsed = CapturedTrace.parseStackAndMessage(error);
- var message = parsed.message;
- var stacks = [parsed.stack];
- var trace = this;
- while (trace !== undefined) {
- stacks.push(cleanStack(trace.stack.split("\n")));
- trace = trace._parent;
- }
- removeCommonRoots(stacks);
- removeDuplicateOrEmptyJumps(stacks);
- util.notEnumerableProp(error, "stack", reconstructStack(message, stacks));
- util.notEnumerableProp(error, "__stackCleaned__", true);
- };
- function reconstructStack(message, stacks) {
- for (var i = 0; i < stacks.length - 1; ++i) {
- stacks[i].push("From previous event:");
- stacks[i] = stacks[i].join("\n");
- }
- if (i < stacks.length) {
- stacks[i] = stacks[i].join("\n");
- }
- return message + "\n" + stacks.join("\n");
- }
- function removeDuplicateOrEmptyJumps(stacks) {
- for (var i = 0; i < stacks.length; ++i) {
- if (stacks[i].length === 0 ||
- ((i + 1 < stacks.length) && stacks[i][0] === stacks[i+1][0])) {
- stacks.splice(i, 1);
- i--;
- }
- }
- }
- function removeCommonRoots(stacks) {
- var current = stacks[0];
- for (var i = 1; i < stacks.length; ++i) {
- var prev = stacks[i];
- var currentLastIndex = current.length - 1;
- var currentLastLine = current[currentLastIndex];
- var commonRootMeetPoint = -1;
- for (var j = prev.length - 1; j >= 0; --j) {
- if (prev[j] === currentLastLine) {
- commonRootMeetPoint = j;
- break;
- }
- }
- for (var j = commonRootMeetPoint; j >= 0; --j) {
- var line = prev[j];
- if (current[currentLastIndex] === line) {
- current.pop();
- currentLastIndex--;
- } else {
- break;
- }
- }
- current = prev;
- }
- }
- function cleanStack(stack) {
- var ret = [];
- for (var i = 0; i < stack.length; ++i) {
- var line = stack[i];
- var isTraceLine = stackFramePattern.test(line) ||
- " (No stack trace)" === line;
- var isInternalFrame = isTraceLine && shouldIgnore(line);
- if (isTraceLine && !isInternalFrame) {
- if (indentStackFrames && line.charAt(0) !== " ") {
- line = " " + line;
- }
- ret.push(line);
- }
- }
- return ret;
- }
- function stackFramesAsArray(error) {
- var stack = error.stack.replace(/\s+$/g, "").split("\n");
- for (var i = 0; i < stack.length; ++i) {
- var line = stack[i];
- if (" (No stack trace)" === line || stackFramePattern.test(line)) {
- break;
- }
- }
- if (i > 0) {
- stack = stack.slice(i);
- }
- return stack;
- }
- CapturedTrace.parseStackAndMessage = function(error) {
- var stack = error.stack;
- var message = error.toString();
- stack = typeof stack === "string" && stack.length > 0
- ? stackFramesAsArray(error) : [" (No stack trace)"];
- return {
- message: message,
- stack: cleanStack(stack)
- };
- };
- CapturedTrace.formatAndLogError = function(error, title) {
- if (typeof console !== "undefined") {
- var message;
- if (typeof error === "object" || typeof error === "function") {
- var stack = error.stack;
- message = title + formatStack(stack, error);
- } else {
- message = title + String(error);
- }
- if (typeof warn === "function") {
- warn(message);
- } else if (typeof console.log === "function" ||
- typeof console.log === "object") {
- console.log(message);
- }
- }
- };
- CapturedTrace.unhandledRejection = function (reason) {
- CapturedTrace.formatAndLogError(reason, "^--- With additional stack trace: ");
- };
- CapturedTrace.isSupported = function () {
- return typeof captureStackTrace === "function";
- };
- CapturedTrace.fireRejectionEvent =
- function(name, localHandler, reason, promise) {
- var localEventFired = false;
- try {
- if (typeof localHandler === "function") {
- localEventFired = true;
- if (name === "rejectionHandled") {
- localHandler(promise);
- } else {
- localHandler(reason, promise);
- }
- }
- } catch (e) {
- async.throwLater(e);
- }
- var globalEventFired = false;
- try {
- globalEventFired = fireGlobalEvent(name, reason, promise);
- } catch (e) {
- globalEventFired = true;
- async.throwLater(e);
- }
- var domEventFired = false;
- if (fireDomEvent) {
- try {
- domEventFired = fireDomEvent(name.toLowerCase(), {
- reason: reason,
- promise: promise
- });
- } catch (e) {
- domEventFired = true;
- async.throwLater(e);
- }
- }
- if (!globalEventFired && !localEventFired && !domEventFired &&
- name === "unhandledRejection") {
- CapturedTrace.formatAndLogError(reason, "Unhandled rejection ");
- }
- };
- 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) + "...";
- }
- var shouldIgnore = function() { return false; };
- var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;
- function parseLineInfo(line) {
- var matches = line.match(parseLineInfoRegex);
- if (matches) {
- return {
- fileName: matches[1],
- line: parseInt(matches[2], 10)
- };
- }
- }
- CapturedTrace.setBounds = function(firstLineError, lastLineError) {
- if (!CapturedTrace.isSupported()) return;
- var firstStackLines = firstLineError.stack.split("\n");
- var lastStackLines = lastLineError.stack.split("\n");
- var firstIndex = -1;
- var lastIndex = -1;
- var firstFileName;
- var lastFileName;
- for (var i = 0; i < firstStackLines.length; ++i) {
- var result = parseLineInfo(firstStackLines[i]);
- if (result) {
- firstFileName = result.fileName;
- firstIndex = result.line;
- break;
- }
- }
- for (var i = 0; i < lastStackLines.length; ++i) {
- var result = parseLineInfo(lastStackLines[i]);
- if (result) {
- lastFileName = result.fileName;
- lastIndex = result.line;
- break;
- }
- }
- if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName ||
- firstFileName !== lastFileName || firstIndex >= lastIndex) {
- return;
- }
- shouldIgnore = function(line) {
- if (bluebirdFramePattern.test(line)) return true;
- var info = parseLineInfo(line);
- if (info) {
- if (info.fileName === firstFileName &&
- (firstIndex <= info.line && info.line <= lastIndex)) {
- return true;
- }
- }
- return false;
- };
- };
- var captureStackTrace = (function stackDetection() {
- var v8stackFramePattern = /^\s*at\s*/;
- var v8stackFormatter = function(stack, error) {
- if (typeof stack === "string") return stack;
- if (error.name !== undefined &&
- error.message !== undefined) {
- return error.toString();
- }
- return formatNonError(error);
- };
- if (typeof Error.stackTraceLimit === "number" &&
- typeof Error.captureStackTrace === "function") {
- Error.stackTraceLimit = Error.stackTraceLimit + 6;
- stackFramePattern = v8stackFramePattern;
- formatStack = v8stackFormatter;
- var captureStackTrace = Error.captureStackTrace;
- shouldIgnore = function(line) {
- return bluebirdFramePattern.test(line);
- };
- return function(receiver, ignoreUntil) {
- Error.stackTraceLimit = Error.stackTraceLimit + 6;
- captureStackTrace(receiver, ignoreUntil);
- Error.stackTraceLimit = Error.stackTraceLimit - 6;
- };
- }
- var err = new Error();
- if (typeof err.stack === "string" &&
- err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) {
- stackFramePattern = /@/;
- formatStack = v8stackFormatter;
- indentStackFrames = true;
- return function captureStackTrace(o) {
- o.stack = new Error().stack;
- };
- }
- var hasStackAfterThrow;
- try { throw new Error(); }
- catch(e) {
- hasStackAfterThrow = ("stack" in e);
- }
- if (!("stack" in err) && hasStackAfterThrow) {
- stackFramePattern = v8stackFramePattern;
- formatStack = v8stackFormatter;
- return function captureStackTrace(o) {
- Error.stackTraceLimit = Error.stackTraceLimit + 6;
- try { throw new Error(); }
- catch(e) { o.stack = e.stack; }
- Error.stackTraceLimit = Error.stackTraceLimit - 6;
- };
- }
- formatStack = function(stack, error) {
- if (typeof stack === "string") return stack;
- if ((typeof error === "object" ||
- typeof error === "function") &&
- error.name !== undefined &&
- error.message !== undefined) {
- return error.toString();
- }
- return formatNonError(error);
- };
- return null;
- })([]);
- var fireDomEvent;
- var fireGlobalEvent = (function() {
- if (util.isNode) {
- return function(name, reason, promise) {
- if (name === "rejectionHandled") {
- return process.emit(name, promise);
- } else {
- return process.emit(name, reason, promise);
- }
- };
- } else {
- var customEventWorks = false;
- var anyEventWorks = true;
- try {
- var ev = new self.CustomEvent("test");
- customEventWorks = ev instanceof CustomEvent;
- } catch (e) {}
- if (!customEventWorks) {
- try {
- var event = document.createEvent("CustomEvent");
- event.initCustomEvent("testingtheevent", false, true, {});
- self.dispatchEvent(event);
- } catch (e) {
- anyEventWorks = false;
- }
- }
- if (anyEventWorks) {
- fireDomEvent = function(type, detail) {
- var event;
- if (customEventWorks) {
- event = new self.CustomEvent(type, {
- detail: detail,
- bubbles: false,
- cancelable: true
- });
- } else if (self.dispatchEvent) {
- event = document.createEvent("CustomEvent");
- event.initCustomEvent(type, false, true, detail);
- }
- return event ? !self.dispatchEvent(event) : false;
- };
- }
- var toWindowMethodNameMap = {};
- toWindowMethodNameMap["unhandledRejection"] = ("on" +
- "unhandledRejection").toLowerCase();
- toWindowMethodNameMap["rejectionHandled"] = ("on" +
- "rejectionHandled").toLowerCase();
- return function(name, reason, promise) {
- var methodName = toWindowMethodNameMap[name];
- var method = self[methodName];
- if (!method) return false;
- if (name === "rejectionHandled") {
- method.call(self, promise);
- } else {
- method.call(self, reason, promise);
- }
- return true;
- };
- }
- })();
- if (typeof console !== "undefined" && typeof console.warn !== "undefined") {
- warn = function (message) {
- console.warn(message);
- };
- if (util.isNode && process.stderr.isTTY) {
- warn = function(message) {
- process.stderr.write("\u001b[31m" + message + "\u001b[39m\n");
- };
- } else if (!util.isNode && typeof (new Error().stack) === "string") {
- warn = function(message) {
- console.warn("%c" + message, "color: red");
- };
- }
- }
- return CapturedTrace;
- };
- },{"./async.js":2,"./util.js":38}],8:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(NEXT_FILTER) {
- var util = _dereq_("./util.js");
- var errors = _dereq_("./errors.js");
- var tryCatch = util.tryCatch;
- var errorObj = util.errorObj;
- var keys = _dereq_("./es5.js").keys;
- var TypeError = errors.TypeError;
- function CatchFilter(instances, callback, promise) {
- this._instances = instances;
- this._callback = callback;
- this._promise = promise;
- }
- function safePredicate(predicate, e) {
- var safeObject = {};
- var retfilter = tryCatch(predicate).call(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\u000a\u000a See http://goo.gl/o84o68\u000a");
- return errorObj;
- }
- return retfilter;
- }
- CatchFilter.prototype.doFilter = function (e) {
- var cb = this._callback;
- var promise = this._promise;
- var boundTo = promise._boundTo;
- 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 = tryCatch(cb).call(boundTo, e);
- if (ret === errorObj) {
- NEXT_FILTER.e = ret.e;
- return NEXT_FILTER;
- }
- return ret;
- } else if (typeof item === "function" && !itemIsErrorType) {
- var shouldHandle = safePredicate(item, e);
- if (shouldHandle === errorObj) {
- e = errorObj.e;
- break;
- } else if (shouldHandle) {
- var ret = tryCatch(cb).call(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":13,"./es5.js":14,"./util.js":38}],9:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, CapturedTrace, isDebugging) {
- var contextStack = [];
- function Context() {
- this._trace = new CapturedTrace(peekContext());
- }
- Context.prototype._pushContext = function () {
- if (!isDebugging()) return;
- if (this._trace !== undefined) {
- contextStack.push(this._trace);
- }
- };
- Context.prototype._popContext = function () {
- if (!isDebugging()) return;
- if (this._trace !== undefined) {
- contextStack.pop();
- }
- };
- function createContext() {
- if (isDebugging()) return new Context();
- }
- function peekContext() {
- var lastIndex = contextStack.length - 1;
- if (lastIndex >= 0) {
- return contextStack[lastIndex];
- }
- return undefined;
- }
- Promise.prototype._peekContext = peekContext;
- Promise.prototype._pushContext = Context.prototype._pushContext;
- Promise.prototype._popContext = Context.prototype._popContext;
- return createContext;
- };
- },{}],10:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, CapturedTrace) {
- var async = _dereq_("./async.js");
- var Warning = _dereq_("./errors.js").Warning;
- var util = _dereq_("./util.js");
- var canAttachTrace = util.canAttachTrace;
- var unhandledRejectionHandled;
- var possiblyUnhandledRejection;
- var debugging = false || (util.isNode &&
- (!!process.env["BLUEBIRD_DEBUG"] ||
- process.env["NODE_ENV"] === "development"));
- if (debugging) {
- async.disableTrampolineIfNecessary();
- }
- Promise.prototype._ensurePossibleRejectionHandled = function () {
- this._setRejectionIsUnhandled();
- async.invokeLater(this._notifyUnhandledRejection, this, undefined);
- };
- Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
- CapturedTrace.fireRejectionEvent("rejectionHandled",
- unhandledRejectionHandled, undefined, this);
- };
- Promise.prototype._notifyUnhandledRejection = function () {
- if (this._isRejectionUnhandled()) {
- var reason = this._getCarriedStackTrace() || this._settledValue;
- this._setUnhandledRejectionIsNotified();
- CapturedTrace.fireRejectionEvent("unhandledRejection",
- possiblyUnhandledRejection, reason, this);
- }
- };
- Promise.prototype._setUnhandledRejectionIsNotified = function () {
- this._bitField = this._bitField | 524288;
- };
- Promise.prototype._unsetUnhandledRejectionIsNotified = function () {
- this._bitField = this._bitField & (~524288);
- };
- Promise.prototype._isUnhandledRejectionNotified = function () {
- return (this._bitField & 524288) > 0;
- };
- Promise.prototype._setRejectionIsUnhandled = function () {
- this._bitField = this._bitField | 2097152;
- };
- Promise.prototype._unsetRejectionIsUnhandled = function () {
- this._bitField = this._bitField & (~2097152);
- if (this._isUnhandledRejectionNotified()) {
- this._unsetUnhandledRejectionIsNotified();
- this._notifyUnhandledRejectionIsHandled();
- }
- };
- Promise.prototype._isRejectionUnhandled = function () {
- return (this._bitField & 2097152) > 0;
- };
- Promise.prototype._setCarriedStackTrace = function (capturedTrace) {
- this._bitField = this._bitField | 1048576;
- this._fulfillmentHandler0 = capturedTrace;
- };
- Promise.prototype._isCarryingStackTrace = function () {
- return (this._bitField & 1048576) > 0;
- };
- Promise.prototype._getCarriedStackTrace = function () {
- return this._isCarryingStackTrace()
- ? this._fulfillmentHandler0
- : undefined;
- };
- Promise.prototype._captureStackTrace = function () {
- if (debugging) {
- this._trace = new CapturedTrace(this._peekContext());
- }
- return this;
- };
- Promise.prototype._attachExtraTrace = function (error, ignoreSelf) {
- if (debugging && canAttachTrace(error)) {
- var trace = this._trace;
- if (trace !== undefined) {
- if (ignoreSelf) trace = trace._parent;
- }
- if (trace !== undefined) {
- trace.attachExtraTrace(error);
- } else if (!error.__stackCleaned__) {
- var parsed = CapturedTrace.parseStackAndMessage(error);
- util.notEnumerableProp(error, "stack",
- parsed.message + "\n" + parsed.stack.join("\n"));
- util.notEnumerableProp(error, "__stackCleaned__", true);
- }
- }
- };
- Promise.prototype._warn = function(message) {
- var warning = new Warning(message);
- var ctx = this._peekContext();
- if (ctx) {
- ctx.attachExtraTrace(warning);
- } else {
- var parsed = CapturedTrace.parseStackAndMessage(warning);
- warning.stack = parsed.message + "\n" + parsed.stack.join("\n");
- }
- CapturedTrace.formatAndLogError(warning, "");
- };
- Promise.onPossiblyUnhandledRejection = function (fn) {
- possiblyUnhandledRejection = typeof fn === "function" ? fn : undefined;
- };
- Promise.onUnhandledRejectionHandled = function (fn) {
- unhandledRejectionHandled = typeof fn === "function" ? fn : undefined;
- };
- Promise.longStackTraces = function () {
- if (async.haveItemsQueued() &&
- debugging === false
- ) {
- throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/DT1qyG\u000a");
- }
- debugging = CapturedTrace.isSupported();
- if (debugging) {
- async.disableTrampolineIfNecessary();
- }
- };
- Promise.hasLongStackTraces = function () {
- return debugging && CapturedTrace.isSupported();
- };
- if (!CapturedTrace.isSupported()) {
- Promise.longStackTraces = function(){};
- debugging = false;
- }
- return function() {
- return debugging;
- };
- };
- },{"./async.js":2,"./errors.js":13,"./util.js":38}],11:[function(_dereq_,module,exports){
- "use strict";
- var util = _dereq_("./util.js");
- var isPrimitive = util.isPrimitive;
- var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
- module.exports = function(Promise) {
- var returner = function () {
- return this;
- };
- var thrower = function () {
- throw this;
- };
- var returnUndefined = function() {};
- var throwUndefined = function() {
- throw undefined;
- };
- var wrapper = function (value, action) {
- if (action === 1) {
- return function () {
- throw value;
- };
- } else if (action === 2) {
- return function () {
- return value;
- };
- }
- };
- Promise.prototype["return"] =
- Promise.prototype.thenReturn = function (value) {
- if (value === undefined) return this.then(returnUndefined);
- if (wrapsPrimitiveReceiver && isPrimitive(value)) {
- return this._then(
- wrapper(value, 2),
- undefined,
- undefined,
- undefined,
- undefined
- );
- }
- return this._then(returner, undefined, undefined, value, undefined);
- };
- Promise.prototype["throw"] =
- Promise.prototype.thenThrow = function (reason) {
- if (reason === undefined) return this.then(throwUndefined);
- if (wrapsPrimitiveReceiver && isPrimitive(reason)) {
- return this._then(
- wrapper(reason, 1),
- undefined,
- undefined,
- undefined,
- undefined
- );
- }
- return this._then(thrower, undefined, undefined, reason, undefined);
- };
- };
- },{"./util.js":38}],12:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var PromiseReduce = Promise.reduce;
- Promise.prototype.each = function (fn) {
- return PromiseReduce(this, fn, null, INTERNAL);
- };
- Promise.each = function (promises, fn) {
- return PromiseReduce(promises, fn, null, INTERNAL);
- };
- };
- },{}],13:[function(_dereq_,module,exports){
- "use strict";
- var es5 = _dereq_("./es5.js");
- var Objectfreeze = es5.freeze;
- var util = _dereq_("./util.js");
- var inherits = util.inherits;
- var notEnumerableProp = util.notEnumerableProp;
- function subError(nameProperty, defaultMessage) {
- function SubError(message) {
- if (!(this instanceof SubError)) return new SubError(message);
- notEnumerableProp(this, "message",
- typeof message === "string" ? message : defaultMessage);
- notEnumerableProp(this, "name", nameProperty);
- if (Error.captureStackTrace) {
- Error.captureStackTrace(this, this.constructor);
- } else {
- Error.call(this);
- }
- }
- inherits(SubError, Error);
- return SubError;
- }
- var _TypeError, _RangeError;
- var Warning = subError("Warning", "warning");
- var CancellationError = subError("CancellationError", "cancellation error");
- var TimeoutError = subError("TimeoutError", "timeout error");
- var AggregateError = subError("AggregateError", "aggregate error");
- try {
- _TypeError = TypeError;
- _RangeError = RangeError;
- } catch(e) {
- _TypeError = subError("TypeError", "type error");
- _RangeError = subError("RangeError", "range error");
- }
- var methods = ("join pop push shift unshift slice filter forEach some " +
- "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" ");
- for (var i = 0; i < methods.length; ++i) {
- if (typeof Array.prototype[methods[i]] === "function") {
- AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];
- }
- }
- es5.defineProperty(AggregateError.prototype, "length", {
- value: 0,
- configurable: false,
- writable: true,
- enumerable: true
- });
- AggregateError.prototype["isOperational"] = true;
- var level = 0;
- AggregateError.prototype.toString = function() {
- var indent = Array(level * 4 + 1).join(" ");
- var ret = "\n" + indent + "AggregateError of:" + "\n";
- level++;
- indent = Array(level * 4 + 1).join(" ");
- for (var i = 0; i < this.length; ++i) {
- var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";
- var lines = str.split("\n");
- for (var j = 0; j < lines.length; ++j) {
- lines[j] = indent + lines[j];
- }
- str = lines.join("\n");
- ret += str + "\n";
- }
- level--;
- return ret;
- };
- function OperationalError(message) {
- if (!(this instanceof OperationalError))
- return new OperationalError(message);
- notEnumerableProp(this, "name", "OperationalError");
- notEnumerableProp(this, "message", message);
- this.cause = message;
- this["isOperational"] = true;
- if (message instanceof Error) {
- notEnumerableProp(this, "message", message.message);
- notEnumerableProp(this, "stack", message.stack);
- } else if (Error.captureStackTrace) {
- Error.captureStackTrace(this, this.constructor);
- }
- }
- inherits(OperationalError, Error);
- var errorTypes = Error["__BluebirdErrorTypes__"];
- if (!errorTypes) {
- errorTypes = Objectfreeze({
- CancellationError: CancellationError,
- TimeoutError: TimeoutError,
- OperationalError: OperationalError,
- RejectionError: OperationalError,
- AggregateError: AggregateError
- });
- notEnumerableProp(Error, "__BluebirdErrorTypes__", errorTypes);
- }
- module.exports = {
- Error: Error,
- TypeError: _TypeError,
- RangeError: _RangeError,
- CancellationError: errorTypes.CancellationError,
- OperationalError: errorTypes.OperationalError,
- TimeoutError: errorTypes.TimeoutError,
- AggregateError: errorTypes.AggregateError,
- Warning: Warning
- };
- },{"./es5.js":14,"./util.js":38}],14:[function(_dereq_,module,exports){
- var isES5 = (function(){
- "use strict";
- return this === undefined;
- })();
- if (isES5) {
- module.exports = {
- freeze: Object.freeze,
- defineProperty: Object.defineProperty,
- getDescriptor: Object.getOwnPropertyDescriptor,
- keys: Object.keys,
- names: Object.getOwnPropertyNames,
- getPrototypeOf: Object.getPrototypeOf,
- isArray: Array.isArray,
- isES5: isES5,
- propertyIsWritable: function(obj, prop) {
- var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
- return !!(!descriptor || descriptor.writable || descriptor.set);
- }
- };
- } else {
- var has = {}.hasOwnProperty;
- var str = {}.toString;
- var proto = {}.constructor.prototype;
- var ObjectKeys = function (o) {
- var ret = [];
- for (var key in o) {
- if (has.call(o, key)) {
- ret.push(key);
- }
- }
- return ret;
- };
- var ObjectGetDescriptor = function(o, key) {
- return {value: o[key]};
- };
- var ObjectDefineProperty = function (o, key, desc) {
- o[key] = desc.value;
- return o;
- };
- var ObjectFreeze = function (obj) {
- return obj;
- };
- var ObjectGetPrototypeOf = function (obj) {
- try {
- return Object(obj).constructor.prototype;
- }
- catch (e) {
- return proto;
- }
- };
- var ArrayIsArray = function (obj) {
- try {
- return str.call(obj) === "[object Array]";
- }
- catch(e) {
- return false;
- }
- };
- module.exports = {
- isArray: ArrayIsArray,
- keys: ObjectKeys,
- names: ObjectKeys,
- defineProperty: ObjectDefineProperty,
- getDescriptor: ObjectGetDescriptor,
- freeze: ObjectFreeze,
- getPrototypeOf: ObjectGetPrototypeOf,
- isES5: isES5,
- propertyIsWritable: function() {
- return true;
- }
- };
- }
- },{}],15:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var PromiseMap = Promise.map;
- Promise.prototype.filter = function (fn, options) {
- return PromiseMap(this, fn, options, INTERNAL);
- };
- Promise.filter = function (promises, fn, options) {
- return PromiseMap(promises, fn, options, INTERNAL);
- };
- };
- },{}],16:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, NEXT_FILTER, tryConvertToPromise) {
- var util = _dereq_("./util.js");
- var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
- var isPrimitive = util.isPrimitive;
- var thrower = util.thrower;
- function returnThis() {
- return this;
- }
- function throwThis() {
- throw this;
- }
- function return$(r) {
- return function() {
- return r;
- };
- }
- function throw$(r) {
- return function() {
- throw r;
- };
- }
- function promisedFinally(ret, reasonOrValue, isFulfilled) {
- var then;
- if (wrapsPrimitiveReceiver && isPrimitive(reasonOrValue)) {
- then = isFulfilled ? return$(reasonOrValue) : throw$(reasonOrValue);
- } else {
- then = isFulfilled ? returnThis : throwThis;
- }
- return ret._then(then, thrower, undefined, reasonOrValue, undefined);
- }
- function finallyHandler(reasonOrValue) {
- var promise = this.promise;
- var handler = this.handler;
- var ret = promise._isBound()
- ? handler.call(promise._boundTo)
- : handler();
- if (ret !== undefined) {
- var maybePromise = tryConvertToPromise(ret, promise);
- if (maybePromise instanceof Promise) {
- maybePromise = maybePromise._target();
- return promisedFinally(maybePromise, reasonOrValue,
- promise.isFulfilled());
- }
- }
- if (promise.isRejected()) {
- NEXT_FILTER.e = reasonOrValue;
- return NEXT_FILTER;
- } else {
- return reasonOrValue;
- }
- }
- function tapHandler(value) {
- var promise = this.promise;
- var handler = this.handler;
- var ret = promise._isBound()
- ? handler.call(promise._boundTo, value)
- : handler(value);
- if (ret !== undefined) {
- var maybePromise = tryConvertToPromise(ret, promise);
- if (maybePromise instanceof Promise) {
- maybePromise = maybePromise._target();
- return promisedFinally(maybePromise, value, true);
- }
- }
- return value;
- }
- Promise.prototype._passThroughHandler = function (handler, isFinally) {
- if (typeof handler !== "function") return this.then();
- var promiseAndHandler = {
- promise: this,
- handler: handler
- };
- return this._then(
- isFinally ? finallyHandler : tapHandler,
- isFinally ? finallyHandler : undefined, undefined,
- promiseAndHandler, undefined);
- };
- Promise.prototype.lastly =
- Promise.prototype["finally"] = function (handler) {
- return this._passThroughHandler(handler, true);
- };
- Promise.prototype.tap = function (handler) {
- return this._passThroughHandler(handler, false);
- };
- };
- },{"./util.js":38}],17:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise,
- apiRejection,
- INTERNAL,
- tryConvertToPromise) {
- var errors = _dereq_("./errors.js");
- var TypeError = errors.TypeError;
- var util = _dereq_("./util.js");
- var errorObj = util.errorObj;
- var tryCatch = util.tryCatch;
- var yieldHandlers = [];
- function promiseFromYieldHandler(value, yieldHandlers, traceParent) {
- for (var i = 0; i < yieldHandlers.length; ++i) {
- traceParent._pushContext();
- var result = tryCatch(yieldHandlers[i])(value);
- traceParent._popContext();
- if (result === errorObj) {
- traceParent._pushContext();
- var ret = Promise.reject(errorObj.e);
- traceParent._popContext();
- return ret;
- }
- var maybePromise = tryConvertToPromise(result, traceParent);
- if (maybePromise instanceof Promise) return maybePromise;
- }
- return null;
- }
- function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) {
- var promise = this._promise = new Promise(INTERNAL);
- promise._captureStackTrace();
- this._stack = stack;
- this._generatorFunction = generatorFunction;
- this._receiver = receiver;
- this._generator = undefined;
- this._yieldHandlers = typeof yieldHandler === "function"
- ? [yieldHandler].concat(yieldHandlers)
- : yieldHandlers;
- }
- PromiseSpawn.prototype.promise = function () {
- return this._promise;
- };
- PromiseSpawn.prototype._run = function () {
- this._generator = this._generatorFunction.call(this._receiver);
- this._receiver =
- this._generatorFunction = undefined;
- this._next(undefined);
- };
- PromiseSpawn.prototype._continue = function (result) {
- if (result === errorObj) {
- return this._promise._rejectCallback(result.e, false, true);
- }
- var value = result.value;
- if (result.done === true) {
- this._promise._resolveCallback(value);
- } else {
- var maybePromise = tryConvertToPromise(value, this._promise);
- if (!(maybePromise instanceof Promise)) {
- maybePromise =
- promiseFromYieldHandler(maybePromise,
- this._yieldHandlers,
- this._promise);
- if (maybePromise === null) {
- this._throw(
- new TypeError(
- "A value %s was yielded that could not be treated as a promise\u000a\u000a See http://goo.gl/4Y4pDk\u000a\u000a".replace("%s", value) +
- "From coroutine:\u000a" +
- this._stack.split("\n").slice(1, -7).join("\n")
- )
- );
- return;
- }
- }
- maybePromise._then(
- this._next,
- this._throw,
- undefined,
- this,
- null
- );
- }
- };
- PromiseSpawn.prototype._throw = function (reason) {
- this._promise._attachExtraTrace(reason);
- this._promise._pushContext();
- var result = tryCatch(this._generator["throw"])
- .call(this._generator, reason);
- this._promise._popContext();
- this._continue(result);
- };
- PromiseSpawn.prototype._next = function (value) {
- this._promise._pushContext();
- var result = tryCatch(this._generator.next).call(this._generator, value);
- this._promise._popContext();
- this._continue(result);
- };
- Promise.coroutine = function (generatorFunction, options) {
- if (typeof generatorFunction !== "function") {
- throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/6Vqhm0\u000a");
- }
- var yieldHandler = Object(options).yieldHandler;
- var PromiseSpawn$ = PromiseSpawn;
- var stack = new Error().stack;
- return function () {
- var generator = generatorFunction.apply(this, arguments);
- var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler,
- stack);
- spawn._generator = generator;
- spawn._next(undefined);
- return spawn.promise();
- };
- };
- Promise.coroutine.addYieldHandler = function(fn) {
- if (typeof fn !== "function") throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- yieldHandlers.push(fn);
- };
- Promise.spawn = function (generatorFunction) {
- if (typeof generatorFunction !== "function") {
- return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/6Vqhm0\u000a");
- }
- var spawn = new PromiseSpawn(generatorFunction, this);
- var ret = spawn.promise();
- spawn._run(Promise.spawn);
- return ret;
- };
- };
- },{"./errors.js":13,"./util.js":38}],18:[function(_dereq_,module,exports){
- "use strict";
- module.exports =
- function(Promise, PromiseArray, tryConvertToPromise, INTERNAL) {
- var util = _dereq_("./util.js");
- var canEvaluate = util.canEvaluate;
- var tryCatch = util.tryCatch;
- var errorObj = util.errorObj;
- var reject;
- if (!true) {
- if (canEvaluate) {
- var thenCallback = function(i) {
- return new Function("value", "holder", " \n\
- 'use strict'; \n\
- holder.pIndex = value; \n\
- holder.checkFulfillment(this); \n\
- ".replace(/Index/g, i));
- };
- var caller = function(count) {
- var values = [];
- for (var i = 1; i <= count; ++i) values.push("holder.p" + i);
- return new Function("holder", " \n\
- 'use strict'; \n\
- var callback = holder.fn; \n\
- return callback(values); \n\
- ".replace(/values/g, values.join(", ")));
- };
- var thenCallbacks = [];
- var callers = [undefined];
- for (var i = 1; i <= 5; ++i) {
- thenCallbacks.push(thenCallback(i));
- callers.push(caller(i));
- }
- var Holder = function(total, fn) {
- this.p1 = this.p2 = this.p3 = this.p4 = this.p5 = null;
- this.fn = fn;
- this.total = total;
- this.now = 0;
- };
- Holder.prototype.callers = callers;
- Holder.prototype.checkFulfillment = function(promise) {
- var now = this.now;
- now++;
- var total = this.total;
- if (now >= total) {
- var handler = this.callers[total];
- promise._pushContext();
- var ret = tryCatch(handler)(this);
- promise._popContext();
- if (ret === errorObj) {
- promise._rejectCallback(ret.e, false, true);
- } else {
- promise._resolveCallback(ret);
- }
- } else {
- this.now = now;
- }
- };
- var reject = function (reason) {
- this._reject(reason);
- };
- }
- }
- Promise.join = function () {
- var last = arguments.length - 1;
- var fn;
- if (last > 0 && typeof arguments[last] === "function") {
- fn = arguments[last];
- if (!true) {
- if (last < 6 && canEvaluate) {
- var ret = new Promise(INTERNAL);
- ret._captureStackTrace();
- var holder = new Holder(last, fn);
- var callbacks = thenCallbacks;
- for (var i = 0; i < last; ++i) {
- var maybePromise = tryConvertToPromise(arguments[i], ret);
- if (maybePromise instanceof Promise) {
- maybePromise = maybePromise._target();
- if (maybePromise._isPending()) {
- maybePromise._then(callbacks[i], reject,
- undefined, ret, holder);
- } else if (maybePromise._isFulfilled()) {
- callbacks[i].call(ret,
- maybePromise._value(), holder);
- } else {
- ret._reject(maybePromise._reason());
- }
- } else {
- callbacks[i].call(ret, maybePromise, holder);
- }
- }
- return ret;
- }
- }
- }
- var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
- if (fn) args.pop();
- var ret = new PromiseArray(args).promise();
- return fn !== undefined ? ret.spread(fn) : ret;
- };
- };
- },{"./util.js":38}],19:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise,
- PromiseArray,
- apiRejection,
- tryConvertToPromise,
- INTERNAL) {
- var async = _dereq_("./async.js");
- var util = _dereq_("./util.js");
- var tryCatch = util.tryCatch;
- var errorObj = util.errorObj;
- var PENDING = {};
- var EMPTY_ARRAY = [];
- function MappingPromiseArray(promises, fn, limit, _filter) {
- this.constructor$(promises);
- this._promise._captureStackTrace();
- this._callback = fn;
- this._preservedValues = _filter === INTERNAL
- ? new Array(this.length())
- : null;
- this._limit = limit;
- this._inFlight = 0;
- this._queue = limit >= 1 ? [] : EMPTY_ARRAY;
- async.invoke(init, this, undefined);
- }
- util.inherits(MappingPromiseArray, PromiseArray);
- function init() {this._init$(undefined, -2);}
- MappingPromiseArray.prototype._init = function () {};
- MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
- var values = this._values;
- var length = this.length();
- var preservedValues = this._preservedValues;
- var limit = this._limit;
- if (values[index] === PENDING) {
- values[index] = value;
- if (limit >= 1) {
- this._inFlight--;
- this._drainQueue();
- if (this._isResolved()) return;
- }
- } else {
- if (limit >= 1 && this._inFlight >= limit) {
- values[index] = value;
- this._queue.push(index);
- return;
- }
- if (preservedValues !== null) preservedValues[index] = value;
- var callback = this._callback;
- var receiver = this._promise._boundTo;
- this._promise._pushContext();
- var ret = tryCatch(callback).call(receiver, value, index, length);
- this._promise._popContext();
- if (ret === errorObj) return this._reject(ret.e);
- var maybePromise = tryConvertToPromise(ret, this._promise);
- if (maybePromise instanceof Promise) {
- maybePromise = maybePromise._target();
- if (maybePromise._isPending()) {
- if (limit >= 1) this._inFlight++;
- values[index] = PENDING;
- return maybePromise._proxyPromiseArray(this, index);
- } else if (maybePromise._isFulfilled()) {
- ret = maybePromise._value();
- } else {
- return this._reject(maybePromise._reason());
- }
- }
- values[index] = ret;
- }
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= length) {
- if (preservedValues !== null) {
- this._filter(values, preservedValues);
- } else {
- this._resolve(values);
- }
- }
- };
- MappingPromiseArray.prototype._drainQueue = function () {
- var queue = this._queue;
- var limit = this._limit;
- var values = this._values;
- while (queue.length > 0 && this._inFlight < limit) {
- if (this._isResolved()) return;
- var index = queue.pop();
- this._promiseFulfilled(values[index], index);
- }
- };
- MappingPromiseArray.prototype._filter = function (booleans, values) {
- 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;
- this._resolve(ret);
- };
- MappingPromiseArray.prototype.preservedValues = function () {
- return this._preservedValues;
- };
- function map(promises, fn, options, _filter) {
- var limit = typeof options === "object" && options !== null
- ? options.concurrency
- : 0;
- limit = typeof limit === "number" &&
- isFinite(limit) && limit >= 1 ? limit : 0;
- return new MappingPromiseArray(promises, fn, limit, _filter);
- }
- Promise.prototype.map = function (fn, options) {
- if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- return map(this, fn, options, null).promise();
- };
- Promise.map = function (promises, fn, options, _filter) {
- if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- return map(promises, fn, options, _filter).promise();
- };
- };
- },{"./async.js":2,"./util.js":38}],20:[function(_dereq_,module,exports){
- "use strict";
- module.exports =
- function(Promise, INTERNAL, tryConvertToPromise, apiRejection) {
- var util = _dereq_("./util.js");
- var tryCatch = util.tryCatch;
- Promise.method = function (fn) {
- if (typeof fn !== "function") {
- throw new Promise.TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- }
- return function () {
- var ret = new Promise(INTERNAL);
- ret._captureStackTrace();
- ret._pushContext();
- var value = tryCatch(fn).apply(this, arguments);
- ret._popContext();
- ret._resolveFromSyncValue(value);
- return ret;
- };
- };
- Promise.attempt = Promise["try"] = function (fn, args, ctx) {
- if (typeof fn !== "function") {
- return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- }
- var ret = new Promise(INTERNAL);
- ret._captureStackTrace();
- ret._pushContext();
- var value = util.isArray(args)
- ? tryCatch(fn).apply(ctx, args)
- : tryCatch(fn).call(ctx, args);
- ret._popContext();
- ret._resolveFromSyncValue(value);
- return ret;
- };
- Promise.prototype._resolveFromSyncValue = function (value) {
- if (value === util.errorObj) {
- this._rejectCallback(value.e, false, true);
- } else {
- this._resolveCallback(value, true);
- }
- };
- };
- },{"./util.js":38}],21:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise) {
- var util = _dereq_("./util.js");
- var async = _dereq_("./async.js");
- var tryCatch = util.tryCatch;
- var errorObj = util.errorObj;
- function spreadAdapter(val, nodeback) {
- var promise = this;
- if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback);
- var ret = tryCatch(nodeback).apply(promise._boundTo, [null].concat(val));
- if (ret === errorObj) {
- async.throwLater(ret.e);
- }
- }
- function successAdapter(val, nodeback) {
- var promise = this;
- var receiver = promise._boundTo;
- var ret = val === undefined
- ? tryCatch(nodeback).call(receiver, null)
- : tryCatch(nodeback).call(receiver, null, val);
- if (ret === errorObj) {
- async.throwLater(ret.e);
- }
- }
- function errorAdapter(reason, nodeback) {
- var promise = this;
- if (!reason) {
- var target = promise._target();
- var newReason = target._getCarriedStackTrace();
- newReason.cause = reason;
- reason = newReason;
- }
- var ret = tryCatch(nodeback).call(promise._boundTo, reason);
- if (ret === errorObj) {
- async.throwLater(ret.e);
- }
- }
- Promise.prototype.asCallback =
- Promise.prototype.nodeify = function (nodeback, options) {
- if (typeof nodeback == "function") {
- var adapter = successAdapter;
- if (options !== undefined && Object(options).spread) {
- adapter = spreadAdapter;
- }
- this._then(
- adapter,
- errorAdapter,
- undefined,
- this,
- nodeback
- );
- }
- return this;
- };
- };
- },{"./async.js":2,"./util.js":38}],22:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, PromiseArray) {
- var util = _dereq_("./util.js");
- var async = _dereq_("./async.js");
- var tryCatch = util.tryCatch;
- var errorObj = util.errorObj;
- Promise.prototype.progressed = function (handler) {
- return this._then(undefined, undefined, handler, undefined, undefined);
- };
- Promise.prototype._progress = function (progressValue) {
- if (this._isFollowingOrFulfilledOrRejected()) return;
- this._target()._progressUnchecked(progressValue);
- };
- Promise.prototype._progressHandlerAt = function (index) {
- return index === 0
- ? this._progressHandler0
- : this[(index << 2) + index - 5 + 2];
- };
- Promise.prototype._doProgressWith = function (progression) {
- var progressValue = progression.value;
- var handler = progression.handler;
- var promise = progression.promise;
- var receiver = progression.receiver;
- var ret = tryCatch(handler).call(receiver, progressValue);
- if (ret === errorObj) {
- if (ret.e != null &&
- ret.e.name !== "StopProgressPropagation") {
- var trace = util.canAttachTrace(ret.e)
- ? ret.e : new Error(util.toString(ret.e));
- promise._attachExtraTrace(trace);
- promise._progress(ret.e);
- }
- } else if (ret instanceof Promise) {
- ret._then(promise._progress, null, null, promise, undefined);
- } else {
- promise._progress(ret);
- }
- };
- Promise.prototype._progressUnchecked = function (progressValue) {
- var len = this._length();
- var progress = this._progress;
- for (var i = 0; i < len; i++) {
- var handler = this._progressHandlerAt(i);
- var promise = this._promiseAt(i);
- if (!(promise instanceof Promise)) {
- var receiver = this._receiverAt(i);
- if (typeof handler === "function") {
- handler.call(receiver, progressValue, promise);
- } else if (receiver instanceof PromiseArray &&
- !receiver._isResolved()) {
- 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(progress, promise, progressValue);
- }
- }
- };
- };
- },{"./async.js":2,"./util.js":38}],23:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function() {
- var makeSelfResolutionError = function () {
- return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/LhFpo0\u000a");
- };
- var reflect = function() {
- return new Promise.PromiseInspection(this._target());
- };
- var apiRejection = function(msg) {
- return Promise.reject(new TypeError(msg));
- };
- var util = _dereq_("./util.js");
- var async = _dereq_("./async.js");
- var errors = _dereq_("./errors.js");
- var TypeError = Promise.TypeError = errors.TypeError;
- Promise.RangeError = errors.RangeError;
- Promise.CancellationError = errors.CancellationError;
- Promise.TimeoutError = errors.TimeoutError;
- Promise.OperationalError = errors.OperationalError;
- Promise.RejectionError = errors.OperationalError;
- Promise.AggregateError = errors.AggregateError;
- var INTERNAL = function(){};
- var APPLY = {};
- var NEXT_FILTER = {e: null};
- var tryConvertToPromise = _dereq_("./thenables.js")(Promise, INTERNAL);
- var PromiseArray =
- _dereq_("./promise_array.js")(Promise, INTERNAL,
- tryConvertToPromise, apiRejection);
- var CapturedTrace = _dereq_("./captured_trace.js")();
- var isDebugging = _dereq_("./debuggability.js")(Promise, CapturedTrace);
- /*jshint unused:false*/
- var createContext =
- _dereq_("./context.js")(Promise, CapturedTrace, isDebugging);
- var CatchFilter = _dereq_("./catch_filter.js")(NEXT_FILTER);
- var PromiseResolver = _dereq_("./promise_resolver.js");
- var nodebackForPromise = PromiseResolver._nodebackForPromise;
- var errorObj = util.errorObj;
- var tryCatch = util.tryCatch;
- function Promise(resolver) {
- if (typeof resolver !== "function") {
- throw new TypeError("the promise constructor requires a resolver function\u000a\u000a See http://goo.gl/EC22Yn\u000a");
- }
- if (this.constructor !== Promise) {
- throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/KsIlge\u000a");
- }
- this._bitField = 0;
- this._fulfillmentHandler0 = undefined;
- this._rejectionHandler0 = undefined;
- this._progressHandler0 = undefined;
- this._promise0 = undefined;
- this._receiver0 = undefined;
- this._settledValue = undefined;
- if (resolver !== INTERNAL) this._resolveFromResolver(resolver);
- }
- Promise.prototype.toString = function () {
- return "[object Promise]";
- };
- Promise.prototype.caught = Promise.prototype["catch"] = function (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 {
- return Promise.reject(
- new TypeError("Catch filter must inherit from Error or be a simple predicate function\u000a\u000a See http://goo.gl/o84o68\u000a"));
- }
- }
- catchInstances.length = j;
- fn = arguments[i];
- var catchFilter = new CatchFilter(catchInstances, fn, this);
- return this._then(undefined, catchFilter.doFilter, undefined,
- catchFilter, undefined);
- }
- return this._then(undefined, fn, undefined, undefined, undefined);
- };
- Promise.prototype.reflect = function () {
- return this._then(reflect, reflect, undefined, this, undefined);
- };
- Promise.prototype.then = function (didFulfill, didReject, didProgress) {
- if (isDebugging() && arguments.length > 0 &&
- typeof didFulfill !== "function" &&
- typeof didReject !== "function") {
- var msg = ".then() only accepts functions but was passed: " +
- util.classString(didFulfill);
- if (arguments.length > 1) {
- msg += ", " + util.classString(didReject);
- }
- this._warn(msg);
- }
- return this._then(didFulfill, didReject, didProgress,
- undefined, undefined);
- };
- Promise.prototype.done = function (didFulfill, didReject, didProgress) {
- var promise = this._then(didFulfill, didReject, didProgress,
- undefined, undefined);
- promise._setIsFinal();
- };
- Promise.prototype.spread = function (didFulfill, didReject) {
- return this.all()._then(didFulfill, didReject, undefined, APPLY, undefined);
- };
- Promise.prototype.isCancellable = function () {
- return !this.isResolved() &&
- this._cancellable();
- };
- Promise.prototype.toJSON = function () {
- var ret = {
- isFulfilled: false,
- isRejected: false,
- fulfillmentValue: undefined,
- rejectionReason: undefined
- };
- if (this.isFulfilled()) {
- ret.fulfillmentValue = this.value();
- ret.isFulfilled = true;
- } else if (this.isRejected()) {
- ret.rejectionReason = this.reason();
- ret.isRejected = true;
- }
- return ret;
- };
- Promise.prototype.all = function () {
- return new PromiseArray(this).promise();
- };
- Promise.prototype.error = function (fn) {
- return this.caught(util.originatesFromRejection, fn);
- };
- Promise.is = function (val) {
- return val instanceof Promise;
- };
- Promise.fromNode = function(fn) {
- var ret = new Promise(INTERNAL);
- var result = tryCatch(fn)(nodebackForPromise(ret));
- if (result === errorObj) {
- ret._rejectCallback(result.e, true, true);
- }
- return ret;
- };
- Promise.all = function (promises) {
- return new PromiseArray(promises).promise();
- };
- Promise.defer = Promise.pending = function () {
- var promise = new Promise(INTERNAL);
- return new PromiseResolver(promise);
- };
- Promise.cast = function (obj) {
- var ret = tryConvertToPromise(obj);
- if (!(ret instanceof Promise)) {
- var val = ret;
- ret = new Promise(INTERNAL);
- ret._fulfillUnchecked(val);
- }
- return ret;
- };
- Promise.resolve = Promise.fulfilled = Promise.cast;
- Promise.reject = Promise.rejected = function (reason) {
- var ret = new Promise(INTERNAL);
- ret._captureStackTrace();
- ret._rejectCallback(reason, true);
- return ret;
- };
- Promise.setScheduler = function(fn) {
- if (typeof fn !== "function") throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- var prev = async._schedule;
- async._schedule = fn;
- return prev;
- };
- Promise.prototype._then = function (
- didFulfill,
- didReject,
- didProgress,
- receiver,
- internalData
- ) {
- var haveInternalData = internalData !== undefined;
- var ret = haveInternalData ? internalData : new Promise(INTERNAL);
- if (!haveInternalData) {
- ret._propagateFrom(this, 4 | 1);
- ret._captureStackTrace();
- }
- var target = this._target();
- if (target !== this) {
- if (receiver === undefined) receiver = this._boundTo;
- if (!haveInternalData) ret._setIsMigrated();
- }
- var callbackIndex =
- target._addCallbacks(didFulfill, didReject, didProgress, ret, receiver);
- if (target._isResolved() && !target._isSettlePromisesQueued()) {
- async.invoke(
- target._settlePromiseAtPostResolution, target, callbackIndex);
- }
- return ret;
- };
- Promise.prototype._settlePromiseAtPostResolution = function (index) {
- if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled();
- this._settlePromiseAt(index);
- };
- Promise.prototype._length = function () {
- return this._bitField & 131071;
- };
- Promise.prototype._isFollowingOrFulfilledOrRejected = function () {
- return (this._bitField & 939524096) > 0;
- };
- Promise.prototype._isFollowing = function () {
- return (this._bitField & 536870912) === 536870912;
- };
- Promise.prototype._setLength = function (len) {
- this._bitField = (this._bitField & -131072) |
- (len & 131071);
- };
- Promise.prototype._setFulfilled = function () {
- this._bitField = this._bitField | 268435456;
- };
- Promise.prototype._setRejected = function () {
- this._bitField = this._bitField | 134217728;
- };
- Promise.prototype._setFollowing = function () {
- this._bitField = this._bitField | 536870912;
- };
- Promise.prototype._setIsFinal = function () {
- this._bitField = this._bitField | 33554432;
- };
- Promise.prototype._isFinal = function () {
- return (this._bitField & 33554432) > 0;
- };
- Promise.prototype._cancellable = function () {
- return (this._bitField & 67108864) > 0;
- };
- Promise.prototype._setCancellable = function () {
- this._bitField = this._bitField | 67108864;
- };
- Promise.prototype._unsetCancellable = function () {
- this._bitField = this._bitField & (~67108864);
- };
- Promise.prototype._setIsMigrated = function () {
- this._bitField = this._bitField | 4194304;
- };
- Promise.prototype._unsetIsMigrated = function () {
- this._bitField = this._bitField & (~4194304);
- };
- Promise.prototype._isMigrated = function () {
- return (this._bitField & 4194304) > 0;
- };
- Promise.prototype._receiverAt = function (index) {
- var ret = index === 0
- ? this._receiver0
- : this[
- index * 5 - 5 + 4];
- if (ret === undefined && this._isBound()) {
- return this._boundTo;
- }
- return ret;
- };
- Promise.prototype._promiseAt = function (index) {
- return index === 0
- ? this._promise0
- : this[index * 5 - 5 + 3];
- };
- Promise.prototype._fulfillmentHandlerAt = function (index) {
- return index === 0
- ? this._fulfillmentHandler0
- : this[index * 5 - 5 + 0];
- };
- Promise.prototype._rejectionHandlerAt = function (index) {
- return index === 0
- ? this._rejectionHandler0
- : this[index * 5 - 5 + 1];
- };
- Promise.prototype._migrateCallbacks = function (follower, index) {
- var fulfill = follower._fulfillmentHandlerAt(index);
- var reject = follower._rejectionHandlerAt(index);
- var progress = follower._progressHandlerAt(index);
- var promise = follower._promiseAt(index);
- var receiver = follower._receiverAt(index);
- if (promise instanceof Promise) promise._setIsMigrated();
- this._addCallbacks(fulfill, reject, progress, promise, receiver);
- };
- Promise.prototype._addCallbacks = function (
- fulfill,
- reject,
- progress,
- promise,
- receiver
- ) {
- var index = this._length();
- if (index >= 131071 - 5) {
- index = 0;
- this._setLength(0);
- }
- if (index === 0) {
- this._promise0 = promise;
- if (receiver !== undefined) 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 base = index * 5 - 5;
- this[base + 3] = promise;
- this[base + 4] = receiver;
- if (typeof fulfill === "function")
- this[base + 0] = fulfill;
- if (typeof reject === "function")
- this[base + 1] = reject;
- if (typeof progress === "function")
- this[base + 2] = progress;
- }
- this._setLength(index + 1);
- return index;
- };
- Promise.prototype._setProxyHandlers = function (receiver, promiseSlotValue) {
- var index = this._length();
- if (index >= 131071 - 5) {
- index = 0;
- this._setLength(0);
- }
- if (index === 0) {
- this._promise0 = promiseSlotValue;
- this._receiver0 = receiver;
- } else {
- var base = index * 5 - 5;
- this[base + 3] = promiseSlotValue;
- this[base + 4] = receiver;
- }
- this._setLength(index + 1);
- };
- Promise.prototype._proxyPromiseArray = function (promiseArray, index) {
- this._setProxyHandlers(promiseArray, index);
- };
- Promise.prototype._resolveCallback = function(value, shouldBind) {
- if (this._isFollowingOrFulfilledOrRejected()) return;
- if (value === this)
- return this._rejectCallback(makeSelfResolutionError(), false, true);
- var maybePromise = tryConvertToPromise(value, this);
- if (!(maybePromise instanceof Promise)) return this._fulfill(value);
- var propagationFlags = 1 | (shouldBind ? 4 : 0);
- this._propagateFrom(maybePromise, propagationFlags);
- var promise = maybePromise._target();
- if (promise._isPending()) {
- var len = this._length();
- for (var i = 0; i < len; ++i) {
- promise._migrateCallbacks(this, i);
- }
- this._setFollowing();
- this._setLength(0);
- this._setFollowee(promise);
- } else if (promise._isFulfilled()) {
- this._fulfillUnchecked(promise._value());
- } else {
- this._rejectUnchecked(promise._reason(),
- promise._getCarriedStackTrace());
- }
- };
- Promise.prototype._rejectCallback =
- function(reason, synchronous, shouldNotMarkOriginatingFromRejection) {
- if (!shouldNotMarkOriginatingFromRejection) {
- util.markAsOriginatingFromRejection(reason);
- }
- var trace = util.ensureErrorObject(reason);
- var hasStack = trace === reason;
- this._attachExtraTrace(trace, synchronous ? hasStack : false);
- this._reject(reason, hasStack ? undefined : trace);
- };
- Promise.prototype._resolveFromResolver = function (resolver) {
- var promise = this;
- this._captureStackTrace();
- this._pushContext();
- var synchronous = true;
- var r = tryCatch(resolver)(function(value) {
- if (promise === null) return;
- promise._resolveCallback(value);
- promise = null;
- }, function (reason) {
- if (promise === null) return;
- promise._rejectCallback(reason, synchronous);
- promise = null;
- });
- synchronous = false;
- this._popContext();
- if (r !== undefined && r === errorObj && promise !== null) {
- promise._rejectCallback(r.e, true, true);
- promise = null;
- }
- };
- Promise.prototype._settlePromiseFromHandler = function (
- handler, receiver, value, promise
- ) {
- if (promise._isRejected()) return;
- promise._pushContext();
- var x;
- if (receiver === APPLY && !this._isRejected()) {
- x = tryCatch(handler).apply(this._boundTo, value);
- } else {
- x = tryCatch(handler).call(receiver, value);
- }
- promise._popContext();
- if (x === errorObj || x === promise || x === NEXT_FILTER) {
- var err = x === promise ? makeSelfResolutionError() : x.e;
- promise._rejectCallback(err, false, true);
- } else {
- promise._resolveCallback(x);
- }
- };
- Promise.prototype._target = function() {
- var ret = this;
- while (ret._isFollowing()) ret = ret._followee();
- return ret;
- };
- Promise.prototype._followee = function() {
- return this._rejectionHandler0;
- };
- Promise.prototype._setFollowee = function(promise) {
- this._rejectionHandler0 = promise;
- };
- Promise.prototype._cleanValues = function () {
- if (this._cancellable()) {
- this._cancellationParent = undefined;
- }
- };
- Promise.prototype._propagateFrom = function (parent, flags) {
- if ((flags & 1) > 0 && parent._cancellable()) {
- this._setCancellable();
- this._cancellationParent = parent;
- }
- if ((flags & 4) > 0 && parent._isBound()) {
- this._setBoundTo(parent._boundTo);
- }
- };
- Promise.prototype._fulfill = function (value) {
- if (this._isFollowingOrFulfilledOrRejected()) return;
- this._fulfillUnchecked(value);
- };
- Promise.prototype._reject = function (reason, carriedStackTrace) {
- if (this._isFollowingOrFulfilledOrRejected()) return;
- this._rejectUnchecked(reason, carriedStackTrace);
- };
- Promise.prototype._settlePromiseAt = function (index) {
- var promise = this._promiseAt(index);
- var isPromise = promise instanceof Promise;
- if (isPromise && promise._isMigrated()) {
- promise._unsetIsMigrated();
- return async.invoke(this._settlePromiseAt, this, index);
- }
- var handler = this._isFulfilled()
- ? this._fulfillmentHandlerAt(index)
- : this._rejectionHandlerAt(index);
- var carriedStackTrace =
- this._isCarryingStackTrace() ? this._getCarriedStackTrace() : undefined;
- var value = this._settledValue;
- var receiver = this._receiverAt(index);
- this._clearCallbackDataAtIndex(index);
- if (typeof handler === "function") {
- if (!isPromise) {
- handler.call(receiver, value, promise);
- } else {
- this._settlePromiseFromHandler(handler, receiver, value, promise);
- }
- } else if (receiver instanceof PromiseArray) {
- if (!receiver._isResolved()) {
- if (this._isFulfilled()) {
- receiver._promiseFulfilled(value, promise);
- }
- else {
- receiver._promiseRejected(value, promise);
- }
- }
- } else if (isPromise) {
- if (this._isFulfilled()) {
- promise._fulfill(value);
- } else {
- promise._reject(value, carriedStackTrace);
- }
- }
- if (index >= 4 && (index & 31) === 4)
- async.invokeLater(this._setLength, this, 0);
- };
- Promise.prototype._clearCallbackDataAtIndex = function(index) {
- if (index === 0) {
- if (!this._isCarryingStackTrace()) {
- this._fulfillmentHandler0 = undefined;
- }
- this._rejectionHandler0 =
- this._progressHandler0 =
- this._receiver0 =
- this._promise0 = undefined;
- } else {
- var base = index * 5 - 5;
- this[base + 3] =
- this[base + 4] =
- this[base + 0] =
- this[base + 1] =
- this[base + 2] = undefined;
- }
- };
- Promise.prototype._isSettlePromisesQueued = function () {
- return (this._bitField &
- -1073741824) === -1073741824;
- };
- Promise.prototype._setSettlePromisesQueued = function () {
- this._bitField = this._bitField | -1073741824;
- };
- Promise.prototype._unsetSettlePromisesQueued = function () {
- this._bitField = this._bitField & (~-1073741824);
- };
- Promise.prototype._queueSettlePromises = function() {
- async.settlePromises(this);
- this._setSettlePromisesQueued();
- };
- Promise.prototype._fulfillUnchecked = function (value) {
- if (value === this) {
- var err = makeSelfResolutionError();
- this._attachExtraTrace(err);
- return this._rejectUnchecked(err, undefined);
- }
- this._setFulfilled();
- this._settledValue = value;
- this._cleanValues();
- if (this._length() > 0) {
- this._queueSettlePromises();
- }
- };
- Promise.prototype._rejectUncheckedCheckError = function (reason) {
- var trace = util.ensureErrorObject(reason);
- this._rejectUnchecked(reason, trace === reason ? undefined : trace);
- };
- Promise.prototype._rejectUnchecked = function (reason, trace) {
- if (reason === this) {
- var err = makeSelfResolutionError();
- this._attachExtraTrace(err);
- return this._rejectUnchecked(err);
- }
- this._setRejected();
- this._settledValue = reason;
- this._cleanValues();
- if (this._isFinal()) {
- async.throwLater(function(e) {
- if ("stack" in e) {
- async.invokeFirst(
- CapturedTrace.unhandledRejection, undefined, e);
- }
- throw e;
- }, trace === undefined ? reason : trace);
- return;
- }
- if (trace !== undefined && trace !== reason) {
- this._setCarriedStackTrace(trace);
- }
- if (this._length() > 0) {
- this._queueSettlePromises();
- } else {
- this._ensurePossibleRejectionHandled();
- }
- };
- Promise.prototype._settlePromises = function () {
- this._unsetSettlePromisesQueued();
- var len = this._length();
- for (var i = 0; i < len; i++) {
- this._settlePromiseAt(i);
- }
- };
- Promise._makeSelfResolutionError = makeSelfResolutionError;
- _dereq_("./progress.js")(Promise, PromiseArray);
- _dereq_("./method.js")(Promise, INTERNAL, tryConvertToPromise, apiRejection);
- _dereq_("./bind.js")(Promise, INTERNAL, tryConvertToPromise);
- _dereq_("./finally.js")(Promise, NEXT_FILTER, tryConvertToPromise);
- _dereq_("./direct_resolve.js")(Promise);
- _dereq_("./synchronous_inspection.js")(Promise);
- _dereq_("./join.js")(Promise, PromiseArray, tryConvertToPromise, INTERNAL);
- Promise.Promise = Promise;
- _dereq_('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL);
- _dereq_('./cancel.js')(Promise);
- _dereq_('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext);
- _dereq_('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise);
- _dereq_('./nodeify.js')(Promise);
- _dereq_('./call_get.js')(Promise);
- _dereq_('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection);
- _dereq_('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection);
- _dereq_('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL);
- _dereq_('./settle.js')(Promise, PromiseArray);
- _dereq_('./some.js')(Promise, PromiseArray, apiRejection);
- _dereq_('./promisify.js')(Promise, INTERNAL);
- _dereq_('./any.js')(Promise);
- _dereq_('./each.js')(Promise, INTERNAL);
- _dereq_('./timers.js')(Promise, INTERNAL);
- _dereq_('./filter.js')(Promise, INTERNAL);
-
- util.toFastProperties(Promise);
- util.toFastProperties(Promise.prototype);
- function fillTypes(value) {
- var p = new Promise(INTERNAL);
- p._fulfillmentHandler0 = value;
- p._rejectionHandler0 = value;
- p._progressHandler0 = value;
- p._promise0 = value;
- p._receiver0 = value;
- p._settledValue = value;
- }
- // Complete slack tracking, opt out of field-type tracking and
- // stabilize map
- fillTypes({a: 1});
- fillTypes({b: 2});
- fillTypes({c: 3});
- fillTypes(1);
- fillTypes(function(){});
- fillTypes(undefined);
- fillTypes(false);
- fillTypes(new Promise(INTERNAL));
- CapturedTrace.setBounds(async.firstLineError, util.lastLineError);
- return Promise;
- };
- },{"./any.js":1,"./async.js":2,"./bind.js":3,"./call_get.js":5,"./cancel.js":6,"./captured_trace.js":7,"./catch_filter.js":8,"./context.js":9,"./debuggability.js":10,"./direct_resolve.js":11,"./each.js":12,"./errors.js":13,"./filter.js":15,"./finally.js":16,"./generators.js":17,"./join.js":18,"./map.js":19,"./method.js":20,"./nodeify.js":21,"./progress.js":22,"./promise_array.js":24,"./promise_resolver.js":25,"./promisify.js":26,"./props.js":27,"./race.js":29,"./reduce.js":30,"./settle.js":32,"./some.js":33,"./synchronous_inspection.js":34,"./thenables.js":35,"./timers.js":36,"./using.js":37,"./util.js":38}],24:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL, tryConvertToPromise,
- apiRejection) {
- var util = _dereq_("./util.js");
- var isArray = util.isArray;
- function toResolutionValue(val) {
- switch(val) {
- case -2: return [];
- case -3: return {};
- }
- }
- function PromiseArray(values) {
- var promise = this._promise = new Promise(INTERNAL);
- var parent;
- if (values instanceof Promise) {
- parent = values;
- promise._propagateFrom(parent, 1 | 4);
- }
- this._values = values;
- this._length = 0;
- this._totalResolved = 0;
- this._init(undefined, -2);
- }
- PromiseArray.prototype.length = function () {
- return this._length;
- };
- PromiseArray.prototype.promise = function () {
- return this._promise;
- };
- PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
- var values = tryConvertToPromise(this._values, this._promise);
- if (values instanceof Promise) {
- values = values._target();
- this._values = values;
- if (values._isFulfilled()) {
- values = values._value();
- if (!isArray(values)) {
- var err = new Promise.TypeError("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a");
- this.__hardReject__(err);
- return;
- }
- } else if (values._isPending()) {
- values._then(
- init,
- this._reject,
- undefined,
- this,
- resolveValueIfEmpty
- );
- return;
- } else {
- this._reject(values._reason());
- return;
- }
- } else if (!isArray(values)) {
- this._promise._reject(apiRejection("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a")._reason());
- return;
- }
- if (values.length === 0) {
- if (resolveValueIfEmpty === -5) {
- this._resolveEmptyArray();
- }
- else {
- this._resolve(toResolutionValue(resolveValueIfEmpty));
- }
- return;
- }
- var len = this.getActualLength(values.length);
- this._length = len;
- this._values = this.shouldCopyValues() ? new Array(len) : this._values;
- var promise = this._promise;
- for (var i = 0; i < len; ++i) {
- var isResolved = this._isResolved();
- var maybePromise = tryConvertToPromise(values[i], promise);
- if (maybePromise instanceof Promise) {
- maybePromise = maybePromise._target();
- if (isResolved) {
- maybePromise._unsetRejectionIsUnhandled();
- } else if (maybePromise._isPending()) {
- maybePromise._proxyPromiseArray(this, i);
- } else if (maybePromise._isFulfilled()) {
- this._promiseFulfilled(maybePromise._value(), i);
- } else {
- this._promiseRejected(maybePromise._reason(), i);
- }
- } else if (!isResolved) {
- this._promiseFulfilled(maybePromise, i);
- }
- }
- };
- PromiseArray.prototype._isResolved = function () {
- return this._values === null;
- };
- PromiseArray.prototype._resolve = function (value) {
- this._values = null;
- this._promise._fulfill(value);
- };
- PromiseArray.prototype.__hardReject__ =
- PromiseArray.prototype._reject = function (reason) {
- this._values = null;
- this._promise._rejectCallback(reason, false, true);
- };
- PromiseArray.prototype._promiseProgressed = function (progressValue, index) {
- this._promise._progress({
- index: index,
- value: progressValue
- });
- };
- PromiseArray.prototype._promiseFulfilled = function (value, index) {
- this._values[index] = value;
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= this._length) {
- this._resolve(this._values);
- }
- };
- PromiseArray.prototype._promiseRejected = function (reason, index) {
- this._totalResolved++;
- this._reject(reason);
- };
- PromiseArray.prototype.shouldCopyValues = function () {
- return true;
- };
- PromiseArray.prototype.getActualLength = function (len) {
- return len;
- };
- return PromiseArray;
- };
- },{"./util.js":38}],25:[function(_dereq_,module,exports){
- "use strict";
- var util = _dereq_("./util.js");
- var maybeWrapAsError = util.maybeWrapAsError;
- var errors = _dereq_("./errors.js");
- var TimeoutError = errors.TimeoutError;
- var OperationalError = errors.OperationalError;
- var haveGetters = util.haveGetters;
- var es5 = _dereq_("./es5.js");
- function isUntypedError(obj) {
- return obj instanceof Error &&
- es5.getPrototypeOf(obj) === Error.prototype;
- }
- var rErrorKey = /^(?:name|message|stack|cause)$/;
- function wrapAsOperationalError(obj) {
- var ret;
- if (isUntypedError(obj)) {
- ret = new OperationalError(obj);
- ret.name = obj.name;
- ret.message = obj.message;
- ret.stack = obj.stack;
- var keys = es5.keys(obj);
- for (var i = 0; i < keys.length; ++i) {
- var key = keys[i];
- if (!rErrorKey.test(key)) {
- ret[key] = obj[key];
- }
- }
- return ret;
- }
- util.markAsOriginatingFromRejection(obj);
- return obj;
- }
- function nodebackForPromise(promise) {
- return function(err, value) {
- if (promise === null) return;
- if (err) {
- var wrapped = wrapAsOperationalError(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;
- };
- }
- var PromiseResolver;
- if (!haveGetters) {
- PromiseResolver = function (promise) {
- this.promise = promise;
- this.asCallback = nodebackForPromise(promise);
- this.callback = this.asCallback;
- };
- }
- else {
- PromiseResolver = function (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 () {
- return "[object PromiseResolver]";
- };
- PromiseResolver.prototype.resolve =
- PromiseResolver.prototype.fulfill = function (value) {
- if (!(this instanceof PromiseResolver)) {
- throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\u000a\u000a See http://goo.gl/sdkXL9\u000a");
- }
- this.promise._resolveCallback(value);
- };
- PromiseResolver.prototype.reject = function (reason) {
- if (!(this instanceof PromiseResolver)) {
- throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\u000a\u000a See http://goo.gl/sdkXL9\u000a");
- }
- this.promise._rejectCallback(reason);
- };
- PromiseResolver.prototype.progress = function (value) {
- if (!(this instanceof PromiseResolver)) {
- throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\u000a\u000a See http://goo.gl/sdkXL9\u000a");
- }
- this.promise._progress(value);
- };
- PromiseResolver.prototype.cancel = function (err) {
- this.promise.cancel(err);
- };
- PromiseResolver.prototype.timeout = function () {
- this.reject(new TimeoutError("timeout"));
- };
- PromiseResolver.prototype.isResolved = function () {
- return this.promise.isResolved();
- };
- PromiseResolver.prototype.toJSON = function () {
- return this.promise.toJSON();
- };
- module.exports = PromiseResolver;
- },{"./errors.js":13,"./es5.js":14,"./util.js":38}],26:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var THIS = {};
- var util = _dereq_("./util.js");
- var nodebackForPromise = _dereq_("./promise_resolver.js")
- ._nodebackForPromise;
- var withAppended = util.withAppended;
- var maybeWrapAsError = util.maybeWrapAsError;
- var canEvaluate = util.canEvaluate;
- var TypeError = _dereq_("./errors").TypeError;
- var defaultSuffix = "Async";
- var defaultPromisified = {__isPromisified__: true};
- var noCopyPropsPattern =
- /^(?:length|name|arguments|caller|callee|prototype|__isPromisified__)$/;
- var defaultFilter = function(name, func) {
- return util.isIdentifier(name) &&
- name.charAt(0) !== "_" &&
- !util.isClass(func);
- };
- function propsFilter(key) {
- return !noCopyPropsPattern.test(key);
- }
- function isPromisified(fn) {
- try {
- return fn.__isPromisified__ === true;
- }
- catch (e) {
- return false;
- }
- }
- function hasPromisified(obj, key, suffix) {
- var val = util.getDataPropertyOrDefault(obj, key + suffix,
- defaultPromisified);
- return val ? isPromisified(val) : false;
- }
- function checkValid(ret, suffix, suffixRegexp) {
- for (var i = 0; i < ret.length; i += 2) {
- var key = ret[i];
- if (suffixRegexp.test(key)) {
- var keyWithoutAsyncSuffix = key.replace(suffixRegexp, "");
- for (var j = 0; j < ret.length; j += 2) {
- if (ret[j] === keyWithoutAsyncSuffix) {
- throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\u000a\u000a See http://goo.gl/iWrZbw\u000a"
- .replace("%s", suffix));
- }
- }
- }
- }
- }
- function promisifiableMethods(obj, suffix, suffixRegexp, filter) {
- var keys = util.inheritedDataKeys(obj);
- var ret = [];
- for (var i = 0; i < keys.length; ++i) {
- var key = keys[i];
- var value = obj[key];
- var passesDefaultFilter = filter === defaultFilter
- ? true : defaultFilter(key, value, obj);
- if (typeof value === "function" &&
- !isPromisified(value) &&
- !hasPromisified(obj, key, suffix) &&
- filter(key, value, obj, passesDefaultFilter)) {
- ret.push(key, value);
- }
- }
- checkValid(ret, suffix, suffixRegexp);
- return ret;
- }
- var escapeIdentRegex = function(str) {
- return str.replace(/([$])/, "\\$");
- };
- var makeNodePromisifiedEval;
- if (!true) {
- var switchCaseArgumentOrder = function(likelyArgumentCount) {
- var ret = [likelyArgumentCount];
- var min = Math.max(0, likelyArgumentCount - 1 - 3);
- for(var i = likelyArgumentCount - 1; i >= min; --i) {
- ret.push(i);
- }
- for(var i = likelyArgumentCount + 1; i <= 3; ++i) {
- ret.push(i);
- }
- return ret;
- };
- var argumentSequence = function(argumentCount) {
- return util.filledRange(argumentCount, "_arg", "");
- };
- var parameterDeclaration = function(parameterCount) {
- return util.filledRange(
- Math.max(parameterCount, 3), "_arg", "");
- };
- var parameterCount = function(fn) {
- if (typeof fn.length === "number") {
- return Math.max(Math.min(fn.length, 1023 + 1), 0);
- }
- return 0;
- };
- makeNodePromisifiedEval =
- function(callback, receiver, originalName, fn) {
- var newParameterCount = Math.max(0, parameterCount(fn) - 1);
- var argumentOrder = switchCaseArgumentOrder(newParameterCount);
- var shouldProxyThis = typeof callback === "string" || receiver === THIS;
- function generateCallForArgumentCount(count) {
- var args = argumentSequence(count).join(", ");
- var comma = count > 0 ? ", " : "";
- var ret;
- if (shouldProxyThis) {
- ret = "ret = callback.call(this, {{args}}, nodeback); break;\n";
- } else {
- ret = receiver === undefined
- ? "ret = callback({{args}}, nodeback); break;\n"
- : "ret = callback.call(receiver, {{args}}, nodeback); break;\n";
- }
- return ret.replace("{{args}}", args).replace(", ", comma);
- }
- function generateArgumentSwitchCase() {
- var ret = "";
- for (var i = 0; i < argumentOrder.length; ++i) {
- ret += "case " + argumentOrder[i] +":" +
- generateCallForArgumentCount(argumentOrder[i]);
- }
- ret += " \n\
- default: \n\
- var args = new Array(len + 1); \n\
- var i = 0; \n\
- for (var i = 0; i < len; ++i) { \n\
- args[i] = arguments[i]; \n\
- } \n\
- args[i] = nodeback; \n\
- [CodeForCall] \n\
- break; \n\
- ".replace("[CodeForCall]", (shouldProxyThis
- ? "ret = callback.apply(this, args);\n"
- : "ret = callback.apply(receiver, args);\n"));
- return ret;
- }
- var getFunctionCode = typeof callback === "string"
- ? ("this != null ? this['"+callback+"'] : fn")
- : "fn";
- return new Function("Promise",
- "fn",
- "receiver",
- "withAppended",
- "maybeWrapAsError",
- "nodebackForPromise",
- "tryCatch",
- "errorObj",
- "INTERNAL","'use strict'; \n\
- var ret = function (Parameters) { \n\
- 'use strict'; \n\
- var len = arguments.length; \n\
- var promise = new Promise(INTERNAL); \n\
- promise._captureStackTrace(); \n\
- var nodeback = nodebackForPromise(promise); \n\
- var ret; \n\
- var callback = tryCatch([GetFunctionCode]); \n\
- switch(len) { \n\
- [CodeForSwitchCase] \n\
- } \n\
- if (ret === errorObj) { \n\
- promise._rejectCallback(maybeWrapAsError(ret.e), true, true);\n\
- } \n\
- return promise; \n\
- }; \n\
- ret.__isPromisified__ = true; \n\
- return ret; \n\
- "
- .replace("Parameters", parameterDeclaration(newParameterCount))
- .replace("[CodeForSwitchCase]", generateArgumentSwitchCase())
- .replace("[GetFunctionCode]", getFunctionCode))(
- Promise,
- fn,
- receiver,
- withAppended,
- maybeWrapAsError,
- nodebackForPromise,
- util.tryCatch,
- util.errorObj,
- INTERNAL
- );
- };
- }
- function makeNodePromisifiedClosure(callback, receiver, _, fn) {
- var defaultThis = (function() {return this;})();
- var method = callback;
- if (typeof method === "string") {
- callback = fn;
- }
- function promisified() {
- var _receiver = receiver;
- if (receiver === THIS) _receiver = this;
- var promise = new Promise(INTERNAL);
- promise._captureStackTrace();
- var cb = typeof method === "string" && this !== defaultThis
- ? this[method] : callback;
- var fn = nodebackForPromise(promise);
- try {
- cb.apply(_receiver, withAppended(arguments, fn));
- } catch(e) {
- promise._rejectCallback(maybeWrapAsError(e), true, true);
- }
- return promise;
- }
- promisified.__isPromisified__ = true;
- return promisified;
- }
- var makeNodePromisified = canEvaluate
- ? makeNodePromisifiedEval
- : makeNodePromisifiedClosure;
- function promisifyAll(obj, suffix, filter, promisifier) {
- var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$");
- var methods =
- promisifiableMethods(obj, suffix, suffixRegexp, filter);
- for (var i = 0, len = methods.length; i < len; i+= 2) {
- var key = methods[i];
- var fn = methods[i+1];
- var promisifiedKey = key + suffix;
- obj[promisifiedKey] = promisifier === makeNodePromisified
- ? makeNodePromisified(key, THIS, key, fn, suffix)
- : promisifier(fn, function() {
- return makeNodePromisified(key, THIS, key, fn, suffix);
- });
- }
- util.toFastProperties(obj);
- return obj;
- }
- function promisify(callback, receiver) {
- return makeNodePromisified(callback, receiver, undefined, callback);
- }
- Promise.promisify = function (fn, receiver) {
- if (typeof fn !== "function") {
- throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- }
- if (isPromisified(fn)) {
- return fn;
- }
- var ret = promisify(fn, arguments.length < 2 ? THIS : receiver);
- util.copyDescriptors(fn, ret, propsFilter);
- return ret;
- };
- Promise.promisifyAll = function (target, options) {
- if (typeof target !== "function" && typeof target !== "object") {
- throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/9ITlV0\u000a");
- }
- options = Object(options);
- var suffix = options.suffix;
- if (typeof suffix !== "string") suffix = defaultSuffix;
- var filter = options.filter;
- if (typeof filter !== "function") filter = defaultFilter;
- var promisifier = options.promisifier;
- if (typeof promisifier !== "function") promisifier = makeNodePromisified;
- if (!util.isIdentifier(suffix)) {
- throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/8FZo5V\u000a");
- }
- var keys = util.inheritedDataKeys(target);
- for (var i = 0; i < keys.length; ++i) {
- var value = target[keys[i]];
- if (keys[i] !== "constructor" &&
- util.isClass(value)) {
- promisifyAll(value.prototype, suffix, filter, promisifier);
- promisifyAll(value, suffix, filter, promisifier);
- }
- }
- return promisifyAll(target, suffix, filter, promisifier);
- };
- };
- },{"./errors":13,"./promise_resolver.js":25,"./util.js":38}],27:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(
- Promise, PromiseArray, tryConvertToPromise, apiRejection) {
- var util = _dereq_("./util.js");
- var isObject = util.isObject;
- var es5 = _dereq_("./es5.js");
- function PropertiesPromiseArray(obj) {
- var keys = es5.keys(obj);
- var len = keys.length;
- var values = new Array(len * 2);
- for (var i = 0; i < len; ++i) {
- var key = keys[i];
- values[i] = obj[key];
- values[i + len] = key;
- }
- this.constructor$(values);
- }
- util.inherits(PropertiesPromiseArray, PromiseArray);
- PropertiesPromiseArray.prototype._init = function () {
- this._init$(undefined, -3) ;
- };
- PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {
- 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 (value, index) {
- this._promise._progress({
- key: this._values[index + this.length()],
- value: value
- });
- };
- PropertiesPromiseArray.prototype.shouldCopyValues = function () {
- return false;
- };
- PropertiesPromiseArray.prototype.getActualLength = function (len) {
- return len >> 1;
- };
- function props(promises) {
- var ret;
- var castValue = tryConvertToPromise(promises);
- if (!isObject(castValue)) {
- return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/OsFKC8\u000a");
- } else if (castValue instanceof Promise) {
- ret = castValue._then(
- Promise.props, undefined, undefined, undefined, undefined);
- } else {
- ret = new PropertiesPromiseArray(castValue).promise();
- }
- if (castValue instanceof Promise) {
- ret._propagateFrom(castValue, 4);
- }
- return ret;
- }
- Promise.prototype.props = function () {
- return props(this);
- };
- Promise.props = function (promises) {
- return props(promises);
- };
- };
- },{"./es5.js":14,"./util.js":38}],28:[function(_dereq_,module,exports){
- "use strict";
- function arrayMove(src, srcIndex, dst, dstIndex, len) {
- for (var j = 0; j < len; ++j) {
- dst[j + dstIndex] = src[j + srcIndex];
- src[j + srcIndex] = void 0;
- }
- }
- function Queue(capacity) {
- this._capacity = capacity;
- this._length = 0;
- this._front = 0;
- }
- Queue.prototype._willBeOverCapacity = function (size) {
- return this._capacity < size;
- };
- Queue.prototype._pushOne = function (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._unshiftOne = function(value) {
- var capacity = this._capacity;
- this._checkCapacity(this.length() + 1);
- var front = this._front;
- var i = (((( front - 1 ) &
- ( capacity - 1) ) ^ capacity ) - capacity );
- this[i] = value;
- this._front = i;
- this._length = this.length() + 1;
- };
- Queue.prototype.unshift = function(fn, receiver, arg) {
- this._unshiftOne(arg);
- this._unshiftOne(receiver);
- this._unshiftOne(fn);
- };
- Queue.prototype.push = function (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 () {
- var front = this._front,
- ret = this[front];
- this[front] = undefined;
- this._front = (front + 1) & (this._capacity - 1);
- this._length--;
- return ret;
- };
- Queue.prototype.length = function () {
- return this._length;
- };
- Queue.prototype._checkCapacity = function (size) {
- if (this._capacity < size) {
- this._resizeTo(this._capacity << 1);
- }
- };
- Queue.prototype._resizeTo = function (capacity) {
- var oldCapacity = this._capacity;
- this._capacity = capacity;
- var front = this._front;
- var length = this._length;
- var moveItemsCount = (front + length) & (oldCapacity - 1);
- arrayMove(this, 0, this, oldCapacity, moveItemsCount);
- };
- module.exports = Queue;
- },{}],29:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(
- Promise, INTERNAL, tryConvertToPromise, apiRejection) {
- var isArray = _dereq_("./util.js").isArray;
- var raceLater = function (promise) {
- return promise.then(function(array) {
- return race(array, promise);
- });
- };
- function race(promises, parent) {
- var maybePromise = tryConvertToPromise(promises);
- if (maybePromise instanceof Promise) {
- return raceLater(maybePromise);
- } else if (!isArray(promises)) {
- return apiRejection("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a");
- }
- var ret = new Promise(INTERNAL);
- if (parent !== undefined) {
- ret._propagateFrom(parent, 4 | 1);
- }
- var fulfill = ret._fulfill;
- var reject = ret._reject;
- for (var i = 0, len = promises.length; i < len; ++i) {
- var val = promises[i];
- if (val === undefined && !(i in promises)) {
- continue;
- }
- Promise.cast(val)._then(fulfill, reject, undefined, ret, null);
- }
- return ret;
- }
- Promise.race = function (promises) {
- return race(promises, undefined);
- };
- Promise.prototype.race = function () {
- return race(this, undefined);
- };
- };
- },{"./util.js":38}],30:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise,
- PromiseArray,
- apiRejection,
- tryConvertToPromise,
- INTERNAL) {
- var async = _dereq_("./async.js");
- var util = _dereq_("./util.js");
- var tryCatch = util.tryCatch;
- var errorObj = util.errorObj;
- function ReductionPromiseArray(promises, fn, accum, _each) {
- this.constructor$(promises);
- this._promise._captureStackTrace();
- this._preservedValues = _each === INTERNAL ? [] : null;
- this._zerothIsAccum = (accum === undefined);
- this._gotAccum = false;
- this._reducingIndex = (this._zerothIsAccum ? 1 : 0);
- this._valuesPhase = undefined;
- var maybePromise = tryConvertToPromise(accum, this._promise);
- var rejected = false;
- var isPromise = maybePromise instanceof Promise;
- if (isPromise) {
- maybePromise = maybePromise._target();
- if (maybePromise._isPending()) {
- maybePromise._proxyPromiseArray(this, -1);
- } else if (maybePromise._isFulfilled()) {
- accum = maybePromise._value();
- this._gotAccum = true;
- } else {
- this._reject(maybePromise._reason());
- rejected = true;
- }
- }
- if (!(isPromise || this._zerothIsAccum)) this._gotAccum = true;
- this._callback = fn;
- this._accum = accum;
- if (!rejected) async.invoke(init, this, undefined);
- }
- function init() {
- this._init$(undefined, -5);
- }
- util.inherits(ReductionPromiseArray, PromiseArray);
- ReductionPromiseArray.prototype._init = function () {};
- ReductionPromiseArray.prototype._resolveEmptyArray = function () {
- if (this._gotAccum || this._zerothIsAccum) {
- this._resolve(this._preservedValues !== null
- ? [] : this._accum);
- }
- };
- ReductionPromiseArray.prototype._promiseFulfilled = function (value, index) {
- var values = this._values;
- values[index] = value;
- var length = this.length();
- var preservedValues = this._preservedValues;
- var isEach = preservedValues !== null;
- var gotAccum = this._gotAccum;
- var valuesPhase = this._valuesPhase;
- var valuesPhaseIndex;
- if (!valuesPhase) {
- valuesPhase = this._valuesPhase = new Array(length);
- for (valuesPhaseIndex=0; valuesPhaseIndex<length; ++valuesPhaseIndex) {
- valuesPhase[valuesPhaseIndex] = 0;
- }
- }
- valuesPhaseIndex = valuesPhase[index];
- if (index === 0 && this._zerothIsAccum) {
- this._accum = value;
- this._gotAccum = gotAccum = true;
- valuesPhase[index] = ((valuesPhaseIndex === 0)
- ? 1 : 2);
- } else if (index === -1) {
- this._accum = value;
- this._gotAccum = gotAccum = true;
- } else {
- if (valuesPhaseIndex === 0) {
- valuesPhase[index] = 1;
- } else {
- valuesPhase[index] = 2;
- this._accum = value;
- }
- }
- if (!gotAccum) return;
- var callback = this._callback;
- var receiver = this._promise._boundTo;
- var ret;
- for (var i = this._reducingIndex; i < length; ++i) {
- valuesPhaseIndex = valuesPhase[i];
- if (valuesPhaseIndex === 2) {
- this._reducingIndex = i + 1;
- continue;
- }
- if (valuesPhaseIndex !== 1) return;
- value = values[i];
- this._promise._pushContext();
- if (isEach) {
- preservedValues.push(value);
- ret = tryCatch(callback).call(receiver, value, i, length);
- }
- else {
- ret = tryCatch(callback)
- .call(receiver, this._accum, value, i, length);
- }
- this._promise._popContext();
- if (ret === errorObj) return this._reject(ret.e);
- var maybePromise = tryConvertToPromise(ret, this._promise);
- if (maybePromise instanceof Promise) {
- maybePromise = maybePromise._target();
- if (maybePromise._isPending()) {
- valuesPhase[i] = 4;
- return maybePromise._proxyPromiseArray(this, i);
- } else if (maybePromise._isFulfilled()) {
- ret = maybePromise._value();
- } else {
- return this._reject(maybePromise._reason());
- }
- }
- this._reducingIndex = i + 1;
- this._accum = ret;
- }
- this._resolve(isEach ? preservedValues : this._accum);
- };
- function reduce(promises, fn, initialValue, _each) {
- if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- var array = new ReductionPromiseArray(promises, fn, initialValue, _each);
- return array.promise();
- }
- Promise.prototype.reduce = function (fn, initialValue) {
- return reduce(this, fn, initialValue, null);
- };
- Promise.reduce = function (promises, fn, initialValue, _each) {
- return reduce(promises, fn, initialValue, _each);
- };
- };
- },{"./async.js":2,"./util.js":38}],31:[function(_dereq_,module,exports){
- "use strict";
- var schedule;
- var noAsyncScheduler = function() {
- throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/m3OTXk\u000a");
- };
- if (_dereq_("./util.js").isNode) {
- var version = process.versions.node.split(".").map(Number);
- schedule = (version[0] === 0 && version[1] > 10) || (version[0] > 0)
- ? function(fn) { global.setImmediate(fn); } : process.nextTick;
- if (!schedule) {
- if (typeof setImmediate !== "undefined") {
- schedule = setImmediate;
- } else if (typeof setTimeout !== "undefined") {
- schedule = setTimeout;
- } else {
- schedule = noAsyncScheduler;
- }
- }
- } else if (typeof MutationObserver !== "undefined") {
- schedule = function(fn) {
- var div = document.createElement("div");
- var observer = new MutationObserver(fn);
- observer.observe(div, {attributes: true});
- return function() { div.classList.toggle("foo"); };
- };
- schedule.isStatic = true;
- } else if (typeof setImmediate !== "undefined") {
- schedule = function (fn) {
- setImmediate(fn);
- };
- } else if (typeof setTimeout !== "undefined") {
- schedule = function (fn) {
- setTimeout(fn, 0);
- };
- } else {
- schedule = noAsyncScheduler;
- }
- module.exports = schedule;
- },{"./util.js":38}],32:[function(_dereq_,module,exports){
- "use strict";
- module.exports =
- function(Promise, PromiseArray) {
- var PromiseInspection = Promise.PromiseInspection;
- var util = _dereq_("./util.js");
- function SettledPromiseArray(values) {
- this.constructor$(values);
- }
- util.inherits(SettledPromiseArray, PromiseArray);
- SettledPromiseArray.prototype._promiseResolved = function (index, inspection) {
- this._values[index] = inspection;
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= this._length) {
- this._resolve(this._values);
- }
- };
- SettledPromiseArray.prototype._promiseFulfilled = function (value, index) {
- var ret = new PromiseInspection();
- ret._bitField = 268435456;
- ret._settledValue = value;
- this._promiseResolved(index, ret);
- };
- SettledPromiseArray.prototype._promiseRejected = function (reason, index) {
- var ret = new PromiseInspection();
- ret._bitField = 134217728;
- ret._settledValue = reason;
- this._promiseResolved(index, ret);
- };
- Promise.settle = function (promises) {
- return new SettledPromiseArray(promises).promise();
- };
- Promise.prototype.settle = function () {
- return new SettledPromiseArray(this).promise();
- };
- };
- },{"./util.js":38}],33:[function(_dereq_,module,exports){
- "use strict";
- module.exports =
- function(Promise, PromiseArray, apiRejection) {
- var util = _dereq_("./util.js");
- var RangeError = _dereq_("./errors.js").RangeError;
- var AggregateError = _dereq_("./errors.js").AggregateError;
- var isArray = util.isArray;
- function SomePromiseArray(values) {
- this.constructor$(values);
- this._howMany = 0;
- this._unwrap = false;
- this._initialized = false;
- }
- util.inherits(SomePromiseArray, PromiseArray);
- SomePromiseArray.prototype._init = function () {
- if (!this._initialized) {
- return;
- }
- if (this._howMany === 0) {
- this._resolve([]);
- return;
- }
- this._init$(undefined, -5);
- var isArrayResolved = isArray(this._values);
- if (!this._isResolved() &&
- isArrayResolved &&
- this._howMany > this._canPossiblyFulfill()) {
- this._reject(this._getRangeError(this.length()));
- }
- };
- SomePromiseArray.prototype.init = function () {
- this._initialized = true;
- this._init();
- };
- SomePromiseArray.prototype.setUnwrap = function () {
- this._unwrap = true;
- };
- SomePromiseArray.prototype.howMany = function () {
- return this._howMany;
- };
- SomePromiseArray.prototype.setHowMany = function (count) {
- this._howMany = count;
- };
- SomePromiseArray.prototype._promiseFulfilled = function (value) {
- 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 (reason) {
- this._addRejected(reason);
- if (this.howMany() > this._canPossiblyFulfill()) {
- var e = new AggregateError();
- for (var i = this.length(); i < this._values.length; ++i) {
- e.push(this._values[i]);
- }
- this._reject(e);
- }
- };
- SomePromiseArray.prototype._fulfilled = function () {
- return this._totalResolved;
- };
- SomePromiseArray.prototype._rejected = function () {
- return this._values.length - this.length();
- };
- SomePromiseArray.prototype._addRejected = function (reason) {
- this._values.push(reason);
- };
- SomePromiseArray.prototype._addFulfilled = function (value) {
- this._values[this._totalResolved++] = value;
- };
- SomePromiseArray.prototype._canPossiblyFulfill = function () {
- return this.length() - this._rejected();
- };
- SomePromiseArray.prototype._getRangeError = function (count) {
- var message = "Input array must contain at least " +
- this._howMany + " items but contains only " + count + " items";
- return new RangeError(message);
- };
- SomePromiseArray.prototype._resolveEmptyArray = function () {
- this._reject(this._getRangeError(0));
- };
- function some(promises, howMany) {
- if ((howMany | 0) !== howMany || howMany < 0) {
- return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/1wAmHx\u000a");
- }
- var ret = new SomePromiseArray(promises);
- var promise = ret.promise();
- ret.setHowMany(howMany);
- ret.init();
- return promise;
- }
- Promise.some = function (promises, howMany) {
- return some(promises, howMany);
- };
- Promise.prototype.some = function (howMany) {
- return some(this, howMany);
- };
- Promise._SomePromiseArray = SomePromiseArray;
- };
- },{"./errors.js":13,"./util.js":38}],34:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise) {
- function PromiseInspection(promise) {
- if (promise !== undefined) {
- promise = promise._target();
- this._bitField = promise._bitField;
- this._settledValue = promise._settledValue;
- }
- else {
- this._bitField = 0;
- this._settledValue = undefined;
- }
- }
- PromiseInspection.prototype.value = function () {
- if (!this.isFulfilled()) {
- throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/hc1DLj\u000a");
- }
- return this._settledValue;
- };
- PromiseInspection.prototype.error =
- PromiseInspection.prototype.reason = function () {
- if (!this.isRejected()) {
- throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/hPuiwB\u000a");
- }
- return this._settledValue;
- };
- PromiseInspection.prototype.isFulfilled =
- Promise.prototype._isFulfilled = function () {
- return (this._bitField & 268435456) > 0;
- };
- PromiseInspection.prototype.isRejected =
- Promise.prototype._isRejected = function () {
- return (this._bitField & 134217728) > 0;
- };
- PromiseInspection.prototype.isPending =
- Promise.prototype._isPending = function () {
- return (this._bitField & 402653184) === 0;
- };
- PromiseInspection.prototype.isResolved =
- Promise.prototype._isResolved = function () {
- return (this._bitField & 402653184) > 0;
- };
- Promise.prototype.isPending = function() {
- return this._target()._isPending();
- };
- Promise.prototype.isRejected = function() {
- return this._target()._isRejected();
- };
- Promise.prototype.isFulfilled = function() {
- return this._target()._isFulfilled();
- };
- Promise.prototype.isResolved = function() {
- return this._target()._isResolved();
- };
- Promise.prototype._value = function() {
- return this._settledValue;
- };
- Promise.prototype._reason = function() {
- this._unsetRejectionIsUnhandled();
- return this._settledValue;
- };
- Promise.prototype.value = function() {
- var target = this._target();
- if (!target.isFulfilled()) {
- throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/hc1DLj\u000a");
- }
- return target._settledValue;
- };
- Promise.prototype.reason = function() {
- var target = this._target();
- if (!target.isRejected()) {
- throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/hPuiwB\u000a");
- }
- target._unsetRejectionIsUnhandled();
- return target._settledValue;
- };
- Promise.PromiseInspection = PromiseInspection;
- };
- },{}],35:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var util = _dereq_("./util.js");
- var errorObj = util.errorObj;
- var isObject = util.isObject;
- function tryConvertToPromise(obj, context) {
- if (isObject(obj)) {
- if (obj instanceof Promise) {
- return obj;
- }
- else if (isAnyBluebirdPromise(obj)) {
- var ret = new Promise(INTERNAL);
- obj._then(
- ret._fulfillUnchecked,
- ret._rejectUncheckedCheckError,
- ret._progressUnchecked,
- ret,
- null
- );
- return ret;
- }
- var then = util.tryCatch(getThen)(obj);
- if (then === errorObj) {
- if (context) context._pushContext();
- var ret = Promise.reject(then.e);
- if (context) context._popContext();
- return ret;
- } else if (typeof then === "function") {
- return doThenable(obj, then, context);
- }
- }
- return obj;
- }
- function getThen(obj) {
- return obj.then;
- }
- var hasProp = {}.hasOwnProperty;
- function isAnyBluebirdPromise(obj) {
- return hasProp.call(obj, "_promise0");
- }
- function doThenable(x, then, context) {
- var promise = new Promise(INTERNAL);
- var ret = promise;
- if (context) context._pushContext();
- promise._captureStackTrace();
- if (context) context._popContext();
- var synchronous = true;
- var result = util.tryCatch(then).call(x,
- resolveFromThenable,
- rejectFromThenable,
- progressFromThenable);
- synchronous = false;
- if (promise && result === errorObj) {
- promise._rejectCallback(result.e, true, true);
- promise = null;
- }
- function resolveFromThenable(value) {
- if (!promise) return;
- if (x === value) {
- promise._rejectCallback(
- Promise._makeSelfResolutionError(), false, true);
- } else {
- promise._resolveCallback(value);
- }
- promise = null;
- }
- function rejectFromThenable(reason) {
- if (!promise) return;
- promise._rejectCallback(reason, synchronous, true);
- promise = null;
- }
- function progressFromThenable(value) {
- if (!promise) return;
- if (typeof promise._progress === "function") {
- promise._progress(value);
- }
- }
- return ret;
- }
- return tryConvertToPromise;
- };
- },{"./util.js":38}],36:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function(Promise, INTERNAL) {
- var util = _dereq_("./util.js");
- var TimeoutError = Promise.TimeoutError;
- var afterTimeout = function (promise, message) {
- if (!promise.isPending()) return;
- if (typeof message !== "string") {
- message = "operation timed out";
- }
- var err = new TimeoutError(message);
- util.markAsOriginatingFromRejection(err);
- promise._attachExtraTrace(err);
- promise._cancel(err);
- };
- var afterValue = function(value) { return delay(+this).thenReturn(value); };
- var delay = Promise.delay = function (value, ms) {
- if (ms === undefined) {
- ms = value;
- value = undefined;
- var ret = new Promise(INTERNAL);
- setTimeout(function() { ret._fulfill(); }, ms);
- return ret;
- }
- ms = +ms;
- return Promise.resolve(value)._then(afterValue, null, null, ms, undefined);
- };
- Promise.prototype.delay = function (ms) {
- return delay(this, ms);
- };
- function successClear(value) {
- var handle = this;
- if (handle instanceof Number) handle = +handle;
- clearTimeout(handle);
- return value;
- }
- function failureClear(reason) {
- var handle = this;
- if (handle instanceof Number) handle = +handle;
- clearTimeout(handle);
- throw reason;
- }
- Promise.prototype.timeout = function (ms, message) {
- ms = +ms;
- var ret = this.then().cancellable();
- ret._cancellationParent = this;
- var handle = setTimeout(function timeoutTimeout() {
- afterTimeout(ret, message);
- }, ms);
- return ret._then(successClear, failureClear, undefined, handle, undefined);
- };
- };
- },{"./util.js":38}],37:[function(_dereq_,module,exports){
- "use strict";
- module.exports = function (Promise, apiRejection, tryConvertToPromise,
- createContext) {
- var TypeError = _dereq_("./errors.js").TypeError;
- var inherits = _dereq_("./util.js").inherits;
- var PromiseInspection = Promise.PromiseInspection;
- function inspectionMapper(inspections) {
- var len = inspections.length;
- for (var i = 0; i < len; ++i) {
- var inspection = inspections[i];
- if (inspection.isRejected()) {
- return Promise.reject(inspection.error());
- }
- inspections[i] = inspection._settledValue;
- }
- return inspections;
- }
- function thrower(e) {
- setTimeout(function(){throw e;}, 0);
- }
- function castPreservingDisposable(thenable) {
- var maybePromise = tryConvertToPromise(thenable);
- if (maybePromise !== thenable &&
- typeof thenable._isDisposable === "function" &&
- typeof thenable._getDisposer === "function" &&
- thenable._isDisposable()) {
- maybePromise._setDisposable(thenable._getDisposer());
- }
- return maybePromise;
- }
- function dispose(resources, inspection) {
- var i = 0;
- var len = resources.length;
- var ret = Promise.defer();
- function iterator() {
- if (i >= len) return ret.resolve();
- var maybePromise = castPreservingDisposable(resources[i++]);
- if (maybePromise instanceof Promise &&
- maybePromise._isDisposable()) {
- try {
- maybePromise = tryConvertToPromise(
- maybePromise._getDisposer().tryDispose(inspection),
- resources.promise);
- } catch (e) {
- return thrower(e);
- }
- if (maybePromise instanceof Promise) {
- return maybePromise._then(iterator, thrower,
- null, null, null);
- }
- }
- iterator();
- }
- iterator();
- return ret.promise;
- }
- function disposerSuccess(value) {
- var inspection = new PromiseInspection();
- inspection._settledValue = value;
- inspection._bitField = 268435456;
- return dispose(this, inspection).thenReturn(value);
- }
- function disposerFail(reason) {
- var inspection = new PromiseInspection();
- inspection._settledValue = reason;
- inspection._bitField = 134217728;
- return dispose(this, inspection).thenThrow(reason);
- }
- function Disposer(data, promise, context) {
- this._data = data;
- this._promise = promise;
- this._context = context;
- }
- Disposer.prototype.data = function () {
- return this._data;
- };
- Disposer.prototype.promise = function () {
- return this._promise;
- };
- Disposer.prototype.resource = function () {
- if (this.promise().isFulfilled()) {
- return this.promise().value();
- }
- return null;
- };
- Disposer.prototype.tryDispose = function(inspection) {
- var resource = this.resource();
- var context = this._context;
- if (context !== undefined) context._pushContext();
- var ret = resource !== null
- ? this.doDispose(resource, inspection) : null;
- if (context !== undefined) context._popContext();
- this._promise._unsetDisposable();
- this._data = null;
- return ret;
- };
- Disposer.isDisposer = function (d) {
- return (d != null &&
- typeof d.resource === "function" &&
- typeof d.tryDispose === "function");
- };
- function FunctionDisposer(fn, promise, context) {
- this.constructor$(fn, promise, context);
- }
- inherits(FunctionDisposer, Disposer);
- FunctionDisposer.prototype.doDispose = function (resource, inspection) {
- var fn = this.data();
- return fn.call(resource, resource, inspection);
- };
- function maybeUnwrapDisposer(value) {
- if (Disposer.isDisposer(value)) {
- this.resources[this.index]._setDisposable(value);
- return value.promise();
- }
- return value;
- }
- Promise.using = function () {
- var len = arguments.length;
- if (len < 2) return apiRejection(
- "you must pass at least 2 arguments to Promise.using");
- var fn = arguments[len - 1];
- if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- len--;
- var resources = new Array(len);
- for (var i = 0; i < len; ++i) {
- var resource = arguments[i];
- if (Disposer.isDisposer(resource)) {
- var disposer = resource;
- resource = resource.promise();
- resource._setDisposable(disposer);
- } else {
- var maybePromise = tryConvertToPromise(resource);
- if (maybePromise instanceof Promise) {
- resource =
- maybePromise._then(maybeUnwrapDisposer, null, null, {
- resources: resources,
- index: i
- }, undefined);
- }
- }
- resources[i] = resource;
- }
- var promise = Promise.settle(resources)
- .then(inspectionMapper)
- .then(function(vals) {
- promise._pushContext();
- var ret;
- try {
- ret = fn.apply(undefined, vals);
- } finally {
- promise._popContext();
- }
- return ret;
- })
- ._then(
- disposerSuccess, disposerFail, undefined, resources, undefined);
- resources.promise = promise;
- return promise;
- };
- Promise.prototype._setDisposable = function (disposer) {
- this._bitField = this._bitField | 262144;
- this._disposer = disposer;
- };
- Promise.prototype._isDisposable = function () {
- return (this._bitField & 262144) > 0;
- };
- Promise.prototype._getDisposer = function () {
- return this._disposer;
- };
- Promise.prototype._unsetDisposable = function () {
- this._bitField = this._bitField & (~262144);
- this._disposer = undefined;
- };
- Promise.prototype.disposer = function (fn) {
- if (typeof fn === "function") {
- return new FunctionDisposer(fn, this, createContext());
- }
- throw new TypeError();
- };
- };
- },{"./errors.js":13,"./util.js":38}],38:[function(_dereq_,module,exports){
- "use strict";
- var es5 = _dereq_("./es5.js");
- var canEvaluate = typeof navigator == "undefined";
- var haveGetters = (function(){
- try {
- var o = {};
- es5.defineProperty(o, "f", {
- get: function () {
- return 3;
- }
- });
- return o.f === 3;
- }
- catch (e) {
- return false;
- }
- })();
- var errorObj = {e: {}};
- var tryCatchTarget;
- function tryCatcher() {
- try {
- return tryCatchTarget.apply(this, arguments);
- } catch (e) {
- errorObj.e = e;
- return errorObj;
- }
- }
- function tryCatch(fn) {
- tryCatchTarget = fn;
- return tryCatcher;
- }
- 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 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(safeToString(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 getDataPropertyOrDefault(obj, key, defaultValue) {
- if (es5.isES5) {
- var desc = Object.getOwnPropertyDescriptor(obj, key);
- if (desc != null) {
- return desc.get == null && desc.set == null
- ? desc.value
- : defaultValue;
- }
- } else {
- return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
- }
- }
- function notEnumerableProp(obj, name, value) {
- if (isPrimitive(obj)) return obj;
- 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 inheritedDataKeys = (function() {
- if (es5.isES5) {
- var oProto = Object.prototype;
- var getKeys = Object.getOwnPropertyNames;
- return function(obj) {
- var ret = [];
- var visitedKeys = Object.create(null);
- while (obj != null && obj !== oProto) {
- var keys;
- try {
- keys = getKeys(obj);
- } catch (e) {
- return ret;
- }
- for (var i = 0; i < keys.length; ++i) {
- var key = keys[i];
- if (visitedKeys[key]) continue;
- visitedKeys[key] = true;
- var desc = Object.getOwnPropertyDescriptor(obj, key);
- if (desc != null && desc.get == null && desc.set == null) {
- ret.push(key);
- }
- }
- obj = es5.getPrototypeOf(obj);
- }
- return ret;
- };
- } else {
- return function(obj) {
- var ret = [];
- /*jshint forin:false */
- for (var key in obj) {
- ret.push(key);
- }
- return ret;
- };
- }
- })();
- function isClass(fn) {
- try {
- if (typeof fn === "function") {
- var keys = es5.names(fn.prototype);
- if (es5.isES5) return keys.length > 1;
- return keys.length > 0 &&
- !(keys.length === 1 && keys[0] === "constructor");
- }
- return false;
- } catch (e) {
- return false;
- }
- }
- function toFastProperties(obj) {
- /*jshint -W027,-W055,-W031*/
- function f() {}
- f.prototype = obj;
- var l = 8;
- while (l--) new f();
- return obj;
- eval(obj);
- }
- var rident = /^[a-z$_][a-z$_0-9]*$/i;
- function isIdentifier(str) {
- return rident.test(str);
- }
- function filledRange(count, prefix, suffix) {
- var ret = new Array(count);
- for(var i = 0; i < count; ++i) {
- ret[i] = prefix + i + suffix;
- }
- return ret;
- }
- function safeToString(obj) {
- try {
- return obj + "";
- } catch (e) {
- return "[no string representation]";
- }
- }
- function markAsOriginatingFromRejection(e) {
- try {
- notEnumerableProp(e, "isOperational", true);
- }
- catch(ignore) {}
- }
- function originatesFromRejection(e) {
- if (e == null) return false;
- return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) ||
- e["isOperational"] === true);
- }
- function canAttachTrace(obj) {
- return obj instanceof Error && es5.propertyIsWritable(obj, "stack");
- }
- var ensureErrorObject = (function() {
- if (!("stack" in new Error())) {
- return function(value) {
- if (canAttachTrace(value)) return value;
- try {throw new Error(safeToString(value));}
- catch(err) {return err;}
- };
- } else {
- return function(value) {
- if (canAttachTrace(value)) return value;
- return new Error(safeToString(value));
- };
- }
- })();
- function classString(obj) {
- return {}.toString.call(obj);
- }
- function copyDescriptors(from, to, filter) {
- var keys = es5.names(from);
- for (var i = 0; i < keys.length; ++i) {
- var key = keys[i];
- if (filter(key)) {
- es5.defineProperty(to, key, es5.getDescriptor(from, key));
- }
- }
- }
- var ret = {
- isClass: isClass,
- isIdentifier: isIdentifier,
- inheritedDataKeys: inheritedDataKeys,
- getDataPropertyOrDefault: getDataPropertyOrDefault,
- thrower: thrower,
- isArray: es5.isArray,
- haveGetters: haveGetters,
- notEnumerableProp: notEnumerableProp,
- isPrimitive: isPrimitive,
- isObject: isObject,
- canEvaluate: canEvaluate,
- errorObj: errorObj,
- tryCatch: tryCatch,
- inherits: inherits,
- withAppended: withAppended,
- maybeWrapAsError: maybeWrapAsError,
- wrapsPrimitiveReceiver: wrapsPrimitiveReceiver,
- toFastProperties: toFastProperties,
- filledRange: filledRange,
- toString: safeToString,
- canAttachTrace: canAttachTrace,
- ensureErrorObject: ensureErrorObject,
- originatesFromRejection: originatesFromRejection,
- markAsOriginatingFromRejection: markAsOriginatingFromRejection,
- classString: classString,
- copyDescriptors: copyDescriptors,
- hasDevTools: typeof chrome !== "undefined" && chrome &&
- typeof chrome.loadTimes === "function",
- isNode: typeof process !== "undefined" &&
- classString(process).toLowerCase() === "[object process]"
- };
- try {throw new Error(); } catch (e) {ret.lastLineError = e;}
- module.exports = ret;
- },{"./es5.js":14}],39:[function(_dereq_,module,exports){
- // Copyright Joyent, Inc. and other Node contributors.
- //
- // 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:
- //
- // 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 EventEmitter() {
- this._events = this._events || {};
- this._maxListeners = this._maxListeners || undefined;
- }
- module.exports = EventEmitter;
- // Backwards-compat with node 0.10.x
- EventEmitter.EventEmitter = EventEmitter;
- EventEmitter.prototype._events = undefined;
- EventEmitter.prototype._maxListeners = undefined;
- // By default EventEmitters will print a warning if more than 10 listeners are
- // added to it. This is a useful default which helps finding memory leaks.
- EventEmitter.defaultMaxListeners = 10;
- // Obviously not all Emitters should be limited to 10. This function allows
- // that to be increased. Set to zero for unlimited.
- EventEmitter.prototype.setMaxListeners = function(n) {
- if (!isNumber(n) || n < 0 || isNaN(n))
- throw TypeError('n must be a positive number');
- this._maxListeners = n;
- return this;
- };
- EventEmitter.prototype.emit = function(type) {
- var er, handler, len, args, i, listeners;
- if (!this._events)
- this._events = {};
- // If there is no 'error' event listener then throw.
- if (type === 'error') {
- if (!this._events.error ||
- (isObject(this._events.error) && !this._events.error.length)) {
- er = arguments[1];
- if (er instanceof Error) {
- throw er; // Unhandled 'error' event
- }
- throw TypeError('Uncaught, unspecified "error" event.');
- }
- }
- handler = this._events[type];
- if (isUndefined(handler))
- return false;
- if (isFunction(handler)) {
- switch (arguments.length) {
- // fast cases
- case 1:
- handler.call(this);
- break;
- case 2:
- handler.call(this, arguments[1]);
- break;
- case 3:
- handler.call(this, arguments[1], arguments[2]);
- break;
- // slower
- default:
- len = arguments.length;
- args = new Array(len - 1);
- for (i = 1; i < len; i++)
- args[i - 1] = arguments[i];
- handler.apply(this, args);
- }
- } else if (isObject(handler)) {
- len = arguments.length;
- args = new Array(len - 1);
- for (i = 1; i < len; i++)
- args[i - 1] = arguments[i];
- listeners = handler.slice();
- len = listeners.length;
- for (i = 0; i < len; i++)
- listeners[i].apply(this, args);
- }
- return true;
- };
- EventEmitter.prototype.addListener = function(type, listener) {
- var m;
- if (!isFunction(listener))
- throw TypeError('listener must be a function');
- if (!this._events)
- this._events = {};
- // To avoid recursion in the case that type === "newListener"! Before
- // adding it to the listeners, first emit "newListener".
- if (this._events.newListener)
- this.emit('newListener', type,
- isFunction(listener.listener) ?
- listener.listener : listener);
- if (!this._events[type])
- // Optimize the case of one listener. Don't need the extra array object.
- this._events[type] = listener;
- else if (isObject(this._events[type]))
- // If we've already got an array, just append.
- this._events[type].push(listener);
- else
- // Adding the second element, need to change to array.
- this._events[type] = [this._events[type], listener];
- // Check for listener leak
- if (isObject(this._events[type]) && !this._events[type].warned) {
- var m;
- if (!isUndefined(this._maxListeners)) {
- m = this._maxListeners;
- } else {
- m = EventEmitter.defaultMaxListeners;
- }
- if (m && m > 0 && this._events[type].length > m) {
- this._events[type].warned = true;
- console.error('(node) warning: possible EventEmitter memory ' +
- 'leak detected. %d listeners added. ' +
- 'Use emitter.setMaxListeners() to increase limit.',
- this._events[type].length);
- if (typeof console.trace === 'function') {
- // not supported in IE 10
- console.trace();
- }
- }
- }
- return this;
- };
- EventEmitter.prototype.on = EventEmitter.prototype.addListener;
- EventEmitter.prototype.once = function(type, listener) {
- if (!isFunction(listener))
- throw TypeError('listener must be a function');
- var fired = false;
- function g() {
- this.removeListener(type, g);
- if (!fired) {
- fired = true;
- listener.apply(this, arguments);
- }
- }
- g.listener = listener;
- this.on(type, g);
- return this;
- };
- // emits a 'removeListener' event iff the listener was removed
- EventEmitter.prototype.removeListener = function(type, listener) {
- var list, position, length, i;
- if (!isFunction(listener))
- throw TypeError('listener must be a function');
- if (!this._events || !this._events[type])
- return this;
- list = this._events[type];
- length = list.length;
- position = -1;
- if (list === listener ||
- (isFunction(list.listener) && list.listener === listener)) {
- delete this._events[type];
- if (this._events.removeListener)
- this.emit('removeListener', type, listener);
- } else if (isObject(list)) {
- for (i = length; i-- > 0;) {
- if (list[i] === listener ||
- (list[i].listener && list[i].listener === listener)) {
- position = i;
- break;
- }
- }
- if (position < 0)
- return this;
- if (list.length === 1) {
- list.length = 0;
- delete this._events[type];
- } else {
- list.splice(position, 1);
- }
- if (this._events.removeListener)
- this.emit('removeListener', type, listener);
- }
- return this;
- };
- EventEmitter.prototype.removeAllListeners = function(type) {
- var key, listeners;
- if (!this._events)
- return this;
- // not listening for removeListener, no need to emit
- if (!this._events.removeListener) {
- if (arguments.length === 0)
- this._events = {};
- else if (this._events[type])
- delete this._events[type];
- return this;
- }
- // emit removeListener for all listeners on all events
- if (arguments.length === 0) {
- for (key in this._events) {
- if (key === 'removeListener') continue;
- this.removeAllListeners(key);
- }
- this.removeAllListeners('removeListener');
- this._events = {};
- return this;
- }
- listeners = this._events[type];
- if (isFunction(listeners)) {
- this.removeListener(type, listeners);
- } else {
- // LIFO order
- while (listeners.length)
- this.removeListener(type, listeners[listeners.length - 1]);
- }
- delete this._events[type];
- return this;
- };
- EventEmitter.prototype.listeners = function(type) {
- var ret;
- if (!this._events || !this._events[type])
- ret = [];
- else if (isFunction(this._events[type]))
- ret = [this._events[type]];
- else
- ret = this._events[type].slice();
- return ret;
- };
- EventEmitter.listenerCount = function(emitter, type) {
- var ret;
- if (!emitter._events || !emitter._events[type])
- ret = 0;
- else if (isFunction(emitter._events[type]))
- ret = 1;
- else
- ret = emitter._events[type].length;
- return ret;
- };
- function isFunction(arg) {
- return typeof arg === 'function';
- }
- function isNumber(arg) {
- return typeof arg === 'number';
- }
- function isObject(arg) {
- return typeof arg === 'object' && arg !== null;
- }
- function isUndefined(arg) {
- return arg === void 0;
- }
- },{}]},{},[4])(4)
- }); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }
|