bluebird.core.js 116 KB

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