1/** 2 * bluebird build version 2.3.6 3 * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, progress, cancel, using, filter, any, each, timers 4*/ 5/** 6 * @preserve The MIT License (MIT) 7 * 8 * Copyright (c) 2014 Petka Antonov 9 * 10 * Permission is hereby granted, free of charge, to any person obtaining a copy 11 * of this software and associated documentation files (the "Software"), to deal 12 * in the Software without restriction, including without limitation the rights 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 * copies of the Software, and to permit persons to whom the Software is 15 * furnished to do so, subject to the following conditions:</p> 16 * 17 * The above copyright notice and this permission notice shall be included in 18 * all copies or substantial portions of the Software. 19 * 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 * THE SOFTWARE. 27 * 28 */ 29!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 require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ 30/** 31 * The MIT License (MIT) 32 * 33 * Copyright (c) 2014 Petka Antonov 34 * 35 * Permission is hereby granted, free of charge, to any person obtaining a copy 36 * of this software and associated documentation files (the "Software"), to deal 37 * in the Software without restriction, including without limitation the rights 38 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 * copies of the Software, and to permit persons to whom the Software is 40 * furnished to do so, subject to the following conditions:</p> 41 * 42 * The above copyright notice and this permission notice shall be included in 43 * all copies or substantial portions of the Software. 44 * 45 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 * THE SOFTWARE. 52 * 53 */ 54"use strict"; 55module.exports = function(Promise) { 56var SomePromiseArray = Promise._SomePromiseArray; 57function Promise$_Any(promises) { 58 var ret = new SomePromiseArray(promises); 59 var promise = ret.promise(); 60 if (promise.isRejected()) { 61 return promise; 62 } 63 ret.setHowMany(1); 64 ret.setUnwrap(); 65 ret.init(); 66 return promise; 67} 68 69Promise.any = function Promise$Any(promises) { 70 return Promise$_Any(promises); 71}; 72 73Promise.prototype.any = function Promise$any() { 74 return Promise$_Any(this); 75}; 76 77}; 78 79},{}],2:[function(_dereq_,module,exports){ 80/** 81 * The MIT License (MIT) 82 * 83 * Copyright (c) 2014 Petka Antonov 84 * 85 * Permission is hereby granted, free of charge, to any person obtaining a copy 86 * of this software and associated documentation files (the "Software"), to deal 87 * in the Software without restriction, including without limitation the rights 88 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 89 * copies of the Software, and to permit persons to whom the Software is 90 * furnished to do so, subject to the following conditions:</p> 91 * 92 * The above copyright notice and this permission notice shall be included in 93 * all copies or substantial portions of the Software. 94 * 95 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 96 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 97 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 98 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 99 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 100 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 101 * THE SOFTWARE. 102 * 103 */ 104"use strict"; 105var schedule = _dereq_("./schedule.js"); 106var Queue = _dereq_("./queue.js"); 107var errorObj = _dereq_("./util.js").errorObj; 108var tryCatch1 = _dereq_("./util.js").tryCatch1; 109var _process = typeof process !== "undefined" ? process : void 0; 110 111function Async() { 112 this._isTickUsed = false;
113 this._schedule = schedule; 114 this._length = 0; 115 this._lateBuffer = new Queue(16); 116 this._functionBuffer = new Queue(65536); 117 var self = this; 118 this.consumeFunctionBuffer = function Async$consumeFunctionBuffer() { 119 self._consumeFunctionBuffer(); 120 }; 121} 122 123Async.prototype.haveItemsQueued = function Async$haveItemsQueued() { 124 return this._length > 0; 125}; 126 127Async.prototype.invokeLater = function Async$invokeLater(fn, receiver, arg) { 128 if (_process !== void 0 && 129 _process.domain != null && 130 !fn.domain) { 131 fn = _process.domain.bind(fn); 132 } 133 this._lateBuffer.push(fn, receiver, arg); 134 this._queueTick(); 135}; 136 137Async.prototype.invoke = function Async$invoke(fn, receiver, arg) { 138 if (_process !== void 0 && 139 _process.domain != null && 140 !fn.domain) { 141 fn = _process.domain.bind(fn); 142 } 143 var functionBuffer = this._functionBuffer; 144 functionBuffer.push(fn, receiver, arg); 145 this._length = functionBuffer.length(); 146 this._queueTick(); 147}; 148 149Async.prototype._consumeFunctionBuffer = 150function Async$_consumeFunctionBuffer() { 151 var functionBuffer = this._functionBuffer; 152 while (functionBuffer.length() > 0) { 153 var fn = functionBuffer.shift(); 154 var receiver = functionBuffer.shift(); 155 var arg = functionBuffer.shift(); 156 fn.call(receiver, arg); 157 } 158 this._reset(); 159 this._consumeLateBuffer(); 160}; 161 162Async.prototype._consumeLateBuffer = function Async$_consumeLateBuffer() { 163 var buffer = this._lateBuffer; 164 while(buffer.length() > 0) { 165 var fn = buffer.shift(); 166 var receiver = buffer.shift(); 167 var arg = buffer.shift(); 168 var res = tryCatch1(fn, receiver, arg); 169 if (res === errorObj) { 170 this._queueTick(); 171 if (fn.domain != null) { 172 fn.domain.emit("error", res.e); 173 } else { 174 throw res.e; 175 } 176 } 177 } 178}; 179 180Async.prototype._queueTick = function Async$_queue() { 181 if (!this._isTickUsed) { 182 this._schedule(this.consumeFunctionBuffer); 183 this._isTickUsed = true; 184 } 185}; 186 187Async.prototype._reset = function Async$_reset() { 188 this._isTickUsed = false; 189 this._length = 0; 190}; 191 192module.exports = new Async(); 193 194},{"./queue.js":25,"./schedule.js":28,"./util.js":35}],3:[function(_dereq_,module,exports){ 195/** 196 * The MIT License (MIT) 197 * 198 * Copyright (c) 2014 Petka Antonov 199 * 200 * Permission is hereby granted, free of charge, to any person obtaining a copy 201 * of this software and associated documentation files (the "Software"), to deal 202 * in the Software without restriction, including without limitation the rights 203 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 204 * copies of the Software, and to permit persons to whom the Software is 205 * furnished to do so, subject to the following conditions:</p> 206 * 207 * The above copyright notice and this permission notice shall be included in 208 * all copies or substantial portions of the Software. 209 * 210 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 211 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 212 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 213 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 214 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 215 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 216 * THE SOFTWARE. 217 * 218 */ 219"use strict"; 220var Promise = _dereq_("./promise.js")(); 221module.exports = Promise; 222},{"./promise.js":20}],4:[function(_dereq_,module,exports){ 223/** 224 * The MIT License (MIT) 225 * 226 * Copyright (c) 2014 Petka Antonov 227 * 228 * Permission is hereby granted, free of charge, to any person obtaining a copy 229 * of this software and associated documentation files (the "Software"), to deal 230 * in the Software without restriction, including without limitation the rights 231 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 232 * copies of the Software, and to permit persons to whom the Software is 233 * furnished to do so, subject to the following conditions:</p> 234 * 235 * The above copyright notice and this permission notice shall be included in 236 * all copies or substantial portions of the Software. 237 * 238 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 239 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 240 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 241 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 242 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 243 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 244 * THE SOFTWARE. 245 * 246 */ 247"use strict"; 248var cr = Object.create; 249if (cr) { 250 var callerCache = cr(null); 251 var getterCache = cr(null); 252 callerCache[" size"] = getterCache[" size"] = 0; 253} 254 255module.exports = function(Promise) { 256var util = _dereq_("./util.js"); 257var canEvaluate = util.canEvaluate; 258var isIdentifier = util.isIdentifier; 259 260function makeMethodCaller (methodName) { 261 return new Function("obj", " \n\ 262 'use strict' \n\ 263 var len = this.length; \n\ 264 switch(len) { \n\ 265 case 1: return obj.methodName(this[0]); \n\ 266 case 2: return obj.methodName(this[0], this[1]); \n\ 267 case 3: return obj.methodName(this[0], this[1], this[2]); \n\ 268 case 0: return obj.methodName(); \n\ 269 default: return obj.methodName.apply(obj, this); \n\ 270 } \n\ 271 ".replace(/methodName/g, methodName)); 272} 273 274function makeGetter (propertyName) { 275 return new Function("obj", " \n\ 276 'use strict'; \n\ 277 return obj.propertyName; \n\ 278 ".replace("propertyName", propertyName)); 279} 280 281function getCompiled(name, compiler, cache) { 282 var ret = cache[name]; 283 if (typeof ret !== "function") { 284 if (!isIdentifier(name)) { 285 return null; 286 } 287 ret = compiler(name); 288 cache[name] = ret; 289 cache[" size"]++; 290 if (cache[" size"] > 512) { 291 var keys = Object.keys(cache); 292 for (var i = 0; i < 256; ++i) delete cache[keys[i]]; 293 cache[" size"] = keys.length - 256; 294 } 295 } 296 return ret; 297} 298 299function getMethodCaller(name) { 300 return getCompiled(name, makeMethodCaller, callerCache); 301} 302 303function getGetter(name) { 304 return getCompiled(name, makeGetter, getterCache); 305} 306 307function caller(obj) { 308 return obj[this.pop()].apply(obj, this); 309} 310Promise.prototype.call = function Promise$call(methodName) { 311 var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];} 312 if (canEvaluate) { 313 var maybeCaller = getMethodCaller(methodName); 314 if (maybeCaller !== null) { 315 return this._then(maybeCaller, void 0, void 0, args, void 0); 316 } 317 } 318 args.push(methodName); 319 return this._then(caller, void 0, void 0, args, void 0); 320}; 321 322function namedGetter(obj) { 323 return obj[this]; 324} 325function indexedGetter(obj) { 326 return obj[this]; 327} 328Promise.prototype.get = function Promise$get(propertyName) { 329 var isIndex = (typeof propertyName === "number"); 330 var getter; 331 if (!isIndex) { 332 if (canEvaluate) { 333 var maybeGetter = getGetter(propertyName); 334 getter = maybeGetter !== null ? maybeGetter : namedGetter; 335 } else { 336 getter = namedGetter; 337 } 338 } else { 339 getter = indexedGetter; 340 } 341 return this._then(getter, void 0, void 0, propertyName, void 0); 342}; 343}; 344 345},{"./util.js":35}],5:[function(_dereq_,module,exports){ 346/** 347 * The MIT License (MIT) 348 * 349 * Copyright (c) 2014 Petka Antonov 350 * 351 * Permission is hereby granted, free of charge, to any person obtaining a copy 352 * of this software and associated documentation files (the "Software"), to deal 353 * in the Software without restriction, including without limitation the rights 354 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 355 * copies of the Software, and to permit persons to whom the Software is 356 * furnished to do so, subject to the following conditions:</p> 357 * 358 * The above copyright notice and this permission notice shall be included in 359 * all copies or substantial portions of the Software. 360 * 361 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 362 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 363 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 364 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 365 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 366 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 367 * THE SOFTWARE. 368 * 369 */ 370"use strict"; 371module.exports = function(Promise, INTERNAL) { 372var errors = _dereq_("./errors.js"); 373var canAttach = errors.canAttach; 374var async = _dereq_("./async.js"); 375var CancellationError = errors.CancellationError; 376 377Promise.prototype._cancel = function Promise$_cancel(reason) { 378 if (!this.isCancellable()) return this; 379 var parent; 380 var promiseToReject = this; 381 while ((parent = promiseToReject._cancellationParent) !== void 0 && 382 parent.isCancellable()) { 383 promiseToReject = parent; 384 } 385 promiseToReject._attachExtraTrace(reason); 386 promiseToReject._rejectUnchecked(reason); 387}; 388 389Promise.prototype.cancel = function Promise$cancel(reason) { 390 if (!this.isCancellable()) return this; 391 reason = reason !== void 0 392 ? (canAttach(reason) ? reason : new Error(reason + "")) 393 : new CancellationError(); 394 async.invokeLater(this._cancel, this, reason); 395 return this; 396}; 397 398Promise.prototype.cancellable = function Promise$cancellable() { 399 if (this._cancellable()) return this; 400 this._setCancellable(); 401 this._cancellationParent = void 0; 402 return this; 403}; 404 405Promise.prototype.uncancellable = function Promise$uncancellable() { 406 var ret = new Promise(INTERNAL); 407 ret._propagateFrom(this, 2 | 4); 408 ret._follow(this); 409 ret._unsetCancellable(); 410 return ret; 411}; 412 413Promise.prototype.fork = 414function Promise$fork(didFulfill, didReject, didProgress) { 415 var ret = this._then(didFulfill, didReject, didProgress, 416 void 0, void 0); 417 418 ret._setCancellable(); 419 ret._cancellationParent = void 0; 420 return ret; 421}; 422}; 423 424},{"./async.js":2,"./errors.js":10}],6:[function(_dereq_,module,exports){ 425/** 426 * The MIT License (MIT) 427 * 428 * Copyright (c) 2014 Petka Antonov 429 * 430 * Permission is hereby granted, free of charge, to any person obtaining a copy 431 * of this software and associated documentation files (the "Software"), to deal 432 * in the Software without restriction, including without limitation the rights 433 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 434 * copies of the Software, and to permit persons to whom the Software is 435 * furnished to do so, subject to the following conditions:</p> 436 * 437 * The above copyright notice and this permission notice shall be included in 438 * all copies or substantial portions of the Software. 439 * 440 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 441 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 442 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 443 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 444 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 445 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 446 * THE SOFTWARE. 447 * 448 */ 449"use strict"; 450module.exports = function() { 451var inherits = _dereq_("./util.js").inherits;
452var defineProperty = _dereq_("./es5.js").defineProperty; 453 454var rignore = new RegExp( 455 "\\b(?:[a-zA-Z0-9.]+\\$_\\w+|" + 456 "tryCatch(?:1|2|3|4|Apply)|new \\w*PromiseArray|" + 457 "\\w*PromiseArray\\.\\w*PromiseArray|" + 458 "setTimeout|CatchFilter\\$_\\w+|makeNodePromisified|processImmediate|" + 459 "process._tickCallback|nextTick|Async\\$\\w+)\\b" 460); 461 462var rtraceline = null; 463var formatStack = null; 464 465function formatNonError(obj) { 466 var str; 467 if (typeof obj === "function") { 468 str = "[function " + 469 (obj.name || "anonymous") + 470 "]"; 471 } else { 472 str = obj.toString(); 473 var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/; 474 if (ruselessToString.test(str)) { 475 try { 476 var newStr = JSON.stringify(obj); 477 str = newStr; 478 } 479 catch(e) { 480 481 } 482 } 483 if (str.length === 0) { 484 str = "(empty array)"; 485 } 486 } 487 return ("(<" + snip(str) + ">, no stack trace)"); 488} 489 490function snip(str) { 491 var maxChars = 41; 492 if (str.length < maxChars) { 493 return str; 494 } 495 return str.substr(0, maxChars - 3) + "..."; 496} 497 498function CapturedTrace(ignoreUntil, isTopLevel) { 499 this.captureStackTrace(CapturedTrace, isTopLevel); 500 501} 502inherits(CapturedTrace, Error); 503 504CapturedTrace.prototype.captureStackTrace = 505function CapturedTrace$captureStackTrace(ignoreUntil, isTopLevel) { 506 captureStackTrace(this, ignoreUntil, isTopLevel); 507}; 508 509CapturedTrace.possiblyUnhandledRejection = 510function CapturedTrace$PossiblyUnhandledRejection(reason) { 511 if (typeof console === "object") { 512 var message; 513 if (typeof reason === "object" || typeof reason === "function") { 514 var stack = reason.stack; 515 message = "Possibly unhandled " + formatStack(stack, reason); 516 } else { 517 message = "Possibly unhandled " + String(reason); 518 } 519 if (typeof console.error === "function" || 520 typeof console.error === "object") { 521 console.error(message); 522 } else if (typeof console.log === "function" || 523 typeof console.log === "object") { 524 console.log(message); 525 } 526 } 527}; 528 529CapturedTrace.combine = function CapturedTrace$Combine(current, prev) { 530 var curLast = current.length - 1; 531 for (var i = prev.length - 1; i >= 0; --i) { 532 var line = prev[i]; 533 if (current[curLast] === line) { 534 current.pop(); 535 curLast--; 536 } else { 537 break; 538 } 539 } 540 541 current.push("From previous event:"); 542 var lines = current.concat(prev); 543 544 var ret = []; 545 546 for (var i = 0, len = lines.length; i < len; ++i) { 547 548 if (((rignore.test(lines[i]) && rtraceline.test(lines[i])) || 549 (i > 0 && !rtraceline.test(lines[i])) && 550 lines[i] !== "From previous event:") 551 ) { 552 continue; 553 } 554 ret.push(lines[i]); 555 } 556 return ret; 557}; 558 559CapturedTrace.protectErrorMessageNewlines = function(stack) { 560 for (var i = 0; i < stack.length; ++i) { 561 if (rtraceline.test(stack[i])) { 562 break; 563 } 564 } 565 566 if (i <= 1) return; 567 568 var errorMessageLines = []; 569 for (var j = 0; j < i; ++j) { 570 errorMessageLines.push(stack.shift()); 571 } 572 stack.unshift(errorMessageLines.join("\u0002\u0000\u0001")); 573}; 574 575CapturedTrace.isSupported = function CapturedTrace$IsSupported() { 576 return typeof captureStackTrace === "function"; 577}; 578 579var captureStackTrace = (function stackDetection() { 580 if (typeof Error.stackTraceLimit === "number" && 581 typeof Error.captureStackTrace === "function") { 582 rtraceline = /^\s*at\s*/; 583 formatStack = function(stack, error) { 584 if (typeof stack === "string") return stack; 585 586 if (error.name !== void 0 && 587 error.message !== void 0) { 588 return error.name + ". " + error.message; 589 } 590 return formatNonError(error); 591 592 593 }; 594 var captureStackTrace = Error.captureStackTrace; 595 return function CapturedTrace$_captureStackTrace( 596 receiver, ignoreUntil) { 597 captureStackTrace(receiver, ignoreUntil); 598 }; 599 } 600 var err = new Error(); 601 602 if (typeof err.stack === "string" && 603 typeof "".startsWith === "function" && 604 (err.stack.startsWith("stackDetection@")) && 605 stackDetection.name === "stackDetection") { 606 607 defineProperty(Error, "stackTraceLimit", { 608 writable: true, 609 enumerable: false, 610 configurable: false, 611 value: 25 612 }); 613 rtraceline = /@/; 614 var rline = /[@\n]/; 615 616 formatStack = function(stack, error) { 617 if (typeof stack === "string") { 618 return (error.name + ". " + error.message + "\n" + stack); 619 } 620 621 if (error.name !== void 0 && 622 error.message !== void 0) { 623 return error.name + ". " + error.message; 624 } 625 return formatNonError(error); 626 }; 627 628 return function captureStackTrace(o) { 629 var stack = new Error().stack; 630 var split = stack.split(rline); 631 var len = split.length; 632 var ret = ""; 633 for (var i = 0; i < len; i += 2) { 634 ret += split[i]; 635 ret += "@"; 636 ret += split[i + 1]; 637 ret += "\n"; 638 } 639 o.stack = ret; 640 }; 641 } else { 642 formatStack = function(stack, error) { 643 if (typeof stack === "string") return stack; 644 645 if ((typeof error === "object" || 646 typeof error === "function") &&
647 error.name !== void 0 && 648 error.message !== void 0) { 649 return error.name + ". " + error.message; 650 } 651 return formatNonError(error); 652 }; 653 654 return null; 655 } 656})(); 657 658return CapturedTrace; 659}; 660 661},{"./es5.js":12,"./util.js":35}],7:[function(_dereq_,module,exports){ 662/** 663 * The MIT License (MIT) 664 * 665 * Copyright (c) 2014 Petka Antonov 666 * 667 * Permission is hereby granted, free of charge, to any person obtaining a copy 668 * of this software and associated documentation files (the "Software"), to deal 669 * in the Software without restriction, including without limitation the rights 670 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 671 * copies of the Software, and to permit persons to whom the Software is 672 * furnished to do so, subject to the following conditions:</p> 673 * 674 * The above copyright notice and this permission notice shall be included in 675 * all copies or substantial portions of the Software. 676 * 677 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 678 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 679 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 680 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 681 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 682 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 683 * THE SOFTWARE. 684 * 685 */ 686"use strict"; 687module.exports = function(NEXT_FILTER) { 688var util = _dereq_("./util.js"); 689var errors = _dereq_("./errors.js"); 690var tryCatch1 = util.tryCatch1; 691var errorObj = util.errorObj; 692var keys = _dereq_("./es5.js").keys; 693var TypeError = errors.TypeError; 694 695function CatchFilter(instances, callback, promise) { 696 this._instances = instances; 697 this._callback = callback; 698 this._promise = promise; 699} 700 701function CatchFilter$_safePredicate(predicate, e) { 702 var safeObject = {}; 703 var retfilter = tryCatch1(predicate, safeObject, e); 704 705 if (retfilter === errorObj) return retfilter; 706 707 var safeKeys = keys(safeObject); 708 if (safeKeys.length) { 709 errorObj.e = new TypeError( 710 "Catch filter must inherit from Error " 711 + "or be a simple predicate function"); 712 return errorObj; 713 } 714 return retfilter; 715} 716 717CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) { 718 var cb = this._callback; 719 var promise = this._promise; 720 var boundTo = promise._boundTo; 721 for (var i = 0, len = this._instances.length; i < len; ++i) { 722 var item = this._instances[i]; 723 var itemIsErrorType = item === Error || 724 (item != null && item.prototype instanceof Error); 725 726 if (itemIsErrorType && e instanceof item) { 727 var ret = tryCatch1(cb, boundTo, e); 728 if (ret === errorObj) { 729 NEXT_FILTER.e = ret.e; 730 return NEXT_FILTER; 731 } 732 return ret; 733 } else if (typeof item === "function" && !itemIsErrorType) { 734 var shouldHandle = CatchFilter$_safePredicate(item, e); 735 if (shouldHandle === errorObj) { 736 var trace = errors.canAttach(errorObj.e) 737 ? errorObj.e 738 : new Error(errorObj.e + ""); 739 this._promise._attachExtraTrace(trace); 740 e = errorObj.e; 741 break; 742 } else if (shouldHandle) { 743 var ret = tryCatch1(cb, boundTo, e); 744 if (ret === errorObj) { 745 NEXT_FILTER.e = ret.e; 746 return NEXT_FILTER; 747 } 748 return ret; 749 } 750 } 751 } 752 NEXT_FILTER.e = e; 753 return NEXT_FILTER; 754}; 755 756return CatchFilter; 757}; 758 759},{"./errors.js":10,"./es5.js":12,"./util.js":35}],8:[function(_dereq_,module,exports){ 760/** 761 * The MIT License (MIT) 762 * 763 * Copyright (c) 2014 Petka Antonov 764 * 765 * Permission is hereby granted, free of charge, to any person obtaining a copy 766 * of this software and associated documentation files (the "Software"), to deal 767 * in the Software without restriction, including without limitation the rights 768 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 769 * copies of the Software, and to permit persons to whom the Software is 770 * furnished to do so, subject to the following conditions:</p> 771 * 772 * The above copyright notice and this permission notice shall be included in 773 * all copies or substantial portions of the Software. 774 * 775 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 776 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 777 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 778 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 779 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 780 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 781 * THE SOFTWARE. 782 * 783 */ 784"use strict"; 785var util = _dereq_("./util.js"); 786var isPrimitive = util.isPrimitive; 787var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver; 788 789module.exports = function(Promise) { 790var returner = function Promise$_returner() { 791 return this; 792}; 793var thrower = function Promise$_thrower() { 794 throw this; 795}; 796 797var wrapper = function Promise$_wrapper(value, action) { 798 if (action === 1) { 799 return function Promise$_thrower() { 800 throw value; 801 }; 802 } else if (action === 2) { 803 return function Promise$_returner() { 804 return value; 805 }; 806 } 807}; 808 809 810Promise.prototype["return"] = 811Promise.prototype.thenReturn =
812function Promise$thenReturn(value) { 813 if (wrapsPrimitiveReceiver && isPrimitive(value)) { 814 return this._then( 815 wrapper(value, 2), 816 void 0, 817 void 0, 818 void 0, 819 void 0 820 ); 821 } 822 return this._then(returner, void 0, void 0, value, void 0); 823}; 824 825Promise.prototype["throw"] = 826Promise.prototype.thenThrow = 827function Promise$thenThrow(reason) { 828 if (wrapsPrimitiveReceiver && isPrimitive(reason)) { 829 return this._then( 830 wrapper(reason, 1), 831 void 0, 832 void 0, 833 void 0, 834 void 0 835 ); 836 } 837 return this._then(thrower, void 0, void 0, reason, void 0); 838}; 839}; 840 841},{"./util.js":35}],9:[function(_dereq_,module,exports){ 842/** 843 * The MIT License (MIT) 844 * 845 * Copyright (c) 2014 Petka Antonov 846 * 847 * Permission is hereby granted, free of charge, to any person obtaining a copy 848 * of this software and associated documentation files (the "Software"), to deal 849 * in the Software without restriction, including without limitation the rights 850 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 851 * copies of the Software, and to permit persons to whom the Software is 852 * furnished to do so, subject to the following conditions:</p> 853 * 854 * The above copyright notice and this permission notice shall be included in 855 * all copies or substantial portions of the Software. 856 * 857 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 858 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 859 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 860 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 861 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 862 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 863 * THE SOFTWARE. 864 * 865 */ 866"use strict"; 867module.exports = function(Promise, INTERNAL) { 868var PromiseReduce = Promise.reduce; 869 870Promise.prototype.each = function Promise$each(fn) { 871 return PromiseReduce(this, fn, null, INTERNAL); 872}; 873 874Promise.each = function Promise$Each(promises, fn) { 875 return PromiseReduce(promises, fn, null, INTERNAL); 876}; 877}; 878 879},{}],10:[function(_dereq_,module,exports){ 880/** 881 * The MIT License (MIT) 882 * 883 * Copyright (c) 2014 Petka Antonov 884 * 885 * Permission is hereby granted, free of charge, to any person obtaining a copy 886 * of this software and associated documentation files (the "Software"), to deal 887 * in the Software without restriction, including without limitation the rights 888 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 889 * copies of the Software, and to permit persons to whom the Software is 890 * furnished to do so, subject to the following conditions:</p> 891 * 892 * The above copyright notice and this permission notice shall be included in 893 * all copies or substantial portions of the Software. 894 * 895 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 896 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 897 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 898 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 899 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 900 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 901 * THE SOFTWARE. 902 * 903 */ 904"use strict"; 905var Objectfreeze = _dereq_("./es5.js").freeze; 906var util = _dereq_("./util.js"); 907var inherits = util.inherits; 908var notEnumerableProp = util.notEnumerableProp; 909 910function markAsOriginatingFromRejection(e) { 911 try { 912 notEnumerableProp(e, "isOperational", true); 913 } 914 catch(ignore) {} 915} 916 917function originatesFromRejection(e) { 918 if (e == null) return false; 919 return ((e instanceof OperationalError) || 920 e["isOperational"] === true); 921} 922 923function isError(obj) { 924 return obj instanceof Error; 925} 926 927function canAttach(obj) { 928 return isError(obj); 929} 930 931function subError(nameProperty, defaultMessage) { 932 function SubError(message) { 933 if (!(this instanceof SubError)) return new SubError(message); 934 this.message = typeof message === "string" ? message : defaultMessage; 935 this.name = nameProperty; 936 if (Error.captureStackTrace) { 937 Error.captureStackTrace(this, this.constructor); 938 } 939 } 940 inherits(SubError, Error); 941 return SubError; 942} 943 944var _TypeError, _RangeError; 945var CancellationError = subError("CancellationError", "cancellation error"); 946var TimeoutError = subError("TimeoutError", "timeout error"); 947var AggregateError = subError("AggregateError", "aggregate error"); 948try { 949 _TypeError = TypeError; 950 _RangeError = RangeError; 951} catch(e) { 952 _TypeError = subError("TypeError", "type error"); 953 _RangeError = subError("RangeError", "range error"); 954} 955 956var methods = ("join pop push shift unshift slice filter forEach some " + 957 "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" "); 958 959for (var i = 0; i < methods.length; ++i) { 960 if (typeof Array.prototype[methods[i]] === "function") { 961 AggregateError.prototype[methods[i]] = Array.prototype[methods[i]]; 962 } 963} 964 965AggregateError.prototype.length = 0; 966AggregateError.prototype["isOperational"] = true; 967var level = 0; 968AggregateError.prototype.toString = function() { 969 var indent = Array(level * 4 + 1).join(" "); 970 var ret = "\n" + indent + "AggregateError of:" + "\n"; 971 level++; 972 indent = Array(level * 4 + 1).join(" "); 973 for (var i = 0; i < this.length; ++i) { 974 var str = this[i] === this ? "[Circular AggregateError]" : this[i] + ""; 975 var lines = str.split("\n"); 976 for (var j = 0; j < lines.length; ++j) { 977 lines[j] = indent + lines[j]; 978 } 979 str = lines.join("\n"); 980 ret += str + "\n"; 981 } 982 level--; 983 return ret; 984}; 985 986function OperationalError(message) { 987 this.name = "OperationalError"; 988 this.message = message; 989 this.cause = message; 990 this["isOperational"] = true; 991 992 if (message instanceof Error) { 993 this.message = message.message; 994 this.stack = message.stack; 995 } else if (Error.captureStackTrace) { 996 Error.captureStackTrace(this, this.constructor); 997 } 998 999} 1000inherits(OperationalError, Error); 1001 1002var key = "__BluebirdErrorTypes__"; 1003var errorTypes = Error[key]; 1004if (!errorTypes) { 1005 errorTypes = Objectfreeze({ 1006 CancellationError: CancellationError, 1007 TimeoutError: TimeoutError, 1008 OperationalError: OperationalError, 1009 RejectionError: OperationalError, 1010 AggregateError: AggregateError 1011 }); 1012 notEnumerableProp(Error, key, errorTypes); 1013} 1014 1015module.exports = { 1016 Error: Error, 1017 TypeError: _TypeError, 1018 RangeError: _RangeError, 1019 CancellationError: errorTypes.CancellationError, 1020 OperationalError: errorTypes.OperationalError, 1021 TimeoutError: errorTypes.TimeoutError, 1022 AggregateError: errorTypes.AggregateError, 1023 originatesFromRejection: originatesFromRejection, 1024 markAsOriginatingFromRejection: markAsOriginatingFromRejection, 1025 canAttach: canAttach 1026}; 1027 1028},{"./es5.js":12,"./util.js":35}],11:[function(_dereq_,module,exports){ 1029/** 1030 * The MIT License (MIT) 1031 * 1032 * Copyright (c) 2014 Petka Antonov 1033 * 1034 * Permission is hereby granted, free of charge, to any person obtaining a copy 1035 * of this software and associated documentation files (the "Software"), to deal 1036 * in the Software without restriction, including without limitation the rights 1037 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1038 * copies of the Software, and to permit persons to whom the Software is 1039 * furnished to do so, subject to the following conditions:</p> 1040 * 1041 * The above copyright notice and this permission notice shall be included in 1042 * all copies or substantial portions of the Software. 1043 * 1044 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1045 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1046 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1047 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1048 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1049 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1050 * THE SOFTWARE. 1051 * 1052 */ 1053"use strict"; 1054module.exports = function(Promise) { 1055var TypeError = _dereq_('./errors.js').TypeError; 1056 1057function apiRejection(msg) { 1058 var error = new TypeError(msg); 1059 var ret = Promise.rejected(error); 1060 var parent = ret._peekContext(); 1061 if (parent != null) { 1062 parent._attachExtraTrace(error); 1063 } 1064 return ret; 1065} 1066 1067return apiRejection; 1068}; 1069 1070},{"./errors.js":10}],12:[function(_dereq_,module,exports){ 1071/** 1072 * The MIT License (MIT) 1073 * 1074 * Copyright (c) 2014 Petka Antonov 1075 * 1076 * Permission is hereby granted, free of charge, to any person obtaining a copy 1077 * of this software and associated documentation files (the "Software"), to deal 1078 * in the Software without restriction, including without limitation the rights 1079 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1080 * copies of the Software, and to permit persons to whom the Software is 1081 * furnished to do so, subject to the following conditions:</p> 1082 * 1083 * The above copyright notice and this permission notice shall be included in 1084 * all copies or substantial portions of the Software. 1085 * 1086 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1087 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1088 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1089 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1090 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1091 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1092 * THE SOFTWARE. 1093 * 1094 */ 1095var isES5 = (function(){ 1096 "use strict"; 1097 return this === void 0; 1098})(); 1099 1100if (isES5) { 1101 module.exports = { 1102 freeze: Object.freeze, 1103 defineProperty: Object.defineProperty, 1104 keys: Object.keys, 1105 getPrototypeOf: Object.getPrototypeOf, 1106 isArray: Array.isArray, 1107 isES5: isES5 1108 }; 1109} else { 1110 var has = {}.hasOwnProperty; 1111 var str = {}.toString; 1112 var proto = {}.constructor.prototype; 1113 1114 var ObjectKeys = function ObjectKeys(o) { 1115 var ret = []; 1116 for (var key in o) { 1117 if (has.call(o, key)) {
1118 ret.push(key); 1119 } 1120 } 1121 return ret; 1122 } 1123 1124 var ObjectDefineProperty = function ObjectDefineProperty(o, key, desc) { 1125 o[key] = desc.value; 1126 return o; 1127 } 1128 1129 var ObjectFreeze = function ObjectFreeze(obj) { 1130 return obj; 1131 } 1132 1133 var ObjectGetPrototypeOf = function ObjectGetPrototypeOf(obj) { 1134 try { 1135 return Object(obj).constructor.prototype; 1136 } 1137 catch (e) { 1138 return proto; 1139 } 1140 } 1141 1142 var ArrayIsArray = function ArrayIsArray(obj) { 1143 try { 1144 return str.call(obj) === "[object Array]"; 1145 } 1146 catch(e) { 1147 return false; 1148 } 1149 } 1150 1151 module.exports = { 1152 isArray: ArrayIsArray, 1153 keys: ObjectKeys, 1154 defineProperty: ObjectDefineProperty, 1155 freeze: ObjectFreeze, 1156 getPrototypeOf: ObjectGetPrototypeOf, 1157 isES5: isES5 1158 }; 1159} 1160 1161},{}],13:[function(_dereq_,module,exports){ 1162/** 1163 * The MIT License (MIT) 1164 * 1165 * Copyright (c) 2014 Petka Antonov 1166 * 1167 * Permission is hereby granted, free of charge, to any person obtaining a copy 1168 * of this software and associated documentation files (the "Software"), to deal 1169 * in the Software without restriction, including without limitation the rights 1170 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1171 * copies of the Software, and to permit persons to whom the Software is 1172 * furnished to do so, subject to the following conditions:</p> 1173 * 1174 * The above copyright notice and this permission notice shall be included in 1175 * all copies or substantial portions of the Software. 1176 * 1177 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1178 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1179 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1180 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1181 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1182 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1183 * THE SOFTWARE. 1184 * 1185 */ 1186"use strict"; 1187module.exports = function(Promise, INTERNAL) { 1188var PromiseMap = Promise.map; 1189 1190Promise.prototype.filter = function Promise$filter(fn, options) { 1191 return PromiseMap(this, fn, options, INTERNAL); 1192}; 1193 1194Promise.filter = function Promise$Filter(promises, fn, options) { 1195 return PromiseMap(promises, fn, options, INTERNAL); 1196}; 1197}; 1198 1199},{}],14:[function(_dereq_,module,exports){ 1200/** 1201 * The MIT License (MIT) 1202 * 1203 * Copyright (c) 2014 Petka Antonov 1204 * 1205 * Permission is hereby granted, free of charge, to any person obtaining a copy 1206 * of this software and associated documentation files (the "Software"), to deal 1207 * in the Software without restriction, including without limitation the rights 1208 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1209 * copies of the Software, and to permit persons to whom the Software is 1210 * furnished to do so, subject to the following conditions:</p> 1211 * 1212 * The above copyright notice and this permission notice shall be included in 1213 * all copies or substantial portions of the Software. 1214 * 1215 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1216 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1217 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1218 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1219 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1220 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1221 * THE SOFTWARE. 1222 * 1223 */ 1224"use strict"; 1225module.exports = function(Promise, NEXT_FILTER, cast) { 1226var util = _dereq_("./util.js"); 1227var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver; 1228var isPrimitive = util.isPrimitive; 1229var thrower = util.thrower; 1230 1231function returnThis() { 1232 return this; 1233} 1234function throwThis() { 1235 throw this; 1236} 1237function return$(r) { 1238 return function Promise$_returner() { 1239 return r; 1240 }; 1241} 1242function throw$(r) { 1243 return function Promise$_thrower() { 1244 throw r; 1245 }; 1246} 1247function promisedFinally(ret, reasonOrValue, isFulfilled) { 1248 var then; 1249 if (wrapsPrimitiveReceiver && isPrimitive(reasonOrValue)) { 1250 then = isFulfilled ? return$(reasonOrValue) : throw$(reasonOrValue); 1251 } else { 1252 then = isFulfilled ? returnThis : throwThis; 1253 } 1254 return ret._then(then, thrower, void 0, reasonOrValue, void 0); 1255} 1256 1257function finallyHandler(reasonOrValue) { 1258 var promise = this.promise; 1259 var handler = this.handler; 1260 1261 var ret = promise._isBound() 1262 ? handler.call(promise._boundTo) 1263 : handler(); 1264 1265 if (ret !== void 0) { 1266 var maybePromise = cast(ret, void 0); 1267 if (maybePromise instanceof Promise) { 1268 return promisedFinally(maybePromise, reasonOrValue, 1269 promise.isFulfilled()); 1270 } 1271 } 1272 1273 if (promise.isRejected()) { 1274 NEXT_FILTER.e = reasonOrValue; 1275 return NEXT_FILTER; 1276 } else { 1277 return reasonOrValue; 1278 } 1279} 1280 1281function tapHandler(value) { 1282 var promise = this.promise; 1283 var handler = this.handler; 1284 1285 var ret = promise._isBound() 1286 ? handler.call(promise._boundTo, value) 1287 : handler(value); 1288 1289 if (ret !== void 0) { 1290 var maybePromise = cast(ret, void 0); 1291 if (maybePromise instanceof Promise) { 1292 return promisedFinally(maybePromise, value, true); 1293 } 1294 } 1295 return value; 1296} 1297 1298Promise.prototype._passThroughHandler = 1299function Promise$_passThroughHandler(handler, isFinally) { 1300 if (typeof handler !== "function") return this.then(); 1301 1302 var promiseAndHandler = { 1303 promise: this, 1304 handler: handler 1305 }; 1306 1307 return this._then( 1308 isFinally ? finallyHandler : tapHandler, 1309 isFinally ? finallyHandler : void 0, void 0, 1310 promiseAndHandler, void 0); 1311}; 1312 1313Promise.prototype.lastly = 1314Promise.prototype["finally"] = function Promise$finally(handler) { 1315 return this._passThroughHandler(handler, true); 1316}; 1317 1318Promise.prototype.tap = function Promise$tap(handler) { 1319 return this._passThroughHandler(handler, false); 1320}; 1321}; 1322 1323},{"./util.js":35}],15:[function(_dereq_,module,exports){ 1324/** 1325 * The MIT License (MIT) 1326 * 1327 * Copyright (c) 2014 Petka Antonov 1328 * 1329 * Permission is hereby granted, free of charge, to any person obtaining a copy 1330 * of this software and associated documentation files (the "Software"), to deal 1331 * in the Software without restriction, including without limitation the rights 1332 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1333 * copies of the Software, and to permit persons to whom the Software is 1334 * furnished to do so, subject to the following conditions:</p> 1335 * 1336 * The above copyright notice and this permission notice shall be included in 1337 * all copies or substantial portions of the Software. 1338 * 1339 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1340 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1341 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1342 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1343 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1344 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1345 * THE SOFTWARE. 1346 * 1347 */ 1348"use strict"; 1349module.exports = function(Promise, apiRejection, INTERNAL, cast) { 1350var errors = _dereq_("./errors.js"); 1351var TypeError = errors.TypeError; 1352var deprecated = _dereq_("./util.js").deprecated; 1353var util = _dereq_("./util.js"); 1354var errorObj = util.errorObj; 1355var tryCatch1 = util.tryCatch1; 1356var yieldHandlers = []; 1357 1358function promiseFromYieldHandler(value, yieldHandlers) { 1359 var _errorObj = errorObj; 1360 var _Promise = Promise; 1361 var len = yieldHandlers.length; 1362 for (var i = 0; i < len; ++i) { 1363 var result = tryCatch1(yieldHandlers[i], void 0, value); 1364 if (result === _errorObj) { 1365 return _Promise.reject(_errorObj.e); 1366 } 1367 var maybePromise = cast(result, promiseFromYieldHandler); 1368 if (maybePromise instanceof _Promise) return maybePromise; 1369 } 1370 return null; 1371} 1372 1373function PromiseSpawn(generatorFunction, receiver, yieldHandler) { 1374 var promise = this._promise = new Promise(INTERNAL); 1375 promise._setTrace(void 0); 1376 this._generatorFunction = generatorFunction; 1377 this._receiver = receiver; 1378 this._generator = void 0; 1379 this._yieldHandlers = typeof yieldHandler === "function" 1380 ? [yieldHandler].concat(yieldHandlers) 1381 : yieldHandlers; 1382} 1383 1384PromiseSpawn.prototype.promise = function PromiseSpawn$promise() { 1385 return this._promise; 1386}; 1387 1388PromiseSpawn.prototype._run = function PromiseSpawn$_run() { 1389 this._generator = this._generatorFunction.call(this._receiver); 1390 this._receiver = 1391 this._generatorFunction = void 0; 1392 this._next(void 0); 1393}; 1394 1395PromiseSpawn.prototype._continue = function PromiseSpawn$_continue(result) { 1396 if (result === errorObj) { 1397 this._generator = void 0; 1398 var trace = errors.canAttach(result.e) 1399 ? result.e : new Error(result.e + ""); 1400 this._promise._attachExtraTrace(trace); 1401 this._promise._reject(result.e, trace); 1402 return; 1403 } 1404 1405 var value = result.value; 1406 if (result.done === true) { 1407 this._generator = void 0; 1408 if (!this._promise._tryFollow(value)) { 1409 this._promise._fulfill(value); 1410 } 1411 } else { 1412 var maybePromise = cast(value, void 0); 1413 if (!(maybePromise instanceof Promise)) { 1414 maybePromise = 1415 promiseFromYieldHandler(maybePromise, this._yieldHandlers); 1416 if (maybePromise === null) { 1417 this._throw(new TypeError("A value was yielded that could not be treated as a promise")); 1418 return; 1419 } 1420 } 1421 maybePromise._then( 1422 this._next, 1423 this._throw, 1424 void 0, 1425 this, 1426 null 1427 ); 1428 } 1429}; 1430 1431PromiseSpawn.prototype._throw = function PromiseSpawn$_throw(reason) { 1432 if (errors.canAttach(reason)) 1433 this._promise._attachExtraTrace(reason); 1434 this._continue( 1435 tryCatch1(this._generator["throw"], this._generator, reason) 1436 ); 1437}; 1438 1439PromiseSpawn.prototype._next = function PromiseSpawn$_next(value) { 1440 this._continue( 1441 tryCatch1(this._generator.next, this._generator, value) 1442 ); 1443}; 1444 1445Promise.coroutine = 1446function Promise$Coroutine(generatorFunction, options) { 1447 if (typeof generatorFunction !== "function") { 1448 throw new TypeError("generatorFunction must be a function"); 1449 } 1450 var yieldHandler = Object(options).yieldHandler; 1451 var PromiseSpawn$ = PromiseSpawn; 1452 return function () { 1453 var generator = generatorFunction.apply(this, arguments); 1454 var spawn = new PromiseSpawn$(void 0, void 0, yieldHandler); 1455 spawn._generator = generator; 1456 spawn._next(void 0); 1457 return spawn.promise(); 1458 }; 1459}; 1460 1461Promise.coroutine.addYieldHandler = function(fn) { 1462 if (typeof fn !== "function") throw new TypeError("fn must be a function"); 1463 yieldHandlers.push(fn); 1464}; 1465 1466Promise.spawn = function Promise$Spawn(generatorFunction) { 1467 deprecated("Promise.spawn is deprecated. Use Promise.coroutine instead."); 1468 if (typeof generatorFunction !== "function") { 1469 return apiRejection("generatorFunction must be a function"); 1470 } 1471 var spawn = new PromiseSpawn(generatorFunction, this); 1472 var ret = spawn.promise();
1473 spawn._run(Promise.spawn); 1474 return ret; 1475}; 1476}; 1477 1478},{"./errors.js":10,"./util.js":35}],16:[function(_dereq_,module,exports){ 1479/** 1480 * The MIT License (MIT) 1481 * 1482 * Copyright (c) 2014 Petka Antonov 1483 * 1484 * Permission is hereby granted, free of charge, to any person obtaining a copy 1485 * of this software and associated documentation files (the "Software"), to deal 1486 * in the Software without restriction, including without limitation the rights 1487 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1488 * copies of the Software, and to permit persons to whom the Software is 1489 * furnished to do so, subject to the following conditions:</p> 1490 * 1491 * The above copyright notice and this permission notice shall be included in 1492 * all copies or substantial portions of the Software. 1493 * 1494 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1495 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1496 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1497 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1498 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1499 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1500 * THE SOFTWARE. 1501 * 1502 */ 1503"use strict"; 1504module.exports = 1505function(Promise, PromiseArray, cast, INTERNAL) { 1506var util = _dereq_("./util.js"); 1507var canEvaluate = util.canEvaluate; 1508var tryCatch1 = util.tryCatch1; 1509var errorObj = util.errorObj; 1510 1511 1512if (canEvaluate) { 1513 var thenCallback = function(i) { 1514 return new Function("value", "holder", " \n\ 1515 'use strict'; \n\ 1516 holder.pIndex = value; \n\ 1517 holder.checkFulfillment(this); \n\ 1518 ".replace(/Index/g, i)); 1519 }; 1520 1521 var caller = function(count) { 1522 var values = []; 1523 for (var i = 1; i <= count; ++i) values.push("holder.p" + i); 1524 return new Function("holder", " \n\ 1525 'use strict'; \n\ 1526 var callback = holder.fn; \n\ 1527 return callback(values); \n\ 1528 ".replace(/values/g, values.join(", "))); 1529 }; 1530 var thenCallbacks = []; 1531 var callers = [void 0]; 1532 for (var i = 1; i <= 5; ++i) { 1533 thenCallbacks.push(thenCallback(i)); 1534 callers.push(caller(i)); 1535 } 1536 1537 var Holder = function(total, fn) { 1538 this.p1 = this.p2 = this.p3 = this.p4 = this.p5 = null; 1539 this.fn = fn; 1540 this.total = total; 1541 this.now = 0; 1542 }; 1543 1544 Holder.prototype.callers = callers; 1545 Holder.prototype.checkFulfillment = function(promise) { 1546 var now = this.now; 1547 now++; 1548 var total = this.total; 1549 if (now >= total) { 1550 var handler = this.callers[total]; 1551 var ret = tryCatch1(handler, void 0, this); 1552 if (ret === errorObj) { 1553 promise._rejectUnchecked(ret.e); 1554 } else if (!promise._tryFollow(ret)) { 1555 promise._fulfillUnchecked(ret); 1556 } 1557 } else { 1558 this.now = now; 1559 } 1560 }; 1561} 1562 1563 1564 1565 1566Promise.join = function Promise$Join() { 1567 var last = arguments.length - 1; 1568 var fn; 1569 if (last > 0 && typeof arguments[last] === "function") { 1570 fn = arguments[last]; 1571 if (last < 6 && canEvaluate) { 1572 var ret = new Promise(INTERNAL); 1573 ret._setTrace(void 0); 1574 var holder = new Holder(last, fn); 1575 var reject = ret._reject; 1576 var callbacks = thenCallbacks; 1577 for (var i = 0; i < last; ++i) { 1578 var maybePromise = cast(arguments[i], void 0); 1579 if (maybePromise instanceof Promise) { 1580 if (maybePromise.isPending()) { 1581 maybePromise._then(callbacks[i], reject, 1582 void 0, ret, holder); 1583 } else if (maybePromise.isFulfilled()) { 1584 callbacks[i].call(ret, 1585 maybePromise._settledValue, holder); 1586 } else { 1587 ret._reject(maybePromise._settledValue); 1588 maybePromise._unsetRejectionIsUnhandled(); 1589 } 1590 } else { 1591 callbacks[i].call(ret, maybePromise, holder); 1592 } 1593 } 1594 return ret; 1595 } 1596 } 1597 var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];} 1598 var ret = new PromiseArray(args).promise(); 1599 return fn !== void 0 ? ret.spread(fn) : ret; 1600}; 1601 1602}; 1603 1604},{"./util.js":35}],17:[function(_dereq_,module,exports){ 1605/** 1606 * The MIT License (MIT) 1607 * 1608 * Copyright (c) 2014 Petka Antonov 1609 * 1610 * Permission is hereby granted, free of charge, to any person obtaining a copy 1611 * of this software and associated documentation files (the "Software"), to deal 1612 * in the Software without restriction, including without limitation the rights 1613 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1614 * copies of the Software, and to permit persons to whom the Software is 1615 * furnished to do so, subject to the following conditions:</p> 1616 * 1617 * The above copyright notice and this permission notice shall be included in 1618 * all copies or substantial portions of the Software. 1619 * 1620 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1621 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1622 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1623 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1624 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1625 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1626 * THE SOFTWARE. 1627 * 1628 */ 1629"use strict"; 1630module.exports = function(Promise, PromiseArray, apiRejection, cast, INT
1630ERNAL) { 1631var util = _dereq_("./util.js"); 1632var tryCatch3 = util.tryCatch3; 1633var errorObj = util.errorObj; 1634var PENDING = {}; 1635var EMPTY_ARRAY = []; 1636 1637function MappingPromiseArray(promises, fn, limit, _filter) { 1638 this.constructor$(promises); 1639 this._callback = fn; 1640 this._preservedValues = _filter === INTERNAL 1641 ? new Array(this.length()) 1642 : null; 1643 this._limit = limit; 1644 this._inFlight = 0; 1645 this._queue = limit >= 1 ? [] : EMPTY_ARRAY; 1646 this._init$(void 0, -2); 1647} 1648util.inherits(MappingPromiseArray, PromiseArray); 1649 1650MappingPromiseArray.prototype._init = function MappingPromiseArray$_init() {}; 1651 1652MappingPromiseArray.prototype._promiseFulfilled = 1653function MappingPromiseArray$_promiseFulfilled(value, index) { 1654 var values = this._values; 1655 if (values === null) return; 1656 1657 var length = this.length(); 1658 var preservedValues = this._preservedValues; 1659 var limit = this._limit; 1660 if (values[index] === PENDING) { 1661 values[index] = value; 1662 if (limit >= 1) { 1663 this._inFlight--; 1664 this._drainQueue(); 1665 if (this._isResolved()) return; 1666 } 1667 } else { 1668 if (limit >= 1 && this._inFlight >= limit) { 1669 values[index] = value; 1670 this._queue.push(index); 1671 return; 1672 } 1673 if (preservedValues !== null) preservedValues[index] = value; 1674 1675 var callback = this._callback; 1676 var receiver = this._promise._boundTo; 1677 var ret = tryCatch3(callback, receiver, value, index, length); 1678 if (ret === errorObj) return this._reject(ret.e); 1679 1680 var maybePromise = cast(ret, void 0); 1681 if (maybePromise instanceof Promise) { 1682 if (maybePromise.isPending()) { 1683 if (limit >= 1) this._inFlight++; 1684 values[index] = PENDING; 1685 return maybePromise._proxyPromiseArray(this, index); 1686 } else if (maybePromise.isFulfilled()) { 1687 ret = maybePromise.value(); 1688 } else { 1689 maybePromise._unsetRejectionIsUnhandled(); 1690 return this._reject(maybePromise.reason()); 1691 } 1692 } 1693 values[index] = ret; 1694 } 1695 var totalResolved = ++this._totalResolved; 1696 if (totalResolved >= length) { 1697 if (preservedValues !== null) { 1698 this._filter(values, preservedValues); 1699 } else { 1700 this._resolve(values); 1701 } 1702 1703 } 1704}; 1705 1706MappingPromiseArray.prototype._drainQueue = 1707function MappingPromiseArray$_drainQueue() { 1708 var queue = this._queue; 1709 var limit = this._limit; 1710 var values = this._values; 1711 while (queue.length > 0 && this._inFlight < limit) { 1712 var index = queue.pop(); 1713 this._promiseFulfilled(values[index], index); 1714 } 1715}; 1716 1717MappingPromiseArray.prototype._filter = 1718function MappingPromiseArray$_filter(booleans, values) { 1719 var len = values.length; 1720 var ret = new Array(len); 1721 var j = 0; 1722 for (var i = 0; i < len; ++i) { 1723 if (booleans[i]) ret[j++] = values[i]; 1724 } 1725 ret.length = j; 1726 this._resolve(ret); 1727}; 1728 1729MappingPromiseArray.prototype.preservedValues = 1730function MappingPromiseArray$preserveValues() { 1731 return this._preservedValues; 1732}; 1733 1734function map(promises, fn, options, _filter) { 1735 var limit = typeof options === "object" && options !== null 1736 ? options.concurrency 1737 : 0; 1738 limit = typeof limit === "number" && 1739 isFinite(limit) && limit >= 1 ? limit : 0; 1740 return new MappingPromiseArray(promises, fn, limit, _filter); 1741} 1742 1743Promise.prototype.map = function Promise$map(fn, options) { 1744 if (typeof fn !== "function") return apiRejection("fn must be a function"); 1745 1746 return map(this, fn, options, null).promise(); 1747}; 1748 1749Promise.map = function Promise$Map(promises, fn, options, _filter) { 1750 if (typeof fn !== "function") return apiRejection("fn must be a function"); 1751 return map(promises, fn, options, _filter).promise(); 1752}; 1753 1754 1755}; 1756 1757},{"./util.js":35}],18:[function(_dereq_,module,exports){ 1758/** 1759 * The MIT License (MIT) 1760 * 1761 * Copyright (c) 2014 Petka Antonov 1762 * 1763 * Permission is hereby granted, free of charge, to any person obtaining a copy 1764 * of this software and associated documentation files (the "Software"), to deal 1765 * in the Software without restriction, including without limitation the rights 1766 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1767 * copies of the Software, and to permit persons to whom the Software is 1768 * furnished to do so, subject to the following conditions:</p> 1769 * 1770 * The above copyright notice and this permission notice shall be included in 1771 * all copies or substantial portions of the Software. 1772 * 1773 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1774 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1775 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1776 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1777 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1778 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1779 * THE SOFTWARE. 1780 * 1781 */ 1782"use strict"; 1783module.exports = function(Promise) { 1784var util = _dereq_("./util.js"); 1785var async = _dereq_("./async.js"); 1786var tryCatch2 = util.tryCatch2; 1787var tryCatch1 = util.tryCatch1; 1788var errorObj = util.errorObj; 1789 1790function thrower(r) { 1791 throw r; 1792} 1793 1794function Promise$_spreadAdapter(val, receiver) { 1795 if (!util.isArray(val)) return Promise$_successAdapter(val, receiver); 1796 var ret = util.tryCatchApply(this, [null].concat(val), receiver); 1797 if (ret === errorObj) { 1798 async.invokeLater(thrower, void 0, ret.e); 1799 } 1800} 1801 1802function Promise$_successAdapter(val, receiver) { 1803 var nodeback = this; 1804 var ret = val === void 0
1805 ? tryCatch1(nodeback, receiver, null) 1806 : tryCatch2(nodeback, receiver, null, val); 1807 if (ret === errorObj) { 1808 async.invokeLater(thrower, void 0, ret.e); 1809 } 1810} 1811function Promise$_errorAdapter(reason, receiver) { 1812 var nodeback = this; 1813 var ret = tryCatch1(nodeback, receiver, reason); 1814 if (ret === errorObj) { 1815 async.invokeLater(thrower, void 0, ret.e); 1816 } 1817} 1818 1819Promise.prototype.nodeify = function Promise$nodeify(nodeback, options) { 1820 if (typeof nodeback == "function") { 1821 var adapter = Promise$_successAdapter; 1822 if (options !== void 0 && Object(options).spread) { 1823 adapter = Promise$_spreadAdapter; 1824 } 1825 this._then( 1826 adapter, 1827 Promise$_errorAdapter, 1828 void 0, 1829 nodeback, 1830 this._boundTo 1831 ); 1832 } 1833 return this; 1834}; 1835}; 1836 1837},{"./async.js":2,"./util.js":35}],19:[function(_dereq_,module,exports){ 1838/** 1839 * The MIT License (MIT) 1840 * 1841 * Copyright (c) 2014 Petka Antonov 1842 * 1843 * Permission is hereby granted, free of charge, to any person obtaining a copy 1844 * of this software and associated documentation files (the "Software"), to deal 1845 * in the Software without restriction, including without limitation the rights 1846 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1847 * copies of the Software, and to permit persons to whom the Software is 1848 * furnished to do so, subject to the following conditions:</p> 1849 * 1850 * The above copyright notice and this permission notice shall be included in 1851 * all copies or substantial portions of the Software. 1852 * 1853 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1854 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1855 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1856 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1857 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1858 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1859 * THE SOFTWARE. 1860 * 1861 */ 1862"use strict"; 1863module.exports = function(Promise, PromiseArray) { 1864var util = _dereq_("./util.js"); 1865var async = _dereq_("./async.js"); 1866var errors = _dereq_("./errors.js"); 1867var tryCatch1 = util.tryCatch1; 1868var errorObj = util.errorObj; 1869 1870Promise.prototype.progressed = function Promise$progressed(handler) { 1871 return this._then(void 0, void 0, handler, void 0, void 0); 1872}; 1873 1874Promise.prototype._progress = function Promise$_progress(progressValue) { 1875 if (this._isFollowingOrFulfilledOrRejected()) return; 1876 this._progressUnchecked(progressValue); 1877 1878}; 1879 1880Promise.prototype._clearFirstHandlerData$Base = 1881Promise.prototype._clearFirstHandlerData; 1882Promise.prototype._clearFirstHandlerData = 1883function Promise$_clearFirstHandlerData() { 1884 this._clearFirstHandlerData$Base(); 1885 this._progressHandler0 = void 0; 1886}; 1887 1888Promise.prototype._progressHandlerAt = 1889function Promise$_progressHandlerAt(index) { 1890 return index === 0 1891 ? this._progressHandler0 1892 : this[(index << 2) + index - 5 + 2]; 1893}; 1894 1895Promise.prototype._doProgressWith = 1896function Promise$_doProgressWith(progression) { 1897 var progressValue = progression.value; 1898 var handler = progression.handler; 1899 var promise = progression.promise; 1900 var receiver = progression.receiver; 1901 1902 var ret = tryCatch1(handler, receiver, progressValue); 1903 if (ret === errorObj) { 1904 if (ret.e != null && 1905 ret.e.name !== "StopProgressPropagation") { 1906 var trace = errors.canAttach(ret.e) 1907 ? ret.e : new Error(ret.e + ""); 1908 promise._attachExtraTrace(trace); 1909 promise._progress(ret.e); 1910 } 1911 } else if (ret instanceof Promise) { 1912 ret._then(promise._progress, null, null, promise, void 0); 1913 } else { 1914 promise._progress(ret); 1915 } 1916}; 1917 1918 1919Promise.prototype._progressUnchecked = 1920function Promise$_progressUnchecked(progressValue) { 1921 if (!this.isPending()) return; 1922 var len = this._length(); 1923 var progress = this._progress; 1924 for (var i = 0; i < len; i++) { 1925 var handler = this._progressHandlerAt(i); 1926 var promise = this._promiseAt(i); 1927 if (!(promise instanceof Promise)) { 1928 var receiver = this._receiverAt(i); 1929 if (typeof handler === "function") { 1930 handler.call(receiver, progressValue, promise); 1931 } else if (receiver instanceof Promise && receiver._isProxied()) { 1932 receiver._progressUnchecked(progressValue); 1933 } else if (receiver instanceof PromiseArray) { 1934 receiver._promiseProgressed(progressValue, promise); 1935 } 1936 continue; 1937 } 1938 1939 if (typeof handler === "function") { 1940 async.invoke(this._doProgressWith, this, { 1941 handler: handler, 1942 promise: promise, 1943 receiver: this._receiverAt(i), 1944 value: progressValue 1945 }); 1946 } else { 1947 async.invoke(progress, promise, progressValue); 1948 } 1949 } 1950}; 1951}; 1952 1953},{"./async.js":2,"./errors.js":10,"./util.js":35}],20:[function(_dereq_,module,exports){ 1954/** 1955 * The MIT License (MIT) 1956 * 1957 * Copyright (c) 2014 Petka Antonov 1958 * 1959 * Permission is hereby granted, free of charge, to any person obtaining a copy 1960 * of this software and associated documentation files (the "Software"), to deal 1961 * in the Software without restriction, including without limitation the rights 1962 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1963 * copies of the Software, and to permit persons to whom the Software is 1964 * furnished to do so, subject to the following conditions:</p> 1965 * 1966 * The above copyright notice and this permission notice shall be included in 1967 * all copies or substantial portions of the Software. 1968 * 1969 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1970 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1971 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1972 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1973 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1974 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1975 * THE SOFTWARE. 1976 * 1977 */ 1978"use strict"; 1979var old; 1980if (typeof Promise !== "undefined") old = Promise; 1981function noConflict(bluebird) { 1982 try { if (Promise === bluebird) Promise = old; } 1983 catch (e) {} 1984 return bluebird; 1985} 1986module.exports = function() { 1987var util = _dereq_("./util.js"); 1988var async = _dereq_("./async.js"); 1989var errors = _dereq_("./errors.js"); 1990 1991var INTERNAL = function(){}; 1992var APPLY = {}; 1993var NEXT_FILTER = {e: null}; 1994 1995var cast = _dereq_("./thenables.js")(Promise, INTERNAL); 1996var PromiseArray = _dereq_("./promise_array.js")(Promise, INTERNAL, cast); 1997var CapturedTrace = _dereq_("./captured_trace.js")(); 1998var CatchFilter = _dereq_("./catch_filter.js")(NEXT_FILTER); 1999var PromiseResolver = _dereq_("./promise_resolver.js"); 2000 2001var isArray = util.isArray; 2002 2003var errorObj = util.errorObj; 2004var tryCatch1 = util.tryCatch1; 2005var tryCatch2 = util.tryCatch2; 2006var tryCatchApply = util.tryCatchApply; 2007var RangeError = errors.RangeError; 2008var TypeError = errors.TypeError; 2009var CancellationError = errors.CancellationError; 2010var TimeoutError = errors.TimeoutError; 2011var OperationalError = errors.OperationalError; 2012var originatesFromRejection = errors.originatesFromRejection; 2013var markAsOriginatingFromRejection = errors.markAsOriginatingFromRejection; 2014var canAttach = errors.canAttach; 2015var thrower = util.thrower; 2016var apiRejection = _dereq_("./errors_api_rejection")(Promise); 2017 2018 2019var makeSelfResolutionError = function Promise$_makeSelfResolutionError() { 2020 return new TypeError("circular promise resolution chain"); 2021}; 2022 2023function Promise(resolver) { 2024 if (typeof resolver !== "function") { 2025 throw new TypeError("the promise constructor requires a resolver function"); 2026 } 2027 if (this.constructor !== Promise) { 2028 throw new TypeError("the promise constructor cannot be invoked directly"); 2029 } 2030 this._bitField = 0; 2031 this._fulfillmentHandler0 = void 0; 2032 this._rejectionHandler0 = void 0; 2033 this._promise0 = void 0; 2034 this._receiver0 = void 0; 2035 this._settledValue = void 0; 2036 this._boundTo = void 0; 2037 if (resolver !== INTERNAL) this._resolveFromResolver(resolver); 2038} 2039 2040function returnFirstElement(elements) { 2041 return elements[0]; 2042} 2043 2044Promise.prototype.bind = function Promise$bind(thisArg) { 2045 var maybePromise = cast(thisArg, void 0); 2046 var ret = new Promise(INTERNAL); 2047 if (maybePromise instanceof Promise) { 2048 var binder = maybePromise.then(function(thisArg) { 2049 ret._setBoundTo(thisArg); 2050 }); 2051 var p = Promise.all([this, binder]).then(returnFirstElement); 2052 ret._follow(p); 2053 } else { 2054 ret._follow(this); 2055 ret._setBoundTo(thisArg); 2056 } 2057 ret._propagateFrom(this, 2 | 1); 2058 return ret; 2059}; 2060 2061Promise.prototype.toString = function Promise$toString() { 2062 return "[object Promise]"; 2063}; 2064 2065Promise.prototype.caught = Promise.prototype["catch"] = 2066function Promise$catch(fn) { 2067 var len = arguments.length; 2068 if (len > 1) { 2069 var catchInstances = new Array(len - 1), 2070 j = 0, i; 2071 for (i = 0; i < len - 1; ++i) { 2072 var item = arguments[i]; 2073 if (typeof item === "function") { 2074 catchInstances[j++] = item; 2075 } else { 2076 var catchFilterTypeError = 2077 new TypeError( 2078 "A catch filter must be an error constructor " 2079 + "or a filter function"); 2080 2081 this._attachExtraTrace(catchFilterTypeError); 2082 return Promise.reject(catchFilterTypeError); 2083 } 2084 } 2085 catchInstances.length = j; 2086 fn = arguments[i]; 2087 2088 this._resetTrace(); 2089 var catchFilter = new CatchFilter(catchInstances, fn, this); 2090 return this._then(void 0, catchFilter.doFilter, void 0, 2091 catchFilter, void 0); 2092 } 2093 return this._then(void 0, fn, void 0, void 0, void 0); 2094}; 2095 2096function reflect() { 2097 return new Promise.PromiseInspection(this); 2098} 2099 2100Promise.prototype.reflect = function Promise$reflect() { 2101 return this._then(reflect, reflect, void 0, this, void 0); 2102}; 2103 2104Promise.prototype.then = 2105function Promise$then(didFulfill, didReject, didProgress) { 2106 return this._then(didFulfill, didReject, didProgress, 2107 void 0, void 0); 2108}; 2109 2110 2111Promise.prototype.done = 2112function Promise$done(didFulfill, didReject, didProgress) { 2113 var promise = this._then(didFulfill, didReject, didProgress, 2114 void 0, void 0); 2115 promise._setIsFinal(); 2116}; 2117 2118Promise.prototype.spread = function Promise$spread(didFulfill, didReject) { 2119 return this._then(didFulfill, didReject, void 0, 2120 APPLY, void 0); 2121}; 2122 2123Promise.prototype.isCancellable = function Promise$isCancellable() { 2124 return !this.isResolved() && 2125 this._cancellable(); 2126}; 2127 2128Promise.prototype.toJSON = function Promise$toJSON() { 2129 var ret = { 2130 isFulfilled: false, 2131 isRejected: false, 2132 fulfillmentValue: void 0, 2133 rejectionReason: void 0 2134 }; 2135 if (this.isFulfilled()) { 2136 ret.fulfillmentValue = this._settledValue; 2137 ret.isFulfilled = true; 2138 } else if (this.isRejected()) { 2139 ret.rejectionReason = this._settledValue; 2140 ret.isRejected = true; 2141 } 2142 return ret; 2143}; 2144 2145Promise.prototype.all = function Promise$all() { 2146 return new PromiseArray(this).promise(); 2147}; 2148 2149 2150Promise.is = function Promise$Is(val) { 2151 return val instanceof Promise; 2152}; 2153 2154Promise.all = function Promise$All(promises) { 2155 return new PromiseArray(promises).promise(); 2156}; 2157 2158Promise.prototype.error = function Promise$_error(fn) { 2159 return this.caught(originatesFromRejection, fn); 2160}; 2161 2162Promise.prototype._resolveFromSyncValue = 2163function Promise$_resolveFromSyncValue(value) { 2164 if (value === errorObj) { 2165 this._cleanValues(); 2166 this._setRejected(); 2167 this._settledValue = value.e; 2168 this._ensurePossibleRejectionHandled(); 2169 } else { 2170 var maybePromise = cast(value, void 0); 2171 if (maybePromise instanceof Promise) { 2172 this._follow(maybePromise); 2173 } else { 2174 this._cleanValues(); 2175 this._setFulfilled(); 2176 this._settledValue = value; 2177 } 2178 } 2179}; 2180 2181Promise.method = function Promise$_Method(fn) { 2182 if (typeof fn !== "function") { 2183 throw new TypeError("fn must be a function"); 2184 } 2185 return function Promise$_method() { 2186 var value; 2187 switch(arguments.length) { 2188 case 0: value = tryCatch1(fn, this, void 0); break; 2189 case 1: value = tryCatch1(fn, this, arguments[0]); break; 2190 case 2: value = tryCatch2(fn, this, arguments[0], arguments[1]); break; 2191 default: 2192 var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];} 2193 value = tryCatchApply(fn, args, this); break; 2194 } 2195 var ret = new Promise(INTERNAL); 2196 ret._setTrace(void 0); 2197 ret._resolveFromSyncValue(value); 2198 return ret; 2199 }; 2200}; 2201 2202Promise.attempt = Promise["try"] = function Promise$_Try(fn, args, ctx) { 2203 if (typeof fn !== "function") { 2204 return apiRejection("fn must be a function"); 2205 } 2206 var value = isArray(args)
2207 ? tryCatchApply(fn, args, ctx) 2208 : tryCatch1(fn, ctx, args); 2209 2210 var ret = new Promise(INTERNAL); 2211 ret._setTrace(void 0); 2212 ret._resolveFromSyncValue(value); 2213 return ret; 2214}; 2215 2216Promise.defer = Promise.pending = function Promise$Defer() { 2217 var promise = new Promise(INTERNAL); 2218 promise._setTrace(void 0); 2219 return new PromiseResolver(promise); 2220}; 2221 2222Promise.bind = function Promise$Bind(thisArg) { 2223 var maybePromise = cast(thisArg, void 0); 2224 var ret = new Promise(INTERNAL); 2225 ret._setTrace(void 0); 2226 2227 if (maybePromise instanceof Promise) { 2228 var p = maybePromise.then(function(thisArg) { 2229 ret._setBoundTo(thisArg); 2230 }); 2231 ret._follow(p); 2232 } else { 2233 ret._setBoundTo(thisArg); 2234 ret._setFulfilled(); 2235 } 2236 return ret; 2237}; 2238 2239Promise.cast = function Promise$_Cast(obj) { 2240 var ret = cast(obj, void 0); 2241 if (!(ret instanceof Promise)) { 2242 var val = ret; 2243 ret = new Promise(INTERNAL); 2244 ret._setTrace(void 0); 2245 ret._setFulfilled(); 2246 ret._cleanValues(); 2247 ret._settledValue = val; 2248 } 2249 return ret; 2250}; 2251 2252Promise.resolve = Promise.fulfilled = Promise.cast; 2253 2254Promise.reject = Promise.rejected = function Promise$Reject(reason) { 2255 var ret = new Promise(INTERNAL); 2256 ret._setTrace(void 0); 2257 markAsOriginatingFromRejection(reason); 2258 ret._cleanValues(); 2259 ret._setRejected(); 2260 ret._settledValue = reason; 2261 if (!canAttach(reason)) { 2262 var trace = new Error(reason + ""); 2263 ret._setCarriedStackTrace(trace); 2264 } 2265 ret._ensurePossibleRejectionHandled(); 2266 return ret; 2267}; 2268 2269Promise.onPossiblyUnhandledRejection = 2270function Promise$OnPossiblyUnhandledRejection(fn) { 2271 CapturedTrace.possiblyUnhandledRejection = typeof fn === "function" 2272 ? fn : void 0; 2273}; 2274 2275var unhandledRejectionHandled; 2276Promise.onUnhandledRejectionHandled = 2277function Promise$onUnhandledRejectionHandled(fn) { 2278 unhandledRejectionHandled = typeof fn === "function" ? fn : void 0; 2279}; 2280 2281var debugging = false || !!( 2282 typeof process !== "undefined" && 2283 typeof process.execPath === "string" && 2284 typeof process.env === "object" && 2285 (process.env["BLUEBIRD_DEBUG"] || 2286 process.env["NODE_ENV"] === "development") 2287); 2288 2289 2290Promise.longStackTraces = function Promise$LongStackTraces() { 2291 if (async.haveItemsQueued() && 2292 debugging === false 2293 ) { 2294 throw new Error("cannot enable long stack traces after promises have been created"); 2295 } 2296 debugging = CapturedTrace.isSupported(); 2297}; 2298 2299Promise.hasLongStackTraces = function Promise$HasLongStackTraces() { 2300 return debugging && CapturedTrace.isSupported(); 2301}; 2302 2303Promise.prototype._then = 2304function Promise$_then( 2305 didFulfill, 2306 didReject, 2307 didProgress, 2308 receiver, 2309 internalData 2310) { 2311 var haveInternalData = internalData !== void 0; 2312 var ret = haveInternalData ? internalData : new Promise(INTERNAL); 2313 2314 if (!haveInternalData) { 2315 if (debugging) { 2316 var haveSameContext = this._peekContext() === this._traceParent; 2317 ret._traceParent = haveSameContext ? this._traceParent : this; 2318 } 2319 ret._propagateFrom(this, 7); 2320 } 2321 2322 var callbackIndex = 2323 this._addCallbacks(didFulfill, didReject, didProgress, ret, receiver); 2324 2325 if (this.isResolved()) { 2326 async.invoke(this._queueSettleAt, this, callbackIndex); 2327 } 2328 2329 return ret; 2330}; 2331 2332Promise.prototype._length = function Promise$_length() { 2333 return this._bitField & 262143; 2334}; 2335 2336Promise.prototype._isFollowingOrFulfilledOrRejected = 2337function Promise$_isFollowingOrFulfilledOrRejected() { 2338 return (this._bitField & 939524096) > 0; 2339}; 2340 2341Promise.prototype._isFollowing = function Promise$_isFollowing() { 2342 return (this._bitField & 536870912) === 536870912; 2343}; 2344 2345Promise.prototype._setLength = function Promise$_setLength(len) { 2346 this._bitField = (this._bitField & -262144) | 2347 (len & 262143); 2348}; 2349 2350Promise.prototype._setFulfilled = function Promise$_setFulfilled() { 2351 this._bitField = this._bitField | 268435456; 2352}; 2353 2354Promise.prototype._setRejected = function Promise$_setRejected() { 2355 this._bitField = this._bitField | 134217728; 2356}; 2357 2358Promise.prototype._setFollowing = function Promise$_setFollowing() { 2359 this._bitField = this._bitField | 536870912; 2360}; 2361 2362Promise.prototype._setIsFinal = function Promise$_setIsFinal() { 2363 this._bitField = this._bitField | 33554432; 2364}; 2365 2366Promise.prototype._isFinal = function Promise$_isFinal() { 2367 return (this._bitField & 33554432) > 0; 2368}; 2369 2370Promise.prototype._cancellable = function Promise$_cancellable() { 2371 return (this._bitField & 67108864) > 0; 2372}; 2373 2374Promise.prototype._setCancellable = function Promise$_setCancellable() { 2375 this._bitField = this._bitField | 67108864; 2376}; 2377 2378Promise.prototype._unsetCancellable = function Promise$_unsetCancellable() { 2379 this._bitField = this._bitField & (~67108864); 2380}; 2381 2382Promise.prototype._setRejectionIsUnhandled = 2383function Promise$_setRejectionIsUnhandled() { 2384 this._bitField = this._bitField | 2097152; 2385}; 2386 2387Promise.prototype._unsetRejectionIsUnhandled = 2388function Promise$_unsetRejectionIsUnhandled() { 2389 this._bitField = this._bitField & (~2097152); 2390 if (this._isUnhandledRejectionNotified()) { 2391 this._unsetUnhandledRejectionIsNotified(); 2392 this._notifyUnhandledRejectionIsHandled(); 2393 } 2394}; 2395 2396Promise.prototype._isRejectionUnhandled = 2397function Promise$_isRejectionUnhandled() { 2398 return (this._bitField & 2097152) > 0; 2399}; 2400 2401Promise.prototype._setUnhandledRejectionIsNotified = 2402function Promise$_setUnhandledRejectionIsNotified() { 2403 this._bitField = this._bitField | 524288; 2404}; 2405 2406Promise.prototype._unsetUnhandledRejectionIsNotified = 2407function Promise$_unsetUnhandledRejectionIsNotified() { 2408 this._bitField = this._bitField & (~524288); 2409}; 2410
2411Promise.prototype._isUnhandledRejectionNotified = 2412function Promise$_isUnhandledRejectionNotified() { 2413 return (this._bitField & 524288) > 0; 2414}; 2415 2416Promise.prototype._setCarriedStackTrace = 2417function Promise$_setCarriedStackTrace(capturedTrace) { 2418 this._bitField = this._bitField | 1048576; 2419 this._fulfillmentHandler0 = capturedTrace; 2420}; 2421 2422Promise.prototype._unsetCarriedStackTrace = 2423function Promise$_unsetCarriedStackTrace() { 2424 this._bitField = this._bitField & (~1048576); 2425 this._fulfillmentHandler0 = void 0; 2426}; 2427 2428Promise.prototype._isCarryingStackTrace = 2429function Promise$_isCarryingStackTrace() { 2430 return (this._bitField & 1048576) > 0; 2431}; 2432 2433Promise.prototype._getCarriedStackTrace = 2434function Promise$_getCarriedStackTrace() { 2435 return this._isCarryingStackTrace() 2436 ? this._fulfillmentHandler0 2437 : void 0; 2438}; 2439 2440Promise.prototype._receiverAt = function Promise$_receiverAt(index) { 2441 var ret = index === 0 2442 ? this._receiver0 2443 : this[(index << 2) + index - 5 + 4]; 2444 if (this._isBound() && ret === void 0) { 2445 return this._boundTo; 2446 } 2447 return ret; 2448}; 2449 2450Promise.prototype._promiseAt = function Promise$_promiseAt(index) { 2451 return index === 0 2452 ? this._promise0 2453 : this[(index << 2) + index - 5 + 3]; 2454}; 2455 2456Promise.prototype._fulfillmentHandlerAt = 2457function Promise$_fulfillmentHandlerAt(index) { 2458 return index === 0 2459 ? this._fulfillmentHandler0 2460 : this[(index << 2) + index - 5 + 0]; 2461}; 2462 2463Promise.prototype._rejectionHandlerAt = 2464function Promise$_rejectionHandlerAt(index) { 2465 return index === 0 2466 ? this._rejectionHandler0 2467 : this[(index << 2) + index - 5 + 1]; 2468}; 2469 2470Promise.prototype._addCallbacks = function Promise$_addCallbacks( 2471 fulfill, 2472 reject, 2473 progress, 2474 promise, 2475 receiver 2476) { 2477 var index = this._length(); 2478 2479 if (index >= 262143 - 5) { 2480 index = 0; 2481 this._setLength(0); 2482 } 2483 2484 if (index === 0) { 2485 this._promise0 = promise; 2486 if (receiver !== void 0) this._receiver0 = receiver; 2487 if (typeof fulfill === "function" && !this._isCarryingStackTrace()) 2488 this._fulfillmentHandler0 = fulfill; 2489 if (typeof reject === "function") this._rejectionHandler0 = reject; 2490 if (typeof progress === "function") this._progressHandler0 = progress; 2491 } else { 2492 var base = (index << 2) + index - 5; 2493 this[base + 3] = promise; 2494 this[base + 4] = receiver; 2495 this[base + 0] = typeof fulfill === "function" 2496 ? fulfill : void 0; 2497 this[base + 1] = typeof reject === "function" 2498 ? reject : void 0; 2499 this[base + 2] = typeof progress === "function" 2500 ? progress : void 0; 2501 } 2502 this._setLength(index + 1); 2503 return index; 2504}; 2505 2506Promise.prototype._setProxyHandlers = 2507function Promise$_setProxyHandlers(receiver, promiseSlotValue) { 2508 var index = this._length(); 2509 2510 if (index >= 262143 - 5) { 2511 index = 0; 2512 this._setLength(0); 2513 } 2514 if (index === 0) { 2515 this._promise0 = promiseSlotValue; 2516 this._receiver0 = receiver; 2517 } else { 2518 var base = (index << 2) + index - 5; 2519 this[base + 3] = promiseSlotValue; 2520 this[base + 4] = receiver; 2521 this[base + 0] = 2522 this[base + 1] = 2523 this[base + 2] = void 0; 2524 } 2525 this._setLength(index + 1); 2526}; 2527 2528Promise.prototype._proxyPromiseArray = 2529function Promise$_proxyPromiseArray(promiseArray, index) { 2530 this._setProxyHandlers(promiseArray, index); 2531}; 2532 2533Promise.prototype._proxyPromise = function Promise$_proxyPromise(promise) { 2534 promise._setProxied(); 2535 this._setProxyHandlers(promise, -15); 2536}; 2537 2538Promise.prototype._setBoundTo = function Promise$_setBoundTo(obj) { 2539 if (obj !== void 0) { 2540 this._bitField = this._bitField | 8388608; 2541 this._boundTo = obj; 2542 } else { 2543 this._bitField = this._bitField & (~8388608); 2544 } 2545}; 2546 2547Promise.prototype._isBound = function Promise$_isBound() { 2548 return (this._bitField & 8388608) === 8388608; 2549}; 2550 2551Promise.prototype._resolveFromResolver = 2552function Promise$_resolveFromResolver(resolver) { 2553 var promise = this; 2554 this._setTrace(void 0); 2555 this._pushContext(); 2556 2557 function Promise$_resolver(val) { 2558 if (promise._tryFollow(val)) { 2559 return; 2560 } 2561 promise._fulfill(val); 2562 } 2563 function Promise$_rejecter(val) { 2564 var trace = canAttach(val) ? val : new Error(val + ""); 2565 promise._attachExtraTrace(trace); 2566 markAsOriginatingFromRejection(val); 2567 promise._reject(val, trace === val ? void 0 : trace); 2568 } 2569 var r = tryCatch2(resolver, void 0, Promise$_resolver, Promise$_rejecter); 2570 this._popContext(); 2571 2572 if (r !== void 0 && r === errorObj) { 2573 var e = r.e; 2574 var trace = canAttach(e) ? e : new Error(e + ""); 2575 promise._reject(e, trace); 2576 } 2577}; 2578 2579Promise.prototype._spreadSlowCase = 2580function Promise$_spreadSlowCase(targetFn, promise, values, boundTo) { 2581 var promiseForAll = new PromiseArray(values).promise(); 2582 var promise2 = promiseForAll._then(function() { 2583 return targetFn.apply(boundTo, arguments); 2584 }, void 0, void 0, APPLY, void 0); 2585 promise._follow(promise2); 2586}; 2587 2588Promise.prototype._callSpread = 2589function Promise$_callSpread(handler, promise, value) { 2590 var boundTo = this._boundTo; 2591 if (isArray(value)) { 2592 for (var i = 0, len = value.length; i < len; ++i) { 2593 if (cast(value[i], void 0) instanceof Promise) { 2594 this._spreadSlowCase(handler, promise, value, boundTo); 2595 return; 2596 } 2597 } 2598 } 2599 promise._pushContext();
2600 return tryCatchApply(handler, value, boundTo); 2601}; 2602 2603Promise.prototype._callHandler = 2604function Promise$_callHandler( 2605 handler, receiver, promise, value) { 2606 var x; 2607 if (receiver === APPLY && !this.isRejected()) { 2608 x = this._callSpread(handler, promise, value); 2609 } else { 2610 promise._pushContext(); 2611 x = tryCatch1(handler, receiver, value); 2612 } 2613 promise._popContext(); 2614 return x; 2615}; 2616 2617Promise.prototype._settlePromiseFromHandler = 2618function Promise$_settlePromiseFromHandler( 2619 handler, receiver, value, promise 2620) { 2621 if (!(promise instanceof Promise)) { 2622 handler.call(receiver, value, promise); 2623 return; 2624 } 2625 var x = this._callHandler(handler, receiver, promise, value); 2626 if (promise._isFollowing()) return; 2627 2628 if (x === errorObj || x === promise || x === NEXT_FILTER) { 2629 var err = x === promise 2630 ? makeSelfResolutionError() 2631 : x.e; 2632 var trace = canAttach(err) ? err : new Error(err + ""); 2633 if (x !== NEXT_FILTER) promise._attachExtraTrace(trace); 2634 promise._rejectUnchecked(err, trace); 2635 } else { 2636 var castValue = cast(x, promise); 2637 if (castValue instanceof Promise) { 2638 if (castValue.isRejected() && 2639 !castValue._isCarryingStackTrace() && 2640 !canAttach(castValue._settledValue)) { 2641 var trace = new Error(castValue._settledValue + ""); 2642 promise._attachExtraTrace(trace); 2643 castValue._setCarriedStackTrace(trace); 2644 } 2645 promise._follow(castValue); 2646 promise._propagateFrom(castValue, 1); 2647 } else { 2648 promise._fulfillUnchecked(x); 2649 } 2650 } 2651}; 2652 2653Promise.prototype._follow = 2654function Promise$_follow(promise) { 2655 this._setFollowing(); 2656 2657 if (promise.isPending()) { 2658 this._propagateFrom(promise, 1); 2659 promise._proxyPromise(this); 2660 } else if (promise.isFulfilled()) { 2661 this._fulfillUnchecked(promise._settledValue); 2662 } else { 2663 this._rejectUnchecked(promise._settledValue, 2664 promise._getCarriedStackTrace()); 2665 } 2666 2667 if (promise._isRejectionUnhandled()) promise._unsetRejectionIsUnhandled(); 2668 2669 if (debugging && 2670 promise._traceParent == null) { 2671 promise._traceParent = this; 2672 } 2673}; 2674 2675Promise.prototype._tryFollow = 2676function Promise$_tryFollow(value) { 2677 if (this._isFollowingOrFulfilledOrRejected() || 2678 value === this) { 2679 return false; 2680 } 2681 var maybePromise = cast(value, void 0); 2682 if (!(maybePromise instanceof Promise)) { 2683 return false; 2684 } 2685 this._follow(maybePromise); 2686 return true; 2687}; 2688 2689Promise.prototype._resetTrace = function Promise$_resetTrace() { 2690 if (debugging) { 2691 this._trace = new CapturedTrace(this._peekContext() === void 0); 2692 } 2693}; 2694 2695Promise.prototype._setTrace = function Promise$_setTrace(parent) { 2696 if (debugging) { 2697 var context = this._peekContext(); 2698 this._traceParent = context; 2699 var isTopLevel = context === void 0; 2700 if (parent !== void 0 && 2701 parent._traceParent === context) { 2702 this._trace = parent._trace; 2703 } else { 2704 this._trace = new CapturedTrace(isTopLevel); 2705 } 2706 } 2707 return this; 2708}; 2709 2710Promise.prototype._attachExtraTrace = 2711function Promise$_attachExtraTrace(error) { 2712 if (debugging) { 2713 var promise = this; 2714 var stack = error.stack; 2715 stack = typeof stack === "string" ? stack.split("\n") : []; 2716 CapturedTrace.protectErrorMessageNewlines(stack); 2717 var headerLineCount = 1; 2718 var combinedTraces = 1; 2719 while(promise != null && 2720 promise._trace != null) { 2721 stack = CapturedTrace.combine( 2722 stack, 2723 promise._trace.stack.split("\n") 2724 ); 2725 promise = promise._traceParent; 2726 combinedTraces++; 2727 } 2728 2729 var stackTraceLimit = Error.stackTraceLimit || 10; 2730 var max = (stackTraceLimit + headerLineCount) * combinedTraces; 2731 var len = stack.length; 2732 if (len > max) { 2733 stack.length = max; 2734 } 2735 2736 if (len > 0) 2737 stack[0] = stack[0].split("\u0002\u0000\u0001").join("\n"); 2738 2739 if (stack.length <= headerLineCount) { 2740 error.stack = "(No stack trace)"; 2741 } else { 2742 error.stack = stack.join("\n"); 2743 } 2744 } 2745}; 2746 2747Promise.prototype._cleanValues = function Promise$_cleanValues() { 2748 if (this._cancellable()) { 2749 this._cancellationParent = void 0; 2750 } 2751}; 2752 2753Promise.prototype._propagateFrom = 2754function Promise$_propagateFrom(parent, flags) { 2755 if ((flags & 1) > 0 && parent._cancellable()) { 2756 this._setCancellable(); 2757 this._cancellationParent = parent; 2758 } 2759 if ((flags & 4) > 0) { 2760 this._setBoundTo(parent._boundTo); 2761 } 2762 if ((flags & 2) > 0) { 2763 this._setTrace(parent); 2764 } 2765}; 2766 2767Promise.prototype._fulfill = function Promise$_fulfill(value) { 2768 if (this._isFollowingOrFulfilledOrRejected()) return; 2769 this._fulfillUnchecked(value); 2770}; 2771 2772Promise.prototype._reject = 2773function Promise$_reject(reason, carriedStackTrace) { 2774 if (this._isFollowingOrFulfilledOrRejected()) return; 2775 this._rejectUnchecked(reason, carriedStackTrace); 2776}; 2777 2778Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) { 2779 var handler = this.isFulfilled() 2780 ? this._fulfillmentHandlerAt(index) 2781 : this._rejectionHandlerAt(index); 2782 2783 var value = this._settledValue; 2784 var receiver = this._receiverAt(index); 2785 var promise = this._promiseAt(index); 2786 2787 if (typeof handler === "function") { 2788 this._settlePromiseFromHandler(handler, receiver, value, promise); 2789 } else { 2790 var done = false;
2791 var isFulfilled = this.isFulfilled(); 2792 if (receiver !== void 0) { 2793 if (receiver instanceof Promise && 2794 receiver._isProxied()) { 2795 receiver._unsetProxied(); 2796 2797 if (isFulfilled) receiver._fulfillUnchecked(value); 2798 else receiver._rejectUnchecked(value, 2799 this._getCarriedStackTrace()); 2800 done = true; 2801 } else if (receiver instanceof PromiseArray) { 2802 if (isFulfilled) receiver._promiseFulfilled(value, promise); 2803 else receiver._promiseRejected(value, promise); 2804 done = true; 2805 } 2806 } 2807 2808 if (!done) { 2809 if (isFulfilled) promise._fulfill(value); 2810 else promise._reject(value, this._getCarriedStackTrace()); 2811 } 2812 } 2813 2814 if (index >= 4) { 2815 this._queueGC(); 2816 } 2817}; 2818 2819Promise.prototype._isProxied = function Promise$_isProxied() { 2820 return (this._bitField & 4194304) === 4194304; 2821}; 2822 2823Promise.prototype._setProxied = function Promise$_setProxied() { 2824 this._bitField = this._bitField | 4194304; 2825}; 2826 2827Promise.prototype._unsetProxied = function Promise$_unsetProxied() { 2828 this._bitField = this._bitField & (~4194304); 2829}; 2830 2831Promise.prototype._isGcQueued = function Promise$_isGcQueued() { 2832 return (this._bitField & -1073741824) === -1073741824; 2833}; 2834 2835Promise.prototype._setGcQueued = function Promise$_setGcQueued() { 2836 this._bitField = this._bitField | -1073741824; 2837}; 2838 2839Promise.prototype._unsetGcQueued = function Promise$_unsetGcQueued() { 2840 this._bitField = this._bitField & (~-1073741824); 2841}; 2842 2843Promise.prototype._queueGC = function Promise$_queueGC() { 2844 if (this._isGcQueued()) return; 2845 this._setGcQueued(); 2846 async.invokeLater(this._gc, this, void 0); 2847}; 2848 2849Promise.prototype._gc = function Promise$gc() { 2850 var len = this._length() * 5 - 5; 2851 for (var i = 0; i < len; i++) { 2852 delete this[i]; 2853 } 2854 this._clearFirstHandlerData(); 2855 this._setLength(0); 2856 this._unsetGcQueued(); 2857}; 2858 2859Promise.prototype._clearFirstHandlerData = 2860function Promise$_clearFirstHandlerData() { 2861 this._fulfillmentHandler0 = void 0; 2862 this._rejectionHandler0 = void 0; 2863 this._promise0 = void 0; 2864 this._receiver0 = void 0; 2865}; 2866 2867Promise.prototype._queueSettleAt = function Promise$_queueSettleAt(index) { 2868 if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled(); 2869 async.invoke(this._settlePromiseAt, this, index); 2870}; 2871 2872Promise.prototype._fulfillUnchecked = 2873function Promise$_fulfillUnchecked(value) { 2874 if (!this.isPending()) return; 2875 if (value === this) { 2876 var err = makeSelfResolutionError(); 2877 this._attachExtraTrace(err); 2878 return this._rejectUnchecked(err, void 0); 2879 } 2880 this._cleanValues(); 2881 this._setFulfilled(); 2882 this._settledValue = value; 2883 var len = this._length(); 2884 2885 if (len > 0) { 2886 async.invoke(this._settlePromises, this, len); 2887 } 2888}; 2889 2890Promise.prototype._rejectUncheckedCheckError = 2891function Promise$_rejectUncheckedCheckError(reason) { 2892 var trace = canAttach(reason) ? reason : new Error(reason + ""); 2893 this._rejectUnchecked(reason, trace === reason ? void 0 : trace); 2894}; 2895 2896Promise.prototype._rejectUnchecked = 2897function Promise$_rejectUnchecked(reason, trace) { 2898 if (!this.isPending()) return; 2899 if (reason === this) { 2900 var err = makeSelfResolutionError(); 2901 this._attachExtraTrace(err); 2902 return this._rejectUnchecked(err); 2903 } 2904 this._cleanValues(); 2905 this._setRejected(); 2906 this._settledValue = reason; 2907 2908 if (this._isFinal()) { 2909 async.invokeLater(thrower, void 0, trace === void 0 ? reason : trace); 2910 return; 2911 } 2912 var len = this._length(); 2913 2914 if (trace !== void 0) this._setCarriedStackTrace(trace); 2915 2916 if (len > 0) { 2917 async.invoke(this._rejectPromises, this, null); 2918 } else { 2919 this._ensurePossibleRejectionHandled(); 2920 } 2921}; 2922 2923Promise.prototype._rejectPromises = function Promise$_rejectPromises() { 2924 this._settlePromises(); 2925 this._unsetCarriedStackTrace(); 2926}; 2927 2928Promise.prototype._settlePromises = function Promise$_settlePromises() { 2929 var len = this._length(); 2930 for (var i = 0; i < len; i++) { 2931 this._settlePromiseAt(i); 2932 } 2933}; 2934 2935Promise.prototype._ensurePossibleRejectionHandled = 2936function Promise$_ensurePossibleRejectionHandled() { 2937 this._setRejectionIsUnhandled(); 2938 if (CapturedTrace.possiblyUnhandledRejection !== void 0) { 2939 async.invokeLater(this._notifyUnhandledRejection, this, void 0); 2940 } 2941}; 2942 2943Promise.prototype._notifyUnhandledRejectionIsHandled = 2944function Promise$_notifyUnhandledRejectionIsHandled() { 2945 if (typeof unhandledRejectionHandled === "function") { 2946 async.invokeLater(unhandledRejectionHandled, void 0, this); 2947 } 2948}; 2949 2950Promise.prototype._notifyUnhandledRejection = 2951function Promise$_notifyUnhandledRejection() { 2952 if (this._isRejectionUnhandled()) { 2953 var reason = this._settledValue; 2954 var trace = this._getCarriedStackTrace(); 2955 2956 this._setUnhandledRejectionIsNotified(); 2957 2958 if (trace !== void 0) { 2959 this._unsetCarriedStackTrace(); 2960 reason = trace; 2961 } 2962 if (typeof CapturedTrace.possiblyUnhandledRejection === "function") { 2963 CapturedTrace.possiblyUnhandledRejection(reason, this); 2964 } 2965 } 2966}; 2967
2968var contextStack = []; 2969Promise.prototype._peekContext = function Promise$_peekContext() { 2970 var lastIndex = contextStack.length - 1; 2971 if (lastIndex >= 0) { 2972 return contextStack[lastIndex]; 2973 } 2974 return void 0; 2975 2976}; 2977 2978Promise.prototype._pushContext = function Promise$_pushContext() { 2979 if (!debugging) return; 2980 contextStack.push(this); 2981}; 2982 2983Promise.prototype._popContext = function Promise$_popContext() { 2984 if (!debugging) return; 2985 contextStack.pop(); 2986}; 2987 2988Promise.noConflict = function Promise$NoConflict() { 2989 return noConflict(Promise); 2990}; 2991 2992Promise.setScheduler = function(fn) { 2993 if (typeof fn !== "function") throw new TypeError("fn must be a function"); 2994 async._schedule = fn; 2995}; 2996 2997if (!CapturedTrace.isSupported()) { 2998 Promise.longStackTraces = function(){}; 2999 debugging = false; 3000} 3001 3002Promise._makeSelfResolutionError = makeSelfResolutionError; 3003_dereq_("./finally.js")(Promise, NEXT_FILTER, cast); 3004_dereq_("./direct_resolve.js")(Promise); 3005_dereq_("./synchronous_inspection.js")(Promise); 3006_dereq_("./join.js")(Promise, PromiseArray, cast, INTERNAL); 3007Promise.RangeError = RangeError; 3008Promise.CancellationError = CancellationError; 3009Promise.TimeoutError = TimeoutError; 3010Promise.TypeError = TypeError; 3011Promise.OperationalError = OperationalError; 3012Promise.RejectionError = OperationalError; 3013Promise.AggregateError = errors.AggregateError; 3014 3015util.toFastProperties(Promise); 3016util.toFastProperties(Promise.prototype); 3017Promise.Promise = Promise; 3018_dereq_('./timers.js')(Promise,INTERNAL,cast); 3019_dereq_('./race.js')(Promise,INTERNAL,cast); 3020_dereq_('./call_get.js')(Promise); 3021_dereq_('./generators.js')(Promise,apiRejection,INTERNAL,cast); 3022_dereq_('./map.js')(Promise,PromiseArray,apiRejection,cast,INTERNAL); 3023_dereq_('./nodeify.js')(Promise); 3024_dereq_('./promisify.js')(Promise,INTERNAL); 3025_dereq_('./props.js')(Promise,PromiseArray,cast); 3026_dereq_('./reduce.js')(Promise,PromiseArray,apiRejection,cast,INTERNAL); 3027_dereq_('./settle.js')(Promise,PromiseArray); 3028_dereq_('./some.js')(Promise,PromiseArray,apiRejection); 3029_dereq_('./progress.js')(Promise,PromiseArray); 3030_dereq_('./cancel.js')(Promise,INTERNAL); 3031_dereq_('./filter.js')(Promise,INTERNAL); 3032_dereq_('./any.js')(Promise,PromiseArray); 3033_dereq_('./each.js')(Promise,INTERNAL); 3034_dereq_('./using.js')(Promise,apiRejection,cast); 3035 3036Promise.prototype = Promise.prototype; 3037return Promise; 3038 3039}; 3040 3041},{"./any.js":1,"./async.js":2,"./call_get.js":4,"./cancel.js":5,"./captured_trace.js":6,"./catch_filter.js":7,"./direct_resolve.js":8,"./each.js":9,"./errors.js":10,"./errors_api_rejection":11,"./filter.js":13,"./finally.js":14,"./generators.js":15,"./join.js":16,"./map.js":17,"./nodeify.js":18,"./progress.js":19,"./promise_array.js":21,"./promise_resolver.js":22,"./promisify.js":23,"./props.js":24,"./race.js":26,"./reduce.js":27,"./settle.js":29,"./some.js":30,"./synchronous_inspection.js":31,"./thenables.js":32,"./timers.js":33,"./using.js":34,"./util.js":35}],21:[function(_dereq_,module,exports){ 3042/** 3043 * The MIT License (MIT) 3044 * 3045 * Copyright (c) 2014 Petka Antonov 3046 * 3047 * Permission is hereby granted, free of charge, to any person obtaining a copy 3048 * of this software and associated documentation files (the "Software"), to deal 3049 * in the Software without restriction, including without limitation the rights 3050 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 3051 * copies of the Software, and to permit persons to whom the Software is 3052 * furnished to do so, subject to the following conditions:</p> 3053 * 3054 * The above copyright notice and this permission notice shall be included in 3055 * all copies or substantial portions of the Software. 3056 * 3057 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 3058 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 3059 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 3060 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 3061 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 3062 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 3063 * THE SOFTWARE. 3064 * 3065 */ 3066"use strict"; 3067module.exports = function(Promise, INTERNAL, cast) { 3068var canAttach = _dereq_("./errors.js").canAttach; 3069var util = _dereq_("./util.js"); 3070var isArray = util.isArray; 3071 3072function toResolutionValue(val) { 3073 switch(val) { 3074 case -1: return void 0; 3075 case -2: return []; 3076 case -3: return {}; 3077 } 3078} 3079 3080function PromiseArray(values) { 3081 var promise = this._promise = new Promise(INTERNAL); 3082 var parent = void 0; 3083 if (values instanceof Promise) { 3084 parent = values;
3085 promise._propagateFrom(parent, 1 | 4); 3086 } 3087 promise._setTrace(parent); 3088 this._values = values; 3089 this._length = 0; 3090 this._totalResolved = 0; 3091 this._init(void 0, -2); 3092} 3093PromiseArray.prototype.length = function PromiseArray$length() { 3094 return this._length; 3095}; 3096 3097PromiseArray.prototype.promise = function PromiseArray$promise() { 3098 return this._promise; 3099}; 3100 3101PromiseArray.prototype._init = 3102function PromiseArray$_init(_, resolveValueIfEmpty) { 3103 var values = cast(this._values, void 0); 3104 if (values instanceof Promise) { 3105 this._values = values; 3106 values._setBoundTo(this._promise._boundTo); 3107 if (values.isFulfilled()) { 3108 values = values._settledValue; 3109 if (!isArray(values)) { 3110 var err = new Promise.TypeError("expecting an array, a promise or a thenable"); 3111 this.__hardReject__(err); 3112 return; 3113 } 3114 } else if (values.isPending()) { 3115 values._then( 3116 PromiseArray$_init, 3117 this._reject, 3118 void 0, 3119 this, 3120 resolveValueIfEmpty 3121 ); 3122 return; 3123 } else { 3124 values._unsetRejectionIsUnhandled(); 3125 this._reject(values._settledValue); 3126 return; 3127 } 3128 } else if (!isArray(values)) { 3129 var err = new Promise.TypeError("expecting an array, a promise or a thenable"); 3130 this.__hardReject__(err); 3131 return; 3132 } 3133 3134 if (values.length === 0) { 3135 if (resolveValueIfEmpty === -5) { 3136 this._resolveEmptyArray(); 3137 } 3138 else { 3139 this._resolve(toResolutionValue(resolveValueIfEmpty)); 3140 } 3141 return; 3142 } 3143 var len = this.getActualLength(values.length); 3144 var newLen = len; 3145 var newValues = this.shouldCopyValues() ? new Array(len) : this._values; 3146 var isDirectScanNeeded = false; 3147 for (var i = 0; i < len; ++i) { 3148 var maybePromise = cast(values[i], void 0); 3149 if (maybePromise instanceof Promise) { 3150 if (maybePromise.isPending()) { 3151 maybePromise._proxyPromiseArray(this, i); 3152 } else { 3153 maybePromise._unsetRejectionIsUnhandled(); 3154 isDirectScanNeeded = true; 3155 } 3156 } else { 3157 isDirectScanNeeded = true; 3158 } 3159 newValues[i] = maybePromise; 3160 } 3161 this._values = newValues; 3162 this._length = newLen; 3163 if (isDirectScanNeeded) { 3164 this._scanDirectValues(len); 3165 } 3166}; 3167 3168PromiseArray.prototype._settlePromiseAt = 3169function PromiseArray$_settlePromiseAt(index) { 3170 var value = this._values[index]; 3171 if (!(value instanceof Promise)) { 3172 this._promiseFulfilled(value, index); 3173 } else if (value.isFulfilled()) { 3174 this._promiseFulfilled(value._settledValue, index); 3175 } else if (value.isRejected()) { 3176 this._promiseRejected(value._settledValue, index); 3177 } 3178}; 3179 3180PromiseArray.prototype._scanDirectValues = 3181function PromiseArray$_scanDirectValues(len) { 3182 for (var i = 0; i < len; ++i) { 3183 if (this._isResolved()) { 3184 break; 3185 } 3186 this._settlePromiseAt(i); 3187 } 3188}; 3189 3190PromiseArray.prototype._isResolved = function PromiseArray$_isResolved() { 3191 return this._values === null; 3192}; 3193 3194PromiseArray.prototype._resolve = function PromiseArray$_resolve(value) { 3195 this._values = null; 3196 this._promise._fulfill(value); 3197}; 3198 3199PromiseArray.prototype.__hardReject__ = 3200PromiseArray.prototype._reject = function PromiseArray$_reject(reason) { 3201 this._values = null; 3202 var trace = canAttach(reason) ? reason : new Error(reason + ""); 3203 this._promise._attachExtraTrace(trace); 3204 this._promise._reject(reason, trace); 3205}; 3206 3207PromiseArray.prototype._promiseProgressed = 3208function PromiseArray$_promiseProgressed(progressValue, index) { 3209 if (this._isResolved()) return; 3210 this._promise._progress({ 3211 index: index, 3212 value: progressValue 3213 }); 3214}; 3215 3216 3217PromiseArray.prototype._promiseFulfilled = 3218function PromiseArray$_promiseFulfilled(value, index) { 3219 if (this._isResolved()) return; 3220 this._values[index] = value; 3221 var totalResolved = ++this._totalResolved; 3222 if (totalResolved >= this._length) { 3223 this._resolve(this._values); 3224 } 3225}; 3226
3227PromiseArray.prototype._promiseRejected = 3228function PromiseArray$_promiseRejected(reason, index) { 3229 if (this._isResolved()) return; 3230 this._totalResolved++; 3231 this._reject(reason); 3232}; 3233 3234PromiseArray.prototype.shouldCopyValues = 3235function PromiseArray$_shouldCopyValues() { 3236 return true; 3237}; 3238 3239PromiseArray.prototype.getActualLength = 3240function PromiseArray$getActualLength(len) { 3241 return len; 3242}; 3243 3244return PromiseArray; 3245}; 3246 3247},{"./errors.js":10,"./util.js":35}],22:[function(_dereq_,module,exports){ 3248/** 3249 * The MIT License (MIT) 3250 * 3251 * Copyright (c) 2014 Petka Antonov 3252 * 3253 * Permission is hereby granted, free of charge, to any person obtaining a copy 3254 * of this software and associated documentation files (the "Software"), to deal 3255 * in the Software without restriction, including without limitation the rights 3256 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 3257 * copies of the Software, and to permit persons to whom the Software is 3258 * furnished to do so, subject to the following conditions:</p> 3259 * 3260 * The above copyright notice and this permission notice shall be included in 3261 * all copies or substantial portions of the Software. 3262 * 3263 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 3264 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 3265 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 3266 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 3267 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 3268 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 3269 * THE SOFTWARE. 3270 * 3271 */ 3272"use strict"; 3273var util = _dereq_("./util.js"); 3274var maybeWrapAsError = util.maybeWrapAsError; 3275var errors = _dereq_("./errors.js"); 3276var TimeoutError = errors.TimeoutError; 3277var OperationalError = errors.OperationalError; 3278var async = _dereq_("./async.js"); 3279var haveGetters = util.haveGetters; 3280var es5 = _dereq_("./es5.js"); 3281 3282function isUntypedError(obj) { 3283 return obj instanceof Error && 3284 es5.getPrototypeOf(obj) === Error.prototype; 3285} 3286 3287function wrapAsOperationalError(obj) { 3288 var ret; 3289 if (isUntypedError(obj)) { 3290 ret = new OperationalError(obj); 3291 } else { 3292 ret = obj; 3293 } 3294 errors.markAsOriginatingFromRejection(ret); 3295 return ret; 3296} 3297 3298function nodebackForPromise(promise) { 3299 function PromiseResolver$_callback(err, value) { 3300 if (promise === null) return; 3301 3302 if (err) { 3303 var wrapped = wrapAsOperationalError(maybeWrapAsError(err)); 3304 promise._attachExtraTrace(wrapped); 3305 promise._reject(wrapped); 3306 } else if (arguments.length > 2) { 3307 var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];} 3308 promise._fulfill(args); 3309 } else { 3310 promise._fulfill(value); 3311 } 3312 3313 promise = null; 3314 } 3315 return PromiseResolver$_callback; 3316} 3317 3318 3319var PromiseResolver; 3320if (!haveGetters) { 3321 PromiseResolver = function PromiseResolver(promise) { 3322 this.promise = promise; 3323 this.asCallback = nodebackForPromise(promise); 3324 this.callback = this.asCallback; 3325 }; 3326} 3327else { 3328 PromiseResolver = function PromiseResolver(promise) { 3329 this.promise = promise; 3330 }; 3331} 3332if (haveGetters) { 3333 var prop = { 3334 get: function() { 3335 return nodebackForPromise(this.promise); 3336 } 3337 }; 3338 es5.defineProperty(PromiseResolver.prototype, "asCallback", prop); 3339 es5.defineProperty(PromiseResolver.prototype, "callback", prop); 3340} 3341 3342PromiseResolver._nodebackForPromise = nodebackForPromise; 3343 3344PromiseResolver.prototype.toString = function PromiseResolver$toString() { 3345 return "[object PromiseResolver]"; 3346}; 3347 3348PromiseResolver.prototype.resolve = 3349PromiseResolver.prototype.fulfill = function PromiseResolver$resolve(value) { 3350 if (!(this instanceof PromiseResolver)) { 3351 throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead."); 3352 } 3353 3354 var promise = this.promise; 3355 if (promise._tryFollow(value)) { 3356 return; 3357 } 3358 async.invoke(promise._fulfill, promise, value); 3359}; 3360 3361PromiseResolver.prototype.reject = function PromiseResolver$reject(reason) { 3362 if (!(this instanceof PromiseResolver)) { 3363 throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead."); 3364 } 3365 3366 var promise = this.promise; 3367 errors.markAsOriginatingFromRejection(reason); 3368 var trace = errors.canAttach(reason) ? reason : new Error(reason + ""); 3369 promise._attachExtraTrace(trace); 3370 async.invoke(promise._reject, promise, reason); 3371 if (trace !== reason) { 3372 async.invoke(this._setCarriedStackTrace, this, trace); 3373 } 3374}; 3375 3376PromiseResolver.prototype.progress = 3377function PromiseResolver$progress(value) { 3378 if (!(this instanceof PromiseResolver)) { 3379 throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead."); 3380 } 3381 async.invoke(this.promise._progress, this.promise, value); 3382}; 3383 3384PromiseResolver.prototype.cancel = function PromiseResolver$cancel() { 3385 async.invoke(this.promise.cancel, this.promise, void 0); 3386}; 3387 3388PromiseResolver.prototype.timeout = function PromiseResolver$timeout() { 3389 this.reject(new TimeoutError("timeout")); 3390}; 3391 3392PromiseResolver.prototype.isResolved = function PromiseResolver$isResolved() { 3393 return this.promise.isResolved(); 3394}; 3395 3396PromiseResolver.prototype.toJSON = function PromiseResolver$toJSON() { 3397 return this.promise.toJSON(); 3398}; 3399 3400PromiseResolver.prototype._setCarriedStackTrace = 3401function PromiseResolver$_setCarriedStackTrace(trace) { 3402 if (this.promise.isRejected()) { 3403 this.promise._setCarriedStackTrace(trace); 3404 } 3405}; 3406 3407module.exports = PromiseResolver; 3408 3409},{"./async.js":2,"./errors.js":10,"./es5.js":12,"./util.js":35}],23:[function(_dereq_,module,exports){ 3410/** 3411 * The MIT License (MIT) 3412 * 3413 * Copyright (c) 2014 Petka Antonov 3414 * 3415 * Permission is hereby granted, free of charge, to any person obtaining a copy 3416 * of this software and associated documentation files (the "Software"), to deal 3417 * in the Software without restriction, including without limitation the rights 3418 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 3419 * copies of the Software, and to permit persons to whom the Software is 3420 * furnished to do so, subject to the following conditions:</p> 3421 * 3422 * The above copyright notice and this permission notice shall be included in 3423 * all copies or substantial portions of the Software. 3424 * 3425 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 3426 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 3427 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 3428 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 3429 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 3430 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 3431 * THE SOFTWARE. 3432 * 3433 */ 3434"use strict"; 3435module.exports = function(Promise, INTERNAL) { 3436var THIS = {}; 3437var util = _dereq_("./util.js"); 3438var nodebackForPromise = _dereq_("./promise_resolver.js") 3439 ._nodebackForPromise; 3440var withAppended = util.withAppended; 3441var maybeWrapAsError = util.maybeWrapAsError; 3442var canEvaluate = util.canEvaluate; 3443var TypeError = _dereq_("./errors").TypeError; 3444var defaultSuffix = "Async"; 3445var defaultFilter = function(name, func) { 3446 return util.isIdentifier(name) && 3447 name.charAt(0) !== "_" && 3448 !util.isClass(func); 3449}; 3450var defaultPromisified = {__isPromisified__: true}; 3451 3452 3453function escapeIdentRegex(str) { 3454 return str.replace(/([$])/, "\\$"); 3455} 3456 3457function isPromisified(fn) { 3458 try { 3459 return fn.__isPromisified__ === true; 3460 } 3461 catch (e) { 3462 return false;
3463 } 3464} 3465 3466function hasPromisified(obj, key, suffix) { 3467 var val = util.getDataPropertyOrDefault(obj, key + suffix, 3468 defaultPromisified); 3469 return val ? isPromisified(val) : false; 3470} 3471function checkValid(ret, suffix, suffixRegexp) { 3472 for (var i = 0; i < ret.length; i += 2) { 3473 var key = ret[i]; 3474 if (suffixRegexp.test(key)) { 3475 var keyWithoutAsyncSuffix = key.replace(suffixRegexp, ""); 3476 for (var j = 0; j < ret.length; j += 2) { 3477 if (ret[j] === keyWithoutAsyncSuffix) { 3478 throw new TypeError("Cannot promisify an API " + 3479 "that has normal methods with '"+suffix+"'-suffix"); 3480 } 3481 } 3482 } 3483 } 3484} 3485 3486function promisifiableMethods(obj, suffix, suffixRegexp, filter) { 3487 var keys = util.inheritedDataKeys(obj); 3488 var ret = []; 3489 for (var i = 0; i < keys.length; ++i) { 3490 var key = keys[i]; 3491 var value = obj[key]; 3492 if (typeof value === "function" &&
3493 !isPromisified(value) && 3494 !hasPromisified(obj, key, suffix) && 3495 filter(key, value, obj)) { 3496 ret.push(key, value); 3497 } 3498 } 3499 checkValid(ret, suffix, suffixRegexp); 3500 return ret; 3501} 3502 3503function switchCaseArgumentOrder(likelyArgumentCount) { 3504 var ret = [likelyArgumentCount]; 3505 var min = Math.max(0, likelyArgumentCount - 1 - 5); 3506 for(var i = likelyArgumentCount - 1; i >= min; --i) { 3507 if (i === likelyArgumentCount) continue; 3508 ret.push(i); 3509 } 3510 for(var i = likelyArgumentCount + 1; i <= 5; ++i) { 3511 ret.push(i); 3512 } 3513 return ret; 3514} 3515 3516function argumentSequence(argumentCount) { 3517 return util.filledRange(argumentCount, "arguments[", "]"); 3518} 3519 3520function parameterDeclaration(parameterCount) { 3521 return util.filledRange(parameterCount, "_arg", ""); 3522} 3523 3524function parameterCount(fn) { 3525 if (typeof fn.length === "number") { 3526 return Math.max(Math.min(fn.length, 1023 + 1), 0); 3527 } 3528 return 0; 3529} 3530 3531function generatePropertyAccess(key) { 3532 if (util.isIdentifier(key)) { 3533 return "." + key; 3534 } 3535 else return "['" + key.replace(/(['\\])/g, "\\$1") + "']"; 3536} 3537 3538function makeNodePromisifiedEval(callback, receiver, originalName, fn, suffix) { 3539 var newParameterCount = Math.max(0, parameterCount(fn) - 1); 3540 var argumentOrder = switchCaseArgumentOrder(newParameterCount); 3541 var callbackName = 3542 (typeof originalName === "string" && util.isIdentifier(originalName) 3543 ? originalName + suffix 3544 : "promisified"); 3545 3546 function generateCallForArgumentCount(count) { 3547 var args = argumentSequence(count).join(", "); 3548 var comma = count > 0 ? ", " : ""; 3549 var ret; 3550 if (typeof callback === "string") { 3551 ret = " \n\ 3552 this.method({{args}}, fn); \n\ 3553 break; \n\ 3554 ".replace(".method", generatePropertyAccess(callback)); 3555 } else if (receiver === THIS) { 3556 ret = " \n\ 3557 callback.call(this, {{args}}, fn); \n\ 3558 break; \n\ 3559 "; 3560 } else if (receiver !== void 0) { 3561 ret = " \n\ 3562 callback.call(receiver, {{args}}, fn); \n\ 3563 break; \n\ 3564 "; 3565 } else { 3566 ret = " \n\ 3567 callback({{args}}, fn); \n\ 3568 break; \n\ 3569 "; 3570 } 3571 return ret.replace("{{args}}", args).replace(", ", comma); 3572 } 3573 3574 function generateArgumentSwitchCase() { 3575 var ret = ""; 3576 for(var i = 0; i < argumentOrder.length; ++i) { 3577 ret += "case " + argumentOrder[i] +":" + 3578 generateCallForArgumentCount(argumentOrder[i]); 3579 } 3580 var codeForCall; 3581 if (typeof callback === "string") { 3582 codeForCall = " \n\ 3583 this.property.apply(this, args); \n\ 3584 " 3585 .replace(".property", generatePropertyAccess(callback)); 3586 } else if (receiver === THIS) { 3587 codeForCall = " \n\ 3588 callback.apply(this, args); \n\ 3589 "; 3590 } else { 3591 codeForCall = " \n\ 3592 callback.apply(receiver, args); \n\ 3593 "; 3594 } 3595 3596 ret += " \n\ 3597 default: \n\ 3598 var args = new Array(len + 1); \n\ 3599 var i = 0; \n\ 3600 for (var i = 0; i < len; ++i) { \n\ 3601 args[i] = arguments[i]; \n\ 3602 } \n\ 3603 args[i] = fn; \n\ 3604 [CodeForCall] \n\ 3605 break; \n\ 3606 ".replace("[CodeForCall]", codeForCall); 3607 return ret; 3608 } 3609 3610 return new Function("Promise", 3611 "callback", 3612 "receiver", 3613 "withAppended", 3614 "maybeWrapAsError", 3615 "nodebackForPromise", 3616 "INTERNAL"," \n\ 3617 var ret = function FunctionName(Parameters) { \n\ 3618 'use strict'; \n\ 3619 var len = arguments.length; \n\ 3620 var promise = new Promise(INTERNAL); \n\ 3621 promise._setTrace(void 0); \n\ 3622 var fn = nodebackForPromise(promise); \n\ 3623 try { \n\ 3624 switch(len) { \n\ 3625 [CodeForSwitchCase] \n\ 3626 } \n\ 3627 } catch (e) { \n\ 3628 var wrapped = maybeWrapAsError(e); \n\ 3629 promise._attachExtraTrace(wrapped); \n\ 3630 promise._reject(wrapped); \n\ 3631 } \n\ 3632 return promise; \n\ 3633 }; \n\ 3634 ret.__isPromisified__ = true; \n\ 3635 return ret; \n\ 3636 " 3637 .replace("FunctionName", callbackName) 3638 .replace("Parameters", parameterDeclaration(newParameterCount)) 3639 .replace("[CodeForSwitchCase]", generateArgumentSwitchCase()))( 3640 Promise, 3641 callback, 3642 receiver, 3643 withAppended, 3644 maybeWrapAsError, 3645 nodebackForPromise, 3646 INTERNAL 3647 ); 3648} 3649 3650function makeNodePromisifiedClosure(callback, receiver) { 3651 function promisified() { 3652 var _receiver = receiver; 3653 if (receiver === THIS) _receiver = this; 3654 if (typeof callback === "string") { 3655 callback = _receiver[callback]; 3656 } 3657 var promise = new Promise(INTERNAL); 3658 promise._setTrace(void 0); 3659 var fn = nodebackForPromise(promise); 3660 try { 3661 callback.apply(_receiver, withAppended(arguments, fn)); 3662 } catch(e) { 3663 var wrapped = maybeWrapAsError(e); 3664 promise._attachExtraTrace(wrapped); 3665 promise._reject(wrapped); 3666 } 3667 return promise; 3668 } 3669 promisified.__isPromisified__ = true; 3670 return promisified; 3671} 3672 3673var makeNodePromisified = canEvaluate 3674 ? makeNodePromisifiedEval 3675 : makeNodePromisifiedClosure; 3676 3677function promisifyAll(obj, suffix, filter, promisifier) { 3678 var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$"); 3679 var methods = 3680 promisifiableMethods(obj, suffix, suffixRegexp, filter); 3681 3682 for (var i = 0, len = methods.length; i < len; i+= 2) { 3683 var key = methods[i]; 3684 var fn = methods[i+1]; 3685 var promisifiedKey = key + suffix; 3686 obj[promisifiedKey] = promisifier === makeNodePromisified 3687 ? makeNodePromisified(key, THIS, key, fn, suffix) 3688 : promisifier(fn); 3689 } 3690 util.toFastProperties(obj); 3691 return obj; 3692} 3693 3694function promisify(callback, receiver) { 3695 return makeNodePromisified(callback, receiver, void 0, callback); 3696} 3697 3698Promise.promisify = function Promise$Promisify(fn, receiver) { 3699 if (typeof fn !== "function") { 3700 throw new TypeError("fn must be a function"); 3701 }
3702 if (isPromisified(fn)) { 3703 return fn; 3704 } 3705 return promisify(fn, arguments.length < 2 ? THIS : receiver); 3706}; 3707 3708Promise.promisifyAll = function Promise$PromisifyAll(target, options) { 3709 if (typeof target !== "function" && typeof target !== "object") { 3710 throw new TypeError("the target of promisifyAll must be an object or a function"); 3711 } 3712 options = Object(options); 3713 var suffix = options.suffix; 3714 if (typeof suffix !== "string") suffix = defaultSuffix; 3715 var filter = options.filter; 3716 if (typeof filter !== "function") filter = defaultFilter; 3717 var promisifier = options.promisifier; 3718 if (typeof promisifier !== "function") promisifier = makeNodePromisified; 3719 3720 if (!util.isIdentifier(suffix)) { 3721 throw new RangeError("suffix must be a valid identifier"); 3722 } 3723 3724 var keys = util.inheritedDataKeys(target, {includeHidden: true}); 3725 for (var i = 0; i < keys.length; ++i) { 3726 var value = target[keys[i]]; 3727 if (keys[i] !== "constructor" && 3728 util.isClass(value)) { 3729 promisifyAll(value.prototype, suffix, filter, promisifier); 3730 promisifyAll(value, suffix, filter, promisifier); 3731 } 3732 } 3733 3734 return promisifyAll(target, suffix, filter, promisifier); 3735}; 3736}; 3737 3738 3739},{"./errors":10,"./promise_resolver.js":22,"./util.js":35}],24:[function(_dereq_,module,exports){ 3740/** 3741 * The MIT License (MIT) 3742 * 3743 * Copyright (c) 2014 Petka Antonov 3744 * 3745 * Permission is hereby granted, free of charge, to any person obtaining a copy 3746 * of this software and associated documentation files (the "Software"), to deal 3747 * in the Software without restriction, including without limitation the rights 3748 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 3749 * copies of the Software, and to permit persons to whom the Software is 3750 * furnished to do so, subject to the following conditions:</p> 3751 * 3752 * The above copyright notice and this permission notice shall be included in 3753 * all copies or substantial portions of the Software. 3754 * 3755 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 3756 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 3757 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 3758 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 3759 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 3760 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 3761 * THE SOFTWARE. 3762 * 3763 */ 3764"use strict"; 3765module.exports = function(Promise, PromiseArray, cast) { 3766var util = _dereq_("./util.js"); 3767var apiRejection = _dereq_("./errors_api_rejection")(Promise); 3768var isObject = util.isObject; 3769var es5 = _dereq_("./es5.js"); 3770 3771function PropertiesPromiseArray(obj) { 3772 var keys = es5.keys(obj); 3773 var len = keys.length; 3774 var values = new Array(len * 2); 3775 for (var i = 0; i < len; ++i) { 3776 var key = keys[i]; 3777 values[i] = obj[key]; 3778 values[i + len] = key; 3779 } 3780 this.constructor$(values); 3781} 3782util.inherits(PropertiesPromiseArray, PromiseArray); 3783 3784PropertiesPromiseArray.prototype._init = 3785function PropertiesPromiseArray$_init() { 3786 this._init$(void 0, -3) ; 3787}; 3788 3789PropertiesPromiseArray.prototype._promiseFulfilled = 3790function PropertiesPromiseArray$_promiseFulfilled(value, index) { 3791 if (this._isResolved()) return; 3792 this._values[index] = value; 3793 var totalResolved = ++this._totalResolved; 3794 if (totalResolved >= this._length) { 3795 var val = {}; 3796 var keyOffset = this.length(); 3797 for (var i = 0, len = this.length(); i < len; ++i) { 3798 val[this._values[i + keyOffset]] = this._values[i]; 3799 } 3800 this._resolve(val); 3801 } 3802}; 3803 3804PropertiesPromiseArray.prototype._promiseProgressed = 3805function PropertiesPromiseArray$_promiseProgressed(value, index) { 3806 if (this._isResolved()) return; 3807 3808 this._promise._progress({ 3809 key: this._values[index + this.length()], 3810 value: value 3811 }); 3812}; 3813 3814PropertiesPromiseArray.prototype.shouldCopyValues = 3815function PropertiesPromiseArray$_shouldCopyValues() { 3816 return false;
3817}; 3818 3819PropertiesPromiseArray.prototype.getActualLength = 3820function PropertiesPromiseArray$getActualLength(len) { 3821 return len >> 1; 3822}; 3823 3824function Promise$_Props(promises) { 3825 var ret; 3826 var castValue = cast(promises, void 0); 3827 3828 if (!isObject(castValue)) { 3829 return apiRejection("cannot await properties of a non-object"); 3830 } else if (castValue instanceof Promise) { 3831 ret = castValue._then(Promise.props, void 0, void 0, void 0, void 0); 3832 } else { 3833 ret = new PropertiesPromiseArray(castValue).promise(); 3834 } 3835 3836 if (castValue instanceof Promise) { 3837 ret._propagateFrom(castValue, 4); 3838 } 3839 return ret; 3840} 3841 3842Promise.prototype.props = function Promise$props() { 3843 return Promise$_Props(this); 3844}; 3845 3846Promise.props = function Promise$Props(promises) { 3847 return Promise$_Props(promises); 3848}; 3849}; 3850 3851},{"./errors_api_rejection":11,"./es5.js":12,"./util.js":35}],25:[function(_dereq_,module,exports){ 3852/** 3853 * The MIT License (MIT) 3854 * 3855 * Copyright (c) 2014 Petka Antonov 3856 * 3857 * Permission is hereby granted, free of charge, to any person obtaining a copy 3858 * of this software and associated documentation files (the "Software"), to deal 3859 * in the Software without restriction, including without limitation the rights 3860 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 3861 * copies of the Software, and to permit persons to whom the Software is 3862 * furnished to do so, subject to the following conditions:</p> 3863 * 3864 * The above copyright notice and this permission notice shall be included in 3865 * all copies or substantial portions of the Software. 3866 * 3867 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 3868 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 3869 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 3870 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 3871 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 3872 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 3873 * THE SOFTWARE. 3874 * 3875 */ 3876"use strict"; 3877function arrayCopy(src, srcIndex, dst, dstIndex, len) { 3878 for (var j = 0; j < len; ++j) { 3879 dst[j + dstIndex] = src[j + srcIndex]; 3880 } 3881} 3882 3883function Queue(capacity) { 3884 this._capacity = capacity; 3885 this._length = 0; 3886 this._front = 0; 3887 this._makeCapacity(); 3888} 3889 3890Queue.prototype._willBeOverCapacity = 3891function Queue$_willBeOverCapacity(size) { 3892 return this._capacity < size; 3893}; 3894 3895Queue.prototype._pushOne = function Queue$_pushOne(arg) { 3896 var length = this.length(); 3897 this._checkCapacity(length + 1); 3898 var i = (this._front + length) & (this._capacity - 1); 3899 this[i] = arg; 3900 this._length = length + 1; 3901}; 3902 3903Queue.prototype.push = function Queue$push(fn, receiver, arg) { 3904 var length = this.length() + 3; 3905 if (this._willBeOverCapacity(length)) { 3906 this._pushOne(fn); 3907 this._pushOne(receiver); 3908 this._pushOne(arg); 3909 return; 3910 } 3911 var j = this._front + length - 3; 3912 this._checkCapacity(length); 3913 var wrapMask = this._capacity - 1; 3914 this[(j + 0) & wrapMask] = fn; 3915 this[(j + 1) & wrapMask] = receiver; 3916 this[(j + 2) & wrapMask] = arg; 3917 this._length = length; 3918}; 3919 3920Queue.prototype.shift = function Queue$shift() { 3921 var front = this._front, 3922 ret = this[front]; 3923 3924 this[front] = void 0; 3925 this._front = (front + 1) & (this._capacity - 1); 3926 this._length--; 3927 return ret; 3928}; 3929 3930Queue.prototype.length = function Queue$length() { 3931 return this._length; 3932}; 3933 3934Queue.prototype._makeCapacity = function Queue$_makeCapacity() { 3935 var len = this._capacity; 3936 for (var i = 0; i < len; ++i) { 3937 this[i] = void 0; 3938 } 3939}; 3940 3941Queue.prototype._checkCapacity = function Queue$_checkCapacity(size) { 3942 if (this._capacity < size) { 3943 this._resizeTo(this._capacity << 3); 3944 } 3945}; 3946 3947Queue.prototype._resizeTo = function Queue$_resizeTo(capacity) { 3948 var oldFront = this._front; 3949 var oldCapacity = this._capacity; 3950 var oldQueue = new Array(oldCapacity); 3951 var length = this.length(); 3952 3953 arrayCopy(this, 0, oldQueue, 0, oldCapacity); 3954 this._capacity = capacity; 3955 this._makeCapacity(); 3956 this._front = 0; 3957 if (oldFront + length <= oldCapacity) { 3958 arrayCopy(oldQueue, oldFront, this, 0, length); 3959 } else { var lengthBeforeWrapping = 3960 length - ((oldFront + length) & (oldCapacity - 1)); 3961 3962 arrayCopy(oldQueue, oldFront, this, 0, lengthBeforeWrapping); 3963 arrayCopy(oldQueue, 0, this, lengthBeforeWrapping, 3964 length - lengthBeforeWrapping); 3965 } 3966}; 3967 3968module.exports = Queue; 3969 3970},{}],26:[function(_dereq_,module,exports){ 3971/** 3972 * The MIT License (MIT) 3973 * 3974 * Copyright (c) 2014 Petka Antonov 3975 * 3976 * Permission is hereby granted, free of charge, to any person obtaining a copy 3977 * of this software and associated documentation files (the "Software"), to deal 3978 * in the Software without restriction, including without limitation the rights 3979 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 3980 * copies of the Software, and to permit persons to whom the Software is 3981 * furnished to do so, subject to the following conditions:</p> 3982 * 3983 * The above copyright notice and this permission notice shall be included in 3984 * all copies or substantial portions of the Software. 3985 * 3986 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 3987 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 3988 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 3989 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 3990 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 3991 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 3992 * THE SOFTWARE. 3993 * 3994 */ 3995"use strict"; 3996module.exports = function(Promise, INTERNAL, cast) { 3997var apiRejection = _dereq_("./errors_api_rejection.js")(Promise); 3998var isArray = _dereq_("./util.js").isArray; 3999 4000var raceLater = function Promise$_raceLater(promise) { 4001 return promise.then(function(array) { 4002 return Promise$_Race(array, promise); 4003 }); 4004}; 4005 4006var hasOwn = {}.hasOwnProperty; 4007function Promise$_Race(promises, parent) { 4008 var maybePromise = cast(promises, void 0); 4009 4010 if (maybePromise instanceof Promise) { 4011 return raceLater(maybePromise); 4012 } else if (!isArray(promises)) { 4013 return apiRejection("expecting an array, a promise or a thenable"); 4014 } 4015 4016 var ret = new Promise(INTERNAL); 4017 if (parent !== void 0) { 4018 ret._propagateFrom(parent, 7); 4019 } else { 4020 ret._setTrace(void 0); 4021 } 4022 var fulfill = ret._fulfill; 4023 var reject = ret._reject; 4024 for (var i = 0, len = promises.length; i < len; ++i) { 4025 var val = promises[i]; 4026 4027 if (val === void 0 && !(hasOwn.call(promises, i))) { 4028 continue; 4029 } 4030 4031 Promise.cast(val)._then(fulfill, reject, void 0, ret, null); 4032 } 4033 return ret; 4034} 4035 4036Promise.race = function Promise$Race(promises) { 4037 return Promise$_Race(promises, void 0); 4038}; 4039 4040Promise.prototype.race = function Promise$race() { 4041 return Promise$_Race(this, void 0); 4042}; 4043 4044}; 4045 4046},{"./errors_api_rejection.js":11,"./util.js":35}],27:[function(_dereq_,module,exports){ 4047/** 4048 * The MIT License (MIT) 4049 * 4050 * Copyright (c) 2014 Petka Antonov 4051 * 4052 * Permission is hereby granted, free of charge, to any person obtaining a copy 4053 * of this software and associated documentation files (the "Software"), to deal 4054 * in the Software without restriction, including without limitation the rights 4055 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 4056 * copies of the Software, and to permit persons to whom the Software is 4057 * furnished to do so, subject to the following conditions:</p> 4058 * 4059 * The above copyright notice and this permission notice shall be included in 4060 * all copies or substantial portions of the Software. 4061 * 4062 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4063 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4064 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 4065 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 4066 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 4067 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 4068 * THE SOFTWARE. 4069 * 4070 */ 4071"use strict"; 4072module.exports = function(Promise, PromiseArray, apiRejection, cast, INT
4072ERNAL) { 4073var util = _dereq_("./util.js"); 4074var tryCatch4 = util.tryCatch4; 4075var tryCatch3 = util.tryCatch3; 4076var errorObj = util.errorObj; 4077function ReductionPromiseArray(promises, fn, accum, _each) { 4078 this.constructor$(promises); 4079 this._preservedValues = _each === INTERNAL ? [] : null; 4080 this._zerothIsAccum = (accum === void 0); 4081 this._gotAccum = false; 4082 this._reducingIndex = (this._zerothIsAccum ? 1 : 0); 4083 this._valuesPhase = undefined; 4084 4085 var maybePromise = cast(accum, void 0); 4086 var rejected = false; 4087 var isPromise = maybePromise instanceof Promise; 4088 if (isPromise) { 4089 if (maybePromise.isPending()) { 4090 maybePromise._proxyPromiseArray(this, -1); 4091 } else if (maybePromise.isFulfilled()) { 4092 accum = maybePromise.value(); 4093 this._gotAccum = true; 4094 } else { 4095 maybePromise._unsetRejectionIsUnhandled(); 4096 this._reject(maybePromise.reason()); 4097 rejected = true; 4098 } 4099 } 4100 if (!(isPromise || this._zerothIsAccum)) this._gotAccum = true; 4101 this._callback = fn; 4102 this._accum = accum; 4103 if (!rejected) this._init$(void 0, -5); 4104} 4105util.inherits(ReductionPromiseArray, PromiseArray); 4106 4107ReductionPromiseArray.prototype._init = 4108function ReductionPromiseArray$_init() {}; 4109 4110ReductionPromiseArray.prototype._resolveEmptyArray = 4111function ReductionPromiseArray$_resolveEmptyArray() { 4112 if (this._gotAccum || this._zerothIsAccum) { 4113 this._resolve(this._preservedValues !== null 4114 ? [] : this._accum); 4115 } 4116}; 4117 4118ReductionPromiseArray.prototype._promiseFulfilled = 4119function ReductionPromiseArray$_promiseFulfilled(value, index) { 4120 var values = this._values; 4121 if (values === null) return; 4122 var length = this.length(); 4123 var preservedValues = this._preservedValues; 4124 var isEach = preservedValues !== null; 4125 var gotAccum = this._gotAccum; 4126 var valuesPhase = this._valuesPhase; 4127 var valuesPhaseIndex; 4128 if (!valuesPhase) { 4129 valuesPhase = this._valuesPhase = Array(length); 4130 for (valuesPhaseIndex=0; valuesPhaseIndex<length; ++valuesPhaseIndex) { 4131 valuesPhase[valuesPhaseIndex] = 0; 4132 } 4133 } 4134 valuesPhaseIndex = valuesPhase[index]; 4135 4136 if (index === 0 && this._zerothIsAccum) { 4137 if (!gotAccum) { 4138 this._accum = value; 4139 this._gotAccum = gotAccum = true; 4140 } 4141 valuesPhase[index] = ((valuesPhaseIndex === 0) 4142 ? 1 : 2); 4143 } else if (index === -1) { 4144 if (!gotAccum) { 4145 this._accum = value; 4146 this._gotAccum = gotAccum = true; 4147 } 4148 } else { 4149 if (valuesPhaseIndex === 0) { 4150 valuesPhase[index] = 1; 4151 } 4152 else { 4153 valuesPhase[index] = 2; 4154 if (gotAccum) { 4155 this._accum = value; 4156 } 4157 } 4158 } 4159 if (!gotAccum) return; 4160 4161 var callback = this._callback; 4162 var receiver = this._promise._boundTo; 4163 var ret; 4164 4165 for (var i = this._reducingIndex; i < length; ++i) { 4166 valuesPhaseIndex = valuesPhase[i]; 4167 if (valuesPhaseIndex === 2) { 4168 this._reducingIndex = i + 1; 4169 continue; 4170 } 4171 if (valuesPhaseIndex !== 1) return; 4172 4173 value = values[i]; 4174 if (value instanceof Promise) { 4175 if (value.isFulfilled()) { 4176 value = value._settledValue; 4177 } else if (value.isPending()) { 4178 return; 4179 } else { 4180 value._unsetRejectionIsUnhandled(); 4181 return this._reject(value.reason()); 4182 } 4183 } 4184 4185 if (isEach) { 4186 preservedValues.push(value); 4187 ret = tryCatch3(callback, receiver, value, i, length); 4188 } 4189 else { 4190 ret = tryCatch4(callback, receiver, this._accum, value, i, length); 4191 } 4192 4193 if (ret === errorObj) return this._reject(ret.e); 4194 4195 var maybePromise = cast(ret, void 0); 4196 if (maybePromise instanceof Promise) { 4197 if (maybePromise.isPending()) { 4198 valuesPhase[i] = 4; 4199 return maybePromise._proxyPromiseArray(this, i); 4200 } else if (maybePromise.isFulfilled()) { 4201 ret = maybePromise.value(); 4202 } else { 4203 maybePromise._unsetRejectionIsUnhandled(); 4204 return this._reject(maybePromise.reason()); 4205 } 4206 } 4207 4208 this._reducingIndex = i + 1; 4209 this._accum = ret; 4210 } 4211 4212 if (this._reducingIndex < length) return; 4213 this._resolve(isEach ? preservedValues : this._accum); 4214}; 4215 4216function reduce(promises, fn, initialValue, _each) { 4217 if (typeof fn !== "function") return apiRejection("fn must be a function"); 4218 var array = new ReductionPromiseArray(promises, fn, initialValue, _each); 4219 return array.promise(); 4220} 4221 4222Promise.prototype.reduce = function Promise$reduce(fn, initialValue) { 4223 return reduce(this, fn, initialValue, null); 4224}; 4225 4226Promise.reduce = function Promise$Reduce(promises, fn, initialValue, _each) { 4227 return reduce(promises, fn, initialValue, _each); 4228}; 4229}; 4230 4231},{"./util.js":35}],28:[function(_dereq_,module,exports){ 4232/** 4233 * The MIT License (MIT) 4234 * 4235 * Copyright (c) 2014 Petka Antonov 4236 * 4237 * Permission is hereby granted, free of charge, to any person obtaining a copy 4238 * of this software and associated documentation files (the "Software"), to deal 4239 * in the Software without restriction, including without limitation the rights 4240 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 4241 * copies of the Software, and to permit persons to whom the Software is 4242 * furnished to do so, subject to the following conditions:</p> 4243 * 4244 * The above copyright notice and this permission notice shall be included in 4245 * all copies or substantial portions of the Software. 4246 * 4247 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4248 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4249 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 4250 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 4251 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 4252 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 4253 * THE SOFTWARE. 4254 * 4255 */ 4256"use strict"; 4257var schedule; 4258var _MutationObserver; 4259if (typeof process === "object" && typeof process.version === "string") { 4260 schedule = function Promise$_Scheduler(fn) { 4261 process.nextTick(fn); 4262 }; 4263} 4264else if ((typeof MutationObserver !== "undefined" && 4265 (_MutationObserver = MutationObserver)) || 4266 (typeof WebKitMutationObserver !== "undefined" && 4267 (_MutationObserver = WebKitMutationObserver))) { 4268 schedule = (function() { 4269 var div = document.createElement("div"); 4270 var queuedFn = void 0; 4271 var observer = new _MutationObserver( 4272 function Promise$_Scheduler() { 4273 var fn = queuedFn; 4274 queuedFn = void 0; 4275 fn(); 4276 } 4277 ); 4278 observer.observe(div, { 4279 attributes: true 4280 }); 4281 return function Promise$_Scheduler(fn) { 4282 queuedFn = fn; 4283 div.classList.toggle("foo"); 4284 }; 4285 4286 })(); 4287} 4288else if (typeof setTimeout !== "undefined") { 4289 schedule = function Promise$_Scheduler(fn) { 4290 setTimeout(fn, 0); 4291 }; 4292} 4293else throw new Error("no async scheduler available"); 4294module.exports = schedule; 4295 4296},{}],29:[function(_dereq_,module,exports){ 4297/** 4298 * The MIT License (MIT) 4299 * 4300 * Copyright (c) 2014 Petka Antonov 4301 * 4302 * Permission is hereby granted, free of charge, to any person obtaining a copy 4303 * of this software and associated documentation files (the "Software"), to deal 4304 * in the Software without restriction, including without limitation the rights 4305 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 4306 * copies of the Software, and to permit persons to whom the Software is 4307 * furnished to do so, subject to the following conditions:</p> 4308 * 4309 * The above copyright notice and this permission notice shall be included in 4310 * all copies or substantial portions of the Software. 4311 * 4312 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4313 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4314 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 4315 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 4316 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 4317 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 4318 * THE SOFTWARE. 4319 * 4320 */ 4321"use strict"; 4322module.exports = 4323 function(Promise, PromiseArray) { 4324var PromiseInspection = Promise.PromiseInspection; 4325var util = _dereq_("./util.js"); 4326 4327function SettledPromiseArray(values) { 4328 this.constructor$(values); 4329} 4330util.inherits(SettledPromiseArray, PromiseArray); 4331 4332SettledPromiseArray.prototype._promiseResolved = 4333function SettledPromiseArray$_promiseResolved(index, inspection) { 4334 this._values[index] = inspection; 4335 var totalResolved = ++this._totalResolved; 4336 if (totalResolved >= this._length) { 4337 this._resolve(this._values); 4338 } 4339}; 4340 4341SettledPromiseArray.prototype._promiseFulfilled = 4342function SettledPromiseArray$_promiseFulfilled(value, index) { 4343 if (this._isResolved()) return; 4344 var ret = new PromiseInspection(); 4345 ret._bitField = 268435456; 4346 ret._settledValue = value; 4347 this._promiseResolved(index, ret); 4348};
4349SettledPromiseArray.prototype._promiseRejected = 4350function SettledPromiseArray$_promiseRejected(reason, index) { 4351 if (this._isResolved()) return; 4352 var ret = new PromiseInspection(); 4353 ret._bitField = 134217728; 4354 ret._settledValue = reason; 4355 this._promiseResolved(index, ret); 4356}; 4357 4358Promise.settle = function Promise$Settle(promises) { 4359 return new SettledPromiseArray(promises).promise(); 4360}; 4361 4362Promise.prototype.settle = function Promise$settle() { 4363 return new SettledPromiseArray(this).promise(); 4364}; 4365}; 4366 4367},{"./util.js":35}],30:[function(_dereq_,module,exports){ 4368/** 4369 * The MIT License (MIT) 4370 * 4371 * Copyright (c) 2014 Petka Antonov 4372 * 4373 * Permission is hereby granted, free of charge, to any person obtaining a copy 4374 * of this software and associated documentation files (the "Software"), to deal 4375 * in the Software without restriction, including without limitation the rights 4376 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 4377 * copies of the Software, and to permit persons to whom the Software is 4378 * furnished to do so, subject to the following conditions:</p> 4379 * 4380 * The above copyright notice and this permission notice shall be included in 4381 * all copies or substantial portions of the Software. 4382 * 4383 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4384 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4385 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 4386 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 4387 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 4388 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 4389 * THE SOFTWARE. 4390 * 4391 */ 4392"use strict"; 4393module.exports = 4394function(Promise, PromiseArray, apiRejection) { 4395var util = _dereq_("./util.js"); 4396var RangeError = _dereq_("./errors.js").RangeError; 4397var AggregateError = _dereq_("./errors.js").AggregateError; 4398var isArray = util.isArray; 4399 4400 4401function SomePromiseArray(values) { 4402 this.constructor$(values); 4403 this._howMany = 0; 4404 this._unwrap = false; 4405 this._initialized = false; 4406} 4407util.inherits(SomePromiseArray, PromiseArray); 4408 4409SomePromiseArray.prototype._init = function SomePromiseArray$_init() { 4410 if (!this._initialized) { 4411 return; 4412 } 4413 if (this._howMany === 0) { 4414 this._resolve([]); 4415 return; 4416 } 4417 this._init$(void 0, -5); 4418 var isArrayResolved = isArray(this._values); 4419 if (!this._isResolved() && 4420 isArrayResolved && 4421 this._howMany > this._canPossiblyFulfill()) { 4422 this._reject(this._getRangeError(this.length())); 4423 } 4424}; 4425 4426SomePromiseArray.prototype.init = function SomePromiseArray$init() { 4427 this._initialized = true; 4428 this._init(); 4429}; 4430 4431SomePromiseArray.prototype.setUnwrap = function SomePromiseArray$setUnwrap() { 4432 this._unwrap = true; 4433}; 4434 4435SomePromiseArray.prototype.howMany = function SomePromiseArray$howMany() { 4436 return this._howMany; 4437}; 4438 4439SomePromiseArray.prototype.setHowMany = 4440function SomePromiseArray$setHowMany(count) { 4441 if (this._isResolved()) return; 4442 this._howMany = count; 4443}; 4444 4445SomePromiseArray.prototype._promiseFulfilled = 4446function SomePromiseArray$_promiseFulfilled(value) { 4447 if (this._isResolved()) return; 4448 this._addFulfilled(value); 4449 if (this._fulfilled() === this.howMany()) { 4450 this._values.length = this.howMany(); 4451 if (this.howMany() === 1 && this._unwrap) { 4452 this._resolve(this._values[0]); 4453 } else { 4454 this._resolve(this._values); 4455 } 4456 } 4457 4458};
4459SomePromiseArray.prototype._promiseRejected = 4460function SomePromiseArray$_promiseRejected(reason) { 4461 if (this._isResolved()) return; 4462 this._addRejected(reason); 4463 if (this.howMany() > this._canPossiblyFulfill()) { 4464 var e = new AggregateError(); 4465 for (var i = this.length(); i < this._values.length; ++i) { 4466 e.push(this._values[i]); 4467 } 4468 this._reject(e); 4469 } 4470}; 4471 4472SomePromiseArray.prototype._fulfilled = function SomePromiseArray$_fulfilled() { 4473 return this._totalResolved; 4474}; 4475 4476SomePromiseArray.prototype._rejected = function SomePromiseArray$_rejected() { 4477 return this._values.length - this.length(); 4478}; 4479 4480SomePromiseArray.prototype._addRejected = 4481function SomePromiseArray$_addRejected(reason) { 4482 this._values.push(reason); 4483}; 4484 4485SomePromiseArray.prototype._addFulfilled = 4486function SomePromiseArray$_addFulfilled(value) { 4487 this._values[this._totalResolved++] = value; 4488}; 4489 4490SomePromiseArray.prototype._canPossiblyFulfill = 4491function SomePromiseArray$_canPossiblyFulfill() { 4492 return this.length() - this._rejected(); 4493}; 4494 4495SomePromiseArray.prototype._getRangeError = 4496function SomePromiseArray$_getRangeError(count) { 4497 var message = "Input array must contain at least " + 4498 this._howMany + " items but contains only " + count + " items"; 4499 return new RangeError(message); 4500}; 4501 4502SomePromiseArray.prototype._resolveEmptyArray = 4503function SomePromiseArray$_resolveEmptyArray() { 4504 this._reject(this._getRangeError(0)); 4505}; 4506 4507function Promise$_Some(promises, howMany) { 4508 if ((howMany | 0) !== howMany || howMany < 0) { 4509 return apiRejection("expecting a positive integer"); 4510 } 4511 var ret = new SomePromiseArray(promises); 4512 var promise = ret.promise(); 4513 if (promise.isRejected()) { 4514 return promise; 4515 } 4516 ret.setHowMany(howMany); 4517 ret.init(); 4518 return promise; 4519} 4520 4521Promise.some = function Promise$Some(promises, howMany) { 4522 return Promise$_Some(promises, howMany); 4523}; 4524 4525Promise.prototype.some = function Promise$some(howMany) { 4526 return Promise$_Some(this, howMany); 4527}; 4528 4529Promise._SomePromiseArray = SomePromiseArray; 4530}; 4531 4532},{"./errors.js":10,"./util.js":35}],31:[function(_dereq_,module,exports){ 4533/** 4534 * The MIT License (MIT) 4535 * 4536 * Copyright (c) 2014 Petka Antonov 4537 * 4538 * Permission is hereby granted, free of charge, to any person obtaining a copy 4539 * of this software and associated documentation files (the "Software"), to deal 4540 * in the Software without restriction, including without limitation the rights 4541 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 4542 * copies of the Software, and to permit persons to whom the Software is 4543 * furnished to do so, subject to the following conditions:</p> 4544 * 4545 * The above copyright notice and this permission notice shall be included in 4546 * all copies or substantial portions of the Software. 4547 * 4548 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4549 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4550 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 4551 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 4552 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 4553 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 4554 * THE SOFTWARE. 4555 * 4556 */ 4557"use strict"; 4558module.exports = function(Promise) { 4559function PromiseInspection(promise) { 4560 if (promise !== void 0) { 4561 this._bitField = promise._bitField; 4562 this._settledValue = promise.isResolved() 4563 ? promise._settledValue 4564 : void 0; 4565 } 4566 else { 4567 this._bitField = 0; 4568 this._settledValue = void 0; 4569 } 4570} 4571 4572PromiseInspection.prototype.isFulfilled = 4573Promise.prototype.isFulfilled = function Promise$isFulfilled() { 4574 return (this._bitField & 268435456) > 0; 4575}; 4576 4577PromiseInspection.prototype.isRejected = 4578Promise.prototype.isRejected = function Promise$isRejected() { 4579 return (this._bitField & 134217728) > 0; 4580}; 4581 4582PromiseInspection.prototype.isPending = 4583Promise.prototype.isPending = function Promise$isPending() {
4584 return (this._bitField & 402653184) === 0; 4585}; 4586 4587PromiseInspection.prototype.value = 4588Promise.prototype.value = function Promise$value() { 4589 if (!this.isFulfilled()) { 4590 throw new TypeError("cannot get fulfillment value of a non-fulfilled promise"); 4591 } 4592 return this._settledValue; 4593}; 4594 4595PromiseInspection.prototype.error = 4596PromiseInspection.prototype.reason = 4597Promise.prototype.reason = function Promise$reason() { 4598 if (!this.isRejected()) { 4599 throw new TypeError("cannot get rejection reason of a non-rejected promise"); 4600 } 4601 return this._settledValue; 4602}; 4603 4604PromiseInspection.prototype.isResolved = 4605Promise.prototype.isResolved = function Promise$isResolved() { 4606 return (this._bitField & 402653184) > 0; 4607}; 4608 4609Promise.PromiseInspection = PromiseInspection; 4610}; 4611 4612},{}],32:[function(_dereq_,module,exports){ 4613/** 4614 * The MIT License (MIT) 4615 * 4616 * Copyright (c) 2014 Petka Antonov 4617 * 4618 * Permission is hereby granted, free of charge, to any person obtaining a copy 4619 * of this software and associated documentation files (the "Software"), to deal 4620 * in the Software without restriction, including without limitation the rights 4621 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 4622 * copies of the Software, and to permit persons to whom the Software is 4623 * furnished to do so, subject to the following conditions:</p> 4624 * 4625 * The above copyright notice and this permission notice shall be included in 4626 * all copies or substantial portions of the Software. 4627 * 4628 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4629 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4630 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 4631 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 4632 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 4633 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 4634 * THE SOFTWARE. 4635 * 4636 */ 4637"use strict"; 4638module.exports = function(Promise, INTERNAL) { 4639var util = _dereq_("./util.js"); 4640var canAttach = _dereq_("./errors.js").canAttach; 4641var errorObj = util.errorObj; 4642var isObject = util.isObject; 4643 4644function getThen(obj) { 4645 try { 4646 return obj.then; 4647 } 4648 catch(e) { 4649 errorObj.e = e; 4650 return errorObj; 4651 } 4652} 4653 4654function Promise$_Cast(obj, originalPromise) { 4655 if (isObject(obj)) { 4656 if (obj instanceof Promise) { 4657 return obj; 4658 } 4659 else if (isAnyBluebirdPromise(obj)) { 4660 var ret = new Promise(INTERNAL); 4661 ret._setTrace(void 0); 4662 obj._then( 4663 ret._fulfillUnchecked, 4664 ret._rejectUncheckedCheckError, 4665 ret._progressUnchecked, 4666 ret, 4667 null 4668 ); 4669 ret._setFollowing(); 4670 return ret; 4671 } 4672 var then = getThen(obj); 4673 if (then === errorObj) { 4674 if (originalPromise !== void 0 && canAttach(then.e)) { 4675 originalPromise._attachExtraTrace(then.e); 4676 } 4677 return Promise.reject(then.e); 4678 } else if (typeof then === "function") { 4679 return Promise$_doThenable(obj, then, originalPromise); 4680 } 4681 } 4682 return obj; 4683} 4684 4685var hasProp = {}.hasOwnProperty; 4686function isAnyBluebirdPromise(obj) { 4687 return hasProp.call(obj, "_promise0"); 4688} 4689 4690function Promise$_doThenable(x, then, originalPromise) { 4691 var resolver = Promise.defer(); 4692 var called = false; 4693 try { 4694 then.call( 4695 x, 4696 Promise$_resolveFromThenable, 4697 Promise$_rejectFromThenable, 4698 Promise$_progressFromThenable 4699 ); 4700 } catch(e) { 4701 if (!called) { 4702 called = true; 4703 var trace = canAttach(e) ? e : new Error(e + ""); 4704 if (originalPromise !== void 0) { 4705 originalPromise._attachExtraTrace(trace); 4706 } 4707 resolver.promise._reject(e, trace); 4708 } 4709 } 4710 return resolver.promise; 4711 4712 function Promise$_resolveFromThenable(y) { 4713 if (called) return; 4714 called = true; 4715 4716 if (x === y) { 4717 var e = Promise._makeSelfResolutionError(); 4718 if (originalPromise !== void 0) { 4719 originalPromise._attachExtraTrace(e); 4720 } 4721 resolver.promise._reject(e, void 0); 4722 return; 4723 } 4724 resolver.resolve(y); 4725 } 4726 4727 function Promise$_rejectFromThenable(r) { 4728 if (called) return; 4729 called = true; 4730 var trace = canAttach(r) ? r : new Error(r + ""); 4731 if (originalPromise !== void 0) { 4732 originalPromise._attachExtraTrace(trace); 4733 } 4734 resolver.promise._reject(r, trace); 4735 } 4736 4737 function Promise$_progressFromThenable(v) { 4738 if (called) return; 4739 var promise = resolver.promise; 4740 if (typeof promise._progress === "function") { 4741 promise._progress(v); 4742 } 4743 } 4744} 4745 4746return Promise$_Cast; 4747}; 4748 4749},{"./errors.js":10,"./util.js":35}],33:[function(_dereq_,module,exports){ 4750/** 4751 * The MIT License (MIT) 4752 * 4753 * Copyright (c) 2014 Petka Antonov 4754 * 4755 * Permission is hereby granted, free of charge, to any person obtaining a copy 4756 * of this software and associated documentation files (the "Software"), to deal 4757 * in the Software without restriction, including without limitation the rights 4758 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 4759 * copies of the Software, and to permit persons to whom the Software is 4760 * furnished to do so, subject to the following conditions:</p> 4761 * 4762 * The above copyright notice and this permission notice shall be included in 4763 * all copies or substantial portions of the Software. 4764 * 4765 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4766 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4767 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 4768 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 4769 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 4770 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 4771 * THE SOFTWARE. 4772 * 4773 */ 4774"use strict"; 4775var _setTimeout = function(fn, ms) { 4776 var len = arguments.length; 4777 var arg0 = arguments[2]; 4778 var arg1 = arguments[3]; 4779 var arg2 = len >= 5 ? arguments[4] : void 0; 4780 setTimeout(function() { 4781 fn(arg0, arg1, arg2); 4782 }, ms|0); 4783}; 4784 4785module.exports = function(Promise, INTERNAL, cast) { 4786var util = _dereq_("./util.js"); 4787var errors = _dereq_("./errors.js"); 4788var apiRejection = _dereq_("./errors_api_rejection")(Promise); 4789var TimeoutError = Promise.TimeoutError; 4790 4791var afterTimeout = function Promise$_afterTimeout(promise, message, ms) { 4792 if (!promise.isPending()) return; 4793 if (typeof message !== "string") { 4794 message = "operation timed out after" + " " + ms + " ms" 4795 } 4796 var err = new TimeoutError(message); 4797 errors.markAsOriginatingFromRejection(err); 4798 promise._attachExtraTrace(err); 4799 promise._cancel(err); 4800}; 4801 4802var afterDelay = function Promise$_afterDelay(value, promise) { 4803 promise._fulfill(value); 4804}; 4805
4806var delay = Promise.delay = function Promise$Delay(value, ms) { 4807 if (ms === void 0) { 4808 ms = value; 4809 value = void 0; 4810 } 4811 ms = +ms; 4812 var maybePromise = cast(value, void 0); 4813 var promise = new Promise(INTERNAL); 4814 4815 if (maybePromise instanceof Promise) { 4816 promise._propagateFrom(maybePromise, 7); 4817 promise._follow(maybePromise); 4818 return promise.then(function(value) { 4819 return Promise.delay(value, ms); 4820 }); 4821 } else { 4822 promise._setTrace(void 0); 4823 _setTimeout(afterDelay, ms, value, promise); 4824 } 4825 return promise; 4826}; 4827 4828Promise.prototype.delay = function Promise$delay(ms) { 4829 return delay(this, ms); 4830}; 4831 4832Promise.prototype.timeout = function Promise$timeout(ms, message) { 4833 ms = +ms; 4834 4835 var ret = new Promise(INTERNAL); 4836 ret._propagateFrom(this, 7); 4837 ret._follow(this); 4838 _setTimeout(afterTimeout, ms, ret, message, ms); 4839 return ret.cancellable(); 4840}; 4841 4842}; 4843 4844},{"./errors.js":10,"./errors_api_rejection":11,"./util.js":35}],34:[function(_dereq_,module,exports){ 4845/** 4846 * The MIT License (MIT) 4847 * 4848 * Copyright (c) 2014 Petka Antonov 4849 * 4850 * Permission is hereby granted, free of charge, to any person obtaining a copy 4851 * of this software and associated documentation files (the "Software"), to deal 4852 * in the Software without restriction, including without limitation the rights 4853 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 4854 * copies of the Software, and to permit persons to whom the Software is 4855 * furnished to do so, subject to the following conditions:</p> 4856 * 4857 * The above copyright notice and this permission notice shall be included in 4858 * all copies or substantial portions of the Software. 4859 * 4860 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4861 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4862 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 4863 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 4864 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 4865 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 4866 * THE SOFTWARE. 4867 * 4868 */ 4869"use strict"; 4870module.exports = function (Promise, apiRejection, cast) { 4871 var TypeError = _dereq_("./errors.js").TypeError; 4872 var inherits = _dereq_("./util.js").inherits; 4873 var PromiseInspection = Promise.PromiseInspection; 4874 4875 function inspectionMapper(inspections) { 4876 var len = inspections.length; 4877 for (var i = 0; i < len; ++i) { 4878 var inspection = inspections[i]; 4879 if (inspection.isRejected()) { 4880 return Promise.reject(inspection.error()); 4881 } 4882 inspections[i] = inspection.value(); 4883 } 4884 return inspections; 4885 } 4886 4887 function thrower(e) { 4888 setTimeout(function(){throw e;}, 0); 4889 } 4890 4891 function castPreservingDisposable(thenable) { 4892 var maybePromise = cast(thenable, void 0); 4893 if (maybePromise !== thenable && 4894 typeof thenable._isDisposable === "function" && 4895 typeof thenable._getDisposer === "function" && 4896 thenable._isDisposable()) { 4897 maybePromise._setDisposable(thenable._getDisposer()); 4898 } 4899 return maybePromise; 4900 } 4901 function dispose(resources, inspection) { 4902 var i = 0; 4903 var len = resources.length; 4904 var ret = Promise.defer(); 4905 function iterator() { 4906 if (i >= len) return ret.resolve(); 4907 var maybePromise = castPreservingDisposable(resources[i++]); 4908 if (maybePromise instanceof Promise && 4909 maybePromise._isDisposable()) { 4910 try { 4911 maybePromise = cast(maybePromise._getDisposer() 4912 .tryDispose(inspection), void 0); 4913 } catch (e) { 4914 return thrower(e); 4915 } 4916 if (maybePromise instanceof Promise) { 4917 return maybePromise._then(iterator, thrower, 4918 null, null, null); 4919 } 4920 } 4921 iterator(); 4922 } 4923 iterator(); 4924 return ret.promise; 4925 } 4926 4927 function disposerSuccess(value) { 4928 var inspection = new PromiseInspection(); 4929 inspection._settledValue = value; 4930 inspection._bitField = 268435456;
4931 return dispose(this, inspection).thenReturn(value); 4932 } 4933 4934 function disposerFail(reason) { 4935 var inspection = new PromiseInspection(); 4936 inspection._settledValue = reason; 4937 inspection._bitField = 134217728; 4938 return dispose(this, inspection).thenThrow(reason); 4939 } 4940 4941 function Disposer(data, promise) { 4942 this._data = data; 4943 this._promise = promise; 4944 } 4945 4946 Disposer.prototype.data = function Disposer$data() { 4947 return this._data; 4948 }; 4949 4950 Disposer.prototype.promise = function Disposer$promise() { 4951 return this._promise; 4952 }; 4953 4954 Disposer.prototype.resource = function Disposer$resource() { 4955 if (this.promise().isFulfilled()) { 4956 return this.promise().value(); 4957 } 4958 return null; 4959 }; 4960 4961 Disposer.prototype.tryDispose = function(inspection) { 4962 var resource = this.resource(); 4963 var ret = resource !== null 4964 ? this.doDispose(resource, inspection) : null; 4965 this._promise._unsetDisposable(); 4966 this._data = this._promise = null; 4967 return ret; 4968 }; 4969 4970 Disposer.isDisposer = function Disposer$isDisposer(d) { 4971 return (d != null && 4972 typeof d.resource === "function" && 4973 typeof d.tryDispose === "function"); 4974 }; 4975 4976 function FunctionDisposer(fn, promise) { 4977 this.constructor$(fn, promise); 4978 } 4979 inherits(FunctionDisposer, Disposer); 4980 4981 FunctionDisposer.prototype.doDispose = function (resource, inspection) { 4982 var fn = this.data(); 4983 return fn.call(resource, resource, inspection); 4984 }; 4985 4986 Promise.using = function Promise$using() { 4987 var len = arguments.length; 4988 if (len < 2) return apiRejection( 4989 "you must pass at least 2 arguments to Promise.using"); 4990 var fn = arguments[len - 1]; 4991 if (typeof fn !== "function") return apiRejection("fn must be a function"); 4992 len--; 4993 var resources = new Array(len); 4994 for (var i = 0; i < len; ++i) { 4995 var resource = arguments[i]; 4996 if (Disposer.isDisposer(resource)) { 4997 var disposer = resource; 4998 resource = resource.promise(); 4999 resource._setDisposable(disposer); 5000 } 5001 resources[i] = resource; 5002 } 5003 5004 return Promise.settle(resources) 5005 .then(inspectionMapper) 5006 .spread(fn) 5007 ._then(disposerSuccess, disposerFail, void 0, resources, void 0); 5008 }; 5009 5010 Promise.prototype._setDisposable = 5011 function Promise$_setDisposable(disposer) { 5012 this._bitField = this._bitField | 262144; 5013 this._disposer = disposer; 5014 }; 5015 5016 Promise.prototype._isDisposable = function Promise$_isDisposable() { 5017 return (this._bitField & 262144) > 0; 5018 }; 5019 5020 Promise.prototype._getDisposer = function Promise$_getDisposer() { 5021 return this._disposer; 5022 }; 5023 5024 Promise.prototype._unsetDisposable = function Promise$_unsetDisposable() { 5025 this._bitField = this._bitField & (~262144); 5026 this._disposer = void 0; 5027 }; 5028 5029 Promise.prototype.disposer = function Promise$disposer(fn) { 5030 if (typeof fn === "function") { 5031 return new FunctionDisposer(fn, this); 5032 } 5033 throw new TypeError(); 5034 }; 5035 5036}; 5037 5038},{"./errors.js":10,"./util.js":35}],35:[function(_dereq_,module,exports){ 5039/** 5040 * The MIT License (MIT) 5041 * 5042 * Copyright (c) 2014 Petka Antonov 5043 * 5044 * Permission is hereby granted, free of charge, to any person obtaining a copy 5045 * of this software and associated documentation files (the "Software"), to deal 5046 * in the Software without restriction, including without limitation the rights 5047 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5048 * copies of the Software, and to permit persons to whom the Software is 5049 * furnished to do so, subject to the following conditions:</p> 5050 * 5051 * The above copyright notice and this permission notice shall be included in 5052 * all copies or substantial portions of the Software. 5053 * 5054 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 5055 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 5056 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 5057 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 5058 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 5059 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 5060 * THE SOFTWARE. 5061 * 5062 */ 5063"use strict";
5064var es5 = _dereq_("./es5.js"); 5065var haveGetters = (function(){ 5066 try { 5067 var o = {}; 5068 es5.defineProperty(o, "f", { 5069 get: function () { 5070 return 3; 5071 } 5072 }); 5073 return o.f === 3; 5074 } 5075 catch (e) { 5076 return false; 5077 } 5078 5079})(); 5080var canEvaluate = typeof navigator == "undefined"; 5081var errorObj = {e: {}}; 5082function tryCatch1(fn, receiver, arg) { 5083 try { return fn.call(receiver, arg); } 5084 catch (e) { 5085 errorObj.e = e; 5086 return errorObj; 5087 } 5088} 5089 5090function tryCatch2(fn, receiver, arg, arg2) { 5091 try { return fn.call(receiver, arg, arg2); } 5092 catch (e) { 5093 errorObj.e = e; 5094 return errorObj; 5095 } 5096} 5097 5098function tryCatch3(fn, receiver, arg, arg2, arg3) { 5099 try { return fn.call(receiver, arg, arg2, arg3); } 5100 catch (e) { 5101 errorObj.e = e; 5102 return errorObj; 5103 } 5104} 5105 5106function tryCatch4(fn, receiver, arg, arg2, arg3, arg4) { 5107 try { return fn.call(receiver, arg, arg2, arg3, arg4); } 5108 catch (e) { 5109 errorObj.e = e; 5110 return errorObj; 5111 } 5112} 5113 5114function tryCatchApply(fn, args, receiver) { 5115 try { return fn.apply(receiver, args); } 5116 catch (e) { 5117 errorObj.e = e; 5118 return errorObj; 5119 } 5120} 5121 5122var inherits = function(Child, Parent) { 5123 var hasProp = {}.hasOwnProperty; 5124 5125 function T() { 5126 this.constructor = Child; 5127 this.constructor$ = Parent; 5128 for (var propertyName in Parent.prototype) { 5129 if (hasProp.call(Parent.prototype, propertyName) && 5130 propertyName.charAt(propertyName.length-1) !== "$" 5131 ) { 5132 this[propertyName + "$"] = Parent.prototype[propertyName]; 5133 } 5134 } 5135 } 5136 T.prototype = Parent.prototype; 5137 Child.prototype = new T(); 5138 return Child.prototype; 5139}; 5140 5141function asString(val) { 5142 return typeof val === "string" ? val : ("" + val); 5143} 5144 5145function isPrimitive(val) { 5146 return val == null || val === true || val === false || 5147 typeof val === "string" || typeof val === "number"; 5148 5149} 5150 5151function isObject(value) { 5152 return !isPrimitive(value); 5153} 5154 5155function maybeWrapAsError(maybeError) { 5156 if (!isPrimitive(maybeError)) return maybeError; 5157 5158 return new Error(asString(maybeError)); 5159} 5160 5161function withAppended(target, appendee) { 5162 var len = target.length; 5163 var ret = new Array(len + 1); 5164 var i; 5165 for (i = 0; i < len; ++i) { 5166 ret[i] = target[i]; 5167 } 5168 ret[i] = appendee; 5169 return ret; 5170} 5171 5172function getDataPropertyOrDefault(obj, key, defaultValue) { 5173 if (es5.isES5) { 5174 var desc = Object.getOwnPropertyDescriptor(obj, key); 5175 if (desc != null) { 5176 return desc.get == null && desc.set == null 5177 ? desc.value 5178 : defaultValue; 5179 } 5180 } else { 5181 return {}.hasOwnProperty.call(obj, key) ? obj[key] : void 0; 5182 } 5183} 5184 5185function notEnumerableProp(obj, name, value) { 5186 if (isPrimitive(obj)) return obj; 5187 var descriptor = { 5188 value: value, 5189 configurable: true, 5190 enumerable: false, 5191 writable: true 5192 }; 5193 es5.defineProperty(obj, name, descriptor); 5194 return obj; 5195} 5196 5197 5198var wrapsPrimitiveReceiver = (function() { 5199 return this !== "string"; 5200}).call("string"); 5201 5202function thrower(r) { 5203 throw r; 5204} 5205 5206var inheritedDataKeys = (function() { 5207 if (es5.isES5) { 5208 return function(obj, opts) { 5209 var ret = []; 5210 var visitedKeys = Object.create(null); 5211 var getKeys = Object(opts).includeHidden 5212 ? Object.getOwnPropertyNames 5213 : Object.keys; 5214 while (obj != null) { 5215 var keys; 5216 try { 5217 keys = getKeys(obj); 5218 } catch (e) { 5219 return ret; 5220 } 5221 for (var i = 0; i < keys.length; ++i) { 5222 var key = keys[i]; 5223 if (visitedKeys[key]) continue; 5224 visitedKeys[key] = true; 5225 var desc = Object.getOwnPropertyDescriptor(obj, key); 5226 if (desc != null && desc.get == null && desc.set == null) {
5227 ret.push(key); 5228 } 5229 } 5230 obj = es5.getPrototypeOf(obj); 5231 } 5232 return ret; 5233 }; 5234 } else { 5235 return function(obj) { 5236 var ret = []; 5237 /*jshint forin:false */ 5238 for (var key in obj) { 5239 ret.push(key); 5240 } 5241 return ret; 5242 }; 5243 } 5244 5245})(); 5246 5247function isClass(fn) { 5248 try { 5249 if (typeof fn === "function") { 5250 var keys = es5.keys(fn.prototype); 5251 return keys.length > 0 && 5252 !(keys.length === 1 && keys[0] === "constructor"); 5253 } 5254 return false; 5255 } catch (e) { 5256 return false; 5257 } 5258} 5259 5260function toFastProperties(obj) { 5261 /*jshint -W027*/ 5262 function f() {} 5263 f.prototype = obj; 5264 return f; 5265 eval(obj); 5266} 5267 5268var rident = /^[a-z$_][a-z$_0-9]*$/i; 5269function isIdentifier(str) { 5270 return rident.test(str); 5271} 5272 5273function filledRange(count, prefix, suffix) { 5274 var ret = new Array(count); 5275 for(var i = 0; i < count; ++i) { 5276 ret[i] = prefix + i + suffix; 5277 } 5278 return ret; 5279} 5280 5281var ret = { 5282 isClass: isClass, 5283 isIdentifier: isIdentifier, 5284 inheritedDataKeys: inheritedDataKeys, 5285 getDataPropertyOrDefault: getDataPropertyOrDefault, 5286 thrower: thrower, 5287 isArray: es5.isArray, 5288 haveGetters: haveGetters, 5289 notEnumerableProp: notEnumerableProp, 5290 isPrimitive: isPrimitive, 5291 isObject: isObject, 5292 canEvaluate: canEvaluate, 5293 errorObj: errorObj, 5294 tryCatch1: tryCatch1, 5295 tryCatch2: tryCatch2, 5296 tryCatch3: tryCatch3, 5297 tryCatch4: tryCatch4, 5298 tryCatchApply: tryCatchApply, 5299 inherits: inherits, 5300 withAppended: withAppended, 5301 asString: asString, 5302 maybeWrapAsError: maybeWrapAsError, 5303 wrapsPrimitiveReceiver: wrapsPrimitiveReceiver, 5304 toFastProperties: toFastProperties, 5305 filledRange: filledRange 5306}; 5307 5308module.exports = ret; 5309 5310},{"./es5.js":12}]},{},[3]) 5311(3) 5312}); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.