Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bluebird.core.js 116KB

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