bluebird.core.js 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914
  1. /* @preserve
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2013-2018 Petka Antonov
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. *
  24. */
  25. /**
  26. * bluebird build version 3.7.2
  27. * Features enabled: core
  28. * Features disabled: race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, using, timers, filter, any, each
  29. */
  30. !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){
  31. "use strict";
  32. var firstLineError;
  33. try {throw new Error(); } catch (e) {firstLineError = e;}
  34. var schedule = _dereq_("./schedule");
  35. var Queue = _dereq_("./queue");
  36. function Async() {
  37. this._customScheduler = false;
  38. this._isTickUsed = false;
  39. this._lateQueue = new Queue(16);
  40. this._normalQueue = new Queue(16);
  41. this._haveDrainedQueues = false;
  42. var self = this;
  43. this.drainQueues = function () {
  44. self._drainQueues();
  45. };
  46. this._schedule = schedule;
  47. }
  48. Async.prototype.setScheduler = function(fn) {
  49. var prev = this._schedule;
  50. this._schedule = fn;
  51. this._customScheduler = true;
  52. return prev;
  53. };
  54. Async.prototype.hasCustomScheduler = function() {
  55. return this._customScheduler;
  56. };
  57. Async.prototype.haveItemsQueued = function () {
  58. return this._isTickUsed || this._haveDrainedQueues;
  59. };
  60. Async.prototype.fatalError = function(e, isNode) {
  61. if (isNode) {
  62. process.stderr.write("Fatal " + (e instanceof Error ? e.stack : e) +
  63. "\n");
  64. process.exit(2);
  65. } else {
  66. this.throwLater(e);
  67. }
  68. };
  69. Async.prototype.throwLater = function(fn, arg) {
  70. if (arguments.length === 1) {
  71. arg = fn;
  72. fn = function () { throw arg; };
  73. }
  74. if (typeof setTimeout !== "undefined") {
  75. setTimeout(function() {
  76. fn(arg);
  77. }, 0);
  78. } else try {
  79. this._schedule(function() {
  80. fn(arg);
  81. });
  82. } catch (e) {
  83. throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  84. }
  85. };
  86. function AsyncInvokeLater(fn, receiver, arg) {
  87. this._lateQueue.push(fn, receiver, arg);
  88. this._queueTick();
  89. }
  90. function AsyncInvoke(fn, receiver, arg) {
  91. this._normalQueue.push(fn, receiver, arg);
  92. this._queueTick();
  93. }
  94. function AsyncSettlePromises(promise) {
  95. this._normalQueue._pushOne(promise);
  96. this._queueTick();
  97. }
  98. Async.prototype.invokeLater = AsyncInvokeLater;
  99. Async.prototype.invoke = AsyncInvoke;
  100. Async.prototype.settlePromises = AsyncSettlePromises;
  101. function _drainQueue(queue) {
  102. while (queue.length() > 0) {
  103. _drainQueueStep(queue);
  104. }
  105. }
  106. function _drainQueueStep(queue) {
  107. var fn = queue.shift();
  108. if (typeof fn !== "function") {
  109. fn._settlePromises();
  110. } else {
  111. var receiver = queue.shift();
  112. var arg = queue.shift();
  113. fn.call(receiver, arg);
  114. }
  115. }
  116. Async.prototype._drainQueues = function () {
  117. _drainQueue(this._normalQueue);
  118. this._reset();
  119. this._haveDrainedQueues = true;
  120. _drainQueue(this._lateQueue);
  121. };
  122. Async.prototype._queueTick = function () {
  123. if (!this._isTickUsed) {
  124. this._isTickUsed = true;
  125. this._schedule(this.drainQueues);
  126. }
  127. };
  128. Async.prototype._reset = function () {
  129. this._isTickUsed = false;
  130. };
  131. module.exports = Async;
  132. module.exports.firstLineError = firstLineError;
  133. },{"./queue":17,"./schedule":18}],2:[function(_dereq_,module,exports){
  134. "use strict";
  135. module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) {
  136. var calledBind = false;
  137. var rejectThis = function(_, e) {
  138. this._reject(e);
  139. };
  140. var targetRejected = function(e, context) {
  141. context.promiseRejectionQueued = true;
  142. context.bindingPromise._then(rejectThis, rejectThis, null, this, e);
  143. };
  144. var bindingResolved = function(thisArg, context) {
  145. if (((this._bitField & 50397184) === 0)) {
  146. this._resolveCallback(context.target);
  147. }
  148. };
  149. var bindingRejected = function(e, context) {
  150. if (!context.promiseRejectionQueued) this._reject(e);
  151. };
  152. Promise.prototype.bind = function (thisArg) {
  153. if (!calledBind) {
  154. calledBind = true;
  155. Promise.prototype._propagateFrom = debug.propagateFromFunction();
  156. Promise.prototype._boundValue = debug.boundValueFunction();
  157. }
  158. var maybePromise = tryConvertToPromise(thisArg);
  159. var ret = new Promise(INTERNAL);
  160. ret._propagateFrom(this, 1);
  161. var target = this._target();
  162. ret._setBoundTo(maybePromise);
  163. if (maybePromise instanceof Promise) {
  164. var context = {
  165. promiseRejectionQueued: false,
  166. promise: ret,
  167. target: target,
  168. bindingPromise: maybePromise
  169. };
  170. target._then(INTERNAL, targetRejected, undefined, ret, context);
  171. maybePromise._then(
  172. bindingResolved, bindingRejected, undefined, ret, context);
  173. ret._setOnCancel(maybePromise);
  174. } else {
  175. ret._resolveCallback(target);
  176. }
  177. return ret;
  178. };
  179. Promise.prototype._setBoundTo = function (obj) {
  180. if (obj !== undefined) {
  181. this._bitField = this._bitField | 2097152;
  182. this._boundTo = obj;
  183. } else {
  184. this._bitField = this._bitField & (~2097152);
  185. }
  186. };
  187. Promise.prototype._isBound = function () {
  188. return (this._bitField & 2097152) === 2097152;
  189. };
  190. Promise.bind = function (thisArg, value) {
  191. return Promise.resolve(value).bind(thisArg);
  192. };
  193. };
  194. },{}],3:[function(_dereq_,module,exports){
  195. "use strict";
  196. var old;
  197. if (typeof Promise !== "undefined") old = Promise;
  198. function noConflict() {
  199. try { if (Promise === bluebird) Promise = old; }
  200. catch (e) {}
  201. return bluebird;
  202. }
  203. var bluebird = _dereq_("./promise")();
  204. bluebird.noConflict = noConflict;
  205. module.exports = bluebird;
  206. },{"./promise":15}],4:[function(_dereq_,module,exports){
  207. "use strict";
  208. module.exports = function(Promise, PromiseArray, apiRejection, debug) {
  209. var util = _dereq_("./util");
  210. var tryCatch = util.tryCatch;
  211. var errorObj = util.errorObj;
  212. var async = Promise._async;
  213. Promise.prototype["break"] = Promise.prototype.cancel = function() {
  214. if (!debug.cancellation()) return this._warn("cancellation is disabled");
  215. var promise = this;
  216. var child = promise;
  217. while (promise._isCancellable()) {
  218. if (!promise._cancelBy(child)) {
  219. if (child._isFollowing()) {
  220. child._followee().cancel();
  221. } else {
  222. child._cancelBranched();
  223. }
  224. break;
  225. }
  226. var parent = promise._cancellationParent;
  227. if (parent == null || !parent._isCancellable()) {
  228. if (promise._isFollowing()) {
  229. promise._followee().cancel();
  230. } else {
  231. promise._cancelBranched();
  232. }
  233. break;
  234. } else {
  235. if (promise._isFollowing()) promise._followee().cancel();
  236. promise._setWillBeCancelled();
  237. child = promise;
  238. promise = parent;
  239. }
  240. }
  241. };
  242. Promise.prototype._branchHasCancelled = function() {
  243. this._branchesRemainingToCancel--;
  244. };
  245. Promise.prototype._enoughBranchesHaveCancelled = function() {
  246. return this._branchesRemainingToCancel === undefined ||
  247. this._branchesRemainingToCancel <= 0;
  248. };
  249. Promise.prototype._cancelBy = function(canceller) {
  250. if (canceller === this) {
  251. this._branchesRemainingToCancel = 0;
  252. this._invokeOnCancel();
  253. return true;
  254. } else {
  255. this._branchHasCancelled();
  256. if (this._enoughBranchesHaveCancelled()) {
  257. this._invokeOnCancel();
  258. return true;
  259. }
  260. }
  261. return false;
  262. };
  263. Promise.prototype._cancelBranched = function() {
  264. if (this._enoughBranchesHaveCancelled()) {
  265. this._cancel();
  266. }
  267. };
  268. Promise.prototype._cancel = function() {
  269. if (!this._isCancellable()) return;
  270. this._setCancelled();
  271. async.invoke(this._cancelPromises, this, undefined);
  272. };
  273. Promise.prototype._cancelPromises = function() {
  274. if (this._length() > 0) this._settlePromises();
  275. };
  276. Promise.prototype._unsetOnCancel = function() {
  277. this._onCancelField = undefined;
  278. };
  279. Promise.prototype._isCancellable = function() {
  280. return this.isPending() && !this._isCancelled();
  281. };
  282. Promise.prototype.isCancellable = function() {
  283. return this.isPending() && !this.isCancelled();
  284. };
  285. Promise.prototype._doInvokeOnCancel = function(onCancelCallback, internalOnly) {
  286. if (util.isArray(onCancelCallback)) {
  287. for (var i = 0; i < onCancelCallback.length; ++i) {
  288. this._doInvokeOnCancel(onCancelCallback[i], internalOnly);
  289. }
  290. } else if (onCancelCallback !== undefined) {
  291. if (typeof onCancelCallback === "function") {
  292. if (!internalOnly) {
  293. var e = tryCatch(onCancelCallback).call(this._boundValue());
  294. if (e === errorObj) {
  295. this._attachExtraTrace(e.e);
  296. async.throwLater(e.e);
  297. }
  298. }
  299. } else {
  300. onCancelCallback._resultCancelled(this);
  301. }
  302. }
  303. };
  304. Promise.prototype._invokeOnCancel = function() {
  305. var onCancelCallback = this._onCancel();
  306. this._unsetOnCancel();
  307. async.invoke(this._doInvokeOnCancel, this, onCancelCallback);
  308. };
  309. Promise.prototype._invokeInternalOnCancel = function() {
  310. if (this._isCancellable()) {
  311. this._doInvokeOnCancel(this._onCancel(), true);
  312. this._unsetOnCancel();
  313. }
  314. };
  315. Promise.prototype._resultCancelled = function() {
  316. this.cancel();
  317. };
  318. };
  319. },{"./util":21}],5:[function(_dereq_,module,exports){
  320. "use strict";
  321. module.exports = function(NEXT_FILTER) {
  322. var util = _dereq_("./util");
  323. var getKeys = _dereq_("./es5").keys;
  324. var tryCatch = util.tryCatch;
  325. var errorObj = util.errorObj;
  326. function catchFilter(instances, cb, promise) {
  327. return function(e) {
  328. var boundTo = promise._boundValue();
  329. predicateLoop: for (var i = 0; i < instances.length; ++i) {
  330. var item = instances[i];
  331. if (item === Error ||
  332. (item != null && item.prototype instanceof Error)) {
  333. if (e instanceof item) {
  334. return tryCatch(cb).call(boundTo, e);
  335. }
  336. } else if (typeof item === "function") {
  337. var matchesPredicate = tryCatch(item).call(boundTo, e);
  338. if (matchesPredicate === errorObj) {
  339. return matchesPredicate;
  340. } else if (matchesPredicate) {
  341. return tryCatch(cb).call(boundTo, e);
  342. }
  343. } else if (util.isObject(e)) {
  344. var keys = getKeys(item);
  345. for (var j = 0; j < keys.length; ++j) {
  346. var key = keys[j];
  347. if (item[key] != e[key]) {
  348. continue predicateLoop;
  349. }
  350. }
  351. return tryCatch(cb).call(boundTo, e);
  352. }
  353. }
  354. return NEXT_FILTER;
  355. };
  356. }
  357. return catchFilter;
  358. };
  359. },{"./es5":10,"./util":21}],6:[function(_dereq_,module,exports){
  360. "use strict";
  361. module.exports = function(Promise) {
  362. var longStackTraces = false;
  363. var contextStack = [];
  364. Promise.prototype._promiseCreated = function() {};
  365. Promise.prototype._pushContext = function() {};
  366. Promise.prototype._popContext = function() {return null;};
  367. Promise._peekContext = Promise.prototype._peekContext = function() {};
  368. function Context() {
  369. this._trace = new Context.CapturedTrace(peekContext());
  370. }
  371. Context.prototype._pushContext = function () {
  372. if (this._trace !== undefined) {
  373. this._trace._promiseCreated = null;
  374. contextStack.push(this._trace);
  375. }
  376. };
  377. Context.prototype._popContext = function () {
  378. if (this._trace !== undefined) {
  379. var trace = contextStack.pop();
  380. var ret = trace._promiseCreated;
  381. trace._promiseCreated = null;
  382. return ret;
  383. }
  384. return null;
  385. };
  386. function createContext() {
  387. if (longStackTraces) return new Context();
  388. }
  389. function peekContext() {
  390. var lastIndex = contextStack.length - 1;
  391. if (lastIndex >= 0) {
  392. return contextStack[lastIndex];
  393. }
  394. return undefined;
  395. }
  396. Context.CapturedTrace = null;
  397. Context.create = createContext;
  398. Context.deactivateLongStackTraces = function() {};
  399. Context.activateLongStackTraces = function() {
  400. var Promise_pushContext = Promise.prototype._pushContext;
  401. var Promise_popContext = Promise.prototype._popContext;
  402. var Promise_PeekContext = Promise._peekContext;
  403. var Promise_peekContext = Promise.prototype._peekContext;
  404. var Promise_promiseCreated = Promise.prototype._promiseCreated;
  405. Context.deactivateLongStackTraces = function() {
  406. Promise.prototype._pushContext = Promise_pushContext;
  407. Promise.prototype._popContext = Promise_popContext;
  408. Promise._peekContext = Promise_PeekContext;
  409. Promise.prototype._peekContext = Promise_peekContext;
  410. Promise.prototype._promiseCreated = Promise_promiseCreated;
  411. longStackTraces = false;
  412. };
  413. longStackTraces = true;
  414. Promise.prototype._pushContext = Context.prototype._pushContext;
  415. Promise.prototype._popContext = Context.prototype._popContext;
  416. Promise._peekContext = Promise.prototype._peekContext = peekContext;
  417. Promise.prototype._promiseCreated = function() {
  418. var ctx = this._peekContext();
  419. if (ctx && ctx._promiseCreated == null) ctx._promiseCreated = this;
  420. };
  421. };
  422. return Context;
  423. };
  424. },{}],7:[function(_dereq_,module,exports){
  425. "use strict";
  426. module.exports = function(Promise, Context,
  427. enableAsyncHooks, disableAsyncHooks) {
  428. var async = Promise._async;
  429. var Warning = _dereq_("./errors").Warning;
  430. var util = _dereq_("./util");
  431. var es5 = _dereq_("./es5");
  432. var canAttachTrace = util.canAttachTrace;
  433. var unhandledRejectionHandled;
  434. var possiblyUnhandledRejection;
  435. var bluebirdFramePattern =
  436. /[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/;
  437. var nodeFramePattern = /\((?:timers\.js):\d+:\d+\)/;
  438. var parseLinePattern = /[\/<\(](.+?):(\d+):(\d+)\)?\s*$/;
  439. var stackFramePattern = null;
  440. var formatStack = null;
  441. var indentStackFrames = false;
  442. var printWarning;
  443. var debugging = !!(util.env("BLUEBIRD_DEBUG") != 0 &&
  444. (true ||
  445. util.env("BLUEBIRD_DEBUG") ||
  446. util.env("NODE_ENV") === "development"));
  447. var warnings = !!(util.env("BLUEBIRD_WARNINGS") != 0 &&
  448. (debugging || util.env("BLUEBIRD_WARNINGS")));
  449. var longStackTraces = !!(util.env("BLUEBIRD_LONG_STACK_TRACES") != 0 &&
  450. (debugging || util.env("BLUEBIRD_LONG_STACK_TRACES")));
  451. var wForgottenReturn = util.env("BLUEBIRD_W_FORGOTTEN_RETURN") != 0 &&
  452. (warnings || !!util.env("BLUEBIRD_W_FORGOTTEN_RETURN"));
  453. var deferUnhandledRejectionCheck;
  454. (function() {
  455. var promises = [];
  456. function unhandledRejectionCheck() {
  457. for (var i = 0; i < promises.length; ++i) {
  458. promises[i]._notifyUnhandledRejection();
  459. }
  460. unhandledRejectionClear();
  461. }
  462. function unhandledRejectionClear() {
  463. promises.length = 0;
  464. }
  465. deferUnhandledRejectionCheck = function(promise) {
  466. promises.push(promise);
  467. setTimeout(unhandledRejectionCheck, 1);
  468. };
  469. es5.defineProperty(Promise, "_unhandledRejectionCheck", {
  470. value: unhandledRejectionCheck
  471. });
  472. es5.defineProperty(Promise, "_unhandledRejectionClear", {
  473. value: unhandledRejectionClear
  474. });
  475. })();
  476. Promise.prototype.suppressUnhandledRejections = function() {
  477. var target = this._target();
  478. target._bitField = ((target._bitField & (~1048576)) |
  479. 524288);
  480. };
  481. Promise.prototype._ensurePossibleRejectionHandled = function () {
  482. if ((this._bitField & 524288) !== 0) return;
  483. this._setRejectionIsUnhandled();
  484. deferUnhandledRejectionCheck(this);
  485. };
  486. Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
  487. fireRejectionEvent("rejectionHandled",
  488. unhandledRejectionHandled, undefined, this);
  489. };
  490. Promise.prototype._setReturnedNonUndefined = function() {
  491. this._bitField = this._bitField | 268435456;
  492. };
  493. Promise.prototype._returnedNonUndefined = function() {
  494. return (this._bitField & 268435456) !== 0;
  495. };
  496. Promise.prototype._notifyUnhandledRejection = function () {
  497. if (this._isRejectionUnhandled()) {
  498. var reason = this._settledValue();
  499. this._setUnhandledRejectionIsNotified();
  500. fireRejectionEvent("unhandledRejection",
  501. possiblyUnhandledRejection, reason, this);
  502. }
  503. };
  504. Promise.prototype._setUnhandledRejectionIsNotified = function () {
  505. this._bitField = this._bitField | 262144;
  506. };
  507. Promise.prototype._unsetUnhandledRejectionIsNotified = function () {
  508. this._bitField = this._bitField & (~262144);
  509. };
  510. Promise.prototype._isUnhandledRejectionNotified = function () {
  511. return (this._bitField & 262144) > 0;
  512. };
  513. Promise.prototype._setRejectionIsUnhandled = function () {
  514. this._bitField = this._bitField | 1048576;
  515. };
  516. Promise.prototype._unsetRejectionIsUnhandled = function () {
  517. this._bitField = this._bitField & (~1048576);
  518. if (this._isUnhandledRejectionNotified()) {
  519. this._unsetUnhandledRejectionIsNotified();
  520. this._notifyUnhandledRejectionIsHandled();
  521. }
  522. };
  523. Promise.prototype._isRejectionUnhandled = function () {
  524. return (this._bitField & 1048576) > 0;
  525. };
  526. Promise.prototype._warn = function(message, shouldUseOwnTrace, promise) {
  527. return warn(message, shouldUseOwnTrace, promise || this);
  528. };
  529. Promise.onPossiblyUnhandledRejection = function (fn) {
  530. var context = Promise._getContext();
  531. possiblyUnhandledRejection = util.contextBind(context, fn);
  532. };
  533. Promise.onUnhandledRejectionHandled = function (fn) {
  534. var context = Promise._getContext();
  535. unhandledRejectionHandled = util.contextBind(context, fn);
  536. };
  537. var disableLongStackTraces = function() {};
  538. Promise.longStackTraces = function () {
  539. if (async.haveItemsQueued() && !config.longStackTraces) {
  540. throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  541. }
  542. if (!config.longStackTraces && longStackTracesIsSupported()) {
  543. var Promise_captureStackTrace = Promise.prototype._captureStackTrace;
  544. var Promise_attachExtraTrace = Promise.prototype._attachExtraTrace;
  545. var Promise_dereferenceTrace = Promise.prototype._dereferenceTrace;
  546. config.longStackTraces = true;
  547. disableLongStackTraces = function() {
  548. if (async.haveItemsQueued() && !config.longStackTraces) {
  549. throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  550. }
  551. Promise.prototype._captureStackTrace = Promise_captureStackTrace;
  552. Promise.prototype._attachExtraTrace = Promise_attachExtraTrace;
  553. Promise.prototype._dereferenceTrace = Promise_dereferenceTrace;
  554. Context.deactivateLongStackTraces();
  555. config.longStackTraces = false;
  556. };
  557. Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace;
  558. Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace;
  559. Promise.prototype._dereferenceTrace = longStackTracesDereferenceTrace;
  560. Context.activateLongStackTraces();
  561. }
  562. };
  563. Promise.hasLongStackTraces = function () {
  564. return config.longStackTraces && longStackTracesIsSupported();
  565. };
  566. var legacyHandlers = {
  567. unhandledrejection: {
  568. before: function() {
  569. var ret = util.global.onunhandledrejection;
  570. util.global.onunhandledrejection = null;
  571. return ret;
  572. },
  573. after: function(fn) {
  574. util.global.onunhandledrejection = fn;
  575. }
  576. },
  577. rejectionhandled: {
  578. before: function() {
  579. var ret = util.global.onrejectionhandled;
  580. util.global.onrejectionhandled = null;
  581. return ret;
  582. },
  583. after: function(fn) {
  584. util.global.onrejectionhandled = fn;
  585. }
  586. }
  587. };
  588. var fireDomEvent = (function() {
  589. var dispatch = function(legacy, e) {
  590. if (legacy) {
  591. var fn;
  592. try {
  593. fn = legacy.before();
  594. return !util.global.dispatchEvent(e);
  595. } finally {
  596. legacy.after(fn);
  597. }
  598. } else {
  599. return !util.global.dispatchEvent(e);
  600. }
  601. };
  602. try {
  603. if (typeof CustomEvent === "function") {
  604. var event = new CustomEvent("CustomEvent");
  605. util.global.dispatchEvent(event);
  606. return function(name, event) {
  607. name = name.toLowerCase();
  608. var eventData = {
  609. detail: event,
  610. cancelable: true
  611. };
  612. var domEvent = new CustomEvent(name, eventData);
  613. es5.defineProperty(
  614. domEvent, "promise", {value: event.promise});
  615. es5.defineProperty(
  616. domEvent, "reason", {value: event.reason});
  617. return dispatch(legacyHandlers[name], domEvent);
  618. };
  619. } else if (typeof Event === "function") {
  620. var event = new Event("CustomEvent");
  621. util.global.dispatchEvent(event);
  622. return function(name, event) {
  623. name = name.toLowerCase();
  624. var domEvent = new Event(name, {
  625. cancelable: true
  626. });
  627. domEvent.detail = event;
  628. es5.defineProperty(domEvent, "promise", {value: event.promise});
  629. es5.defineProperty(domEvent, "reason", {value: event.reason});
  630. return dispatch(legacyHandlers[name], domEvent);
  631. };
  632. } else {
  633. var event = document.createEvent("CustomEvent");
  634. event.initCustomEvent("testingtheevent", false, true, {});
  635. util.global.dispatchEvent(event);
  636. return function(name, event) {
  637. name = name.toLowerCase();
  638. var domEvent = document.createEvent("CustomEvent");
  639. domEvent.initCustomEvent(name, false, true,
  640. event);
  641. return dispatch(legacyHandlers[name], domEvent);
  642. };
  643. }
  644. } catch (e) {}
  645. return function() {
  646. return false;
  647. };
  648. })();
  649. var fireGlobalEvent = (function() {
  650. if (util.isNode) {
  651. return function() {
  652. return process.emit.apply(process, arguments);
  653. };
  654. } else {
  655. if (!util.global) {
  656. return function() {
  657. return false;
  658. };
  659. }
  660. return function(name) {
  661. var methodName = "on" + name.toLowerCase();
  662. var method = util.global[methodName];
  663. if (!method) return false;
  664. method.apply(util.global, [].slice.call(arguments, 1));
  665. return true;
  666. };
  667. }
  668. })();
  669. function generatePromiseLifecycleEventObject(name, promise) {
  670. return {promise: promise};
  671. }
  672. var eventToObjectGenerator = {
  673. promiseCreated: generatePromiseLifecycleEventObject,
  674. promiseFulfilled: generatePromiseLifecycleEventObject,
  675. promiseRejected: generatePromiseLifecycleEventObject,
  676. promiseResolved: generatePromiseLifecycleEventObject,
  677. promiseCancelled: generatePromiseLifecycleEventObject,
  678. promiseChained: function(name, promise, child) {
  679. return {promise: promise, child: child};
  680. },
  681. warning: function(name, warning) {
  682. return {warning: warning};
  683. },
  684. unhandledRejection: function (name, reason, promise) {
  685. return {reason: reason, promise: promise};
  686. },
  687. rejectionHandled: generatePromiseLifecycleEventObject
  688. };
  689. var activeFireEvent = function (name) {
  690. var globalEventFired = false;
  691. try {
  692. globalEventFired = fireGlobalEvent.apply(null, arguments);
  693. } catch (e) {
  694. async.throwLater(e);
  695. globalEventFired = true;
  696. }
  697. var domEventFired = false;
  698. try {
  699. domEventFired = fireDomEvent(name,
  700. eventToObjectGenerator[name].apply(null, arguments));
  701. } catch (e) {
  702. async.throwLater(e);
  703. domEventFired = true;
  704. }
  705. return domEventFired || globalEventFired;
  706. };
  707. Promise.config = function(opts) {
  708. opts = Object(opts);
  709. if ("longStackTraces" in opts) {
  710. if (opts.longStackTraces) {
  711. Promise.longStackTraces();
  712. } else if (!opts.longStackTraces && Promise.hasLongStackTraces()) {
  713. disableLongStackTraces();
  714. }
  715. }
  716. if ("warnings" in opts) {
  717. var warningsOption = opts.warnings;
  718. config.warnings = !!warningsOption;
  719. wForgottenReturn = config.warnings;
  720. if (util.isObject(warningsOption)) {
  721. if ("wForgottenReturn" in warningsOption) {
  722. wForgottenReturn = !!warningsOption.wForgottenReturn;
  723. }
  724. }
  725. }
  726. if ("cancellation" in opts && opts.cancellation && !config.cancellation) {
  727. if (async.haveItemsQueued()) {
  728. throw new Error(
  729. "cannot enable cancellation after promises are in use");
  730. }
  731. Promise.prototype._clearCancellationData =
  732. cancellationClearCancellationData;
  733. Promise.prototype._propagateFrom = cancellationPropagateFrom;
  734. Promise.prototype._onCancel = cancellationOnCancel;
  735. Promise.prototype._setOnCancel = cancellationSetOnCancel;
  736. Promise.prototype._attachCancellationCallback =
  737. cancellationAttachCancellationCallback;
  738. Promise.prototype._execute = cancellationExecute;
  739. propagateFromFunction = cancellationPropagateFrom;
  740. config.cancellation = true;
  741. }
  742. if ("monitoring" in opts) {
  743. if (opts.monitoring && !config.monitoring) {
  744. config.monitoring = true;
  745. Promise.prototype._fireEvent = activeFireEvent;
  746. } else if (!opts.monitoring && config.monitoring) {
  747. config.monitoring = false;
  748. Promise.prototype._fireEvent = defaultFireEvent;
  749. }
  750. }
  751. if ("asyncHooks" in opts && util.nodeSupportsAsyncResource) {
  752. var prev = config.asyncHooks;
  753. var cur = !!opts.asyncHooks;
  754. if (prev !== cur) {
  755. config.asyncHooks = cur;
  756. if (cur) {
  757. enableAsyncHooks();
  758. } else {
  759. disableAsyncHooks();
  760. }
  761. }
  762. }
  763. return Promise;
  764. };
  765. function defaultFireEvent() { return false; }
  766. Promise.prototype._fireEvent = defaultFireEvent;
  767. Promise.prototype._execute = function(executor, resolve, reject) {
  768. try {
  769. executor(resolve, reject);
  770. } catch (e) {
  771. return e;
  772. }
  773. };
  774. Promise.prototype._onCancel = function () {};
  775. Promise.prototype._setOnCancel = function (handler) { ; };
  776. Promise.prototype._attachCancellationCallback = function(onCancel) {
  777. ;
  778. };
  779. Promise.prototype._captureStackTrace = function () {};
  780. Promise.prototype._attachExtraTrace = function () {};
  781. Promise.prototype._dereferenceTrace = function () {};
  782. Promise.prototype._clearCancellationData = function() {};
  783. Promise.prototype._propagateFrom = function (parent, flags) {
  784. ;
  785. ;
  786. };
  787. function cancellationExecute(executor, resolve, reject) {
  788. var promise = this;
  789. try {
  790. executor(resolve, reject, function(onCancel) {
  791. if (typeof onCancel !== "function") {
  792. throw new TypeError("onCancel must be a function, got: " +
  793. util.toString(onCancel));
  794. }
  795. promise._attachCancellationCallback(onCancel);
  796. });
  797. } catch (e) {
  798. return e;
  799. }
  800. }
  801. function cancellationAttachCancellationCallback(onCancel) {
  802. if (!this._isCancellable()) return this;
  803. var previousOnCancel = this._onCancel();
  804. if (previousOnCancel !== undefined) {
  805. if (util.isArray(previousOnCancel)) {
  806. previousOnCancel.push(onCancel);
  807. } else {
  808. this._setOnCancel([previousOnCancel, onCancel]);
  809. }
  810. } else {
  811. this._setOnCancel(onCancel);
  812. }
  813. }
  814. function cancellationOnCancel() {
  815. return this._onCancelField;
  816. }
  817. function cancellationSetOnCancel(onCancel) {
  818. this._onCancelField = onCancel;
  819. }
  820. function cancellationClearCancellationData() {
  821. this._cancellationParent = undefined;
  822. this._onCancelField = undefined;
  823. }
  824. function cancellationPropagateFrom(parent, flags) {
  825. if ((flags & 1) !== 0) {
  826. this._cancellationParent = parent;
  827. var branchesRemainingToCancel = parent._branchesRemainingToCancel;
  828. if (branchesRemainingToCancel === undefined) {
  829. branchesRemainingToCancel = 0;
  830. }
  831. parent._branchesRemainingToCancel = branchesRemainingToCancel + 1;
  832. }
  833. if ((flags & 2) !== 0 && parent._isBound()) {
  834. this._setBoundTo(parent._boundTo);
  835. }
  836. }
  837. function bindingPropagateFrom(parent, flags) {
  838. if ((flags & 2) !== 0 && parent._isBound()) {
  839. this._setBoundTo(parent._boundTo);
  840. }
  841. }
  842. var propagateFromFunction = bindingPropagateFrom;
  843. function boundValueFunction() {
  844. var ret = this._boundTo;
  845. if (ret !== undefined) {
  846. if (ret instanceof Promise) {
  847. if (ret.isFulfilled()) {
  848. return ret.value();
  849. } else {
  850. return undefined;
  851. }
  852. }
  853. }
  854. return ret;
  855. }
  856. function longStackTracesCaptureStackTrace() {
  857. this._trace = new CapturedTrace(this._peekContext());
  858. }
  859. function longStackTracesAttachExtraTrace(error, ignoreSelf) {
  860. if (canAttachTrace(error)) {
  861. var trace = this._trace;
  862. if (trace !== undefined) {
  863. if (ignoreSelf) trace = trace._parent;
  864. }
  865. if (trace !== undefined) {
  866. trace.attachExtraTrace(error);
  867. } else if (!error.__stackCleaned__) {
  868. var parsed = parseStackAndMessage(error);
  869. util.notEnumerableProp(error, "stack",
  870. parsed.message + "\n" + parsed.stack.join("\n"));
  871. util.notEnumerableProp(error, "__stackCleaned__", true);
  872. }
  873. }
  874. }
  875. function longStackTracesDereferenceTrace() {
  876. this._trace = undefined;
  877. }
  878. function checkForgottenReturns(returnValue, promiseCreated, name, promise,
  879. parent) {
  880. if (returnValue === undefined && promiseCreated !== null &&
  881. wForgottenReturn) {
  882. if (parent !== undefined && parent._returnedNonUndefined()) return;
  883. if ((promise._bitField & 65535) === 0) return;
  884. if (name) name = name + " ";
  885. var handlerLine = "";
  886. var creatorLine = "";
  887. if (promiseCreated._trace) {
  888. var traceLines = promiseCreated._trace.stack.split("\n");
  889. var stack = cleanStack(traceLines);
  890. for (var i = stack.length - 1; i >= 0; --i) {
  891. var line = stack[i];
  892. if (!nodeFramePattern.test(line)) {
  893. var lineMatches = line.match(parseLinePattern);
  894. if (lineMatches) {
  895. handlerLine = "at " + lineMatches[1] +
  896. ":" + lineMatches[2] + ":" + lineMatches[3] + " ";
  897. }
  898. break;
  899. }
  900. }
  901. if (stack.length > 0) {
  902. var firstUserLine = stack[0];
  903. for (var i = 0; i < traceLines.length; ++i) {
  904. if (traceLines[i] === firstUserLine) {
  905. if (i > 0) {
  906. creatorLine = "\n" + traceLines[i - 1];
  907. }
  908. break;
  909. }
  910. }
  911. }
  912. }
  913. var msg = "a promise was created in a " + name +
  914. "handler " + handlerLine + "but was not returned from it, " +
  915. "see http://goo.gl/rRqMUw" +
  916. creatorLine;
  917. promise._warn(msg, true, promiseCreated);
  918. }
  919. }
  920. function deprecated(name, replacement) {
  921. var message = name +
  922. " is deprecated and will be removed in a future version.";
  923. if (replacement) message += " Use " + replacement + " instead.";
  924. return warn(message);
  925. }
  926. function warn(message, shouldUseOwnTrace, promise) {
  927. if (!config.warnings) return;
  928. var warning = new Warning(message);
  929. var ctx;
  930. if (shouldUseOwnTrace) {
  931. promise._attachExtraTrace(warning);
  932. } else if (config.longStackTraces && (ctx = Promise._peekContext())) {
  933. ctx.attachExtraTrace(warning);
  934. } else {
  935. var parsed = parseStackAndMessage(warning);
  936. warning.stack = parsed.message + "\n" + parsed.stack.join("\n");
  937. }
  938. if (!activeFireEvent("warning", warning)) {
  939. formatAndLogError(warning, "", true);
  940. }
  941. }
  942. function reconstructStack(message, stacks) {
  943. for (var i = 0; i < stacks.length - 1; ++i) {
  944. stacks[i].push("From previous event:");
  945. stacks[i] = stacks[i].join("\n");
  946. }
  947. if (i < stacks.length) {
  948. stacks[i] = stacks[i].join("\n");
  949. }
  950. return message + "\n" + stacks.join("\n");
  951. }
  952. function removeDuplicateOrEmptyJumps(stacks) {
  953. for (var i = 0; i < stacks.length; ++i) {
  954. if (stacks[i].length === 0 ||
  955. ((i + 1 < stacks.length) && stacks[i][0] === stacks[i+1][0])) {
  956. stacks.splice(i, 1);
  957. i--;
  958. }
  959. }
  960. }
  961. function removeCommonRoots(stacks) {
  962. var current = stacks[0];
  963. for (var i = 1; i < stacks.length; ++i) {
  964. var prev = stacks[i];
  965. var currentLastIndex = current.length - 1;
  966. var currentLastLine = current[currentLastIndex];
  967. var commonRootMeetPoint = -1;
  968. for (var j = prev.length - 1; j >= 0; --j) {
  969. if (prev[j] === currentLastLine) {
  970. commonRootMeetPoint = j;
  971. break;
  972. }
  973. }
  974. for (var j = commonRootMeetPoint; j >= 0; --j) {
  975. var line = prev[j];
  976. if (current[currentLastIndex] === line) {
  977. current.pop();
  978. currentLastIndex--;
  979. } else {
  980. break;
  981. }
  982. }
  983. current = prev;
  984. }
  985. }
  986. function cleanStack(stack) {
  987. var ret = [];
  988. for (var i = 0; i < stack.length; ++i) {
  989. var line = stack[i];
  990. var isTraceLine = " (No stack trace)" === line ||
  991. stackFramePattern.test(line);
  992. var isInternalFrame = isTraceLine && shouldIgnore(line);
  993. if (isTraceLine && !isInternalFrame) {
  994. if (indentStackFrames && line.charAt(0) !== " ") {
  995. line = " " + line;
  996. }
  997. ret.push(line);
  998. }
  999. }
  1000. return ret;
  1001. }
  1002. function stackFramesAsArray(error) {
  1003. var stack = error.stack.replace(/\s+$/g, "").split("\n");
  1004. for (var i = 0; i < stack.length; ++i) {
  1005. var line = stack[i];
  1006. if (" (No stack trace)" === line || stackFramePattern.test(line)) {
  1007. break;
  1008. }
  1009. }
  1010. if (i > 0 && error.name != "SyntaxError") {
  1011. stack = stack.slice(i);
  1012. }
  1013. return stack;
  1014. }
  1015. function parseStackAndMessage(error) {
  1016. var stack = error.stack;
  1017. var message = error.toString();
  1018. stack = typeof stack === "string" && stack.length > 0
  1019. ? stackFramesAsArray(error) : [" (No stack trace)"];
  1020. return {
  1021. message: message,
  1022. stack: error.name == "SyntaxError" ? stack : cleanStack(stack)
  1023. };
  1024. }
  1025. function formatAndLogError(error, title, isSoft) {
  1026. if (typeof console !== "undefined") {
  1027. var message;
  1028. if (util.isObject(error)) {
  1029. var stack = error.stack;
  1030. message = title + formatStack(stack, error);
  1031. } else {
  1032. message = title + String(error);
  1033. }
  1034. if (typeof printWarning === "function") {
  1035. printWarning(message, isSoft);
  1036. } else if (typeof console.log === "function" ||
  1037. typeof console.log === "object") {
  1038. console.log(message);
  1039. }
  1040. }
  1041. }
  1042. function fireRejectionEvent(name, localHandler, reason, promise) {
  1043. var localEventFired = false;
  1044. try {
  1045. if (typeof localHandler === "function") {
  1046. localEventFired = true;
  1047. if (name === "rejectionHandled") {
  1048. localHandler(promise);
  1049. } else {
  1050. localHandler(reason, promise);
  1051. }
  1052. }
  1053. } catch (e) {
  1054. async.throwLater(e);
  1055. }
  1056. if (name === "unhandledRejection") {
  1057. if (!activeFireEvent(name, reason, promise) && !localEventFired) {
  1058. formatAndLogError(reason, "Unhandled rejection ");
  1059. }
  1060. } else {
  1061. activeFireEvent(name, promise);
  1062. }
  1063. }
  1064. function formatNonError(obj) {
  1065. var str;
  1066. if (typeof obj === "function") {
  1067. str = "[function " +
  1068. (obj.name || "anonymous") +
  1069. "]";
  1070. } else {
  1071. str = obj && typeof obj.toString === "function"
  1072. ? obj.toString() : util.toString(obj);
  1073. var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
  1074. if (ruselessToString.test(str)) {
  1075. try {
  1076. var newStr = JSON.stringify(obj);
  1077. str = newStr;
  1078. }
  1079. catch(e) {
  1080. }
  1081. }
  1082. if (str.length === 0) {
  1083. str = "(empty array)";
  1084. }
  1085. }
  1086. return ("(<" + snip(str) + ">, no stack trace)");
  1087. }
  1088. function snip(str) {
  1089. var maxChars = 41;
  1090. if (str.length < maxChars) {
  1091. return str;
  1092. }
  1093. return str.substr(0, maxChars - 3) + "...";
  1094. }
  1095. function longStackTracesIsSupported() {
  1096. return typeof captureStackTrace === "function";
  1097. }
  1098. var shouldIgnore = function() { return false; };
  1099. var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;
  1100. function parseLineInfo(line) {
  1101. var matches = line.match(parseLineInfoRegex);
  1102. if (matches) {
  1103. return {
  1104. fileName: matches[1],
  1105. line: parseInt(matches[2], 10)
  1106. };
  1107. }
  1108. }
  1109. function setBounds(firstLineError, lastLineError) {
  1110. if (!longStackTracesIsSupported()) return;
  1111. var firstStackLines = (firstLineError.stack || "").split("\n");
  1112. var lastStackLines = (lastLineError.stack || "").split("\n");
  1113. var firstIndex = -1;
  1114. var lastIndex = -1;
  1115. var firstFileName;
  1116. var lastFileName;
  1117. for (var i = 0; i < firstStackLines.length; ++i) {
  1118. var result = parseLineInfo(firstStackLines[i]);
  1119. if (result) {
  1120. firstFileName = result.fileName;
  1121. firstIndex = result.line;
  1122. break;
  1123. }
  1124. }
  1125. for (var i = 0; i < lastStackLines.length; ++i) {
  1126. var result = parseLineInfo(lastStackLines[i]);
  1127. if (result) {
  1128. lastFileName = result.fileName;
  1129. lastIndex = result.line;
  1130. break;
  1131. }
  1132. }
  1133. if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName ||
  1134. firstFileName !== lastFileName || firstIndex >= lastIndex) {
  1135. return;
  1136. }
  1137. shouldIgnore = function(line) {
  1138. if (bluebirdFramePattern.test(line)) return true;
  1139. var info = parseLineInfo(line);
  1140. if (info) {
  1141. if (info.fileName === firstFileName &&
  1142. (firstIndex <= info.line && info.line <= lastIndex)) {
  1143. return true;
  1144. }
  1145. }
  1146. return false;
  1147. };
  1148. }
  1149. function CapturedTrace(parent) {
  1150. this._parent = parent;
  1151. this._promisesCreated = 0;
  1152. var length = this._length = 1 + (parent === undefined ? 0 : parent._length);
  1153. captureStackTrace(this, CapturedTrace);
  1154. if (length > 32) this.uncycle();
  1155. }
  1156. util.inherits(CapturedTrace, Error);
  1157. Context.CapturedTrace = CapturedTrace;
  1158. CapturedTrace.prototype.uncycle = function() {
  1159. var length = this._length;
  1160. if (length < 2) return;
  1161. var nodes = [];
  1162. var stackToIndex = {};
  1163. for (var i = 0, node = this; node !== undefined; ++i) {
  1164. nodes.push(node);
  1165. node = node._parent;
  1166. }
  1167. length = this._length = i;
  1168. for (var i = length - 1; i >= 0; --i) {
  1169. var stack = nodes[i].stack;
  1170. if (stackToIndex[stack] === undefined) {
  1171. stackToIndex[stack] = i;
  1172. }
  1173. }
  1174. for (var i = 0; i < length; ++i) {
  1175. var currentStack = nodes[i].stack;
  1176. var index = stackToIndex[currentStack];
  1177. if (index !== undefined && index !== i) {
  1178. if (index > 0) {
  1179. nodes[index - 1]._parent = undefined;
  1180. nodes[index - 1]._length = 1;
  1181. }
  1182. nodes[i]._parent = undefined;
  1183. nodes[i]._length = 1;
  1184. var cycleEdgeNode = i > 0 ? nodes[i - 1] : this;
  1185. if (index < length - 1) {
  1186. cycleEdgeNode._parent = nodes[index + 1];
  1187. cycleEdgeNode._parent.uncycle();
  1188. cycleEdgeNode._length =
  1189. cycleEdgeNode._parent._length + 1;
  1190. } else {
  1191. cycleEdgeNode._parent = undefined;
  1192. cycleEdgeNode._length = 1;
  1193. }
  1194. var currentChildLength = cycleEdgeNode._length + 1;
  1195. for (var j = i - 2; j >= 0; --j) {
  1196. nodes[j]._length = currentChildLength;
  1197. currentChildLength++;
  1198. }
  1199. return;
  1200. }
  1201. }
  1202. };
  1203. CapturedTrace.prototype.attachExtraTrace = function(error) {
  1204. if (error.__stackCleaned__) return;
  1205. this.uncycle();
  1206. var parsed = parseStackAndMessage(error);
  1207. var message = parsed.message;
  1208. var stacks = [parsed.stack];
  1209. var trace = this;
  1210. while (trace !== undefined) {
  1211. stacks.push(cleanStack(trace.stack.split("\n")));
  1212. trace = trace._parent;
  1213. }
  1214. removeCommonRoots(stacks);
  1215. removeDuplicateOrEmptyJumps(stacks);
  1216. util.notEnumerableProp(error, "stack", reconstructStack(message, stacks));
  1217. util.notEnumerableProp(error, "__stackCleaned__", true);
  1218. };
  1219. var captureStackTrace = (function stackDetection() {
  1220. var v8stackFramePattern = /^\s*at\s*/;
  1221. var v8stackFormatter = function(stack, error) {
  1222. if (typeof stack === "string") return stack;
  1223. if (error.name !== undefined &&
  1224. error.message !== undefined) {
  1225. return error.toString();
  1226. }
  1227. return formatNonError(error);
  1228. };
  1229. if (typeof Error.stackTraceLimit === "number" &&
  1230. typeof Error.captureStackTrace === "function") {
  1231. Error.stackTraceLimit += 6;
  1232. stackFramePattern = v8stackFramePattern;
  1233. formatStack = v8stackFormatter;
  1234. var captureStackTrace = Error.captureStackTrace;
  1235. shouldIgnore = function(line) {
  1236. return bluebirdFramePattern.test(line);
  1237. };
  1238. return function(receiver, ignoreUntil) {
  1239. Error.stackTraceLimit += 6;
  1240. captureStackTrace(receiver, ignoreUntil);
  1241. Error.stackTraceLimit -= 6;
  1242. };
  1243. }
  1244. var err = new Error();
  1245. if (typeof err.stack === "string" &&
  1246. err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) {
  1247. stackFramePattern = /@/;
  1248. formatStack = v8stackFormatter;
  1249. indentStackFrames = true;
  1250. return function captureStackTrace(o) {
  1251. o.stack = new Error().stack;
  1252. };
  1253. }
  1254. var hasStackAfterThrow;
  1255. try { throw new Error(); }
  1256. catch(e) {
  1257. hasStackAfterThrow = ("stack" in e);
  1258. }
  1259. if (!("stack" in err) && hasStackAfterThrow &&
  1260. typeof Error.stackTraceLimit === "number") {
  1261. stackFramePattern = v8stackFramePattern;
  1262. formatStack = v8stackFormatter;
  1263. return function captureStackTrace(o) {
  1264. Error.stackTraceLimit += 6;
  1265. try { throw new Error(); }
  1266. catch(e) { o.stack = e.stack; }
  1267. Error.stackTraceLimit -= 6;
  1268. };
  1269. }
  1270. formatStack = function(stack, error) {
  1271. if (typeof stack === "string") return stack;
  1272. if ((typeof error === "object" ||
  1273. typeof error === "function") &&
  1274. error.name !== undefined &&
  1275. error.message !== undefined) {
  1276. return error.toString();
  1277. }
  1278. return formatNonError(error);
  1279. };
  1280. return null;
  1281. })([]);
  1282. if (typeof console !== "undefined" && typeof console.warn !== "undefined") {
  1283. printWarning = function (message) {
  1284. console.warn(message);
  1285. };
  1286. if (util.isNode && process.stderr.isTTY) {
  1287. printWarning = function(message, isSoft) {
  1288. var color = isSoft ? "\u001b[33m" : "\u001b[31m";
  1289. console.warn(color + message + "\u001b[0m\n");
  1290. };
  1291. } else if (!util.isNode && typeof (new Error().stack) === "string") {
  1292. printWarning = function(message, isSoft) {
  1293. console.warn("%c" + message,
  1294. isSoft ? "color: darkorange" : "color: red");
  1295. };
  1296. }
  1297. }
  1298. var config = {
  1299. warnings: warnings,
  1300. longStackTraces: false,
  1301. cancellation: false,
  1302. monitoring: false,
  1303. asyncHooks: false
  1304. };
  1305. if (longStackTraces) Promise.longStackTraces();
  1306. return {
  1307. asyncHooks: function() {
  1308. return config.asyncHooks;
  1309. },
  1310. longStackTraces: function() {
  1311. return config.longStackTraces;
  1312. },
  1313. warnings: function() {
  1314. return config.warnings;
  1315. },
  1316. cancellation: function() {
  1317. return config.cancellation;
  1318. },
  1319. monitoring: function() {
  1320. return config.monitoring;
  1321. },
  1322. propagateFromFunction: function() {
  1323. return propagateFromFunction;
  1324. },
  1325. boundValueFunction: function() {
  1326. return boundValueFunction;
  1327. },
  1328. checkForgottenReturns: checkForgottenReturns,
  1329. setBounds: setBounds,
  1330. warn: warn,
  1331. deprecated: deprecated,
  1332. CapturedTrace: CapturedTrace,
  1333. fireDomEvent: fireDomEvent,
  1334. fireGlobalEvent: fireGlobalEvent
  1335. };
  1336. };
  1337. },{"./errors":9,"./es5":10,"./util":21}],8:[function(_dereq_,module,exports){
  1338. "use strict";
  1339. module.exports = function(Promise) {
  1340. function returner() {
  1341. return this.value;
  1342. }
  1343. function thrower() {
  1344. throw this.reason;
  1345. }
  1346. Promise.prototype["return"] =
  1347. Promise.prototype.thenReturn = function (value) {
  1348. if (value instanceof Promise) value.suppressUnhandledRejections();
  1349. return this._then(
  1350. returner, undefined, undefined, {value: value}, undefined);
  1351. };
  1352. Promise.prototype["throw"] =
  1353. Promise.prototype.thenThrow = function (reason) {
  1354. return this._then(
  1355. thrower, undefined, undefined, {reason: reason}, undefined);
  1356. };
  1357. Promise.prototype.catchThrow = function (reason) {
  1358. if (arguments.length <= 1) {
  1359. return this._then(
  1360. undefined, thrower, undefined, {reason: reason}, undefined);
  1361. } else {
  1362. var _reason = arguments[1];
  1363. var handler = function() {throw _reason;};
  1364. return this.caught(reason, handler);
  1365. }
  1366. };
  1367. Promise.prototype.catchReturn = function (value) {
  1368. if (arguments.length <= 1) {
  1369. if (value instanceof Promise) value.suppressUnhandledRejections();
  1370. return this._then(
  1371. undefined, returner, undefined, {value: value}, undefined);
  1372. } else {
  1373. var _value = arguments[1];
  1374. if (_value instanceof Promise) _value.suppressUnhandledRejections();
  1375. var handler = function() {return _value;};
  1376. return this.caught(value, handler);
  1377. }
  1378. };
  1379. };
  1380. },{}],9:[function(_dereq_,module,exports){
  1381. "use strict";
  1382. var es5 = _dereq_("./es5");
  1383. var Objectfreeze = es5.freeze;
  1384. var util = _dereq_("./util");
  1385. var inherits = util.inherits;
  1386. var notEnumerableProp = util.notEnumerableProp;
  1387. function subError(nameProperty, defaultMessage) {
  1388. function SubError(message) {
  1389. if (!(this instanceof SubError)) return new SubError(message);
  1390. notEnumerableProp(this, "message",
  1391. typeof message === "string" ? message : defaultMessage);
  1392. notEnumerableProp(this, "name", nameProperty);
  1393. if (Error.captureStackTrace) {
  1394. Error.captureStackTrace(this, this.constructor);
  1395. } else {
  1396. Error.call(this);
  1397. }
  1398. }
  1399. inherits(SubError, Error);
  1400. return SubError;
  1401. }
  1402. var _TypeError, _RangeError;
  1403. var Warning = subError("Warning", "warning");
  1404. var CancellationError = subError("CancellationError", "cancellation error");
  1405. var TimeoutError = subError("TimeoutError", "timeout error");
  1406. var AggregateError = subError("AggregateError", "aggregate error");
  1407. try {
  1408. _TypeError = TypeError;
  1409. _RangeError = RangeError;
  1410. } catch(e) {
  1411. _TypeError = subError("TypeError", "type error");
  1412. _RangeError = subError("RangeError", "range error");
  1413. }
  1414. var methods = ("join pop push shift unshift slice filter forEach some " +
  1415. "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" ");
  1416. for (var i = 0; i < methods.length; ++i) {
  1417. if (typeof Array.prototype[methods[i]] === "function") {
  1418. AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];
  1419. }
  1420. }
  1421. es5.defineProperty(AggregateError.prototype, "length", {
  1422. value: 0,
  1423. configurable: false,
  1424. writable: true,
  1425. enumerable: true
  1426. });
  1427. AggregateError.prototype["isOperational"] = true;
  1428. var level = 0;
  1429. AggregateError.prototype.toString = function() {
  1430. var indent = Array(level * 4 + 1).join(" ");
  1431. var ret = "\n" + indent + "AggregateError of:" + "\n";
  1432. level++;
  1433. indent = Array(level * 4 + 1).join(" ");
  1434. for (var i = 0; i < this.length; ++i) {
  1435. var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";
  1436. var lines = str.split("\n");
  1437. for (var j = 0; j < lines.length; ++j) {
  1438. lines[j] = indent + lines[j];
  1439. }
  1440. str = lines.join("\n");
  1441. ret += str + "\n";
  1442. }
  1443. level--;
  1444. return ret;
  1445. };
  1446. function OperationalError(message) {
  1447. if (!(this instanceof OperationalError))
  1448. return new OperationalError(message);
  1449. notEnumerableProp(this, "name", "OperationalError");
  1450. notEnumerableProp(this, "message", message);
  1451. this.cause = message;
  1452. this["isOperational"] = true;
  1453. if (message instanceof Error) {
  1454. notEnumerableProp(this, "message", message.message);
  1455. notEnumerableProp(this, "stack", message.stack);
  1456. } else if (Error.captureStackTrace) {
  1457. Error.captureStackTrace(this, this.constructor);
  1458. }
  1459. }
  1460. inherits(OperationalError, Error);
  1461. var errorTypes = Error["__BluebirdErrorTypes__"];
  1462. if (!errorTypes) {
  1463. errorTypes = Objectfreeze({
  1464. CancellationError: CancellationError,
  1465. TimeoutError: TimeoutError,
  1466. OperationalError: OperationalError,
  1467. RejectionError: OperationalError,
  1468. AggregateError: AggregateError
  1469. });
  1470. es5.defineProperty(Error, "__BluebirdErrorTypes__", {
  1471. value: errorTypes,
  1472. writable: false,
  1473. enumerable: false,
  1474. configurable: false
  1475. });
  1476. }
  1477. module.exports = {
  1478. Error: Error,
  1479. TypeError: _TypeError,
  1480. RangeError: _RangeError,
  1481. CancellationError: errorTypes.CancellationError,
  1482. OperationalError: errorTypes.OperationalError,
  1483. TimeoutError: errorTypes.TimeoutError,
  1484. AggregateError: errorTypes.AggregateError,
  1485. Warning: Warning
  1486. };
  1487. },{"./es5":10,"./util":21}],10:[function(_dereq_,module,exports){
  1488. var isES5 = (function(){
  1489. "use strict";
  1490. return this === undefined;
  1491. })();
  1492. if (isES5) {
  1493. module.exports = {
  1494. freeze: Object.freeze,
  1495. defineProperty: Object.defineProperty,
  1496. getDescriptor: Object.getOwnPropertyDescriptor,
  1497. keys: Object.keys,
  1498. names: Object.getOwnPropertyNames,
  1499. getPrototypeOf: Object.getPrototypeOf,
  1500. isArray: Array.isArray,
  1501. isES5: isES5,
  1502. propertyIsWritable: function(obj, prop) {
  1503. var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
  1504. return !!(!descriptor || descriptor.writable || descriptor.set);
  1505. }
  1506. };
  1507. } else {
  1508. var has = {}.hasOwnProperty;
  1509. var str = {}.toString;
  1510. var proto = {}.constructor.prototype;
  1511. var ObjectKeys = function (o) {
  1512. var ret = [];
  1513. for (var key in o) {
  1514. if (has.call(o, key)) {
  1515. ret.push(key);
  1516. }
  1517. }
  1518. return ret;
  1519. };
  1520. var ObjectGetDescriptor = function(o, key) {
  1521. return {value: o[key]};
  1522. };
  1523. var ObjectDefineProperty = function (o, key, desc) {
  1524. o[key] = desc.value;
  1525. return o;
  1526. };
  1527. var ObjectFreeze = function (obj) {
  1528. return obj;
  1529. };
  1530. var ObjectGetPrototypeOf = function (obj) {
  1531. try {
  1532. return Object(obj).constructor.prototype;
  1533. }
  1534. catch (e) {
  1535. return proto;
  1536. }
  1537. };
  1538. var ArrayIsArray = function (obj) {
  1539. try {
  1540. return str.call(obj) === "[object Array]";
  1541. }
  1542. catch(e) {
  1543. return false;
  1544. }
  1545. };
  1546. module.exports = {
  1547. isArray: ArrayIsArray,
  1548. keys: ObjectKeys,
  1549. names: ObjectKeys,
  1550. defineProperty: ObjectDefineProperty,
  1551. getDescriptor: ObjectGetDescriptor,
  1552. freeze: ObjectFreeze,
  1553. getPrototypeOf: ObjectGetPrototypeOf,
  1554. isES5: isES5,
  1555. propertyIsWritable: function() {
  1556. return true;
  1557. }
  1558. };
  1559. }
  1560. },{}],11:[function(_dereq_,module,exports){
  1561. "use strict";
  1562. module.exports = function(Promise, tryConvertToPromise, NEXT_FILTER) {
  1563. var util = _dereq_("./util");
  1564. var CancellationError = Promise.CancellationError;
  1565. var errorObj = util.errorObj;
  1566. var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER);
  1567. function PassThroughHandlerContext(promise, type, handler) {
  1568. this.promise = promise;
  1569. this.type = type;
  1570. this.handler = handler;
  1571. this.called = false;
  1572. this.cancelPromise = null;
  1573. }
  1574. PassThroughHandlerContext.prototype.isFinallyHandler = function() {
  1575. return this.type === 0;
  1576. };
  1577. function FinallyHandlerCancelReaction(finallyHandler) {
  1578. this.finallyHandler = finallyHandler;
  1579. }
  1580. FinallyHandlerCancelReaction.prototype._resultCancelled = function() {
  1581. checkCancel(this.finallyHandler);
  1582. };
  1583. function checkCancel(ctx, reason) {
  1584. if (ctx.cancelPromise != null) {
  1585. if (arguments.length > 1) {
  1586. ctx.cancelPromise._reject(reason);
  1587. } else {
  1588. ctx.cancelPromise._cancel();
  1589. }
  1590. ctx.cancelPromise = null;
  1591. return true;
  1592. }
  1593. return false;
  1594. }
  1595. function succeed() {
  1596. return finallyHandler.call(this, this.promise._target()._settledValue());
  1597. }
  1598. function fail(reason) {
  1599. if (checkCancel(this, reason)) return;
  1600. errorObj.e = reason;
  1601. return errorObj;
  1602. }
  1603. function finallyHandler(reasonOrValue) {
  1604. var promise = this.promise;
  1605. var handler = this.handler;
  1606. if (!this.called) {
  1607. this.called = true;
  1608. var ret = this.isFinallyHandler()
  1609. ? handler.call(promise._boundValue())
  1610. : handler.call(promise._boundValue(), reasonOrValue);
  1611. if (ret === NEXT_FILTER) {
  1612. return ret;
  1613. } else if (ret !== undefined) {
  1614. promise._setReturnedNonUndefined();
  1615. var maybePromise = tryConvertToPromise(ret, promise);
  1616. if (maybePromise instanceof Promise) {
  1617. if (this.cancelPromise != null) {
  1618. if (maybePromise._isCancelled()) {
  1619. var reason =
  1620. new CancellationError("late cancellation observer");
  1621. promise._attachExtraTrace(reason);
  1622. errorObj.e = reason;
  1623. return errorObj;
  1624. } else if (maybePromise.isPending()) {
  1625. maybePromise._attachCancellationCallback(
  1626. new FinallyHandlerCancelReaction(this));
  1627. }
  1628. }
  1629. return maybePromise._then(
  1630. succeed, fail, undefined, this, undefined);
  1631. }
  1632. }
  1633. }
  1634. if (promise.isRejected()) {
  1635. checkCancel(this);
  1636. errorObj.e = reasonOrValue;
  1637. return errorObj;
  1638. } else {
  1639. checkCancel(this);
  1640. return reasonOrValue;
  1641. }
  1642. }
  1643. Promise.prototype._passThrough = function(handler, type, success, fail) {
  1644. if (typeof handler !== "function") return this.then();
  1645. return this._then(success,
  1646. fail,
  1647. undefined,
  1648. new PassThroughHandlerContext(this, type, handler),
  1649. undefined);
  1650. };
  1651. Promise.prototype.lastly =
  1652. Promise.prototype["finally"] = function (handler) {
  1653. return this._passThrough(handler,
  1654. 0,
  1655. finallyHandler,
  1656. finallyHandler);
  1657. };
  1658. Promise.prototype.tap = function (handler) {
  1659. return this._passThrough(handler, 1, finallyHandler);
  1660. };
  1661. Promise.prototype.tapCatch = function (handlerOrPredicate) {
  1662. var len = arguments.length;
  1663. if(len === 1) {
  1664. return this._passThrough(handlerOrPredicate,
  1665. 1,
  1666. undefined,
  1667. finallyHandler);
  1668. } else {
  1669. var catchInstances = new Array(len - 1),
  1670. j = 0, i;
  1671. for (i = 0; i < len - 1; ++i) {
  1672. var item = arguments[i];
  1673. if (util.isObject(item)) {
  1674. catchInstances[j++] = item;
  1675. } else {
  1676. return Promise.reject(new TypeError(
  1677. "tapCatch statement predicate: "
  1678. + "expecting an object but got " + util.classString(item)
  1679. ));
  1680. }
  1681. }
  1682. catchInstances.length = j;
  1683. var handler = arguments[i];
  1684. return this._passThrough(catchFilter(catchInstances, handler, this),
  1685. 1,
  1686. undefined,
  1687. finallyHandler);
  1688. }
  1689. };
  1690. return PassThroughHandlerContext;
  1691. };
  1692. },{"./catch_filter":5,"./util":21}],12:[function(_dereq_,module,exports){
  1693. "use strict";
  1694. module.exports =
  1695. function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async) {
  1696. var util = _dereq_("./util");
  1697. var canEvaluate = util.canEvaluate;
  1698. var tryCatch = util.tryCatch;
  1699. var errorObj = util.errorObj;
  1700. var reject;
  1701. if (!true) {
  1702. if (canEvaluate) {
  1703. var thenCallback = function(i) {
  1704. return new Function("value", "holder", " \n\
  1705. 'use strict'; \n\
  1706. holder.pIndex = value; \n\
  1707. holder.checkFulfillment(this); \n\
  1708. ".replace(/Index/g, i));
  1709. };
  1710. var promiseSetter = function(i) {
  1711. return new Function("promise", "holder", " \n\
  1712. 'use strict'; \n\
  1713. holder.pIndex = promise; \n\
  1714. ".replace(/Index/g, i));
  1715. };
  1716. var generateHolderClass = function(total) {
  1717. var props = new Array(total);
  1718. for (var i = 0; i < props.length; ++i) {
  1719. props[i] = "this.p" + (i+1);
  1720. }
  1721. var assignment = props.join(" = ") + " = null;";
  1722. var cancellationCode= "var promise;\n" + props.map(function(prop) {
  1723. return " \n\
  1724. promise = " + prop + "; \n\
  1725. if (promise instanceof Promise) { \n\
  1726. promise.cancel(); \n\
  1727. } \n\
  1728. ";
  1729. }).join("\n");
  1730. var passedArguments = props.join(", ");
  1731. var name = "Holder$" + total;
  1732. var code = "return function(tryCatch, errorObj, Promise, async) { \n\
  1733. 'use strict'; \n\
  1734. function [TheName](fn) { \n\
  1735. [TheProperties] \n\
  1736. this.fn = fn; \n\
  1737. this.asyncNeeded = true; \n\
  1738. this.now = 0; \n\
  1739. } \n\
  1740. \n\
  1741. [TheName].prototype._callFunction = function(promise) { \n\
  1742. promise._pushContext(); \n\
  1743. var ret = tryCatch(this.fn)([ThePassedArguments]); \n\
  1744. promise._popContext(); \n\
  1745. if (ret === errorObj) { \n\
  1746. promise._rejectCallback(ret.e, false); \n\
  1747. } else { \n\
  1748. promise._resolveCallback(ret); \n\
  1749. } \n\
  1750. }; \n\
  1751. \n\
  1752. [TheName].prototype.checkFulfillment = function(promise) { \n\
  1753. var now = ++this.now; \n\
  1754. if (now === [TheTotal]) { \n\
  1755. if (this.asyncNeeded) { \n\
  1756. async.invoke(this._callFunction, this, promise); \n\
  1757. } else { \n\
  1758. this._callFunction(promise); \n\
  1759. } \n\
  1760. \n\
  1761. } \n\
  1762. }; \n\
  1763. \n\
  1764. [TheName].prototype._resultCancelled = function() { \n\
  1765. [CancellationCode] \n\
  1766. }; \n\
  1767. \n\
  1768. return [TheName]; \n\
  1769. }(tryCatch, errorObj, Promise, async); \n\
  1770. ";
  1771. code = code.replace(/\[TheName\]/g, name)
  1772. .replace(/\[TheTotal\]/g, total)
  1773. .replace(/\[ThePassedArguments\]/g, passedArguments)
  1774. .replace(/\[TheProperties\]/g, assignment)
  1775. .replace(/\[CancellationCode\]/g, cancellationCode);
  1776. return new Function("tryCatch", "errorObj", "Promise", "async", code)
  1777. (tryCatch, errorObj, Promise, async);
  1778. };
  1779. var holderClasses = [];
  1780. var thenCallbacks = [];
  1781. var promiseSetters = [];
  1782. for (var i = 0; i < 8; ++i) {
  1783. holderClasses.push(generateHolderClass(i + 1));
  1784. thenCallbacks.push(thenCallback(i + 1));
  1785. promiseSetters.push(promiseSetter(i + 1));
  1786. }
  1787. reject = function (reason) {
  1788. this._reject(reason);
  1789. };
  1790. }}
  1791. Promise.join = function () {
  1792. var last = arguments.length - 1;
  1793. var fn;
  1794. if (last > 0 && typeof arguments[last] === "function") {
  1795. fn = arguments[last];
  1796. if (!true) {
  1797. if (last <= 8 && canEvaluate) {
  1798. var ret = new Promise(INTERNAL);
  1799. ret._captureStackTrace();
  1800. var HolderClass = holderClasses[last - 1];
  1801. var holder = new HolderClass(fn);
  1802. var callbacks = thenCallbacks;
  1803. for (var i = 0; i < last; ++i) {
  1804. var maybePromise = tryConvertToPromise(arguments[i], ret);
  1805. if (maybePromise instanceof Promise) {
  1806. maybePromise = maybePromise._target();
  1807. var bitField = maybePromise._bitField;
  1808. ;
  1809. if (((bitField & 50397184) === 0)) {
  1810. maybePromise._then(callbacks[i], reject,
  1811. undefined, ret, holder);
  1812. promiseSetters[i](maybePromise, holder);
  1813. holder.asyncNeeded = false;
  1814. } else if (((bitField & 33554432) !== 0)) {
  1815. callbacks[i].call(ret,
  1816. maybePromise._value(), holder);
  1817. } else if (((bitField & 16777216) !== 0)) {
  1818. ret._reject(maybePromise._reason());
  1819. } else {
  1820. ret._cancel();
  1821. }
  1822. } else {
  1823. callbacks[i].call(ret, maybePromise, holder);
  1824. }
  1825. }
  1826. if (!ret._isFateSealed()) {
  1827. if (holder.asyncNeeded) {
  1828. var context = Promise._getContext();
  1829. holder.fn = util.contextBind(context, holder.fn);
  1830. }
  1831. ret._setAsyncGuaranteed();
  1832. ret._setOnCancel(holder);
  1833. }
  1834. return ret;
  1835. }
  1836. }
  1837. }
  1838. var args = [].slice.call(arguments);;
  1839. if (fn) args.pop();
  1840. var ret = new PromiseArray(args).promise();
  1841. return fn !== undefined ? ret.spread(fn) : ret;
  1842. };
  1843. };
  1844. },{"./util":21}],13:[function(_dereq_,module,exports){
  1845. "use strict";
  1846. module.exports =
  1847. function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) {
  1848. var util = _dereq_("./util");
  1849. var tryCatch = util.tryCatch;
  1850. Promise.method = function (fn) {
  1851. if (typeof fn !== "function") {
  1852. throw new Promise.TypeError("expecting a function but got " + util.classString(fn));
  1853. }
  1854. return function () {
  1855. var ret = new Promise(INTERNAL);
  1856. ret._captureStackTrace();
  1857. ret._pushContext();
  1858. var value = tryCatch(fn).apply(this, arguments);
  1859. var promiseCreated = ret._popContext();
  1860. debug.checkForgottenReturns(
  1861. value, promiseCreated, "Promise.method", ret);
  1862. ret._resolveFromSyncValue(value);
  1863. return ret;
  1864. };
  1865. };
  1866. Promise.attempt = Promise["try"] = function (fn) {
  1867. if (typeof fn !== "function") {
  1868. return apiRejection("expecting a function but got " + util.classString(fn));
  1869. }
  1870. var ret = new Promise(INTERNAL);
  1871. ret._captureStackTrace();
  1872. ret._pushContext();
  1873. var value;
  1874. if (arguments.length > 1) {
  1875. debug.deprecated("calling Promise.try with more than 1 argument");
  1876. var arg = arguments[1];
  1877. var ctx = arguments[2];
  1878. value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg)
  1879. : tryCatch(fn).call(ctx, arg);
  1880. } else {
  1881. value = tryCatch(fn)();
  1882. }
  1883. var promiseCreated = ret._popContext();
  1884. debug.checkForgottenReturns(
  1885. value, promiseCreated, "Promise.try", ret);
  1886. ret._resolveFromSyncValue(value);
  1887. return ret;
  1888. };
  1889. Promise.prototype._resolveFromSyncValue = function (value) {
  1890. if (value === util.errorObj) {
  1891. this._rejectCallback(value.e, false);
  1892. } else {
  1893. this._resolveCallback(value, true);
  1894. }
  1895. };
  1896. };
  1897. },{"./util":21}],14:[function(_dereq_,module,exports){
  1898. "use strict";
  1899. var util = _dereq_("./util");
  1900. var maybeWrapAsError = util.maybeWrapAsError;
  1901. var errors = _dereq_("./errors");
  1902. var OperationalError = errors.OperationalError;
  1903. var es5 = _dereq_("./es5");
  1904. function isUntypedError(obj) {
  1905. return obj instanceof Error &&
  1906. es5.getPrototypeOf(obj) === Error.prototype;
  1907. }
  1908. var rErrorKey = /^(?:name|message|stack|cause)$/;
  1909. function wrapAsOperationalError(obj) {
  1910. var ret;
  1911. if (isUntypedError(obj)) {
  1912. ret = new OperationalError(obj);
  1913. ret.name = obj.name;
  1914. ret.message = obj.message;
  1915. ret.stack = obj.stack;
  1916. var keys = es5.keys(obj);
  1917. for (var i = 0; i < keys.length; ++i) {
  1918. var key = keys[i];
  1919. if (!rErrorKey.test(key)) {
  1920. ret[key] = obj[key];
  1921. }
  1922. }
  1923. return ret;
  1924. }
  1925. util.markAsOriginatingFromRejection(obj);
  1926. return obj;
  1927. }
  1928. function nodebackForPromise(promise, multiArgs) {
  1929. return function(err, value) {
  1930. if (promise === null) return;
  1931. if (err) {
  1932. var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
  1933. promise._attachExtraTrace(wrapped);
  1934. promise._reject(wrapped);
  1935. } else if (!multiArgs) {
  1936. promise._fulfill(value);
  1937. } else {
  1938. var args = [].slice.call(arguments, 1);;
  1939. promise._fulfill(args);
  1940. }
  1941. promise = null;
  1942. };
  1943. }
  1944. module.exports = nodebackForPromise;
  1945. },{"./errors":9,"./es5":10,"./util":21}],15:[function(_dereq_,module,exports){
  1946. "use strict";
  1947. module.exports = function() {
  1948. var makeSelfResolutionError = function () {
  1949. return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  1950. };
  1951. var reflectHandler = function() {
  1952. return new Promise.PromiseInspection(this._target());
  1953. };
  1954. var apiRejection = function(msg) {
  1955. return Promise.reject(new TypeError(msg));
  1956. };
  1957. function Proxyable() {}
  1958. var UNDEFINED_BINDING = {};
  1959. var util = _dereq_("./util");
  1960. util.setReflectHandler(reflectHandler);
  1961. var getDomain = function() {
  1962. var domain = process.domain;
  1963. if (domain === undefined) {
  1964. return null;
  1965. }
  1966. return domain;
  1967. };
  1968. var getContextDefault = function() {
  1969. return null;
  1970. };
  1971. var getContextDomain = function() {
  1972. return {
  1973. domain: getDomain(),
  1974. async: null
  1975. };
  1976. };
  1977. var AsyncResource = util.isNode && util.nodeSupportsAsyncResource ?
  1978. _dereq_("async_hooks").AsyncResource : null;
  1979. var getContextAsyncHooks = function() {
  1980. return {
  1981. domain: getDomain(),
  1982. async: new AsyncResource("Bluebird::Promise")
  1983. };
  1984. };
  1985. var getContext = util.isNode ? getContextDomain : getContextDefault;
  1986. util.notEnumerableProp(Promise, "_getContext", getContext);
  1987. var enableAsyncHooks = function() {
  1988. getContext = getContextAsyncHooks;
  1989. util.notEnumerableProp(Promise, "_getContext", getContextAsyncHooks);
  1990. };
  1991. var disableAsyncHooks = function() {
  1992. getContext = getContextDomain;
  1993. util.notEnumerableProp(Promise, "_getContext", getContextDomain);
  1994. };
  1995. var es5 = _dereq_("./es5");
  1996. var Async = _dereq_("./async");
  1997. var async = new Async();
  1998. es5.defineProperty(Promise, "_async", {value: async});
  1999. var errors = _dereq_("./errors");
  2000. var TypeError = Promise.TypeError = errors.TypeError;
  2001. Promise.RangeError = errors.RangeError;
  2002. var CancellationError = Promise.CancellationError = errors.CancellationError;
  2003. Promise.TimeoutError = errors.TimeoutError;
  2004. Promise.OperationalError = errors.OperationalError;
  2005. Promise.RejectionError = errors.OperationalError;
  2006. Promise.AggregateError = errors.AggregateError;
  2007. var INTERNAL = function(){};
  2008. var APPLY = {};
  2009. var NEXT_FILTER = {};
  2010. var tryConvertToPromise = _dereq_("./thenables")(Promise, INTERNAL);
  2011. var PromiseArray =
  2012. _dereq_("./promise_array")(Promise, INTERNAL,
  2013. tryConvertToPromise, apiRejection, Proxyable);
  2014. var Context = _dereq_("./context")(Promise);
  2015. /*jshint unused:false*/
  2016. var createContext = Context.create;
  2017. var debug = _dereq_("./debuggability")(Promise, Context,
  2018. enableAsyncHooks, disableAsyncHooks);
  2019. var CapturedTrace = debug.CapturedTrace;
  2020. var PassThroughHandlerContext =
  2021. _dereq_("./finally")(Promise, tryConvertToPromise, NEXT_FILTER);
  2022. var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER);
  2023. var nodebackForPromise = _dereq_("./nodeback");
  2024. var errorObj = util.errorObj;
  2025. var tryCatch = util.tryCatch;
  2026. function check(self, executor) {
  2027. if (self == null || self.constructor !== Promise) {
  2028. throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  2029. }
  2030. if (typeof executor !== "function") {
  2031. throw new TypeError("expecting a function but got " + util.classString(executor));
  2032. }
  2033. }
  2034. function Promise(executor) {
  2035. if (executor !== INTERNAL) {
  2036. check(this, executor);
  2037. }
  2038. this._bitField = 0;
  2039. this._fulfillmentHandler0 = undefined;
  2040. this._rejectionHandler0 = undefined;
  2041. this._promise0 = undefined;
  2042. this._receiver0 = undefined;
  2043. this._resolveFromExecutor(executor);
  2044. this._promiseCreated();
  2045. this._fireEvent("promiseCreated", this);
  2046. }
  2047. Promise.prototype.toString = function () {
  2048. return "[object Promise]";
  2049. };
  2050. Promise.prototype.caught = Promise.prototype["catch"] = function (fn) {
  2051. var len = arguments.length;
  2052. if (len > 1) {
  2053. var catchInstances = new Array(len - 1),
  2054. j = 0, i;
  2055. for (i = 0; i < len - 1; ++i) {
  2056. var item = arguments[i];
  2057. if (util.isObject(item)) {
  2058. catchInstances[j++] = item;
  2059. } else {
  2060. return apiRejection("Catch statement predicate: " +
  2061. "expecting an object but got " + util.classString(item));
  2062. }
  2063. }
  2064. catchInstances.length = j;
  2065. fn = arguments[i];
  2066. if (typeof fn !== "function") {
  2067. throw new TypeError("The last argument to .catch() " +
  2068. "must be a function, got " + util.toString(fn));
  2069. }
  2070. return this.then(undefined, catchFilter(catchInstances, fn, this));
  2071. }
  2072. return this.then(undefined, fn);
  2073. };
  2074. Promise.prototype.reflect = function () {
  2075. return this._then(reflectHandler,
  2076. reflectHandler, undefined, this, undefined);
  2077. };
  2078. Promise.prototype.then = function (didFulfill, didReject) {
  2079. if (debug.warnings() && arguments.length > 0 &&
  2080. typeof didFulfill !== "function" &&
  2081. typeof didReject !== "function") {
  2082. var msg = ".then() only accepts functions but was passed: " +
  2083. util.classString(didFulfill);
  2084. if (arguments.length > 1) {
  2085. msg += ", " + util.classString(didReject);
  2086. }
  2087. this._warn(msg);
  2088. }
  2089. return this._then(didFulfill, didReject, undefined, undefined, undefined);
  2090. };
  2091. Promise.prototype.done = function (didFulfill, didReject) {
  2092. var promise =
  2093. this._then(didFulfill, didReject, undefined, undefined, undefined);
  2094. promise._setIsFinal();
  2095. };
  2096. Promise.prototype.spread = function (fn) {
  2097. if (typeof fn !== "function") {
  2098. return apiRejection("expecting a function but got " + util.classString(fn));
  2099. }
  2100. return this.all()._then(fn, undefined, undefined, APPLY, undefined);
  2101. };
  2102. Promise.prototype.toJSON = function () {
  2103. var ret = {
  2104. isFulfilled: false,
  2105. isRejected: false,
  2106. fulfillmentValue: undefined,
  2107. rejectionReason: undefined
  2108. };
  2109. if (this.isFulfilled()) {
  2110. ret.fulfillmentValue = this.value();
  2111. ret.isFulfilled = true;
  2112. } else if (this.isRejected()) {
  2113. ret.rejectionReason = this.reason();
  2114. ret.isRejected = true;
  2115. }
  2116. return ret;
  2117. };
  2118. Promise.prototype.all = function () {
  2119. if (arguments.length > 0) {
  2120. this._warn(".all() was passed arguments but it does not take any");
  2121. }
  2122. return new PromiseArray(this).promise();
  2123. };
  2124. Promise.prototype.error = function (fn) {
  2125. return this.caught(util.originatesFromRejection, fn);
  2126. };
  2127. Promise.getNewLibraryCopy = module.exports;
  2128. Promise.is = function (val) {
  2129. return val instanceof Promise;
  2130. };
  2131. Promise.fromNode = Promise.fromCallback = function(fn) {
  2132. var ret = new Promise(INTERNAL);
  2133. ret._captureStackTrace();
  2134. var multiArgs = arguments.length > 1 ? !!Object(arguments[1]).multiArgs
  2135. : false;
  2136. var result = tryCatch(fn)(nodebackForPromise(ret, multiArgs));
  2137. if (result === errorObj) {
  2138. ret._rejectCallback(result.e, true);
  2139. }
  2140. if (!ret._isFateSealed()) ret._setAsyncGuaranteed();
  2141. return ret;
  2142. };
  2143. Promise.all = function (promises) {
  2144. return new PromiseArray(promises).promise();
  2145. };
  2146. Promise.cast = function (obj) {
  2147. var ret = tryConvertToPromise(obj);
  2148. if (!(ret instanceof Promise)) {
  2149. ret = new Promise(INTERNAL);
  2150. ret._captureStackTrace();
  2151. ret._setFulfilled();
  2152. ret._rejectionHandler0 = obj;
  2153. }
  2154. return ret;
  2155. };
  2156. Promise.resolve = Promise.fulfilled = Promise.cast;
  2157. Promise.reject = Promise.rejected = function (reason) {
  2158. var ret = new Promise(INTERNAL);
  2159. ret._captureStackTrace();
  2160. ret._rejectCallback(reason, true);
  2161. return ret;
  2162. };
  2163. Promise.setScheduler = function(fn) {
  2164. if (typeof fn !== "function") {
  2165. throw new TypeError("expecting a function but got " + util.classString(fn));
  2166. }
  2167. return async.setScheduler(fn);
  2168. };
  2169. Promise.prototype._then = function (
  2170. didFulfill,
  2171. didReject,
  2172. _, receiver,
  2173. internalData
  2174. ) {
  2175. var haveInternalData = internalData !== undefined;
  2176. var promise = haveInternalData ? internalData : new Promise(INTERNAL);
  2177. var target = this._target();
  2178. var bitField = target._bitField;
  2179. if (!haveInternalData) {
  2180. promise._propagateFrom(this, 3);
  2181. promise._captureStackTrace();
  2182. if (receiver === undefined &&
  2183. ((this._bitField & 2097152) !== 0)) {
  2184. if (!((bitField & 50397184) === 0)) {
  2185. receiver = this._boundValue();
  2186. } else {
  2187. receiver = target === this ? undefined : this._boundTo;
  2188. }
  2189. }
  2190. this._fireEvent("promiseChained", this, promise);
  2191. }
  2192. var context = getContext();
  2193. if (!((bitField & 50397184) === 0)) {
  2194. var handler, value, settler = target._settlePromiseCtx;
  2195. if (((bitField & 33554432) !== 0)) {
  2196. value = target._rejectionHandler0;
  2197. handler = didFulfill;
  2198. } else if (((bitField & 16777216) !== 0)) {
  2199. value = target._fulfillmentHandler0;
  2200. handler = didReject;
  2201. target._unsetRejectionIsUnhandled();
  2202. } else {
  2203. settler = target._settlePromiseLateCancellationObserver;
  2204. value = new CancellationError("late cancellation observer");
  2205. target._attachExtraTrace(value);
  2206. handler = didReject;
  2207. }
  2208. async.invoke(settler, target, {
  2209. handler: util.contextBind(context, handler),
  2210. promise: promise,
  2211. receiver: receiver,
  2212. value: value
  2213. });
  2214. } else {
  2215. target._addCallbacks(didFulfill, didReject, promise,
  2216. receiver, context);
  2217. }
  2218. return promise;
  2219. };
  2220. Promise.prototype._length = function () {
  2221. return this._bitField & 65535;
  2222. };
  2223. Promise.prototype._isFateSealed = function () {
  2224. return (this._bitField & 117506048) !== 0;
  2225. };
  2226. Promise.prototype._isFollowing = function () {
  2227. return (this._bitField & 67108864) === 67108864;
  2228. };
  2229. Promise.prototype._setLength = function (len) {
  2230. this._bitField = (this._bitField & -65536) |
  2231. (len & 65535);
  2232. };
  2233. Promise.prototype._setFulfilled = function () {
  2234. this._bitField = this._bitField | 33554432;
  2235. this._fireEvent("promiseFulfilled", this);
  2236. };
  2237. Promise.prototype._setRejected = function () {
  2238. this._bitField = this._bitField | 16777216;
  2239. this._fireEvent("promiseRejected", this);
  2240. };
  2241. Promise.prototype._setFollowing = function () {
  2242. this._bitField = this._bitField | 67108864;
  2243. this._fireEvent("promiseResolved", this);
  2244. };
  2245. Promise.prototype._setIsFinal = function () {
  2246. this._bitField = this._bitField | 4194304;
  2247. };
  2248. Promise.prototype._isFinal = function () {
  2249. return (this._bitField & 4194304) > 0;
  2250. };
  2251. Promise.prototype._unsetCancelled = function() {
  2252. this._bitField = this._bitField & (~65536);
  2253. };
  2254. Promise.prototype._setCancelled = function() {
  2255. this._bitField = this._bitField | 65536;
  2256. this._fireEvent("promiseCancelled", this);
  2257. };
  2258. Promise.prototype._setWillBeCancelled = function() {
  2259. this._bitField = this._bitField | 8388608;
  2260. };
  2261. Promise.prototype._setAsyncGuaranteed = function() {
  2262. if (async.hasCustomScheduler()) return;
  2263. var bitField = this._bitField;
  2264. this._bitField = bitField |
  2265. (((bitField & 536870912) >> 2) ^
  2266. 134217728);
  2267. };
  2268. Promise.prototype._setNoAsyncGuarantee = function() {
  2269. this._bitField = (this._bitField | 536870912) &
  2270. (~134217728);
  2271. };
  2272. Promise.prototype._receiverAt = function (index) {
  2273. var ret = index === 0 ? this._receiver0 : this[
  2274. index * 4 - 4 + 3];
  2275. if (ret === UNDEFINED_BINDING) {
  2276. return undefined;
  2277. } else if (ret === undefined && this._isBound()) {
  2278. return this._boundValue();
  2279. }
  2280. return ret;
  2281. };
  2282. Promise.prototype._promiseAt = function (index) {
  2283. return this[
  2284. index * 4 - 4 + 2];
  2285. };
  2286. Promise.prototype._fulfillmentHandlerAt = function (index) {
  2287. return this[
  2288. index * 4 - 4 + 0];
  2289. };
  2290. Promise.prototype._rejectionHandlerAt = function (index) {
  2291. return this[
  2292. index * 4 - 4 + 1];
  2293. };
  2294. Promise.prototype._boundValue = function() {};
  2295. Promise.prototype._migrateCallback0 = function (follower) {
  2296. var bitField = follower._bitField;
  2297. var fulfill = follower._fulfillmentHandler0;
  2298. var reject = follower._rejectionHandler0;
  2299. var promise = follower._promise0;
  2300. var receiver = follower._receiverAt(0);
  2301. if (receiver === undefined) receiver = UNDEFINED_BINDING;
  2302. this._addCallbacks(fulfill, reject, promise, receiver, null);
  2303. };
  2304. Promise.prototype._migrateCallbackAt = function (follower, index) {
  2305. var fulfill = follower._fulfillmentHandlerAt(index);
  2306. var reject = follower._rejectionHandlerAt(index);
  2307. var promise = follower._promiseAt(index);
  2308. var receiver = follower._receiverAt(index);
  2309. if (receiver === undefined) receiver = UNDEFINED_BINDING;
  2310. this._addCallbacks(fulfill, reject, promise, receiver, null);
  2311. };
  2312. Promise.prototype._addCallbacks = function (
  2313. fulfill,
  2314. reject,
  2315. promise,
  2316. receiver,
  2317. context
  2318. ) {
  2319. var index = this._length();
  2320. if (index >= 65535 - 4) {
  2321. index = 0;
  2322. this._setLength(0);
  2323. }
  2324. if (index === 0) {
  2325. this._promise0 = promise;
  2326. this._receiver0 = receiver;
  2327. if (typeof fulfill === "function") {
  2328. this._fulfillmentHandler0 = util.contextBind(context, fulfill);
  2329. }
  2330. if (typeof reject === "function") {
  2331. this._rejectionHandler0 = util.contextBind(context, reject);
  2332. }
  2333. } else {
  2334. var base = index * 4 - 4;
  2335. this[base + 2] = promise;
  2336. this[base + 3] = receiver;
  2337. if (typeof fulfill === "function") {
  2338. this[base + 0] =
  2339. util.contextBind(context, fulfill);
  2340. }
  2341. if (typeof reject === "function") {
  2342. this[base + 1] =
  2343. util.contextBind(context, reject);
  2344. }
  2345. }
  2346. this._setLength(index + 1);
  2347. return index;
  2348. };
  2349. Promise.prototype._proxy = function (proxyable, arg) {
  2350. this._addCallbacks(undefined, undefined, arg, proxyable, null);
  2351. };
  2352. Promise.prototype._resolveCallback = function(value, shouldBind) {
  2353. if (((this._bitField & 117506048) !== 0)) return;
  2354. if (value === this)
  2355. return this._rejectCallback(makeSelfResolutionError(), false);
  2356. var maybePromise = tryConvertToPromise(value, this);
  2357. if (!(maybePromise instanceof Promise)) return this._fulfill(value);
  2358. if (shouldBind) this._propagateFrom(maybePromise, 2);
  2359. var promise = maybePromise._target();
  2360. if (promise === this) {
  2361. this._reject(makeSelfResolutionError());
  2362. return;
  2363. }
  2364. var bitField = promise._bitField;
  2365. if (((bitField & 50397184) === 0)) {
  2366. var len = this._length();
  2367. if (len > 0) promise._migrateCallback0(this);
  2368. for (var i = 1; i < len; ++i) {
  2369. promise._migrateCallbackAt(this, i);
  2370. }
  2371. this._setFollowing();
  2372. this._setLength(0);
  2373. this._setFollowee(maybePromise);
  2374. } else if (((bitField & 33554432) !== 0)) {
  2375. this._fulfill(promise._value());
  2376. } else if (((bitField & 16777216) !== 0)) {
  2377. this._reject(promise._reason());
  2378. } else {
  2379. var reason = new CancellationError("late cancellation observer");
  2380. promise._attachExtraTrace(reason);
  2381. this._reject(reason);
  2382. }
  2383. };
  2384. Promise.prototype._rejectCallback =
  2385. function(reason, synchronous, ignoreNonErrorWarnings) {
  2386. var trace = util.ensureErrorObject(reason);
  2387. var hasStack = trace === reason;
  2388. if (!hasStack && !ignoreNonErrorWarnings && debug.warnings()) {
  2389. var message = "a promise was rejected with a non-error: " +
  2390. util.classString(reason);
  2391. this._warn(message, true);
  2392. }
  2393. this._attachExtraTrace(trace, synchronous ? hasStack : false);
  2394. this._reject(reason);
  2395. };
  2396. Promise.prototype._resolveFromExecutor = function (executor) {
  2397. if (executor === INTERNAL) return;
  2398. var promise = this;
  2399. this._captureStackTrace();
  2400. this._pushContext();
  2401. var synchronous = true;
  2402. var r = this._execute(executor, function(value) {
  2403. promise._resolveCallback(value);
  2404. }, function (reason) {
  2405. promise._rejectCallback(reason, synchronous);
  2406. });
  2407. synchronous = false;
  2408. this._popContext();
  2409. if (r !== undefined) {
  2410. promise._rejectCallback(r, true);
  2411. }
  2412. };
  2413. Promise.prototype._settlePromiseFromHandler = function (
  2414. handler, receiver, value, promise
  2415. ) {
  2416. var bitField = promise._bitField;
  2417. if (((bitField & 65536) !== 0)) return;
  2418. promise._pushContext();
  2419. var x;
  2420. if (receiver === APPLY) {
  2421. if (!value || typeof value.length !== "number") {
  2422. x = errorObj;
  2423. x.e = new TypeError("cannot .spread() a non-array: " +
  2424. util.classString(value));
  2425. } else {
  2426. x = tryCatch(handler).apply(this._boundValue(), value);
  2427. }
  2428. } else {
  2429. x = tryCatch(handler).call(receiver, value);
  2430. }
  2431. var promiseCreated = promise._popContext();
  2432. bitField = promise._bitField;
  2433. if (((bitField & 65536) !== 0)) return;
  2434. if (x === NEXT_FILTER) {
  2435. promise._reject(value);
  2436. } else if (x === errorObj) {
  2437. promise._rejectCallback(x.e, false);
  2438. } else {
  2439. debug.checkForgottenReturns(x, promiseCreated, "", promise, this);
  2440. promise._resolveCallback(x);
  2441. }
  2442. };
  2443. Promise.prototype._target = function() {
  2444. var ret = this;
  2445. while (ret._isFollowing()) ret = ret._followee();
  2446. return ret;
  2447. };
  2448. Promise.prototype._followee = function() {
  2449. return this._rejectionHandler0;
  2450. };
  2451. Promise.prototype._setFollowee = function(promise) {
  2452. this._rejectionHandler0 = promise;
  2453. };
  2454. Promise.prototype._settlePromise = function(promise, handler, receiver, value) {
  2455. var isPromise = promise instanceof Promise;
  2456. var bitField = this._bitField;
  2457. var asyncGuaranteed = ((bitField & 134217728) !== 0);
  2458. if (((bitField & 65536) !== 0)) {
  2459. if (isPromise) promise._invokeInternalOnCancel();
  2460. if (receiver instanceof PassThroughHandlerContext &&
  2461. receiver.isFinallyHandler()) {
  2462. receiver.cancelPromise = promise;
  2463. if (tryCatch(handler).call(receiver, value) === errorObj) {
  2464. promise._reject(errorObj.e);
  2465. }
  2466. } else if (handler === reflectHandler) {
  2467. promise._fulfill(reflectHandler.call(receiver));
  2468. } else if (receiver instanceof Proxyable) {
  2469. receiver._promiseCancelled(promise);
  2470. } else if (isPromise || promise instanceof PromiseArray) {
  2471. promise._cancel();
  2472. } else {
  2473. receiver.cancel();
  2474. }
  2475. } else if (typeof handler === "function") {
  2476. if (!isPromise) {
  2477. handler.call(receiver, value, promise);
  2478. } else {
  2479. if (asyncGuaranteed) promise._setAsyncGuaranteed();
  2480. this._settlePromiseFromHandler(handler, receiver, value, promise);
  2481. }
  2482. } else if (receiver instanceof Proxyable) {
  2483. if (!receiver._isResolved()) {
  2484. if (((bitField & 33554432) !== 0)) {
  2485. receiver._promiseFulfilled(value, promise);
  2486. } else {
  2487. receiver._promiseRejected(value, promise);
  2488. }
  2489. }
  2490. } else if (isPromise) {
  2491. if (asyncGuaranteed) promise._setAsyncGuaranteed();
  2492. if (((bitField & 33554432) !== 0)) {
  2493. promise._fulfill(value);
  2494. } else {
  2495. promise._reject(value);
  2496. }
  2497. }
  2498. };
  2499. Promise.prototype._settlePromiseLateCancellationObserver = function(ctx) {
  2500. var handler = ctx.handler;
  2501. var promise = ctx.promise;
  2502. var receiver = ctx.receiver;
  2503. var value = ctx.value;
  2504. if (typeof handler === "function") {
  2505. if (!(promise instanceof Promise)) {
  2506. handler.call(receiver, value, promise);
  2507. } else {
  2508. this._settlePromiseFromHandler(handler, receiver, value, promise);
  2509. }
  2510. } else if (promise instanceof Promise) {
  2511. promise._reject(value);
  2512. }
  2513. };
  2514. Promise.prototype._settlePromiseCtx = function(ctx) {
  2515. this._settlePromise(ctx.promise, ctx.handler, ctx.receiver, ctx.value);
  2516. };
  2517. Promise.prototype._settlePromise0 = function(handler, value, bitField) {
  2518. var promise = this._promise0;
  2519. var receiver = this._receiverAt(0);
  2520. this._promise0 = undefined;
  2521. this._receiver0 = undefined;
  2522. this._settlePromise(promise, handler, receiver, value);
  2523. };
  2524. Promise.prototype._clearCallbackDataAtIndex = function(index) {
  2525. var base = index * 4 - 4;
  2526. this[base + 2] =
  2527. this[base + 3] =
  2528. this[base + 0] =
  2529. this[base + 1] = undefined;
  2530. };
  2531. Promise.prototype._fulfill = function (value) {
  2532. var bitField = this._bitField;
  2533. if (((bitField & 117506048) >>> 16)) return;
  2534. if (value === this) {
  2535. var err = makeSelfResolutionError();
  2536. this._attachExtraTrace(err);
  2537. return this._reject(err);
  2538. }
  2539. this._setFulfilled();
  2540. this._rejectionHandler0 = value;
  2541. if ((bitField & 65535) > 0) {
  2542. if (((bitField & 134217728) !== 0)) {
  2543. this._settlePromises();
  2544. } else {
  2545. async.settlePromises(this);
  2546. }
  2547. this._dereferenceTrace();
  2548. }
  2549. };
  2550. Promise.prototype._reject = function (reason) {
  2551. var bitField = this._bitField;
  2552. if (((bitField & 117506048) >>> 16)) return;
  2553. this._setRejected();
  2554. this._fulfillmentHandler0 = reason;
  2555. if (this._isFinal()) {
  2556. return async.fatalError(reason, util.isNode);
  2557. }
  2558. if ((bitField & 65535) > 0) {
  2559. async.settlePromises(this);
  2560. } else {
  2561. this._ensurePossibleRejectionHandled();
  2562. }
  2563. };
  2564. Promise.prototype._fulfillPromises = function (len, value) {
  2565. for (var i = 1; i < len; i++) {
  2566. var handler = this._fulfillmentHandlerAt(i);
  2567. var promise = this._promiseAt(i);
  2568. var receiver = this._receiverAt(i);
  2569. this._clearCallbackDataAtIndex(i);
  2570. this._settlePromise(promise, handler, receiver, value);
  2571. }
  2572. };
  2573. Promise.prototype._rejectPromises = function (len, reason) {
  2574. for (var i = 1; i < len; i++) {
  2575. var handler = this._rejectionHandlerAt(i);
  2576. var promise = this._promiseAt(i);
  2577. var receiver = this._receiverAt(i);
  2578. this._clearCallbackDataAtIndex(i);
  2579. this._settlePromise(promise, handler, receiver, reason);
  2580. }
  2581. };
  2582. Promise.prototype._settlePromises = function () {
  2583. var bitField = this._bitField;
  2584. var len = (bitField & 65535);
  2585. if (len > 0) {
  2586. if (((bitField & 16842752) !== 0)) {
  2587. var reason = this._fulfillmentHandler0;
  2588. this._settlePromise0(this._rejectionHandler0, reason, bitField);
  2589. this._rejectPromises(len, reason);
  2590. } else {
  2591. var value = this._rejectionHandler0;
  2592. this._settlePromise0(this._fulfillmentHandler0, value, bitField);
  2593. this._fulfillPromises(len, value);
  2594. }
  2595. this._setLength(0);
  2596. }
  2597. this._clearCancellationData();
  2598. };
  2599. Promise.prototype._settledValue = function() {
  2600. var bitField = this._bitField;
  2601. if (((bitField & 33554432) !== 0)) {
  2602. return this._rejectionHandler0;
  2603. } else if (((bitField & 16777216) !== 0)) {
  2604. return this._fulfillmentHandler0;
  2605. }
  2606. };
  2607. if (typeof Symbol !== "undefined" && Symbol.toStringTag) {
  2608. es5.defineProperty(Promise.prototype, Symbol.toStringTag, {
  2609. get: function () {
  2610. return "Object";
  2611. }
  2612. });
  2613. }
  2614. function deferResolve(v) {this.promise._resolveCallback(v);}
  2615. function deferReject(v) {this.promise._rejectCallback(v, false);}
  2616. Promise.defer = Promise.pending = function() {
  2617. debug.deprecated("Promise.defer", "new Promise");
  2618. var promise = new Promise(INTERNAL);
  2619. return {
  2620. promise: promise,
  2621. resolve: deferResolve,
  2622. reject: deferReject
  2623. };
  2624. };
  2625. util.notEnumerableProp(Promise,
  2626. "_makeSelfResolutionError",
  2627. makeSelfResolutionError);
  2628. _dereq_("./method")(Promise, INTERNAL, tryConvertToPromise, apiRejection,
  2629. debug);
  2630. _dereq_("./bind")(Promise, INTERNAL, tryConvertToPromise, debug);
  2631. _dereq_("./cancel")(Promise, PromiseArray, apiRejection, debug);
  2632. _dereq_("./direct_resolve")(Promise);
  2633. _dereq_("./synchronous_inspection")(Promise);
  2634. _dereq_("./join")(
  2635. Promise, PromiseArray, tryConvertToPromise, INTERNAL, async);
  2636. Promise.Promise = Promise;
  2637. Promise.version = "3.7.2";
  2638. util.toFastProperties(Promise);
  2639. util.toFastProperties(Promise.prototype);
  2640. function fillTypes(value) {
  2641. var p = new Promise(INTERNAL);
  2642. p._fulfillmentHandler0 = value;
  2643. p._rejectionHandler0 = value;
  2644. p._promise0 = value;
  2645. p._receiver0 = value;
  2646. }
  2647. // Complete slack tracking, opt out of field-type tracking and
  2648. // stabilize map
  2649. fillTypes({a: 1});
  2650. fillTypes({b: 2});
  2651. fillTypes({c: 3});
  2652. fillTypes(1);
  2653. fillTypes(function(){});
  2654. fillTypes(undefined);
  2655. fillTypes(false);
  2656. fillTypes(new Promise(INTERNAL));
  2657. debug.setBounds(Async.firstLineError, util.lastLineError);
  2658. return Promise;
  2659. };
  2660. },{"./async":1,"./bind":2,"./cancel":4,"./catch_filter":5,"./context":6,"./debuggability":7,"./direct_resolve":8,"./errors":9,"./es5":10,"./finally":11,"./join":12,"./method":13,"./nodeback":14,"./promise_array":16,"./synchronous_inspection":19,"./thenables":20,"./util":21,"async_hooks":undefined}],16:[function(_dereq_,module,exports){
  2661. "use strict";
  2662. module.exports = function(Promise, INTERNAL, tryConvertToPromise,
  2663. apiRejection, Proxyable) {
  2664. var util = _dereq_("./util");
  2665. var isArray = util.isArray;
  2666. function toResolutionValue(val) {
  2667. switch(val) {
  2668. case -2: return [];
  2669. case -3: return {};
  2670. case -6: return new Map();
  2671. }
  2672. }
  2673. function PromiseArray(values) {
  2674. var promise = this._promise = new Promise(INTERNAL);
  2675. if (values instanceof Promise) {
  2676. promise._propagateFrom(values, 3);
  2677. values.suppressUnhandledRejections();
  2678. }
  2679. promise._setOnCancel(this);
  2680. this._values = values;
  2681. this._length = 0;
  2682. this._totalResolved = 0;
  2683. this._init(undefined, -2);
  2684. }
  2685. util.inherits(PromiseArray, Proxyable);
  2686. PromiseArray.prototype.length = function () {
  2687. return this._length;
  2688. };
  2689. PromiseArray.prototype.promise = function () {
  2690. return this._promise;
  2691. };
  2692. PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
  2693. var values = tryConvertToPromise(this._values, this._promise);
  2694. if (values instanceof Promise) {
  2695. values = values._target();
  2696. var bitField = values._bitField;
  2697. ;
  2698. this._values = values;
  2699. if (((bitField & 50397184) === 0)) {
  2700. this._promise._setAsyncGuaranteed();
  2701. return values._then(
  2702. init,
  2703. this._reject,
  2704. undefined,
  2705. this,
  2706. resolveValueIfEmpty
  2707. );
  2708. } else if (((bitField & 33554432) !== 0)) {
  2709. values = values._value();
  2710. } else if (((bitField & 16777216) !== 0)) {
  2711. return this._reject(values._reason());
  2712. } else {
  2713. return this._cancel();
  2714. }
  2715. }
  2716. values = util.asArray(values);
  2717. if (values === null) {
  2718. var err = apiRejection(
  2719. "expecting an array or an iterable object but got " + util.classString(values)).reason();
  2720. this._promise._rejectCallback(err, false);
  2721. return;
  2722. }
  2723. if (values.length === 0) {
  2724. if (resolveValueIfEmpty === -5) {
  2725. this._resolveEmptyArray();
  2726. }
  2727. else {
  2728. this._resolve(toResolutionValue(resolveValueIfEmpty));
  2729. }
  2730. return;
  2731. }
  2732. this._iterate(values);
  2733. };
  2734. PromiseArray.prototype._iterate = function(values) {
  2735. var len = this.getActualLength(values.length);
  2736. this._length = len;
  2737. this._values = this.shouldCopyValues() ? new Array(len) : this._values;
  2738. var result = this._promise;
  2739. var isResolved = false;
  2740. var bitField = null;
  2741. for (var i = 0; i < len; ++i) {
  2742. var maybePromise = tryConvertToPromise(values[i], result);
  2743. if (maybePromise instanceof Promise) {
  2744. maybePromise = maybePromise._target();
  2745. bitField = maybePromise._bitField;
  2746. } else {
  2747. bitField = null;
  2748. }
  2749. if (isResolved) {
  2750. if (bitField !== null) {
  2751. maybePromise.suppressUnhandledRejections();
  2752. }
  2753. } else if (bitField !== null) {
  2754. if (((bitField & 50397184) === 0)) {
  2755. maybePromise._proxy(this, i);
  2756. this._values[i] = maybePromise;
  2757. } else if (((bitField & 33554432) !== 0)) {
  2758. isResolved = this._promiseFulfilled(maybePromise._value(), i);
  2759. } else if (((bitField & 16777216) !== 0)) {
  2760. isResolved = this._promiseRejected(maybePromise._reason(), i);
  2761. } else {
  2762. isResolved = this._promiseCancelled(i);
  2763. }
  2764. } else {
  2765. isResolved = this._promiseFulfilled(maybePromise, i);
  2766. }
  2767. }
  2768. if (!isResolved) result._setAsyncGuaranteed();
  2769. };
  2770. PromiseArray.prototype._isResolved = function () {
  2771. return this._values === null;
  2772. };
  2773. PromiseArray.prototype._resolve = function (value) {
  2774. this._values = null;
  2775. this._promise._fulfill(value);
  2776. };
  2777. PromiseArray.prototype._cancel = function() {
  2778. if (this._isResolved() || !this._promise._isCancellable()) return;
  2779. this._values = null;
  2780. this._promise._cancel();
  2781. };
  2782. PromiseArray.prototype._reject = function (reason) {
  2783. this._values = null;
  2784. this._promise._rejectCallback(reason, false);
  2785. };
  2786. PromiseArray.prototype._promiseFulfilled = function (value, index) {
  2787. this._values[index] = value;
  2788. var totalResolved = ++this._totalResolved;
  2789. if (totalResolved >= this._length) {
  2790. this._resolve(this._values);
  2791. return true;
  2792. }
  2793. return false;
  2794. };
  2795. PromiseArray.prototype._promiseCancelled = function() {
  2796. this._cancel();
  2797. return true;
  2798. };
  2799. PromiseArray.prototype._promiseRejected = function (reason) {
  2800. this._totalResolved++;
  2801. this._reject(reason);
  2802. return true;
  2803. };
  2804. PromiseArray.prototype._resultCancelled = function() {
  2805. if (this._isResolved()) return;
  2806. var values = this._values;
  2807. this._cancel();
  2808. if (values instanceof Promise) {
  2809. values.cancel();
  2810. } else {
  2811. for (var i = 0; i < values.length; ++i) {
  2812. if (values[i] instanceof Promise) {
  2813. values[i].cancel();
  2814. }
  2815. }
  2816. }
  2817. };
  2818. PromiseArray.prototype.shouldCopyValues = function () {
  2819. return true;
  2820. };
  2821. PromiseArray.prototype.getActualLength = function (len) {
  2822. return len;
  2823. };
  2824. return PromiseArray;
  2825. };
  2826. },{"./util":21}],17:[function(_dereq_,module,exports){
  2827. "use strict";
  2828. function arrayMove(src, srcIndex, dst, dstIndex, len) {
  2829. for (var j = 0; j < len; ++j) {
  2830. dst[j + dstIndex] = src[j + srcIndex];
  2831. src[j + srcIndex] = void 0;
  2832. }
  2833. }
  2834. function Queue(capacity) {
  2835. this._capacity = capacity;
  2836. this._length = 0;
  2837. this._front = 0;
  2838. }
  2839. Queue.prototype._willBeOverCapacity = function (size) {
  2840. return this._capacity < size;
  2841. };
  2842. Queue.prototype._pushOne = function (arg) {
  2843. var length = this.length();
  2844. this._checkCapacity(length + 1);
  2845. var i = (this._front + length) & (this._capacity - 1);
  2846. this[i] = arg;
  2847. this._length = length + 1;
  2848. };
  2849. Queue.prototype.push = function (fn, receiver, arg) {
  2850. var length = this.length() + 3;
  2851. if (this._willBeOverCapacity(length)) {
  2852. this._pushOne(fn);
  2853. this._pushOne(receiver);
  2854. this._pushOne(arg);
  2855. return;
  2856. }
  2857. var j = this._front + length - 3;
  2858. this._checkCapacity(length);
  2859. var wrapMask = this._capacity - 1;
  2860. this[(j + 0) & wrapMask] = fn;
  2861. this[(j + 1) & wrapMask] = receiver;
  2862. this[(j + 2) & wrapMask] = arg;
  2863. this._length = length;
  2864. };
  2865. Queue.prototype.shift = function () {
  2866. var front = this._front,
  2867. ret = this[front];
  2868. this[front] = undefined;
  2869. this._front = (front + 1) & (this._capacity - 1);
  2870. this._length--;
  2871. return ret;
  2872. };
  2873. Queue.prototype.length = function () {
  2874. return this._length;
  2875. };
  2876. Queue.prototype._checkCapacity = function (size) {
  2877. if (this._capacity < size) {
  2878. this._resizeTo(this._capacity << 1);
  2879. }
  2880. };
  2881. Queue.prototype._resizeTo = function (capacity) {
  2882. var oldCapacity = this._capacity;
  2883. this._capacity = capacity;
  2884. var front = this._front;
  2885. var length = this._length;
  2886. var moveItemsCount = (front + length) & (oldCapacity - 1);
  2887. arrayMove(this, 0, this, oldCapacity, moveItemsCount);
  2888. };
  2889. module.exports = Queue;
  2890. },{}],18:[function(_dereq_,module,exports){
  2891. "use strict";
  2892. var util = _dereq_("./util");
  2893. var schedule;
  2894. var noAsyncScheduler = function() {
  2895. throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  2896. };
  2897. var NativePromise = util.getNativePromise();
  2898. if (util.isNode && typeof MutationObserver === "undefined") {
  2899. var GlobalSetImmediate = global.setImmediate;
  2900. var ProcessNextTick = process.nextTick;
  2901. schedule = util.isRecentNode
  2902. ? function(fn) { GlobalSetImmediate.call(global, fn); }
  2903. : function(fn) { ProcessNextTick.call(process, fn); };
  2904. } else if (typeof NativePromise === "function" &&
  2905. typeof NativePromise.resolve === "function") {
  2906. var nativePromise = NativePromise.resolve();
  2907. schedule = function(fn) {
  2908. nativePromise.then(fn);
  2909. };
  2910. } else if ((typeof MutationObserver !== "undefined") &&
  2911. !(typeof window !== "undefined" &&
  2912. window.navigator &&
  2913. (window.navigator.standalone || window.cordova)) &&
  2914. ("classList" in document.documentElement)) {
  2915. schedule = (function() {
  2916. var div = document.createElement("div");
  2917. var opts = {attributes: true};
  2918. var toggleScheduled = false;
  2919. var div2 = document.createElement("div");
  2920. var o2 = new MutationObserver(function() {
  2921. div.classList.toggle("foo");
  2922. toggleScheduled = false;
  2923. });
  2924. o2.observe(div2, opts);
  2925. var scheduleToggle = function() {
  2926. if (toggleScheduled) return;
  2927. toggleScheduled = true;
  2928. div2.classList.toggle("foo");
  2929. };
  2930. return function schedule(fn) {
  2931. var o = new MutationObserver(function() {
  2932. o.disconnect();
  2933. fn();
  2934. });
  2935. o.observe(div, opts);
  2936. scheduleToggle();
  2937. };
  2938. })();
  2939. } else if (typeof setImmediate !== "undefined") {
  2940. schedule = function (fn) {
  2941. setImmediate(fn);
  2942. };
  2943. } else if (typeof setTimeout !== "undefined") {
  2944. schedule = function (fn) {
  2945. setTimeout(fn, 0);
  2946. };
  2947. } else {
  2948. schedule = noAsyncScheduler;
  2949. }
  2950. module.exports = schedule;
  2951. },{"./util":21}],19:[function(_dereq_,module,exports){
  2952. "use strict";
  2953. module.exports = function(Promise) {
  2954. function PromiseInspection(promise) {
  2955. if (promise !== undefined) {
  2956. promise = promise._target();
  2957. this._bitField = promise._bitField;
  2958. this._settledValueField = promise._isFateSealed()
  2959. ? promise._settledValue() : undefined;
  2960. }
  2961. else {
  2962. this._bitField = 0;
  2963. this._settledValueField = undefined;
  2964. }
  2965. }
  2966. PromiseInspection.prototype._settledValue = function() {
  2967. return this._settledValueField;
  2968. };
  2969. var value = PromiseInspection.prototype.value = function () {
  2970. if (!this.isFulfilled()) {
  2971. throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  2972. }
  2973. return this._settledValue();
  2974. };
  2975. var reason = PromiseInspection.prototype.error =
  2976. PromiseInspection.prototype.reason = function () {
  2977. if (!this.isRejected()) {
  2978. throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  2979. }
  2980. return this._settledValue();
  2981. };
  2982. var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
  2983. return (this._bitField & 33554432) !== 0;
  2984. };
  2985. var isRejected = PromiseInspection.prototype.isRejected = function () {
  2986. return (this._bitField & 16777216) !== 0;
  2987. };
  2988. var isPending = PromiseInspection.prototype.isPending = function () {
  2989. return (this._bitField & 50397184) === 0;
  2990. };
  2991. var isResolved = PromiseInspection.prototype.isResolved = function () {
  2992. return (this._bitField & 50331648) !== 0;
  2993. };
  2994. PromiseInspection.prototype.isCancelled = function() {
  2995. return (this._bitField & 8454144) !== 0;
  2996. };
  2997. Promise.prototype.__isCancelled = function() {
  2998. return (this._bitField & 65536) === 65536;
  2999. };
  3000. Promise.prototype._isCancelled = function() {
  3001. return this._target().__isCancelled();
  3002. };
  3003. Promise.prototype.isCancelled = function() {
  3004. return (this._target()._bitField & 8454144) !== 0;
  3005. };
  3006. Promise.prototype.isPending = function() {
  3007. return isPending.call(this._target());
  3008. };
  3009. Promise.prototype.isRejected = function() {
  3010. return isRejected.call(this._target());
  3011. };
  3012. Promise.prototype.isFulfilled = function() {
  3013. return isFulfilled.call(this._target());
  3014. };
  3015. Promise.prototype.isResolved = function() {
  3016. return isResolved.call(this._target());
  3017. };
  3018. Promise.prototype.value = function() {
  3019. return value.call(this._target());
  3020. };
  3021. Promise.prototype.reason = function() {
  3022. var target = this._target();
  3023. target._unsetRejectionIsUnhandled();
  3024. return reason.call(target);
  3025. };
  3026. Promise.prototype._value = function() {
  3027. return this._settledValue();
  3028. };
  3029. Promise.prototype._reason = function() {
  3030. this._unsetRejectionIsUnhandled();
  3031. return this._settledValue();
  3032. };
  3033. Promise.PromiseInspection = PromiseInspection;
  3034. };
  3035. },{}],20:[function(_dereq_,module,exports){
  3036. "use strict";
  3037. module.exports = function(Promise, INTERNAL) {
  3038. var util = _dereq_("./util");
  3039. var errorObj = util.errorObj;
  3040. var isObject = util.isObject;
  3041. function tryConvertToPromise(obj, context) {
  3042. if (isObject(obj)) {
  3043. if (obj instanceof Promise) return obj;
  3044. var then = getThen(obj);
  3045. if (then === errorObj) {
  3046. if (context) context._pushContext();
  3047. var ret = Promise.reject(then.e);
  3048. if (context) context._popContext();
  3049. return ret;
  3050. } else if (typeof then === "function") {
  3051. if (isAnyBluebirdPromise(obj)) {
  3052. var ret = new Promise(INTERNAL);
  3053. obj._then(
  3054. ret._fulfill,
  3055. ret._reject,
  3056. undefined,
  3057. ret,
  3058. null
  3059. );
  3060. return ret;
  3061. }
  3062. return doThenable(obj, then, context);
  3063. }
  3064. }
  3065. return obj;
  3066. }
  3067. function doGetThen(obj) {
  3068. return obj.then;
  3069. }
  3070. function getThen(obj) {
  3071. try {
  3072. return doGetThen(obj);
  3073. } catch (e) {
  3074. errorObj.e = e;
  3075. return errorObj;
  3076. }
  3077. }
  3078. var hasProp = {}.hasOwnProperty;
  3079. function isAnyBluebirdPromise(obj) {
  3080. try {
  3081. return hasProp.call(obj, "_promise0");
  3082. } catch (e) {
  3083. return false;
  3084. }
  3085. }
  3086. function doThenable(x, then, context) {
  3087. var promise = new Promise(INTERNAL);
  3088. var ret = promise;
  3089. if (context) context._pushContext();
  3090. promise._captureStackTrace();
  3091. if (context) context._popContext();
  3092. var synchronous = true;
  3093. var result = util.tryCatch(then).call(x, resolve, reject);
  3094. synchronous = false;
  3095. if (promise && result === errorObj) {
  3096. promise._rejectCallback(result.e, true, true);
  3097. promise = null;
  3098. }
  3099. function resolve(value) {
  3100. if (!promise) return;
  3101. promise._resolveCallback(value);
  3102. promise = null;
  3103. }
  3104. function reject(reason) {
  3105. if (!promise) return;
  3106. promise._rejectCallback(reason, synchronous, true);
  3107. promise = null;
  3108. }
  3109. return ret;
  3110. }
  3111. return tryConvertToPromise;
  3112. };
  3113. },{"./util":21}],21:[function(_dereq_,module,exports){
  3114. "use strict";
  3115. var es5 = _dereq_("./es5");
  3116. var canEvaluate = typeof navigator == "undefined";
  3117. var errorObj = {e: {}};
  3118. var tryCatchTarget;
  3119. var globalObject = typeof self !== "undefined" ? self :
  3120. typeof window !== "undefined" ? window :
  3121. typeof global !== "undefined" ? global :
  3122. this !== undefined ? this : null;
  3123. function tryCatcher() {
  3124. try {
  3125. var target = tryCatchTarget;
  3126. tryCatchTarget = null;
  3127. return target.apply(this, arguments);
  3128. } catch (e) {
  3129. errorObj.e = e;
  3130. return errorObj;
  3131. }
  3132. }
  3133. function tryCatch(fn) {
  3134. tryCatchTarget = fn;
  3135. return tryCatcher;
  3136. }
  3137. var inherits = function(Child, Parent) {
  3138. var hasProp = {}.hasOwnProperty;
  3139. function T() {
  3140. this.constructor = Child;
  3141. this.constructor$ = Parent;
  3142. for (var propertyName in Parent.prototype) {
  3143. if (hasProp.call(Parent.prototype, propertyName) &&
  3144. propertyName.charAt(propertyName.length-1) !== "$"
  3145. ) {
  3146. this[propertyName + "$"] = Parent.prototype[propertyName];
  3147. }
  3148. }
  3149. }
  3150. T.prototype = Parent.prototype;
  3151. Child.prototype = new T();
  3152. return Child.prototype;
  3153. };
  3154. function isPrimitive(val) {
  3155. return val == null || val === true || val === false ||
  3156. typeof val === "string" || typeof val === "number";
  3157. }
  3158. function isObject(value) {
  3159. return typeof value === "function" ||
  3160. typeof value === "object" && value !== null;
  3161. }
  3162. function maybeWrapAsError(maybeError) {
  3163. if (!isPrimitive(maybeError)) return maybeError;
  3164. return new Error(safeToString(maybeError));
  3165. }
  3166. function withAppended(target, appendee) {
  3167. var len = target.length;
  3168. var ret = new Array(len + 1);
  3169. var i;
  3170. for (i = 0; i < len; ++i) {
  3171. ret[i] = target[i];
  3172. }
  3173. ret[i] = appendee;
  3174. return ret;
  3175. }
  3176. function getDataPropertyOrDefault(obj, key, defaultValue) {
  3177. if (es5.isES5) {
  3178. var desc = Object.getOwnPropertyDescriptor(obj, key);
  3179. if (desc != null) {
  3180. return desc.get == null && desc.set == null
  3181. ? desc.value
  3182. : defaultValue;
  3183. }
  3184. } else {
  3185. return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
  3186. }
  3187. }
  3188. function notEnumerableProp(obj, name, value) {
  3189. if (isPrimitive(obj)) return obj;
  3190. var descriptor = {
  3191. value: value,
  3192. configurable: true,
  3193. enumerable: false,
  3194. writable: true
  3195. };
  3196. es5.defineProperty(obj, name, descriptor);
  3197. return obj;
  3198. }
  3199. function thrower(r) {
  3200. throw r;
  3201. }
  3202. var inheritedDataKeys = (function() {
  3203. var excludedPrototypes = [
  3204. Array.prototype,
  3205. Object.prototype,
  3206. Function.prototype
  3207. ];
  3208. var isExcludedProto = function(val) {
  3209. for (var i = 0; i < excludedPrototypes.length; ++i) {
  3210. if (excludedPrototypes[i] === val) {
  3211. return true;
  3212. }
  3213. }
  3214. return false;
  3215. };
  3216. if (es5.isES5) {
  3217. var getKeys = Object.getOwnPropertyNames;
  3218. return function(obj) {
  3219. var ret = [];
  3220. var visitedKeys = Object.create(null);
  3221. while (obj != null && !isExcludedProto(obj)) {
  3222. var keys;
  3223. try {
  3224. keys = getKeys(obj);
  3225. } catch (e) {
  3226. return ret;
  3227. }
  3228. for (var i = 0; i < keys.length; ++i) {
  3229. var key = keys[i];
  3230. if (visitedKeys[key]) continue;
  3231. visitedKeys[key] = true;
  3232. var desc = Object.getOwnPropertyDescriptor(obj, key);
  3233. if (desc != null && desc.get == null && desc.set == null) {
  3234. ret.push(key);
  3235. }
  3236. }
  3237. obj = es5.getPrototypeOf(obj);
  3238. }
  3239. return ret;
  3240. };
  3241. } else {
  3242. var hasProp = {}.hasOwnProperty;
  3243. return function(obj) {
  3244. if (isExcludedProto(obj)) return [];
  3245. var ret = [];
  3246. /*jshint forin:false */
  3247. enumeration: for (var key in obj) {
  3248. if (hasProp.call(obj, key)) {
  3249. ret.push(key);
  3250. } else {
  3251. for (var i = 0; i < excludedPrototypes.length; ++i) {
  3252. if (hasProp.call(excludedPrototypes[i], key)) {
  3253. continue enumeration;
  3254. }
  3255. }
  3256. ret.push(key);
  3257. }
  3258. }
  3259. return ret;
  3260. };
  3261. }
  3262. })();
  3263. var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/;
  3264. function isClass(fn) {
  3265. try {
  3266. if (typeof fn === "function") {
  3267. var keys = es5.names(fn.prototype);
  3268. var hasMethods = es5.isES5 && keys.length > 1;
  3269. var hasMethodsOtherThanConstructor = keys.length > 0 &&
  3270. !(keys.length === 1 && keys[0] === "constructor");
  3271. var hasThisAssignmentAndStaticMethods =
  3272. thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0;
  3273. if (hasMethods || hasMethodsOtherThanConstructor ||
  3274. hasThisAssignmentAndStaticMethods) {
  3275. return true;
  3276. }
  3277. }
  3278. return false;
  3279. } catch (e) {
  3280. return false;
  3281. }
  3282. }
  3283. function toFastProperties(obj) {
  3284. /*jshint -W027,-W055,-W031*/
  3285. function FakeConstructor() {}
  3286. FakeConstructor.prototype = obj;
  3287. var receiver = new FakeConstructor();
  3288. function ic() {
  3289. return typeof receiver.foo;
  3290. }
  3291. ic();
  3292. ic();
  3293. return obj;
  3294. eval(obj);
  3295. }
  3296. var rident = /^[a-z$_][a-z$_0-9]*$/i;
  3297. function isIdentifier(str) {
  3298. return rident.test(str);
  3299. }
  3300. function filledRange(count, prefix, suffix) {
  3301. var ret = new Array(count);
  3302. for(var i = 0; i < count; ++i) {
  3303. ret[i] = prefix + i + suffix;
  3304. }
  3305. return ret;
  3306. }
  3307. function safeToString(obj) {
  3308. try {
  3309. return obj + "";
  3310. } catch (e) {
  3311. return "[no string representation]";
  3312. }
  3313. }
  3314. function isError(obj) {
  3315. return obj instanceof Error ||
  3316. (obj !== null &&
  3317. typeof obj === "object" &&
  3318. typeof obj.message === "string" &&
  3319. typeof obj.name === "string");
  3320. }
  3321. function markAsOriginatingFromRejection(e) {
  3322. try {
  3323. notEnumerableProp(e, "isOperational", true);
  3324. }
  3325. catch(ignore) {}
  3326. }
  3327. function originatesFromRejection(e) {
  3328. if (e == null) return false;
  3329. return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) ||
  3330. e["isOperational"] === true);
  3331. }
  3332. function canAttachTrace(obj) {
  3333. return isError(obj) && es5.propertyIsWritable(obj, "stack");
  3334. }
  3335. var ensureErrorObject = (function() {
  3336. if (!("stack" in new Error())) {
  3337. return function(value) {
  3338. if (canAttachTrace(value)) return value;
  3339. try {throw new Error(safeToString(value));}
  3340. catch(err) {return err;}
  3341. };
  3342. } else {
  3343. return function(value) {
  3344. if (canAttachTrace(value)) return value;
  3345. return new Error(safeToString(value));
  3346. };
  3347. }
  3348. })();
  3349. function classString(obj) {
  3350. return {}.toString.call(obj);
  3351. }
  3352. function copyDescriptors(from, to, filter) {
  3353. var keys = es5.names(from);
  3354. for (var i = 0; i < keys.length; ++i) {
  3355. var key = keys[i];
  3356. if (filter(key)) {
  3357. try {
  3358. es5.defineProperty(to, key, es5.getDescriptor(from, key));
  3359. } catch (ignore) {}
  3360. }
  3361. }
  3362. }
  3363. var asArray = function(v) {
  3364. if (es5.isArray(v)) {
  3365. return v;
  3366. }
  3367. return null;
  3368. };
  3369. if (typeof Symbol !== "undefined" && Symbol.iterator) {
  3370. var ArrayFrom = typeof Array.from === "function" ? function(v) {
  3371. return Array.from(v);
  3372. } : function(v) {
  3373. var ret = [];
  3374. var it = v[Symbol.iterator]();
  3375. var itResult;
  3376. while (!((itResult = it.next()).done)) {
  3377. ret.push(itResult.value);
  3378. }
  3379. return ret;
  3380. };
  3381. asArray = function(v) {
  3382. if (es5.isArray(v)) {
  3383. return v;
  3384. } else if (v != null && typeof v[Symbol.iterator] === "function") {
  3385. return ArrayFrom(v);
  3386. }
  3387. return null;
  3388. };
  3389. }
  3390. var isNode = typeof process !== "undefined" &&
  3391. classString(process).toLowerCase() === "[object process]";
  3392. var hasEnvVariables = typeof process !== "undefined" &&
  3393. typeof process.env !== "undefined";
  3394. function env(key) {
  3395. return hasEnvVariables ? process.env[key] : undefined;
  3396. }
  3397. function getNativePromise() {
  3398. if (typeof Promise === "function") {
  3399. try {
  3400. var promise = new Promise(function(){});
  3401. if (classString(promise) === "[object Promise]") {
  3402. return Promise;
  3403. }
  3404. } catch (e) {}
  3405. }
  3406. }
  3407. var reflectHandler;
  3408. function contextBind(ctx, cb) {
  3409. if (ctx === null ||
  3410. typeof cb !== "function" ||
  3411. cb === reflectHandler) {
  3412. return cb;
  3413. }
  3414. if (ctx.domain !== null) {
  3415. cb = ctx.domain.bind(cb);
  3416. }
  3417. var async = ctx.async;
  3418. if (async !== null) {
  3419. var old = cb;
  3420. cb = function() {
  3421. var args = (new Array(2)).concat([].slice.call(arguments));;
  3422. args[0] = old;
  3423. args[1] = this;
  3424. return async.runInAsyncScope.apply(async, args);
  3425. };
  3426. }
  3427. return cb;
  3428. }
  3429. var ret = {
  3430. setReflectHandler: function(fn) {
  3431. reflectHandler = fn;
  3432. },
  3433. isClass: isClass,
  3434. isIdentifier: isIdentifier,
  3435. inheritedDataKeys: inheritedDataKeys,
  3436. getDataPropertyOrDefault: getDataPropertyOrDefault,
  3437. thrower: thrower,
  3438. isArray: es5.isArray,
  3439. asArray: asArray,
  3440. notEnumerableProp: notEnumerableProp,
  3441. isPrimitive: isPrimitive,
  3442. isObject: isObject,
  3443. isError: isError,
  3444. canEvaluate: canEvaluate,
  3445. errorObj: errorObj,
  3446. tryCatch: tryCatch,
  3447. inherits: inherits,
  3448. withAppended: withAppended,
  3449. maybeWrapAsError: maybeWrapAsError,
  3450. toFastProperties: toFastProperties,
  3451. filledRange: filledRange,
  3452. toString: safeToString,
  3453. canAttachTrace: canAttachTrace,
  3454. ensureErrorObject: ensureErrorObject,
  3455. originatesFromRejection: originatesFromRejection,
  3456. markAsOriginatingFromRejection: markAsOriginatingFromRejection,
  3457. classString: classString,
  3458. copyDescriptors: copyDescriptors,
  3459. isNode: isNode,
  3460. hasEnvVariables: hasEnvVariables,
  3461. env: env,
  3462. global: globalObject,
  3463. getNativePromise: getNativePromise,
  3464. contextBind: contextBind
  3465. };
  3466. ret.isRecentNode = ret.isNode && (function() {
  3467. var version;
  3468. if (process.versions && process.versions.node) {
  3469. version = process.versions.node.split(".").map(Number);
  3470. } else if (process.version) {
  3471. version = process.version.split(".").map(Number);
  3472. }
  3473. return (version[0] === 0 && version[1] > 10) || (version[0] > 0);
  3474. })();
  3475. ret.nodeSupportsAsyncResource = ret.isNode && (function() {
  3476. var supportsAsync = false;
  3477. try {
  3478. var res = _dereq_("async_hooks").AsyncResource;
  3479. supportsAsync = typeof res.prototype.runInAsyncScope === "function";
  3480. } catch (e) {
  3481. supportsAsync = false;
  3482. }
  3483. return supportsAsync;
  3484. })();
  3485. if (ret.isNode) ret.toFastProperties(process);
  3486. try {throw new Error(); } catch (e) {ret.lastLineError = e;}
  3487. module.exports = ret;
  3488. },{"./es5":10,"async_hooks":undefined}]},{},[3])(3)
  3489. }); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }