From 2195fa910fd55578600470ed8d5dcc497a7b4144 Mon Sep 17 00:00:00 2001
From: Gordon Woodhull
Date: Fri, 20 Feb 2015 19:06:15 -0500
Subject: [PATCH 1/3] upgrade bluebird and use line breaks in R stack traces
fixes #1360
---
htdocs/js/rcloud.js | 4 +-
htdocs/lib/dependencies_bundle.js | 7157 ++++++++++++------------
htdocs/lib/dependencies_bundle.min.js | 63 +-
htdocs/lib/js/bluebird.js | 7253 ++++++++++++-------------
4 files changed, 6780 insertions(+), 7697 deletions(-)
diff --git a/htdocs/js/rcloud.js b/htdocs/js/rcloud.js
index 2d429aa1b5..50d17a7e05 100644
--- a/htdocs/js/rcloud.js
+++ b/htdocs/js/rcloud.js
@@ -25,8 +25,8 @@ RCloud.promisify_paths = (function() {
function success(result) {
if(result && RCloud.is_exception(result)) {
var tb = result['traceback'] ? result['traceback'] : "";
- if (tb.join) tb = tb.join(" <- ");
- throw new Error(command + ": " + result['error'].replace('\n', ' ') + " " + tb);
+ if (tb.join) tb = tb.join("\n");
+ throw new Error(command + ": " + result.error + tb);
}
return result;
}
diff --git a/htdocs/lib/dependencies_bundle.js b/htdocs/lib/dependencies_bundle.js
index d3cfb07fd5..3cbebe5de8 100644
--- a/htdocs/lib/dependencies_bundle.js
+++ b/htdocs/lib/dependencies_bundle.js
@@ -2066,34 +2066,9 @@ var requirejs, require, define;
//Set up with config info.
req(cfg);
}(this));
-/**
- * bluebird build version 1.1.1
- * Features enabled: core, timers, race, any, call_get, filter, generators, map, nodeify, promisify, props, reduce, settle, some, progress, cancel, synchronous_inspection
-*/
-/**
- * @preserve Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
+/* @preserve
+ * The MIT License (MIT)
*
- */
-!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Promise=e():"undefined"!=typeof global?global.Promise=e():"undefined"!=typeof self&&(self.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
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{}],2:[function(_dereq_,module,exports){
"use strict";
-var schedule = require("./schedule.js");
-var Queue = require("./queue.js");
-var errorObj = require("./util.js").errorObj;
-var tryCatch1 = require("./util.js").tryCatch1;
-var process = require("./global.js").process;
+var firstLineError;
+try {throw new Error(); } catch (e) {firstLineError = e;}
+var schedule = _dereq_("./schedule.js");
+var Queue = _dereq_("./queue.js");
+var _process = typeof process !== "undefined" ? process : undefined;
function Async() {
this._isTickUsed = false;
- this._length = 0;
- this._lateBuffer = new Queue();
- this._functionBuffer = new Queue(25000 * 3);
+ this._lateQueue = new Queue(16);
+ this._normalQueue = new Queue(16);
var self = this;
- this.consumeFunctionBuffer = function Async$consumeFunctionBuffer() {
- self._consumeFunctionBuffer();
+ this.drainQueues = function () {
+ self._drainQueues();
};
+ this._schedule =
+ schedule.isStatic ? schedule(this.drainQueues) : schedule;
}
-Async.prototype.haveItemsQueued = function Async$haveItemsQueued() {
- return this._length > 0;
+Async.prototype.haveItemsQueued = function () {
+ return this._normalQueue.length() > 0;
};
-Async.prototype.invokeLater = function Async$invokeLater(fn, receiver, arg) {
- if (process !== void 0 &&
- process.domain != null &&
+Async.prototype._withDomain = function(fn) {
+ if (_process !== undefined &&
+ _process.domain != null &&
!fn.domain) {
- fn = process.domain.bind(fn);
+ fn = _process.domain.bind(fn);
}
- this._lateBuffer.push(fn, receiver, arg);
- this._queueTick();
+ return fn;
};
-Async.prototype.invoke = function Async$invoke(fn, receiver, arg) {
- if (process !== void 0 &&
- process.domain != null &&
- !fn.domain) {
- fn = process.domain.bind(fn);
+Async.prototype.throwLater = function(fn, arg) {
+ if (arguments.length === 1) {
+ arg = fn;
+ fn = function () { throw arg; };
+ }
+ fn = this._withDomain(fn);
+ if (typeof setTimeout !== "undefined") {
+ setTimeout(function() {
+ fn(arg);
+ }, 0);
+ } else try {
+ this._schedule(function() {
+ fn(arg);
+ });
+ } catch (e) {
+ throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/m3OTXk\u000a");
}
- var functionBuffer = this._functionBuffer;
- functionBuffer.push(fn, receiver, arg);
- this._length = functionBuffer.length();
+};
+
+Async.prototype.invokeLater = function (fn, receiver, arg) {
+ fn = this._withDomain(fn);
+ this._lateQueue.push(fn, receiver, arg);
+ this._queueTick();
+};
+
+Async.prototype.invokeFirst = function (fn, receiver, arg) {
+ fn = this._withDomain(fn);
+ this._normalQueue.unshift(fn, receiver, arg);
+ this._queueTick();
+};
+
+Async.prototype.invoke = function (fn, receiver, arg) {
+ fn = this._withDomain(fn);
+ this._normalQueue.push(fn, receiver, arg);
+ this._queueTick();
+};
+
+Async.prototype.settlePromises = function(promise) {
+ this._normalQueue._pushOne(promise);
this._queueTick();
};
-Async.prototype._consumeFunctionBuffer =
-function Async$_consumeFunctionBuffer() {
- var functionBuffer = this._functionBuffer;
- while(functionBuffer.length() > 0) {
- var fn = functionBuffer.shift();
- var receiver = functionBuffer.shift();
- var arg = functionBuffer.shift();
+Async.prototype._drainQueue = function(queue) {
+ while (queue.length() > 0) {
+ var fn = queue.shift();
+ if (typeof fn !== "function") {
+ fn._settlePromises();
+ continue;
+ }
+ var receiver = queue.shift();
+ var arg = queue.shift();
fn.call(receiver, arg);
}
+};
+
+Async.prototype._drainQueues = function () {
+ this._drainQueue(this._normalQueue);
this._reset();
- this._consumeLateBuffer();
-};
-
-Async.prototype._consumeLateBuffer = function Async$_consumeLateBuffer() {
- var buffer = this._lateBuffer;
- while(buffer.length() > 0) {
- var fn = buffer.shift();
- var receiver = buffer.shift();
- var arg = buffer.shift();
- var res = tryCatch1(fn, receiver, arg);
- if (res === errorObj) {
- this._queueTick();
- if (fn.domain != null) {
- fn.domain.emit("error", res.e);
- }
- else {
- throw res.e;
- }
- }
- }
+ this._drainQueue(this._lateQueue);
};
-Async.prototype._queueTick = function Async$_queue() {
+Async.prototype._queueTick = function () {
if (!this._isTickUsed) {
- schedule(this.consumeFunctionBuffer);
this._isTickUsed = true;
+ this._schedule(this.drainQueues);
}
};
-Async.prototype._reset = function Async$_reset() {
+Async.prototype._reset = function () {
this._isTickUsed = false;
- this._length = 0;
};
module.exports = new Async();
+module.exports.firstLineError = firstLineError;
-},{"./global.js":15,"./queue.js":27,"./schedule.js":30,"./util.js":38}],3:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var Promise = require("./promise.js")();
-module.exports = Promise;
-},{"./promise.js":19}],4:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./queue.js":28,"./schedule.js":31}],3:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(Promise) {
- Promise.prototype.call = function Promise$call(propertyName) {
- var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
+module.exports = function(Promise, INTERNAL, tryConvertToPromise) {
+var rejectThis = function(_, e) {
+ this._reject(e);
+};
- return this._then(function(obj) {
- return obj[propertyName].apply(obj, args);
- },
- void 0,
- void 0,
- void 0,
- void 0,
- this.call
- );
- };
+var targetRejected = function(e, context) {
+ context.promiseRejectionQueued = true;
+ context.bindingPromise._then(rejectThis, rejectThis, null, this, e);
+};
- function Promise$getter(obj) {
- var prop = typeof this === "string"
- ? this
- : ("" + this);
- return obj[prop];
+var bindingResolved = function(thisArg, context) {
+ this._setBoundTo(thisArg);
+ if (this._isPending()) {
+ this._resolveCallback(context.target);
}
- Promise.prototype.get = function Promise$get(propertyName) {
- return this._then(
- Promise$getter,
- void 0,
- void 0,
- propertyName,
- void 0,
- this.get
- );
- };
};
-},{}],5:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, INTERNAL) {
- var errors = require("./errors.js");
- var async = require("./async.js");
- var CancellationError = errors.CancellationError;
- var SYNC_TOKEN = {};
-
- Promise.prototype._cancel = function Promise$_cancel() {
- if (!this.isCancellable()) return this;
- var parent;
- if ((parent = this._cancellationParent) !== void 0) {
- parent.cancel(SYNC_TOKEN);
- return;
- }
- var err = new CancellationError();
- this._attachExtraTrace(err);
- this._rejectUnchecked(err);
- };
+var bindingRejected = function(e, context) {
+ if (!context.promiseRejectionQueued) this._reject(e);
+};
- Promise.prototype.cancel = function Promise$cancel(token) {
- if (!this.isCancellable()) return this;
- if (token === SYNC_TOKEN) {
- this._cancel();
- return this;
- }
- async.invokeLater(this._cancel, this, void 0);
- return this;
- };
+Promise.prototype.bind = function (thisArg) {
+ var maybePromise = tryConvertToPromise(thisArg);
+ var ret = new Promise(INTERNAL);
+ ret._propagateFrom(this, 1);
+ var target = this._target();
+ if (maybePromise instanceof Promise) {
+ var context = {
+ promiseRejectionQueued: false,
+ promise: ret,
+ target: target,
+ bindingPromise: maybePromise
+ };
+ target._then(INTERNAL, targetRejected, ret._progress, ret, context);
+ maybePromise._then(
+ bindingResolved, bindingRejected, ret._progress, ret, context);
+ } else {
+ ret._setBoundTo(thisArg);
+ ret._resolveCallback(target);
+ }
+ return ret;
+};
- Promise.prototype.cancellable = function Promise$cancellable() {
- if (this._cancellable()) return this;
- this._setCancellable();
- this._cancellationParent = void 0;
- return this;
- };
+Promise.prototype._setBoundTo = function (obj) {
+ if (obj !== undefined) {
+ this._bitField = this._bitField | 131072;
+ this._boundTo = obj;
+ } else {
+ this._bitField = this._bitField & (~131072);
+ }
+};
- Promise.prototype.uncancellable = function Promise$uncancellable() {
- var ret = new Promise(INTERNAL);
- ret._setTrace(this.uncancellable, this);
- ret._follow(this);
- ret._unsetCancellable();
- if (this._isBound()) ret._setBoundTo(this._boundTo);
- return ret;
- };
+Promise.prototype._isBound = function () {
+ return (this._bitField & 131072) === 131072;
+};
- Promise.prototype.fork =
- function Promise$fork(didFulfill, didReject, didProgress) {
- var ret = this._then(didFulfill, didReject, didProgress,
- void 0, void 0, this.fork);
+Promise.bind = function (thisArg, value) {
+ var maybePromise = tryConvertToPromise(thisArg);
+ var ret = new Promise(INTERNAL);
- ret._setCancellable();
- ret._cancellationParent = void 0;
- return ret;
- };
+ if (maybePromise instanceof Promise) {
+ maybePromise._then(function(thisArg) {
+ ret._setBoundTo(thisArg);
+ ret._resolveCallback(value);
+ }, ret._reject, ret._progress, ret, null);
+ } else {
+ ret._setBoundTo(thisArg);
+ ret._resolveCallback(value);
+ }
+ return ret;
+};
};
-},{"./async.js":2,"./errors.js":9}],6:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{}],4:[function(_dereq_,module,exports){
"use strict";
-module.exports = function() {
-var inherits = require("./util.js").inherits;
-var defineProperty = require("./es5.js").defineProperty;
-
-var rignore = new RegExp(
- "\\b(?:[\\w.]*Promise(?:Array|Spawn)?\\$_\\w+|" +
- "tryCatch(?:1|2|Apply)|new \\w*PromiseArray|" +
- "\\w*PromiseArray\\.\\w*PromiseArray|" +
- "setTimeout|CatchFilter\\$_\\w+|makeNodePromisified|processImmediate|" +
- "process._tickCallback|nextTick|Async\\$\\w+)\\b"
-);
-
-var rtraceline = null;
-var formatStack = null;
-var areNamesMangled = false;
+var old;
+if (typeof Promise !== "undefined") old = Promise;
+function noConflict() {
+ try { if (Promise === bluebird) Promise = old; }
+ catch (e) {}
+ return bluebird;
+}
+var bluebird = _dereq_("./promise.js")();
+bluebird.noConflict = noConflict;
+module.exports = bluebird;
-function formatNonError(obj) {
- var str;
- if (typeof obj === "function") {
- str = "[function " +
- (obj.name || "anonymous") +
- "]";
- }
- else {
- str = obj.toString();
- var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
- if (ruselessToString.test(str)) {
- try {
- var newStr = JSON.stringify(obj);
- str = newStr;
- }
- catch(e) {
+},{"./promise.js":23}],5:[function(_dereq_,module,exports){
+"use strict";
+var cr = Object.create;
+if (cr) {
+ var callerCache = cr(null);
+ var getterCache = cr(null);
+ callerCache[" size"] = getterCache[" size"] = 0;
+}
- }
+module.exports = function(Promise) {
+var util = _dereq_("./util.js");
+var canEvaluate = util.canEvaluate;
+var isIdentifier = util.isIdentifier;
+
+var getMethodCaller;
+var getGetter;
+if (!true) {
+var makeMethodCaller = function (methodName) {
+ return new Function("ensureMethod", " \n\
+ return function(obj) { \n\
+ 'use strict' \n\
+ var len = this.length; \n\
+ ensureMethod(obj, 'methodName'); \n\
+ switch(len) { \n\
+ case 1: return obj.methodName(this[0]); \n\
+ case 2: return obj.methodName(this[0], this[1]); \n\
+ case 3: return obj.methodName(this[0], this[1], this[2]); \n\
+ case 0: return obj.methodName(); \n\
+ default: \n\
+ return obj.methodName.apply(obj, this); \n\
+ } \n\
+ }; \n\
+ ".replace(/methodName/g, methodName))(ensureMethod);
+};
+
+var makeGetter = function (propertyName) {
+ return new Function("obj", " \n\
+ 'use strict'; \n\
+ return obj.propertyName; \n\
+ ".replace("propertyName", propertyName));
+};
+
+var getCompiled = function(name, compiler, cache) {
+ var ret = cache[name];
+ if (typeof ret !== "function") {
+ if (!isIdentifier(name)) {
+ return null;
}
- if (str.length === 0) {
- str = "(empty array)";
+ ret = compiler(name);
+ cache[name] = ret;
+ cache[" size"]++;
+ if (cache[" size"] > 512) {
+ var keys = Object.keys(cache);
+ for (var i = 0; i < 256; ++i) delete cache[keys[i]];
+ cache[" size"] = keys.length - 256;
}
}
- return ("(<" + snip(str) + ">, no stack trace)");
+ return ret;
+};
+
+getMethodCaller = function(name) {
+ return getCompiled(name, makeMethodCaller, callerCache);
+};
+
+getGetter = function(name) {
+ return getCompiled(name, makeGetter, getterCache);
+};
}
-function snip(str) {
- var maxChars = 41;
- if (str.length < maxChars) {
- return str;
+function ensureMethod(obj, methodName) {
+ var fn;
+ if (obj != null) fn = obj[methodName];
+ if (typeof fn !== "function") {
+ var message = "Object " + util.classString(obj) + " has no method '" +
+ util.toString(methodName) + "'";
+ throw new Promise.TypeError(message);
}
- return str.substr(0, maxChars - 3) + "...";
+ return fn;
}
-function CapturedTrace(ignoreUntil, isTopLevel) {
- if (!areNamesMangled) {
+function caller(obj) {
+ var methodName = this.pop();
+ var fn = ensureMethod(obj, methodName);
+ return fn.apply(obj, this);
+}
+Promise.prototype.call = function (methodName) {
+ var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
+ if (!true) {
+ if (canEvaluate) {
+ var maybeCaller = getMethodCaller(methodName);
+ if (maybeCaller !== null) {
+ return this._then(
+ maybeCaller, undefined, undefined, args, undefined);
+ }
+ }
}
- this.captureStackTrace(ignoreUntil, isTopLevel);
+ args.push(methodName);
+ return this._then(caller, undefined, undefined, args, undefined);
+};
+function namedGetter(obj) {
+ return obj[this];
}
-inherits(CapturedTrace, Error);
+function indexedGetter(obj) {
+ var index = +this;
+ if (index < 0) index = Math.max(0, index + obj.length);
+ return obj[index];
+}
+Promise.prototype.get = function (propertyName) {
+ var isIndex = (typeof propertyName === "number");
+ var getter;
+ if (!isIndex) {
+ if (canEvaluate) {
+ var maybeGetter = getGetter(propertyName);
+ getter = maybeGetter !== null ? maybeGetter : namedGetter;
+ } else {
+ getter = namedGetter;
+ }
+ } else {
+ getter = indexedGetter;
+ }
+ return this._then(getter, undefined, undefined, propertyName, undefined);
+};
+};
+
+},{"./util.js":38}],6:[function(_dereq_,module,exports){
+"use strict";
+module.exports = function(Promise) {
+var errors = _dereq_("./errors.js");
+var async = _dereq_("./async.js");
+var CancellationError = errors.CancellationError;
-CapturedTrace.prototype.captureStackTrace =
-function CapturedTrace$captureStackTrace(ignoreUntil, isTopLevel) {
- captureStackTrace(this, ignoreUntil, isTopLevel);
+Promise.prototype._cancel = function (reason) {
+ if (!this.isCancellable()) return this;
+ var parent;
+ var promiseToReject = this;
+ while ((parent = promiseToReject._cancellationParent) !== undefined &&
+ parent.isCancellable()) {
+ promiseToReject = parent;
+ }
+ this._unsetCancellable();
+ promiseToReject._target()._rejectCallback(reason, false, true);
};
-CapturedTrace.possiblyUnhandledRejection =
-function CapturedTrace$PossiblyUnhandledRejection(reason) {
- if (typeof console === "object") {
- var message;
- if (typeof reason === "object" || typeof reason === "function") {
- var stack = reason.stack;
- message = "Possibly unhandled " + formatStack(stack, reason);
+Promise.prototype.cancel = function (reason) {
+ if (!this.isCancellable()) return this;
+ if (reason === undefined) reason = new CancellationError();
+ async.invokeLater(this._cancel, this, reason);
+ return this;
+};
+
+Promise.prototype.cancellable = function () {
+ if (this._cancellable()) return this;
+ this._setCancellable();
+ this._cancellationParent = undefined;
+ return this;
+};
+
+Promise.prototype.uncancellable = function () {
+ var ret = this.then();
+ ret._unsetCancellable();
+ return ret;
+};
+
+Promise.prototype.fork = function (didFulfill, didReject, didProgress) {
+ var ret = this._then(didFulfill, didReject, didProgress,
+ undefined, undefined);
+
+ ret._setCancellable();
+ ret._cancellationParent = undefined;
+ return ret;
+};
+};
+
+},{"./async.js":2,"./errors.js":13}],7:[function(_dereq_,module,exports){
+"use strict";
+module.exports = function() {
+var async = _dereq_("./async.js");
+var util = _dereq_("./util.js");
+var bluebirdFramePattern =
+ /[\\\/]bluebird[\\\/]js[\\\/](main|debug|zalgo|instrumented)/;
+var stackFramePattern = null;
+var formatStack = null;
+var indentStackFrames = false;
+var warn;
+
+function CapturedTrace(parent) {
+ this._parent = parent;
+ var length = this._length = 1 + (parent === undefined ? 0 : parent._length);
+ captureStackTrace(this, CapturedTrace);
+ if (length > 32) this.uncycle();
+}
+util.inherits(CapturedTrace, Error);
+
+CapturedTrace.prototype.uncycle = function() {
+ var length = this._length;
+ if (length < 2) return;
+ var nodes = [];
+ var stackToIndex = {};
+
+ for (var i = 0, node = this; node !== undefined; ++i) {
+ nodes.push(node);
+ node = node._parent;
+ }
+ length = this._length = i;
+ for (var i = length - 1; i >= 0; --i) {
+ var stack = nodes[i].stack;
+ if (stackToIndex[stack] === undefined) {
+ stackToIndex[stack] = i;
+ }
+ }
+ for (var i = 0; i < length; ++i) {
+ var currentStack = nodes[i].stack;
+ var index = stackToIndex[currentStack];
+ if (index !== undefined && index !== i) {
+ if (index > 0) {
+ nodes[index - 1]._parent = undefined;
+ nodes[index - 1]._length = 1;
+ }
+ nodes[i]._parent = undefined;
+ nodes[i]._length = 1;
+ var cycleEdgeNode = i > 0 ? nodes[i - 1] : this;
+
+ if (index < length - 1) {
+ cycleEdgeNode._parent = nodes[index + 1];
+ cycleEdgeNode._parent.uncycle();
+ cycleEdgeNode._length =
+ cycleEdgeNode._parent._length + 1;
+ } else {
+ cycleEdgeNode._parent = undefined;
+ cycleEdgeNode._length = 1;
+ }
+ var currentChildLength = cycleEdgeNode._length + 1;
+ for (var j = i - 2; j >= 0; --j) {
+ nodes[j]._length = currentChildLength;
+ currentChildLength++;
+ }
+ return;
}
- else {
- message = "Possibly unhandled " + String(reason);
+ }
+};
+
+CapturedTrace.prototype.parent = function() {
+ return this._parent;
+};
+
+CapturedTrace.prototype.hasParent = function() {
+ return this._parent !== undefined;
+};
+
+CapturedTrace.prototype.attachExtraTrace = function(error) {
+ if (error.__stackCleaned__) return;
+ this.uncycle();
+ var parsed = CapturedTrace.parseStackAndMessage(error);
+ var message = parsed.message;
+ var stacks = [parsed.stack];
+
+ var trace = this;
+ while (trace !== undefined) {
+ stacks.push(cleanStack(trace.stack.split("\n")));
+ trace = trace._parent;
+ }
+ removeCommonRoots(stacks);
+ removeDuplicateOrEmptyJumps(stacks);
+ error.stack = reconstructStack(message, stacks);
+ util.notEnumerableProp(error, "__stackCleaned__", true);
+};
+
+function reconstructStack(message, stacks) {
+ for (var i = 0; i < stacks.length - 1; ++i) {
+ stacks[i].push("From previous event:");
+ stacks[i] = stacks[i].join("\n");
+ }
+ if (i < stacks.length) {
+ stacks[i] = stacks[i].join("\n");
+ }
+ return message + "\n" + stacks.join("\n");
+}
+
+function removeDuplicateOrEmptyJumps(stacks) {
+ for (var i = 0; i < stacks.length; ++i) {
+ if (stacks[i].length === 0 ||
+ ((i + 1 < stacks.length) && stacks[i][0] === stacks[i+1][0])) {
+ stacks.splice(i, 1);
+ i--;
+ }
+ }
+}
+
+function removeCommonRoots(stacks) {
+ var current = stacks[0];
+ for (var i = 1; i < stacks.length; ++i) {
+ var prev = stacks[i];
+ var currentLastIndex = current.length - 1;
+ var currentLastLine = current[currentLastIndex];
+ var commonRootMeetPoint = -1;
+
+ for (var j = prev.length - 1; j >= 0; --j) {
+ if (prev[j] === currentLastLine) {
+ commonRootMeetPoint = j;
+ break;
+ }
+ }
+
+ for (var j = commonRootMeetPoint; j >= 0; --j) {
+ var line = prev[j];
+ if (current[currentLastIndex] === line) {
+ current.pop();
+ currentLastIndex--;
+ } else {
+ break;
+ }
+ }
+ current = prev;
+ }
+}
+
+function cleanStack(stack) {
+ var ret = [];
+ for (var i = 0; i < stack.length; ++i) {
+ var line = stack[i];
+ var isTraceLine = stackFramePattern.test(line) ||
+ " (No stack trace)" === line;
+ var isInternalFrame = isTraceLine && shouldIgnore(line);
+ if (isTraceLine && !isInternalFrame) {
+ if (indentStackFrames && line.charAt(0) !== " ") {
+ line = " " + line;
+ }
+ ret.push(line);
+ }
+ }
+ return ret;
+}
+
+function stackFramesAsArray(error) {
+ var stack = error.stack.replace(/\s+$/g, "").split("\n");
+ for (var i = 0; i < stack.length; ++i) {
+ var line = stack[i];
+ if (" (No stack trace)" === line || stackFramePattern.test(line)) {
+ break;
}
- if (typeof console.error === "function" ||
- typeof console.error === "object") {
- console.error(message);
+ }
+ if (i > 0) {
+ stack = stack.slice(i);
+ }
+ return stack;
+}
+
+CapturedTrace.parseStackAndMessage = function(error) {
+ var stack = error.stack;
+ var message = error.toString();
+ stack = typeof stack === "string" && stack.length > 0
+ ? stackFramesAsArray(error) : [" (No stack trace)"];
+ return {
+ message: message,
+ stack: cleanStack(stack)
+ };
+};
+
+CapturedTrace.formatAndLogError = function(error, title) {
+ if (typeof console !== "undefined") {
+ var message;
+ if (typeof error === "object" || typeof error === "function") {
+ var stack = error.stack;
+ message = title + formatStack(stack, error);
+ } else {
+ message = title + String(error);
}
- else if (typeof console.log === "function" ||
- typeof console.error === "object") {
+ if (typeof warn === "function") {
+ warn(message);
+ } else if (typeof console.log === "function" ||
+ typeof console.log === "object") {
console.log(message);
}
}
};
-areNamesMangled = CapturedTrace.prototype.captureStackTrace.name !==
- "CapturedTrace$captureStackTrace";
+CapturedTrace.unhandledRejection = function (reason) {
+ CapturedTrace.formatAndLogError(reason, "^--- With additional stack trace: ");
+};
+
+CapturedTrace.isSupported = function () {
+ return typeof captureStackTrace === "function";
+};
-CapturedTrace.combine = function CapturedTrace$Combine(current, prev) {
- var curLast = current.length - 1;
- for (var i = prev.length - 1; i >= 0; --i) {
- var line = prev[i];
- if (current[curLast] === line) {
- current.pop();
- curLast--;
+CapturedTrace.fireRejectionEvent =
+function(name, localHandler, reason, promise) {
+ var localEventFired = false;
+ try {
+ if (typeof localHandler === "function") {
+ localEventFired = true;
+ if (name === "rejectionHandled") {
+ localHandler(promise);
+ } else {
+ localHandler(reason, promise);
+ }
}
- else {
- break;
+ } catch (e) {
+ async.throwLater(e);
+ }
+
+ var globalEventFired = false;
+ try {
+ globalEventFired = fireGlobalEvent(name, reason, promise);
+ } catch (e) {
+ globalEventFired = true;
+ async.throwLater(e);
+ }
+
+ var domEventFired = false;
+ if (fireDomEvent) {
+ try {
+ domEventFired = fireDomEvent(name.toLowerCase(), {
+ reason: reason,
+ promise: promise
+ });
+ } catch (e) {
+ domEventFired = true;
+ async.throwLater(e);
}
}
- current.push("From previous event:");
- var lines = current.concat(prev);
+ if (!globalEventFired && !localEventFired && !domEventFired &&
+ name === "unhandledRejection") {
+ CapturedTrace.formatAndLogError(reason, "Unhandled rejection ");
+ }
+};
- var ret = [];
+function formatNonError(obj) {
+ var str;
+ if (typeof obj === "function") {
+ str = "[function " +
+ (obj.name || "anonymous") +
+ "]";
+ } else {
+ str = obj.toString();
+ var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
+ if (ruselessToString.test(str)) {
+ try {
+ var newStr = JSON.stringify(obj);
+ str = newStr;
+ }
+ catch(e) {
+ }
+ }
+ if (str.length === 0) {
+ str = "(empty array)";
+ }
+ }
+ return ("(<" + snip(str) + ">, no stack trace)");
+}
- for (var i = 0, len = lines.length; i < len; ++i) {
+function snip(str) {
+ var maxChars = 41;
+ if (str.length < maxChars) {
+ return str;
+ }
+ return str.substr(0, maxChars - 3) + "...";
+}
- if ((rignore.test(lines[i]) ||
- (i > 0 && !rtraceline.test(lines[i])) &&
- lines[i] !== "From previous event:")
- ) {
- continue;
+var shouldIgnore = function() { return false; };
+var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;
+function parseLineInfo(line) {
+ var matches = line.match(parseLineInfoRegex);
+ if (matches) {
+ return {
+ fileName: matches[1],
+ line: parseInt(matches[2], 10)
+ };
+ }
+}
+CapturedTrace.setBounds = function(firstLineError, lastLineError) {
+ if (!CapturedTrace.isSupported()) return;
+ var firstStackLines = firstLineError.stack.split("\n");
+ var lastStackLines = lastLineError.stack.split("\n");
+ var firstIndex = -1;
+ var lastIndex = -1;
+ var firstFileName;
+ var lastFileName;
+ for (var i = 0; i < firstStackLines.length; ++i) {
+ var result = parseLineInfo(firstStackLines[i]);
+ if (result) {
+ firstFileName = result.fileName;
+ firstIndex = result.line;
+ break;
}
- ret.push(lines[i]);
}
- return ret;
-};
+ for (var i = 0; i < lastStackLines.length; ++i) {
+ var result = parseLineInfo(lastStackLines[i]);
+ if (result) {
+ lastFileName = result.fileName;
+ lastIndex = result.line;
+ break;
+ }
+ }
+ if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName ||
+ firstFileName !== lastFileName || firstIndex >= lastIndex) {
+ return;
+ }
-CapturedTrace.isSupported = function CapturedTrace$IsSupported() {
- return typeof captureStackTrace === "function";
+ shouldIgnore = function(line) {
+ if (bluebirdFramePattern.test(line)) return true;
+ var info = parseLineInfo(line);
+ if (info) {
+ if (info.fileName === firstFileName &&
+ (firstIndex <= info.line && info.line <= lastIndex)) {
+ return true;
+ }
+ }
+ return false;
+ };
};
var captureStackTrace = (function stackDetection() {
- if (typeof Error.stackTraceLimit === "number" &&
- typeof Error.captureStackTrace === "function") {
- rtraceline = /^\s*at\s*/;
- formatStack = function(stack, error) {
- if (typeof stack === "string") return stack;
+ var v8stackFramePattern = /^\s*at\s*/;
+ var v8stackFormatter = function(stack, error) {
+ if (typeof stack === "string") return stack;
- if (error.name !== void 0 &&
- error.message !== void 0) {
- return error.name + ". " + error.message;
- }
- return formatNonError(error);
+ if (error.name !== undefined &&
+ error.message !== undefined) {
+ return error.toString();
+ }
+ return formatNonError(error);
+ };
+ if (typeof Error.stackTraceLimit === "number" &&
+ typeof Error.captureStackTrace === "function") {
+ Error.stackTraceLimit = Error.stackTraceLimit + 6;
+ stackFramePattern = v8stackFramePattern;
+ formatStack = v8stackFormatter;
+ var captureStackTrace = Error.captureStackTrace;
+ shouldIgnore = function(line) {
+ return bluebirdFramePattern.test(line);
};
- var captureStackTrace = Error.captureStackTrace;
- return function CapturedTrace$_captureStackTrace(
- receiver, ignoreUntil) {
+ return function(receiver, ignoreUntil) {
+ Error.stackTraceLimit = Error.stackTraceLimit + 6;
captureStackTrace(receiver, ignoreUntil);
+ Error.stackTraceLimit = Error.stackTraceLimit - 6;
};
}
var err = new Error();
- if (!areNamesMangled && typeof err.stack === "string" &&
- typeof "".startsWith === "function" &&
- (err.stack.startsWith("stackDetection@")) &&
- stackDetection.name === "stackDetection") {
+ if (typeof err.stack === "string" &&
+ err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) {
+ stackFramePattern = /@/;
+ formatStack = v8stackFormatter;
+ indentStackFrames = true;
+ return function captureStackTrace(o) {
+ o.stack = new Error().stack;
+ };
+ }
- defineProperty(Error, "stackTraceLimit", {
- writable: true,
- enumerable: false,
- configurable: false,
- value: 25
- });
- rtraceline = /@/;
- var rline = /[@\n]/;
+ var hasStackAfterThrow;
+ try { throw new Error(); }
+ catch(e) {
+ hasStackAfterThrow = ("stack" in e);
+ }
+ if (!("stack" in err) && hasStackAfterThrow) {
+ stackFramePattern = v8stackFramePattern;
+ formatStack = v8stackFormatter;
+ return function captureStackTrace(o) {
+ Error.stackTraceLimit = Error.stackTraceLimit + 6;
+ try { throw new Error(); }
+ catch(e) { o.stack = e.stack; }
+ Error.stackTraceLimit = Error.stackTraceLimit - 6;
+ };
+ }
- formatStack = function(stack, error) {
- if (typeof stack === "string") {
- return (error.name + ". " + error.message + "\n" + stack);
- }
+ formatStack = function(stack, error) {
+ if (typeof stack === "string") return stack;
+
+ if ((typeof error === "object" ||
+ typeof error === "function") &&
+ error.name !== undefined &&
+ error.message !== undefined) {
+ return error.toString();
+ }
+ return formatNonError(error);
+ };
+
+ return null;
- if (error.name !== void 0 &&
- error.message !== void 0) {
- return error.name + ". " + error.message;
+})([]);
+
+var fireDomEvent;
+var fireGlobalEvent = (function() {
+ if (util.isNode) {
+ return function(name, reason, promise) {
+ if (name === "rejectionHandled") {
+ return process.emit(name, promise);
+ } else {
+ return process.emit(name, reason, promise);
}
- return formatNonError(error);
};
-
- return function captureStackTrace(o, fn) {
- var name = fn.name;
- var stack = new Error().stack;
- var split = stack.split(rline);
- var i, len = split.length;
- for (i = 0; i < len; i += 2) {
- if (split[i] === name) {
- break;
- }
+ } else {
+ var customEventWorks = false;
+ var anyEventWorks = true;
+ try {
+ var ev = new self.CustomEvent("test");
+ customEventWorks = ev instanceof CustomEvent;
+ } catch (e) {}
+ if (!customEventWorks) {
+ try {
+ var event = document.createEvent("CustomEvent");
+ event.initCustomEvent("testingtheevent", false, true, {});
+ self.dispatchEvent(event);
+ } catch (e) {
+ anyEventWorks = false;
}
- split = split.slice(i + 2);
- len = split.length - 2;
- var ret = "";
- for (i = 0; i < len; i += 2) {
- ret += split[i];
- ret += "@";
- ret += split[i + 1];
- ret += "\n";
+ }
+ if (anyEventWorks) {
+ fireDomEvent = function(type, detail) {
+ var event;
+ if (customEventWorks) {
+ event = new self.CustomEvent(type, {
+ detail: detail,
+ bubbles: false,
+ cancelable: true
+ });
+ } else if (self.dispatchEvent) {
+ event = document.createEvent("CustomEvent");
+ event.initCustomEvent(type, false, true, detail);
+ }
+
+ return event ? !self.dispatchEvent(event) : false;
+ };
+ }
+
+ var toWindowMethodNameMap = {};
+ toWindowMethodNameMap["unhandledRejection"] = ("on" +
+ "unhandledRejection").toLowerCase();
+ toWindowMethodNameMap["rejectionHandled"] = ("on" +
+ "rejectionHandled").toLowerCase();
+
+ return function(name, reason, promise) {
+ var methodName = toWindowMethodNameMap[name];
+ var method = self[methodName];
+ if (!method) return false;
+ if (name === "rejectionHandled") {
+ method.call(self, promise);
+ } else {
+ method.call(self, reason, promise);
}
- o.stack = ret;
+ return true;
};
}
- else {
- formatStack = function(stack, error) {
- if (typeof stack === "string") return stack;
-
- if ((typeof error === "object" ||
- typeof error === "function") &&
- error.name !== void 0 &&
- error.message !== void 0) {
- return error.name + ". " + error.message;
- }
- return formatNonError(error);
- };
+})();
- return null;
+if (typeof console !== "undefined" && typeof console.warn !== "undefined") {
+ warn = function (message) {
+ console.warn(message);
+ };
+ if (util.isNode && process.stderr.isTTY) {
+ warn = function(message) {
+ process.stderr.write("\u001b[31m" + message + "\u001b[39m\n");
+ };
+ } else if (!util.isNode && typeof (new Error().stack) === "string") {
+ warn = function(message) {
+ console.warn("%c" + message, "color: red");
+ };
}
-})();
+}
return CapturedTrace;
};
-},{"./es5.js":11,"./util.js":38}],7:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./async.js":2,"./util.js":38}],8:[function(_dereq_,module,exports){
"use strict";
module.exports = function(NEXT_FILTER) {
-var util = require("./util.js");
-var errors = require("./errors.js");
-var tryCatch1 = util.tryCatch1;
+var util = _dereq_("./util.js");
+var errors = _dereq_("./errors.js");
+var tryCatch = util.tryCatch;
var errorObj = util.errorObj;
-var keys = require("./es5.js").keys;
+var keys = _dereq_("./es5.js").keys;
+var TypeError = errors.TypeError;
function CatchFilter(instances, callback, promise) {
this._instances = instances;
@@ -2699,49 +2997,43 @@ function CatchFilter(instances, callback, promise) {
this._promise = promise;
}
-function CatchFilter$_safePredicate(predicate, e) {
+function safePredicate(predicate, e) {
var safeObject = {};
- var retfilter = tryCatch1(predicate, safeObject, e);
+ var retfilter = tryCatch(predicate).call(safeObject, e);
if (retfilter === errorObj) return retfilter;
var safeKeys = keys(safeObject);
if (safeKeys.length) {
- errorObj.e = new TypeError(
- "Catch filter must inherit from Error "
- + "or be a simple predicate function");
+ errorObj.e = new TypeError("Catch filter must inherit from Error or be a simple predicate function\u000a\u000a See http://goo.gl/o84o68\u000a");
return errorObj;
}
return retfilter;
}
-CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) {
+CatchFilter.prototype.doFilter = function (e) {
var cb = this._callback;
var promise = this._promise;
- var boundTo = promise._isBound() ? promise._boundTo : void 0;
+ var boundTo = promise._boundTo;
for (var i = 0, len = this._instances.length; i < len; ++i) {
var item = this._instances[i];
var itemIsErrorType = item === Error ||
(item != null && item.prototype instanceof Error);
if (itemIsErrorType && e instanceof item) {
- var ret = tryCatch1(cb, boundTo, e);
+ var ret = tryCatch(cb).call(boundTo, e);
if (ret === errorObj) {
NEXT_FILTER.e = ret.e;
return NEXT_FILTER;
}
return ret;
} else if (typeof item === "function" && !itemIsErrorType) {
- var shouldHandle = CatchFilter$_safePredicate(item, e);
+ var shouldHandle = safePredicate(item, e);
if (shouldHandle === errorObj) {
- var trace = errors.canAttach(errorObj.e)
- ? errorObj.e
- : new Error(errorObj.e + "");
- this._promise._attachExtraTrace(trace);
e = errorObj.e;
break;
} else if (shouldHandle) {
- var ret = tryCatch1(cb, boundTo, e);
+ var ret = tryCatch(cb).call(boundTo, e);
if (ret === errorObj) {
NEXT_FILTER.e = ret.e;
return NEXT_FILTER;
@@ -2757,50 +3049,208 @@ CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) {
return CatchFilter;
};
-},{"./errors.js":9,"./es5.js":11,"./util.js":38}],8:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./errors.js":13,"./es5.js":14,"./util.js":38}],9:[function(_dereq_,module,exports){
+"use strict";
+module.exports = function(Promise, CapturedTrace, isDebugging) {
+var contextStack = [];
+function Context() {
+ this._trace = new CapturedTrace(peekContext());
+}
+Context.prototype._pushContext = function () {
+ if (!isDebugging()) return;
+ if (this._trace !== undefined) {
+ contextStack.push(this._trace);
+ }
+};
+
+Context.prototype._popContext = function () {
+ if (!isDebugging()) return;
+ if (this._trace !== undefined) {
+ contextStack.pop();
+ }
+};
+
+function createContext() {
+ if (isDebugging()) return new Context();
+}
+
+function peekContext() {
+ var lastIndex = contextStack.length - 1;
+ if (lastIndex >= 0) {
+ return contextStack[lastIndex];
+ }
+ return undefined;
+}
+
+Promise.prototype._peekContext = peekContext;
+Promise.prototype._pushContext = Context.prototype._pushContext;
+Promise.prototype._popContext = Context.prototype._popContext;
+
+return createContext;
+};
+
+},{}],10:[function(_dereq_,module,exports){
+"use strict";
+module.exports = function(Promise, CapturedTrace) {
+var async = _dereq_("./async.js");
+var Warning = _dereq_("./errors.js").Warning;
+var util = _dereq_("./util.js");
+var canAttachTrace = util.canAttachTrace;
+var unhandledRejectionHandled;
+var possiblyUnhandledRejection;
+var debugging = false || (util.isNode &&
+ (!!process.env["BLUEBIRD_DEBUG"] ||
+ process.env["NODE_ENV"] === "development"));
+
+Promise.prototype._ensurePossibleRejectionHandled = function () {
+ this._setRejectionIsUnhandled();
+ async.invokeLater(this._notifyUnhandledRejection, this, undefined);
+};
+
+Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
+ CapturedTrace.fireRejectionEvent("rejectionHandled",
+ unhandledRejectionHandled, undefined, this);
+};
+
+Promise.prototype._notifyUnhandledRejection = function () {
+ if (this._isRejectionUnhandled()) {
+ var reason = this._getCarriedStackTrace() || this._settledValue;
+ this._setUnhandledRejectionIsNotified();
+ CapturedTrace.fireRejectionEvent("unhandledRejection",
+ possiblyUnhandledRejection, reason, this);
+ }
+};
+
+Promise.prototype._setUnhandledRejectionIsNotified = function () {
+ this._bitField = this._bitField | 524288;
+};
+
+Promise.prototype._unsetUnhandledRejectionIsNotified = function () {
+ this._bitField = this._bitField & (~524288);
+};
+
+Promise.prototype._isUnhandledRejectionNotified = function () {
+ return (this._bitField & 524288) > 0;
+};
+
+Promise.prototype._setRejectionIsUnhandled = function () {
+ this._bitField = this._bitField | 2097152;
+};
+
+Promise.prototype._unsetRejectionIsUnhandled = function () {
+ this._bitField = this._bitField & (~2097152);
+ if (this._isUnhandledRejectionNotified()) {
+ this._unsetUnhandledRejectionIsNotified();
+ this._notifyUnhandledRejectionIsHandled();
+ }
+};
+
+Promise.prototype._isRejectionUnhandled = function () {
+ return (this._bitField & 2097152) > 0;
+};
+
+Promise.prototype._setCarriedStackTrace = function (capturedTrace) {
+ this._bitField = this._bitField | 1048576;
+ this._fulfillmentHandler0 = capturedTrace;
+};
+
+Promise.prototype._isCarryingStackTrace = function () {
+ return (this._bitField & 1048576) > 0;
+};
+
+Promise.prototype._getCarriedStackTrace = function () {
+ return this._isCarryingStackTrace()
+ ? this._fulfillmentHandler0
+ : undefined;
+};
+
+Promise.prototype._captureStackTrace = function () {
+ if (debugging) {
+ this._trace = new CapturedTrace(this._peekContext());
+ }
+ return this;
+};
+
+Promise.prototype._attachExtraTrace = function (error, ignoreSelf) {
+ if (debugging && canAttachTrace(error)) {
+ var trace = this._trace;
+ if (trace !== undefined) {
+ if (ignoreSelf) trace = trace._parent;
+ }
+ if (trace !== undefined) {
+ trace.attachExtraTrace(error);
+ } else if (!error.__stackCleaned__) {
+ var parsed = CapturedTrace.parseStackAndMessage(error);
+ error.stack = parsed.message + "\n" + parsed.stack.join("\n");
+ util.notEnumerableProp(error, "__stackCleaned__", true);
+ }
+ }
+};
+
+Promise.prototype._warn = function(message) {
+ var warning = new Warning(message);
+ var ctx = this._peekContext();
+ if (ctx) {
+ ctx.attachExtraTrace(warning);
+ } else {
+ var parsed = CapturedTrace.parseStackAndMessage(warning);
+ warning.stack = parsed.message + "\n" + parsed.stack.join("\n");
+ }
+ CapturedTrace.formatAndLogError(warning, "");
+};
+
+Promise.onPossiblyUnhandledRejection = function (fn) {
+ possiblyUnhandledRejection = typeof fn === "function" ? fn : undefined;
+};
+
+Promise.onUnhandledRejectionHandled = function (fn) {
+ unhandledRejectionHandled = typeof fn === "function" ? fn : undefined;
+};
+
+Promise.longStackTraces = function () {
+ if (async.haveItemsQueued() &&
+ debugging === false
+ ) {
+ throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/DT1qyG\u000a");
+ }
+ debugging = CapturedTrace.isSupported();
+};
+
+Promise.hasLongStackTraces = function () {
+ return debugging && CapturedTrace.isSupported();
+};
+
+if (!CapturedTrace.isSupported()) {
+ Promise.longStackTraces = function(){};
+ debugging = false;
+}
+
+return function() {
+ return debugging;
+};
+};
+
+},{"./async.js":2,"./errors.js":13,"./util.js":38}],11:[function(_dereq_,module,exports){
"use strict";
-var util = require("./util.js");
+var util = _dereq_("./util.js");
var isPrimitive = util.isPrimitive;
var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
module.exports = function(Promise) {
-var returner = function Promise$_returner() {
+var returner = function () {
return this;
};
-var thrower = function Promise$_thrower() {
+var thrower = function () {
throw this;
};
-var wrapper = function Promise$_wrapper(value, action) {
+var wrapper = function (value, action) {
if (action === 1) {
- return function Promise$_thrower() {
+ return function () {
throw value;
};
- }
- else if (action === 2) {
- return function Promise$_returner() {
+ } else if (action === 2) {
+ return function () {
return value;
};
}
@@ -2808,241 +3258,188 @@ var wrapper = function Promise$_wrapper(value, action) {
Promise.prototype["return"] =
-Promise.prototype.thenReturn =
-function Promise$thenReturn(value) {
+Promise.prototype.thenReturn = function (value) {
if (wrapsPrimitiveReceiver && isPrimitive(value)) {
return this._then(
wrapper(value, 2),
- void 0,
- void 0,
- void 0,
- void 0,
- this.thenReturn
+ undefined,
+ undefined,
+ undefined,
+ undefined
);
}
- return this._then(returner, void 0, void 0,
- value, void 0, this.thenReturn);
+ return this._then(returner, undefined, undefined, value, undefined);
};
Promise.prototype["throw"] =
-Promise.prototype.thenThrow =
-function Promise$thenThrow(reason) {
+Promise.prototype.thenThrow = function (reason) {
if (wrapsPrimitiveReceiver && isPrimitive(reason)) {
return this._then(
wrapper(reason, 1),
- void 0,
- void 0,
- void 0,
- void 0,
- this.thenThrow
+ undefined,
+ undefined,
+ undefined,
+ undefined
);
}
- return this._then(thrower, void 0, void 0,
- reason, void 0, this.thenThrow);
+ return this._then(thrower, undefined, undefined, reason, undefined);
};
};
-},{"./util.js":38}],9:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./util.js":38}],12:[function(_dereq_,module,exports){
"use strict";
-var global = require("./global.js");
-var Objectfreeze = require("./es5.js").freeze;
-var util = require("./util.js");
-var inherits = util.inherits;
-var notEnumerableProp = util.notEnumerableProp;
-var Error = global.Error;
-
-function markAsOriginatingFromRejection(e) {
- try {
- notEnumerableProp(e, "isAsync", true);
- }
- catch(ignore) {}
-}
+module.exports = function(Promise, INTERNAL) {
+var PromiseReduce = Promise.reduce;
-function originatesFromRejection(e) {
- if (e == null) return false;
- return ((e instanceof RejectionError) ||
- e["isAsync"] === true);
-}
+Promise.prototype.each = function (fn) {
+ return PromiseReduce(this, fn, null, INTERNAL);
+};
-function isError(obj) {
- return obj instanceof Error;
-}
+Promise.each = function (promises, fn) {
+ return PromiseReduce(promises, fn, null, INTERNAL);
+};
+};
-function canAttach(obj) {
- return isError(obj);
-}
+},{}],13:[function(_dereq_,module,exports){
+"use strict";
+var es5 = _dereq_("./es5.js");
+var Objectfreeze = es5.freeze;
+var util = _dereq_("./util.js");
+var inherits = util.inherits;
+var notEnumerableProp = util.notEnumerableProp;
function subError(nameProperty, defaultMessage) {
function SubError(message) {
if (!(this instanceof SubError)) return new SubError(message);
- this.message = typeof message === "string" ? message : defaultMessage;
- this.name = nameProperty;
+ notEnumerableProp(this, "message",
+ typeof message === "string" ? message : defaultMessage);
+ notEnumerableProp(this, "name", nameProperty);
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
+ } else {
+ Error.call(this);
}
}
inherits(SubError, Error);
return SubError;
}
-var TypeError = global.TypeError;
-if (typeof TypeError !== "function") {
- TypeError = subError("TypeError", "type error");
-}
-var RangeError = global.RangeError;
-if (typeof RangeError !== "function") {
- RangeError = subError("RangeError", "range error");
-}
+var _TypeError, _RangeError;
+var Warning = subError("Warning", "warning");
var CancellationError = subError("CancellationError", "cancellation error");
var TimeoutError = subError("TimeoutError", "timeout error");
+var AggregateError = subError("AggregateError", "aggregate error");
+try {
+ _TypeError = TypeError;
+ _RangeError = RangeError;
+} catch(e) {
+ _TypeError = subError("TypeError", "type error");
+ _RangeError = subError("RangeError", "range error");
+}
-function RejectionError(message) {
- this.name = "RejectionError";
- this.message = message;
+var methods = ("join pop push shift unshift slice filter forEach some " +
+ "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" ");
+
+for (var i = 0; i < methods.length; ++i) {
+ if (typeof Array.prototype[methods[i]] === "function") {
+ AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];
+ }
+}
+
+es5.defineProperty(AggregateError.prototype, "length", {
+ value: 0,
+ configurable: false,
+ writable: true,
+ enumerable: true
+});
+AggregateError.prototype["isOperational"] = true;
+var level = 0;
+AggregateError.prototype.toString = function() {
+ var indent = Array(level * 4 + 1).join(" ");
+ var ret = "\n" + indent + "AggregateError of:" + "\n";
+ level++;
+ indent = Array(level * 4 + 1).join(" ");
+ for (var i = 0; i < this.length; ++i) {
+ var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";
+ var lines = str.split("\n");
+ for (var j = 0; j < lines.length; ++j) {
+ lines[j] = indent + lines[j];
+ }
+ str = lines.join("\n");
+ ret += str + "\n";
+ }
+ level--;
+ return ret;
+};
+
+function OperationalError(message) {
+ if (!(this instanceof OperationalError))
+ return new OperationalError(message);
+ notEnumerableProp(this, "name", "OperationalError");
+ notEnumerableProp(this, "message", message);
this.cause = message;
- this.isAsync = true;
+ this["isOperational"] = true;
if (message instanceof Error) {
- this.message = message.message;
- this.stack = message.stack;
- }
- else if (Error.captureStackTrace) {
+ notEnumerableProp(this, "message", message.message);
+ notEnumerableProp(this, "stack", message.stack);
+ } else if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
-inherits(RejectionError, Error);
+inherits(OperationalError, Error);
-var key = "__BluebirdErrorTypes__";
-var errorTypes = global[key];
+var errorTypes = Error["__BluebirdErrorTypes__"];
if (!errorTypes) {
errorTypes = Objectfreeze({
CancellationError: CancellationError,
TimeoutError: TimeoutError,
- RejectionError: RejectionError
+ OperationalError: OperationalError,
+ RejectionError: OperationalError,
+ AggregateError: AggregateError
});
- notEnumerableProp(global, key, errorTypes);
+ notEnumerableProp(Error, "__BluebirdErrorTypes__", errorTypes);
}
module.exports = {
Error: Error,
- TypeError: TypeError,
- RangeError: RangeError,
+ TypeError: _TypeError,
+ RangeError: _RangeError,
CancellationError: errorTypes.CancellationError,
- RejectionError: errorTypes.RejectionError,
+ OperationalError: errorTypes.OperationalError,
TimeoutError: errorTypes.TimeoutError,
- originatesFromRejection: originatesFromRejection,
- markAsOriginatingFromRejection: markAsOriginatingFromRejection,
- canAttach: canAttach
-};
-
-},{"./es5.js":11,"./global.js":15,"./util.js":38}],10:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise) {
-var TypeError = require('./errors.js').TypeError;
-
-function apiRejection(msg) {
- var error = new TypeError(msg);
- var ret = Promise.rejected(error);
- var parent = ret._peekContext();
- if (parent != null) {
- parent._attachExtraTrace(error);
- }
- return ret;
-}
-
-return apiRejection;
+ AggregateError: errorTypes.AggregateError,
+ Warning: Warning
};
-},{"./errors.js":9}],11:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./es5.js":14,"./util.js":38}],14:[function(_dereq_,module,exports){
var isES5 = (function(){
"use strict";
- return this === void 0;
+ return this === undefined;
})();
if (isES5) {
module.exports = {
freeze: Object.freeze,
defineProperty: Object.defineProperty,
+ getDescriptor: Object.getOwnPropertyDescriptor,
keys: Object.keys,
+ names: Object.getOwnPropertyNames,
getPrototypeOf: Object.getPrototypeOf,
isArray: Array.isArray,
- isES5: isES5
+ isES5: isES5,
+ propertyIsWritable: function(obj, prop) {
+ var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
+ return !!(!descriptor || descriptor.writable || descriptor.set);
+ }
};
-}
-
-else {
+} else {
var has = {}.hasOwnProperty;
var str = {}.toString;
var proto = {}.constructor.prototype;
- function ObjectKeys(o) {
+ var ObjectKeys = function (o) {
var ret = [];
for (var key in o) {
if (has.call(o, key)) {
@@ -3050,754 +3447,791 @@ else {
}
}
return ret;
- }
+ };
- function ObjectDefineProperty(o, key, desc) {
+ var ObjectGetDescriptor = function(o, key) {
+ return {value: o[key]};
+ };
+
+ var ObjectDefineProperty = function (o, key, desc) {
o[key] = desc.value;
return o;
- }
+ };
- function ObjectFreeze(obj) {
+ var ObjectFreeze = function (obj) {
return obj;
- }
+ };
- function ObjectGetPrototypeOf(obj) {
+ var ObjectGetPrototypeOf = function (obj) {
try {
return Object(obj).constructor.prototype;
}
catch (e) {
return proto;
}
- }
+ };
- function ArrayIsArray(obj) {
+ var ArrayIsArray = function (obj) {
try {
return str.call(obj) === "[object Array]";
}
catch(e) {
return false;
}
- }
+ };
module.exports = {
isArray: ArrayIsArray,
keys: ObjectKeys,
+ names: ObjectKeys,
defineProperty: ObjectDefineProperty,
+ getDescriptor: ObjectGetDescriptor,
freeze: ObjectFreeze,
getPrototypeOf: ObjectGetPrototypeOf,
- isES5: isES5
+ isES5: isES5,
+ propertyIsWritable: function() {
+ return true;
+ }
};
}
-},{}],12:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{}],15:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(Promise) {
- var isArray = require("./util.js").isArray;
+module.exports = function(Promise, INTERNAL) {
+var PromiseMap = Promise.map;
- function Promise$_filter(booleans) {
- var values = this._settledValue;
- var len = values.length;
- var ret = new Array(len);
- var j = 0;
+Promise.prototype.filter = function (fn, options) {
+ return PromiseMap(this, fn, options, INTERNAL);
+};
- for (var i = 0; i < len; ++i) {
- if (booleans[i]) ret[j++] = values[i];
+Promise.filter = function (promises, fn, options) {
+ return PromiseMap(promises, fn, options, INTERNAL);
+};
+};
- }
- ret.length = j;
- return ret;
- }
+},{}],16:[function(_dereq_,module,exports){
+"use strict";
+module.exports = function(Promise, NEXT_FILTER, tryConvertToPromise) {
+var util = _dereq_("./util.js");
+var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
+var isPrimitive = util.isPrimitive;
+var thrower = util.thrower;
- var ref = {ref: null};
- Promise.filter = function Promise$Filter(promises, fn) {
- return Promise.map(promises, fn, ref)
- ._then(Promise$_filter, void 0, void 0,
- ref.ref, void 0, Promise.filter);
+function returnThis() {
+ return this;
+}
+function throwThis() {
+ throw this;
+}
+function return$(r) {
+ return function() {
+ return r;
};
-
- Promise.prototype.filter = function Promise$filter(fn) {
- return this.map(fn, ref)
- ._then(Promise$_filter, void 0, void 0,
- ref.ref, void 0, this.filter);
+}
+function throw$(r) {
+ return function() {
+ throw r;
};
-};
+}
+function promisedFinally(ret, reasonOrValue, isFulfilled) {
+ var then;
+ if (wrapsPrimitiveReceiver && isPrimitive(reasonOrValue)) {
+ then = isFulfilled ? return$(reasonOrValue) : throw$(reasonOrValue);
+ } else {
+ then = isFulfilled ? returnThis : throwThis;
+ }
+ return ret._then(then, thrower, undefined, reasonOrValue, undefined);
+}
-},{"./util.js":38}],13:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, NEXT_FILTER) {
- var util = require("./util.js");
- var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
- var isPrimitive = util.isPrimitive;
- var thrower = util.thrower;
+function finallyHandler(reasonOrValue) {
+ var promise = this.promise;
+ var handler = this.handler;
+ var ret = promise._isBound()
+ ? handler.call(promise._boundTo)
+ : handler();
- function returnThis() {
- return this;
- }
- function throwThis() {
- throw this;
- }
- function makeReturner(r) {
- return function Promise$_returner() {
- return r;
- };
+ if (ret !== undefined) {
+ var maybePromise = tryConvertToPromise(ret, promise);
+ if (maybePromise instanceof Promise) {
+ maybePromise = maybePromise._target();
+ return promisedFinally(maybePromise, reasonOrValue,
+ promise.isFulfilled());
+ }
}
- function makeThrower(r) {
- return function Promise$_thrower() {
- throw r;
- };
+
+ if (promise.isRejected()) {
+ NEXT_FILTER.e = reasonOrValue;
+ return NEXT_FILTER;
+ } else {
+ return reasonOrValue;
}
- function promisedFinally(ret, reasonOrValue, isFulfilled) {
- var useConstantFunction =
- wrapsPrimitiveReceiver && isPrimitive(reasonOrValue);
+}
- if (isFulfilled) {
- return ret._then(
- useConstantFunction
- ? returnThis
- : makeReturner(reasonOrValue),
- thrower, void 0, reasonOrValue, void 0, promisedFinally);
- }
- else {
- return ret._then(
- useConstantFunction
- ? throwThis
- : makeThrower(reasonOrValue),
- thrower, void 0, reasonOrValue, void 0, promisedFinally);
+function tapHandler(value) {
+ var promise = this.promise;
+ var handler = this.handler;
+
+ var ret = promise._isBound()
+ ? handler.call(promise._boundTo, value)
+ : handler(value);
+
+ if (ret !== undefined) {
+ var maybePromise = tryConvertToPromise(ret, promise);
+ if (maybePromise instanceof Promise) {
+ maybePromise = maybePromise._target();
+ return promisedFinally(maybePromise, value, true);
}
}
+ return value;
+}
- function finallyHandler(reasonOrValue) {
- var promise = this.promise;
- var handler = this.handler;
+Promise.prototype._passThroughHandler = function (handler, isFinally) {
+ if (typeof handler !== "function") return this.then();
- var ret = promise._isBound()
- ? handler.call(promise._boundTo)
- : handler();
+ var promiseAndHandler = {
+ promise: this,
+ handler: handler
+ };
- if (ret !== void 0) {
- var maybePromise = Promise._cast(ret, finallyHandler, void 0);
- if (maybePromise instanceof Promise) {
- return promisedFinally(maybePromise, reasonOrValue,
- promise.isFulfilled());
- }
- }
+ return this._then(
+ isFinally ? finallyHandler : tapHandler,
+ isFinally ? finallyHandler : undefined, undefined,
+ promiseAndHandler, undefined);
+};
- if (promise.isRejected()) {
- NEXT_FILTER.e = reasonOrValue;
- return NEXT_FILTER;
- }
- else {
- return reasonOrValue;
- }
- }
+Promise.prototype.lastly =
+Promise.prototype["finally"] = function (handler) {
+ return this._passThroughHandler(handler, true);
+};
- function tapHandler(value) {
- var promise = this.promise;
- var handler = this.handler;
+Promise.prototype.tap = function (handler) {
+ return this._passThroughHandler(handler, false);
+};
+};
- var ret = promise._isBound()
- ? handler.call(promise._boundTo, value)
- : handler(value);
+},{"./util.js":38}],17:[function(_dereq_,module,exports){
+"use strict";
+module.exports = function(Promise,
+ apiRejection,
+ INTERNAL,
+ tryConvertToPromise) {
+var errors = _dereq_("./errors.js");
+var TypeError = errors.TypeError;
+var util = _dereq_("./util.js");
+var errorObj = util.errorObj;
+var tryCatch = util.tryCatch;
+var yieldHandlers = [];
- if (ret !== void 0) {
- var maybePromise = Promise._cast(ret, tapHandler, void 0);
- if (maybePromise instanceof Promise) {
- return promisedFinally(maybePromise, value, true);
- }
+function promiseFromYieldHandler(value, yieldHandlers, traceParent) {
+ for (var i = 0; i < yieldHandlers.length; ++i) {
+ traceParent._pushContext();
+ var result = tryCatch(yieldHandlers[i])(value);
+ traceParent._popContext();
+ if (result === errorObj) {
+ traceParent._pushContext();
+ var ret = Promise.reject(errorObj.e);
+ traceParent._popContext();
+ return ret;
}
- return value;
+ var maybePromise = tryConvertToPromise(result, traceParent);
+ if (maybePromise instanceof Promise) return maybePromise;
}
+ return null;
+}
- Promise.prototype._passThroughHandler =
- function Promise$_passThroughHandler(handler, isFinally, caller) {
- if (typeof handler !== "function") return this.then();
+function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) {
+ var promise = this._promise = new Promise(INTERNAL);
+ promise._captureStackTrace();
+ this._stack = stack;
+ this._generatorFunction = generatorFunction;
+ this._receiver = receiver;
+ this._generator = undefined;
+ this._yieldHandlers = typeof yieldHandler === "function"
+ ? [yieldHandler].concat(yieldHandlers)
+ : yieldHandlers;
+}
- var promiseAndHandler = {
- promise: this,
- handler: handler
- };
+PromiseSpawn.prototype.promise = function () {
+ return this._promise;
+};
- return this._then(
- isFinally ? finallyHandler : tapHandler,
- isFinally ? finallyHandler : void 0, void 0,
- promiseAndHandler, void 0, caller);
- };
+PromiseSpawn.prototype._run = function () {
+ this._generator = this._generatorFunction.call(this._receiver);
+ this._receiver =
+ this._generatorFunction = undefined;
+ this._next(undefined);
+};
- Promise.prototype.lastly =
- Promise.prototype["finally"] = function Promise$finally(handler) {
- return this._passThroughHandler(handler, true, this.lastly);
- };
+PromiseSpawn.prototype._continue = function (result) {
+ if (result === errorObj) {
+ return this._promise._rejectCallback(result.e, false, true);
+ }
- Promise.prototype.tap = function Promise$tap(handler) {
- return this._passThroughHandler(handler, false, this.tap);
- };
+ var value = result.value;
+ if (result.done === true) {
+ this._promise._resolveCallback(value);
+ } else {
+ var maybePromise = tryConvertToPromise(value, this._promise);
+ if (!(maybePromise instanceof Promise)) {
+ maybePromise =
+ promiseFromYieldHandler(maybePromise,
+ this._yieldHandlers,
+ this._promise);
+ if (maybePromise === null) {
+ this._throw(
+ new TypeError(
+ "A value %s was yielded that could not be treated as a promise\u000a\u000a See http://goo.gl/4Y4pDk\u000a\u000a".replace("%s", value) +
+ "From coroutine:\u000a" +
+ this._stack.split("\n").slice(1, -7).join("\n")
+ )
+ );
+ return;
+ }
+ }
+ maybePromise._then(
+ this._next,
+ this._throw,
+ undefined,
+ this,
+ null
+ );
+ }
};
-},{"./util.js":38}],14:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, apiRejection, INTERNAL) {
- var PromiseSpawn = require("./promise_spawn.js")(Promise, INTERNAL);
- var errors = require("./errors.js");
- var TypeError = errors.TypeError;
- var deprecated = require("./util.js").deprecated;
-
- Promise.coroutine = function Promise$Coroutine(generatorFunction) {
- if (typeof generatorFunction !== "function") {
- throw new TypeError("generatorFunction must be a function");
- }
- var PromiseSpawn$ = PromiseSpawn;
- return function anonymous() {
- var generator = generatorFunction.apply(this, arguments);
- var spawn = new PromiseSpawn$(void 0, void 0, anonymous);
- spawn._generator = generator;
- spawn._next(void 0);
- return spawn.promise();
- };
- };
+PromiseSpawn.prototype._throw = function (reason) {
+ this._promise._attachExtraTrace(reason);
+ this._promise._pushContext();
+ var result = tryCatch(this._generator["throw"])
+ .call(this._generator, reason);
+ this._promise._popContext();
+ this._continue(result);
+};
- Promise.coroutine.addYieldHandler = PromiseSpawn.addYieldHandler;
+PromiseSpawn.prototype._next = function (value) {
+ this._promise._pushContext();
+ var result = tryCatch(this._generator.next).call(this._generator, value);
+ this._promise._popContext();
+ this._continue(result);
+};
- Promise.spawn = function Promise$Spawn(generatorFunction) {
- deprecated("Promise.spawn is deprecated. Use Promise.coroutine instead.");
- if (typeof generatorFunction !== "function") {
- return apiRejection("generatorFunction must be a function");
- }
- var spawn = new PromiseSpawn(generatorFunction, this, Promise.spawn);
- var ret = spawn.promise();
- spawn._run(Promise.spawn);
- return ret;
+Promise.coroutine = function (generatorFunction, options) {
+ if (typeof generatorFunction !== "function") {
+ throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/6Vqhm0\u000a");
+ }
+ var yieldHandler = Object(options).yieldHandler;
+ var PromiseSpawn$ = PromiseSpawn;
+ var stack = new Error().stack;
+ return function () {
+ var generator = generatorFunction.apply(this, arguments);
+ var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler,
+ stack);
+ spawn._generator = generator;
+ spawn._next(undefined);
+ return spawn.promise();
};
};
-},{"./errors.js":9,"./promise_spawn.js":23,"./util.js":38}],15:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = (function(){
- if (typeof this !== "undefined") {
- return this;
- }
- if (typeof process !== "undefined" &&
- typeof global !== "undefined" &&
- typeof process.execPath === "string") {
- return global;
- }
- if (typeof window !== "undefined" &&
- typeof document !== "undefined" &&
- typeof navigator !== "undefined" && navigator !== null &&
- typeof navigator.appName === "string") {
- if(window.wrappedJSObject !== undefined){
- return window.wrappedJSObject;
- }
- return window;
+Promise.coroutine.addYieldHandler = function(fn) {
+ if (typeof fn !== "function") throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
+ yieldHandlers.push(fn);
+};
+
+Promise.spawn = function (generatorFunction) {
+ if (typeof generatorFunction !== "function") {
+ return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/6Vqhm0\u000a");
}
-})();
+ var spawn = new PromiseSpawn(generatorFunction, this);
+ var ret = spawn.promise();
+ spawn._run(Promise.spawn);
+ return ret;
+};
+};
-},{}],16:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./errors.js":13,"./util.js":38}],18:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(
- Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection) {
-
- function Promise$_mapper(values) {
- var fn = this;
- var receiver = void 0;
-
- if (typeof fn !== "function") {
- receiver = fn.receiver;
- fn = fn.fn;
+module.exports =
+function(Promise, PromiseArray, tryConvertToPromise, INTERNAL) {
+var util = _dereq_("./util.js");
+var canEvaluate = util.canEvaluate;
+var tryCatch = util.tryCatch;
+var errorObj = util.errorObj;
+var reject;
+
+if (!true) {
+if (canEvaluate) {
+ var thenCallback = function(i) {
+ return new Function("value", "holder", " \n\
+ 'use strict'; \n\
+ holder.pIndex = value; \n\
+ holder.checkFulfillment(this); \n\
+ ".replace(/Index/g, i));
+ };
+
+ var caller = function(count) {
+ var values = [];
+ for (var i = 1; i <= count; ++i) values.push("holder.p" + i);
+ return new Function("holder", " \n\
+ 'use strict'; \n\
+ var callback = holder.fn; \n\
+ return callback(values); \n\
+ ".replace(/values/g, values.join(", ")));
+ };
+ var thenCallbacks = [];
+ var callers = [undefined];
+ for (var i = 1; i <= 5; ++i) {
+ thenCallbacks.push(thenCallback(i));
+ callers.push(caller(i));
+ }
+
+ var Holder = function(total, fn) {
+ this.p1 = this.p2 = this.p3 = this.p4 = this.p5 = null;
+ this.fn = fn;
+ this.total = total;
+ this.now = 0;
+ };
+
+ Holder.prototype.callers = callers;
+ Holder.prototype.checkFulfillment = function(promise) {
+ var now = this.now;
+ now++;
+ var total = this.total;
+ if (now >= total) {
+ var handler = this.callers[total];
+ promise._pushContext();
+ var ret = tryCatch(handler)(this);
+ promise._popContext();
+ if (ret === errorObj) {
+ promise._rejectCallback(ret.e, false, true);
+ } else {
+ promise._resolveCallback(ret);
+ }
+ } else {
+ this.now = now;
}
- var shouldDefer = false;
+ };
- var ret = new Array(values.length);
+ var reject = function (reason) {
+ this._reject(reason);
+ };
+}
+}
- if (receiver === void 0) {
- for (var i = 0, len = values.length; i < len; ++i) {
- var value = fn(values[i], i, len);
- if (!shouldDefer) {
- var maybePromise = Promise._cast(value,
- Promise$_mapper, void 0);
- if (maybePromise instanceof Promise) {
- if (maybePromise.isFulfilled()) {
- ret[i] = maybePromise._settledValue;
- continue;
- }
- else {
- shouldDefer = true;
- }
- value = maybePromise;
- }
- }
- ret[i] = value;
- }
- }
- else {
- for (var i = 0, len = values.length; i < len; ++i) {
- var value = fn.call(receiver, values[i], i, len);
- if (!shouldDefer) {
- var maybePromise = Promise._cast(value,
- Promise$_mapper, void 0);
+Promise.join = function () {
+ var last = arguments.length - 1;
+ var fn;
+ if (last > 0 && typeof arguments[last] === "function") {
+ fn = arguments[last];
+ if (!true) {
+ if (last < 6 && canEvaluate) {
+ var ret = new Promise(INTERNAL);
+ ret._captureStackTrace();
+ var holder = new Holder(last, fn);
+ var callbacks = thenCallbacks;
+ for (var i = 0; i < last; ++i) {
+ var maybePromise = tryConvertToPromise(arguments[i], ret);
if (maybePromise instanceof Promise) {
- if (maybePromise.isFulfilled()) {
- ret[i] = maybePromise._settledValue;
- continue;
- }
- else {
- shouldDefer = true;
+ maybePromise = maybePromise._target();
+ if (maybePromise._isPending()) {
+ maybePromise._then(callbacks[i], reject,
+ undefined, ret, holder);
+ } else if (maybePromise._isFulfilled()) {
+ callbacks[i].call(ret,
+ maybePromise._value(), holder);
+ } else {
+ ret._reject(maybePromise._reason());
}
- value = maybePromise;
+ } else {
+ callbacks[i].call(ret, maybePromise, holder);
}
}
- ret[i] = value;
+ return ret;
}
}
- return shouldDefer
- ? Promise$_CreatePromiseArray(ret, PromiseArray,
- Promise$_mapper, void 0).promise()
- : ret;
}
+ var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
+ if (fn) args.pop();
+ var ret = new PromiseArray(args).promise();
+ return fn !== undefined ? ret.spread(fn) : ret;
+};
- function Promise$_Map(promises, fn, useBound, caller, ref) {
- if (typeof fn !== "function") {
- return apiRejection("fn must be a function");
- }
+};
- if (useBound === true && promises._isBound()) {
- fn = {
- fn: fn,
- receiver: promises._boundTo
- };
- }
+},{"./util.js":38}],19:[function(_dereq_,module,exports){
+"use strict";
+module.exports = function(Promise,
+ PromiseArray,
+ apiRejection,
+ tryConvertToPromise,
+ INTERNAL) {
+var util = _dereq_("./util.js");
+var tryCatch = util.tryCatch;
+var errorObj = util.errorObj;
+var PENDING = {};
+var EMPTY_ARRAY = [];
+
+function MappingPromiseArray(promises, fn, limit, _filter) {
+ this.constructor$(promises);
+ this._promise._captureStackTrace();
+ this._callback = fn;
+ this._preservedValues = _filter === INTERNAL
+ ? new Array(this.length())
+ : null;
+ this._limit = limit;
+ this._inFlight = 0;
+ this._queue = limit >= 1 ? [] : EMPTY_ARRAY;
+ this._init$(undefined, -2);
+}
+util.inherits(MappingPromiseArray, PromiseArray);
- var ret = Promise$_CreatePromiseArray(
- promises,
- PromiseArray,
- caller,
- useBound === true && promises._isBound()
- ? promises._boundTo
- : void 0
- ).promise();
+MappingPromiseArray.prototype._init = function () {};
- if (ref !== void 0) {
- ref.ref = ret;
+MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
+ var values = this._values;
+ var length = this.length();
+ var preservedValues = this._preservedValues;
+ var limit = this._limit;
+ if (values[index] === PENDING) {
+ values[index] = value;
+ if (limit >= 1) {
+ this._inFlight--;
+ this._drainQueue();
+ if (this._isResolved()) return;
}
+ } else {
+ if (limit >= 1 && this._inFlight >= limit) {
+ values[index] = value;
+ this._queue.push(index);
+ return;
+ }
+ if (preservedValues !== null) preservedValues[index] = value;
- return ret._then(
- Promise$_mapper,
- void 0,
- void 0,
- fn,
- void 0,
- caller
- );
- }
+ var callback = this._callback;
+ var receiver = this._promise._boundTo;
+ this._promise._pushContext();
+ var ret = tryCatch(callback).call(receiver, value, index, length);
+ this._promise._popContext();
+ if (ret === errorObj) return this._reject(ret.e);
- Promise.prototype.map = function Promise$map(fn, ref) {
- return Promise$_Map(this, fn, true, this.map, ref);
- };
+ var maybePromise = tryConvertToPromise(ret, this._promise);
+ if (maybePromise instanceof Promise) {
+ maybePromise = maybePromise._target();
+ if (maybePromise._isPending()) {
+ if (limit >= 1) this._inFlight++;
+ values[index] = PENDING;
+ return maybePromise._proxyPromiseArray(this, index);
+ } else if (maybePromise._isFulfilled()) {
+ ret = maybePromise._value();
+ } else {
+ return this._reject(maybePromise._reason());
+ }
+ }
+ values[index] = ret;
+ }
+ var totalResolved = ++this._totalResolved;
+ if (totalResolved >= length) {
+ if (preservedValues !== null) {
+ this._filter(values, preservedValues);
+ } else {
+ this._resolve(values);
+ }
- Promise.map = function Promise$Map(promises, fn, ref) {
- return Promise$_Map(promises, fn, false, Promise.map, ref);
- };
+ }
};
-},{}],17:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise) {
- var util = require("./util.js");
- var async = require("./async.js");
- var tryCatch2 = util.tryCatch2;
- var tryCatch1 = util.tryCatch1;
- var errorObj = util.errorObj;
-
- function thrower(r) {
- throw r;
+MappingPromiseArray.prototype._drainQueue = function () {
+ var queue = this._queue;
+ var limit = this._limit;
+ var values = this._values;
+ while (queue.length > 0 && this._inFlight < limit) {
+ if (this._isResolved()) return;
+ var index = queue.pop();
+ this._promiseFulfilled(values[index], index);
}
+};
- function Promise$_successAdapter(val, receiver) {
- var nodeback = this;
- var ret = tryCatch2(nodeback, receiver, null, val);
- if (ret === errorObj) {
- async.invokeLater(thrower, void 0, ret.e);
- }
- }
- function Promise$_errorAdapter(reason, receiver) {
- var nodeback = this;
- var ret = tryCatch1(nodeback, receiver, reason);
- if (ret === errorObj) {
- async.invokeLater(thrower, void 0, ret.e);
- }
+MappingPromiseArray.prototype._filter = function (booleans, values) {
+ var len = values.length;
+ var ret = new Array(len);
+ var j = 0;
+ for (var i = 0; i < len; ++i) {
+ if (booleans[i]) ret[j++] = values[i];
}
+ ret.length = j;
+ this._resolve(ret);
+};
- Promise.prototype.nodeify = function Promise$nodeify(nodeback) {
- if (typeof nodeback == "function") {
- this._then(
- Promise$_successAdapter,
- Promise$_errorAdapter,
- void 0,
- nodeback,
- this._isBound() ? this._boundTo : null,
- this.nodeify
- );
- return;
- }
- return this;
- };
+MappingPromiseArray.prototype.preservedValues = function () {
+ return this._preservedValues;
};
-},{"./async.js":2,"./util.js":38}],18:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, isPromiseArrayProxy) {
- var util = require("./util.js");
- var async = require("./async.js");
- var errors = require("./errors.js");
- var tryCatch1 = util.tryCatch1;
- var errorObj = util.errorObj;
+function map(promises, fn, options, _filter) {
+ var limit = typeof options === "object" && options !== null
+ ? options.concurrency
+ : 0;
+ limit = typeof limit === "number" &&
+ isFinite(limit) && limit >= 1 ? limit : 0;
+ return new MappingPromiseArray(promises, fn, limit, _filter);
+}
- Promise.prototype.progressed = function Promise$progressed(handler) {
- return this._then(void 0, void 0, handler,
- void 0, void 0, this.progressed);
- };
+Promise.prototype.map = function (fn, options) {
+ if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- Promise.prototype._progress = function Promise$_progress(progressValue) {
- if (this._isFollowingOrFulfilledOrRejected()) return;
- this._progressUnchecked(progressValue);
+ return map(this, fn, options, null).promise();
+};
- };
+Promise.map = function (promises, fn, options, _filter) {
+ if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
+ return map(promises, fn, options, _filter).promise();
+};
- Promise.prototype._progressHandlerAt =
- function Promise$_progressHandlerAt(index) {
- if (index === 0) return this._progressHandler0;
- return this[index + 2 - 5];
- };
- Promise.prototype._doProgressWith =
- function Promise$_doProgressWith(progression) {
- var progressValue = progression.value;
- var handler = progression.handler;
- var promise = progression.promise;
- var receiver = progression.receiver;
+};
- this._pushContext();
- var ret = tryCatch1(handler, receiver, progressValue);
- this._popContext();
+},{"./util.js":38}],20:[function(_dereq_,module,exports){
+"use strict";
+module.exports =
+function(Promise, INTERNAL, tryConvertToPromise, apiRejection) {
+var util = _dereq_("./util.js");
+var tryCatch = util.tryCatch;
- if (ret === errorObj) {
- if (ret.e != null &&
- ret.e.name !== "StopProgressPropagation") {
- var trace = errors.canAttach(ret.e)
- ? ret.e : new Error(ret.e + "");
- promise._attachExtraTrace(trace);
- promise._progress(ret.e);
- }
- }
- else if (Promise.is(ret)) {
- ret._then(promise._progress, null, null, promise, void 0,
- this._progress);
- }
- else {
- promise._progress(ret);
- }
+Promise.method = function (fn) {
+ if (typeof fn !== "function") {
+ throw new Promise.TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
+ }
+ return function () {
+ var ret = new Promise(INTERNAL);
+ ret._captureStackTrace();
+ ret._pushContext();
+ var value = tryCatch(fn).apply(this, arguments);
+ ret._popContext();
+ ret._resolveFromSyncValue(value);
+ return ret;
};
+};
+Promise.attempt = Promise["try"] = function (fn, args, ctx) {
+ if (typeof fn !== "function") {
+ return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
+ }
+ var ret = new Promise(INTERNAL);
+ ret._captureStackTrace();
+ ret._pushContext();
+ var value = util.isArray(args)
+ ? tryCatch(fn).apply(ctx, args)
+ : tryCatch(fn).call(ctx, args);
+ ret._popContext();
+ ret._resolveFromSyncValue(value);
+ return ret;
+};
- Promise.prototype._progressUnchecked =
- function Promise$_progressUnchecked(progressValue) {
- if (!this.isPending()) return;
- var len = this._length();
+Promise.prototype._resolveFromSyncValue = function (value) {
+ if (value === util.errorObj) {
+ this._rejectCallback(value.e, false, true);
+ } else {
+ this._resolveCallback(value, true);
+ }
+};
+};
- for (var i = 0; i < len; i += 5) {
- var handler = this._progressHandlerAt(i);
- var promise = this._promiseAt(i);
- if (!Promise.is(promise)) {
- var receiver = this._receiverAt(i);
- if (typeof handler === "function") {
- handler.call(receiver, progressValue, promise);
- }
- else if (Promise.is(receiver) && receiver._isProxied()) {
- receiver._progressUnchecked(progressValue);
- }
- else if (isPromiseArrayProxy(receiver, promise)) {
- receiver._promiseProgressed(progressValue, promise);
- }
- continue;
- }
+},{"./util.js":38}],21:[function(_dereq_,module,exports){
+"use strict";
+module.exports = function(Promise) {
+var util = _dereq_("./util.js");
+var async = _dereq_("./async.js");
+var tryCatch = util.tryCatch;
+var errorObj = util.errorObj;
- if (typeof handler === "function") {
- async.invoke(this._doProgressWith, this, {
- handler: handler,
- promise: promise,
- receiver: this._receiverAt(i),
- value: progressValue
- });
- }
- else {
- async.invoke(promise._progress, promise, progressValue);
- }
+function spreadAdapter(val, nodeback) {
+ var promise = this;
+ if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback);
+ var ret = tryCatch(nodeback).apply(promise._boundTo, [null].concat(val));
+ if (ret === errorObj) {
+ async.throwLater(ret.e);
+ }
+}
+
+function successAdapter(val, nodeback) {
+ var promise = this;
+ var receiver = promise._boundTo;
+ var ret = val === undefined
+ ? tryCatch(nodeback).call(receiver, null)
+ : tryCatch(nodeback).call(receiver, null, val);
+ if (ret === errorObj) {
+ async.throwLater(ret.e);
+ }
+}
+function errorAdapter(reason, nodeback) {
+ var promise = this;
+ if (!reason) {
+ var target = promise._target();
+ var newReason = target._getCarriedStackTrace();
+ newReason.cause = reason;
+ reason = newReason;
+ }
+ var ret = tryCatch(nodeback).call(promise._boundTo, reason);
+ if (ret === errorObj) {
+ async.throwLater(ret.e);
+ }
+}
+
+Promise.prototype.nodeify = function (nodeback, options) {
+ if (typeof nodeback == "function") {
+ var adapter = successAdapter;
+ if (options !== undefined && Object(options).spread) {
+ adapter = spreadAdapter;
}
- };
+ this._then(
+ adapter,
+ errorAdapter,
+ undefined,
+ this,
+ nodeback
+ );
+ }
+ return this;
+};
};
-},{"./async.js":2,"./errors.js":9,"./util.js":38}],19:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./async.js":2,"./util.js":38}],22:[function(_dereq_,module,exports){
"use strict";
-module.exports = function() {
-var global = require("./global.js");
-var util = require("./util.js");
-var async = require("./async.js");
-var errors = require("./errors.js");
+module.exports = function(Promise, PromiseArray) {
+var util = _dereq_("./util.js");
+var async = _dereq_("./async.js");
+var tryCatch = util.tryCatch;
+var errorObj = util.errorObj;
-var INTERNAL = function(){};
-var APPLY = {};
-var NEXT_FILTER = {e: null};
+Promise.prototype.progressed = function (handler) {
+ return this._then(undefined, undefined, handler, undefined, undefined);
+};
-var PromiseArray = require("./promise_array.js")(Promise, INTERNAL);
-var CapturedTrace = require("./captured_trace.js")();
-var CatchFilter = require("./catch_filter.js")(NEXT_FILTER);
-var PromiseResolver = require("./promise_resolver.js");
+Promise.prototype._progress = function (progressValue) {
+ if (this._isFollowingOrFulfilledOrRejected()) return;
+ this._target()._progressUnchecked(progressValue);
-var isArray = util.isArray;
+};
-var errorObj = util.errorObj;
-var tryCatch1 = util.tryCatch1;
-var tryCatch2 = util.tryCatch2;
-var tryCatchApply = util.tryCatchApply;
-var RangeError = errors.RangeError;
-var TypeError = errors.TypeError;
-var CancellationError = errors.CancellationError;
-var TimeoutError = errors.TimeoutError;
-var RejectionError = errors.RejectionError;
-var originatesFromRejection = errors.originatesFromRejection;
-var markAsOriginatingFromRejection = errors.markAsOriginatingFromRejection;
-var canAttach = errors.canAttach;
-var thrower = util.thrower;
-var apiRejection = require("./errors_api_rejection")(Promise);
+Promise.prototype._progressHandlerAt = function (index) {
+ return index === 0
+ ? this._progressHandler0
+ : this[(index << 2) + index - 5 + 2];
+};
+Promise.prototype._doProgressWith = function (progression) {
+ var progressValue = progression.value;
+ var handler = progression.handler;
+ var promise = progression.promise;
+ var receiver = progression.receiver;
-var makeSelfResolutionError = function Promise$_makeSelfResolutionError() {
- return new TypeError("circular promise resolution chain");
+ var ret = tryCatch(handler).call(receiver, progressValue);
+ if (ret === errorObj) {
+ if (ret.e != null &&
+ ret.e.name !== "StopProgressPropagation") {
+ var trace = util.canAttachTrace(ret.e)
+ ? ret.e : new Error(util.toString(ret.e));
+ promise._attachExtraTrace(trace);
+ promise._progress(ret.e);
+ }
+ } else if (ret instanceof Promise) {
+ ret._then(promise._progress, null, null, promise, undefined);
+ } else {
+ promise._progress(ret);
+ }
};
-function isPromise(obj) {
- if (obj === void 0) return false;
- return obj instanceof Promise;
-}
-function isPromiseArrayProxy(receiver, promiseSlotValue) {
- if (receiver instanceof PromiseArray) {
- return promiseSlotValue >= 0;
+Promise.prototype._progressUnchecked = function (progressValue) {
+ var len = this._length();
+ var progress = this._progress;
+ for (var i = 0; i < len; i++) {
+ var handler = this._progressHandlerAt(i);
+ var promise = this._promiseAt(i);
+ if (!(promise instanceof Promise)) {
+ var receiver = this._receiverAt(i);
+ if (typeof handler === "function") {
+ handler.call(receiver, progressValue, promise);
+ } else if (receiver instanceof PromiseArray &&
+ !receiver._isResolved()) {
+ receiver._promiseProgressed(progressValue, promise);
+ }
+ continue;
+ }
+
+ if (typeof handler === "function") {
+ async.invoke(this._doProgressWith, this, {
+ handler: handler,
+ promise: promise,
+ receiver: this._receiverAt(i),
+ value: progressValue
+ });
+ } else {
+ async.invoke(progress, promise, progressValue);
+ }
}
- return false;
-}
+};
+};
+},{"./async.js":2,"./util.js":38}],23:[function(_dereq_,module,exports){
+"use strict";
+module.exports = function() {
+var makeSelfResolutionError = function () {
+ return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/LhFpo0\u000a");
+};
+var reflect = function() {
+ return new Promise.PromiseInspection(this._target());
+};
+var apiRejection = function(msg) {
+ return Promise.reject(new TypeError(msg));
+};
+var util = _dereq_("./util.js");
+var async = _dereq_("./async.js");
+var errors = _dereq_("./errors.js");
+var TypeError = Promise.TypeError = errors.TypeError;
+Promise.RangeError = errors.RangeError;
+Promise.CancellationError = errors.CancellationError;
+Promise.TimeoutError = errors.TimeoutError;
+Promise.OperationalError = errors.OperationalError;
+Promise.RejectionError = errors.OperationalError;
+Promise.AggregateError = errors.AggregateError;
+var INTERNAL = function(){};
+var APPLY = {};
+var NEXT_FILTER = {e: null};
+var tryConvertToPromise = _dereq_("./thenables.js")(Promise, INTERNAL);
+var PromiseArray =
+ _dereq_("./promise_array.js")(Promise, INTERNAL,
+ tryConvertToPromise, apiRejection);
+var CapturedTrace = _dereq_("./captured_trace.js")();
+var isDebugging = _dereq_("./debuggability.js")(Promise, CapturedTrace);
+ /*jshint unused:false*/
+var createContext =
+ _dereq_("./context.js")(Promise, CapturedTrace, isDebugging);
+var CatchFilter = _dereq_("./catch_filter.js")(NEXT_FILTER);
+var PromiseResolver = _dereq_("./promise_resolver.js");
+var nodebackForPromise = PromiseResolver._nodebackForPromise;
+var errorObj = util.errorObj;
+var tryCatch = util.tryCatch;
function Promise(resolver) {
if (typeof resolver !== "function") {
- throw new TypeError("the promise constructor requires a resolver function");
+ throw new TypeError("the promise constructor requires a resolver function\u000a\u000a See http://goo.gl/EC22Yn\u000a");
}
if (this.constructor !== Promise) {
- throw new TypeError("the promise constructor cannot be invoked directly");
+ throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/KsIlge\u000a");
}
this._bitField = 0;
- this._fulfillmentHandler0 = void 0;
- this._rejectionHandler0 = void 0;
- this._promise0 = void 0;
- this._receiver0 = void 0;
- this._settledValue = void 0;
- this._boundTo = void 0;
+ this._fulfillmentHandler0 = undefined;
+ this._rejectionHandler0 = undefined;
+ this._progressHandler0 = undefined;
+ this._promise0 = undefined;
+ this._receiver0 = undefined;
+ this._settledValue = undefined;
if (resolver !== INTERNAL) this._resolveFromResolver(resolver);
}
-Promise.prototype.bind = function Promise$bind(thisArg) {
- var ret = new Promise(INTERNAL);
- if (debugging) ret._setTrace(this.bind, this);
- ret._follow(this);
- ret._setBoundTo(thisArg);
- if (this._cancellable()) {
- ret._setCancellable();
- ret._cancellationParent = this;
- }
- return ret;
-};
-
-Promise.prototype.toString = function Promise$toString() {
+Promise.prototype.toString = function () {
return "[object Promise]";
};
-Promise.prototype.caught = Promise.prototype["catch"] =
-function Promise$catch(fn) {
+Promise.prototype.caught = Promise.prototype["catch"] = function (fn) {
var len = arguments.length;
if (len > 1) {
var catchInstances = new Array(len - 1),
@@ -3806,508 +4240,265 @@ function Promise$catch(fn) {
var item = arguments[i];
if (typeof item === "function") {
catchInstances[j++] = item;
- }
- else {
- var catchFilterTypeError =
- new TypeError(
- "A catch filter must be an error constructor "
- + "or a filter function");
-
- this._attachExtraTrace(catchFilterTypeError);
- async.invoke(this._reject, this, catchFilterTypeError);
- return;
+ } else {
+ return Promise.reject(
+ new TypeError("Catch filter must inherit from Error or be a simple predicate function\u000a\u000a See http://goo.gl/o84o68\u000a"));
}
}
catchInstances.length = j;
fn = arguments[i];
-
- this._resetTrace(this.caught);
var catchFilter = new CatchFilter(catchInstances, fn, this);
- return this._then(void 0, catchFilter.doFilter, void 0,
- catchFilter, void 0, this.caught);
+ return this._then(undefined, catchFilter.doFilter, undefined,
+ catchFilter, undefined);
}
- return this._then(void 0, fn, void 0, void 0, void 0, this.caught);
+ return this._then(undefined, fn, undefined, undefined, undefined);
};
-Promise.prototype.then =
-function Promise$then(didFulfill, didReject, didProgress) {
- return this._then(didFulfill, didReject, didProgress,
- void 0, void 0, this.then);
+Promise.prototype.reflect = function () {
+ return this._then(reflect, reflect, undefined, this, undefined);
};
+Promise.prototype.then = function (didFulfill, didReject, didProgress) {
+ if (isDebugging() && arguments.length > 0 &&
+ typeof didFulfill !== "function" &&
+ typeof didReject !== "function") {
+ var msg = ".then() only accepts functions but was passed: " +
+ util.classString(didFulfill);
+ if (arguments.length > 1) {
+ msg += ", " + util.classString(didReject);
+ }
+ this._warn(msg);
+ }
+ return this._then(didFulfill, didReject, didProgress,
+ undefined, undefined);
+};
-Promise.prototype.done =
-function Promise$done(didFulfill, didReject, didProgress) {
+Promise.prototype.done = function (didFulfill, didReject, didProgress) {
var promise = this._then(didFulfill, didReject, didProgress,
- void 0, void 0, this.done);
+ undefined, undefined);
promise._setIsFinal();
};
-Promise.prototype.spread = function Promise$spread(didFulfill, didReject) {
- return this._then(didFulfill, didReject, void 0,
- APPLY, void 0, this.spread);
-};
-
-Promise.prototype.isFulfilled = function Promise$isFulfilled() {
- return (this._bitField & 268435456) > 0;
-};
-
-
-Promise.prototype.isRejected = function Promise$isRejected() {
- return (this._bitField & 134217728) > 0;
-};
-
-Promise.prototype.isPending = function Promise$isPending() {
- return !this.isResolved();
-};
-
-
-Promise.prototype.isResolved = function Promise$isResolved() {
- return (this._bitField & 402653184) > 0;
+Promise.prototype.spread = function (didFulfill, didReject) {
+ return this.all()._then(didFulfill, didReject, undefined, APPLY, undefined);
};
-
-Promise.prototype.isCancellable = function Promise$isCancellable() {
+Promise.prototype.isCancellable = function () {
return !this.isResolved() &&
this._cancellable();
};
-Promise.prototype.toJSON = function Promise$toJSON() {
+Promise.prototype.toJSON = function () {
var ret = {
isFulfilled: false,
isRejected: false,
- fulfillmentValue: void 0,
- rejectionReason: void 0
+ fulfillmentValue: undefined,
+ rejectionReason: undefined
};
if (this.isFulfilled()) {
- ret.fulfillmentValue = this._settledValue;
+ ret.fulfillmentValue = this.value();
ret.isFulfilled = true;
- }
- else if (this.isRejected()) {
- ret.rejectionReason = this._settledValue;
+ } else if (this.isRejected()) {
+ ret.rejectionReason = this.reason();
ret.isRejected = true;
}
return ret;
};
-Promise.prototype.all = function Promise$all() {
- return Promise$_all(this, true, this.all);
-};
-
-
-Promise.is = isPromise;
-
-function Promise$_all(promises, useBound, caller) {
- return Promise$_CreatePromiseArray(
- promises,
- PromiseArray,
- caller,
- useBound === true && promises._isBound()
- ? promises._boundTo
- : void 0
- ).promise();
-}
-Promise.all = function Promise$All(promises) {
- return Promise$_all(promises, false, Promise.all);
+Promise.prototype.all = function () {
+ return new PromiseArray(this).promise();
};
-Promise.join = function Promise$Join() {
- var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
- return Promise$_CreatePromiseArray(
- args, PromiseArray, Promise.join, void 0).promise();
+Promise.prototype.error = function (fn) {
+ return this.caught(util.originatesFromRejection, fn);
};
-Promise.resolve = Promise.fulfilled =
-function Promise$Resolve(value, caller) {
- var ret = new Promise(INTERNAL);
- if (debugging) ret._setTrace(typeof caller === "function"
- ? caller
- : Promise.resolve, void 0);
- if (ret._tryFollow(value)) {
- return ret;
- }
- ret._cleanValues();
- ret._setFulfilled();
- ret._settledValue = value;
- return ret;
+Promise.is = function (val) {
+ return val instanceof Promise;
};
-Promise.reject = Promise.rejected = function Promise$Reject(reason) {
+Promise.fromNode = function(fn) {
var ret = new Promise(INTERNAL);
- if (debugging) ret._setTrace(Promise.reject, void 0);
- markAsOriginatingFromRejection(reason);
- ret._cleanValues();
- ret._setRejected();
- ret._settledValue = reason;
- if (!canAttach(reason)) {
- var trace = new Error(reason + "");
- ret._setCarriedStackTrace(trace);
+ var result = tryCatch(fn)(nodebackForPromise(ret));
+ if (result === errorObj) {
+ ret._rejectCallback(result.e, true, true);
}
- ret._ensurePossibleRejectionHandled();
return ret;
};
-Promise.prototype.error = function Promise$_error(fn) {
- return this.caught(originatesFromRejection, fn);
-};
-
-Promise.prototype._resolveFromSyncValue =
-function Promise$_resolveFromSyncValue(value, caller) {
- if (value === errorObj) {
- this._cleanValues();
- this._setRejected();
- this._settledValue = value.e;
- this._ensurePossibleRejectionHandled();
- }
- else {
- var maybePromise = Promise._cast(value, caller, void 0);
- if (maybePromise instanceof Promise) {
- this._follow(maybePromise);
- }
- else {
- this._cleanValues();
- this._setFulfilled();
- this._settledValue = value;
- }
- }
-};
-
-Promise.method = function Promise$_Method(fn) {
- if (typeof fn !== "function") {
- throw new TypeError("fn must be a function");
- }
- return function Promise$_method() {
- var value;
- switch(arguments.length) {
- case 0: value = tryCatch1(fn, this, void 0); break;
- case 1: value = tryCatch1(fn, this, arguments[0]); break;
- case 2: value = tryCatch2(fn, this, arguments[0], arguments[1]); break;
- default:
- var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
- value = tryCatchApply(fn, args, this); break;
- }
- var ret = new Promise(INTERNAL);
- if (debugging) ret._setTrace(Promise$_method, void 0);
- ret._resolveFromSyncValue(value, Promise$_method);
- return ret;
- };
-};
-
-Promise.attempt = Promise["try"] = function Promise$_Try(fn, args, ctx) {
-
- if (typeof fn !== "function") {
- return apiRejection("fn must be a function");
- }
- var value = isArray(args)
- ? tryCatchApply(fn, args, ctx)
- : tryCatch1(fn, ctx, args);
-
- var ret = new Promise(INTERNAL);
- if (debugging) ret._setTrace(Promise.attempt, void 0);
- ret._resolveFromSyncValue(value, Promise.attempt);
- return ret;
+Promise.all = function (promises) {
+ return new PromiseArray(promises).promise();
};
-Promise.defer = Promise.pending = function Promise$Defer(caller) {
+Promise.defer = Promise.pending = function () {
var promise = new Promise(INTERNAL);
- if (debugging) promise._setTrace(typeof caller === "function"
- ? caller : Promise.defer, void 0);
return new PromiseResolver(promise);
};
-Promise.bind = function Promise$Bind(thisArg) {
- var ret = new Promise(INTERNAL);
- if (debugging) ret._setTrace(Promise.bind, void 0);
- ret._setFulfilled();
- ret._setBoundTo(thisArg);
- return ret;
-};
-
-Promise.cast = function Promise$_Cast(obj, caller) {
- if (typeof caller !== "function") {
- caller = Promise.cast;
- }
- var ret = Promise._cast(obj, caller, void 0);
+Promise.cast = function (obj) {
+ var ret = tryConvertToPromise(obj);
if (!(ret instanceof Promise)) {
- return Promise.resolve(ret, caller);
+ var val = ret;
+ ret = new Promise(INTERNAL);
+ ret._fulfillUnchecked(val);
}
return ret;
};
-Promise.onPossiblyUnhandledRejection =
-function Promise$OnPossiblyUnhandledRejection(fn) {
- if (typeof fn === "function") {
- CapturedTrace.possiblyUnhandledRejection = fn;
- }
- else {
- CapturedTrace.possiblyUnhandledRejection = void 0;
- }
-};
-
-var debugging = false || !!(
- typeof process !== "undefined" &&
- typeof process.execPath === "string" &&
- typeof process.env === "object" &&
- (process.env["BLUEBIRD_DEBUG"] ||
- process.env["NODE_ENV"] === "development")
-);
-
-
-Promise.longStackTraces = function Promise$LongStackTraces() {
- if (async.haveItemsQueued() &&
- debugging === false
- ) {
- throw new Error("cannot enable long stack traces after promises have been created");
- }
- debugging = CapturedTrace.isSupported();
-};
-
-Promise.hasLongStackTraces = function Promise$HasLongStackTraces() {
- return debugging && CapturedTrace.isSupported();
-};
-
-Promise.prototype._setProxyHandlers =
-function Promise$_setProxyHandlers(receiver, promiseSlotValue) {
- var index = this._length();
-
- if (index >= 1048575 - 5) {
- index = 0;
- this._setLength(0);
- }
- if (index === 0) {
- this._promise0 = promiseSlotValue;
- this._receiver0 = receiver;
- }
- else {
- var i = index - 5;
- this[i + 3] = promiseSlotValue;
- this[i + 4] = receiver;
- this[i + 0] =
- this[i + 1] =
- this[i + 2] = void 0;
- }
- this._setLength(index + 5);
-};
+Promise.resolve = Promise.fulfilled = Promise.cast;
-Promise.prototype._proxyPromiseArray =
-function Promise$_proxyPromiseArray(promiseArray, index) {
- this._setProxyHandlers(promiseArray, index);
+Promise.reject = Promise.rejected = function (reason) {
+ var ret = new Promise(INTERNAL);
+ ret._captureStackTrace();
+ ret._rejectCallback(reason, true);
+ return ret;
};
-Promise.prototype._proxyPromise = function Promise$_proxyPromise(promise) {
- promise._setProxied();
- this._setProxyHandlers(promise, -1);
+Promise.setScheduler = function(fn) {
+ if (typeof fn !== "function") throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
+ var prev = async._schedule;
+ async._schedule = fn;
+ return prev;
};
-Promise.prototype._then =
-function Promise$_then(
+Promise.prototype._then = function (
didFulfill,
didReject,
didProgress,
receiver,
- internalData,
- caller
+ internalData
) {
- var haveInternalData = internalData !== void 0;
+ var haveInternalData = internalData !== undefined;
var ret = haveInternalData ? internalData : new Promise(INTERNAL);
- if (debugging && !haveInternalData) {
- var haveSameContext = this._peekContext() === this._traceParent;
- ret._traceParent = haveSameContext ? this._traceParent : this;
- ret._setTrace(typeof caller === "function"
- ? caller
- : this._then, this);
+ if (!haveInternalData) {
+ ret._propagateFrom(this, 4 | 1);
+ ret._captureStackTrace();
}
- if (!haveInternalData && this._isBound()) {
- ret._setBoundTo(this._boundTo);
+ var target = this._target();
+ if (target !== this) {
+ if (receiver === undefined) receiver = this._boundTo;
+ if (!haveInternalData) ret._setIsMigrated();
}
var callbackIndex =
- this._addCallbacks(didFulfill, didReject, didProgress, ret, receiver);
-
- if (!haveInternalData && this._cancellable()) {
- ret._setCancellable();
- ret._cancellationParent = this;
- }
+ target._addCallbacks(didFulfill, didReject, didProgress, ret, receiver);
- if (this.isResolved()) {
- async.invoke(this._queueSettleAt, this, callbackIndex);
+ if (target._isResolved() && !target._isSettlePromisesQueued()) {
+ async.invoke(
+ target._settlePromiseAtPostResolution, target, callbackIndex);
}
return ret;
};
-Promise.prototype._length = function Promise$_length() {
- return this._bitField & 1048575;
+Promise.prototype._settlePromiseAtPostResolution = function (index) {
+ if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled();
+ this._settlePromiseAt(index);
+};
+
+Promise.prototype._length = function () {
+ return this._bitField & 131071;
};
-Promise.prototype._isFollowingOrFulfilledOrRejected =
-function Promise$_isFollowingOrFulfilledOrRejected() {
+Promise.prototype._isFollowingOrFulfilledOrRejected = function () {
return (this._bitField & 939524096) > 0;
};
-Promise.prototype._isFollowing = function Promise$_isFollowing() {
+Promise.prototype._isFollowing = function () {
return (this._bitField & 536870912) === 536870912;
};
-Promise.prototype._setLength = function Promise$_setLength(len) {
- this._bitField = (this._bitField & -1048576) |
- (len & 1048575);
+Promise.prototype._setLength = function (len) {
+ this._bitField = (this._bitField & -131072) |
+ (len & 131071);
};
-Promise.prototype._setFulfilled = function Promise$_setFulfilled() {
+Promise.prototype._setFulfilled = function () {
this._bitField = this._bitField | 268435456;
};
-Promise.prototype._setRejected = function Promise$_setRejected() {
+Promise.prototype._setRejected = function () {
this._bitField = this._bitField | 134217728;
};
-Promise.prototype._setFollowing = function Promise$_setFollowing() {
+Promise.prototype._setFollowing = function () {
this._bitField = this._bitField | 536870912;
};
-Promise.prototype._setIsFinal = function Promise$_setIsFinal() {
+Promise.prototype._setIsFinal = function () {
this._bitField = this._bitField | 33554432;
};
-Promise.prototype._isFinal = function Promise$_isFinal() {
+Promise.prototype._isFinal = function () {
return (this._bitField & 33554432) > 0;
};
-Promise.prototype._cancellable = function Promise$_cancellable() {
+Promise.prototype._cancellable = function () {
return (this._bitField & 67108864) > 0;
};
-Promise.prototype._setCancellable = function Promise$_setCancellable() {
+Promise.prototype._setCancellable = function () {
this._bitField = this._bitField | 67108864;
};
-Promise.prototype._unsetCancellable = function Promise$_unsetCancellable() {
+Promise.prototype._unsetCancellable = function () {
this._bitField = this._bitField & (~67108864);
};
-Promise.prototype._setRejectionIsUnhandled =
-function Promise$_setRejectionIsUnhandled() {
- this._bitField = this._bitField | 2097152;
-};
-
-Promise.prototype._unsetRejectionIsUnhandled =
-function Promise$_unsetRejectionIsUnhandled() {
- this._bitField = this._bitField & (~2097152);
-};
-
-Promise.prototype._isRejectionUnhandled =
-function Promise$_isRejectionUnhandled() {
- return (this._bitField & 2097152) > 0;
-};
-
-Promise.prototype._setCarriedStackTrace =
-function Promise$_setCarriedStackTrace(capturedTrace) {
- this._bitField = this._bitField | 1048576;
- this._fulfillmentHandler0 = capturedTrace;
-};
-
-Promise.prototype._unsetCarriedStackTrace =
-function Promise$_unsetCarriedStackTrace() {
- this._bitField = this._bitField & (~1048576);
- this._fulfillmentHandler0 = void 0;
+Promise.prototype._setIsMigrated = function () {
+ this._bitField = this._bitField | 4194304;
};
-Promise.prototype._isCarryingStackTrace =
-function Promise$_isCarryingStackTrace() {
- return (this._bitField & 1048576) > 0;
+Promise.prototype._unsetIsMigrated = function () {
+ this._bitField = this._bitField & (~4194304);
};
-Promise.prototype._getCarriedStackTrace =
-function Promise$_getCarriedStackTrace() {
- return this._isCarryingStackTrace()
- ? this._fulfillmentHandler0
- : void 0;
+Promise.prototype._isMigrated = function () {
+ return (this._bitField & 4194304) > 0;
};
-Promise.prototype._receiverAt = function Promise$_receiverAt(index) {
- var ret;
- if (index === 0) {
- ret = this._receiver0;
- }
- else {
- ret = this[index + 4 - 5];
- }
- if (this._isBound() && ret === void 0) {
+Promise.prototype._receiverAt = function (index) {
+ var ret = index === 0
+ ? this._receiver0
+ : this[
+ index * 5 - 5 + 4];
+ if (ret === undefined && this._isBound()) {
return this._boundTo;
}
return ret;
};
-Promise.prototype._promiseAt = function Promise$_promiseAt(index) {
- if (index === 0) return this._promise0;
- return this[index + 3 - 5];
-};
-
-Promise.prototype._fulfillmentHandlerAt =
-function Promise$_fulfillmentHandlerAt(index) {
- if (index === 0) return this._fulfillmentHandler0;
- return this[index + 0 - 5];
+Promise.prototype._promiseAt = function (index) {
+ return index === 0
+ ? this._promise0
+ : this[index * 5 - 5 + 3];
};
-Promise.prototype._rejectionHandlerAt =
-function Promise$_rejectionHandlerAt(index) {
- if (index === 0) return this._rejectionHandler0;
- return this[index + 1 - 5];
+Promise.prototype._fulfillmentHandlerAt = function (index) {
+ return index === 0
+ ? this._fulfillmentHandler0
+ : this[index * 5 - 5 + 0];
};
-Promise.prototype._unsetAt = function Promise$_unsetAt(index) {
- if (index === 0) {
- this._rejectionHandler0 =
- this._progressHandler0 =
- this._promise0 =
- this._receiver0 = void 0;
- if (!this._isCarryingStackTrace()) {
- this._fulfillmentHandler0 = void 0;
- }
- }
- else {
- this[index - 5 + 0] =
- this[index - 5 + 1] =
- this[index - 5 + 2] =
- this[index - 5 + 3] =
- this[index - 5 + 4] = void 0;
- }
+Promise.prototype._rejectionHandlerAt = function (index) {
+ return index === 0
+ ? this._rejectionHandler0
+ : this[index * 5 - 5 + 1];
};
-Promise.prototype._resolveFromResolver =
-function Promise$_resolveFromResolver(resolver) {
- var promise = this;
- var localDebugging = debugging;
- if (localDebugging) {
- this._setTrace(this._resolveFromResolver, void 0);
- this._pushContext();
- }
- function Promise$_resolver(val) {
- if (promise._tryFollow(val)) {
- return;
- }
- promise._fulfill(val);
- }
- function Promise$_rejecter(val) {
- var trace = canAttach(val) ? val : new Error(val + "");
- promise._attachExtraTrace(trace);
- markAsOriginatingFromRejection(val);
- promise._reject(val, trace === val ? void 0 : trace);
- }
- var r = tryCatch2(resolver, void 0, Promise$_resolver, Promise$_rejecter);
- if (localDebugging) this._popContext();
-
- if (r !== void 0 && r === errorObj) {
- var e = r.e;
- var trace = canAttach(e) ? e : new Error(e + "");
- promise._reject(e, trace);
- }
+Promise.prototype._migrateCallbacks = function (follower, index) {
+ var fulfill = follower._fulfillmentHandlerAt(index);
+ var reject = follower._rejectionHandlerAt(index);
+ var progress = follower._progressHandlerAt(index);
+ var promise = follower._promiseAt(index);
+ var receiver = follower._receiverAt(index);
+ if (promise instanceof Promise) promise._setIsMigrated();
+ this._addCallbacks(fulfill, reject, progress, promise, receiver);
};
-Promise.prototype._addCallbacks = function Promise$_addCallbacks(
+Promise.prototype._addCallbacks = function (
fulfill,
reject,
progress,
@@ -4316,757 +4507,485 @@ Promise.prototype._addCallbacks = function Promise$_addCallbacks(
) {
var index = this._length();
- if (index >= 1048575 - 5) {
+ if (index >= 131071 - 5) {
index = 0;
this._setLength(0);
}
if (index === 0) {
this._promise0 = promise;
- if (receiver !== void 0) this._receiver0 = receiver;
+ if (receiver !== undefined) this._receiver0 = receiver;
if (typeof fulfill === "function" && !this._isCarryingStackTrace())
this._fulfillmentHandler0 = fulfill;
if (typeof reject === "function") this._rejectionHandler0 = reject;
if (typeof progress === "function") this._progressHandler0 = progress;
- }
- else {
- var i = index - 5;
- this[i + 3] = promise;
- this[i + 4] = receiver;
- this[i + 0] = typeof fulfill === "function"
- ? fulfill : void 0;
- this[i + 1] = typeof reject === "function"
- ? reject : void 0;
- this[i + 2] = typeof progress === "function"
- ? progress : void 0;
- }
- this._setLength(index + 5);
+ } else {
+ var base = index * 5 - 5;
+ this[base + 3] = promise;
+ this[base + 4] = receiver;
+ if (typeof fulfill === "function")
+ this[base + 0] = fulfill;
+ if (typeof reject === "function")
+ this[base + 1] = reject;
+ if (typeof progress === "function")
+ this[base + 2] = progress;
+ }
+ this._setLength(index + 1);
return index;
};
+Promise.prototype._setProxyHandlers = function (receiver, promiseSlotValue) {
+ var index = this._length();
-
-Promise.prototype._setBoundTo = function Promise$_setBoundTo(obj) {
- if (obj !== void 0) {
- this._bitField = this._bitField | 8388608;
- this._boundTo = obj;
+ if (index >= 131071 - 5) {
+ index = 0;
+ this._setLength(0);
}
- else {
- this._bitField = this._bitField & (~8388608);
+ if (index === 0) {
+ this._promise0 = promiseSlotValue;
+ this._receiver0 = receiver;
+ } else {
+ var base = index * 5 - 5;
+ this[base + 3] = promiseSlotValue;
+ this[base + 4] = receiver;
}
+ this._setLength(index + 1);
};
-Promise.prototype._isBound = function Promise$_isBound() {
- return (this._bitField & 8388608) === 8388608;
-};
-
-Promise.prototype._spreadSlowCase =
-function Promise$_spreadSlowCase(targetFn, promise, values, boundTo) {
- var promiseForAll =
- Promise$_CreatePromiseArray
- (values, PromiseArray, this._spreadSlowCase, boundTo)
- .promise()
- ._then(function() {
- return targetFn.apply(boundTo, arguments);
- }, void 0, void 0, APPLY, void 0, this._spreadSlowCase);
-
- promise._follow(promiseForAll);
+Promise.prototype._proxyPromiseArray = function (promiseArray, index) {
+ this._setProxyHandlers(promiseArray, index);
};
-Promise.prototype._callSpread =
-function Promise$_callSpread(handler, promise, value, localDebugging) {
- var boundTo = this._isBound() ? this._boundTo : void 0;
- if (isArray(value)) {
- var caller = this._settlePromiseFromHandler;
- for (var i = 0, len = value.length; i < len; ++i) {
- if (isPromise(Promise._cast(value[i], caller, void 0))) {
- this._spreadSlowCase(handler, promise, value, boundTo);
- return;
- }
+Promise.prototype._resolveCallback = function(value, shouldBind) {
+ if (this._isFollowingOrFulfilledOrRejected()) return;
+ if (value === this)
+ return this._rejectCallback(makeSelfResolutionError(), false, true);
+ var maybePromise = tryConvertToPromise(value, this);
+ if (!(maybePromise instanceof Promise)) return this._fulfill(value);
+
+ var propagationFlags = 1 | (shouldBind ? 4 : 0);
+ this._propagateFrom(maybePromise, propagationFlags);
+ var promise = maybePromise._target();
+ if (promise._isPending()) {
+ var len = this._length();
+ for (var i = 0; i < len; ++i) {
+ promise._migrateCallbacks(this, i);
}
+ this._setFollowing();
+ this._setLength(0);
+ this._setFollowee(promise);
+ } else if (promise._isFulfilled()) {
+ this._fulfillUnchecked(promise._value());
+ } else {
+ this._rejectUnchecked(promise._reason(),
+ promise._getCarriedStackTrace());
}
- if (localDebugging) promise._pushContext();
- return tryCatchApply(handler, value, boundTo);
-};
-
-Promise.prototype._callHandler =
-function Promise$_callHandler(
- handler, receiver, promise, value, localDebugging) {
- var x;
- if (receiver === APPLY && !this.isRejected()) {
- x = this._callSpread(handler, promise, value, localDebugging);
- }
- else {
- if (localDebugging) promise._pushContext();
- x = tryCatch1(handler, receiver, value);
- }
- if (localDebugging) promise._popContext();
- return x;
};
-Promise.prototype._settlePromiseFromHandler =
-function Promise$_settlePromiseFromHandler(
- handler, receiver, value, promise
-) {
- if (!isPromise(promise)) {
- handler.call(receiver, value, promise);
- return;
- }
-
- var localDebugging = debugging;
- var x = this._callHandler(handler, receiver,
- promise, value, localDebugging);
-
- if (promise._isFollowing()) return;
-
- if (x === errorObj || x === promise || x === NEXT_FILTER) {
- var err = x === promise
- ? makeSelfResolutionError()
- : x.e;
- var trace = canAttach(err) ? err : new Error(err + "");
- if (x !== NEXT_FILTER) promise._attachExtraTrace(trace);
- promise._rejectUnchecked(err, trace);
- }
- else {
- var castValue = Promise._cast(x,
- localDebugging ? this._settlePromiseFromHandler : void 0,
- promise);
-
- if (isPromise(castValue)) {
- if (castValue.isRejected() &&
- !castValue._isCarryingStackTrace() &&
- !canAttach(castValue._settledValue)) {
- var trace = new Error(castValue._settledValue + "");
- promise._attachExtraTrace(trace);
- castValue._setCarriedStackTrace(trace);
- }
- promise._follow(castValue);
- if (castValue._cancellable()) {
- promise._cancellationParent = castValue;
- promise._setCancellable();
- }
- }
- else {
- promise._fulfillUnchecked(x);
- }
+Promise.prototype._rejectCallback =
+function(reason, synchronous, shouldNotMarkOriginatingFromRejection) {
+ if (!shouldNotMarkOriginatingFromRejection) {
+ util.markAsOriginatingFromRejection(reason);
}
+ var trace = util.ensureErrorObject(reason);
+ var hasStack = trace === reason;
+ this._attachExtraTrace(trace, synchronous ? hasStack : false);
+ this._reject(reason, hasStack ? undefined : trace);
};
-Promise.prototype._follow =
-function Promise$_follow(promise) {
- this._setFollowing();
-
- if (promise.isPending()) {
- if (promise._cancellable() ) {
- this._cancellationParent = promise;
- this._setCancellable();
- }
- promise._proxyPromise(this);
- }
- else if (promise.isFulfilled()) {
- this._fulfillUnchecked(promise._settledValue);
- }
- else {
- this._rejectUnchecked(promise._settledValue,
- promise._getCarriedStackTrace());
- }
-
- if (promise._isRejectionUnhandled()) promise._unsetRejectionIsUnhandled();
+Promise.prototype._resolveFromResolver = function (resolver) {
+ var promise = this;
+ this._captureStackTrace();
+ this._pushContext();
+ var synchronous = true;
+ var r = tryCatch(resolver)(function(value) {
+ if (promise === null) return;
+ promise._resolveCallback(value);
+ promise = null;
+ }, function (reason) {
+ if (promise === null) return;
+ promise._rejectCallback(reason, synchronous);
+ promise = null;
+ });
+ synchronous = false;
+ this._popContext();
- if (debugging &&
- promise._traceParent == null) {
- promise._traceParent = this;
+ if (r !== undefined && r === errorObj && promise !== null) {
+ promise._rejectCallback(r.e, true, true);
+ promise = null;
}
};
-Promise.prototype._tryFollow =
-function Promise$_tryFollow(value) {
- if (this._isFollowingOrFulfilledOrRejected() ||
- value === this) {
- return false;
+Promise.prototype._settlePromiseFromHandler = function (
+ handler, receiver, value, promise
+) {
+ if (promise._isRejected()) return;
+ promise._pushContext();
+ var x;
+ if (receiver === APPLY && !this._isRejected()) {
+ x = tryCatch(handler).apply(this._boundTo, value);
+ } else {
+ x = tryCatch(handler).call(receiver, value);
}
- var maybePromise = Promise._cast(value, this._tryFollow, void 0);
- if (!isPromise(maybePromise)) {
- return false;
+ promise._popContext();
+
+ if (x === errorObj || x === promise || x === NEXT_FILTER) {
+ var err = x === promise ? makeSelfResolutionError() : x.e;
+ promise._rejectCallback(err, false, true);
+ } else {
+ promise._resolveCallback(x);
}
- this._follow(maybePromise);
- return true;
};
-Promise.prototype._resetTrace = function Promise$_resetTrace(caller) {
- if (debugging) {
- var context = this._peekContext();
- var isTopLevel = context === void 0;
- this._trace = new CapturedTrace(
- typeof caller === "function"
- ? caller
- : this._resetTrace,
- isTopLevel
- );
- }
+Promise.prototype._target = function() {
+ var ret = this;
+ while (ret._isFollowing()) ret = ret._followee();
+ return ret;
};
-Promise.prototype._setTrace = function Promise$_setTrace(caller, parent) {
- if (debugging) {
- var context = this._peekContext();
- this._traceParent = context;
- var isTopLevel = context === void 0;
- if (parent !== void 0 &&
- parent._traceParent === context) {
- this._trace = parent._trace;
- }
- else {
- this._trace = new CapturedTrace(
- typeof caller === "function"
- ? caller
- : this._setTrace,
- isTopLevel
- );
- }
- }
- return this;
+Promise.prototype._followee = function() {
+ return this._rejectionHandler0;
};
-Promise.prototype._attachExtraTrace =
-function Promise$_attachExtraTrace(error) {
- if (debugging) {
- var promise = this;
- var stack = error.stack;
- stack = typeof stack === "string"
- ? stack.split("\n") : [];
- var headerLineCount = 1;
-
- while(promise != null &&
- promise._trace != null) {
- stack = CapturedTrace.combine(
- stack,
- promise._trace.stack.split("\n")
- );
- promise = promise._traceParent;
- }
+Promise.prototype._setFollowee = function(promise) {
+ this._rejectionHandler0 = promise;
+};
- var max = Error.stackTraceLimit + headerLineCount;
- var len = stack.length;
- if (len > max) {
- stack.length = max;
- }
- if (stack.length <= headerLineCount) {
- error.stack = "(No stack trace)";
- }
- else {
- error.stack = stack.join("\n");
- }
+Promise.prototype._cleanValues = function () {
+ if (this._cancellable()) {
+ this._cancellationParent = undefined;
}
};
-Promise.prototype._cleanValues = function Promise$_cleanValues() {
- if (this._cancellable()) {
- this._cancellationParent = void 0;
+Promise.prototype._propagateFrom = function (parent, flags) {
+ if ((flags & 1) > 0 && parent._cancellable()) {
+ this._setCancellable();
+ this._cancellationParent = parent;
+ }
+ if ((flags & 4) > 0 && parent._isBound()) {
+ this._setBoundTo(parent._boundTo);
}
};
-Promise.prototype._fulfill = function Promise$_fulfill(value) {
+Promise.prototype._fulfill = function (value) {
if (this._isFollowingOrFulfilledOrRejected()) return;
this._fulfillUnchecked(value);
};
-Promise.prototype._reject =
-function Promise$_reject(reason, carriedStackTrace) {
+Promise.prototype._reject = function (reason, carriedStackTrace) {
if (this._isFollowingOrFulfilledOrRejected()) return;
this._rejectUnchecked(reason, carriedStackTrace);
};
-Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) {
- var handler = this.isFulfilled()
+Promise.prototype._settlePromiseAt = function (index) {
+ var promise = this._promiseAt(index);
+ var isPromise = promise instanceof Promise;
+
+ if (isPromise && promise._isMigrated()) {
+ promise._unsetIsMigrated();
+ return async.invoke(this._settlePromiseAt, this, index);
+ }
+ var handler = this._isFulfilled()
? this._fulfillmentHandlerAt(index)
: this._rejectionHandlerAt(index);
+ var carriedStackTrace =
+ this._isCarryingStackTrace() ? this._getCarriedStackTrace() : undefined;
var value = this._settledValue;
var receiver = this._receiverAt(index);
- var promise = this._promiseAt(index);
- if (typeof handler === "function") {
- this._settlePromiseFromHandler(handler, receiver, value, promise);
- }
- else {
- var done = false;
- var isFulfilled = this.isFulfilled();
- if (receiver !== void 0) {
- if (receiver instanceof Promise &&
- receiver._isProxied()) {
- receiver._unsetProxied();
-
- if (isFulfilled) receiver._fulfillUnchecked(value);
- else receiver._rejectUnchecked(value,
- this._getCarriedStackTrace());
- done = true;
- }
- else if (isPromiseArrayProxy(receiver, promise)) {
- if (isFulfilled) receiver._promiseFulfilled(value, promise);
- else receiver._promiseRejected(value, promise);
+ this._clearCallbackDataAtIndex(index);
- done = true;
+ if (typeof handler === "function") {
+ if (!isPromise) {
+ handler.call(receiver, value, promise);
+ } else {
+ this._settlePromiseFromHandler(handler, receiver, value, promise);
+ }
+ } else if (receiver instanceof PromiseArray) {
+ if (!receiver._isResolved()) {
+ if (this._isFulfilled()) {
+ receiver._promiseFulfilled(value, promise);
+ }
+ else {
+ receiver._promiseRejected(value, promise);
}
}
-
- if (!done) {
-
- if (isFulfilled) promise._fulfill(value);
- else promise._reject(value, this._getCarriedStackTrace());
-
+ } else if (isPromise) {
+ if (this._isFulfilled()) {
+ promise._fulfill(value);
+ } else {
+ promise._reject(value, carriedStackTrace);
}
}
- if (index >= 256) {
- this._queueGC();
- }
-};
-
-Promise.prototype._isProxied = function Promise$_isProxied() {
- return (this._bitField & 4194304) === 4194304;
-};
-
-Promise.prototype._setProxied = function Promise$_setProxied() {
- this._bitField = this._bitField | 4194304;
+ if (index >= 4 && (index & 31) === 4)
+ async.invokeLater(this._setLength, this, 0);
};
-Promise.prototype._unsetProxied = function Promise$_unsetProxied() {
- this._bitField = this._bitField & (~4194304);
+Promise.prototype._clearCallbackDataAtIndex = function(index) {
+ if (index === 0) {
+ if (!this._isCarryingStackTrace()) {
+ this._fulfillmentHandler0 = undefined;
+ }
+ this._rejectionHandler0 =
+ this._progressHandler0 =
+ this._receiver0 =
+ this._promise0 = undefined;
+ } else {
+ var base = index * 5 - 5;
+ this[base + 3] =
+ this[base + 4] =
+ this[base + 0] =
+ this[base + 1] =
+ this[base + 2] = undefined;
+ }
};
-Promise.prototype._isGcQueued = function Promise$_isGcQueued() {
- return (this._bitField & -1073741824) === -1073741824;
+Promise.prototype._isSettlePromisesQueued = function () {
+ return (this._bitField &
+ -1073741824) === -1073741824;
};
-Promise.prototype._setGcQueued = function Promise$_setGcQueued() {
+Promise.prototype._setSettlePromisesQueued = function () {
this._bitField = this._bitField | -1073741824;
};
-Promise.prototype._unsetGcQueued = function Promise$_unsetGcQueued() {
+Promise.prototype._unsetSettlePromisesQueued = function () {
this._bitField = this._bitField & (~-1073741824);
};
-Promise.prototype._queueGC = function Promise$_queueGC() {
- if (this._isGcQueued()) return;
- this._setGcQueued();
- async.invokeLater(this._gc, this, void 0);
+Promise.prototype._queueSettlePromises = function() {
+ async.settlePromises(this);
+ this._setSettlePromisesQueued();
};
-Promise.prototype._gc = function Promise$gc() {
- var len = this._length();
- this._unsetAt(0);
- for (var i = 0; i < len; i++) {
- delete this[i];
- }
- this._setLength(0);
- this._unsetGcQueued();
-};
-
-Promise.prototype._queueSettleAt = function Promise$_queueSettleAt(index) {
- if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled();
- async.invoke(this._settlePromiseAt, this, index);
-};
-
-Promise.prototype._fulfillUnchecked =
-function Promise$_fulfillUnchecked(value) {
- if (!this.isPending()) return;
+Promise.prototype._fulfillUnchecked = function (value) {
if (value === this) {
var err = makeSelfResolutionError();
this._attachExtraTrace(err);
- return this._rejectUnchecked(err, void 0);
+ return this._rejectUnchecked(err, undefined);
}
- this._cleanValues();
this._setFulfilled();
this._settledValue = value;
- var len = this._length();
+ this._cleanValues();
- if (len > 0) {
- async.invoke(this._fulfillPromises, this, len);
+ if (this._length() > 0) {
+ this._queueSettlePromises();
}
};
-Promise.prototype._rejectUncheckedCheckError =
-function Promise$_rejectUncheckedCheckError(reason) {
- var trace = canAttach(reason) ? reason : new Error(reason + "");
- this._rejectUnchecked(reason, trace === reason ? void 0 : trace);
+Promise.prototype._rejectUncheckedCheckError = function (reason) {
+ var trace = util.ensureErrorObject(reason);
+ this._rejectUnchecked(reason, trace === reason ? undefined : trace);
};
-Promise.prototype._rejectUnchecked =
-function Promise$_rejectUnchecked(reason, trace) {
- if (!this.isPending()) return;
+Promise.prototype._rejectUnchecked = function (reason, trace) {
if (reason === this) {
var err = makeSelfResolutionError();
this._attachExtraTrace(err);
return this._rejectUnchecked(err);
}
- this._cleanValues();
this._setRejected();
this._settledValue = reason;
+ this._cleanValues();
if (this._isFinal()) {
- async.invokeLater(thrower, void 0, trace === void 0 ? reason : trace);
+ async.throwLater(function(e) {
+ if ("stack" in e) {
+ async.invokeFirst(
+ CapturedTrace.unhandledRejection, undefined, e);
+ }
+ throw e;
+ }, trace === undefined ? reason : trace);
return;
}
- var len = this._length();
-
- if (trace !== void 0) this._setCarriedStackTrace(trace);
- if (len > 0) {
- async.invoke(this._rejectPromises, this, null);
+ if (trace !== undefined && trace !== reason) {
+ this._setCarriedStackTrace(trace);
}
- else {
+
+ if (this._length() > 0) {
+ this._queueSettlePromises();
+ } else {
this._ensurePossibleRejectionHandled();
}
};
-Promise.prototype._rejectPromises = function Promise$_rejectPromises() {
+Promise.prototype._settlePromises = function () {
+ this._unsetSettlePromisesQueued();
var len = this._length();
- for (var i = 0; i < len; i+= 5) {
- this._settlePromiseAt(i);
- }
- this._unsetCarriedStackTrace();
-};
-
-Promise.prototype._fulfillPromises = function Promise$_fulfillPromises(len) {
- len = this._length();
- for (var i = 0; i < len; i+= 5) {
+ for (var i = 0; i < len; i++) {
this._settlePromiseAt(i);
}
};
-Promise.prototype._ensurePossibleRejectionHandled =
-function Promise$_ensurePossibleRejectionHandled() {
- this._setRejectionIsUnhandled();
- if (CapturedTrace.possiblyUnhandledRejection !== void 0) {
- async.invokeLater(this._notifyUnhandledRejection, this, void 0);
- }
-};
-
-Promise.prototype._notifyUnhandledRejection =
-function Promise$_notifyUnhandledRejection() {
- if (this._isRejectionUnhandled()) {
- var reason = this._settledValue;
- var trace = this._getCarriedStackTrace();
-
- this._unsetRejectionIsUnhandled();
-
- if (trace !== void 0) {
- this._unsetCarriedStackTrace();
- reason = trace;
- }
- if (typeof CapturedTrace.possiblyUnhandledRejection === "function") {
- CapturedTrace.possiblyUnhandledRejection(reason, this);
- }
- }
-};
-
-var contextStack = [];
-Promise.prototype._peekContext = function Promise$_peekContext() {
- var lastIndex = contextStack.length - 1;
- if (lastIndex >= 0) {
- return contextStack[lastIndex];
- }
- return void 0;
-
-};
-
-Promise.prototype._pushContext = function Promise$_pushContext() {
- if (!debugging) return;
- contextStack.push(this);
-};
-
-Promise.prototype._popContext = function Promise$_popContext() {
- if (!debugging) return;
- contextStack.pop();
-};
-
-function Promise$_CreatePromiseArray(
- promises, PromiseArrayConstructor, caller, boundTo) {
-
- var list = null;
- if (isArray(promises)) {
- list = promises;
- }
- else {
- list = Promise._cast(promises, caller, void 0);
- if (list !== promises) {
- list._setBoundTo(boundTo);
- }
- else if (!isPromise(list)) {
- list = null;
- }
- }
- if (list !== null) {
- return new PromiseArrayConstructor(
- list,
- typeof caller === "function"
- ? caller
- : Promise$_CreatePromiseArray,
- boundTo
- );
- }
- return {
- promise: function() {return apiRejection("expecting an array, a promise or a thenable");}
- };
-}
-
-var old = global.Promise;
-
-Promise.noConflict = function() {
- if (global.Promise === Promise) {
- global.Promise = old;
- }
- return Promise;
-};
-
-if (!CapturedTrace.isSupported()) {
- Promise.longStackTraces = function(){};
- debugging = false;
-}
-
Promise._makeSelfResolutionError = makeSelfResolutionError;
-require("./finally.js")(Promise, NEXT_FILTER);
-require("./direct_resolve.js")(Promise);
-require("./thenables.js")(Promise, INTERNAL);
-Promise.RangeError = RangeError;
-Promise.CancellationError = CancellationError;
-Promise.TimeoutError = TimeoutError;
-Promise.TypeError = TypeError;
-Promise.RejectionError = RejectionError;
-
-util.toFastProperties(Promise);
-util.toFastProperties(Promise.prototype);
-require('./timers.js')(Promise,INTERNAL);
-require('./synchronous_inspection.js')(Promise);
-require('./any.js')(Promise,Promise$_CreatePromiseArray,PromiseArray);
-require('./race.js')(Promise,INTERNAL);
-require('./call_get.js')(Promise);
-require('./filter.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection);
-require('./generators.js')(Promise,apiRejection,INTERNAL);
-require('./map.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection);
-require('./nodeify.js')(Promise);
-require('./promisify.js')(Promise,INTERNAL);
-require('./props.js')(Promise,PromiseArray);
-require('./reduce.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection,INTERNAL);
-require('./settle.js')(Promise,Promise$_CreatePromiseArray,PromiseArray);
-require('./some.js')(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection);
-require('./progress.js')(Promise,isPromiseArrayProxy);
-require('./cancel.js')(Promise,INTERNAL);
-
-Promise.prototype = Promise.prototype;
-return Promise;
-
-};
-
-},{"./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,"./errors.js":9,"./errors_api_rejection":10,"./filter.js":12,"./finally.js":13,"./generators.js":14,"./global.js":15,"./map.js":16,"./nodeify.js":17,"./progress.js":18,"./promise_array.js":20,"./promise_resolver.js":22,"./promisify.js":24,"./props.js":26,"./race.js":28,"./reduce.js":29,"./settle.js":31,"./some.js":33,"./synchronous_inspection.js":35,"./thenables.js":36,"./timers.js":37,"./util.js":38}],20:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+_dereq_("./method.js")(Promise, INTERNAL, tryConvertToPromise, apiRejection);
+_dereq_("./bind.js")(Promise, INTERNAL, tryConvertToPromise);
+_dereq_("./finally.js")(Promise, NEXT_FILTER, tryConvertToPromise);
+_dereq_("./direct_resolve.js")(Promise);
+_dereq_("./synchronous_inspection.js")(Promise);
+_dereq_("./join.js")(Promise, PromiseArray, tryConvertToPromise, INTERNAL);
+Promise.Promise = Promise;
+_dereq_('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL);
+_dereq_('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext);
+_dereq_('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise);
+_dereq_('./nodeify.js')(Promise);
+_dereq_('./cancel.js')(Promise);
+_dereq_('./promisify.js')(Promise, INTERNAL);
+_dereq_('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection);
+_dereq_('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection);
+_dereq_('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL);
+_dereq_('./settle.js')(Promise, PromiseArray);
+_dereq_('./call_get.js')(Promise);
+_dereq_('./some.js')(Promise, PromiseArray, apiRejection);
+_dereq_('./progress.js')(Promise, PromiseArray);
+_dereq_('./any.js')(Promise);
+_dereq_('./each.js')(Promise, INTERNAL);
+_dereq_('./timers.js')(Promise, INTERNAL);
+_dereq_('./filter.js')(Promise, INTERNAL);
+
+ util.toFastProperties(Promise);
+ util.toFastProperties(Promise.prototype);
+ function fillTypes(value) {
+ var p = new Promise(INTERNAL);
+ p._fulfillmentHandler0 = value;
+ p._rejectionHandler0 = value;
+ p._progressHandler0 = value;
+ p._promise0 = value;
+ p._receiver0 = value;
+ p._settledValue = value;
+ }
+ // Complete slack tracking, opt out of field-type tracking and
+ // stabilize map
+ fillTypes({a: 1});
+ fillTypes({b: 2});
+ fillTypes({c: 3});
+ fillTypes(1);
+ fillTypes(function(){});
+ fillTypes(undefined);
+ fillTypes(false);
+ fillTypes(new Promise(INTERNAL));
+ CapturedTrace.setBounds(async.firstLineError, util.lastLineError);
+ return Promise;
+
+};
+
+},{"./any.js":1,"./async.js":2,"./bind.js":3,"./call_get.js":5,"./cancel.js":6,"./captured_trace.js":7,"./catch_filter.js":8,"./context.js":9,"./debuggability.js":10,"./direct_resolve.js":11,"./each.js":12,"./errors.js":13,"./filter.js":15,"./finally.js":16,"./generators.js":17,"./join.js":18,"./map.js":19,"./method.js":20,"./nodeify.js":21,"./progress.js":22,"./promise_array.js":24,"./promise_resolver.js":25,"./promisify.js":26,"./props.js":27,"./race.js":29,"./reduce.js":30,"./settle.js":32,"./some.js":33,"./synchronous_inspection.js":34,"./thenables.js":35,"./timers.js":36,"./using.js":37,"./util.js":38}],24:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(Promise, INTERNAL) {
-var canAttach = require("./errors.js").canAttach;
-var util = require("./util.js");
-var async = require("./async.js");
-var hasOwn = {}.hasOwnProperty;
+module.exports = function(Promise, INTERNAL, tryConvertToPromise,
+ apiRejection) {
+var util = _dereq_("./util.js");
var isArray = util.isArray;
function toResolutionValue(val) {
switch(val) {
- case -1: return void 0;
case -2: return [];
case -3: return {};
}
}
-function PromiseArray(values, caller, boundTo) {
+function PromiseArray(values) {
var promise = this._promise = new Promise(INTERNAL);
- var parent = void 0;
- if (Promise.is(values)) {
+ var parent;
+ if (values instanceof Promise) {
parent = values;
- if (values._cancellable()) {
- promise._setCancellable();
- promise._cancellationParent = values;
- }
- if (values._isBound()) {
- promise._setBoundTo(boundTo);
- }
+ promise._propagateFrom(parent, 1 | 4);
}
- promise._setTrace(caller, parent);
this._values = values;
this._length = 0;
this._totalResolved = 0;
- this._init(void 0, -2);
+ this._init(undefined, -2);
}
-PromiseArray.PropertiesPromiseArray = function() {};
-
-PromiseArray.prototype.length = function PromiseArray$length() {
+PromiseArray.prototype.length = function () {
return this._length;
};
-PromiseArray.prototype.promise = function PromiseArray$promise() {
+PromiseArray.prototype.promise = function () {
return this._promise;
};
-PromiseArray.prototype._init =
-function PromiseArray$_init(_, resolveValueIfEmpty) {
- var values = this._values;
- if (Promise.is(values)) {
- if (values.isFulfilled()) {
- values = values._settledValue;
+PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
+ var values = tryConvertToPromise(this._values, this._promise);
+ if (values instanceof Promise) {
+ values = values._target();
+ this._values = values;
+ if (values._isFulfilled()) {
+ values = values._value();
if (!isArray(values)) {
- var err = new Promise.TypeError("expecting an array, a promise or a thenable");
+ var err = new Promise.TypeError("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a");
this.__hardReject__(err);
return;
}
- this._values = values;
- }
- else if (values.isPending()) {
+ } else if (values._isPending()) {
values._then(
- this._init,
+ init,
this._reject,
- void 0,
+ undefined,
this,
- resolveValueIfEmpty,
- this.constructor
+ resolveValueIfEmpty
);
return;
- }
- else {
- this._reject(values._settledValue);
+ } else {
+ this._reject(values._reason());
return;
}
+ } else if (!isArray(values)) {
+ this._promise._reject(apiRejection("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a")._reason());
+ return;
}
if (values.length === 0) {
- this._resolve(toResolutionValue(resolveValueIfEmpty));
- return;
- }
- var len = values.length;
- var newLen = len;
- var newValues;
- if (this instanceof PromiseArray.PropertiesPromiseArray) {
- newValues = this._values;
- }
- else {
- newValues = new Array(len);
- }
- var isDirectScanNeeded = false;
- for (var i = 0; i < len; ++i) {
- var promise = values[i];
- if (promise === void 0 && !hasOwn.call(values, i)) {
- newLen--;
- continue;
- }
- var maybePromise = Promise._cast(promise, void 0, void 0);
- if (maybePromise instanceof Promise) {
- if (maybePromise.isPending()) {
- maybePromise._proxyPromiseArray(this, i);
- }
- else {
- maybePromise._unsetRejectionIsUnhandled();
- isDirectScanNeeded = true;
- }
- }
- else {
- isDirectScanNeeded = true;
- }
- newValues[i] = maybePromise;
- }
- if (newLen === 0) {
- if (resolveValueIfEmpty === -2) {
- this._resolve(newValues);
+ if (resolveValueIfEmpty === -5) {
+ this._resolveEmptyArray();
}
else {
this._resolve(toResolutionValue(resolveValueIfEmpty));
}
return;
}
- this._values = newValues;
- this._length = newLen;
- if (isDirectScanNeeded) {
- var scanMethod = newLen === len
- ? this._scanDirectValues
- : this._scanDirectValuesHoled;
- async.invoke(scanMethod, this, len);
- }
-};
-
-PromiseArray.prototype._settlePromiseAt =
-function PromiseArray$_settlePromiseAt(index) {
- var value = this._values[index];
- if (!Promise.is(value)) {
- this._promiseFulfilled(value, index);
- }
- else if (value.isFulfilled()) {
- this._promiseFulfilled(value._settledValue, index);
- }
- else if (value.isRejected()) {
- this._promiseRejected(value._settledValue, index);
- }
-};
-
-PromiseArray.prototype._scanDirectValuesHoled =
-function PromiseArray$_scanDirectValuesHoled(len) {
- for (var i = 0; i < len; ++i) {
- if (this._isResolved()) {
- break;
- }
- if (hasOwn.call(this._values, i)) {
- this._settlePromiseAt(i);
- }
- }
-};
-
-PromiseArray.prototype._scanDirectValues =
-function PromiseArray$_scanDirectValues(len) {
+ var len = this.getActualLength(values.length);
+ this._length = len;
+ this._values = this.shouldCopyValues() ? new Array(len) : this._values;
+ var promise = this._promise;
for (var i = 0; i < len; ++i) {
- if (this._isResolved()) {
- break;
+ var isResolved = this._isResolved();
+ var maybePromise = tryConvertToPromise(values[i], promise);
+ if (maybePromise instanceof Promise) {
+ maybePromise = maybePromise._target();
+ if (isResolved) {
+ maybePromise._unsetRejectionIsUnhandled();
+ } else if (maybePromise._isPending()) {
+ maybePromise._proxyPromiseArray(this, i);
+ } else if (maybePromise._isFulfilled()) {
+ this._promiseFulfilled(maybePromise._value(), i);
+ } else {
+ this._promiseRejected(maybePromise._reason(), i);
+ }
+ } else if (!isResolved) {
+ this._promiseFulfilled(maybePromise, i);
}
- this._settlePromiseAt(i);
}
};
-PromiseArray.prototype._isResolved = function PromiseArray$_isResolved() {
+PromiseArray.prototype._isResolved = function () {
return this._values === null;
};
-PromiseArray.prototype._resolve = function PromiseArray$_resolve(value) {
+PromiseArray.prototype._resolve = function (value) {
this._values = null;
this._promise._fulfill(value);
};
PromiseArray.prototype.__hardReject__ =
-PromiseArray.prototype._reject = function PromiseArray$_reject(reason) {
+PromiseArray.prototype._reject = function (reason) {
this._values = null;
- var trace = canAttach(reason) ? reason : new Error(reason + "");
- this._promise._attachExtraTrace(trace);
- this._promise._reject(reason, trace);
+ this._promise._rejectCallback(reason, false, true);
};
-PromiseArray.prototype._promiseProgressed =
-function PromiseArray$_promiseProgressed(progressValue, index) {
- if (this._isResolved()) return;
+PromiseArray.prototype._promiseProgressed = function (progressValue, index) {
this._promise._progress({
index: index,
value: progressValue
@@ -5074,9 +4993,7 @@ function PromiseArray$_promiseProgressed(progressValue, index) {
};
-PromiseArray.prototype._promiseFulfilled =
-function PromiseArray$_promiseFulfilled(value, index) {
- if (this._isResolved()) return;
+PromiseArray.prototype._promiseFulfilled = function (value, index) {
this._values[index] = value;
var totalResolved = ++this._totalResolved;
if (totalResolved >= this._length) {
@@ -5084,169 +5001,88 @@ function PromiseArray$_promiseFulfilled(value, index) {
}
};
-PromiseArray.prototype._promiseRejected =
-function PromiseArray$_promiseRejected(reason, index) {
- if (this._isResolved()) return;
+PromiseArray.prototype._promiseRejected = function (reason, index) {
this._totalResolved++;
this._reject(reason);
};
-return PromiseArray;
-};
-
-},{"./async.js":2,"./errors.js":9,"./util.js":38}],21:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var TypeError = require("./errors.js").TypeError;
-
-function PromiseInspection(promise) {
- if (promise !== void 0) {
- this._bitField = promise._bitField;
- this._settledValue = promise.isResolved()
- ? promise._settledValue
- : void 0;
- }
- else {
- this._bitField = 0;
- this._settledValue = void 0;
- }
-}
-PromiseInspection.prototype.isFulfilled =
-function PromiseInspection$isFulfilled() {
- return (this._bitField & 268435456) > 0;
-};
-
-PromiseInspection.prototype.isRejected =
-function PromiseInspection$isRejected() {
- return (this._bitField & 134217728) > 0;
-};
-
-PromiseInspection.prototype.isPending = function PromiseInspection$isPending() {
- return (this._bitField & 402653184) === 0;
-};
-
-PromiseInspection.prototype.value = function PromiseInspection$value() {
- if (!this.isFulfilled()) {
- throw new TypeError("cannot get fulfillment value of a non-fulfilled promise");
- }
- return this._settledValue;
+PromiseArray.prototype.shouldCopyValues = function () {
+ return true;
};
-PromiseInspection.prototype.error = function PromiseInspection$error() {
- if (!this.isRejected()) {
- throw new TypeError("cannot get rejection reason of a non-rejected promise");
- }
- return this._settledValue;
+PromiseArray.prototype.getActualLength = function (len) {
+ return len;
};
-module.exports = PromiseInspection;
+return PromiseArray;
+};
-},{"./errors.js":9}],22:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./util.js":38}],25:[function(_dereq_,module,exports){
"use strict";
-var util = require("./util.js");
+var util = _dereq_("./util.js");
var maybeWrapAsError = util.maybeWrapAsError;
-var errors = require("./errors.js");
+var errors = _dereq_("./errors.js");
var TimeoutError = errors.TimeoutError;
-var RejectionError = errors.RejectionError;
-var async = require("./async.js");
+var OperationalError = errors.OperationalError;
var haveGetters = util.haveGetters;
-var es5 = require("./es5.js");
+var es5 = _dereq_("./es5.js");
function isUntypedError(obj) {
return obj instanceof Error &&
es5.getPrototypeOf(obj) === Error.prototype;
}
-function wrapAsRejectionError(obj) {
+var rErrorKey = /^(?:name|message|stack|cause)$/;
+function wrapAsOperationalError(obj) {
var ret;
if (isUntypedError(obj)) {
- ret = new RejectionError(obj);
- }
- else {
- ret = obj;
+ ret = new OperationalError(obj);
+ ret.name = obj.name;
+ ret.message = obj.message;
+ ret.stack = obj.stack;
+ var keys = es5.keys(obj);
+ for (var i = 0; i < keys.length; ++i) {
+ var key = keys[i];
+ if (!rErrorKey.test(key)) {
+ ret[key] = obj[key];
+ }
+ }
+ return ret;
}
- errors.markAsOriginatingFromRejection(ret);
- return ret;
+ util.markAsOriginatingFromRejection(obj);
+ return obj;
}
function nodebackForPromise(promise) {
- function PromiseResolver$_callback(err, value) {
+ return function(err, value) {
if (promise === null) return;
if (err) {
- var wrapped = wrapAsRejectionError(maybeWrapAsError(err));
+ var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
promise._attachExtraTrace(wrapped);
promise._reject(wrapped);
- }
- else {
- if (arguments.length > 2) {
- var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
- promise._fulfill(args);
- }
- else {
- promise._fulfill(value);
- }
+ } else if (arguments.length > 2) {
+ var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
+ promise._fulfill(args);
+ } else {
+ promise._fulfill(value);
}
promise = null;
- }
- return PromiseResolver$_callback;
+ };
}
var PromiseResolver;
if (!haveGetters) {
- PromiseResolver = function PromiseResolver(promise) {
+ PromiseResolver = function (promise) {
this.promise = promise;
this.asCallback = nodebackForPromise(promise);
this.callback = this.asCallback;
};
}
else {
- PromiseResolver = function PromiseResolver(promise) {
+ PromiseResolver = function (promise) {
this.promise = promise;
};
}
@@ -5262,415 +5098,266 @@ if (haveGetters) {
PromiseResolver._nodebackForPromise = nodebackForPromise;
-PromiseResolver.prototype.toString = function PromiseResolver$toString() {
+PromiseResolver.prototype.toString = function () {
return "[object PromiseResolver]";
};
PromiseResolver.prototype.resolve =
-PromiseResolver.prototype.fulfill = function PromiseResolver$resolve(value) {
- var promise = this.promise;
- if (promise._tryFollow(value)) {
- return;
+PromiseResolver.prototype.fulfill = function (value) {
+ if (!(this instanceof PromiseResolver)) {
+ throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\u000a\u000a See http://goo.gl/sdkXL9\u000a");
}
- async.invoke(promise._fulfill, promise, value);
+ this.promise._resolveCallback(value);
};
-PromiseResolver.prototype.reject = function PromiseResolver$reject(reason) {
- var promise = this.promise;
- errors.markAsOriginatingFromRejection(reason);
- var trace = errors.canAttach(reason) ? reason : new Error(reason + "");
- promise._attachExtraTrace(trace);
- async.invoke(promise._reject, promise, reason);
- if (trace !== reason) {
- async.invoke(this._setCarriedStackTrace, this, trace);
+PromiseResolver.prototype.reject = function (reason) {
+ if (!(this instanceof PromiseResolver)) {
+ throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\u000a\u000a See http://goo.gl/sdkXL9\u000a");
}
+ this.promise._rejectCallback(reason);
};
-PromiseResolver.prototype.progress =
-function PromiseResolver$progress(value) {
- async.invoke(this.promise._progress, this.promise, value);
+PromiseResolver.prototype.progress = function (value) {
+ if (!(this instanceof PromiseResolver)) {
+ throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\u000a\u000a See http://goo.gl/sdkXL9\u000a");
+ }
+ this.promise._progress(value);
};
-PromiseResolver.prototype.cancel = function PromiseResolver$cancel() {
- async.invoke(this.promise.cancel, this.promise, void 0);
+PromiseResolver.prototype.cancel = function (err) {
+ this.promise.cancel(err);
};
-PromiseResolver.prototype.timeout = function PromiseResolver$timeout() {
+PromiseResolver.prototype.timeout = function () {
this.reject(new TimeoutError("timeout"));
};
-PromiseResolver.prototype.isResolved = function PromiseResolver$isResolved() {
+PromiseResolver.prototype.isResolved = function () {
return this.promise.isResolved();
};
-PromiseResolver.prototype.toJSON = function PromiseResolver$toJSON() {
+PromiseResolver.prototype.toJSON = function () {
return this.promise.toJSON();
};
-PromiseResolver.prototype._setCarriedStackTrace =
-function PromiseResolver$_setCarriedStackTrace(trace) {
- if (this.promise.isRejected()) {
- this.promise._setCarriedStackTrace(trace);
- }
-};
-
module.exports = PromiseResolver;
-},{"./async.js":2,"./errors.js":9,"./es5.js":11,"./util.js":38}],23:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./errors.js":13,"./es5.js":14,"./util.js":38}],26:[function(_dereq_,module,exports){
"use strict";
module.exports = function(Promise, INTERNAL) {
-var errors = require("./errors.js");
-var TypeError = errors.TypeError;
-var util = require("./util.js");
-var isArray = util.isArray;
-var errorObj = util.errorObj;
-var tryCatch1 = util.tryCatch1;
-var yieldHandlers = [];
+var THIS = {};
+var util = _dereq_("./util.js");
+var nodebackForPromise = _dereq_("./promise_resolver.js")
+ ._nodebackForPromise;
+var withAppended = util.withAppended;
+var maybeWrapAsError = util.maybeWrapAsError;
+var canEvaluate = util.canEvaluate;
+var TypeError = _dereq_("./errors").TypeError;
+var defaultSuffix = "Async";
+var defaultPromisified = {__isPromisified__: true};
+var noCopyPropsPattern =
+ /^(?:length|name|arguments|caller|prototype|__isPromisified__)$/;
+var defaultFilter = function(name, func) {
+ return util.isIdentifier(name) &&
+ name.charAt(0) !== "_" &&
+ !util.isClass(func);
+};
+
+function propsFilter(key) {
+ return !noCopyPropsPattern.test(key);
+}
-function promiseFromYieldHandler(value) {
- var _yieldHandlers = yieldHandlers;
- var _errorObj = errorObj;
- var _Promise = Promise;
- var len = _yieldHandlers.length;
- for (var i = 0; i < len; ++i) {
- var result = tryCatch1(_yieldHandlers[i], void 0, value);
- if (result === _errorObj) {
- return _Promise.reject(_errorObj.e);
- }
- var maybePromise = _Promise._cast(result,
- promiseFromYieldHandler, void 0);
- if (maybePromise instanceof _Promise) return maybePromise;
+function isPromisified(fn) {
+ try {
+ return fn.__isPromisified__ === true;
+ }
+ catch (e) {
+ return false;
}
- return null;
}
-function PromiseSpawn(generatorFunction, receiver, caller) {
- var promise = this._promise = new Promise(INTERNAL);
- promise._setTrace(caller, void 0);
- this._generatorFunction = generatorFunction;
- this._receiver = receiver;
- this._generator = void 0;
+function hasPromisified(obj, key, suffix) {
+ var val = util.getDataPropertyOrDefault(obj, key + suffix,
+ defaultPromisified);
+ return val ? isPromisified(val) : false;
}
-
-PromiseSpawn.prototype.promise = function PromiseSpawn$promise() {
- return this._promise;
-};
-
-PromiseSpawn.prototype._run = function PromiseSpawn$_run() {
- this._generator = this._generatorFunction.call(this._receiver);
- this._receiver =
- this._generatorFunction = void 0;
- this._next(void 0);
-};
-
-PromiseSpawn.prototype._continue = function PromiseSpawn$_continue(result) {
- if (result === errorObj) {
- this._generator = void 0;
- var trace = errors.canAttach(result.e)
- ? result.e : new Error(result.e + "");
- this._promise._attachExtraTrace(trace);
- this._promise._reject(result.e, trace);
- return;
- }
-
- var value = result.value;
- if (result.done === true) {
- this._generator = void 0;
- if (!this._promise._tryFollow(value)) {
- this._promise._fulfill(value);
- }
- }
- else {
- var maybePromise = Promise._cast(value, PromiseSpawn$_continue, void 0);
- if (!(maybePromise instanceof Promise)) {
- if (isArray(maybePromise)) {
- maybePromise = Promise.all(maybePromise);
- }
- else {
- maybePromise = promiseFromYieldHandler(maybePromise);
- }
- if (maybePromise === null) {
- this._throw(new TypeError("A value was yielded that could not be treated as a promise"));
- return;
+function checkValid(ret, suffix, suffixRegexp) {
+ for (var i = 0; i < ret.length; i += 2) {
+ var key = ret[i];
+ if (suffixRegexp.test(key)) {
+ var keyWithoutAsyncSuffix = key.replace(suffixRegexp, "");
+ for (var j = 0; j < ret.length; j += 2) {
+ if (ret[j] === keyWithoutAsyncSuffix) {
+ throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\u000a\u000a See http://goo.gl/iWrZbw\u000a"
+ .replace("%s", suffix));
+ }
}
}
- maybePromise._then(
- this._next,
- this._throw,
- void 0,
- this,
- null,
- void 0
- );
}
-};
-
-PromiseSpawn.prototype._throw = function PromiseSpawn$_throw(reason) {
- if (errors.canAttach(reason))
- this._promise._attachExtraTrace(reason);
- this._continue(
- tryCatch1(this._generator["throw"], this._generator, reason)
- );
-};
-
-PromiseSpawn.prototype._next = function PromiseSpawn$_next(value) {
- this._continue(
- tryCatch1(this._generator.next, this._generator, value)
- );
-};
+}
-PromiseSpawn.addYieldHandler = function PromiseSpawn$AddYieldHandler(fn) {
- if (typeof fn !== "function") throw new TypeError("fn must be a function");
- yieldHandlers.push(fn);
-};
+function promisifiableMethods(obj, suffix, suffixRegexp, filter) {
+ var keys = util.inheritedDataKeys(obj);
+ var ret = [];
+ for (var i = 0; i < keys.length; ++i) {
+ var key = keys[i];
+ var value = obj[key];
+ var passesDefaultFilter = filter === defaultFilter
+ ? true : defaultFilter(key, value, obj);
+ if (typeof value === "function" &&
+ !isPromisified(value) &&
+ !hasPromisified(obj, key, suffix) &&
+ filter(key, value, obj, passesDefaultFilter)) {
+ ret.push(key, value);
+ }
+ }
+ checkValid(ret, suffix, suffixRegexp);
+ return ret;
+}
-return PromiseSpawn;
+var escapeIdentRegex = function(str) {
+ return str.replace(/([$])/, "\\$");
};
-},{"./errors.js":9,"./util.js":38}],24:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, INTERNAL) {
-var THIS = {};
-var util = require("./util.js");
-var es5 = require("./es5.js");
-var nodebackForPromise = require("./promise_resolver.js")
- ._nodebackForPromise;
-var withAppended = util.withAppended;
-var maybeWrapAsError = util.maybeWrapAsError;
-var canEvaluate = util.canEvaluate;
-var notEnumerableProp = util.notEnumerableProp;
-var deprecated = util.deprecated;
-var roriginal = new RegExp("__beforePromisified__" + "$");
-var hasProp = {}.hasOwnProperty;
-function isPromisified(fn) {
- return fn.__isPromisified__ === true;
-}
-var inheritedMethods = (function() {
- if (es5.isES5) {
- var create = Object.create;
- var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
- return function(cur) {
- var original = cur;
- var ret = [];
- var visitedKeys = create(null);
- while (cur !== null) {
- var keys = es5.keys(cur);
- for (var i = 0, len = keys.length; i < len; ++i) {
- var key = keys[i];
- if (visitedKeys[key] ||
- roriginal.test(key) ||
- hasProp.call(original, key + "__beforePromisified__")
- ) {
- continue;
- }
- visitedKeys[key] = true;
- var desc = getOwnPropertyDescriptor(cur, key);
- if (desc != null &&
- typeof desc.value === "function" &&
- !isPromisified(desc.value)) {
- ret.push(key, desc.value);
- }
- }
- cur = es5.getPrototypeOf(cur);
- }
- return ret;
- };
- }
- else {
- return function(obj) {
- var ret = [];
- /*jshint forin:false */
- for (var key in obj) {
- if (roriginal.test(key) ||
- hasProp.call(obj, key + "__beforePromisified__")) {
- continue;
- }
- var fn = obj[key];
- if (typeof fn === "function" &&
- !isPromisified(fn)) {
- ret.push(key, fn);
- }
- }
- return ret;
- };
- }
-})();
-
-function switchCaseArgumentOrder(likelyArgumentCount) {
+var makeNodePromisifiedEval;
+if (!true) {
+var switchCaseArgumentOrder = function(likelyArgumentCount) {
var ret = [likelyArgumentCount];
- var min = Math.max(0, likelyArgumentCount - 1 - 5);
+ var min = Math.max(0, likelyArgumentCount - 1 - 3);
for(var i = likelyArgumentCount - 1; i >= min; --i) {
- if (i === likelyArgumentCount) continue;
ret.push(i);
}
- for(var i = likelyArgumentCount + 1; i <= 5; ++i) {
+ for(var i = likelyArgumentCount + 1; i <= 3; ++i) {
ret.push(i);
}
return ret;
-}
+};
-function parameterDeclaration(parameterCount) {
- var ret = new Array(parameterCount);
- for(var i = 0; i < ret.length; ++i) {
- ret[i] = "_arg" + i;
- }
- return ret.join(", ");
-}
+var argumentSequence = function(argumentCount) {
+ return util.filledRange(argumentCount, "_arg", "");
+};
+
+var parameterDeclaration = function(parameterCount) {
+ return util.filledRange(
+ Math.max(parameterCount, 3), "_arg", "");
+};
-function parameterCount(fn) {
+var parameterCount = function(fn) {
if (typeof fn.length === "number") {
return Math.max(Math.min(fn.length, 1023 + 1), 0);
}
return 0;
-}
-
-function propertyAccess(id) {
- var rident = /^[a-z$_][a-z$_0-9]*$/i;
-
- if (rident.test(id)) {
- return "." + id;
- }
- else return "['" + id.replace(/(['\\])/g, "\\$1") + "']";
-}
+};
-function makeNodePromisifiedEval(callback, receiver, originalName, fn) {
+makeNodePromisifiedEval =
+function(callback, receiver, originalName, fn) {
var newParameterCount = Math.max(0, parameterCount(fn) - 1);
var argumentOrder = switchCaseArgumentOrder(newParameterCount);
-
- var callbackName = (typeof originalName === "string" ?
- originalName + "Async" :
- "promisified");
+ var shouldProxyThis = typeof callback === "string" || receiver === THIS;
function generateCallForArgumentCount(count) {
- var args = new Array(count);
- for (var i = 0, len = args.length; i < len; ++i) {
- args[i] = "arguments[" + i + "]";
- }
- var comma = count > 0 ? "," : "";
-
- if (typeof callback === "string" &&
- receiver === THIS) {
- return "this" + propertyAccess(callback) + "("+args.join(",") +
- comma +" fn);"+
- "break;";
+ var args = argumentSequence(count).join(", ");
+ var comma = count > 0 ? ", " : "";
+ var ret;
+ if (shouldProxyThis) {
+ ret = "ret = callback.call(this, {{args}}, nodeback); break;\n";
+ } else {
+ ret = receiver === undefined
+ ? "ret = callback({{args}}, nodeback); break;\n"
+ : "ret = callback.call(receiver, {{args}}, nodeback); break;\n";
}
- return (receiver === void 0
- ? "callback("+args.join(",")+ comma +" fn);"
- : "callback.call("+(receiver === THIS
- ? "this"
- : "receiver")+", "+args.join(",") + comma + " fn);") +
- "break;";
+ return ret.replace("{{args}}", args).replace(", ", comma);
}
function generateArgumentSwitchCase() {
var ret = "";
- for(var i = 0; i < argumentOrder.length; ++i) {
+ for (var i = 0; i < argumentOrder.length; ++i) {
ret += "case " + argumentOrder[i] +":" +
generateCallForArgumentCount(argumentOrder[i]);
}
- ret += "default: var args = new Array(len + 1);" +
- "var i = 0;" +
- "for (var i = 0; i < len; ++i) { " +
- " args[i] = arguments[i];" +
- "}" +
- "args[i] = fn;" +
-
- (typeof callback === "string"
- ? "this" + propertyAccess(callback) + ".apply("
- : "callback.apply(") +
- (receiver === THIS ? "this" : "receiver") +
- ", args); break;";
+ ret += " \n\
+ default: \n\
+ var args = new Array(len + 1); \n\
+ var i = 0; \n\
+ for (var i = 0; i < len; ++i) { \n\
+ args[i] = arguments[i]; \n\
+ } \n\
+ args[i] = nodeback; \n\
+ [CodeForCall] \n\
+ break; \n\
+ ".replace("[CodeForCall]", (shouldProxyThis
+ ? "ret = callback.apply(this, args);\n"
+ : "ret = callback.apply(receiver, args);\n"));
return ret;
}
- return new Function("Promise", "callback", "receiver",
- "withAppended", "maybeWrapAsError", "nodebackForPromise",
- "INTERNAL",
- "var ret = function " + callbackName +
- "(" + parameterDeclaration(newParameterCount) + ") {\"use strict\";" +
- "var len = arguments.length;" +
- "var promise = new Promise(INTERNAL);"+
- "promise._setTrace(" + callbackName + ", void 0);" +
- "var fn = nodebackForPromise(promise);"+
- "try {" +
- "switch(len) {" +
- generateArgumentSwitchCase() +
- "}" +
- "}" +
- "catch(e){ " +
- "var wrapped = maybeWrapAsError(e);" +
- "promise._attachExtraTrace(wrapped);" +
- "promise._reject(wrapped);" +
- "}" +
- "return promise;" +
- "" +
- "}; ret.__isPromisified__ = true; return ret;"
- )(Promise, callback, receiver, withAppended,
- maybeWrapAsError, nodebackForPromise, INTERNAL);
+ var getFunctionCode = typeof callback === "string"
+ ? ("this != null ? this['"+callback+"'] : fn")
+ : "fn";
+
+ return new Function("Promise",
+ "fn",
+ "receiver",
+ "withAppended",
+ "maybeWrapAsError",
+ "nodebackForPromise",
+ "tryCatch",
+ "errorObj",
+ "INTERNAL","'use strict'; \n\
+ var ret = function (Parameters) { \n\
+ 'use strict'; \n\
+ var len = arguments.length; \n\
+ var promise = new Promise(INTERNAL); \n\
+ promise._captureStackTrace(); \n\
+ var nodeback = nodebackForPromise(promise); \n\
+ var ret; \n\
+ var callback = tryCatch([GetFunctionCode]); \n\
+ switch(len) { \n\
+ [CodeForSwitchCase] \n\
+ } \n\
+ if (ret === errorObj) { \n\
+ promise._rejectCallback(maybeWrapAsError(ret.e), true, true);\n\
+ } \n\
+ return promise; \n\
+ }; \n\
+ ret.__isPromisified__ = true; \n\
+ return ret; \n\
+ "
+ .replace("Parameters", parameterDeclaration(newParameterCount))
+ .replace("[CodeForSwitchCase]", generateArgumentSwitchCase())
+ .replace("[GetFunctionCode]", getFunctionCode))(
+ Promise,
+ fn,
+ receiver,
+ withAppended,
+ maybeWrapAsError,
+ nodebackForPromise,
+ util.tryCatch,
+ util.errorObj,
+ INTERNAL
+ );
+};
}
-function makeNodePromisifiedClosure(callback, receiver) {
+function makeNodePromisifiedClosure(callback, receiver, _, fn) {
+ var defaultThis = (function() {return this;})();
+ var method = callback;
+ if (typeof method === "string") {
+ callback = fn;
+ }
function promisified() {
var _receiver = receiver;
if (receiver === THIS) _receiver = this;
- if (typeof callback === "string") {
- callback = _receiver[callback];
- }
var promise = new Promise(INTERNAL);
- promise._setTrace(promisified, void 0);
+ promise._captureStackTrace();
+ var cb = typeof method === "string" && this !== defaultThis
+ ? this[method] : callback;
var fn = nodebackForPromise(promise);
try {
- callback.apply(_receiver, withAppended(arguments, fn));
- }
- catch(e) {
- var wrapped = maybeWrapAsError(e);
- promise._attachExtraTrace(wrapped);
- promise._reject(wrapped);
+ cb.apply(_receiver, withAppended(arguments, fn));
+ } catch(e) {
+ promise._rejectCallback(maybeWrapAsError(e), true, true);
}
return promise;
}
@@ -5682,105 +5369,98 @@ var makeNodePromisified = canEvaluate
? makeNodePromisifiedEval
: makeNodePromisifiedClosure;
-function _promisify(callback, receiver, isAll) {
- if (isAll) {
- var methods = inheritedMethods(callback);
- for (var i = 0, len = methods.length; i < len; i+= 2) {
- var key = methods[i];
- var fn = methods[i+1];
- var originalKey = key + "__beforePromisified__";
- var promisifiedKey = key + "Async";
- notEnumerableProp(callback, originalKey, fn);
- callback[promisifiedKey] =
- makeNodePromisified(originalKey, THIS,
- key, fn);
- }
- util.toFastProperties(callback);
- return callback;
- }
- else {
- return makeNodePromisified(callback, receiver, void 0, callback);
+function promisifyAll(obj, suffix, filter, promisifier) {
+ var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$");
+ var methods =
+ promisifiableMethods(obj, suffix, suffixRegexp, filter);
+
+ for (var i = 0, len = methods.length; i < len; i+= 2) {
+ var key = methods[i];
+ var fn = methods[i+1];
+ var promisifiedKey = key + suffix;
+ obj[promisifiedKey] = promisifier === makeNodePromisified
+ ? makeNodePromisified(key, THIS, key, fn, suffix)
+ : promisifier(fn, function() {
+ return makeNodePromisified(key, THIS, key, fn, suffix);
+ });
}
+ util.toFastProperties(obj);
+ return obj;
}
-Promise.promisify = function Promise$Promisify(fn, receiver) {
- if (typeof fn === "object" && fn !== null) {
- deprecated("Promise.promisify for promisifying entire objects is deprecated. Use Promise.promisifyAll instead.");
- return _promisify(fn, receiver, true);
- }
+function promisify(callback, receiver) {
+ return makeNodePromisified(callback, receiver, undefined, callback);
+}
+
+Promise.promisify = function (fn, receiver) {
if (typeof fn !== "function") {
- throw new TypeError("fn must be a function");
+ throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
}
if (isPromisified(fn)) {
return fn;
}
- return _promisify(
- fn,
- arguments.length < 2 ? THIS : receiver,
- false);
-};
-
-Promise.promisifyAll = function Promise$PromisifyAll(target) {
- if (typeof target !== "function" && typeof target !== "object") {
- throw new TypeError("the target of promisifyAll must be an object or a function");
- }
- return _promisify(target, void 0, true);
-};
+ var ret = promisify(fn, arguments.length < 2 ? THIS : receiver);
+ util.copyDescriptors(fn, ret, propsFilter);
+ return ret;
};
-
-},{"./es5.js":11,"./promise_resolver.js":22,"./util.js":38}],25:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, PromiseArray) {
-var util = require("./util.js");
-var inherits = util.inherits;
-var es5 = require("./es5.js");
-
-function PropertiesPromiseArray(obj, caller, boundTo) {
- var keys = es5.keys(obj);
- var values = new Array(keys.length);
- for (var i = 0, len = values.length; i < len; ++i) {
- values[i] = obj[keys[i]];
+Promise.promisifyAll = function (target, options) {
+ if (typeof target !== "function" && typeof target !== "object") {
+ throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/9ITlV0\u000a");
+ }
+ options = Object(options);
+ var suffix = options.suffix;
+ if (typeof suffix !== "string") suffix = defaultSuffix;
+ var filter = options.filter;
+ if (typeof filter !== "function") filter = defaultFilter;
+ var promisifier = options.promisifier;
+ if (typeof promisifier !== "function") promisifier = makeNodePromisified;
+
+ if (!util.isIdentifier(suffix)) {
+ throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/8FZo5V\u000a");
}
- this.constructor$(values, caller, boundTo);
- if (!this._isResolved()) {
- for (var i = 0, len = keys.length; i < len; ++i) {
- values.push(keys[i]);
+
+ var keys = util.inheritedDataKeys(target);
+ for (var i = 0; i < keys.length; ++i) {
+ var value = target[keys[i]];
+ if (keys[i] !== "constructor" &&
+ util.isClass(value)) {
+ promisifyAll(value.prototype, suffix, filter, promisifier);
+ promisifyAll(value, suffix, filter, promisifier);
}
}
+
+ return promisifyAll(target, suffix, filter, promisifier);
+};
+};
+
+
+},{"./errors":13,"./promise_resolver.js":25,"./util.js":38}],27:[function(_dereq_,module,exports){
+"use strict";
+module.exports = function(
+ Promise, PromiseArray, tryConvertToPromise, apiRejection) {
+var util = _dereq_("./util.js");
+var isObject = util.isObject;
+var es5 = _dereq_("./es5.js");
+
+function PropertiesPromiseArray(obj) {
+ var keys = es5.keys(obj);
+ var len = keys.length;
+ var values = new Array(len * 2);
+ for (var i = 0; i < len; ++i) {
+ var key = keys[i];
+ values[i] = obj[key];
+ values[i + len] = key;
+ }
+ this.constructor$(values);
}
-inherits(PropertiesPromiseArray, PromiseArray);
+util.inherits(PropertiesPromiseArray, PromiseArray);
-PropertiesPromiseArray.prototype._init =
-function PropertiesPromiseArray$_init() {
- this._init$(void 0, -3) ;
+PropertiesPromiseArray.prototype._init = function () {
+ this._init$(undefined, -3) ;
};
-PropertiesPromiseArray.prototype._promiseFulfilled =
-function PropertiesPromiseArray$_promiseFulfilled(value, index) {
- if (this._isResolved()) return;
+PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {
this._values[index] = value;
var totalResolved = ++this._totalResolved;
if (totalResolved >= this._length) {
@@ -5793,150 +5473,69 @@ function PropertiesPromiseArray$_promiseFulfilled(value, index) {
}
};
-PropertiesPromiseArray.prototype._promiseProgressed =
-function PropertiesPromiseArray$_promiseProgressed(value, index) {
- if (this._isResolved()) return;
-
+PropertiesPromiseArray.prototype._promiseProgressed = function (value, index) {
this._promise._progress({
key: this._values[index + this.length()],
value: value
});
};
-PromiseArray.PropertiesPromiseArray = PropertiesPromiseArray;
+PropertiesPromiseArray.prototype.shouldCopyValues = function () {
+ return false;
+};
-return PropertiesPromiseArray;
+PropertiesPromiseArray.prototype.getActualLength = function (len) {
+ return len >> 1;
};
-},{"./es5.js":11,"./util.js":38}],26:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, PromiseArray) {
- var PropertiesPromiseArray = require("./properties_promise_array.js")(
- Promise, PromiseArray);
- var util = require("./util.js");
- var apiRejection = require("./errors_api_rejection")(Promise);
- var isObject = util.isObject;
+function props(promises) {
+ var ret;
+ var castValue = tryConvertToPromise(promises);
- function Promise$_Props(promises, useBound, caller) {
- var ret;
- var castValue = Promise._cast(promises, caller, void 0);
+ if (!isObject(castValue)) {
+ return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/OsFKC8\u000a");
+ } else if (castValue instanceof Promise) {
+ ret = castValue._then(
+ Promise.props, undefined, undefined, undefined, undefined);
+ } else {
+ ret = new PropertiesPromiseArray(castValue).promise();
+ }
- if (!isObject(castValue)) {
- return apiRejection("cannot await properties of a non-object");
- }
- else if (Promise.is(castValue)) {
- ret = castValue._then(Promise.props, void 0, void 0,
- void 0, void 0, caller);
- }
- else {
- ret = new PropertiesPromiseArray(
- castValue,
- caller,
- useBound === true && castValue._isBound()
- ? castValue._boundTo
- : void 0
- ).promise();
- useBound = false;
- }
- if (useBound === true && castValue._isBound()) {
- ret._setBoundTo(castValue._boundTo);
- }
- return ret;
+ if (castValue instanceof Promise) {
+ ret._propagateFrom(castValue, 4);
}
+ return ret;
+}
- Promise.prototype.props = function Promise$props() {
- return Promise$_Props(this, true, this.props);
- };
+Promise.prototype.props = function () {
+ return props(this);
+};
- Promise.props = function Promise$Props(promises) {
- return Promise$_Props(promises, false, Promise.props);
- };
+Promise.props = function (promises) {
+ return props(promises);
+};
};
-},{"./errors_api_rejection":10,"./properties_promise_array.js":25,"./util.js":38}],27:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./es5.js":14,"./util.js":38}],28:[function(_dereq_,module,exports){
"use strict";
-function arrayCopy(src, srcIndex, dst, dstIndex, len) {
+function arrayMove(src, srcIndex, dst, dstIndex, len) {
for (var j = 0; j < len; ++j) {
dst[j + dstIndex] = src[j + srcIndex];
+ src[j + srcIndex] = void 0;
}
}
-function pow2AtLeast(n) {
- n = n >>> 0;
- n = n - 1;
- n = n | (n >> 1);
- n = n | (n >> 2);
- n = n | (n >> 4);
- n = n | (n >> 8);
- n = n | (n >> 16);
- return n + 1;
-}
-
-function getCapacity(capacity) {
- if (typeof capacity !== "number") return 16;
- return pow2AtLeast(
- Math.min(
- Math.max(16, capacity), 1073741824)
- );
-}
-
function Queue(capacity) {
- this._capacity = getCapacity(capacity);
+ this._capacity = capacity;
this._length = 0;
this._front = 0;
- this._makeCapacity();
}
-Queue.prototype._willBeOverCapacity =
-function Queue$_willBeOverCapacity(size) {
+Queue.prototype._willBeOverCapacity = function (size) {
return this._capacity < size;
};
-Queue.prototype._pushOne = function Queue$_pushOne(arg) {
+Queue.prototype._pushOne = function (arg) {
var length = this.length();
this._checkCapacity(length + 1);
var i = (this._front + length) & (this._capacity - 1);
@@ -5944,7 +5543,24 @@ Queue.prototype._pushOne = function Queue$_pushOne(arg) {
this._length = length + 1;
};
-Queue.prototype.push = function Queue$push(fn, receiver, arg) {
+Queue.prototype._unshiftOne = function(value) {
+ var capacity = this._capacity;
+ this._checkCapacity(this.length() + 1);
+ var front = this._front;
+ var i = (((( front - 1 ) &
+ ( capacity - 1) ) ^ capacity ) - capacity );
+ this[i] = value;
+ this._front = i;
+ this._length = this.length() + 1;
+};
+
+Queue.prototype.unshift = function(fn, receiver, arg) {
+ this._unshiftOne(arg);
+ this._unshiftOne(receiver);
+ this._unshiftOne(fn);
+};
+
+Queue.prototype.push = function (fn, receiver, arg) {
var length = this.length() + 3;
if (this._willBeOverCapacity(length)) {
this._pushOne(fn);
@@ -5961,528 +5577,272 @@ Queue.prototype.push = function Queue$push(fn, receiver, arg) {
this._length = length;
};
-Queue.prototype.shift = function Queue$shift() {
+Queue.prototype.shift = function () {
var front = this._front,
ret = this[front];
- this[front] = void 0;
+ this[front] = undefined;
this._front = (front + 1) & (this._capacity - 1);
this._length--;
return ret;
};
-Queue.prototype.length = function Queue$length() {
+Queue.prototype.length = function () {
return this._length;
};
-Queue.prototype._makeCapacity = function Queue$_makeCapacity() {
- var len = this._capacity;
- for (var i = 0; i < len; ++i) {
- this[i] = void 0;
- }
-};
-
-Queue.prototype._checkCapacity = function Queue$_checkCapacity(size) {
+Queue.prototype._checkCapacity = function (size) {
if (this._capacity < size) {
- this._resizeTo(this._capacity << 3);
+ this._resizeTo(this._capacity << 1);
}
};
-Queue.prototype._resizeTo = function Queue$_resizeTo(capacity) {
- var oldFront = this._front;
+Queue.prototype._resizeTo = function (capacity) {
var oldCapacity = this._capacity;
- var oldQueue = new Array(oldCapacity);
- var length = this.length();
-
- arrayCopy(this, 0, oldQueue, 0, oldCapacity);
this._capacity = capacity;
- this._makeCapacity();
- this._front = 0;
- if (oldFront + length <= oldCapacity) {
- arrayCopy(oldQueue, oldFront, this, 0, length);
- }
- else { var lengthBeforeWrapping =
- length - ((oldFront + length) & (oldCapacity - 1));
-
- arrayCopy(oldQueue, oldFront, this, 0, lengthBeforeWrapping);
- arrayCopy(oldQueue, 0, this, lengthBeforeWrapping,
- length - lengthBeforeWrapping);
- }
+ var front = this._front;
+ var length = this._length;
+ var moveItemsCount = (front + length) & (oldCapacity - 1);
+ arrayMove(this, 0, this, oldCapacity, moveItemsCount);
};
module.exports = Queue;
-},{}],28:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{}],29:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(Promise, INTERNAL) {
- var apiRejection = require("./errors_api_rejection.js")(Promise);
- var isArray = require("./util.js").isArray;
-
- var raceLater = function Promise$_raceLater(promise) {
- return promise.then(function Promise$_lateRacer(array) {
- return Promise$_Race(array, Promise$_lateRacer, promise);
- });
- };
+module.exports = function(
+ Promise, INTERNAL, tryConvertToPromise, apiRejection) {
+var isArray = _dereq_("./util.js").isArray;
- var hasOwn = {}.hasOwnProperty;
- function Promise$_Race(promises, caller, parent) {
- var maybePromise = Promise._cast(promises, caller, void 0);
+var raceLater = function (promise) {
+ return promise.then(function(array) {
+ return race(array, promise);
+ });
+};
- if (Promise.is(maybePromise)) {
- return raceLater(maybePromise);
- }
- else if (!isArray(promises)) {
- return apiRejection("expecting an array, a promise or a thenable");
- }
+function race(promises, parent) {
+ var maybePromise = tryConvertToPromise(promises);
- var ret = new Promise(INTERNAL);
- ret._setTrace(caller, parent);
- if (parent !== void 0) {
- if (parent._isBound()) {
- ret._setBoundTo(parent._boundTo);
- }
- if (parent._cancellable()) {
- ret._setCancellable();
- ret._cancellationParent = parent;
- }
- }
- var fulfill = ret._fulfill;
- var reject = ret._reject;
- for (var i = 0, len = promises.length; i < len; ++i) {
- var val = promises[i];
+ if (maybePromise instanceof Promise) {
+ return raceLater(maybePromise);
+ } else if (!isArray(promises)) {
+ return apiRejection("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a");
+ }
- if (val === void 0 && !(hasOwn.call(promises, i))) {
- continue;
- }
+ var ret = new Promise(INTERNAL);
+ if (parent !== undefined) {
+ ret._propagateFrom(parent, 4 | 1);
+ }
+ var fulfill = ret._fulfill;
+ var reject = ret._reject;
+ for (var i = 0, len = promises.length; i < len; ++i) {
+ var val = promises[i];
- Promise.cast(val)._then(
- fulfill,
- reject,
- void 0,
- ret,
- null,
- caller
- );
+ if (val === undefined && !(i in promises)) {
+ continue;
}
- return ret;
+
+ Promise.cast(val)._then(fulfill, reject, undefined, ret, null);
}
+ return ret;
+}
- Promise.race = function Promise$Race(promises) {
- return Promise$_Race(promises, Promise.race, void 0);
- };
+Promise.race = function (promises) {
+ return race(promises, undefined);
+};
- Promise.prototype.race = function Promise$race() {
- return Promise$_Race(this, this.race, void 0);
- };
+Promise.prototype.race = function () {
+ return race(this, undefined);
+};
};
-},{"./errors_api_rejection.js":10,"./util.js":38}],29:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./util.js":38}],30:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(
- Promise, Promise$_CreatePromiseArray,
- PromiseArray, apiRejection, INTERNAL) {
-
- function Reduction(callback, index, accum, items, receiver) {
- this.promise = new Promise(INTERNAL);
- this.index = index;
- this.length = items.length;
- this.items = items;
- this.callback = callback;
- this.receiver = receiver;
- this.accum = accum;
- }
-
- Reduction.prototype.reject = function Reduction$reject(e) {
- this.promise._reject(e);
- };
-
- Reduction.prototype.fulfill = function Reduction$fulfill(value, index) {
- this.accum = value;
- this.index = index + 1;
- this.iterate();
- };
-
- Reduction.prototype.iterate = function Reduction$iterate() {
- var i = this.index;
- var len = this.length;
- var items = this.items;
- var result = this.accum;
- var receiver = this.receiver;
- var callback = this.callback;
- var iterate = this.iterate;
-
- for(; i < len; ++i) {
- result = Promise._cast(
- callback.call(
- receiver,
- result,
- items[i],
- i,
- len
- ),
- iterate,
- void 0
- );
-
- if (result instanceof Promise) {
- result._then(
- this.fulfill, this.reject, void 0, this, i, iterate);
- return;
- }
- }
- this.promise._fulfill(result);
- };
-
- function Promise$_reducer(fulfilleds, initialValue) {
- var fn = this;
- var receiver = void 0;
- if (typeof fn !== "function") {
- receiver = fn.receiver;
- fn = fn.fn;
- }
- var len = fulfilleds.length;
- var accum = void 0;
- var startIndex = 0;
-
- if (initialValue !== void 0) {
- accum = initialValue;
- startIndex = 0;
- }
- else {
- startIndex = 1;
- if (len > 0) accum = fulfilleds[0];
+module.exports = function(Promise,
+ PromiseArray,
+ apiRejection,
+ tryConvertToPromise,
+ INTERNAL) {
+var util = _dereq_("./util.js");
+var tryCatch = util.tryCatch;
+var errorObj = util.errorObj;
+function ReductionPromiseArray(promises, fn, accum, _each) {
+ this.constructor$(promises);
+ this._promise._captureStackTrace();
+ this._preservedValues = _each === INTERNAL ? [] : null;
+ this._zerothIsAccum = (accum === undefined);
+ this._gotAccum = false;
+ this._reducingIndex = (this._zerothIsAccum ? 1 : 0);
+ this._valuesPhase = undefined;
+ var maybePromise = tryConvertToPromise(accum, this._promise);
+ var rejected = false;
+ var isPromise = maybePromise instanceof Promise;
+ if (isPromise) {
+ maybePromise = maybePromise._target();
+ if (maybePromise._isPending()) {
+ maybePromise._proxyPromiseArray(this, -1);
+ } else if (maybePromise._isFulfilled()) {
+ accum = maybePromise._value();
+ this._gotAccum = true;
+ } else {
+ this._reject(maybePromise._reason());
+ rejected = true;
}
- var i = startIndex;
+ }
+ if (!(isPromise || this._zerothIsAccum)) this._gotAccum = true;
+ this._callback = fn;
+ this._accum = accum;
+ if (!rejected) this._init$(undefined, -5);
+}
+util.inherits(ReductionPromiseArray, PromiseArray);
- if (i >= len) {
- return accum;
- }
+ReductionPromiseArray.prototype._init = function () {};
- var reduction = new Reduction(fn, i, accum, fulfilleds, receiver);
- reduction.iterate();
- return reduction.promise;
+ReductionPromiseArray.prototype._resolveEmptyArray = function () {
+ if (this._gotAccum || this._zerothIsAccum) {
+ this._resolve(this._preservedValues !== null
+ ? [] : this._accum);
}
+};
- function Promise$_unpackReducer(fulfilleds) {
- var fn = this.fn;
- var initialValue = this.initialValue;
- return Promise$_reducer.call(fn, fulfilleds, initialValue);
+ReductionPromiseArray.prototype._promiseFulfilled = function (value, index) {
+ var values = this._values;
+ values[index] = value;
+ var length = this.length();
+ var preservedValues = this._preservedValues;
+ var isEach = preservedValues !== null;
+ var gotAccum = this._gotAccum;
+ var valuesPhase = this._valuesPhase;
+ var valuesPhaseIndex;
+ if (!valuesPhase) {
+ valuesPhase = this._valuesPhase = new Array(length);
+ for (valuesPhaseIndex=0; valuesPhaseIndex
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var global = require("./global.js");
-var schedule;
-if (typeof process !== "undefined" && process !== null &&
- typeof process.cwd === "function" &&
- typeof process.nextTick === "function" &&
- typeof process.version === "string") {
- schedule = function Promise$_Scheduler(fn) {
- process.nextTick(fn);
- };
-}
-else if ((typeof global.MutationObserver === "function" ||
- typeof global.WebkitMutationObserver === "function" ||
- typeof global.WebKitMutationObserver === "function") &&
- typeof document !== "undefined" &&
- typeof document.createElement === "function") {
-
-
- schedule = (function(){
- var MutationObserver = global.MutationObserver ||
- global.WebkitMutationObserver ||
- global.WebKitMutationObserver;
- var div = document.createElement("div");
- var queuedFn = void 0;
- var observer = new MutationObserver(
- function Promise$_Scheduler() {
- var fn = queuedFn;
- queuedFn = void 0;
- fn();
- }
- );
- observer.observe(div, {
- attributes: true
- });
- return function Promise$_Scheduler(fn) {
- queuedFn = fn;
- div.setAttribute("class", "foo");
- };
-
- })();
+function reduce(promises, fn, initialValue, _each) {
+ if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
+ var array = new ReductionPromiseArray(promises, fn, initialValue, _each);
+ return array.promise();
}
-else if (typeof global.postMessage === "function" &&
- typeof global.importScripts !== "function" &&
- typeof global.addEventListener === "function" &&
- typeof global.removeEventListener === "function") {
-
- var MESSAGE_KEY = "bluebird_message_key_" + Math.random();
- schedule = (function(){
- var queuedFn = void 0;
-
- function Promise$_Scheduler(e) {
- if (e.source === global &&
- e.data === MESSAGE_KEY) {
- var fn = queuedFn;
- queuedFn = void 0;
- fn();
- }
- }
- global.addEventListener("message", Promise$_Scheduler, false);
+Promise.prototype.reduce = function (fn, initialValue) {
+ return reduce(this, fn, initialValue, null);
+};
- return function Promise$_Scheduler(fn) {
- queuedFn = fn;
- global.postMessage(
- MESSAGE_KEY, "*"
- );
- };
+Promise.reduce = function (promises, fn, initialValue, _each) {
+ return reduce(promises, fn, initialValue, _each);
+};
+};
- })();
+},{"./util.js":38}],31:[function(_dereq_,module,exports){
+"use strict";
+var schedule;
+if (_dereq_("./util.js").isNode) {
+ var version = process.versions.node.split(".").map(Number);
+ schedule = (version[0] === 0 && version[1] > 10) || (version[0] > 0)
+ ? global.setImmediate : process.nextTick;
}
-else if (typeof global.MessageChannel === "function") {
- schedule = (function(){
- var queuedFn = void 0;
-
- var channel = new global.MessageChannel();
- channel.port1.onmessage = function Promise$_Scheduler() {
- var fn = queuedFn;
- queuedFn = void 0;
- fn();
- };
-
- return function Promise$_Scheduler(fn) {
- queuedFn = fn;
- channel.port2.postMessage(null);
- };
- })();
+else if (typeof MutationObserver !== "undefined") {
+ schedule = function(fn) {
+ var div = document.createElement("div");
+ var observer = new MutationObserver(fn);
+ observer.observe(div, {attributes: true});
+ return function() { div.classList.toggle("foo"); };
+ };
+ schedule.isStatic = true;
}
-else if (global.setTimeout) {
- schedule = function Promise$_Scheduler(fn) {
- setTimeout(fn, 4);
+else if (typeof setTimeout !== "undefined") {
+ schedule = function (fn) {
+ setTimeout(fn, 0);
};
}
else {
- schedule = function Promise$_Scheduler(fn) {
- fn();
+ schedule = function() {
+ throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/m3OTXk\u000a");
};
}
-
module.exports = schedule;
-},{"./global.js":15}],31:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./util.js":38}],32:[function(_dereq_,module,exports){
"use strict";
module.exports =
- function(Promise, Promise$_CreatePromiseArray, PromiseArray) {
-
- var SettledPromiseArray = require("./settled_promise_array.js")(
- Promise, PromiseArray);
-
- function Promise$_Settle(promises, useBound, caller) {
- return Promise$_CreatePromiseArray(
- promises,
- SettledPromiseArray,
- caller,
- useBound === true && promises._isBound()
- ? promises._boundTo
- : void 0
- ).promise();
- }
-
- Promise.settle = function Promise$Settle(promises) {
- return Promise$_Settle(promises, false, Promise.settle);
- };
-
- Promise.prototype.settle = function Promise$settle() {
- return Promise$_Settle(this, true, this.settle);
- };
+ function(Promise, PromiseArray) {
+var PromiseInspection = Promise.PromiseInspection;
+var util = _dereq_("./util.js");
-};
-
-},{"./settled_promise_array.js":32}],32:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, PromiseArray) {
-var PromiseInspection = require("./promise_inspection.js");
-var util = require("./util.js");
-var inherits = util.inherits;
-function SettledPromiseArray(values, caller, boundTo) {
- this.constructor$(values, caller, boundTo);
+function SettledPromiseArray(values) {
+ this.constructor$(values);
}
-inherits(SettledPromiseArray, PromiseArray);
+util.inherits(SettledPromiseArray, PromiseArray);
-SettledPromiseArray.prototype._promiseResolved =
-function SettledPromiseArray$_promiseResolved(index, inspection) {
+SettledPromiseArray.prototype._promiseResolved = function (index, inspection) {
this._values[index] = inspection;
var totalResolved = ++this._totalResolved;
if (totalResolved >= this._length) {
@@ -6490,124 +5850,47 @@ function SettledPromiseArray$_promiseResolved(index, inspection) {
}
};
-SettledPromiseArray.prototype._promiseFulfilled =
-function SettledPromiseArray$_promiseFulfilled(value, index) {
- if (this._isResolved()) return;
+SettledPromiseArray.prototype._promiseFulfilled = function (value, index) {
var ret = new PromiseInspection();
ret._bitField = 268435456;
ret._settledValue = value;
this._promiseResolved(index, ret);
};
-SettledPromiseArray.prototype._promiseRejected =
-function SettledPromiseArray$_promiseRejected(reason, index) {
- if (this._isResolved()) return;
+SettledPromiseArray.prototype._promiseRejected = function (reason, index) {
var ret = new PromiseInspection();
ret._bitField = 134217728;
ret._settledValue = reason;
this._promiseResolved(index, ret);
};
-return SettledPromiseArray;
+Promise.settle = function (promises) {
+ return new SettledPromiseArray(promises).promise();
};
-},{"./promise_inspection.js":21,"./util.js":38}],33:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports =
-function(Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection) {
-
- var SomePromiseArray = require("./some_promise_array.js")(PromiseArray);
- function Promise$_Some(promises, howMany, useBound, caller) {
- if ((howMany | 0) !== howMany || howMany < 0) {
- return apiRejection("expecting a positive integer");
- }
- var ret = Promise$_CreatePromiseArray(
- promises,
- SomePromiseArray,
- caller,
- useBound === true && promises._isBound()
- ? promises._boundTo
- : void 0
- );
- var promise = ret.promise();
- if (promise.isRejected()) {
- return promise;
- }
- ret.setHowMany(howMany);
- ret.init();
- return promise;
- }
-
- Promise.some = function Promise$Some(promises, howMany) {
- return Promise$_Some(promises, howMany, false, Promise.some);
- };
-
- Promise.prototype.some = function Promise$some(count) {
- return Promise$_Some(this, count, true, this.some);
- };
-
+Promise.prototype.settle = function () {
+ return new SettledPromiseArray(this).promise();
+};
};
-},{"./some_promise_array.js":34}],34:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./util.js":38}],33:[function(_dereq_,module,exports){
"use strict";
-module.exports = function (PromiseArray) {
-var util = require("./util.js");
-var RangeError = require("./errors.js").RangeError;
-var inherits = util.inherits;
+module.exports =
+function(Promise, PromiseArray, apiRejection) {
+var util = _dereq_("./util.js");
+var RangeError = _dereq_("./errors.js").RangeError;
+var AggregateError = _dereq_("./errors.js").AggregateError;
var isArray = util.isArray;
-function SomePromiseArray(values, caller, boundTo) {
- this.constructor$(values, caller, boundTo);
+
+function SomePromiseArray(values) {
+ this.constructor$(values);
this._howMany = 0;
this._unwrap = false;
this._initialized = false;
}
-inherits(SomePromiseArray, PromiseArray);
+util.inherits(SomePromiseArray, PromiseArray);
-SomePromiseArray.prototype._init = function SomePromiseArray$_init() {
+SomePromiseArray.prototype._init = function () {
if (!this._initialized) {
return;
}
@@ -6615,407 +5898,562 @@ SomePromiseArray.prototype._init = function SomePromiseArray$_init() {
this._resolve([]);
return;
}
- this._init$(void 0, -2);
+ this._init$(undefined, -5);
var isArrayResolved = isArray(this._values);
- this._holes = isArrayResolved ? this._values.length - this.length() : 0;
-
if (!this._isResolved() &&
isArrayResolved &&
this._howMany > this._canPossiblyFulfill()) {
- var message = "(Promise.some) input array contains less than " +
- this._howMany + " promises";
- this._reject(new RangeError(message));
+ this._reject(this._getRangeError(this.length()));
}
};
-SomePromiseArray.prototype.init = function SomePromiseArray$init() {
+SomePromiseArray.prototype.init = function () {
this._initialized = true;
this._init();
};
-SomePromiseArray.prototype.setUnwrap = function SomePromiseArray$setUnwrap() {
+SomePromiseArray.prototype.setUnwrap = function () {
this._unwrap = true;
};
-SomePromiseArray.prototype.howMany = function SomePromiseArray$howMany() {
+SomePromiseArray.prototype.howMany = function () {
return this._howMany;
};
-SomePromiseArray.prototype.setHowMany =
-function SomePromiseArray$setHowMany(count) {
- if (this._isResolved()) return;
+SomePromiseArray.prototype.setHowMany = function (count) {
this._howMany = count;
};
-SomePromiseArray.prototype._promiseFulfilled =
-function SomePromiseArray$_promiseFulfilled(value) {
- if (this._isResolved()) return;
+SomePromiseArray.prototype._promiseFulfilled = function (value) {
this._addFulfilled(value);
if (this._fulfilled() === this.howMany()) {
this._values.length = this.howMany();
if (this.howMany() === 1 && this._unwrap) {
this._resolve(this._values[0]);
- }
- else {
+ } else {
this._resolve(this._values);
}
}
};
-SomePromiseArray.prototype._promiseRejected =
-function SomePromiseArray$_promiseRejected(reason) {
- if (this._isResolved()) return;
+SomePromiseArray.prototype._promiseRejected = function (reason) {
this._addRejected(reason);
if (this.howMany() > this._canPossiblyFulfill()) {
- if (this._values.length === this.length()) {
- this._reject([]);
- }
- else {
- this._reject(this._values.slice(this.length() + this._holes));
+ var e = new AggregateError();
+ for (var i = this.length(); i < this._values.length; ++i) {
+ e.push(this._values[i]);
}
+ this._reject(e);
}
};
-SomePromiseArray.prototype._fulfilled = function SomePromiseArray$_fulfilled() {
+SomePromiseArray.prototype._fulfilled = function () {
return this._totalResolved;
};
-SomePromiseArray.prototype._rejected = function SomePromiseArray$_rejected() {
- return this._values.length - this.length() - this._holes;
+SomePromiseArray.prototype._rejected = function () {
+ return this._values.length - this.length();
};
-SomePromiseArray.prototype._addRejected =
-function SomePromiseArray$_addRejected(reason) {
+SomePromiseArray.prototype._addRejected = function (reason) {
this._values.push(reason);
};
-SomePromiseArray.prototype._addFulfilled =
-function SomePromiseArray$_addFulfilled(value) {
+SomePromiseArray.prototype._addFulfilled = function (value) {
this._values[this._totalResolved++] = value;
};
-SomePromiseArray.prototype._canPossiblyFulfill =
-function SomePromiseArray$_canPossiblyFulfill() {
+SomePromiseArray.prototype._canPossiblyFulfill = function () {
return this.length() - this._rejected();
};
-return SomePromiseArray;
+SomePromiseArray.prototype._getRangeError = function (count) {
+ var message = "Input array must contain at least " +
+ this._howMany + " items but contains only " + count + " items";
+ return new RangeError(message);
};
-},{"./errors.js":9,"./util.js":38}],35:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+SomePromiseArray.prototype._resolveEmptyArray = function () {
+ this._reject(this._getRangeError(0));
+};
+
+function some(promises, howMany) {
+ if ((howMany | 0) !== howMany || howMany < 0) {
+ return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/1wAmHx\u000a");
+ }
+ var ret = new SomePromiseArray(promises);
+ var promise = ret.promise();
+ ret.setHowMany(howMany);
+ ret.init();
+ return promise;
+}
+
+Promise.some = function (promises, howMany) {
+ return some(promises, howMany);
+};
+
+Promise.prototype.some = function (howMany) {
+ return some(this, howMany);
+};
+
+Promise._SomePromiseArray = SomePromiseArray;
+};
+
+},{"./errors.js":13,"./util.js":38}],34:[function(_dereq_,module,exports){
"use strict";
module.exports = function(Promise) {
- var PromiseInspection = require("./promise_inspection.js");
+function PromiseInspection(promise) {
+ if (promise !== undefined) {
+ promise = promise._target();
+ this._bitField = promise._bitField;
+ this._settledValue = promise._settledValue;
+ }
+ else {
+ this._bitField = 0;
+ this._settledValue = undefined;
+ }
+}
+
+PromiseInspection.prototype.value = function () {
+ if (!this.isFulfilled()) {
+ throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/hc1DLj\u000a");
+ }
+ return this._settledValue;
+};
+
+PromiseInspection.prototype.error =
+PromiseInspection.prototype.reason = function () {
+ if (!this.isRejected()) {
+ throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/hPuiwB\u000a");
+ }
+ return this._settledValue;
+};
+
+PromiseInspection.prototype.isFulfilled =
+Promise.prototype._isFulfilled = function () {
+ return (this._bitField & 268435456) > 0;
+};
+
+PromiseInspection.prototype.isRejected =
+Promise.prototype._isRejected = function () {
+ return (this._bitField & 134217728) > 0;
+};
+
+PromiseInspection.prototype.isPending =
+Promise.prototype._isPending = function () {
+ return (this._bitField & 402653184) === 0;
+};
+
+PromiseInspection.prototype.isResolved =
+Promise.prototype._isResolved = function () {
+ return (this._bitField & 402653184) > 0;
+};
+
+Promise.prototype.isPending = function() {
+ return this._target()._isPending();
+};
+
+Promise.prototype.isRejected = function() {
+ return this._target()._isRejected();
+};
+
+Promise.prototype.isFulfilled = function() {
+ return this._target()._isFulfilled();
+};
+
+Promise.prototype.isResolved = function() {
+ return this._target()._isResolved();
+};
+
+Promise.prototype._value = function() {
+ return this._settledValue;
+};
+
+Promise.prototype._reason = function() {
+ this._unsetRejectionIsUnhandled();
+ return this._settledValue;
+};
+
+Promise.prototype.value = function() {
+ var target = this._target();
+ if (!target.isFulfilled()) {
+ throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/hc1DLj\u000a");
+ }
+ return target._settledValue;
+};
+
+Promise.prototype.reason = function() {
+ var target = this._target();
+ if (!target.isRejected()) {
+ throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/hPuiwB\u000a");
+ }
+ target._unsetRejectionIsUnhandled();
+ return target._settledValue;
+};
+
+
+Promise.PromiseInspection = PromiseInspection;
+};
+
+},{}],35:[function(_dereq_,module,exports){
+"use strict";
+module.exports = function(Promise, INTERNAL) {
+var util = _dereq_("./util.js");
+var errorObj = util.errorObj;
+var isObject = util.isObject;
+
+function tryConvertToPromise(obj, context) {
+ if (isObject(obj)) {
+ if (obj instanceof Promise) {
+ return obj;
+ }
+ else if (isAnyBluebirdPromise(obj)) {
+ var ret = new Promise(INTERNAL);
+ obj._then(
+ ret._fulfillUnchecked,
+ ret._rejectUncheckedCheckError,
+ ret._progressUnchecked,
+ ret,
+ null
+ );
+ return ret;
+ }
+ var then = util.tryCatch(getThen)(obj);
+ if (then === errorObj) {
+ if (context) context._pushContext();
+ var ret = Promise.reject(then.e);
+ if (context) context._popContext();
+ return ret;
+ } else if (typeof then === "function") {
+ return doThenable(obj, then, context);
+ }
+ }
+ return obj;
+}
+
+function getThen(obj) {
+ return obj.then;
+}
+
+var hasProp = {}.hasOwnProperty;
+function isAnyBluebirdPromise(obj) {
+ return hasProp.call(obj, "_promise0");
+}
+
+function doThenable(x, then, context) {
+ var promise = new Promise(INTERNAL);
+ var ret = promise;
+ if (context) context._pushContext();
+ promise._captureStackTrace();
+ if (context) context._popContext();
+ var synchronous = true;
+ var result = util.tryCatch(then).call(x,
+ resolveFromThenable,
+ rejectFromThenable,
+ progressFromThenable);
+ synchronous = false;
+ if (promise && result === errorObj) {
+ promise._rejectCallback(result.e, true, true);
+ promise = null;
+ }
+
+ function resolveFromThenable(value) {
+ if (!promise) return;
+ if (x === value) {
+ promise._rejectCallback(
+ Promise._makeSelfResolutionError(), false, true);
+ } else {
+ promise._resolveCallback(value);
+ }
+ promise = null;
+ }
+
+ function rejectFromThenable(reason) {
+ if (!promise) return;
+ promise._rejectCallback(reason, synchronous, true);
+ promise = null;
+ }
+
+ function progressFromThenable(value) {
+ if (!promise) return;
+ if (typeof promise._progress === "function") {
+ promise._progress(value);
+ }
+ }
+ return ret;
+}
- Promise.prototype.inspect = function Promise$inspect() {
- return new PromiseInspection(this);
- };
+return tryConvertToPromise;
};
-},{"./promise_inspection.js":21}],36:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./util.js":38}],36:[function(_dereq_,module,exports){
"use strict";
module.exports = function(Promise, INTERNAL) {
- var util = require("./util.js");
- var canAttach = require("./errors.js").canAttach;
- var errorObj = util.errorObj;
- var isObject = util.isObject;
+var util = _dereq_("./util.js");
+var TimeoutError = Promise.TimeoutError;
- function getThen(obj) {
- try {
- return obj.then;
- }
- catch(e) {
- errorObj.e = e;
- return errorObj;
- }
+var afterTimeout = function (promise, message) {
+ if (!promise.isPending()) return;
+ if (typeof message !== "string") {
+ message = "operation timed out";
}
+ var err = new TimeoutError(message);
+ util.markAsOriginatingFromRejection(err);
+ promise._attachExtraTrace(err);
+ promise._cancel(err);
+};
- function Promise$_Cast(obj, caller, originalPromise) {
- if (isObject(obj)) {
- if (obj instanceof Promise) {
- return obj;
- }
- else if (isAnyBluebirdPromise(obj)) {
- var ret = new Promise(INTERNAL);
- ret._setTrace(caller, void 0);
- obj._then(
- ret._fulfillUnchecked,
- ret._rejectUncheckedCheckError,
- ret._progressUnchecked,
- ret,
- null,
- void 0
- );
- ret._setFollowing();
- return ret;
- }
- var then = getThen(obj);
- if (then === errorObj) {
- caller = typeof caller === "function" ? caller : Promise$_Cast;
- if (originalPromise !== void 0 && canAttach(then.e)) {
- originalPromise._attachExtraTrace(then.e);
- }
- return Promise.reject(then.e, caller);
- }
- else if (typeof then === "function") {
- caller = typeof caller === "function" ? caller : Promise$_Cast;
- return Promise$_doThenable(obj, then, caller, originalPromise);
+var afterValue = function(value) { return delay(+this).thenReturn(value); };
+var delay = Promise.delay = function (value, ms) {
+ if (ms === undefined) {
+ ms = value;
+ value = undefined;
+ var ret = new Promise(INTERNAL);
+ setTimeout(function() { ret._fulfill(); }, ms);
+ return ret;
+ }
+ ms = +ms;
+ return Promise.resolve(value)._then(afterValue, null, null, ms, undefined);
+};
+
+Promise.prototype.delay = function (ms) {
+ return delay(this, ms);
+};
+
+function successClear(value) {
+ var handle = this;
+ if (handle instanceof Number) handle = +handle;
+ clearTimeout(handle);
+ return value;
+}
+
+function failureClear(reason) {
+ var handle = this;
+ if (handle instanceof Number) handle = +handle;
+ clearTimeout(handle);
+ throw reason;
+}
+
+Promise.prototype.timeout = function (ms, message) {
+ ms = +ms;
+ var ret = this.then().cancellable();
+ ret._cancellationParent = this;
+ var handle = setTimeout(function timeoutTimeout() {
+ afterTimeout(ret, message);
+ }, ms);
+ return ret._then(successClear, failureClear, undefined, handle, undefined);
+};
+
+};
+
+},{"./util.js":38}],37:[function(_dereq_,module,exports){
+"use strict";
+module.exports = function (Promise, apiRejection, tryConvertToPromise,
+ createContext) {
+ var TypeError = _dereq_("./errors.js").TypeError;
+ var inherits = _dereq_("./util.js").inherits;
+ var PromiseInspection = Promise.PromiseInspection;
+
+ function inspectionMapper(inspections) {
+ var len = inspections.length;
+ for (var i = 0; i < len; ++i) {
+ var inspection = inspections[i];
+ if (inspection.isRejected()) {
+ return Promise.reject(inspection.error());
}
+ inspections[i] = inspection._settledValue;
}
- return obj;
+ return inspections;
}
- var hasProp = {}.hasOwnProperty;
- function isAnyBluebirdPromise(obj) {
- return hasProp.call(obj, "_promise0");
+ function thrower(e) {
+ setTimeout(function(){throw e;}, 0);
}
- function Promise$_doThenable(x, then, caller, originalPromise) {
- var resolver = Promise.defer(caller);
- var called = false;
- try {
- then.call(
- x,
- Promise$_resolveFromThenable,
- Promise$_rejectFromThenable,
- Promise$_progressFromThenable
- );
+ function castPreservingDisposable(thenable) {
+ var maybePromise = tryConvertToPromise(thenable);
+ if (maybePromise !== thenable &&
+ typeof thenable._isDisposable === "function" &&
+ typeof thenable._getDisposer === "function" &&
+ thenable._isDisposable()) {
+ maybePromise._setDisposable(thenable._getDisposer());
}
- catch(e) {
- if (!called) {
- called = true;
- var trace = canAttach(e) ? e : new Error(e + "");
- if (originalPromise !== void 0) {
- originalPromise._attachExtraTrace(trace);
+ return maybePromise;
+ }
+ function dispose(resources, inspection) {
+ var i = 0;
+ var len = resources.length;
+ var ret = Promise.defer();
+ function iterator() {
+ if (i >= len) return ret.resolve();
+ var maybePromise = castPreservingDisposable(resources[i++]);
+ if (maybePromise instanceof Promise &&
+ maybePromise._isDisposable()) {
+ try {
+ maybePromise = tryConvertToPromise(
+ maybePromise._getDisposer().tryDispose(inspection),
+ resources.promise);
+ } catch (e) {
+ return thrower(e);
}
- resolver.promise._reject(e, trace);
- }
- }
- return resolver.promise;
-
- function Promise$_resolveFromThenable(y) {
- if (called) return;
- called = true;
-
- if (x === y) {
- var e = Promise._makeSelfResolutionError();
- if (originalPromise !== void 0) {
- originalPromise._attachExtraTrace(e);
+ if (maybePromise instanceof Promise) {
+ return maybePromise._then(iterator, thrower,
+ null, null, null);
}
- resolver.promise._reject(e, void 0);
- return;
}
- resolver.resolve(y);
+ iterator();
}
+ iterator();
+ return ret.promise;
+ }
- function Promise$_rejectFromThenable(r) {
- if (called) return;
- called = true;
- var trace = canAttach(r) ? r : new Error(r + "");
- if (originalPromise !== void 0) {
- originalPromise._attachExtraTrace(trace);
- }
- resolver.promise._reject(r, trace);
- }
+ function disposerSuccess(value) {
+ var inspection = new PromiseInspection();
+ inspection._settledValue = value;
+ inspection._bitField = 268435456;
+ return dispose(this, inspection).thenReturn(value);
+ }
- function Promise$_progressFromThenable(v) {
- if (called) return;
- var promise = resolver.promise;
- if (typeof promise._progress === "function") {
- promise._progress(v);
- }
- }
+ function disposerFail(reason) {
+ var inspection = new PromiseInspection();
+ inspection._settledValue = reason;
+ inspection._bitField = 134217728;
+ return dispose(this, inspection).thenThrow(reason);
}
- Promise._cast = Promise$_Cast;
-};
+ function Disposer(data, promise, context) {
+ this._data = data;
+ this._promise = promise;
+ this._context = context;
+ }
-},{"./errors.js":9,"./util.js":38}],37:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
+ Disposer.prototype.data = function () {
+ return this._data;
+ };
-var global = require("./global.js");
-var setTimeout = function(fn, time) {
- var $_len = arguments.length;var args = new Array($_len - 2); for(var $_i = 2; $_i < $_len; ++$_i) {args[$_i - 2] = arguments[$_i];}
- global.setTimeout(function() {
- fn.apply(void 0, args);
- }, time);
-};
+ Disposer.prototype.promise = function () {
+ return this._promise;
+ };
-var pass = {};
-global.setTimeout( function(_) {
- if(_ === pass) {
- setTimeout = global.setTimeout;
- }
-}, 1, pass);
+ Disposer.prototype.resource = function () {
+ if (this.promise().isFulfilled()) {
+ return this.promise().value();
+ }
+ return null;
+ };
-module.exports = function(Promise, INTERNAL) {
- var util = require("./util.js");
- var errors = require("./errors.js");
- var apiRejection = require("./errors_api_rejection")(Promise);
- var TimeoutError = Promise.TimeoutError;
+ Disposer.prototype.tryDispose = function(inspection) {
+ var resource = this.resource();
+ var context = this._context;
+ if (context !== undefined) context._pushContext();
+ var ret = resource !== null
+ ? this.doDispose(resource, inspection) : null;
+ if (context !== undefined) context._popContext();
+ this._promise._unsetDisposable();
+ this._data = null;
+ return ret;
+ };
- var afterTimeout = function Promise$_afterTimeout(promise, message, ms) {
- if (!promise.isPending()) return;
- if (typeof message !== "string") {
- message = "operation timed out after" + " " + ms + " ms"
- }
- var err = new TimeoutError(message);
- errors.markAsOriginatingFromRejection(err);
- promise._attachExtraTrace(err);
- promise._rejectUnchecked(err);
+ Disposer.isDisposer = function (d) {
+ return (d != null &&
+ typeof d.resource === "function" &&
+ typeof d.tryDispose === "function");
};
- var afterDelay = function Promise$_afterDelay(value, promise) {
- promise._fulfill(value);
+ function FunctionDisposer(fn, promise, context) {
+ this.constructor$(fn, promise, context);
+ }
+ inherits(FunctionDisposer, Disposer);
+
+ FunctionDisposer.prototype.doDispose = function (resource, inspection) {
+ var fn = this.data();
+ return fn.call(resource, resource, inspection);
};
- Promise.delay = function Promise$Delay(value, ms, caller) {
- if (ms === void 0) {
- ms = value;
- value = void 0;
+ function maybeUnwrapDisposer(value) {
+ if (Disposer.isDisposer(value)) {
+ this.resources[this.index]._setDisposable(value);
+ return value.promise();
}
- ms = +ms;
- if (typeof caller !== "function") {
- caller = Promise.delay;
- }
- var maybePromise = Promise._cast(value, caller, void 0);
- var promise = new Promise(INTERNAL);
+ return value;
+ }
- if (Promise.is(maybePromise)) {
- if (maybePromise._isBound()) {
- promise._setBoundTo(maybePromise._boundTo);
- }
- if (maybePromise._cancellable()) {
- promise._setCancellable();
- promise._cancellationParent = maybePromise;
+ Promise.using = function () {
+ var len = arguments.length;
+ if (len < 2) return apiRejection(
+ "you must pass at least 2 arguments to Promise.using");
+ var fn = arguments[len - 1];
+ if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
+ len--;
+ var resources = new Array(len);
+ for (var i = 0; i < len; ++i) {
+ var resource = arguments[i];
+ if (Disposer.isDisposer(resource)) {
+ var disposer = resource;
+ resource = resource.promise();
+ resource._setDisposable(disposer);
+ } else {
+ var maybePromise = tryConvertToPromise(resource);
+ if (maybePromise instanceof Promise) {
+ resource =
+ maybePromise._then(maybeUnwrapDisposer, null, null, {
+ resources: resources,
+ index: i
+ }, undefined);
+ }
}
- promise._setTrace(caller, maybePromise);
- promise._follow(maybePromise);
- return promise.then(function(value) {
- return Promise.delay(value, ms);
- });
- }
- else {
- promise._setTrace(caller, void 0);
- setTimeout(afterDelay, ms, value, promise);
+ resources[i] = resource;
}
+
+ var promise = Promise.settle(resources)
+ .then(inspectionMapper)
+ .then(function(vals) {
+ promise._pushContext();
+ var ret;
+ try {
+ ret = fn.apply(undefined, vals);
+ } finally {
+ promise._popContext();
+ }
+ return ret;
+ })
+ ._then(
+ disposerSuccess, disposerFail, undefined, resources, undefined);
+ resources.promise = promise;
return promise;
};
- Promise.prototype.delay = function Promise$delay(ms) {
- return Promise.delay(this, ms, this.delay);
+ Promise.prototype._setDisposable = function (disposer) {
+ this._bitField = this._bitField | 262144;
+ this._disposer = disposer;
};
- Promise.prototype.timeout = function Promise$timeout(ms, message) {
- ms = +ms;
+ Promise.prototype._isDisposable = function () {
+ return (this._bitField & 262144) > 0;
+ };
- var ret = new Promise(INTERNAL);
- ret._setTrace(this.timeout, this);
+ Promise.prototype._getDisposer = function () {
+ return this._disposer;
+ };
- if (this._isBound()) ret._setBoundTo(this._boundTo);
- if (this._cancellable()) {
- ret._setCancellable();
- ret._cancellationParent = this;
+ Promise.prototype._unsetDisposable = function () {
+ this._bitField = this._bitField & (~262144);
+ this._disposer = undefined;
+ };
+
+ Promise.prototype.disposer = function (fn) {
+ if (typeof fn === "function") {
+ return new FunctionDisposer(fn, this, createContext());
}
- ret._follow(this);
- setTimeout(afterTimeout, ms, ret, message, ms);
- return ret;
+ throw new TypeError();
};
};
-},{"./errors.js":9,"./errors_api_rejection":10,"./global.js":15,"./util.js":38}],38:[function(require,module,exports){
-/**
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
+},{"./errors.js":13,"./util.js":38}],38:[function(_dereq_,module,exports){
"use strict";
-var global = require("./global.js");
-var es5 = require("./es5.js");
+var es5 = _dereq_("./es5.js");
+var canEvaluate = typeof navigator == "undefined";
var haveGetters = (function(){
try {
var o = {};
@@ -7032,53 +6470,19 @@ var haveGetters = (function(){
})();
-var canEvaluate = (function() {
- if (typeof window !== "undefined" && window !== null &&
- typeof window.document !== "undefined" &&
- typeof navigator !== "undefined" && navigator !== null &&
- typeof navigator.appName === "string" &&
- window === global) {
- return false;
- }
- return true;
-})();
-
-function deprecated(msg) {
- if (typeof console !== "undefined" && console !== null &&
- typeof console.warn === "function") {
- console.warn("Bluebird: " + msg);
- }
-}
-
var errorObj = {e: {}};
-function tryCatch1(fn, receiver, arg) {
- try {
- return fn.call(receiver, arg);
- }
- catch (e) {
- errorObj.e = e;
- return errorObj;
- }
-}
-
-function tryCatch2(fn, receiver, arg, arg2) {
+var tryCatchTarget;
+function tryCatcher() {
try {
- return fn.call(receiver, arg, arg2);
- }
- catch (e) {
+ return tryCatchTarget.apply(this, arguments);
+ } catch (e) {
errorObj.e = e;
return errorObj;
}
}
-
-function tryCatchApply(fn, args, receiver) {
- try {
- return fn.apply(receiver, args);
- }
- catch (e) {
- errorObj.e = e;
- return errorObj;
- }
+function tryCatch(fn) {
+ tryCatchTarget = fn;
+ return tryCatcher;
}
var inherits = function(Child, Parent) {
@@ -7100,9 +6504,6 @@ var inherits = function(Child, Parent) {
return Child.prototype;
};
-function asString(val) {
- return typeof val === "string" ? val : ("" + val);
-}
function isPrimitive(val) {
return val == null || val === true || val === false ||
@@ -7117,7 +6518,7 @@ function isObject(value) {
function maybeWrapAsError(maybeError) {
if (!isPrimitive(maybeError)) return maybeError;
- return new Error(asString(maybeError));
+ return new Error(safeToString(maybeError));
}
function withAppended(target, appendee) {
@@ -7131,6 +6532,18 @@ function withAppended(target, appendee) {
return ret;
}
+function getDataPropertyOrDefault(obj, key, defaultValue) {
+ if (es5.isES5) {
+ var desc = Object.getOwnPropertyDescriptor(obj, key);
+ if (desc != null) {
+ return desc.get == null && desc.set == null
+ ? desc.value
+ : defaultValue;
+ }
+ } else {
+ return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
+ }
+}
function notEnumerableProp(obj, name, value) {
if (isPrimitive(obj)) return obj;
@@ -7153,6 +6566,59 @@ function thrower(r) {
throw r;
}
+var inheritedDataKeys = (function() {
+ if (es5.isES5) {
+ var oProto = Object.prototype;
+ var getKeys = Object.getOwnPropertyNames;
+ return function(obj) {
+ var ret = [];
+ var visitedKeys = Object.create(null);
+ while (obj != null && obj !== oProto) {
+ var keys;
+ try {
+ keys = getKeys(obj);
+ } catch (e) {
+ return ret;
+ }
+ for (var i = 0; i < keys.length; ++i) {
+ var key = keys[i];
+ if (visitedKeys[key]) continue;
+ visitedKeys[key] = true;
+ var desc = Object.getOwnPropertyDescriptor(obj, key);
+ if (desc != null && desc.get == null && desc.set == null) {
+ ret.push(key);
+ }
+ }
+ obj = es5.getPrototypeOf(obj);
+ }
+ return ret;
+ };
+ } else {
+ return function(obj) {
+ var ret = [];
+ /*jshint forin:false */
+ for (var key in obj) {
+ ret.push(key);
+ }
+ return ret;
+ };
+ }
+
+})();
+
+function isClass(fn) {
+ try {
+ if (typeof fn === "function") {
+ var keys = es5.names(fn.prototype);
+ if (es5.isES5) return keys.length > 1;
+ return keys.length > 0 &&
+ !(keys.length === 1 && keys[0] === "constructor");
+ }
+ return false;
+ } catch (e) {
+ return false;
+ }
+}
function toFastProperties(obj) {
/*jshint -W027*/
@@ -7162,7 +6628,78 @@ function toFastProperties(obj) {
eval(obj);
}
+var rident = /^[a-z$_][a-z$_0-9]*$/i;
+function isIdentifier(str) {
+ return rident.test(str);
+}
+
+function filledRange(count, prefix, suffix) {
+ var ret = new Array(count);
+ for(var i = 0; i < count; ++i) {
+ ret[i] = prefix + i + suffix;
+ }
+ return ret;
+}
+
+function safeToString(obj) {
+ try {
+ return obj + "";
+ } catch (e) {
+ return "[no string representation]";
+ }
+}
+
+function markAsOriginatingFromRejection(e) {
+ try {
+ notEnumerableProp(e, "isOperational", true);
+ }
+ catch(ignore) {}
+}
+
+function originatesFromRejection(e) {
+ if (e == null) return false;
+ return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) ||
+ e["isOperational"] === true);
+}
+
+function canAttachTrace(obj) {
+ return obj instanceof Error && es5.propertyIsWritable(obj, "stack");
+}
+
+var ensureErrorObject = (function() {
+ if (!("stack" in new Error())) {
+ return function(value) {
+ if (canAttachTrace(value)) return value;
+ try {throw new Error(safeToString(value));}
+ catch(err) {return err;}
+ };
+ } else {
+ return function(value) {
+ if (canAttachTrace(value)) return value;
+ return new Error(safeToString(value));
+ };
+ }
+})();
+
+function classString(obj) {
+ return {}.toString.call(obj);
+}
+
+function copyDescriptors(from, to, filter) {
+ var keys = es5.names(from);
+ for (var i = 0; i < keys.length; ++i) {
+ var key = keys[i];
+ if (filter(key)) {
+ es5.defineProperty(to, key, es5.getDescriptor(from, key));
+ }
+ }
+}
+
var ret = {
+ isClass: isClass,
+ isIdentifier: isIdentifier,
+ inheritedDataKeys: inheritedDataKeys,
+ getDataPropertyOrDefault: getDataPropertyOrDefault,
thrower: thrower,
isArray: es5.isArray,
haveGetters: haveGetters,
@@ -7170,25 +6707,29 @@ var ret = {
isPrimitive: isPrimitive,
isObject: isObject,
canEvaluate: canEvaluate,
- deprecated: deprecated,
errorObj: errorObj,
- tryCatch1: tryCatch1,
- tryCatch2: tryCatch2,
- tryCatchApply: tryCatchApply,
+ tryCatch: tryCatch,
inherits: inherits,
withAppended: withAppended,
- asString: asString,
maybeWrapAsError: maybeWrapAsError,
wrapsPrimitiveReceiver: wrapsPrimitiveReceiver,
- toFastProperties: toFastProperties
+ toFastProperties: toFastProperties,
+ filledRange: filledRange,
+ toString: safeToString,
+ canAttachTrace: canAttachTrace,
+ ensureErrorObject: ensureErrorObject,
+ originatesFromRejection: originatesFromRejection,
+ markAsOriginatingFromRejection: markAsOriginatingFromRejection,
+ classString: classString,
+ copyDescriptors: copyDescriptors,
+ isNode: typeof process !== "undefined" &&
+ classString(process).toLowerCase() === "[object process]"
};
-
+try {throw new Error(); } catch (e) {ret.lastLineError = e;}
module.exports = ret;
-},{"./es5.js":11,"./global.js":15}]},{},[3])
-(3)
-});
-;/*
+},{"./es5.js":14}]},{},[4])(4)
+}); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }/*
* This product includes color specifications and designs developed by Cynthia
* Brewer (http://colorbrewer.org/).
*/
diff --git a/htdocs/lib/dependencies_bundle.min.js b/htdocs/lib/dependencies_bundle.min.js
index daa7008d10..a522d02ff9 100644
--- a/htdocs/lib/dependencies_bundle.min.js
+++ b/htdocs/lib/dependencies_bundle.min.js
@@ -1,31 +1,32 @@
-var requirejs,require,define;(function(global){var req,s,head,baseElement,dataMain,src,interactiveScript,currentlyAddingScript,mainScript,subPath,version="2.1.11",commentRegExp=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/gm,cjsRequireRegExp=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,jsSuffixRegExp=/\.js$/,currDirRegExp=/^\.\//,op=Object.prototype,ostring=op.toString,hasOwn=op.hasOwnProperty,ap=Array.prototype,apsp=ap.splice,isBrowser=!!(typeof window!=="undefined"&&typeof navigator!=="undefined"&&window.document),isWebWorker=!isBrowser&&typeof importScripts!=="undefined",readyRegExp=isBrowser&&navigator.platform==="PLAYSTATION 3"?/^complete$/:/^(complete|loaded)$/,defContextName="_",isOpera=typeof opera!=="undefined"&&opera.toString()==="[object Opera]",contexts={},cfg={},globalDefQueue=[],useInteractive=false;function isFunction(it){return ostring.call(it)==="[object Function]"}function isArray(it){return ostring.call(it)==="[object Array]"}function each(ary,func){if(ary){var i;for(i=0;i-1;i-=1){if(ary[i]&&func(ary[i],i,ary)){break}}}}function hasProp(obj,prop){return hasOwn.call(obj,prop)}function getOwn(obj,prop){return hasProp(obj,prop)&&obj[prop]}function eachProp(obj,func){var prop;for(prop in obj){if(hasProp(obj,prop)){if(func(obj[prop],prop)){break}}}}function mixin(target,source,force,deepStringMixin){if(source){eachProp(source,function(value,prop){if(force||!hasProp(target,prop)){if(deepStringMixin&&typeof value==="object"&&value&&!isArray(value)&&!isFunction(value)&&!(value instanceof RegExp)){if(!target[prop]){target[prop]={}}mixin(target[prop],value,force,deepStringMixin)}else{target[prop]=value}}})}return target}function bind(obj,fn){return function(){return fn.apply(obj,arguments)}}function scripts(){return document.getElementsByTagName("script")}function defaultOnError(err){throw err}function getGlobal(value){if(!value){return value}var g=global;each(value.split("."),function(part){g=g[part]});return g}function makeError(id,msg,err,requireModules){var e=new Error(msg+"\nhttp://requirejs.org/docs/errors.html#"+id);e.requireType=id;e.requireModules=requireModules;if(err){e.originalError=err}return e}if(typeof define!=="undefined"){return}if(typeof requirejs!=="undefined"){if(isFunction(requirejs)){return}cfg=requirejs;requirejs=undefined}if(typeof require!=="undefined"&&!isFunction(require)){cfg=require;require=undefined}function newContext(contextName){var inCheckLoaded,Module,context,handlers,checkLoadedTimeoutId,config={waitSeconds:7,baseUrl:"./",paths:{},bundles:{},pkgs:{},shim:{},config:{}},registry={},enabledRegistry={},undefEvents={},defQueue=[],defined={},urlFetched={},bundlesMap={},requireCounter=1,unnormalizedCounter=1;function trimDots(ary){var i,part,length=ary.length;for(i=0;i0){ary.splice(i-1,2);i-=2}}}}function normalize(name,baseName,applyMap){var pkgMain,mapValue,nameParts,i,j,nameSegment,lastIndex,foundMap,foundI,foundStarMap,starI,baseParts=baseName&&baseName.split("/"),normalizedBaseParts=baseParts,map=config.map,starMap=map&&map["*"];if(name&&name.charAt(0)==="."){if(baseName){normalizedBaseParts=baseParts.slice(0,baseParts.length-1);name=name.split("/");lastIndex=name.length-1;if(config.nodeIdCompat&&jsSuffixRegExp.test(name[lastIndex])){name[lastIndex]=name[lastIndex].replace(jsSuffixRegExp,"")}name=normalizedBaseParts.concat(name);trimDots(name);name=name.join("/")}else if(name.indexOf("./")===0){name=name.substring(2)}}if(applyMap&&map&&(baseParts||starMap)){nameParts=name.split("/");outerLoop:for(i=nameParts.length;i>0;i-=1){nameSegment=nameParts.slice(0,i).join("/");if(baseParts){for(j=baseParts.length;j>0;j-=1){mapValue=getOwn(map,baseParts.slice(0,j).join("/"));if(mapValue){mapValue=getOwn(mapValue,nameSegment);if(mapValue){foundMap=mapValue;foundI=i;break outerLoop}}}}if(!foundStarMap&&starMap&&getOwn(starMap,nameSegment)){foundStarMap=getOwn(starMap,nameSegment);starI=i}}if(!foundMap&&foundStarMap){foundMap=foundStarMap;foundI=starI}if(foundMap){nameParts.splice(0,foundI,foundMap);name=nameParts.join("/")}}pkgMain=getOwn(config.pkgs,name);return pkgMain?pkgMain:name}function removeScript(name){if(isBrowser){each(scripts(),function(scriptNode){if(scriptNode.getAttribute("data-requiremodule")===name&&scriptNode.getAttribute("data-requirecontext")===context.contextName){scriptNode.parentNode.removeChild(scriptNode);return true}})}}function hasPathFallback(id){var pathConfig=getOwn(config.paths,id);if(pathConfig&&isArray(pathConfig)&&pathConfig.length>1){pathConfig.shift();context.require.undef(id);context.require([id]);return true}}function splitPrefix(name){var prefix,index=name?name.indexOf("!"):-1;if(index>-1){prefix=name.substring(0,index);name=name.substring(index+1,name.length)}return[prefix,name]}function makeModuleMap(name,parentModuleMap,isNormalized,applyMap){var url,pluginModule,suffix,nameParts,prefix=null,parentName=parentModuleMap?parentModuleMap.name:null,originalName=name,isDefine=true,normalizedName="";if(!name){isDefine=false;name="_@r"+(requireCounter+=1)}nameParts=splitPrefix(name);prefix=nameParts[0];name=nameParts[1];if(prefix){prefix=normalize(prefix,parentName,applyMap);pluginModule=getOwn(defined,prefix)}if(name){if(prefix){if(pluginModule&&pluginModule.normalize){normalizedName=pluginModule.normalize(name,function(name){return normalize(name,parentName,applyMap)})}else{normalizedName=normalize(name,parentName,applyMap)}}else{normalizedName=normalize(name,parentName,applyMap);nameParts=splitPrefix(normalizedName);prefix=nameParts[0];normalizedName=nameParts[1];isNormalized=true;url=context.nameToUrl(normalizedName)}}suffix=prefix&&!pluginModule&&!isNormalized?"_unnormalized"+(unnormalizedCounter+=1):"";return{prefix:prefix,name:normalizedName,parentMap:parentModuleMap,unnormalized:!!suffix,url:url,originalName:originalName,isDefine:isDefine,id:(prefix?prefix+"!"+normalizedName:normalizedName)+suffix}}function getModule(depMap){var id=depMap.id,mod=getOwn(registry,id);if(!mod){mod=registry[id]=new context.Module(depMap)}return mod}function on(depMap,name,fn){var id=depMap.id,mod=getOwn(registry,id);if(hasProp(defined,id)&&(!mod||mod.defineEmitComplete)){if(name==="defined"){fn(defined[id])}}else{mod=getModule(depMap);if(mod.error&&name==="error"){fn(mod.error)}else{mod.on(name,fn)}}}function onError(err,errback){var ids=err.requireModules,notified=false;if(errback){errback(err)}else{each(ids,function(id){var mod=getOwn(registry,id);if(mod){mod.error=err;if(mod.events.error){notified=true;mod.emit("error",err)}}});if(!notified){req.onError(err)}}}function takeGlobalQueue(){if(globalDefQueue.length){apsp.apply(defQueue,[defQueue.length,0].concat(globalDefQueue));globalDefQueue=[]}}handlers={require:function(mod){if(mod.require){return mod.require}else{return mod.require=context.makeRequire(mod.map)}},exports:function(mod){mod.usingExports=true;if(mod.map.isDefine){if(mod.exports){return defined[mod.map.id]=mod.exports}else{return mod.exports=defined[mod.map.id]={}}}},module:function(mod){if(mod.module){return mod.module}else{return mod.module={id:mod.map.id,uri:mod.map.url,config:function(){return getOwn(config.config,mod.map.id)||{}},exports:mod.exports||(mod.exports={})}}}};function cleanRegistry(id){delete registry[id];delete enabledRegistry[id]}function breakCycle(mod,traced,processed){var id=mod.map.id;if(mod.error){mod.emit("error",mod.error)}else{traced[id]=true;each(mod.depMaps,function(depMap,i){var depId=depMap.id,dep=getOwn(registry,depId);if(dep&&!mod.depMatched[i]&&!processed[depId]){if(getOwn(traced,depId)){mod.defineDep(i,defined[depId]);mod.check()}else{breakCycle(dep,traced,processed)}}});processed[id]=true}}function checkLoaded(){var err,usingPathFallback,waitInterval=config.waitSeconds*1e3,expired=waitInterval&&context.startTime+waitInterval<(new Date).getTime(),noLoads=[],reqCalls=[],stillLoading=false,needCycleCheck=true;if(inCheckLoaded){return}inCheckLoaded=true;eachProp(enabledRegistry,function(mod){var map=mod.map,modId=map.id;if(!mod.enabled){return}if(!map.isDefine){reqCalls.push(mod)}if(!mod.error){if(!mod.inited&&expired){if(hasPathFallback(modId)){usingPathFallback=true;stillLoading=true}else{noLoads.push(modId);removeScript(modId)}}else if(!mod.inited&&mod.fetched&&map.isDefine){stillLoading=true;if(!map.prefix){return needCycleCheck=false}}}});if(expired&&noLoads.length){err=makeError("timeout","Load timeout for modules: "+noLoads,null,noLoads);err.contextName=context.contextName;return onError(err)}if(needCycleCheck){each(reqCalls,function(mod){breakCycle(mod,{},{})})}if((!expired||usingPathFallback)&&stillLoading){if((isBrowser||isWebWorker)&&!checkLoadedTimeoutId){checkLoadedTimeoutId=setTimeout(function(){checkLoadedTimeoutId=0;checkLoaded()},50)}}inCheckLoaded=false}Module=function(map){this.events=getOwn(undefEvents,map.id)||{};this.map=map;this.shim=getOwn(config.shim,map.id);this.depExports=[];this.depMaps=[];this.depMatched=[];this.pluginMaps={};this.depCount=0};Module.prototype={init:function(depMaps,factory,errback,options){options=options||{};if(this.inited){return}this.factory=factory;if(errback){this.on("error",errback)}else if(this.events.error){errback=bind(this,function(err){this.emit("error",err)})}this.depMaps=depMaps&&depMaps.slice(0);this.errback=errback;this.inited=true;this.ignore=options.ignore;if(options.enabled||this.enabled){this.enable()}else{this.check()}},defineDep:function(i,depExports){if(!this.depMatched[i]){this.depMatched[i]=true;this.depCount-=1;this.depExports[i]=depExports}},fetch:function(){if(this.fetched){return}this.fetched=true;context.startTime=(new Date).getTime();var map=this.map;if(this.shim){context.makeRequire(this.map,{enableBuildCallback:true})(this.shim.deps||[],bind(this,function(){return map.prefix?this.callPlugin():this.load()}))}else{return map.prefix?this.callPlugin():this.load()}},load:function(){var url=this.map.url;if(!urlFetched[url]){urlFetched[url]=true;context.load(this.map.id,url)}},check:function(){if(!this.enabled||this.enabling){return}var err,cjsModule,id=this.map.id,depExports=this.depExports,exports=this.exports,factory=this.factory;if(!this.inited){this.fetch()}else if(this.error){this.emit("error",this.error)}else if(!this.defining){this.defining=true;if(this.depCount<1&&!this.defined){if(isFunction(factory)){if(this.events.error&&this.map.isDefine||req.onError!==defaultOnError){try{exports=context.execCb(id,factory,depExports,exports)}catch(e){err=e}}else{exports=context.execCb(id,factory,depExports,exports)}if(this.map.isDefine&&exports===undefined){cjsModule=this.module;if(cjsModule){exports=cjsModule.exports}else if(this.usingExports){exports=this.exports}}if(err){err.requireMap=this.map;err.requireModules=this.map.isDefine?[this.map.id]:null;err.requireType=this.map.isDefine?"define":"require";return onError(this.error=err)}}else{exports=factory}this.exports=exports;if(this.map.isDefine&&!this.ignore){defined[id]=exports;if(req.onResourceLoad){req.onResourceLoad(context,this.map,this.depMaps)}}cleanRegistry(id);this.defined=true}this.defining=false;if(this.defined&&!this.defineEmitted){this.defineEmitted=true;this.emit("defined",this.exports);this.defineEmitComplete=true}}},callPlugin:function(){var map=this.map,id=map.id,pluginMap=makeModuleMap(map.prefix);this.depMaps.push(pluginMap);on(pluginMap,"defined",bind(this,function(plugin){var load,normalizedMap,normalizedMod,bundleId=getOwn(bundlesMap,this.map.id),name=this.map.name,parentName=this.map.parentMap?this.map.parentMap.name:null,localRequire=context.makeRequire(map.parentMap,{enableBuildCallback:true});if(this.map.unnormalized){if(plugin.normalize){name=plugin.normalize(name,function(name){return normalize(name,parentName,true)})||""}normalizedMap=makeModuleMap(map.prefix+"!"+name,this.map.parentMap);on(normalizedMap,"defined",bind(this,function(value){this.init([],function(){return value},null,{enabled:true,ignore:true})}));normalizedMod=getOwn(registry,normalizedMap.id);if(normalizedMod){this.depMaps.push(normalizedMap);if(this.events.error){normalizedMod.on("error",bind(this,function(err){this.emit("error",err)}))}normalizedMod.enable()}return}if(bundleId){this.map.url=context.nameToUrl(bundleId);this.load();return}load=bind(this,function(value){this.init([],function(){return value},null,{enabled:true})});load.error=bind(this,function(err){this.inited=true;this.error=err;err.requireModules=[id];eachProp(registry,function(mod){if(mod.map.id.indexOf(id+"_unnormalized")===0){cleanRegistry(mod.map.id)}});onError(err)});load.fromText=bind(this,function(text,textAlt){var moduleName=map.name,moduleMap=makeModuleMap(moduleName),hasInteractive=useInteractive;if(textAlt){text=textAlt}if(hasInteractive){useInteractive=false}getModule(moduleMap);if(hasProp(config.config,id)){config.config[moduleName]=config.config[id]}try{req.exec(text)}catch(e){return onError(makeError("fromtexteval","fromText eval for "+id+" failed: "+e,e,[id]))}if(hasInteractive){useInteractive=true}this.depMaps.push(moduleMap);context.completeLoad(moduleName);localRequire([moduleName],load)});plugin.load(map.name,localRequire,load,config)}));context.enable(pluginMap,this);this.pluginMaps[pluginMap.id]=pluginMap},enable:function(){enabledRegistry[this.map.id]=this;this.enabled=true;this.enabling=true;each(this.depMaps,bind(this,function(depMap,i){var id,mod,handler;if(typeof depMap==="string"){depMap=makeModuleMap(depMap,this.map.isDefine?this.map:this.map.parentMap,false,!this.skipMap);this.depMaps[i]=depMap;handler=getOwn(handlers,depMap.id);if(handler){this.depExports[i]=handler(this);return}this.depCount+=1;on(depMap,"defined",bind(this,function(depExports){this.defineDep(i,depExports);this.check()}));if(this.errback){on(depMap,"error",bind(this,this.errback))}}id=depMap.id;mod=registry[id];if(!hasProp(handlers,id)&&mod&&!mod.enabled){context.enable(depMap,this)}}));eachProp(this.pluginMaps,bind(this,function(pluginMap){var mod=getOwn(registry,pluginMap.id);if(mod&&!mod.enabled){context.enable(pluginMap,this)}}));this.enabling=false;this.check()},on:function(name,cb){var cbs=this.events[name];if(!cbs){cbs=this.events[name]=[]}cbs.push(cb)},emit:function(name,evt){each(this.events[name],function(cb){cb(evt)});if(name==="error"){delete this.events[name]}}};function callGetModule(args){if(!hasProp(defined,args[0])){getModule(makeModuleMap(args[0],null,true)).init(args[1],args[2])}}function removeListener(node,func,name,ieName){if(node.detachEvent&&!isOpera){if(ieName){node.detachEvent(ieName,func)}}else{node.removeEventListener(name,func,false)}}function getScriptData(evt){var node=evt.currentTarget||evt.srcElement;removeListener(node,context.onScriptLoad,"load","onreadystatechange");removeListener(node,context.onScriptError,"error");return{node:node,id:node&&node.getAttribute("data-requiremodule")}}function intakeDefines(){var args;takeGlobalQueue();while(defQueue.length){args=defQueue.shift();if(args[0]===null){return onError(makeError("mismatch","Mismatched anonymous define() module: "+args[args.length-1]))}else{callGetModule(args)}}}context={config:config,contextName:contextName,registry:registry,defined:defined,urlFetched:urlFetched,defQueue:defQueue,Module:Module,makeModuleMap:makeModuleMap,nextTick:req.nextTick,onError:onError,configure:function(cfg){if(cfg.baseUrl){if(cfg.baseUrl.charAt(cfg.baseUrl.length-1)!=="/"){cfg.baseUrl+="/"}}var shim=config.shim,objs={paths:true,bundles:true,config:true,map:true};eachProp(cfg,function(value,prop){if(objs[prop]){if(!config[prop]){config[prop]={}}mixin(config[prop],value,true,true)}else{config[prop]=value}});if(cfg.bundles){eachProp(cfg.bundles,function(value,prop){each(value,function(v){if(v!==prop){bundlesMap[v]=prop}})})}if(cfg.shim){eachProp(cfg.shim,function(value,id){if(isArray(value)){value={deps:value}}if((value.exports||value.init)&&!value.exportsFn){value.exportsFn=context.makeShimExports(value)}shim[id]=value});config.shim=shim}if(cfg.packages){each(cfg.packages,function(pkgObj){var location,name;pkgObj=typeof pkgObj==="string"?{name:pkgObj}:pkgObj;name=pkgObj.name;location=pkgObj.location;if(location){config.paths[name]=pkgObj.location}config.pkgs[name]=pkgObj.name+"/"+(pkgObj.main||"main").replace(currDirRegExp,"").replace(jsSuffixRegExp,"")})}eachProp(registry,function(mod,id){if(!mod.inited&&!mod.map.unnormalized){mod.map=makeModuleMap(id)}});if(cfg.deps||cfg.callback){context.require(cfg.deps||[],cfg.callback)}},makeShimExports:function(value){function fn(){var ret;if(value.init){ret=value.init.apply(global,arguments)}return ret||value.exports&&getGlobal(value.exports)}return fn},makeRequire:function(relMap,options){options=options||{};function localRequire(deps,callback,errback){var id,map,requireMod;if(options.enableBuildCallback&&callback&&isFunction(callback)){callback.__requireJsBuild=true}if(typeof deps==="string"){if(isFunction(callback)){return onError(makeError("requireargs","Invalid require call"),errback)}if(relMap&&hasProp(handlers,deps)){return handlers[deps](registry[relMap.id])}if(req.get){return req.get(context,deps,relMap,localRequire)}map=makeModuleMap(deps,relMap,false,true);id=map.id;if(!hasProp(defined,id)){return onError(makeError("notloaded",'Module name "'+id+'" has not been loaded yet for context: '+contextName+(relMap?"":". Use require([])")))}return defined[id]}intakeDefines();context.nextTick(function(){intakeDefines();requireMod=getModule(makeModuleMap(null,relMap));requireMod.skipMap=options.skipMap;requireMod.init(deps,callback,errback,{enabled:true});checkLoaded()});return localRequire}mixin(localRequire,{isBrowser:isBrowser,toUrl:function(moduleNamePlusExt){var ext,index=moduleNamePlusExt.lastIndexOf("."),segment=moduleNamePlusExt.split("/")[0],isRelative=segment==="."||segment==="..";if(index!==-1&&(!isRelative||index>1)){ext=moduleNamePlusExt.substring(index,moduleNamePlusExt.length);moduleNamePlusExt=moduleNamePlusExt.substring(0,index)}return context.nameToUrl(normalize(moduleNamePlusExt,relMap&&relMap.id,true),ext,true)},defined:function(id){return hasProp(defined,makeModuleMap(id,relMap,false,true).id)},specified:function(id){id=makeModuleMap(id,relMap,false,true).id;return hasProp(defined,id)||hasProp(registry,id)}});if(!relMap){localRequire.undef=function(id){takeGlobalQueue();var map=makeModuleMap(id,relMap,true),mod=getOwn(registry,id);removeScript(id);delete defined[id];delete urlFetched[map.url];delete undefEvents[id];eachReverse(defQueue,function(args,i){if(args[0]===id){defQueue.splice(i,1)}});if(mod){if(mod.events.defined){undefEvents[id]=mod.events}cleanRegistry(id)}}}return localRequire},enable:function(depMap){var mod=getOwn(registry,depMap.id);if(mod){getModule(depMap).enable()}},completeLoad:function(moduleName){var found,args,mod,shim=getOwn(config.shim,moduleName)||{},shExports=shim.exports;takeGlobalQueue();while(defQueue.length){args=defQueue.shift();if(args[0]===null){args[0]=moduleName;if(found){break}found=true}else if(args[0]===moduleName){found=true}callGetModule(args)}mod=getOwn(registry,moduleName);if(!found&&!hasProp(defined,moduleName)&&mod&&!mod.inited){if(config.enforceDefine&&(!shExports||!getGlobal(shExports))){if(hasPathFallback(moduleName)){return}else{return onError(makeError("nodefine","No define call for "+moduleName,null,[moduleName]))}}else{callGetModule([moduleName,shim.deps||[],shim.exportsFn])}}checkLoaded()},nameToUrl:function(moduleName,ext,skipExt){var paths,syms,i,parentModule,url,parentPath,bundleId,pkgMain=getOwn(config.pkgs,moduleName);if(pkgMain){moduleName=pkgMain}bundleId=getOwn(bundlesMap,moduleName);if(bundleId){return context.nameToUrl(bundleId,ext,skipExt)}if(req.jsExtRegExp.test(moduleName)){url=moduleName+(ext||"")}else{paths=config.paths;syms=moduleName.split("/");for(i=syms.length;i>0;i-=1){parentModule=syms.slice(0,i).join("/");parentPath=getOwn(paths,parentModule);if(parentPath){if(isArray(parentPath)){parentPath=parentPath[0]}syms.splice(0,i,parentPath);break}}url=syms.join("/");url+=ext||(/^data\:|\?/.test(url)||skipExt?"":".js");url=(url.charAt(0)==="/"||url.match(/^[\w\+\.\-]+:/)?"":config.baseUrl)+url}return config.urlArgs?url+((url.indexOf("?")===-1?"?":"&")+config.urlArgs):url},load:function(id,url){req.load(context,id,url)},execCb:function(name,callback,args,exports){return callback.apply(exports,args)},onScriptLoad:function(evt){if(evt.type==="load"||readyRegExp.test((evt.currentTarget||evt.srcElement).readyState)){interactiveScript=null;var data=getScriptData(evt);context.completeLoad(data.id)}},onScriptError:function(evt){var data=getScriptData(evt);if(!hasPathFallback(data.id)){return onError(makeError("scripterror","Script error for: "+data.id,evt,[data.id]))}}};context.require=context.makeRequire();return context}req=requirejs=function(deps,callback,errback,optional){var context,config,contextName=defContextName;if(!isArray(deps)&&typeof deps!=="string"){config=deps;if(isArray(callback)){deps=callback;callback=errback;errback=optional}else{deps=[]}}if(config&&config.context){contextName=config.context}context=getOwn(contexts,contextName);if(!context){context=contexts[contextName]=req.s.newContext(contextName)}if(config){context.configure(config)}return context.require(deps,callback,errback)};req.config=function(config){return req(config)};req.nextTick=typeof setTimeout!=="undefined"?function(fn){setTimeout(fn,4)}:function(fn){fn()};if(!require){require=req}req.version=version;req.jsExtRegExp=/^\/|:|\?|\.js$/;req.isBrowser=isBrowser;s=req.s={contexts:contexts,newContext:newContext};req({});each(["toUrl","undef","defined","specified"],function(prop){req[prop]=function(){var ctx=contexts[defContextName];return ctx.require[prop].apply(ctx,arguments)}});if(isBrowser){head=s.head=document.getElementsByTagName("head")[0];baseElement=document.getElementsByTagName("base")[0];if(baseElement){head=s.head=baseElement.parentNode}}req.onError=defaultOnError;req.createNode=function(config,moduleName,url){var node=config.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script");node.type=config.scriptType||"text/javascript";node.charset="utf-8";node.async=true;return node};req.load=function(context,moduleName,url){var config=context&&context.config||{},node;if(isBrowser){node=req.createNode(config,moduleName,url);node.setAttribute("data-requirecontext",context.contextName);node.setAttribute("data-requiremodule",moduleName);if(node.attachEvent&&!(node.attachEvent.toString&&node.attachEvent.toString().indexOf("[native code")<0)&&!isOpera){useInteractive=true;node.attachEvent("onreadystatechange",context.onScriptLoad)}else{node.addEventListener("load",context.onScriptLoad,false);node.addEventListener("error",context.onScriptError,false)}node.src=url;currentlyAddingScript=node;if(baseElement){head.insertBefore(node,baseElement)}else{head.appendChild(node)}currentlyAddingScript=null;return node}else if(isWebWorker){try{importScripts(url);context.completeLoad(moduleName)}catch(e){context.onError(makeError("importscripts","importScripts failed for "+moduleName+" at "+url,e,[moduleName]))}}};function getInteractiveScript(){if(interactiveScript&&interactiveScript.readyState==="interactive"){return interactiveScript}eachReverse(scripts(),function(script){if(script.readyState==="interactive"){return interactiveScript=script}});return interactiveScript}if(isBrowser&&!cfg.skipDataMain){eachReverse(scripts(),function(script){if(!head){head=script.parentNode}dataMain=script.getAttribute("data-main");if(dataMain){mainScript=dataMain;if(!cfg.baseUrl){src=mainScript.split("/");mainScript=src.pop();subPath=src.length?src.join("/")+"/":"./";cfg.baseUrl=subPath}mainScript=mainScript.replace(jsSuffixRegExp,"");if(req.jsExtRegExp.test(mainScript)){mainScript=dataMain}cfg.deps=cfg.deps?cfg.deps.concat(mainScript):[mainScript];return true}})}define=function(name,deps,callback){var node,context;if(typeof name!=="string"){callback=deps;deps=name;name=null}if(!isArray(deps)){callback=deps;deps=null}if(!deps&&isFunction(callback)){deps=[];if(callback.length){callback.toString().replace(commentRegExp,"").replace(cjsRequireRegExp,function(match,dep){deps.push(dep)});deps=(callback.length===1?["require"]:["require","exports","module"]).concat(deps)}}if(useInteractive){node=currentlyAddingScript||getInteractiveScript();if(node){if(!name){name=node.getAttribute("data-requiremodule")}context=contexts[node.getAttribute("data-requirecontext")]}}(context?context.defQueue:globalDefQueue).push([name,deps,callback])};define.amd={jQuery:true};req.exec=function(text){return eval(text)};req(cfg)})(this);!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Promise=e():"undefined"!=typeof global?global.Promise=e():"undefined"!=typeof self&&(self.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;o0};Async.prototype.invokeLater=function Async$invokeLater(fn,receiver,arg){if(process!==void 0&&process.domain!=null&&!fn.domain){fn=process.domain.bind(fn)}this._lateBuffer.push(fn,receiver,arg);this._queueTick()};Async.prototype.invoke=function Async$invoke(fn,receiver,arg){if(process!==void 0&&process.domain!=null&&!fn.domain){fn=process.domain.bind(fn)}var functionBuffer=this._functionBuffer;functionBuffer.push(fn,receiver,arg);this._length=functionBuffer.length();this._queueTick()};Async.prototype._consumeFunctionBuffer=function Async$_consumeFunctionBuffer(){var functionBuffer=this._functionBuffer;while(functionBuffer.length()>0){var fn=functionBuffer.shift();var receiver=functionBuffer.shift();var arg=functionBuffer.shift();fn.call(receiver,arg)}this._reset();this._consumeLateBuffer()};Async.prototype._consumeLateBuffer=function Async$_consumeLateBuffer(){var buffer=this._lateBuffer;while(buffer.length()>0){var fn=buffer.shift();var receiver=buffer.shift();var arg=buffer.shift();var res=tryCatch1(fn,receiver,arg);if(res===errorObj){this._queueTick();if(fn.domain!=null){fn.domain.emit("error",res.e)}else{throw res.e}}}};Async.prototype._queueTick=function Async$_queue(){if(!this._isTickUsed){schedule(this.consumeFunctionBuffer);this._isTickUsed=true}};Async.prototype._reset=function Async$_reset(){this._isTickUsed=false;this._length=0};module.exports=new Async},{"./global.js":15,"./queue.js":27,"./schedule.js":30,"./util.js":38}],3:[function(require,module,exports){"use strict";var Promise=require("./promise.js")();module.exports=Promise},{"./promise.js":19}],4:[function(require,module,exports){"use strict";module.exports=function(Promise){Promise.prototype.call=function Promise$call(propertyName){var $_len=arguments.length;var args=new Array($_len-1);for(var $_i=1;$_i<$_len;++$_i){args[$_i-1]=arguments[$_i]}return this._then(function(obj){return obj[propertyName].apply(obj,args)},void 0,void 0,void 0,void 0,this.call)};function Promise$getter(obj){var prop=typeof this==="string"?this:""+this;return obj[prop]}Promise.prototype.get=function Promise$get(propertyName){return this._then(Promise$getter,void 0,void 0,propertyName,void 0,this.get)}}},{}],5:[function(require,module,exports){"use strict";module.exports=function(Promise,INTERNAL){var errors=require("./errors.js");var async=require("./async.js");var CancellationError=errors.CancellationError;var SYNC_TOKEN={};Promise.prototype._cancel=function Promise$_cancel(){if(!this.isCancellable())return this;var parent;if((parent=this._cancellationParent)!==void 0){parent.cancel(SYNC_TOKEN);return}var err=new CancellationError;this._attachExtraTrace(err);this._rejectUnchecked(err)};Promise.prototype.cancel=function Promise$cancel(token){if(!this.isCancellable())return this;if(token===SYNC_TOKEN){this._cancel();return this}async.invokeLater(this._cancel,this,void 0);return this};Promise.prototype.cancellable=function Promise$cancellable(){if(this._cancellable())return this;this._setCancellable();this._cancellationParent=void 0;return this};Promise.prototype.uncancellable=function Promise$uncancellable(){var ret=new Promise(INTERNAL);ret._setTrace(this.uncancellable,this);ret._follow(this);ret._unsetCancellable();if(this._isBound())ret._setBoundTo(this._boundTo);return ret};Promise.prototype.fork=function Promise$fork(didFulfill,didReject,didProgress){var ret=this._then(didFulfill,didReject,didProgress,void 0,void 0,this.fork);ret._setCancellable();ret._cancellationParent=void 0;return ret}}},{"./async.js":2,"./errors.js":9}],6:[function(require,module,exports){"use strict";module.exports=function(){var inherits=require("./util.js").inherits;var defineProperty=require("./es5.js").defineProperty;var rignore=new RegExp("\\b(?:[\\w.]*Promise(?:Array|Spawn)?\\$_\\w+|"+"tryCatch(?:1|2|Apply)|new \\w*PromiseArray|"+"\\w*PromiseArray\\.\\w*PromiseArray|"+"setTimeout|CatchFilter\\$_\\w+|makeNodePromisified|processImmediate|"+"process._tickCallback|nextTick|Async\\$\\w+)\\b");var rtraceline=null;var formatStack=null;var areNamesMangled=false;function formatNonError(obj){var str;if(typeof obj==="function"){str="[function "+(obj.name||"anonymous")+"]"}else{str=obj.toString();var ruselessToString=/\[object [a-zA-Z0-9$_]+\]/;if(ruselessToString.test(str)){try{var newStr=JSON.stringify(obj);str=newStr}catch(e){}}if(str.length===0){str="(empty array)"}}return"(<"+snip(str)+">, no stack trace)"}function snip(str){var maxChars=41;if(str.length=0;--i){var line=prev[i];if(current[curLast]===line){current.pop();curLast--}else{break}}current.push("From previous event:");var lines=current.concat(prev);var ret=[];for(var i=0,len=lines.length;i0&&!rtraceline.test(lines[i])&&lines[i]!=="From previous event:"){continue}ret.push(lines[i])}return ret};CapturedTrace.isSupported=function CapturedTrace$IsSupported(){return typeof captureStackTrace==="function"};var captureStackTrace=function stackDetection(){if(typeof Error.stackTraceLimit==="number"&&typeof Error.captureStackTrace==="function"){rtraceline=/^\s*at\s*/;formatStack=function(stack,error){if(typeof stack==="string")return stack;if(error.name!==void 0&&error.message!==void 0){return error.name+". "+error.message}return formatNonError(error)};var captureStackTrace=Error.captureStackTrace;return function CapturedTrace$_captureStackTrace(receiver,ignoreUntil){captureStackTrace(receiver,ignoreUntil)}}var err=new Error;if(!areNamesMangled&&typeof err.stack==="string"&&typeof"".startsWith==="function"&&err.stack.startsWith("stackDetection@")&&stackDetection.name==="stackDetection"){defineProperty(Error,"stackTraceLimit",{writable:true,enumerable:false,configurable:false,value:25});rtraceline=/@/;var rline=/[@\n]/;formatStack=function(stack,error){if(typeof stack==="string"){return error.name+". "+error.message+"\n"+stack}if(error.name!==void 0&&error.message!==void 0){return error.name+". "+error.message}return formatNonError(error)};return function captureStackTrace(o,fn){var name=fn.name;var stack=(new Error).stack;var split=stack.split(rline);var i,len=split.length;for(i=0;i=0}return false}function Promise(resolver){if(typeof resolver!=="function"){throw new TypeError("the promise constructor requires a resolver function")}if(this.constructor!==Promise){throw new TypeError("the promise constructor cannot be invoked directly")}this._bitField=0;this._fulfillmentHandler0=void 0;this._rejectionHandler0=void 0;this._promise0=void 0;this._receiver0=void 0;this._settledValue=void 0;this._boundTo=void 0;if(resolver!==INTERNAL)this._resolveFromResolver(resolver)}Promise.prototype.bind=function Promise$bind(thisArg){var ret=new Promise(INTERNAL);if(debugging)ret._setTrace(this.bind,this);ret._follow(this);ret._setBoundTo(thisArg);if(this._cancellable()){ret._setCancellable();ret._cancellationParent=this}return ret};Promise.prototype.toString=function Promise$toString(){return"[object Promise]"};Promise.prototype.caught=Promise.prototype["catch"]=function Promise$catch(fn){var len=arguments.length;if(len>1){var catchInstances=new Array(len-1),j=0,i;for(i=0;i0};Promise.prototype.isRejected=function Promise$isRejected(){return(this._bitField&134217728)>0};Promise.prototype.isPending=function Promise$isPending(){return!this.isResolved()};Promise.prototype.isResolved=function Promise$isResolved(){return(this._bitField&402653184)>0};Promise.prototype.isCancellable=function Promise$isCancellable(){return!this.isResolved()&&this._cancellable()};Promise.prototype.toJSON=function Promise$toJSON(){var ret={isFulfilled:false,isRejected:false,fulfillmentValue:void 0,rejectionReason:void 0};if(this.isFulfilled()){ret.fulfillmentValue=this._settledValue;ret.isFulfilled=true}else if(this.isRejected()){ret.rejectionReason=this._settledValue;ret.isRejected=true}return ret};Promise.prototype.all=function Promise$all(){return Promise$_all(this,true,this.all)};Promise.is=isPromise;function Promise$_all(promises,useBound,caller){return Promise$_CreatePromiseArray(promises,PromiseArray,caller,useBound===true&&promises._isBound()?promises._boundTo:void 0).promise()}Promise.all=function Promise$All(promises){return Promise$_all(promises,false,Promise.all)};Promise.join=function Promise$Join(){var $_len=arguments.length;var args=new Array($_len);for(var $_i=0;$_i<$_len;++$_i){args[$_i]=arguments[$_i]}return Promise$_CreatePromiseArray(args,PromiseArray,Promise.join,void 0).promise()};Promise.resolve=Promise.fulfilled=function Promise$Resolve(value,caller){var ret=new Promise(INTERNAL);if(debugging)ret._setTrace(typeof caller==="function"?caller:Promise.resolve,void 0);if(ret._tryFollow(value)){return ret}ret._cleanValues();ret._setFulfilled();ret._settledValue=value;return ret};Promise.reject=Promise.rejected=function Promise$Reject(reason){var ret=new Promise(INTERNAL);if(debugging)ret._setTrace(Promise.reject,void 0);markAsOriginatingFromRejection(reason);ret._cleanValues();ret._setRejected();ret._settledValue=reason;if(!canAttach(reason)){var trace=new Error(reason+"");ret._setCarriedStackTrace(trace)}ret._ensurePossibleRejectionHandled();return ret};Promise.prototype.error=function Promise$_error(fn){return this.caught(originatesFromRejection,fn)};Promise.prototype._resolveFromSyncValue=function Promise$_resolveFromSyncValue(value,caller){if(value===errorObj){this._cleanValues();this._setRejected();this._settledValue=value.e;this._ensurePossibleRejectionHandled()}else{var maybePromise=Promise._cast(value,caller,void 0);if(maybePromise instanceof Promise){this._follow(maybePromise)}else{this._cleanValues();this._setFulfilled();this._settledValue=value}}};Promise.method=function Promise$_Method(fn){if(typeof fn!=="function"){throw new TypeError("fn must be a function")}return function Promise$_method(){var value;switch(arguments.length){case 0:value=tryCatch1(fn,this,void 0);break;case 1:value=tryCatch1(fn,this,arguments[0]);break;case 2:value=tryCatch2(fn,this,arguments[0],arguments[1]);break;default:var $_len=arguments.length;var args=new Array($_len);for(var $_i=0;$_i<$_len;++$_i){args[$_i]=arguments[$_i]}value=tryCatchApply(fn,args,this);break}var ret=new Promise(INTERNAL);if(debugging)ret._setTrace(Promise$_method,void 0);ret._resolveFromSyncValue(value,Promise$_method);return ret}};Promise.attempt=Promise["try"]=function Promise$_Try(fn,args,ctx){if(typeof fn!=="function"){return apiRejection("fn must be a function")}var value=isArray(args)?tryCatchApply(fn,args,ctx):tryCatch1(fn,ctx,args);var ret=new Promise(INTERNAL);if(debugging)ret._setTrace(Promise.attempt,void 0);ret._resolveFromSyncValue(value,Promise.attempt);return ret};Promise.defer=Promise.pending=function Promise$Defer(caller){var promise=new Promise(INTERNAL);if(debugging)promise._setTrace(typeof caller==="function"?caller:Promise.defer,void 0);return new PromiseResolver(promise)};Promise.bind=function Promise$Bind(thisArg){var ret=new Promise(INTERNAL);if(debugging)ret._setTrace(Promise.bind,void 0);ret._setFulfilled();ret._setBoundTo(thisArg);return ret};Promise.cast=function Promise$_Cast(obj,caller){if(typeof caller!=="function"){caller=Promise.cast}var ret=Promise._cast(obj,caller,void 0);if(!(ret instanceof Promise)){return Promise.resolve(ret,caller)}return ret};Promise.onPossiblyUnhandledRejection=function Promise$OnPossiblyUnhandledRejection(fn){if(typeof fn==="function"){CapturedTrace.possiblyUnhandledRejection=fn}else{CapturedTrace.possiblyUnhandledRejection=void 0}};var debugging=false||!!(typeof process!=="undefined"&&typeof process.execPath==="string"&&typeof process.env==="object"&&(process.env["BLUEBIRD_DEBUG"]||process.env["NODE_ENV"]==="development"));Promise.longStackTraces=function Promise$LongStackTraces(){if(async.haveItemsQueued()&&debugging===false){throw new Error("cannot enable long stack traces after promises have been created")}debugging=CapturedTrace.isSupported()};Promise.hasLongStackTraces=function Promise$HasLongStackTraces(){return debugging&&CapturedTrace.isSupported()};Promise.prototype._setProxyHandlers=function Promise$_setProxyHandlers(receiver,promiseSlotValue){var index=this._length();if(index>=1048575-5){index=0;this._setLength(0)}if(index===0){this._promise0=promiseSlotValue;this._receiver0=receiver}else{var i=index-5;this[i+3]=promiseSlotValue;this[i+4]=receiver;this[i+0]=this[i+1]=this[i+2]=void 0}this._setLength(index+5)};Promise.prototype._proxyPromiseArray=function Promise$_proxyPromiseArray(promiseArray,index){this._setProxyHandlers(promiseArray,index)};Promise.prototype._proxyPromise=function Promise$_proxyPromise(promise){promise._setProxied();this._setProxyHandlers(promise,-1)};Promise.prototype._then=function Promise$_then(didFulfill,didReject,didProgress,receiver,internalData,caller){var haveInternalData=internalData!==void 0;var ret=haveInternalData?internalData:new Promise(INTERNAL);if(debugging&&!haveInternalData){var haveSameContext=this._peekContext()===this._traceParent;ret._traceParent=haveSameContext?this._traceParent:this;ret._setTrace(typeof caller==="function"?caller:this._then,this)}if(!haveInternalData&&this._isBound()){ret._setBoundTo(this._boundTo)}var callbackIndex=this._addCallbacks(didFulfill,didReject,didProgress,ret,receiver);if(!haveInternalData&&this._cancellable()){ret._setCancellable();ret._cancellationParent=this}if(this.isResolved()){async.invoke(this._queueSettleAt,this,callbackIndex)}return ret};Promise.prototype._length=function Promise$_length(){return this._bitField&1048575};Promise.prototype._isFollowingOrFulfilledOrRejected=function Promise$_isFollowingOrFulfilledOrRejected(){return(this._bitField&939524096)>0};Promise.prototype._isFollowing=function Promise$_isFollowing(){return(this._bitField&536870912)===536870912};Promise.prototype._setLength=function Promise$_setLength(len){this._bitField=this._bitField&-1048576|len&1048575};Promise.prototype._setFulfilled=function Promise$_setFulfilled(){this._bitField=this._bitField|268435456};Promise.prototype._setRejected=function Promise$_setRejected(){this._bitField=this._bitField|134217728};Promise.prototype._setFollowing=function Promise$_setFollowing(){this._bitField=this._bitField|536870912};Promise.prototype._setIsFinal=function Promise$_setIsFinal(){this._bitField=this._bitField|33554432};Promise.prototype._isFinal=function Promise$_isFinal(){return(this._bitField&33554432)>0};Promise.prototype._cancellable=function Promise$_cancellable(){return(this._bitField&67108864)>0};Promise.prototype._setCancellable=function Promise$_setCancellable(){this._bitField=this._bitField|67108864};Promise.prototype._unsetCancellable=function Promise$_unsetCancellable(){this._bitField=this._bitField&~67108864};Promise.prototype._setRejectionIsUnhandled=function Promise$_setRejectionIsUnhandled(){this._bitField=this._bitField|2097152};Promise.prototype._unsetRejectionIsUnhandled=function Promise$_unsetRejectionIsUnhandled(){this._bitField=this._bitField&~2097152};Promise.prototype._isRejectionUnhandled=function Promise$_isRejectionUnhandled(){return(this._bitField&2097152)>0};Promise.prototype._setCarriedStackTrace=function Promise$_setCarriedStackTrace(capturedTrace){this._bitField=this._bitField|1048576;this._fulfillmentHandler0=capturedTrace};Promise.prototype._unsetCarriedStackTrace=function Promise$_unsetCarriedStackTrace(){this._bitField=this._bitField&~1048576;this._fulfillmentHandler0=void 0};Promise.prototype._isCarryingStackTrace=function Promise$_isCarryingStackTrace(){return(this._bitField&1048576)>0};Promise.prototype._getCarriedStackTrace=function Promise$_getCarriedStackTrace(){return this._isCarryingStackTrace()?this._fulfillmentHandler0:void 0};Promise.prototype._receiverAt=function Promise$_receiverAt(index){var ret;if(index===0){ret=this._receiver0}else{ret=this[index+4-5]}if(this._isBound()&&ret===void 0){return this._boundTo}return ret};Promise.prototype._promiseAt=function Promise$_promiseAt(index){if(index===0)return this._promise0;return this[index+3-5]};Promise.prototype._fulfillmentHandlerAt=function Promise$_fulfillmentHandlerAt(index){if(index===0)return this._fulfillmentHandler0;return this[index+0-5]};Promise.prototype._rejectionHandlerAt=function Promise$_rejectionHandlerAt(index){if(index===0)return this._rejectionHandler0;return this[index+1-5]};Promise.prototype._unsetAt=function Promise$_unsetAt(index){if(index===0){this._rejectionHandler0=this._progressHandler0=this._promise0=this._receiver0=void 0;if(!this._isCarryingStackTrace()){this._fulfillmentHandler0=void 0}}else{this[index-5+0]=this[index-5+1]=this[index-5+2]=this[index-5+3]=this[index-5+4]=void 0}};Promise.prototype._resolveFromResolver=function Promise$_resolveFromResolver(resolver){var promise=this;var localDebugging=debugging;if(localDebugging){this._setTrace(this._resolveFromResolver,void 0);this._pushContext()}function Promise$_resolver(val){if(promise._tryFollow(val)){return}promise._fulfill(val)}function Promise$_rejecter(val){var trace=canAttach(val)?val:new Error(val+"");promise._attachExtraTrace(trace);markAsOriginatingFromRejection(val);promise._reject(val,trace===val?void 0:trace)}var r=tryCatch2(resolver,void 0,Promise$_resolver,Promise$_rejecter);if(localDebugging)this._popContext();if(r!==void 0&&r===errorObj){var e=r.e;var trace=canAttach(e)?e:new Error(e+"");promise._reject(e,trace)}};Promise.prototype._addCallbacks=function Promise$_addCallbacks(fulfill,reject,progress,promise,receiver){var index=this._length();if(index>=1048575-5){index=0;this._setLength(0)}if(index===0){this._promise0=promise;if(receiver!==void 0)this._receiver0=receiver;if(typeof fulfill==="function"&&!this._isCarryingStackTrace())this._fulfillmentHandler0=fulfill;
-if(typeof reject==="function")this._rejectionHandler0=reject;if(typeof progress==="function")this._progressHandler0=progress}else{var i=index-5;this[i+3]=promise;this[i+4]=receiver;this[i+0]=typeof fulfill==="function"?fulfill:void 0;this[i+1]=typeof reject==="function"?reject:void 0;this[i+2]=typeof progress==="function"?progress:void 0}this._setLength(index+5);return index};Promise.prototype._setBoundTo=function Promise$_setBoundTo(obj){if(obj!==void 0){this._bitField=this._bitField|8388608;this._boundTo=obj}else{this._bitField=this._bitField&~8388608}};Promise.prototype._isBound=function Promise$_isBound(){return(this._bitField&8388608)===8388608};Promise.prototype._spreadSlowCase=function Promise$_spreadSlowCase(targetFn,promise,values,boundTo){var promiseForAll=Promise$_CreatePromiseArray(values,PromiseArray,this._spreadSlowCase,boundTo).promise()._then(function(){return targetFn.apply(boundTo,arguments)},void 0,void 0,APPLY,void 0,this._spreadSlowCase);promise._follow(promiseForAll)};Promise.prototype._callSpread=function Promise$_callSpread(handler,promise,value,localDebugging){var boundTo=this._isBound()?this._boundTo:void 0;if(isArray(value)){var caller=this._settlePromiseFromHandler;for(var i=0,len=value.length;imax){stack.length=max}if(stack.length<=headerLineCount){error.stack="(No stack trace)"}else{error.stack=stack.join("\n")}}};Promise.prototype._cleanValues=function Promise$_cleanValues(){if(this._cancellable()){this._cancellationParent=void 0}};Promise.prototype._fulfill=function Promise$_fulfill(value){if(this._isFollowingOrFulfilledOrRejected())return;this._fulfillUnchecked(value)};Promise.prototype._reject=function Promise$_reject(reason,carriedStackTrace){if(this._isFollowingOrFulfilledOrRejected())return;this._rejectUnchecked(reason,carriedStackTrace)};Promise.prototype._settlePromiseAt=function Promise$_settlePromiseAt(index){var handler=this.isFulfilled()?this._fulfillmentHandlerAt(index):this._rejectionHandlerAt(index);var value=this._settledValue;var receiver=this._receiverAt(index);var promise=this._promiseAt(index);if(typeof handler==="function"){this._settlePromiseFromHandler(handler,receiver,value,promise)}else{var done=false;var isFulfilled=this.isFulfilled();if(receiver!==void 0){if(receiver instanceof Promise&&receiver._isProxied()){receiver._unsetProxied();if(isFulfilled)receiver._fulfillUnchecked(value);else receiver._rejectUnchecked(value,this._getCarriedStackTrace());done=true}else if(isPromiseArrayProxy(receiver,promise)){if(isFulfilled)receiver._promiseFulfilled(value,promise);else receiver._promiseRejected(value,promise);done=true}}if(!done){if(isFulfilled)promise._fulfill(value);else promise._reject(value,this._getCarriedStackTrace())}}if(index>=256){this._queueGC()}};Promise.prototype._isProxied=function Promise$_isProxied(){return(this._bitField&4194304)===4194304};Promise.prototype._setProxied=function Promise$_setProxied(){this._bitField=this._bitField|4194304};Promise.prototype._unsetProxied=function Promise$_unsetProxied(){this._bitField=this._bitField&~4194304};Promise.prototype._isGcQueued=function Promise$_isGcQueued(){return(this._bitField&-1073741824)===-1073741824};Promise.prototype._setGcQueued=function Promise$_setGcQueued(){this._bitField=this._bitField|-1073741824};Promise.prototype._unsetGcQueued=function Promise$_unsetGcQueued(){this._bitField=this._bitField&~-1073741824};Promise.prototype._queueGC=function Promise$_queueGC(){if(this._isGcQueued())return;this._setGcQueued();async.invokeLater(this._gc,this,void 0)};Promise.prototype._gc=function Promise$gc(){var len=this._length();this._unsetAt(0);for(var i=0;i0){async.invoke(this._fulfillPromises,this,len)}};Promise.prototype._rejectUncheckedCheckError=function Promise$_rejectUncheckedCheckError(reason){var trace=canAttach(reason)?reason:new Error(reason+"");this._rejectUnchecked(reason,trace===reason?void 0:trace)};Promise.prototype._rejectUnchecked=function Promise$_rejectUnchecked(reason,trace){if(!this.isPending())return;if(reason===this){var err=makeSelfResolutionError();this._attachExtraTrace(err);return this._rejectUnchecked(err)}this._cleanValues();this._setRejected();this._settledValue=reason;if(this._isFinal()){async.invokeLater(thrower,void 0,trace===void 0?reason:trace);return}var len=this._length();if(trace!==void 0)this._setCarriedStackTrace(trace);if(len>0){async.invoke(this._rejectPromises,this,null)}else{this._ensurePossibleRejectionHandled()}};Promise.prototype._rejectPromises=function Promise$_rejectPromises(){var len=this._length();for(var i=0;i=0){return contextStack[lastIndex]}return void 0};Promise.prototype._pushContext=function Promise$_pushContext(){if(!debugging)return;contextStack.push(this)};Promise.prototype._popContext=function Promise$_popContext(){if(!debugging)return;contextStack.pop()};function Promise$_CreatePromiseArray(promises,PromiseArrayConstructor,caller,boundTo){var list=null;if(isArray(promises)){list=promises}else{list=Promise._cast(promises,caller,void 0);if(list!==promises){list._setBoundTo(boundTo)}else if(!isPromise(list)){list=null}}if(list!==null){return new PromiseArrayConstructor(list,typeof caller==="function"?caller:Promise$_CreatePromiseArray,boundTo)}return{promise:function(){return apiRejection("expecting an array, a promise or a thenable")}}}var old=global.Promise;Promise.noConflict=function(){if(global.Promise===Promise){global.Promise=old}return Promise};if(!CapturedTrace.isSupported()){Promise.longStackTraces=function(){};debugging=false}Promise._makeSelfResolutionError=makeSelfResolutionError;require("./finally.js")(Promise,NEXT_FILTER);require("./direct_resolve.js")(Promise);require("./thenables.js")(Promise,INTERNAL);Promise.RangeError=RangeError;Promise.CancellationError=CancellationError;Promise.TimeoutError=TimeoutError;Promise.TypeError=TypeError;Promise.RejectionError=RejectionError;util.toFastProperties(Promise);util.toFastProperties(Promise.prototype);require("./timers.js")(Promise,INTERNAL);require("./synchronous_inspection.js")(Promise);require("./any.js")(Promise,Promise$_CreatePromiseArray,PromiseArray);require("./race.js")(Promise,INTERNAL);require("./call_get.js")(Promise);require("./filter.js")(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection);require("./generators.js")(Promise,apiRejection,INTERNAL);require("./map.js")(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection);require("./nodeify.js")(Promise);require("./promisify.js")(Promise,INTERNAL);require("./props.js")(Promise,PromiseArray);require("./reduce.js")(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection,INTERNAL);require("./settle.js")(Promise,Promise$_CreatePromiseArray,PromiseArray);require("./some.js")(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection);require("./progress.js")(Promise,isPromiseArrayProxy);require("./cancel.js")(Promise,INTERNAL);Promise.prototype=Promise.prototype;return Promise}},{"./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,"./errors.js":9,"./errors_api_rejection":10,"./filter.js":12,"./finally.js":13,"./generators.js":14,"./global.js":15,"./map.js":16,"./nodeify.js":17,"./progress.js":18,"./promise_array.js":20,"./promise_resolver.js":22,"./promisify.js":24,"./props.js":26,"./race.js":28,"./reduce.js":29,"./settle.js":31,"./some.js":33,"./synchronous_inspection.js":35,"./thenables.js":36,"./timers.js":37,"./util.js":38}],20:[function(require,module,exports){"use strict";module.exports=function(Promise,INTERNAL){var canAttach=require("./errors.js").canAttach;var util=require("./util.js");var async=require("./async.js");var hasOwn={}.hasOwnProperty;var isArray=util.isArray;function toResolutionValue(val){switch(val){case-1:return void 0;case-2:return[];case-3:return{}}}function PromiseArray(values,caller,boundTo){var promise=this._promise=new Promise(INTERNAL);var parent=void 0;if(Promise.is(values)){parent=values;if(values._cancellable()){promise._setCancellable();promise._cancellationParent=values}if(values._isBound()){promise._setBoundTo(boundTo)}}promise._setTrace(caller,parent);this._values=values;this._length=0;this._totalResolved=0;this._init(void 0,-2)}PromiseArray.PropertiesPromiseArray=function(){};PromiseArray.prototype.length=function PromiseArray$length(){return this._length};PromiseArray.prototype.promise=function PromiseArray$promise(){return this._promise};PromiseArray.prototype._init=function PromiseArray$_init(_,resolveValueIfEmpty){var values=this._values;if(Promise.is(values)){if(values.isFulfilled()){values=values._settledValue;if(!isArray(values)){var err=new Promise.TypeError("expecting an array, a promise or a thenable");this.__hardReject__(err);return}this._values=values}else if(values.isPending()){values._then(this._init,this._reject,void 0,this,resolveValueIfEmpty,this.constructor);return}else{this._reject(values._settledValue);return}}if(values.length===0){this._resolve(toResolutionValue(resolveValueIfEmpty));return}var len=values.length;var newLen=len;var newValues;if(this instanceof PromiseArray.PropertiesPromiseArray){newValues=this._values}else{newValues=new Array(len)}var isDirectScanNeeded=false;for(var i=0;i=this._length){this._resolve(this._values)}};PromiseArray.prototype._promiseRejected=function PromiseArray$_promiseRejected(reason,index){if(this._isResolved())return;this._totalResolved++;this._reject(reason)};return PromiseArray}},{"./async.js":2,"./errors.js":9,"./util.js":38}],21:[function(require,module,exports){"use strict";var TypeError=require("./errors.js").TypeError;function PromiseInspection(promise){if(promise!==void 0){this._bitField=promise._bitField;this._settledValue=promise.isResolved()?promise._settledValue:void 0}else{this._bitField=0;this._settledValue=void 0}}PromiseInspection.prototype.isFulfilled=function PromiseInspection$isFulfilled(){return(this._bitField&268435456)>0};PromiseInspection.prototype.isRejected=function PromiseInspection$isRejected(){return(this._bitField&134217728)>0};PromiseInspection.prototype.isPending=function PromiseInspection$isPending(){return(this._bitField&402653184)===0};PromiseInspection.prototype.value=function PromiseInspection$value(){if(!this.isFulfilled()){throw new TypeError("cannot get fulfillment value of a non-fulfilled promise")}return this._settledValue};PromiseInspection.prototype.error=function PromiseInspection$error(){if(!this.isRejected()){throw new TypeError("cannot get rejection reason of a non-rejected promise")}return this._settledValue};module.exports=PromiseInspection},{"./errors.js":9}],22:[function(require,module,exports){"use strict";var util=require("./util.js");var maybeWrapAsError=util.maybeWrapAsError;var errors=require("./errors.js");var TimeoutError=errors.TimeoutError;var RejectionError=errors.RejectionError;var async=require("./async.js");var haveGetters=util.haveGetters;var es5=require("./es5.js");function isUntypedError(obj){return obj instanceof Error&&es5.getPrototypeOf(obj)===Error.prototype}function wrapAsRejectionError(obj){var ret;if(isUntypedError(obj)){ret=new RejectionError(obj)}else{ret=obj}errors.markAsOriginatingFromRejection(ret);return ret}function nodebackForPromise(promise){function PromiseResolver$_callback(err,value){if(promise===null)return;if(err){var wrapped=wrapAsRejectionError(maybeWrapAsError(err));promise._attachExtraTrace(wrapped);promise._reject(wrapped)}else{if(arguments.length>2){var $_len=arguments.length;var args=new Array($_len-1);for(var $_i=1;$_i<$_len;++$_i){args[$_i-1]=arguments[$_i]}promise._fulfill(args)}else{promise._fulfill(value)}}promise=null}return PromiseResolver$_callback}var PromiseResolver;if(!haveGetters){PromiseResolver=function PromiseResolver(promise){this.promise=promise;this.asCallback=nodebackForPromise(promise);this.callback=this.asCallback}}else{PromiseResolver=function PromiseResolver(promise){this.promise=promise}}if(haveGetters){var prop={get:function(){return nodebackForPromise(this.promise)}};es5.defineProperty(PromiseResolver.prototype,"asCallback",prop);es5.defineProperty(PromiseResolver.prototype,"callback",prop)}PromiseResolver._nodebackForPromise=nodebackForPromise;PromiseResolver.prototype.toString=function PromiseResolver$toString(){return"[object PromiseResolver]"};PromiseResolver.prototype.resolve=PromiseResolver.prototype.fulfill=function PromiseResolver$resolve(value){var promise=this.promise;if(promise._tryFollow(value)){return}async.invoke(promise._fulfill,promise,value)};PromiseResolver.prototype.reject=function PromiseResolver$reject(reason){var promise=this.promise;errors.markAsOriginatingFromRejection(reason);var trace=errors.canAttach(reason)?reason:new Error(reason+"");promise._attachExtraTrace(trace);async.invoke(promise._reject,promise,reason);if(trace!==reason){async.invoke(this._setCarriedStackTrace,this,trace)}};PromiseResolver.prototype.progress=function PromiseResolver$progress(value){async.invoke(this.promise._progress,this.promise,value)};PromiseResolver.prototype.cancel=function PromiseResolver$cancel(){async.invoke(this.promise.cancel,this.promise,void 0)};PromiseResolver.prototype.timeout=function PromiseResolver$timeout(){this.reject(new TimeoutError("timeout"))};PromiseResolver.prototype.isResolved=function PromiseResolver$isResolved(){return this.promise.isResolved()};PromiseResolver.prototype.toJSON=function PromiseResolver$toJSON(){return this.promise.toJSON()};PromiseResolver.prototype._setCarriedStackTrace=function PromiseResolver$_setCarriedStackTrace(trace){if(this.promise.isRejected()){this.promise._setCarriedStackTrace(trace)}};module.exports=PromiseResolver},{"./async.js":2,"./errors.js":9,"./es5.js":11,"./util.js":38}],23:[function(require,module,exports){"use strict";module.exports=function(Promise,INTERNAL){var errors=require("./errors.js");var TypeError=errors.TypeError;var util=require("./util.js");var isArray=util.isArray;var errorObj=util.errorObj;var tryCatch1=util.tryCatch1;var yieldHandlers=[];function promiseFromYieldHandler(value){var _yieldHandlers=yieldHandlers;var _errorObj=errorObj;var _Promise=Promise;var len=_yieldHandlers.length;for(var i=0;i=min;--i){if(i===likelyArgumentCount)continue;ret.push(i)}for(var i=likelyArgumentCount+1;i<=5;++i){ret.push(i)}return ret}function parameterDeclaration(parameterCount){var ret=new Array(parameterCount);for(var i=0;i0?",":"";if(typeof callback==="string"&&receiver===THIS){return"this"+propertyAccess(callback)+"("+args.join(",")+comma+" fn);"+"break;"}return(receiver===void 0?"callback("+args.join(",")+comma+" fn);":"callback.call("+(receiver===THIS?"this":"receiver")+", "+args.join(",")+comma+" fn);")+"break;"}function generateArgumentSwitchCase(){var ret="";for(var i=0;i=this._length){var val={};var keyOffset=this.length();for(var i=0,len=this.length();i>>0;n=n-1;n=n|n>>1;n=n|n>>2;n=n|n>>4;n=n|n>>8;n=n|n>>16;return n+1}function getCapacity(capacity){if(typeof capacity!=="number")return 16;return pow2AtLeast(Math.min(Math.max(16,capacity),1073741824))}function Queue(capacity){this._capacity=getCapacity(capacity);this._length=0;this._front=0;this._makeCapacity()}Queue.prototype._willBeOverCapacity=function Queue$_willBeOverCapacity(size){return this._capacity0)accum=fulfilleds[0]}var i=startIndex;if(i>=len){return accum}var reduction=new Reduction(fn,i,accum,fulfilleds,receiver);reduction.iterate();return reduction.promise}function Promise$_unpackReducer(fulfilleds){var fn=this.fn;var initialValue=this.initialValue;return Promise$_reducer.call(fn,fulfilleds,initialValue)}function Promise$_slowReduce(promises,fn,initialValue,useBound,caller){return initialValue._then(function callee(initialValue){return Promise$_Reduce(promises,fn,initialValue,useBound,callee)},void 0,void 0,void 0,void 0,caller)}function Promise$_Reduce(promises,fn,initialValue,useBound,caller){if(typeof fn!=="function"){return apiRejection("fn must be a function")}if(useBound===true&&promises._isBound()){fn={fn:fn,receiver:promises._boundTo}}if(initialValue!==void 0){if(Promise.is(initialValue)){if(initialValue.isFulfilled()){initialValue=initialValue._settledValue}else{return Promise$_slowReduce(promises,fn,initialValue,useBound,caller)}}return Promise$_CreatePromiseArray(promises,PromiseArray,caller,useBound===true&&promises._isBound()?promises._boundTo:void 0).promise()._then(Promise$_unpackReducer,void 0,void 0,{fn:fn,initialValue:initialValue},void 0,Promise.reduce)}return Promise$_CreatePromiseArray(promises,PromiseArray,caller,useBound===true&&promises._isBound()?promises._boundTo:void 0).promise()._then(Promise$_reducer,void 0,void 0,fn,void 0,caller)}Promise.reduce=function Promise$Reduce(promises,fn,initialValue){return Promise$_Reduce(promises,fn,initialValue,false,Promise.reduce)};Promise.prototype.reduce=function Promise$reduce(fn,initialValue){return Promise$_Reduce(this,fn,initialValue,true,this.reduce)}}},{}],30:[function(require,module,exports){"use strict";var global=require("./global.js");var schedule;if(typeof process!=="undefined"&&process!==null&&typeof process.cwd==="function"&&typeof process.nextTick==="function"&&typeof process.version==="string"){schedule=function Promise$_Scheduler(fn){process.nextTick(fn)}}else if((typeof global.MutationObserver==="function"||typeof global.WebkitMutationObserver==="function"||typeof global.WebKitMutationObserver==="function")&&typeof document!=="undefined"&&typeof document.createElement==="function"){schedule=function(){var MutationObserver=global.MutationObserver||global.WebkitMutationObserver||global.WebKitMutationObserver;var div=document.createElement("div");var queuedFn=void 0;var observer=new MutationObserver(function Promise$_Scheduler(){var fn=queuedFn;queuedFn=void 0;fn()});observer.observe(div,{attributes:true});return function Promise$_Scheduler(fn){queuedFn=fn;div.setAttribute("class","foo")}}()}else if(typeof global.postMessage==="function"&&typeof global.importScripts!=="function"&&typeof global.addEventListener==="function"&&typeof global.removeEventListener==="function"){var MESSAGE_KEY="bluebird_message_key_"+Math.random();schedule=function(){var queuedFn=void 0;function Promise$_Scheduler(e){if(e.source===global&&e.data===MESSAGE_KEY){var fn=queuedFn;queuedFn=void 0;fn()}}global.addEventListener("message",Promise$_Scheduler,false);return function Promise$_Scheduler(fn){queuedFn=fn;global.postMessage(MESSAGE_KEY,"*")}}()}else if(typeof global.MessageChannel==="function"){schedule=function(){var queuedFn=void 0;var channel=new global.MessageChannel;channel.port1.onmessage=function Promise$_Scheduler(){var fn=queuedFn;queuedFn=void 0;fn()};return function Promise$_Scheduler(fn){queuedFn=fn;channel.port2.postMessage(null)}}()}else if(global.setTimeout){schedule=function Promise$_Scheduler(fn){setTimeout(fn,4)}}else{schedule=function Promise$_Scheduler(fn){fn()}}module.exports=schedule},{"./global.js":15}],31:[function(require,module,exports){"use strict";module.exports=function(Promise,Promise$_CreatePromiseArray,PromiseArray){var SettledPromiseArray=require("./settled_promise_array.js")(Promise,PromiseArray);function Promise$_Settle(promises,useBound,caller){return Promise$_CreatePromiseArray(promises,SettledPromiseArray,caller,useBound===true&&promises._isBound()?promises._boundTo:void 0).promise()}Promise.settle=function Promise$Settle(promises){return Promise$_Settle(promises,false,Promise.settle)};Promise.prototype.settle=function Promise$settle(){return Promise$_Settle(this,true,this.settle)}}},{"./settled_promise_array.js":32}],32:[function(require,module,exports){"use strict";module.exports=function(Promise,PromiseArray){var PromiseInspection=require("./promise_inspection.js");var util=require("./util.js");var inherits=util.inherits;function SettledPromiseArray(values,caller,boundTo){this.constructor$(values,caller,boundTo)}inherits(SettledPromiseArray,PromiseArray);SettledPromiseArray.prototype._promiseResolved=function SettledPromiseArray$_promiseResolved(index,inspection){this._values[index]=inspection;var totalResolved=++this._totalResolved;if(totalResolved>=this._length){this._resolve(this._values)}};SettledPromiseArray.prototype._promiseFulfilled=function SettledPromiseArray$_promiseFulfilled(value,index){if(this._isResolved())return;var ret=new PromiseInspection;ret._bitField=268435456;ret._settledValue=value;this._promiseResolved(index,ret)};SettledPromiseArray.prototype._promiseRejected=function SettledPromiseArray$_promiseRejected(reason,index){if(this._isResolved())return;var ret=new PromiseInspection;ret._bitField=134217728;ret._settledValue=reason;this._promiseResolved(index,ret)};return SettledPromiseArray}},{"./promise_inspection.js":21,"./util.js":38}],33:[function(require,module,exports){"use strict";module.exports=function(Promise,Promise$_CreatePromiseArray,PromiseArray,apiRejection){var SomePromiseArray=require("./some_promise_array.js")(PromiseArray);function Promise$_Some(promises,howMany,useBound,caller){if((howMany|0)!==howMany||howMany<0){return apiRejection("expecting a positive integer")}var ret=Promise$_CreatePromiseArray(promises,SomePromiseArray,caller,useBound===true&&promises._isBound()?promises._boundTo:void 0);var promise=ret.promise();if(promise.isRejected()){return promise}ret.setHowMany(howMany);ret.init();return promise}Promise.some=function Promise$Some(promises,howMany){return Promise$_Some(promises,howMany,false,Promise.some)};Promise.prototype.some=function Promise$some(count){return Promise$_Some(this,count,true,this.some)}}},{"./some_promise_array.js":34}],34:[function(require,module,exports){"use strict";module.exports=function(PromiseArray){var util=require("./util.js");var RangeError=require("./errors.js").RangeError;var inherits=util.inherits;var isArray=util.isArray;function SomePromiseArray(values,caller,boundTo){this.constructor$(values,caller,boundTo);this._howMany=0;this._unwrap=false;this._initialized=false}inherits(SomePromiseArray,PromiseArray);SomePromiseArray.prototype._init=function SomePromiseArray$_init(){if(!this._initialized){return}if(this._howMany===0){this._resolve([]);return}this._init$(void 0,-2);var isArrayResolved=isArray(this._values);this._holes=isArrayResolved?this._values.length-this.length():0;if(!this._isResolved()&&isArrayResolved&&this._howMany>this._canPossiblyFulfill()){var message="(Promise.some) input array contains less than "+this._howMany+" promises";this._reject(new RangeError(message))}};SomePromiseArray.prototype.init=function SomePromiseArray$init(){this._initialized=true;this._init()};SomePromiseArray.prototype.setUnwrap=function SomePromiseArray$setUnwrap(){this._unwrap=true};SomePromiseArray.prototype.howMany=function SomePromiseArray$howMany(){return this._howMany};SomePromiseArray.prototype.setHowMany=function SomePromiseArray$setHowMany(count){if(this._isResolved())return;this._howMany=count};SomePromiseArray.prototype._promiseFulfilled=function SomePromiseArray$_promiseFulfilled(value){if(this._isResolved())return;this._addFulfilled(value);if(this._fulfilled()===this.howMany()){this._values.length=this.howMany();if(this.howMany()===1&&this._unwrap){this._resolve(this._values[0])}else{this._resolve(this._values)}}};SomePromiseArray.prototype._promiseRejected=function SomePromiseArray$_promiseRejected(reason){if(this._isResolved())return;this._addRejected(reason);if(this.howMany()>this._canPossiblyFulfill()){if(this._values.length===this.length()){this._reject([])}else{this._reject(this._values.slice(this.length()+this._holes))}}};SomePromiseArray.prototype._fulfilled=function SomePromiseArray$_fulfilled(){return this._totalResolved};SomePromiseArray.prototype._rejected=function SomePromiseArray$_rejected(){return this._values.length-this.length()-this._holes};SomePromiseArray.prototype._addRejected=function SomePromiseArray$_addRejected(reason){this._values.push(reason)};SomePromiseArray.prototype._addFulfilled=function SomePromiseArray$_addFulfilled(value){this._values[this._totalResolved++]=value};SomePromiseArray.prototype._canPossiblyFulfill=function SomePromiseArray$_canPossiblyFulfill(){return this.length()-this._rejected()};return SomePromiseArray}},{"./errors.js":9,"./util.js":38}],35:[function(require,module,exports){"use strict";module.exports=function(Promise){var PromiseInspection=require("./promise_inspection.js");Promise.prototype.inspect=function Promise$inspect(){return new PromiseInspection(this)}}},{"./promise_inspection.js":21}],36:[function(require,module,exports){"use strict";module.exports=function(Promise,INTERNAL){var util=require("./util.js");var canAttach=require("./errors.js").canAttach;var errorObj=util.errorObj;var isObject=util.isObject;function getThen(obj){try{return obj.then}catch(e){errorObj.e=e;return errorObj}}function Promise$_Cast(obj,caller,originalPromise){if(isObject(obj)){if(obj instanceof Promise){return obj}else if(isAnyBluebirdPromise(obj)){var ret=new Promise(INTERNAL);ret._setTrace(caller,void 0);obj._then(ret._fulfillUnchecked,ret._rejectUncheckedCheckError,ret._progressUnchecked,ret,null,void 0);ret._setFollowing();return ret}var then=getThen(obj);if(then===errorObj){caller=typeof caller==="function"?caller:Promise$_Cast;if(originalPromise!==void 0&&canAttach(then.e)){originalPromise._attachExtraTrace(then.e)}return Promise.reject(then.e,caller)}else if(typeof then==="function"){caller=typeof caller==="function"?caller:Promise$_Cast;return Promise$_doThenable(obj,then,caller,originalPromise)}}return obj}var hasProp={}.hasOwnProperty;function isAnyBluebirdPromise(obj){return hasProp.call(obj,"_promise0")}function Promise$_doThenable(x,then,caller,originalPromise){var resolver=Promise.defer(caller);var called=false;try{then.call(x,Promise$_resolveFromThenable,Promise$_rejectFromThenable,Promise$_progressFromThenable)}catch(e){if(!called){called=true;var trace=canAttach(e)?e:new Error(e+"");if(originalPromise!==void 0){originalPromise._attachExtraTrace(trace)}resolver.promise._reject(e,trace)}}return resolver.promise;function Promise$_resolveFromThenable(y){if(called)return;called=true;if(x===y){var e=Promise._makeSelfResolutionError();if(originalPromise!==void 0){originalPromise._attachExtraTrace(e)}resolver.promise._reject(e,void 0);return}resolver.resolve(y)}function Promise$_rejectFromThenable(r){if(called)return;called=true;var trace=canAttach(r)?r:new Error(r+"");if(originalPromise!==void 0){originalPromise._attachExtraTrace(trace)}resolver.promise._reject(r,trace)}function Promise$_progressFromThenable(v){if(called)return;var promise=resolver.promise;if(typeof promise._progress==="function"){promise._progress(v)}}}Promise._cast=Promise$_Cast}},{"./errors.js":9,"./util.js":38}],37:[function(require,module,exports){"use strict";var global=require("./global.js");var setTimeout=function(fn,time){var $_len=arguments.length;var args=new Array($_len-2);for(var $_i=2;$_i<$_len;++$_i){args[$_i-2]=arguments[$_i]}global.setTimeout(function(){fn.apply(void 0,args)},time)};var pass={};global.setTimeout(function(_){if(_===pass){setTimeout=global.setTimeout}},1,pass);module.exports=function(Promise,INTERNAL){var util=require("./util.js");var errors=require("./errors.js");var apiRejection=require("./errors_api_rejection")(Promise);var TimeoutError=Promise.TimeoutError;var afterTimeout=function Promise$_afterTimeout(promise,message,ms){if(!promise.isPending())return;if(typeof message!=="string"){message="operation timed out after"+" "+ms+" ms"}var err=new TimeoutError(message);errors.markAsOriginatingFromRejection(err);promise._attachExtraTrace(err);promise._rejectUnchecked(err)};var afterDelay=function Promise$_afterDelay(value,promise){promise._fulfill(value)};Promise.delay=function Promise$Delay(value,ms,caller){if(ms===void 0){ms=value;value=void 0}ms=+ms;if(typeof caller!=="function"){caller=Promise.delay}var maybePromise=Promise._cast(value,caller,void 0);var promise=new Promise(INTERNAL);if(Promise.is(maybePromise)){if(maybePromise._isBound()){promise._setBoundTo(maybePromise._boundTo)}if(maybePromise._cancellable()){promise._setCancellable();promise._cancellationParent=maybePromise}promise._setTrace(caller,maybePromise);promise._follow(maybePromise);return promise.then(function(value){return Promise.delay(value,ms)})}else{promise._setTrace(caller,void 0);setTimeout(afterDelay,ms,value,promise)}return promise};Promise.prototype.delay=function Promise$delay(ms){return Promise.delay(this,ms,this.delay)};Promise.prototype.timeout=function Promise$timeout(ms,message){ms=+ms;var ret=new Promise(INTERNAL);ret._setTrace(this.timeout,this);if(this._isBound())ret._setBoundTo(this._boundTo);if(this._cancellable()){ret._setCancellable();ret._cancellationParent=this}ret._follow(this);setTimeout(afterTimeout,ms,ret,message,ms);return ret}}},{"./errors.js":9,"./errors_api_rejection":10,"./global.js":15,"./util.js":38}],38:[function(require,module,exports){"use strict";var global=require("./global.js");var es5=require("./es5.js");var haveGetters=function(){try{var o={};es5.defineProperty(o,"f",{get:function(){return 3}});return o.f===3}catch(e){return false}}();var canEvaluate=function(){if(typeof window!=="undefined"&&window!==null&&typeof window.document!=="undefined"&&typeof navigator!=="undefined"&&navigator!==null&&typeof navigator.appName==="string"&&window===global){return false}return true}();function deprecated(msg){if(typeof console!=="undefined"&&console!==null&&typeof console.warn==="function"){console.warn("Bluebird: "+msg)}}var errorObj={e:{}};function tryCatch1(fn,receiver,arg){try{return fn.call(receiver,arg)}catch(e){errorObj.e=e;return errorObj}}function tryCatch2(fn,receiver,arg,arg2){try{return fn.call(receiver,arg,arg2)}catch(e){errorObj.e=e;return errorObj}}function tryCatchApply(fn,args,receiver){try{return fn.apply(receiver,args)}catch(e){errorObj.e=e;return errorObj}}var inherits=function(Child,Parent){var hasProp={}.hasOwnProperty;function T(){this.constructor=Child;this.constructor$=Parent;for(var propertyName in Parent.prototype){if(hasProp.call(Parent.prototype,propertyName)&&propertyName.charAt(propertyName.length-1)!=="$"){this[propertyName+"$"]=Parent.prototype[propertyName]}}}T.prototype=Parent.prototype;Child.prototype=new T;return Child.prototype};function asString(val){return typeof val==="string"?val:""+val}function isPrimitive(val){return val==null||val===true||val===false||typeof val==="string"||typeof val==="number"}function isObject(value){return!isPrimitive(value)}function maybeWrapAsError(maybeError){if(!isPrimitive(maybeError))return maybeError;return new Error(asString(maybeError))}function withAppended(target,appendee){var len=target.length;var ret=new Array(len+1);var i;for(i=0;ib?1:a>=b?0:NaN}d3.descending=function(a,b){return ba?1:b>=a?0:NaN};d3.min=function(array,f){var i=-1,n=array.length,a,b;if(arguments.length===1){while(++ib)a=b}else{while(++ib)a=b}return a};d3.max=function(array,f){var i=-1,n=array.length,a,b;if(arguments.length===1){while(++ia)a=b}else{while(++ia)a=b}return a};d3.extent=function(array,f){var i=-1,n=array.length,a,b,c;if(arguments.length===1){while(++ib)a=b;if(cb)a=b;if(c1)array=array.map(f);array=array.filter(d3_number);return array.length?d3.quantile(array.sort(d3_ascending),.5):undefined};function d3_bisector(compare){return{left:function(a,x,lo,hi){if(arguments.length<3)lo=0;if(arguments.length<4)hi=a.length;while(lo>>1;if(compare(a[mid],x)<0)lo=mid+1;else hi=mid}return lo},right:function(a,x,lo,hi){if(arguments.length<3)lo=0;if(arguments.length<4)hi=a.length;while(lo>>1;if(compare(a[mid],x)>0)hi=mid;else lo=mid+1}return lo}}}var d3_bisect=d3_bisector(d3_ascending);d3.bisectLeft=d3_bisect.left;d3.bisect=d3.bisectRight=d3_bisect.right;d3.bisector=function(f){return d3_bisector(f.length===1?function(d,x){return d3_ascending(f(d),x)}:f)};d3.shuffle=function(array){var m=array.length,t,i;while(m){i=Math.random()*m--|0;t=array[m],array[m]=array[i],array[i]=t}return array};d3.permute=function(array,indexes){var i=indexes.length,permutes=new Array(i);while(i--)permutes[i]=array[indexes[i]];return permutes};d3.pairs=function(array){var i=0,n=array.length-1,p0,p1=array[0],pairs=new Array(n<0?0:n);while(i=0){array=arrays[n];m=array.length;while(--m>=0){merged[--j]=array[m]}}return merged};var abs=Math.abs;d3.range=function(start,stop,step){if(arguments.length<3){step=1;if(arguments.length<2){stop=start;start=0}}if((stop-start)/step===Infinity)throw new Error("infinite range");var range=[],k=d3_range_integerScale(abs(step)),i=-1,j;start*=k,stop*=k,step*=k;if(step<0)while((j=start+step*++i)>stop)range.push(j/k);else while((j=start+step*++i)=keys.length)return rollup?rollup.call(nest,array):sortValues?array.sort(sortValues):array;var i=-1,n=array.length,key=keys[depth++],keyValue,object,setter,valuesByKey=new d3_Map,values;while(++i=keys.length)return map;var array=[],sortKey=sortKeys[depth++];map.forEach(function(key,keyMap){array.push({key:key,values:entries(keyMap,depth)})});return sortKey?array.sort(function(a,b){return sortKey(a.key,b.key)}):array}nest.map=function(array,mapType){return map(mapType,array,0)};nest.entries=function(array){return entries(map(d3.map,array,0),0)};nest.key=function(d){keys.push(d);return nest};nest.sortKeys=function(order){sortKeys[keys.length-1]=order;return nest};nest.sortValues=function(order){sortValues=order;return nest};nest.rollup=function(f){rollup=f;return nest};return nest};d3.set=function(array){var set=new d3_Set;if(array)for(var i=0,n=array.length;i=0){name=type.substring(i+1);type=type.substring(0,i)}if(type)return arguments.length<2?this[type].on(name):this[type].on(name,listener);if(arguments.length===2){if(listener==null)for(type in this){if(this.hasOwnProperty(type))this[type].on(name,null)}return this}};function d3_dispatch_event(dispatch){var listeners=[],listenerByName=new d3_Map;function event(){var z=listeners,i=-1,n=z.length,l;while(++i=0){prefix=name.substring(0,i);name=name.substring(i+1)}return d3_nsPrefix.hasOwnProperty(prefix)?{space:d3_nsPrefix[prefix],local:name}:name}};d3_selectionPrototype.attr=function(name,value){if(arguments.length<2){if(typeof name==="string"){var node=this.node();name=d3.ns.qualify(name);return name.local?node.getAttributeNS(name.space,name.local):node.getAttribute(name)}for(value in name)this.each(d3_selection_attr(value,name[value]));return this}return this.each(d3_selection_attr(name,value))};function d3_selection_attr(name,value){name=d3.ns.qualify(name);function attrNull(){this.removeAttribute(name)}function attrNullNS(){this.removeAttributeNS(name.space,name.local)}function attrConstant(){this.setAttribute(name,value)}function attrConstantNS(){this.setAttributeNS(name.space,name.local,value)}function attrFunction(){var x=value.apply(this,arguments);if(x==null)this.removeAttribute(name);else this.setAttribute(name,x)}function attrFunctionNS(){var x=value.apply(this,arguments);if(x==null)this.removeAttributeNS(name.space,name.local);else this.setAttributeNS(name.space,name.local,x)}return value==null?name.local?attrNullNS:attrNull:typeof value==="function"?name.local?attrFunctionNS:attrFunction:name.local?attrConstantNS:attrConstant}function d3_collapse(s){return s.trim().replace(/\s+/g," ")}d3_selectionPrototype.classed=function(name,value){if(arguments.length<2){if(typeof name==="string"){var node=this.node(),n=(name=d3_selection_classes(name)).length,i=-1;if(value=node.classList){while(++i=0;){if(node=group[i]){if(next&&next!==node.nextSibling)next.parentNode.insertBefore(node,next);next=node}}}return this};d3_selectionPrototype.sort=function(comparator){comparator=d3_selection_sortComparator.apply(this,arguments);for(var j=-1,m=this.length;++j=i0)i0=i+1;while(!(node=group[i0])&&++i00)type=type.substring(0,i);var filter=d3_selection_onFilters.get(type);if(filter)type=filter,wrap=d3_selection_onFilter;function onRemove(){var l=this[name];if(l){this.removeEventListener(type,l,l.$);delete this[name]}}function onAdd(){var l=wrap(listener,d3_array(arguments));onRemove.call(this);this.addEventListener(type,this[name]=l,l.$=capture);l._=listener}function removeAll(){var re=new RegExp("^__on([^.]+)"+d3.requote(type)+"$"),match;for(var name in this){if(match=name.match(re)){var l=this[name];this.removeEventListener(match[1],l,l.$);delete this[name]}}}return i?listener?onAdd:onRemove:listener?d3_noop:removeAll}var d3_selection_onFilters=d3.map({mouseenter:"mouseover",mouseleave:"mouseout"});d3_selection_onFilters.forEach(function(k){if("on"+k in d3_document)d3_selection_onFilters.remove(k)});function d3_selection_onListener(listener,argumentz){return function(e){var o=d3.event;d3.event=e;argumentz[0]=this.__data__;try{listener.apply(this,argumentz)}finally{d3.event=o}}}function d3_selection_onFilter(listener,argumentz){var l=d3_selection_onListener(listener,argumentz);return function(e){var target=this,related=e.relatedTarget;if(!related||related!==target&&!(related.compareDocumentPosition(target)&8)){l.call(target,e)}}}var d3_event_dragSelect="onselectstart"in d3_document?null:d3_vendorSymbol(d3_documentElement.style,"userSelect"),d3_event_dragId=0;function d3_event_dragSuppress(){var name=".dragsuppress-"+ ++d3_event_dragId,click="click"+name,w=d3.select(d3_window).on("touchmove"+name,d3_eventPreventDefault).on("dragstart"+name,d3_eventPreventDefault).on("selectstart"+name,d3_eventPreventDefault);if(d3_event_dragSelect){var style=d3_documentElement.style,select=style[d3_event_dragSelect];style[d3_event_dragSelect]="none"}return function(suppressClick){w.on(name,null);if(d3_event_dragSelect)style[d3_event_dragSelect]=select;if(suppressClick){function off(){w.on(click,null)}w.on(click,function(){d3_eventPreventDefault();off()},true);setTimeout(off,0)}}}d3.mouse=function(container){return d3_mousePoint(container,d3_eventSource())};function d3_mousePoint(container,e){if(e.changedTouches)e=e.changedTouches[0];var svg=container.ownerSVGElement||container;if(svg.createSVGPoint){var point=svg.createSVGPoint();point.x=e.clientX,point.y=e.clientY;point=point.matrixTransform(container.getScreenCTM().inverse());return[point.x,point.y]}var rect=container.getBoundingClientRect();return[e.clientX-rect.left-container.clientLeft,e.clientY-rect.top-container.clientTop]}d3.touches=function(container,touches){if(arguments.length<2)touches=d3_eventSource().touches;return touches?d3_array(touches).map(function(touch){var point=d3_mousePoint(container,touch);point.identifier=touch.identifier;return point}):[]};d3.behavior.drag=function(){var event=d3_eventDispatch(drag,"drag","dragstart","dragend"),origin=null,mousedown=dragstart(d3_noop,d3.mouse,d3_behavior_dragMouseSubject,"mousemove","mouseup"),touchstart=dragstart(d3_behavior_dragTouchId,d3.touch,d3_behavior_dragTouchSubject,"touchmove","touchend");function drag(){this.on("mousedown.drag",mousedown).on("touchstart.drag",touchstart)}function dragstart(id,position,subject,move,end){return function(){var that=this,target=d3.event.target,parent=that.parentNode,dispatch=event.of(that,arguments),dragged=0,dragId=id(),dragName=".drag"+(dragId==null?"":"-"+dragId),dragOffset,dragSubject=d3.select(subject()).on(move+dragName,moved).on(end+dragName,ended),dragRestore=d3_event_dragSuppress(),position0=position(parent,dragId);if(origin){dragOffset=origin.apply(that,arguments);dragOffset=[dragOffset.x-position0[0],dragOffset.y-position0[1]]}else{dragOffset=[0,0]}dispatch({type:"dragstart"});function moved(){var position1=position(parent,dragId),dx,dy;if(!position1)return;dx=position1[0]-position0[0];dy=position1[1]-position0[1];dragged|=dx|dy;position0=position1;dispatch({type:"drag",x:position1[0]+dragOffset[0],y:position1[1]+dragOffset[1],dx:dx,dy:dy})}function ended(){if(!position(parent,dragId))return;dragSubject.on(move+dragName,null).on(end+dragName,null);dragRestore(dragged&&d3.event.target===target);dispatch({type:"dragend"})}}}drag.origin=function(x){if(!arguments.length)return origin;origin=x;return drag};return d3.rebind(drag,event,"on")};function d3_behavior_dragTouchId(){return d3.event.changedTouches[0].identifier}function d3_behavior_dragTouchSubject(){return d3.event.target}function d3_behavior_dragMouseSubject(){return d3_window}var π=Math.PI,τ=2*π,halfπ=π/2,ε=1e-6,ε2=ε*ε,d3_radians=π/180,d3_degrees=180/π;function d3_sgn(x){return x>0?1:x<0?-1:0}function d3_cross2d(a,b,c){return(b[0]-a[0])*(c[1]-a[1])-(b[1]-a[1])*(c[0]-a[0])}function d3_acos(x){return x>1?0:x<-1?π:Math.acos(x)}function d3_asin(x){return x>1?halfπ:x<-1?-halfπ:Math.asin(x)}function d3_sinh(x){return((x=Math.exp(x))-1/x)/2}function d3_cosh(x){return((x=Math.exp(x))+1/x)/2}function d3_tanh(x){return((x=Math.exp(2*x))-1)/(x+1)}function d3_haversin(x){return(x=Math.sin(x/2))*x}var ρ=Math.SQRT2,ρ2=2,ρ4=4;d3.interpolateZoom=function(p0,p1){var ux0=p0[0],uy0=p0[1],w0=p0[2],ux1=p1[0],uy1=p1[1],w1=p1[2];var dx=ux1-ux0,dy=uy1-uy0,d2=dx*dx+dy*dy,d1=Math.sqrt(d2),b0=(w1*w1-w0*w0+ρ4*d2)/(2*w0*ρ2*d1),b1=(w1*w1-w0*w0-ρ4*d2)/(2*w1*ρ2*d1),r0=Math.log(Math.sqrt(b0*b0+1)-b0),r1=Math.log(Math.sqrt(b1*b1+1)-b1),dr=r1-r0,S=(dr||Math.log(w1/w0))/ρ;function interpolate(t){var s=t*S;if(dr){var coshr0=d3_cosh(r0),u=w0/(ρ2*d1)*(coshr0*d3_tanh(ρ*s+r0)-d3_sinh(r0));return[ux0+u*dx,uy0+u*dy,w0*coshr0/d3_cosh(ρ*s+r0)]}return[ux0+t*dx,uy0+t*dy,w0*Math.exp(ρ*s)]}interpolate.duration=S*1e3;return interpolate};d3.behavior.zoom=function(){var view={x:0,y:0,k:1},translate0,center,size=[960,500],scaleExtent=d3_behavior_zoomInfinity,mousedown="mousedown.zoom",mousemove="mousemove.zoom",mouseup="mouseup.zoom",mousewheelTimer,touchstart="touchstart.zoom",touchtime,event=d3_eventDispatch(zoom,"zoomstart","zoom","zoomend"),x0,x1,y0,y1;function zoom(g){g.on(mousedown,mousedowned).on(d3_behavior_zoomWheel+".zoom",mousewheeled).on(mousemove,mousewheelreset).on("dblclick.zoom",dblclicked).on(touchstart,touchstarted)}zoom.event=function(g){g.each(function(){var dispatch=event.of(this,arguments),view1=view;if(d3_transitionInheritId){d3.select(this).transition().each("start.zoom",function(){view=this.__chart__||{x:0,y:0,k:1};zoomstarted(dispatch)}).tween("zoom:zoom",function(){var dx=size[0],dy=size[1],cx=dx/2,cy=dy/2,i=d3.interpolateZoom([(cx-view.x)/view.k,(cy-view.y)/view.k,dx/view.k],[(cx-view1.x)/view1.k,(cy-view1.y)/view1.k,dx/view1.k]);return function(t){var l=i(t),k=dx/l[2];this.__chart__=view={x:cx-l[0]*k,y:cy-l[1]*k,k:k};zoomed(dispatch)}}).each("end.zoom",function(){zoomended(dispatch)})}else{this.__chart__=view;
-zoomstarted(dispatch);zoomed(dispatch);zoomended(dispatch)}})};zoom.translate=function(_){if(!arguments.length)return[view.x,view.y];view={x:+_[0],y:+_[1],k:view.k};rescale();return zoom};zoom.scale=function(_){if(!arguments.length)return view.k;view={x:view.x,y:view.y,k:+_};rescale();return zoom};zoom.scaleExtent=function(_){if(!arguments.length)return scaleExtent;scaleExtent=_==null?d3_behavior_zoomInfinity:[+_[0],+_[1]];return zoom};zoom.center=function(_){if(!arguments.length)return center;center=_&&[+_[0],+_[1]];return zoom};zoom.size=function(_){if(!arguments.length)return size;size=_&&[+_[0],+_[1]];return zoom};zoom.x=function(z){if(!arguments.length)return x1;x1=z;x0=z.copy();view={x:0,y:0,k:1};return zoom};zoom.y=function(z){if(!arguments.length)return y1;y1=z;y0=z.copy();view={x:0,y:0,k:1};return zoom};function location(p){return[(p[0]-view.x)/view.k,(p[1]-view.y)/view.k]}function point(l){return[l[0]*view.k+view.x,l[1]*view.k+view.y]}function scaleTo(s){view.k=Math.max(scaleExtent[0],Math.min(scaleExtent[1],s))}function translateTo(p,l){l=point(l);view.x+=p[0]-l[0];view.y+=p[1]-l[1]}function rescale(){if(x1)x1.domain(x0.range().map(function(x){return(x-view.x)/view.k}).map(x0.invert));if(y1)y1.domain(y0.range().map(function(y){return(y-view.y)/view.k}).map(y0.invert))}function zoomstarted(dispatch){dispatch({type:"zoomstart"})}function zoomed(dispatch){rescale();dispatch({type:"zoom",scale:view.k,translate:[view.x,view.y]})}function zoomended(dispatch){dispatch({type:"zoomend"})}function mousedowned(){var that=this,target=d3.event.target,dispatch=event.of(that,arguments),dragged=0,subject=d3.select(d3_window).on(mousemove,moved).on(mouseup,ended),location0=location(d3.mouse(that)),dragRestore=d3_event_dragSuppress();d3_selection_interrupt.call(that);zoomstarted(dispatch);function moved(){dragged=1;translateTo(d3.mouse(that),location0);zoomed(dispatch)}function ended(){subject.on(mousemove,d3_window===that?mousewheelreset:null).on(mouseup,null);dragRestore(dragged&&d3.event.target===target);zoomended(dispatch)}}function touchstarted(){var that=this,dispatch=event.of(that,arguments),locations0={},distance0=0,scale0,zoomName=".zoom-"+d3.event.changedTouches[0].identifier,touchmove="touchmove"+zoomName,touchend="touchend"+zoomName,targets=[],subject=d3.select(that).on(mousedown,null).on(touchstart,started),dragRestore=d3_event_dragSuppress();d3_selection_interrupt.call(that);started();zoomstarted(dispatch);function relocate(){var touches=d3.touches(that);scale0=view.k;touches.forEach(function(t){if(t.identifier in locations0)locations0[t.identifier]=location(t)});return touches}function started(){var target=d3.event.target;d3.select(target).on(touchmove,moved).on(touchend,ended);targets.push(target);var changed=d3.event.changedTouches;for(var i=0,n=changed.length;i1){var p=touches[0],q=touches[1],dx=p[0]-q[0],dy=p[1]-q[1];distance0=dx*dx+dy*dy}}function moved(){var touches=d3.touches(that),p0,l0,p1,l1;for(var i=0,n=touches.length;i1?1:s;l=l<0?0:l>1?1:l;m2=l<=.5?l*(1+s):l+s-l*s;m1=2*l-m2;function v(h){if(h>360)h-=360;else if(h<0)h+=360;if(h<60)return m1+(m2-m1)*h/60;if(h<180)return m2;if(h<240)return m1+(m2-m1)*(240-h)/60;return m1}function vv(h){return Math.round(v(h)*255)}return d3_rgb(vv(h+120),vv(h),vv(h-120))}d3.hcl=function(h,c,l){return arguments.length===1?h instanceof d3_Hcl?d3_hcl(h.h,h.c,h.l):h instanceof d3_Lab?d3_lab_hcl(h.l,h.a,h.b):d3_lab_hcl((h=d3_rgb_lab((h=d3.rgb(h)).r,h.g,h.b)).l,h.a,h.b):d3_hcl(+h,+c,+l)};function d3_hcl(h,c,l){return new d3_Hcl(h,c,l)}function d3_Hcl(h,c,l){this.h=h;this.c=c;this.l=l}var d3_hclPrototype=d3_Hcl.prototype=new d3_Color;d3_hclPrototype.brighter=function(k){return d3_hcl(this.h,this.c,Math.min(100,this.l+d3_lab_K*(arguments.length?k:1)))};d3_hclPrototype.darker=function(k){return d3_hcl(this.h,this.c,Math.max(0,this.l-d3_lab_K*(arguments.length?k:1)))};d3_hclPrototype.rgb=function(){return d3_hcl_lab(this.h,this.c,this.l).rgb()};function d3_hcl_lab(h,c,l){if(isNaN(h))h=0;if(isNaN(c))c=0;return d3_lab(l,Math.cos(h*=d3_radians)*c,Math.sin(h)*c)}d3.lab=function(l,a,b){return arguments.length===1?l instanceof d3_Lab?d3_lab(l.l,l.a,l.b):l instanceof d3_Hcl?d3_hcl_lab(l.l,l.c,l.h):d3_rgb_lab((l=d3.rgb(l)).r,l.g,l.b):d3_lab(+l,+a,+b)};function d3_lab(l,a,b){return new d3_Lab(l,a,b)}function d3_Lab(l,a,b){this.l=l;this.a=a;this.b=b}var d3_lab_K=18;var d3_lab_X=.95047,d3_lab_Y=1,d3_lab_Z=1.08883;var d3_labPrototype=d3_Lab.prototype=new d3_Color;d3_labPrototype.brighter=function(k){return d3_lab(Math.min(100,this.l+d3_lab_K*(arguments.length?k:1)),this.a,this.b)};d3_labPrototype.darker=function(k){return d3_lab(Math.max(0,this.l-d3_lab_K*(arguments.length?k:1)),this.a,this.b)};d3_labPrototype.rgb=function(){return d3_lab_rgb(this.l,this.a,this.b)};function d3_lab_rgb(l,a,b){var y=(l+16)/116,x=y+a/500,z=y-b/200;x=d3_lab_xyz(x)*d3_lab_X;y=d3_lab_xyz(y)*d3_lab_Y;z=d3_lab_xyz(z)*d3_lab_Z;return d3_rgb(d3_xyz_rgb(3.2404542*x-1.5371385*y-.4985314*z),d3_xyz_rgb(-.969266*x+1.8760108*y+.041556*z),d3_xyz_rgb(.0556434*x-.2040259*y+1.0572252*z))}function d3_lab_hcl(l,a,b){return l>0?d3_hcl(Math.atan2(b,a)*d3_degrees,Math.sqrt(a*a+b*b),l):d3_hcl(NaN,NaN,l)}function d3_lab_xyz(x){return x>.206893034?x*x*x:(x-4/29)/7.787037}function d3_xyz_lab(x){return x>.008856?Math.pow(x,1/3):7.787037*x+4/29}function d3_xyz_rgb(r){return Math.round(255*(r<=.00304?12.92*r:1.055*Math.pow(r,1/2.4)-.055))}d3.rgb=function(r,g,b){return arguments.length===1?r instanceof d3_Rgb?d3_rgb(r.r,r.g,r.b):d3_rgb_parse(""+r,d3_rgb,d3_hsl_rgb):d3_rgb(~~r,~~g,~~b)};function d3_rgbNumber(value){return d3_rgb(value>>16,value>>8&255,value&255)}function d3_rgbString(value){return d3_rgbNumber(value)+""}function d3_rgb(r,g,b){return new d3_Rgb(r,g,b)}function d3_Rgb(r,g,b){this.r=r;this.g=g;this.b=b}var d3_rgbPrototype=d3_Rgb.prototype=new d3_Color;d3_rgbPrototype.brighter=function(k){k=Math.pow(.7,arguments.length?k:1);var r=this.r,g=this.g,b=this.b,i=30;if(!r&&!g&&!b)return d3_rgb(i,i,i);if(r&&r>4;r=r>>4|r;g=color&240;g=g>>4|g;b=color&15;b=b<<4|b}else if(format.length===7){r=(color&16711680)>>16;g=(color&65280)>>8;b=color&255}}return rgb(r,g,b)}function d3_rgb_hsl(r,g,b){var min=Math.min(r/=255,g/=255,b/=255),max=Math.max(r,g,b),d=max-min,h,s,l=(max+min)/2;if(d){s=l<.5?d/(max+min):d/(2-max-min);if(r==max)h=(g-b)/d+(g0&&l<1?0:h}return d3_hsl(h,s,l)}function d3_rgb_lab(r,g,b){r=d3_rgb_xyz(r);g=d3_rgb_xyz(g);b=d3_rgb_xyz(b);var x=d3_xyz_lab((.4124564*r+.3575761*g+.1804375*b)/d3_lab_X),y=d3_xyz_lab((.2126729*r+.7151522*g+.072175*b)/d3_lab_Y),z=d3_xyz_lab((.0193339*r+.119192*g+.9503041*b)/d3_lab_Z);return d3_lab(116*y-16,500*(x-y),200*(y-z))}function d3_rgb_xyz(r){return(r/=255)<=.04045?r/12.92:Math.pow((r+.055)/1.055,2.4)}function d3_rgb_parseNumber(c){var f=parseFloat(c);return c.charAt(c.length-1)==="%"?Math.round(f*2.55):f}var d3_rgb_names=d3.map({aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074});d3_rgb_names.forEach(function(key,value){d3_rgb_names.set(key,d3_rgbNumber(value))});function d3_functor(v){return typeof v==="function"?v:function(){return v}}d3.functor=d3_functor;function d3_identity(d){return d}d3.xhr=d3_xhrType(d3_identity);function d3_xhrType(response){return function(url,mimeType,callback){if(arguments.length===2&&typeof mimeType==="function")callback=mimeType,mimeType=null;return d3_xhr(url,mimeType,response,callback)}}function d3_xhr(url,mimeType,response,callback){var xhr={},dispatch=d3.dispatch("beforesend","progress","load","error"),headers={},request=new XMLHttpRequest,responseType=null;if(d3_window.XDomainRequest&&!("withCredentials"in request)&&/^(http(s)?:)?\/\//.test(url))request=new XDomainRequest;"onload"in request?request.onload=request.onerror=respond:request.onreadystatechange=function(){request.readyState>3&&respond()};function respond(){var status=request.status,result;if(!status&&request.responseText||status>=200&&status<300||status===304){try{result=response.call(xhr,request)}catch(e){dispatch.error.call(xhr,e);return}dispatch.load.call(xhr,result)}else{dispatch.error.call(xhr,request)}}request.onprogress=function(event){var o=d3.event;d3.event=event;try{dispatch.progress.call(xhr,request)}finally{d3.event=o}};xhr.header=function(name,value){name=(name+"").toLowerCase();if(arguments.length<2)return headers[name];if(value==null)delete headers[name];else headers[name]=value+"";return xhr};xhr.mimeType=function(value){if(!arguments.length)return mimeType;mimeType=value==null?null:value+"";return xhr};xhr.responseType=function(value){if(!arguments.length)return responseType;responseType=value;return xhr};xhr.response=function(value){response=value;return xhr};["get","post"].forEach(function(method){xhr[method]=function(){return xhr.send.apply(xhr,[method].concat(d3_array(arguments)))}});xhr.send=function(method,data,callback){if(arguments.length===2&&typeof data==="function")callback=data,data=null;request.open(method,url,true);if(mimeType!=null&&!("accept"in headers))headers["accept"]=mimeType+",*/*";if(request.setRequestHeader)for(var name in headers)request.setRequestHeader(name,headers[name]);if(mimeType!=null&&request.overrideMimeType)request.overrideMimeType(mimeType);if(responseType!=null)request.responseType=responseType;if(callback!=null)xhr.on("error",callback).on("load",function(request){callback(null,request)});dispatch.beforesend.call(xhr,request);request.send(data==null?null:data);return xhr};xhr.abort=function(){request.abort();return xhr};d3.rebind(xhr,dispatch,"on");return callback==null?xhr:xhr.get(d3_xhr_fixCallback(callback))}function d3_xhr_fixCallback(callback){return callback.length===1?function(error,request){callback(error==null?request:null)}:callback}d3.dsv=function(delimiter,mimeType){var reFormat=new RegExp('["'+delimiter+"\n]"),delimiterCode=delimiter.charCodeAt(0);function dsv(url,row,callback){if(arguments.length<3)callback=row,row=null;var xhr=d3_xhr(url,mimeType,row==null?response:typedResponse(row),callback);xhr.row=function(_){return arguments.length?xhr.response((row=_)==null?response:typedResponse(_)):row};return xhr}function response(request){return dsv.parse(request.responseText)}function typedResponse(f){return function(request){return dsv.parse(request.responseText,f)}}dsv.parse=function(text,f){var o;return dsv.parseRows(text,function(row,i){if(o)return o(row,i-1);var a=new Function("d","return {"+row.map(function(name,i){return JSON.stringify(name)+": d["+i+"]"}).join(",")+"}");o=f?function(row,i){return f(a(row),i)}:a})};dsv.parseRows=function(text,f){var EOL={},EOF={},rows=[],N=text.length,I=0,n=0,t,eol;function token(){if(I>=N)return EOF;if(eol)return eol=false,EOL;var j=I;if(text.charCodeAt(j)===34){var i=j;while(i++24){if(isFinite(delay)){clearTimeout(d3_timer_timeout);d3_timer_timeout=setTimeout(d3_timer_step,delay)}d3_timer_interval=0}else{d3_timer_interval=1;d3_timer_frame(d3_timer_step)}}d3.timer.flush=function(){d3_timer_mark();d3_timer_sweep()};function d3_timer_mark(){var now=Date.now();d3_timer_active=d3_timer_queueHead;while(d3_timer_active){if(now>=d3_timer_active.t)d3_timer_active.f=d3_timer_active.c(now-d3_timer_active.t);d3_timer_active=d3_timer_active.n}return now}function d3_timer_sweep(){var t0,t1=d3_timer_queueHead,time=Infinity;while(t1){if(t1.f){t1=t0?t0.n=t1.n:d3_timer_queueHead=t1.n}else{if(t1.t