From 30b5c4686e395ce7cd7345ddb51f9eec3f3455bb Mon Sep 17 00:00:00 2001
From: Dan Stillman
Date: Wed, 28 Jan 2015 15:19:29 -0500
Subject: [PATCH] Update Bluebird to 2.9.3
...with fewer modifications, since one (better debug info on an invalid
yield value) was implemented in Bluebird and the other (detecting a
thrown error that doesn't properly extend Error) we should just fix in
our code.
---
resource/bluebird.js | 4751 ++++++++++++++++++------------------------
1 file changed, 2064 insertions(+), 2687 deletions(-)
diff --git a/resource/bluebird.js b/resource/bluebird.js
index 693a4490f..06d4ec6bf 100644
--- a/resource/bluebird.js
+++ b/resource/bluebird.js
@@ -1,9 +1,7 @@
-/**
- * bluebird build version 2.3.5
- * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, progress, cancel, using, filter, any, each, timers
-*/
-/**
- * @preserve Copyright (c) 2014 Petka Antonov
+/* @preserve
+ * The MIT License (MIT)
+ *
+ * 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
@@ -24,6 +22,10 @@
* THE SOFTWARE.
*
*/
+/**
+ * bluebird build version 2.9.3
+ * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, progress, cancel, using, filter, any, each, timers
+*/
!function(e){
//
// Added by Zotero
@@ -91,217 +93,225 @@
});
return;
-
- "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.
- *
- */
+
+ if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Promise=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof _dereq_=="function"&&_dereq_;for(var o=0;o
- *
- * 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 = typeof process !== "undefined" ? process : void 0;
+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._schedule = schedule;
- this._length = 0;
- this._lateBuffer = new Queue(16);
- this._functionBuffer = new Queue(65536);
+ 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 &&
+Async.prototype._withDomain = function(fn) {
+ if (_process !== undefined &&
_process.domain != null &&
!fn.domain) {
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; };
}
- var functionBuffer = this._functionBuffer;
- functionBuffer.push(fn, receiver, arg);
- this._length = functionBuffer.length();
+ 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");
+ }
+};
+
+Async.prototype.invokeLater = function (fn, receiver, arg) {
+ fn = this._withDomain(fn);
+ this._lateQueue.push(fn, receiver, arg);
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.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._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();
+ this._drainQueue(this._lateQueue);
};
-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() {
+Async.prototype._queueTick = function () {
if (!this._isTickUsed) {
- this._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;
-},{"./queue.js":25,"./schedule.js":28,"./util.js":35}],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.
- *
- */
+},{"./queue.js":28,"./schedule.js":31}],3:[function(_dereq_,module,exports){
"use strict";
-var Promise = require("./promise.js")();
-module.exports = Promise;
-},{"./promise.js":20}],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.
- *
- */
+module.exports = function(Promise, INTERNAL, tryConvertToPromise) {
+function returnThis() { return this.value; }
+function throwThis() { throw this.reason; }
+function awaitBindingThenResolve(value) {
+ return this._then(returnThis, null, null, {value: value}, undefined);
+}
+function awaitBindingThenReject(reason) {
+ return this._then(throwThis, throwThis, null, {reason: reason}, undefined);
+}
+function setBinding(binding) { this._setBoundTo(binding); }
+Promise.prototype.bind = function (thisArg) {
+ var maybePromise = tryConvertToPromise(thisArg);
+ if (maybePromise instanceof Promise) {
+ if (maybePromise.isFulfilled()) {
+ thisArg = maybePromise.value();
+ } else if (maybePromise.isRejected()) {
+ return Promise.reject(maybePromise.reason());
+ } else {
+ var ret = this.then();
+ var parent = ret;
+ ret = ret._then(awaitBindingThenResolve,
+ awaitBindingThenReject,
+ null, maybePromise, undefined);
+ maybePromise._then(setBinding, ret._reject, null, ret, null);
+ if (!ret._cancellable()) ret._setPendingCancellationParent(parent);
+ return ret;
+ }
+ }
+ var ret = this.then();
+ ret._setBoundTo(thisArg);
+ return ret;
+};
+
+Promise.bind = function (thisArg, value) {
+ return Promise.resolve(value).bind(thisArg);
+};
+
+Promise.prototype._setPendingCancellationParent = function(parent) {
+ this._settledValue = parent;
+};
+
+Promise.prototype._pendingCancellationParent = function() {
+ if (this.isPending() && this._settledValue !== undefined) {
+ var ret = this._settledValue;
+ ret.cancellable();
+ this._settledValue = undefined;
+ return ret;
+ }
+};
+
+Promise.prototype._setIsMigratingBinding = function () {
+ this._bitField = this._bitField | 8388608;
+};
+
+Promise.prototype._unsetIsMigratingBinding = function () {
+ this._bitField = this._bitField & (~8388608);
+};
+
+Promise.prototype._isMigratingBinding = function () {
+ return (this._bitField & 8388608) === 8388608;
+};
+
+Promise.prototype._setBoundTo = function (obj) {
+ this._boundTo = obj;
+};
+
+Promise.prototype._isBound = function () {
+ return this._boundTo !== undefined;
+};
+};
+
+},{}],4:[function(_dereq_,module,exports){
+"use strict";
+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;
+
+},{"./promise.js":23}],5:[function(_dereq_,module,exports){
"use strict";
var cr = Object.create;
if (cr) {
@@ -311,11 +321,14 @@ if (cr) {
}
module.exports = function(Promise) {
-var util = require("./util.js");
+var util = _dereq_("./util.js");
var canEvaluate = util.canEvaluate;
var isIdentifier = util.isIdentifier;
-function makeMethodCaller (methodName) {
+var getMethodCaller;
+var getGetter;
+if (!true) {
+var makeMethodCaller = function (methodName) {
return new Function("obj", " \n\
'use strict' \n\
var len = this.length; \n\
@@ -327,16 +340,16 @@ function makeMethodCaller (methodName) {
default: return obj.methodName.apply(obj, this); \n\
} \n\
".replace(/methodName/g, methodName));
-}
+};
-function makeGetter (propertyName) {
+var makeGetter = function (propertyName) {
return new Function("obj", " \n\
'use strict'; \n\
return obj.propertyName; \n\
".replace("propertyName", propertyName));
-}
+};
-function getCompiled(name, compiler, cache) {
+var getCompiled = function(name, compiler, cache) {
var ret = cache[name];
if (typeof ret !== "function") {
if (!isIdentifier(name)) {
@@ -352,38 +365,44 @@ function getCompiled(name, compiler, cache) {
}
}
return ret;
-}
+};
-function getMethodCaller(name) {
+getMethodCaller = function(name) {
return getCompiled(name, makeMethodCaller, callerCache);
-}
+};
-function getGetter(name) {
+getGetter = function(name) {
return getCompiled(name, makeGetter, getterCache);
+};
}
function caller(obj) {
return obj[this.pop()].apply(obj, this);
}
-Promise.prototype.call = function Promise$call(methodName) {
+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 (canEvaluate) {
- var maybeCaller = getMethodCaller(methodName);
- if (maybeCaller !== null) {
- return this._then(maybeCaller, void 0, void 0, args, void 0);
+ if (!true) {
+ if (canEvaluate) {
+ var maybeCaller = getMethodCaller(methodName);
+ if (maybeCaller !== null) {
+ return this._then(
+ maybeCaller, undefined, undefined, args, undefined);
+ }
}
}
args.push(methodName);
- return this._then(caller, void 0, void 0, args, void 0);
+ return this._then(caller, undefined, undefined, args, undefined);
};
function namedGetter(obj) {
return obj[this];
}
function indexedGetter(obj) {
- return obj[this];
+ var index = +this;
+ if (index < 0) index = Math.max(0, index + obj.length);
+ return obj[index];
}
-Promise.prototype.get = function Promise$get(propertyName) {
+Promise.prototype.get = function (propertyName) {
var isIndex = (typeof propertyName === "number");
var getter;
if (!isIndex) {
@@ -396,125 +415,312 @@ Promise.prototype.get = function Promise$get(propertyName) {
} else {
getter = indexedGetter;
}
- return this._then(getter, void 0, void 0, propertyName, void 0);
+ return this._then(getter, undefined, undefined, propertyName, undefined);
};
};
-},{"./util.js":35}],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.
- *
- */
+},{"./util.js":38}],6:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(Promise, INTERNAL) {
-var errors = require("./errors.js");
-var canAttach = errors.canAttach;
-var async = require("./async.js");
+module.exports = function(Promise) {
+var errors = _dereq_("./errors.js");
+var async = _dereq_("./async.js");
var CancellationError = errors.CancellationError;
-Promise.prototype._cancel = function Promise$_cancel(reason) {
+Promise.prototype._cancel = function (reason) {
if (!this.isCancellable()) return this;
var parent;
var promiseToReject = this;
- while ((parent = promiseToReject._cancellationParent) !== void 0 &&
+ while ((parent = promiseToReject._cancellationParent) !== undefined &&
parent.isCancellable()) {
promiseToReject = parent;
}
- promiseToReject._attachExtraTrace(reason);
- promiseToReject._rejectUnchecked(reason);
+ this._unsetCancellable();
+ promiseToReject._target()._rejectCallback(reason, false, true);
};
-Promise.prototype.cancel = function Promise$cancel(reason) {
+Promise.prototype.cancel = function (reason) {
if (!this.isCancellable()) return this;
- reason = reason !== void 0
- ? (canAttach(reason) ? reason : new Error(reason + ""))
- : new CancellationError();
+ if (reason === undefined) reason = new CancellationError();
async.invokeLater(this._cancel, this, reason);
return this;
};
-Promise.prototype.cancellable = function Promise$cancellable() {
+Promise.prototype.cancellable = function () {
if (this._cancellable()) return this;
this._setCancellable();
- this._cancellationParent = void 0;
+ this._cancellationParent = this._pendingCancellationParent();
return this;
};
-Promise.prototype.uncancellable = function Promise$uncancellable() {
- var ret = new Promise(INTERNAL);
- ret._propagateFrom(this, 2 | 4);
- ret._follow(this);
+Promise.prototype.uncancellable = function () {
+ var ret = this.then();
ret._unsetCancellable();
return ret;
};
-Promise.prototype.fork =
-function Promise$fork(didFulfill, didReject, didProgress) {
+Promise.prototype.fork = function (didFulfill, didReject, didProgress) {
var ret = this._then(didFulfill, didReject, didProgress,
- void 0, void 0);
+ undefined, undefined);
ret._setCancellable();
- ret._cancellationParent = void 0;
+ ret._cancellationParent = undefined;
return ret;
};
};
-},{"./async.js":2,"./errors.js":10}],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.
- *
- */
+},{"./async.js":2,"./errors.js":13}],7:[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(?:[a-zA-Z0-9.]+\\$_\\w+|" +
- "tryCatch(?:1|2|3|4|Apply)|new \\w*PromiseArray|" +
- "\\w*PromiseArray\\.\\w*PromiseArray|" +
- "setTimeout|CatchFilter\\$_\\w+|makeNodePromisified|processImmediate|" +
- "process._tickCallback|nextTick|Async\\$\\w+)\\b"
-);
-
-var rtraceline = null;
+var async = _dereq_("./async.js");
+var inherits = _dereq_("./util.js").inherits;
+var bluebirdFramePattern =
+ /[\\\/]bluebird[\\\/]js[\\\/](main|debug|zalgo|instrumented)/;
+var stackFramePattern = null;
var formatStack = null;
+var indentStackFrames = false;
+
+function CapturedTrace(parent) {
+ this._parent = parent;
+ var length = this._length = 1 + (parent === undefined ? 0 : parent._length);
+ captureStackTrace(this, CapturedTrace);
+ if (length > 32) this.uncycle();
+}
+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;
+ }
+ }
+};
+
+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);
+ 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 (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 === "object") {
+ var message;
+ if (typeof error === "object" || typeof error === "function") {
+ var stack = error.stack;
+ message = title + formatStack(stack, error);
+ } else {
+ message = title + String(error);
+ }
+ if (typeof console.warn === "function" ||
+ typeof console.warn === "object") {
+ console.warn(message);
+ } else if (typeof console.log === "function" ||
+ typeof console.log === "object") {
+ console.log(message);
+ }
+ }
+};
+
+CapturedTrace.unhandledRejection = function (reason) {
+ CapturedTrace.formatAndLogError(reason, "^--- With additional stack trace: ");
+};
+
+CapturedTrace.isSupported = function () {
+ return typeof captureStackTrace === "function";
+};
+
+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);
+ }
+ }
+ } 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);
+ }
+ }
+
+ if (!globalEventFired && !localEventFired && !domEventFired &&
+ name === "unhandledRejection") {
+ CapturedTrace.formatAndLogError(reason, "Possibly unhandled ");
+ }
+};
function formatNonError(obj) {
var str;
@@ -549,199 +755,208 @@ function snip(str) {
return str.substr(0, maxChars - 3) + "...";
}
-function CapturedTrace(ignoreUntil, isTopLevel) {
- this.captureStackTrace(CapturedTrace, isTopLevel);
-
+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)
+ };
+ }
}
-inherits(CapturedTrace, Error);
-
-CapturedTrace.prototype.captureStackTrace =
-function CapturedTrace$captureStackTrace(ignoreUntil, isTopLevel) {
- captureStackTrace(this, ignoreUntil, isTopLevel);
-};
-
-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);
- } else {
- message = "Possibly unhandled " + String(reason);
- }
- if (typeof console.error === "function" ||
- typeof console.error === "object") {
- console.error(message);
- } else if (typeof console.log === "function" ||
- typeof console.log === "object") {
- console.log(message);
- }
- }
-};
-
-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--;
- } else {
+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;
}
}
-
- current.push("From previous event:");
- var lines = current.concat(prev);
-
- var ret = [];
-
- for (var i = 0, len = lines.length; i < len; ++i) {
-
- if (((rignore.test(lines[i]) && rtraceline.test(lines[i])) ||
- (i > 0 && !rtraceline.test(lines[i])) &&
- lines[i] !== "From previous event:")
- ) {
- continue;
- }
- ret.push(lines[i]);
- }
- return ret;
-};
-
-CapturedTrace.protectErrorMessageNewlines = function(stack) {
- for (var i = 0; i < stack.length; ++i) {
- if (rtraceline.test(stack[i])) {
+ for (var i = 0; i < lastStackLines.length; ++i) {
+ var result = parseLineInfo(lastStackLines[i]);
+ if (result) {
+ lastFileName = result.fileName;
+ lastIndex = result.line;
break;
}
}
-
- if (i <= 1) return;
-
- var errorMessageLines = [];
- for (var j = 0; j < i; ++j) {
- errorMessageLines.push(stack.shift());
+ if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName ||
+ firstFileName !== lastFileName || firstIndex >= lastIndex) {
+ return;
}
- stack.unshift(errorMessageLines.join("\u0002\u0000\u0001"));
-};
-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() {
+ var v8stackFramePattern = /^\s*at\s*/;
+ var v8stackFormatter = function(stack, error) {
+ if (typeof stack === "string") return stack;
+
+ if (error.name !== undefined &&
+ error.message !== undefined) {
+ return error.toString();
+ }
+ return formatNonError(error);
+ };
+
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);
-
-
- };
+ Error.stackTraceLimit = Error.stackTraceLimit + 6;
+ stackFramePattern = v8stackFramePattern;
+ formatStack = v8stackFormatter;
var captureStackTrace = Error.captureStackTrace;
- return function CapturedTrace$_captureStackTrace(
- receiver, ignoreUntil) {
+
+ shouldIgnore = function(line) {
+ return bluebirdFramePattern.test(line);
+ };
+ return function(receiver, ignoreUntil) {
+ Error.stackTraceLimit = Error.stackTraceLimit + 6;
captureStackTrace(receiver, ignoreUntil);
+ Error.stackTraceLimit = Error.stackTraceLimit - 6;
};
}
var err = new Error();
if (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);
- };
-
+ err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) {
+ stackFramePattern = /@/;
+ formatStack = v8stackFormatter;
+ indentStackFrames = true;
return function captureStackTrace(o) {
- var stack = new Error().stack;
- var split = stack.split(rline);
- var len = split.length;
- var ret = "";
- for (var i = 0; i < len; i += 2) {
- ret += split[i];
- ret += "@";
- ret += split[i + 1];
- ret += "\n";
+ o.stack = new Error().stack;
+ };
+ }
+
+ 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 stack;
+
+ if ((typeof error === "object" ||
+ typeof error === "function") &&
+ error.name !== undefined &&
+ error.message !== undefined) {
+ return error.toString();
+ }
+ return formatNonError(error);
+ };
+
+ return null;
+
+})([]);
+
+var fireDomEvent;
+var fireGlobalEvent = (function() {
+ if (typeof process !== "undefined" &&
+ typeof process.version === "string" &&
+ typeof window === "undefined") {
+ return function(name, reason, promise) {
+ if (name === "rejectionHandled") {
+ return process.emit(name, promise);
+ } else {
+ return process.emit(name, reason, promise);
}
- o.stack = ret;
};
} 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;
+ 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;
}
- return formatNonError(error);
- };
+ }
+ 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 null;
+ 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);
+ }
+ return true;
+ };
}
})();
return CapturedTrace;
};
-},{"./es5.js":12,"./util.js":35}],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) {
@@ -750,23 +965,21 @@ 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._boundTo;
@@ -776,23 +989,19 @@ CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) {
(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;
@@ -808,49 +1017,199 @@ CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) {
return CatchFilter;
};
-},{"./errors.js":10,"./es5.js":12,"./util.js":35}],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";
-var util = require("./util.js");
+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 util = _dereq_("./util.js");
+var canAttachTrace = util.canAttachTrace;
+var unhandledRejectionHandled;
+var possiblyUnhandledRejection;
+var debugging = false || !!(
+ typeof process !== "undefined" &&
+ typeof process.execPath === "string" &&
+ typeof process.env === "object" &&
+ (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.stack.join("\n");
+ error.__stackCleaned__ = true;
+ }
+ }
+};
+
+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,"./util.js":38}],11:[function(_dereq_,module,exports){
+"use strict";
+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() {
+ return function () {
return value;
};
}
@@ -858,129 +1217,61 @@ 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
+ undefined,
+ undefined,
+ undefined,
+ undefined
);
}
- return this._then(returner, void 0, void 0, value, void 0);
+ 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
+ undefined,
+ undefined,
+ undefined,
+ undefined
);
}
- return this._then(thrower, void 0, void 0, reason, void 0);
+ return this._then(thrower, undefined, undefined, reason, undefined);
};
};
-},{"./util.js":35}],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";
module.exports = function(Promise, INTERNAL) {
var PromiseReduce = Promise.reduce;
-Promise.prototype.each = function Promise$each(fn) {
+Promise.prototype.each = function (fn) {
return PromiseReduce(this, fn, null, INTERNAL);
};
-Promise.each = function Promise$Each(promises, fn) {
+Promise.each = function (promises, fn) {
return PromiseReduce(promises, fn, null, INTERNAL);
};
};
-},{}],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.
- *
- */
+},{}],13:[function(_dereq_,module,exports){
"use strict";
-var Objectfreeze = require("./es5.js").freeze;
-var util = require("./util.js");
+var Objectfreeze = _dereq_("./es5.js").freeze;
+var util = _dereq_("./util.js");
var inherits = util.inherits;
var notEnumerableProp = util.notEnumerableProp;
-function markAsOriginatingFromRejection(e) {
- try {
- notEnumerableProp(e, "isOperational", true);
- }
- catch(ignore) {}
-}
-
-function originatesFromRejection(e) {
- if (e == null) return false;
- return ((e instanceof OperationalError) ||
- e["isOperational"] === true);
-}
-
-function isError(obj) {
- // Added by Zotero
- return obj.message && obj.stack;
- return obj instanceof Error;
-}
-
-function canAttach(obj) {
- return isError(obj);
-}
-
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);
}
@@ -1032,14 +1323,16 @@ AggregateError.prototype.toString = function() {
};
function OperationalError(message) {
- this.name = "OperationalError";
- this.message = message;
+ if (!(this instanceof OperationalError))
+ return new OperationalError(message);
+ notEnumerableProp(this, "name", "OperationalError");
+ notEnumerableProp(this, "message", message);
this.cause = message;
this["isOperational"] = true;
if (message instanceof Error) {
- this.message = message.message;
- this.stack = message.stack;
+ notEnumerableProp(this, "message", message.message);
+ notEnumerableProp(this, "stack", message.stack);
} else if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
@@ -1047,8 +1340,7 @@ function OperationalError(message) {
}
inherits(OperationalError, Error);
-var key = "__BluebirdErrorTypes__";
-var errorTypes = Error[key];
+var errorTypes = Error["__BluebirdErrorTypes__"];
if (!errorTypes) {
errorTypes = Objectfreeze({
CancellationError: CancellationError,
@@ -1057,7 +1349,7 @@ if (!errorTypes) {
RejectionError: OperationalError,
AggregateError: AggregateError
});
- notEnumerableProp(Error, key, errorTypes);
+ notEnumerableProp(Error, "__BluebirdErrorTypes__", errorTypes);
}
module.exports = {
@@ -1067,78 +1359,13 @@ module.exports = {
CancellationError: errorTypes.CancellationError,
OperationalError: errorTypes.OperationalError,
TimeoutError: errorTypes.TimeoutError,
- AggregateError: errorTypes.AggregateError,
- originatesFromRejection: originatesFromRejection,
- markAsOriginatingFromRejection: markAsOriginatingFromRejection,
- canAttach: canAttach
+ AggregateError: errorTypes.AggregateError
};
-},{"./es5.js":12,"./util.js":35}],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.
- *
- */
-"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;
-};
-
-},{"./errors.js":10}],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.
- *
- */
+},{"./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) {
@@ -1148,14 +1375,18 @@ if (isES5) {
keys: Object.keys,
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 {
var has = {}.hasOwnProperty;
var str = {}.toString;
var proto = {}.constructor.prototype;
- var ObjectKeys = function ObjectKeys(o) {
+ var ObjectKeys = function (o) {
var ret = [];
for (var key in o) {
if (has.call(o, key)) {
@@ -1163,34 +1394,34 @@ if (isES5) {
}
}
return ret;
- }
+ };
- var ObjectDefineProperty = function ObjectDefineProperty(o, key, desc) {
+ var ObjectDefineProperty = function (o, key, desc) {
o[key] = desc.value;
return o;
- }
+ };
- var ObjectFreeze = function ObjectFreeze(obj) {
+ var ObjectFreeze = function (obj) {
return obj;
- }
+ };
- var ObjectGetPrototypeOf = function ObjectGetPrototypeOf(obj) {
+ var ObjectGetPrototypeOf = function (obj) {
try {
return Object(obj).constructor.prototype;
}
catch (e) {
return proto;
}
- }
+ };
- var ArrayIsArray = function ArrayIsArray(obj) {
+ var ArrayIsArray = function (obj) {
try {
return str.call(obj) === "[object Array]";
}
catch(e) {
return false;
}
- }
+ };
module.exports = {
isArray: ArrayIsArray,
@@ -1198,72 +1429,31 @@ if (isES5) {
defineProperty: ObjectDefineProperty,
freeze: ObjectFreeze,
getPrototypeOf: ObjectGetPrototypeOf,
- isES5: isES5
+ isES5: isES5,
+ propertyIsWritable: function() {
+ return true;
+ }
};
}
-},{}],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.
- *
- */
+},{}],15:[function(_dereq_,module,exports){
"use strict";
module.exports = function(Promise, INTERNAL) {
var PromiseMap = Promise.map;
-Promise.prototype.filter = function Promise$filter(fn, options) {
+Promise.prototype.filter = function (fn, options) {
return PromiseMap(this, fn, options, INTERNAL);
};
-Promise.filter = function Promise$Filter(promises, fn, options) {
+Promise.filter = function (promises, fn, options) {
return PromiseMap(promises, fn, options, INTERNAL);
};
};
-},{}],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.
- *
- */
+},{}],16:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(Promise, NEXT_FILTER, cast) {
-var util = require("./util.js");
+module.exports = function(Promise, NEXT_FILTER, tryConvertToPromise) {
+var util = _dereq_("./util.js");
var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
var isPrimitive = util.isPrimitive;
var thrower = util.thrower;
@@ -1275,12 +1465,12 @@ function throwThis() {
throw this;
}
function return$(r) {
- return function Promise$_returner() {
+ return function() {
return r;
};
}
function throw$(r) {
- return function Promise$_thrower() {
+ return function() {
throw r;
};
}
@@ -1291,7 +1481,7 @@ function promisedFinally(ret, reasonOrValue, isFulfilled) {
} else {
then = isFulfilled ? returnThis : throwThis;
}
- return ret._then(then, thrower, void 0, reasonOrValue, void 0);
+ return ret._then(then, thrower, undefined, reasonOrValue, undefined);
}
function finallyHandler(reasonOrValue) {
@@ -1302,9 +1492,10 @@ function finallyHandler(reasonOrValue) {
? handler.call(promise._boundTo)
: handler();
- if (ret !== void 0) {
- var maybePromise = cast(ret, void 0);
+ if (ret !== undefined) {
+ var maybePromise = tryConvertToPromise(ret, promise);
if (maybePromise instanceof Promise) {
+ maybePromise = maybePromise._target();
return promisedFinally(maybePromise, reasonOrValue,
promise.isFulfilled());
}
@@ -1326,17 +1517,17 @@ function tapHandler(value) {
? handler.call(promise._boundTo, value)
: handler(value);
- if (ret !== void 0) {
- var maybePromise = cast(ret, void 0);
+ if (ret !== undefined) {
+ var maybePromise = tryConvertToPromise(ret, promise);
if (maybePromise instanceof Promise) {
+ maybePromise = maybePromise._target();
return promisedFinally(maybePromise, value, true);
}
}
return value;
}
-Promise.prototype._passThroughHandler =
-function Promise$_passThroughHandler(handler, isFinally) {
+Promise.prototype._passThroughHandler = function (handler, isFinally) {
if (typeof handler !== "function") return this.then();
var promiseAndHandler = {
@@ -1346,172 +1537,150 @@ function Promise$_passThroughHandler(handler, isFinally) {
return this._then(
isFinally ? finallyHandler : tapHandler,
- isFinally ? finallyHandler : void 0, void 0,
- promiseAndHandler, void 0);
+ isFinally ? finallyHandler : undefined, undefined,
+ promiseAndHandler, undefined);
};
Promise.prototype.lastly =
-Promise.prototype["finally"] = function Promise$finally(handler) {
+Promise.prototype["finally"] = function (handler) {
return this._passThroughHandler(handler, true);
};
-Promise.prototype.tap = function Promise$tap(handler) {
+Promise.prototype.tap = function (handler) {
return this._passThroughHandler(handler, false);
};
};
-},{"./util.js":35}],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.
- *
- */
+},{"./util.js":38}],17:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(Promise, apiRejection, INTERNAL, cast) {
-var errors = require("./errors.js");
+module.exports = function(Promise,
+ apiRejection,
+ INTERNAL,
+ tryConvertToPromise) {
+var errors = _dereq_("./errors.js");
var TypeError = errors.TypeError;
-var deprecated = require("./util.js").deprecated;
-var util = require("./util.js");
+var util = _dereq_("./util.js");
var errorObj = util.errorObj;
-var tryCatch1 = util.tryCatch1;
+var tryCatch = util.tryCatch;
var yieldHandlers = [];
-function promiseFromYieldHandler(value, 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);
+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;
}
- var maybePromise = cast(result, promiseFromYieldHandler);
- if (maybePromise instanceof _Promise) return maybePromise;
+ var maybePromise = tryConvertToPromise(result, traceParent);
+ if (maybePromise instanceof Promise) return maybePromise;
}
return null;
}
-function PromiseSpawn(generatorFunction, receiver, yieldHandler) {
+function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) {
var promise = this._promise = new Promise(INTERNAL);
- promise._setTrace(void 0);
+ promise._captureStackTrace();
+ this._stack = stack;
this._generatorFunction = generatorFunction;
this._receiver = receiver;
- this._generator = void 0;
+ this._generator = undefined;
this._yieldHandlers = typeof yieldHandler === "function"
? [yieldHandler].concat(yieldHandlers)
: yieldHandlers;
}
-PromiseSpawn.prototype.promise = function PromiseSpawn$promise() {
+PromiseSpawn.prototype.promise = function () {
return this._promise;
};
-PromiseSpawn.prototype._run = function PromiseSpawn$_run() {
+PromiseSpawn.prototype._run = function () {
this._generator = this._generatorFunction.call(this._receiver);
this._receiver =
- this._generatorFunction = void 0;
- this._next(void 0);
+ this._generatorFunction = undefined;
+ this._next(undefined);
};
-PromiseSpawn.prototype._continue = function PromiseSpawn$_continue(result) {
+PromiseSpawn.prototype._continue = function (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;
+ return this._promise._rejectCallback(result.e, false, true);
}
var value = result.value;
if (result.done === true) {
- this._generator = void 0;
- if (!this._promise._tryFollow(value)) {
- this._promise._fulfill(value);
- }
+ this._promise._resolveCallback(value);
} else {
- var maybePromise = cast(value, void 0);
+ var maybePromise = tryConvertToPromise(value, this._promise);
if (!(maybePromise instanceof Promise)) {
maybePromise =
- promiseFromYieldHandler(maybePromise, this._yieldHandlers);
+ promiseFromYieldHandler(maybePromise,
+ this._yieldHandlers,
+ this._promise);
if (maybePromise === null) {
- // Added by Zotero
- let e = new TypeError(
- "A value was yielded that could not be treated as a promise: " + value
+ 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")
+ )
);
- global.debug(e);
- global.debug(e.stack);
-
- this._throw(new TypeError("A value was yielded that could not be treated as a promise"));
return;
}
}
maybePromise._then(
this._next,
this._throw,
- void 0,
+ undefined,
this,
null
);
}
};
-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._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);
};
-PromiseSpawn.prototype._next = function PromiseSpawn$_next(value) {
- this._continue(
- tryCatch1(this._generator.next, this._generator, value)
- );
+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.coroutine =
-function Promise$Coroutine(generatorFunction, options) {
+Promise.coroutine = function (generatorFunction, options) {
if (typeof generatorFunction !== "function") {
- throw new TypeError("generatorFunction must be a 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$(void 0, void 0, yieldHandler);
+ var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler,
+ stack);
spawn._generator = generator;
- spawn._next(void 0);
+ spawn._next(undefined);
return spawn.promise();
};
};
Promise.coroutine.addYieldHandler = function(fn) {
- if (typeof fn !== "function") throw new TypeError("fn must be a function");
+ 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 Promise$Spawn(generatorFunction) {
- deprecated("Promise.spawn is deprecated. Use Promise.coroutine instead.");
+Promise.spawn = function (generatorFunction) {
if (typeof generatorFunction !== "function") {
- return apiRejection("generatorFunction must be a 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();
@@ -1520,38 +1689,17 @@ Promise.spawn = function Promise$Spawn(generatorFunction) {
};
};
-},{"./errors.js":10,"./util.js":35}],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, PromiseArray, cast, INTERNAL) {
-var util = require("./util.js");
+function(Promise, PromiseArray, tryConvertToPromise, INTERNAL) {
+var util = _dereq_("./util.js");
var canEvaluate = util.canEvaluate;
-var tryCatch1 = util.tryCatch1;
+var tryCatch = util.tryCatch;
var errorObj = util.errorObj;
+var reject;
-
+if (!true) {
if (canEvaluate) {
var thenCallback = function(i) {
return new Function("value", "holder", " \n\
@@ -1571,7 +1719,7 @@ if (canEvaluate) {
".replace(/values/g, values.join(", ")));
};
var thenCallbacks = [];
- var callers = [void 0];
+ var callers = [undefined];
for (var i = 1; i <= 5; ++i) {
thenCallbacks.push(thenCallback(i));
callers.push(caller(i));
@@ -1591,92 +1739,82 @@ if (canEvaluate) {
var total = this.total;
if (now >= total) {
var handler = this.callers[total];
- var ret = tryCatch1(handler, void 0, this);
+ promise._pushContext();
+ var ret = tryCatch(handler)(this);
+ promise._popContext();
if (ret === errorObj) {
- promise._rejectUnchecked(ret.e);
- } else if (!promise._tryFollow(ret)) {
- promise._fulfillUnchecked(ret);
+ promise._rejectCallback(ret.e, false, true);
+ } else {
+ promise._resolveCallback(ret);
}
} else {
this.now = now;
}
};
+
+ var reject = function (reason) {
+ this._reject(reason);
+ };
+}
}
-
-
-
-Promise.join = function Promise$Join() {
+Promise.join = function () {
var last = arguments.length - 1;
var fn;
if (last > 0 && typeof arguments[last] === "function") {
fn = arguments[last];
- if (last < 6 && canEvaluate) {
- var ret = new Promise(INTERNAL);
- ret._setTrace(void 0);
- var holder = new Holder(last, fn);
- var reject = ret._reject;
- var callbacks = thenCallbacks;
- for (var i = 0; i < last; ++i) {
- var maybePromise = cast(arguments[i], void 0);
- if (maybePromise instanceof Promise) {
- if (maybePromise.isPending()) {
- maybePromise._then(callbacks[i], reject,
- void 0, ret, holder);
- } else if (maybePromise.isFulfilled()) {
- callbacks[i].call(ret,
- maybePromise._settledValue, holder);
+ 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) {
+ 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());
+ }
} else {
- ret._reject(maybePromise._settledValue);
- maybePromise._unsetRejectionIsUnhandled();
+ callbacks[i].call(ret, maybePromise, holder);
}
- } else {
- callbacks[i].call(ret, maybePromise, holder);
}
+ return ret;
}
- return 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 !== void 0 ? ret.spread(fn) : ret;
+ return fn !== undefined ? ret.spread(fn) : ret;
};
};
-},{"./util.js":35}],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.
- *
- */
+},{"./util.js":38}],19:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(Promise, PromiseArray, apiRejection, cast, INTERNAL) {
-var util = require("./util.js");
-var tryCatch3 = util.tryCatch3;
+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._setIsSpreadable();
+ this._promise._captureStackTrace();
this._callback = fn;
this._preservedValues = _filter === INTERNAL
? new Array(this.length())
@@ -1684,17 +1822,14 @@ function MappingPromiseArray(promises, fn, limit, _filter) {
this._limit = limit;
this._inFlight = 0;
this._queue = limit >= 1 ? [] : EMPTY_ARRAY;
- this._init$(void 0, -2);
+ this._init$(undefined, -2);
}
util.inherits(MappingPromiseArray, PromiseArray);
-MappingPromiseArray.prototype._init = function MappingPromiseArray$_init() {};
+MappingPromiseArray.prototype._init = function () {};
-MappingPromiseArray.prototype._promiseFulfilled =
-function MappingPromiseArray$_promiseFulfilled(value, index) {
+MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
var values = this._values;
- if (values === null) return;
-
var length = this.length();
var preservedValues = this._preservedValues;
var limit = this._limit;
@@ -1715,20 +1850,22 @@ function MappingPromiseArray$_promiseFulfilled(value, index) {
var callback = this._callback;
var receiver = this._promise._boundTo;
- var ret = tryCatch3(callback, receiver, value, index, length);
+ this._promise._pushContext();
+ var ret = tryCatch(callback).call(receiver, value, index, length);
+ this._promise._popContext();
if (ret === errorObj) return this._reject(ret.e);
- var maybePromise = cast(ret, void 0);
+ var maybePromise = tryConvertToPromise(ret, this._promise);
if (maybePromise instanceof Promise) {
- if (maybePromise.isPending()) {
+ 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 if (maybePromise._isFulfilled()) {
+ ret = maybePromise._value();
} else {
- maybePromise._unsetRejectionIsUnhandled();
- return this._reject(maybePromise.reason());
+ return this._reject(maybePromise._reason());
}
}
values[index] = ret;
@@ -1744,19 +1881,18 @@ function MappingPromiseArray$_promiseFulfilled(value, index) {
}
};
-MappingPromiseArray.prototype._drainQueue =
-function MappingPromiseArray$_drainQueue() {
+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);
}
};
-MappingPromiseArray.prototype._filter =
-function MappingPromiseArray$_filter(booleans, values) {
+MappingPromiseArray.prototype._filter = function (booleans, values) {
var len = values.length;
var ret = new Array(len);
var j = 0;
@@ -1767,8 +1903,7 @@ function MappingPromiseArray$_filter(booleans, values) {
this._resolve(ret);
};
-MappingPromiseArray.prototype.preservedValues =
-function MappingPromiseArray$preserveValues() {
+MappingPromiseArray.prototype.preservedValues = function () {
return this._preservedValues;
};
@@ -1781,181 +1916,173 @@ function map(promises, fn, options, _filter) {
return new MappingPromiseArray(promises, fn, limit, _filter);
}
-Promise.prototype.map = function Promise$map(fn, options) {
- if (typeof fn !== "function") return apiRejection("fn must be a function");
+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");
return map(this, fn, options, null).promise();
};
-Promise.map = function Promise$Map(promises, fn, options, _filter) {
- if (typeof fn !== "function") return apiRejection("fn must be a function");
+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();
};
};
-},{"./util.js":35}],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.
- *
- */
+},{"./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;
+
+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._resolveFromSyncValue = function (value) {
+ if (value === util.errorObj) {
+ this._rejectCallback(value.e, false, true);
+ } else {
+ this._resolveCallback(value, true);
+ }
+};
+};
+
+},{"./util.js":38}],21:[function(_dereq_,module,exports){
"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 util = _dereq_("./util.js");
+var async = _dereq_("./async.js");
+var tryCatch = util.tryCatch;
var errorObj = util.errorObj;
-function thrower(r) {
- throw r;
-}
-
-function Promise$_spreadAdapter(val, receiver) {
- if (!util.isArray(val)) return Promise$_successAdapter(val, receiver);
- var ret = util.tryCatchApply(this, [null].concat(val), receiver);
+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.invokeLater(thrower, void 0, ret.e);
+ async.throwLater(ret.e);
}
}
-function Promise$_successAdapter(val, receiver) {
- var nodeback = this;
- var ret = val === void 0
- ? tryCatch1(nodeback, receiver, null)
- : tryCatch2(nodeback, receiver, null, val);
+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.invokeLater(thrower, void 0, ret.e);
+ async.throwLater(ret.e);
}
}
-function Promise$_errorAdapter(reason, receiver) {
- var nodeback = this;
- var ret = tryCatch1(nodeback, receiver, reason);
+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.invokeLater(thrower, void 0, ret.e);
+ async.throwLater(ret.e);
}
}
-Promise.prototype.nodeify = function Promise$nodeify(nodeback, options) {
+Promise.prototype.nodeify = function (nodeback, options) {
if (typeof nodeback == "function") {
- var adapter = Promise$_successAdapter;
- if (options !== void 0 && Object(options).spread) {
- adapter = Promise$_spreadAdapter;
+ var adapter = successAdapter;
+ if (options !== undefined && Object(options).spread) {
+ adapter = spreadAdapter;
}
this._then(
adapter,
- Promise$_errorAdapter,
- void 0,
- nodeback,
- this._boundTo
+ errorAdapter,
+ undefined,
+ this,
+ nodeback
);
}
return this;
};
};
-},{"./async.js":2,"./util.js":35}],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(Promise, PromiseArray) {
-var util = require("./util.js");
-var async = require("./async.js");
-var errors = require("./errors.js");
-var tryCatch1 = util.tryCatch1;
+var util = _dereq_("./util.js");
+var async = _dereq_("./async.js");
+var tryCatch = util.tryCatch;
var errorObj = util.errorObj;
-Promise.prototype.progressed = function Promise$progressed(handler) {
- return this._then(void 0, void 0, handler, void 0, void 0);
+Promise.prototype.progressed = function (handler) {
+ return this._then(undefined, undefined, handler, undefined, undefined);
};
-Promise.prototype._progress = function Promise$_progress(progressValue) {
+Promise.prototype._progress = function (progressValue) {
if (this._isFollowingOrFulfilledOrRejected()) return;
- this._progressUnchecked(progressValue);
+ this._target()._progressUnchecked(progressValue);
};
-Promise.prototype._clearFirstHandlerData$Base =
-Promise.prototype._clearFirstHandlerData;
-Promise.prototype._clearFirstHandlerData =
-function Promise$_clearFirstHandlerData() {
- this._clearFirstHandlerData$Base();
- this._progressHandler0 = void 0;
-};
-
-Promise.prototype._progressHandlerAt =
-function Promise$_progressHandlerAt(index) {
+Promise.prototype._progressHandlerAt = function (index) {
return index === 0
? this._progressHandler0
: this[(index << 2) + index - 5 + 2];
};
-Promise.prototype._doProgressWith =
-function Promise$_doProgressWith(progression) {
+Promise.prototype._doProgressWith = function (progression) {
var progressValue = progression.value;
var handler = progression.handler;
var promise = progression.promise;
var receiver = progression.receiver;
- var ret = tryCatch1(handler, receiver, progressValue);
+ var ret = tryCatch(handler).call(receiver, progressValue);
if (ret === errorObj) {
if (ret.e != null &&
ret.e.name !== "StopProgressPropagation") {
- var trace = errors.canAttach(ret.e)
- ? ret.e : new Error(ret.e + "");
+ 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, void 0);
+ ret._then(promise._progress, null, null, promise, undefined);
} else {
promise._progress(ret);
}
};
-Promise.prototype._progressUnchecked =
-function Promise$_progressUnchecked(progressValue) {
- if (!this.isPending()) return;
+Promise.prototype._progressUnchecked = function (progressValue) {
var len = this._length();
var progress = this._progress;
for (var i = 0; i < len; i++) {
@@ -1965,9 +2092,8 @@ function Promise$_progressUnchecked(progressValue) {
var receiver = this._receiverAt(i);
if (typeof handler === "function") {
handler.call(receiver, progressValue, promise);
- } else if (receiver instanceof Promise && receiver._isProxied()) {
- receiver._progressUnchecked(progressValue);
- } else if (receiver instanceof PromiseArray) {
+ } else if (receiver instanceof PromiseArray &&
+ !receiver._isResolved()) {
receiver._promiseProgressed(progressValue, promise);
}
continue;
@@ -1987,118 +2113,69 @@ function Promise$_progressUnchecked(progressValue) {
};
};
-},{"./async.js":2,"./errors.js":10,"./util.js":35}],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.
- *
- */
+},{"./async.js":2,"./util.js":38}],23:[function(_dereq_,module,exports){
"use strict";
-var old;
-if (typeof Promise !== "undefined") old = Promise;
-function noConflict(bluebird) {
- try { if (Promise === bluebird) Promise = old; }
- catch (e) {}
- return bluebird;
-}
module.exports = function() {
-var util = require("./util.js");
-var async = require("./async.js");
-var errors = require("./errors.js");
-
+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 cast = require("./thenables.js")(Promise, INTERNAL);
-var PromiseArray = require("./promise_array.js")(Promise, INTERNAL, cast);
-var CapturedTrace = require("./captured_trace.js")();
-var CatchFilter = require("./catch_filter.js")(NEXT_FILTER);
-var PromiseResolver = require("./promise_resolver.js");
-
-var isArray = util.isArray;
-
+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 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 OperationalError = errors.OperationalError;
-var originatesFromRejection = errors.originatesFromRejection;
-var markAsOriginatingFromRejection = errors.markAsOriginatingFromRejection;
-var canAttach = errors.canAttach;
-var thrower = util.thrower;
-var apiRejection = require("./errors_api_rejection")(Promise);
-
-
-var makeSelfResolutionError = function Promise$_makeSelfResolutionError() {
- return new TypeError("circular promise resolution chain");
-};
+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;
+ this._boundTo = undefined;
if (resolver !== INTERNAL) this._resolveFromResolver(resolver);
}
-function returnFirstElement(elements) {
- return elements[0];
-}
-
-Promise.prototype.bind = function Promise$bind(thisArg) {
- var maybePromise = cast(thisArg, void 0);
- var ret = new Promise(INTERNAL);
- if (maybePromise instanceof Promise) {
- var binder = maybePromise.then(function(thisArg) {
- ret._setBoundTo(thisArg);
- });
- var p = Promise.all([this, binder]).then(returnFirstElement);
- ret._follow(p);
- } else {
- ret._follow(this);
- ret._setBoundTo(thisArg);
- }
- ret._propagateFrom(this, 2 | 1);
- 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),
@@ -2108,393 +2185,282 @@ function Promise$catch(fn) {
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);
- return Promise.reject(catchFilterTypeError);
+ 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();
var catchFilter = new CatchFilter(catchInstances, fn, this);
- return this._then(void 0, catchFilter.doFilter, void 0,
- catchFilter, void 0);
+ return this._then(undefined, catchFilter.doFilter, undefined,
+ catchFilter, undefined);
}
- return this._then(void 0, fn, void 0, void 0, void 0);
+ return this._then(undefined, fn, undefined, undefined, undefined);
};
-Promise.prototype.then =
-function Promise$then(didFulfill, didReject, didProgress) {
+Promise.prototype.reflect = function () {
+ return this._then(reflect, reflect, undefined, this, undefined);
+};
+
+Promise.prototype.then = function (didFulfill, didReject, didProgress) {
return this._then(didFulfill, didReject, didProgress,
- void 0, void 0);
+ 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);
+ undefined, undefined);
promise._setIsFinal();
};
-Promise.prototype.spread = function Promise$spread(didFulfill, didReject) {
- return this._then(didFulfill, didReject, void 0,
- APPLY, void 0);
+Promise.prototype.spread = function (didFulfill, didReject) {
+ var followee = this._target();
+ var target = followee._isSpreadable()
+ ? (followee === this ? this : this.then())
+ : this.all();
+ return target._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;
+ ret.rejectionReason = this.reason();
ret.isRejected = true;
}
return ret;
};
-Promise.prototype.all = function Promise$all() {
- return new PromiseArray(this).promise();
+Promise.prototype.all = function () {
+ var ret = new PromiseArray(this).promise();
+ ret._setIsSpreadable();
+ return ret;
};
+Promise.prototype.error = function (fn) {
+ return this.caught(util.originatesFromRejection, fn);
+};
-Promise.is = function Promise$Is(val) {
+Promise.is = function (val) {
return val instanceof Promise;
};
-Promise.all = function Promise$All(promises) {
- return new PromiseArray(promises).promise();
-};
-
-Promise.prototype.error = function Promise$_error(fn) {
- return this.caught(originatesFromRejection, fn);
-};
-
-Promise.prototype._resolveFromSyncValue =
-function Promise$_resolveFromSyncValue(value) {
- if (value === errorObj) {
- this._cleanValues();
- this._setRejected();
- this._settledValue = value.e;
- this._ensurePossibleRejectionHandled();
- } else {
- var maybePromise = cast(value, 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);
- ret._setTrace(void 0);
- ret._resolveFromSyncValue(value);
- 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);
-
+Promise.fromNode = function(fn) {
var ret = new Promise(INTERNAL);
- ret._setTrace(void 0);
- ret._resolveFromSyncValue(value);
+ var result = tryCatch(fn)(nodebackForPromise(ret));
+ if (result === errorObj) {
+ ret._rejectCallback(result.e, true, true);
+ }
return ret;
};
-Promise.defer = Promise.pending = function Promise$Defer() {
+Promise.all = function (promises) {
+ var ret = new PromiseArray(promises).promise();
+ ret._setIsSpreadable();
+ return ret;
+};
+
+Promise.defer = Promise.pending = function () {
var promise = new Promise(INTERNAL);
- promise._setTrace(void 0);
return new PromiseResolver(promise);
};
-Promise.bind = function Promise$Bind(thisArg) {
- var maybePromise = cast(thisArg, void 0);
- var ret = new Promise(INTERNAL);
- ret._setTrace(void 0);
-
- if (maybePromise instanceof Promise) {
- var p = maybePromise.then(function(thisArg) {
- ret._setBoundTo(thisArg);
- });
- ret._follow(p);
- } else {
- ret._setBoundTo(thisArg);
- ret._setFulfilled();
- }
- return ret;
-};
-
-Promise.cast = function Promise$_Cast(obj) {
- var ret = cast(obj, void 0);
+Promise.cast = function (obj) {
+ var ret = tryConvertToPromise(obj);
if (!(ret instanceof Promise)) {
var val = ret;
ret = new Promise(INTERNAL);
- ret._setTrace(void 0);
- ret._setFulfilled();
- ret._cleanValues();
- ret._settledValue = val;
+ ret._fulfillUnchecked(val);
}
return ret;
};
Promise.resolve = Promise.fulfilled = Promise.cast;
-Promise.reject = Promise.rejected = function Promise$Reject(reason) {
+Promise.reject = Promise.rejected = function (reason) {
var ret = new Promise(INTERNAL);
- ret._setTrace(void 0);
- markAsOriginatingFromRejection(reason);
- ret._cleanValues();
- ret._setRejected();
- ret._settledValue = reason;
- if (!canAttach(reason)) {
- var trace = new Error(reason + "");
- ret._setCarriedStackTrace(trace);
- }
- ret._ensurePossibleRejectionHandled();
+ ret._captureStackTrace();
+ ret._rejectCallback(reason, true);
return ret;
};
-Promise.onPossiblyUnhandledRejection =
-function Promise$OnPossiblyUnhandledRejection(fn) {
- CapturedTrace.possiblyUnhandledRejection = typeof fn === "function"
- ? fn : void 0;
+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;
};
-var unhandledRejectionHandled;
-Promise.onUnhandledRejectionHandled =
-function Promise$onUnhandledRejectionHandled(fn) {
- unhandledRejectionHandled = typeof fn === "function" ? fn : 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._then =
-function Promise$_then(
+Promise.prototype._then = function (
didFulfill,
didReject,
didProgress,
receiver,
internalData
) {
- var haveInternalData = internalData !== void 0;
+ var haveInternalData = internalData !== undefined;
var ret = haveInternalData ? internalData : new Promise(INTERNAL);
if (!haveInternalData) {
- if (debugging) {
- var haveSameContext = this._peekContext() === this._traceParent;
- ret._traceParent = haveSameContext ? this._traceParent : this;
+ ret._propagateFrom(this, 4 | 1);
+ ret._captureStackTrace();
+ }
+
+ var target = this._target();
+ if (target !== this) {
+ if (!haveInternalData) {
+ ret._setIsMigrated();
+ if (receiver === undefined) {
+ ret._setIsMigratingBinding();
+ receiver = this;
+ }
}
- ret._propagateFrom(this, 7);
}
var callbackIndex =
- this._addCallbacks(didFulfill, didReject, didProgress, ret, receiver);
+ 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 & 262143;
+Promise.prototype._settlePromiseAtPostResolution = function (index) {
+ if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled();
+ this._settlePromiseAt(index);
};
-Promise.prototype._isFollowingOrFulfilledOrRejected =
-function Promise$_isFollowingOrFulfilledOrRejected() {
+Promise.prototype._length = function () {
+ return this._bitField & 131071;
+};
+
+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 & -262144) |
- (len & 262143);
+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._isSpreadable = function () {
+ return (this._bitField & 131072) > 0;
};
-Promise.prototype._unsetRejectionIsUnhandled =
-function Promise$_unsetRejectionIsUnhandled() {
- this._bitField = this._bitField & (~2097152);
- if (this._isUnhandledRejectionNotified()) {
- this._unsetUnhandledRejectionIsNotified();
- this._notifyUnhandledRejectionIsHandled();
- }
+Promise.prototype._setIsSpreadable = function () {
+ this._bitField = this._bitField | 131072;
};
-Promise.prototype._isRejectionUnhandled =
-function Promise$_isRejectionUnhandled() {
- return (this._bitField & 2097152) > 0;
+Promise.prototype._setIsMigrated = function () {
+ this._bitField = this._bitField | 4194304;
};
-Promise.prototype._setUnhandledRejectionIsNotified =
-function Promise$_setUnhandledRejectionIsNotified() {
- this._bitField = this._bitField | 524288;
+Promise.prototype._unsetIsMigrated = function () {
+ this._bitField = this._bitField & (~4194304);
};
-Promise.prototype._unsetUnhandledRejectionIsNotified =
-function Promise$_unsetUnhandledRejectionIsNotified() {
- this._bitField = this._bitField & (~524288);
+Promise.prototype._isMigrated = function () {
+ return (this._bitField & 4194304) > 0;
};
-Promise.prototype._isUnhandledRejectionNotified =
-function Promise$_isUnhandledRejectionNotified() {
- return (this._bitField & 524288) > 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) {
+Promise.prototype._receiverAt = function (index) {
var ret = index === 0
? this._receiver0
- : this[(index << 2) + index - 5 + 4];
- if (this._isBound() && ret === void 0) {
+ : this[
+ index * 5 - 5 + 4];
+ if (this._isBound() && ret === undefined) {
return this._boundTo;
}
return ret;
};
-Promise.prototype._promiseAt = function Promise$_promiseAt(index) {
+Promise.prototype._promiseAt = function (index) {
return index === 0
? this._promise0
- : this[(index << 2) + index - 5 + 3];
+ : this[index * 5 - 5 + 3];
};
-Promise.prototype._fulfillmentHandlerAt =
-function Promise$_fulfillmentHandlerAt(index) {
+Promise.prototype._fulfillmentHandlerAt = function (index) {
return index === 0
? this._fulfillmentHandler0
- : this[(index << 2) + index - 5 + 0];
+ : this[index * 5 - 5 + 0];
};
-Promise.prototype._rejectionHandlerAt =
-function Promise$_rejectionHandlerAt(index) {
+Promise.prototype._rejectionHandlerAt = function (index) {
return index === 0
? this._rejectionHandler0
- : this[(index << 2) + index - 5 + 1];
+ : this[index * 5 - 5 + 1];
};
-Promise.prototype._addCallbacks = function Promise$_addCallbacks(
+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();
+ if (receiver === undefined) {
+ receiver = follower;
+ promise._setIsMigratingBinding();
+ }
+ }
+ this._addCallbacks(fulfill, reject, progress, promise, receiver);
+};
+
+Promise.prototype._addCallbacks = function (
fulfill,
reject,
progress,
@@ -2503,38 +2469,37 @@ Promise.prototype._addCallbacks = function Promise$_addCallbacks(
) {
var index = this._length();
- if (index >= 262143 - 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 base = (index << 2) + index - 5;
+ var base = index * 5 - 5;
this[base + 3] = promise;
this[base + 4] = receiver;
- this[base + 0] = typeof fulfill === "function"
- ? fulfill : void 0;
- this[base + 1] = typeof reject === "function"
- ? reject : void 0;
- this[base + 2] = typeof progress === "function"
- ? progress : void 0;
+ 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 Promise$_setProxyHandlers(receiver, promiseSlotValue) {
+Promise.prototype._setProxyHandlers = function (receiver, promiseSlotValue) {
var index = this._length();
- if (index >= 262143 - 5) {
+ if (index >= 131071 - 5) {
index = 0;
this._setLength(0);
}
@@ -2542,243 +2507,120 @@ function Promise$_setProxyHandlers(receiver, promiseSlotValue) {
this._promise0 = promiseSlotValue;
this._receiver0 = receiver;
} else {
- var base = (index << 2) + index - 5;
+ var base = index * 5 - 5;
this[base + 3] = promiseSlotValue;
this[base + 4] = receiver;
- this[base + 0] =
- this[base + 1] =
- this[base + 2] = void 0;
}
this._setLength(index + 1);
};
-Promise.prototype._proxyPromiseArray =
-function Promise$_proxyPromiseArray(promiseArray, index) {
+Promise.prototype._proxyPromiseArray = function (promiseArray, index) {
this._setProxyHandlers(promiseArray, index);
};
-Promise.prototype._proxyPromise = function Promise$_proxyPromise(promise) {
- promise._setProxied();
- this._setProxyHandlers(promise, -15);
-};
+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);
-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._resolveFromResolver =
-function Promise$_resolveFromResolver(resolver) {
- var promise = this;
- this._setTrace(void 0);
- this._pushContext();
-
- function Promise$_resolver(val) {
- if (promise._tryFollow(val)) {
- return;
+ 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);
}
- 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);
- 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._spreadSlowCase =
-function Promise$_spreadSlowCase(targetFn, promise, values, boundTo) {
- var promiseForAll = new PromiseArray(values).promise();
- var promise2 = promiseForAll._then(function() {
- return targetFn.apply(boundTo, arguments);
- }, void 0, void 0, APPLY, void 0);
- promise._follow(promise2);
-};
-
-Promise.prototype._callSpread =
-function Promise$_callSpread(handler, promise, value) {
- var boundTo = this._boundTo;
- if (isArray(value)) {
- for (var i = 0, len = value.length; i < len; ++i) {
- if (cast(value[i], void 0) instanceof Promise) {
- this._spreadSlowCase(handler, promise, value, boundTo);
- return;
- }
- }
- }
- promise._pushContext();
- return tryCatchApply(handler, value, boundTo);
-};
-
-Promise.prototype._callHandler =
-function Promise$_callHandler(
- handler, receiver, promise, value) {
- var x;
- if (receiver === APPLY && !this.isRejected()) {
- x = this._callSpread(handler, promise, value);
+ this._setFollowing();
+ this._setLength(0);
+ this._setFollowee(promise);
+ } else if (promise._isFulfilled()) {
+ this._fulfillUnchecked(promise._value());
} else {
- promise._pushContext();
- x = tryCatch1(handler, receiver, value);
- }
- promise._popContext();
- return x;
-};
-
-Promise.prototype._settlePromiseFromHandler =
-function Promise$_settlePromiseFromHandler(
- handler, receiver, value, promise
-) {
- if (!(promise instanceof Promise)) {
- handler.call(receiver, value, promise);
- return;
- }
- var x = this._callHandler(handler, receiver, promise, value);
- 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 = cast(x, promise);
- if (castValue instanceof Promise) {
- if (castValue.isRejected() &&
- !castValue._isCarryingStackTrace() &&
- !canAttach(castValue._settledValue)) {
- var trace = new Error(castValue._settledValue + "");
- promise._attachExtraTrace(trace);
- castValue._setCarriedStackTrace(trace);
- }
- promise._follow(castValue);
- promise._propagateFrom(castValue, 1);
- } else {
- promise._fulfillUnchecked(x);
- }
- }
-};
-
-Promise.prototype._follow =
-function Promise$_follow(promise) {
- this._setFollowing();
-
- if (promise.isPending()) {
- this._propagateFrom(promise, 1);
- promise._proxyPromise(this);
- } else if (promise.isFulfilled()) {
- this._fulfillUnchecked(promise._settledValue);
- } else {
- this._rejectUnchecked(promise._settledValue,
+ this._rejectUnchecked(promise._reason(),
promise._getCarriedStackTrace());
}
+};
- if (promise._isRejectionUnhandled()) promise._unsetRejectionIsUnhandled();
+Promise.prototype._rejectCallback =
+function(reason, synchronous, shouldNotMarkOriginatingFromRejection) {
+ if (!shouldNotMarkOriginatingFromRejection) {
+ util.markAsOriginatingFromRejection(reason);
+ }
+ var trace = util.ensureErrorObject(reason);
+ var hasStack = util.canAttachTrace(reason) &&
+ typeof trace.stack === "string" && trace.stack.length > 0;
+ this._attachExtraTrace(trace, synchronous ? hasStack : false);
+ this._reject(reason, trace === reason ? undefined : trace);
+};
- if (debugging &&
- promise._traceParent == null) {
- promise._traceParent = this;
+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 (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 = cast(value, void 0);
- if (!(maybePromise instanceof Promise)) {
- return false;
- }
- this._follow(maybePromise);
- return true;
-};
+ promise._popContext();
-Promise.prototype._resetTrace = function Promise$_resetTrace() {
- if (debugging) {
- this._trace = new CapturedTrace(this._peekContext() === void 0);
+ if (x === errorObj || x === promise || x === NEXT_FILTER) {
+ var err = x === promise ? makeSelfResolutionError() : x.e;
+ promise._rejectCallback(err, false, true);
+ } else {
+ promise._resolveCallback(x);
}
};
-Promise.prototype._setTrace = function Promise$_setTrace(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(isTopLevel);
- }
- }
- return this;
+Promise.prototype._target = function() {
+ var ret = this;
+ while (ret._isFollowing()) ret = ret._followee();
+ return ret;
};
-Promise.prototype._attachExtraTrace =
-function Promise$_attachExtraTrace(error) {
- if (debugging) {
- var promise = this;
- var stack = error.stack;
- stack = typeof stack === "string" ? stack.split("\n") : [];
- CapturedTrace.protectErrorMessageNewlines(stack);
- var headerLineCount = 1;
- var combinedTraces = 1;
- while(promise != null &&
- promise._trace != null) {
- stack = CapturedTrace.combine(
- stack,
- promise._trace.stack.split("\n")
- );
- promise = promise._traceParent;
- combinedTraces++;
- }
-
- var stackTraceLimit = Error.stackTraceLimit || 10;
- var max = (stackTraceLimit + headerLineCount) * combinedTraces;
- var len = stack.length;
- if (len > max) {
- stack.length = max;
- }
-
- if (len > 0)
- stack[0] = stack[0].split("\u0002\u0000\u0001").join("\n");
-
- if (stack.length <= headerLineCount) {
- error.stack = "(No stack trace)";
- } else {
- error.stack = stack.join("\n");
- }
- }
+Promise.prototype._followee = function() {
+ return this._rejectionHandler0;
};
-Promise.prototype._cleanValues = function Promise$_cleanValues() {
+Promise.prototype._setFollowee = function(promise) {
+ this._rejectionHandler0 = promise;
+};
+
+Promise.prototype._cleanValues = function () {
if (this._cancellable()) {
- this._cancellationParent = void 0;
+ this._cancellationParent = undefined;
}
};
-Promise.prototype._propagateFrom =
-function Promise$_propagateFrom(parent, flags) {
+Promise.prototype._propagateFrom = function (parent, flags) {
if ((flags & 1) > 0 && parent._cancellable()) {
this._setCancellable();
this._cancellationParent = parent;
@@ -2786,317 +2628,209 @@ function Promise$_propagateFrom(parent, flags) {
if ((flags & 4) > 0) {
this._setBoundTo(parent._boundTo);
}
- if ((flags & 2) > 0) {
- this._setTrace(parent);
- }
};
-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 (isPromise && promise._isMigratingBinding()) {
+ promise._unsetIsMigratingBinding();
+ receiver = receiver._boundTo;
+ }
+
+ this._clearCallbackDataAtIndex(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 (receiver instanceof PromiseArray) {
- if (isFulfilled) receiver._promiseFulfilled(value, promise);
- else receiver._promiseRejected(value, promise);
- done = true;
+ 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 >= 4) {
- this._queueGC();
+ if (index >= 4 && (index & 31) === 4)
+ async.invokeLater(this._setLength, this, 0);
+};
+
+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._isProxied = function Promise$_isProxied() {
- return (this._bitField & 4194304) === 4194304;
+Promise.prototype._isSettlePromisesQueued = function () {
+ return (this._bitField &
+ -1073741824) === -1073741824;
};
-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() {
+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() * 5 - 5;
- for (var i = 0; i < len; i++) {
- delete this[i];
- }
- this._clearFirstHandlerData();
- this._setLength(0);
- this._unsetGcQueued();
-};
-
-Promise.prototype._clearFirstHandlerData =
-function Promise$_clearFirstHandlerData() {
- this._fulfillmentHandler0 = void 0;
- this._rejectionHandler0 = void 0;
- this._promise0 = void 0;
- this._receiver0 = void 0;
-};
-
-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._settlePromises, 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 (trace !== undefined && trace !== reason) {
+ this._setCarriedStackTrace(trace);
+ }
- if (len > 0) {
- async.invoke(this._rejectPromises, this, null);
+ if (this._length() > 0) {
+ this._queueSettlePromises();
} else {
this._ensurePossibleRejectionHandled();
}
};
-Promise.prototype._rejectPromises = function Promise$_rejectPromises() {
- this._settlePromises();
- this._unsetCarriedStackTrace();
-};
-
-Promise.prototype._settlePromises = function Promise$_settlePromises() {
+Promise.prototype._settlePromises = function () {
+ this._unsetSettlePromisesQueued();
var len = this._length();
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._notifyUnhandledRejectionIsHandled =
-function Promise$_notifyUnhandledRejectionIsHandled() {
- if (typeof unhandledRejectionHandled === "function") {
- async.invokeLater(unhandledRejectionHandled, void 0, this);
- }
-};
-
-Promise.prototype._notifyUnhandledRejection =
-function Promise$_notifyUnhandledRejection() {
- if (this._isRejectionUnhandled()) {
- var reason = this._settledValue;
- var trace = this._getCarriedStackTrace();
-
- this._setUnhandledRejectionIsNotified();
-
- 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();
-};
-
-Promise.noConflict = function Promise$NoConflict() {
- return noConflict(Promise);
-};
-
-Promise.setScheduler = function(fn) {
- if (typeof fn !== "function") throw new TypeError("fn must be a function");
- async._schedule = fn;
-};
-
-if (!CapturedTrace.isSupported()) {
- Promise.longStackTraces = function(){};
- debugging = false;
-}
-
Promise._makeSelfResolutionError = makeSelfResolutionError;
-require("./finally.js")(Promise, NEXT_FILTER, cast);
-require("./direct_resolve.js")(Promise);
-require("./synchronous_inspection.js")(Promise);
-require("./join.js")(Promise, PromiseArray, cast, INTERNAL);
-Promise.RangeError = RangeError;
-Promise.CancellationError = CancellationError;
-Promise.TimeoutError = TimeoutError;
-Promise.TypeError = TypeError;
-Promise.OperationalError = OperationalError;
-Promise.RejectionError = OperationalError;
-Promise.AggregateError = errors.AggregateError;
+_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);
util.toFastProperties(Promise);
util.toFastProperties(Promise.prototype);
Promise.Promise = Promise;
-require('./timers.js')(Promise,INTERNAL,cast);
-require('./race.js')(Promise,INTERNAL,cast);
-require('./call_get.js')(Promise);
-require('./generators.js')(Promise,apiRejection,INTERNAL,cast);
-require('./map.js')(Promise,PromiseArray,apiRejection,cast,INTERNAL);
-require('./nodeify.js')(Promise);
-require('./promisify.js')(Promise,INTERNAL);
-require('./props.js')(Promise,PromiseArray,cast);
-require('./reduce.js')(Promise,PromiseArray,apiRejection,cast,INTERNAL);
-require('./settle.js')(Promise,PromiseArray);
-require('./some.js')(Promise,PromiseArray,apiRejection);
-require('./progress.js')(Promise,PromiseArray);
-require('./cancel.js')(Promise,INTERNAL);
-require('./filter.js')(Promise,INTERNAL);
-require('./any.js')(Promise,PromiseArray);
-require('./each.js')(Promise,INTERNAL);
-require('./using.js')(Promise,apiRejection,cast);
+CapturedTrace.setBounds(async.firstLineError, util.lastLineError);
+_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);
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,"./each.js":9,"./errors.js":10,"./errors_api_rejection":11,"./filter.js":13,"./finally.js":14,"./generators.js":15,"./join.js":16,"./map.js":17,"./nodeify.js":18,"./progress.js":19,"./promise_array.js":21,"./promise_resolver.js":22,"./promisify.js":23,"./props.js":24,"./race.js":26,"./reduce.js":27,"./settle.js":29,"./some.js":30,"./synchronous_inspection.js":31,"./thenables.js":32,"./timers.js":33,"./using.js":34,"./util.js":35}],21:[function(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.
- *
- */
+},{"./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, cast) {
-var canAttach = require("./errors.js").canAttach;
-var util = require("./util.js");
+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 {};
}
@@ -3104,55 +2838,52 @@ function toResolutionValue(val) {
function PromiseArray(values) {
var promise = this._promise = new Promise(INTERNAL);
- var parent = void 0;
+ var parent;
if (values instanceof Promise) {
parent = values;
promise._propagateFrom(parent, 1 | 4);
}
- promise._setTrace(parent);
this._values = values;
this._length = 0;
this._totalResolved = 0;
- this._init(void 0, -2);
+ this._init(undefined, -2);
}
-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 = cast(this._values, void 0);
+PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
+ var values = tryConvertToPromise(this._values, this._promise);
if (values instanceof Promise) {
- this._values = values;
values._setBoundTo(this._promise._boundTo);
- if (values.isFulfilled()) {
- values = values._settledValue;
+ 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;
}
- } else if (values.isPending()) {
+ } else if (values._isPending()) {
values._then(
- PromiseArray$_init,
+ init,
this._reject,
- void 0,
+ undefined,
this,
resolveValueIfEmpty
);
return;
} else {
- values._unsetRejectionIsUnhandled();
- this._reject(values._settledValue);
+ this._reject(values._reason());
return;
}
} else if (!isArray(values)) {
- var err = new Promise.TypeError("expecting an array, a promise or a thenable");
- this.__hardReject__(err);
+ this._promise._reject(apiRejection("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a")._reason());
return;
}
@@ -3166,72 +2897,45 @@ function PromiseArray$_init(_, resolveValueIfEmpty) {
return;
}
var len = this.getActualLength(values.length);
- var newLen = len;
- var newValues = this.shouldCopyValues() ? new Array(len) : this._values;
- var isDirectScanNeeded = false;
+ this._length = len;
+ this._values = this.shouldCopyValues() ? new Array(len) : this._values;
+ var promise = this._promise;
for (var i = 0; i < len; ++i) {
- var maybePromise = cast(values[i], void 0);
+ var isResolved = this._isResolved();
+ var maybePromise = tryConvertToPromise(values[i], promise);
if (maybePromise instanceof Promise) {
- if (maybePromise.isPending()) {
- maybePromise._proxyPromiseArray(this, i);
- } else {
+ maybePromise = maybePromise._target();
+ if (isResolved) {
maybePromise._unsetRejectionIsUnhandled();
- isDirectScanNeeded = true;
+ } else if (maybePromise._isPending()) {
+ maybePromise._proxyPromiseArray(this, i);
+ } else if (maybePromise._isFulfilled()) {
+ this._promiseFulfilled(maybePromise._value(), i);
+ } else {
+ this._promiseRejected(maybePromise._reason(), i);
}
- } else {
- isDirectScanNeeded = true;
+ } else if (!isResolved) {
+ this._promiseFulfilled(maybePromise, i);
}
- newValues[i] = maybePromise;
- }
- this._values = newValues;
- this._length = newLen;
- if (isDirectScanNeeded) {
- this._scanDirectValues(len);
}
};
-PromiseArray.prototype._settlePromiseAt =
-function PromiseArray$_settlePromiseAt(index) {
- var value = this._values[index];
- if (!(value instanceof Promise)) {
- this._promiseFulfilled(value, index);
- } else if (value.isFulfilled()) {
- this._promiseFulfilled(value._settledValue, index);
- } else if (value.isRejected()) {
- this._promiseRejected(value._settledValue, index);
- }
-};
-
-PromiseArray.prototype._scanDirectValues =
-function PromiseArray$_scanDirectValues(len) {
- for (var i = 0; i < len; ++i) {
- if (this._isResolved()) {
- break;
- }
- 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
@@ -3239,9 +2943,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) {
@@ -3249,77 +2951,60 @@ 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);
};
-PromiseArray.prototype.shouldCopyValues =
-function PromiseArray$_shouldCopyValues() {
+PromiseArray.prototype.shouldCopyValues = function () {
return true;
};
-PromiseArray.prototype.getActualLength =
-function PromiseArray$getActualLength(len) {
+PromiseArray.prototype.getActualLength = function (len) {
return len;
};
return PromiseArray;
};
-},{"./errors.js":10,"./util.js":35}],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 OperationalError = errors.OperationalError;
-var async = require("./async.js");
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;
}
+var rErrorKey = /^(?:name|message|stack|cause)$/;
function wrapAsOperationalError(obj) {
var ret;
if (isUntypedError(obj)) {
ret = new OperationalError(obj);
- } else {
- ret = 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) {
@@ -3334,21 +3019,20 @@ function nodebackForPromise(promise) {
}
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;
};
}
@@ -3364,104 +3048,61 @@ 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) {
+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.");
+ 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");
}
-
- var promise = this.promise;
- if (promise._tryFollow(value)) {
- return;
- }
- async.invoke(promise._fulfill, promise, value);
+ this.promise._resolveCallback(value);
};
-PromiseResolver.prototype.reject = function PromiseResolver$reject(reason) {
+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.");
- }
-
- 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);
+ 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) {
+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.");
+ 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(this.promise._progress, this.promise, value);
+ 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":10,"./es5.js":12,"./util.js":35}],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 THIS = {};
-var util = require("./util.js");
-var nodebackForPromise = require("./promise_resolver.js")
+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 = require("./errors").TypeError;
+var TypeError = _dereq_("./errors").TypeError;
var defaultSuffix = "Async";
var defaultFilter = function(name, func) {
return util.isIdentifier(name) &&
@@ -3470,11 +3111,6 @@ var defaultFilter = function(name, func) {
};
var defaultPromisified = {__isPromisified__: true};
-
-function escapeIdentRegex(str) {
- return str.replace(/([$])/, "\\$");
-}
-
function isPromisified(fn) {
try {
return fn.__isPromisified__ === true;
@@ -3496,8 +3132,8 @@ function checkValid(ret, suffix, suffixRegexp) {
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 '"+suffix+"'-suffix");
+ 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));
}
}
}
@@ -3510,10 +3146,12 @@ function promisifiableMethods(obj, suffix, suffixRegexp, filter) {
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)) {
+ filter(key, value, obj, passesDefaultFilter)) {
ret.push(key, value);
}
}
@@ -3521,42 +3159,48 @@ function promisifiableMethods(obj, suffix, suffixRegexp, filter) {
return ret;
}
-function switchCaseArgumentOrder(likelyArgumentCount) {
+var escapeIdentRegex = function(str) {
+ return str.replace(/([$])/, "\\$");
+};
+
+var makeNodePromisifiedEval;
+if (!true) {
+var switchCaseArgumentOrder = function(likelyArgumentCount) {
var ret = [likelyArgumentCount];
var min = Math.max(0, likelyArgumentCount - 1 - 5);
for(var i = likelyArgumentCount - 1; i >= min; --i) {
- if (i === likelyArgumentCount) continue;
ret.push(i);
}
for(var i = likelyArgumentCount + 1; i <= 5; ++i) {
ret.push(i);
}
return ret;
-}
+};
-function argumentSequence(argumentCount) {
+var argumentSequence = function(argumentCount) {
return util.filledRange(argumentCount, "arguments[", "]");
-}
+};
-function parameterDeclaration(parameterCount) {
+var parameterDeclaration = function(parameterCount) {
return util.filledRange(parameterCount, "_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 generatePropertyAccess(key) {
+var generatePropertyAccess = function(key) {
if (util.isIdentifier(key)) {
return "." + key;
}
else return "['" + key.replace(/(['\\])/g, "\\$1") + "']";
-}
+};
-function makeNodePromisifiedEval(callback, receiver, originalName, fn, suffix) {
+makeNodePromisifiedEval =
+function(callback, receiver, originalName, fn, suffix) {
var newParameterCount = Math.max(0, parameterCount(fn) - 1);
var argumentOrder = switchCaseArgumentOrder(newParameterCount);
var callbackName =
@@ -3578,7 +3222,7 @@ function makeNodePromisifiedEval(callback, receiver, originalName, fn, suffix) {
callback.call(this, {{args}}, fn); \n\
break; \n\
";
- } else if (receiver !== void 0) {
+ } else if (receiver !== undefined) {
ret = " \n\
callback.call(receiver, {{args}}, fn); \n\
break; \n\
@@ -3635,11 +3279,12 @@ function makeNodePromisifiedEval(callback, receiver, originalName, fn, suffix) {
"maybeWrapAsError",
"nodebackForPromise",
"INTERNAL"," \n\
- var ret = function FunctionName(Parameters) { \n\
+ var ret = function (Parameters) { \n\
'use strict'; \n\
var len = arguments.length; \n\
var promise = new Promise(INTERNAL); \n\
- promise._setTrace(void 0); \n\
+ promise._captureStackTrace(); \n\
+ promise._setIsSpreadable(); \n\
var fn = nodebackForPromise(promise); \n\
try { \n\
switch(len) { \n\
@@ -3666,6 +3311,7 @@ function makeNodePromisifiedEval(callback, receiver, originalName, fn, suffix) {
nodebackForPromise,
INTERNAL
);
+};
}
function makeNodePromisifiedClosure(callback, receiver) {
@@ -3676,7 +3322,8 @@ function makeNodePromisifiedClosure(callback, receiver) {
callback = _receiver[callback];
}
var promise = new Promise(INTERNAL);
- promise._setTrace(void 0);
+ promise._captureStackTrace();
+ promise._setIsSpreadable();
var fn = nodebackForPromise(promise);
try {
callback.apply(_receiver, withAppended(arguments, fn));
@@ -3706,19 +3353,21 @@ function promisifyAll(obj, suffix, filter, promisifier) {
var promisifiedKey = key + suffix;
obj[promisifiedKey] = promisifier === makeNodePromisified
? makeNodePromisified(key, THIS, key, fn, suffix)
- : promisifier(fn);
+ : promisifier(fn, function() {
+ return makeNodePromisified(key, THIS, key, fn, suffix);
+ });
}
util.toFastProperties(obj);
return obj;
}
function promisify(callback, receiver) {
- return makeNodePromisified(callback, receiver, void 0, callback);
+ return makeNodePromisified(callback, receiver, undefined, callback);
}
-Promise.promisify = function Promise$Promisify(fn, receiver) {
+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;
@@ -3726,9 +3375,9 @@ Promise.promisify = function Promise$Promisify(fn, receiver) {
return promisify(fn, arguments.length < 2 ? THIS : receiver);
};
-Promise.promisifyAll = function Promise$PromisifyAll(target, options) {
+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");
+ 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;
@@ -3739,7 +3388,7 @@ Promise.promisifyAll = function Promise$PromisifyAll(target, options) {
if (typeof promisifier !== "function") promisifier = makeNodePromisified;
if (!util.isIdentifier(suffix)) {
- throw new RangeError("suffix must be a valid identifier");
+ throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/8FZo5V\u000a");
}
var keys = util.inheritedDataKeys(target, {includeHidden: true});
@@ -3757,35 +3406,13 @@ Promise.promisifyAll = function Promise$PromisifyAll(target, options) {
};
-},{"./errors":10,"./promise_resolver.js":22,"./util.js":35}],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.
- *
- */
+},{"./errors":13,"./promise_resolver.js":25,"./util.js":38}],27:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(Promise, PromiseArray, cast) {
-var util = require("./util.js");
-var apiRejection = require("./errors_api_rejection")(Promise);
+module.exports = function(
+ Promise, PromiseArray, tryConvertToPromise, apiRejection) {
+var util = _dereq_("./util.js");
var isObject = util.isObject;
-var es5 = require("./es5.js");
+var es5 = _dereq_("./es5.js");
function PropertiesPromiseArray(obj) {
var keys = es5.keys(obj);
@@ -3800,14 +3427,11 @@ function PropertiesPromiseArray(obj) {
}
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) {
@@ -3820,34 +3444,30 @@ 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
});
};
-PropertiesPromiseArray.prototype.shouldCopyValues =
-function PropertiesPromiseArray$_shouldCopyValues() {
+PropertiesPromiseArray.prototype.shouldCopyValues = function () {
return false;
};
-PropertiesPromiseArray.prototype.getActualLength =
-function PropertiesPromiseArray$getActualLength(len) {
+PropertiesPromiseArray.prototype.getActualLength = function (len) {
return len >> 1;
};
-function Promise$_Props(promises) {
+function props(promises) {
var ret;
- var castValue = cast(promises, void 0);
+ var castValue = tryConvertToPromise(promises);
if (!isObject(castValue)) {
- return apiRejection("cannot await properties of a non-object");
+ 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, void 0, void 0, void 0, void 0);
+ ret = castValue._then(
+ Promise.props, undefined, undefined, undefined, undefined);
} else {
ret = new PropertiesPromiseArray(castValue).promise();
}
@@ -3858,42 +3478,21 @@ function Promise$_Props(promises) {
return ret;
}
-Promise.prototype.props = function Promise$props() {
- return Promise$_Props(this);
+Promise.prototype.props = function () {
+ return props(this);
};
-Promise.props = function Promise$Props(promises) {
- return Promise$_Props(promises);
+Promise.props = function (promises) {
+ return props(promises);
};
};
-},{"./errors_api_rejection":11,"./es5.js":12,"./util.js":35}],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.
- *
- */
+},{"./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;
}
}
@@ -3901,15 +3500,13 @@ function Queue(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);
@@ -3917,7 +3514,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);
@@ -3934,204 +3548,138 @@ 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;
-},{}],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.
- *
- */
+},{}],29:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(Promise, INTERNAL, cast) {
-var apiRejection = require("./errors_api_rejection.js")(Promise);
-var isArray = require("./util.js").isArray;
+module.exports = function(
+ Promise, INTERNAL, tryConvertToPromise, apiRejection) {
+var isArray = _dereq_("./util.js").isArray;
-var raceLater = function Promise$_raceLater(promise) {
+var raceLater = function (promise) {
return promise.then(function(array) {
- return Promise$_Race(array, promise);
+ return race(array, promise);
});
};
-var hasOwn = {}.hasOwnProperty;
-function Promise$_Race(promises, parent) {
- var maybePromise = cast(promises, void 0);
+function race(promises, parent) {
+ var maybePromise = tryConvertToPromise(promises);
if (maybePromise instanceof Promise) {
return raceLater(maybePromise);
} else if (!isArray(promises)) {
- return apiRejection("expecting an array, a promise or a thenable");
+ return apiRejection("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a");
}
var ret = new Promise(INTERNAL);
- if (parent !== void 0) {
- ret._propagateFrom(parent, 7);
- } else {
- ret._setTrace(void 0);
+ 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];
- if (val === void 0 && !(hasOwn.call(promises, i))) {
+ if (val === undefined && !(i in promises)) {
continue;
}
- Promise.cast(val)._then(fulfill, reject, void 0, ret, null);
+ Promise.cast(val)._then(fulfill, reject, undefined, ret, null);
}
return ret;
}
-Promise.race = function Promise$Race(promises) {
- return Promise$_Race(promises, void 0);
+Promise.race = function (promises) {
+ return race(promises, undefined);
};
-Promise.prototype.race = function Promise$race() {
- return Promise$_Race(this, void 0);
+Promise.prototype.race = function () {
+ return race(this, undefined);
};
};
-},{"./errors_api_rejection.js":11,"./util.js":35}],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.
- *
- */
+},{"./util.js":38}],30:[function(_dereq_,module,exports){
"use strict";
-module.exports = function(Promise, PromiseArray, apiRejection, cast, INTERNAL) {
-var util = require("./util.js");
-var tryCatch4 = util.tryCatch4;
-var tryCatch3 = util.tryCatch3;
+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 === void 0);
+ this._zerothIsAccum = (accum === undefined);
this._gotAccum = false;
this._reducingIndex = (this._zerothIsAccum ? 1 : 0);
this._valuesPhase = undefined;
-
- var maybePromise = cast(accum, void 0);
+ var maybePromise = tryConvertToPromise(accum, this._promise);
var rejected = false;
var isPromise = maybePromise instanceof Promise;
if (isPromise) {
- if (maybePromise.isPending()) {
+ maybePromise = maybePromise._target();
+ if (maybePromise._isPending()) {
maybePromise._proxyPromiseArray(this, -1);
- } else if (maybePromise.isFulfilled()) {
- accum = maybePromise.value();
+ } else if (maybePromise._isFulfilled()) {
+ accum = maybePromise._value();
this._gotAccum = true;
} else {
- maybePromise._unsetRejectionIsUnhandled();
- this._reject(maybePromise.reason());
+ this._reject(maybePromise._reason());
rejected = true;
}
}
if (!(isPromise || this._zerothIsAccum)) this._gotAccum = true;
this._callback = fn;
this._accum = accum;
- if (!rejected) this._init$(void 0, -5);
+ if (!rejected) this._init$(undefined, -5);
}
util.inherits(ReductionPromiseArray, PromiseArray);
-ReductionPromiseArray.prototype._init =
-function ReductionPromiseArray$_init() {};
+ReductionPromiseArray.prototype._init = function () {};
-ReductionPromiseArray.prototype._resolveEmptyArray =
-function ReductionPromiseArray$_resolveEmptyArray() {
+ReductionPromiseArray.prototype._resolveEmptyArray = function () {
if (this._gotAccum || this._zerothIsAccum) {
this._resolve(this._preservedValues !== null
? [] : this._accum);
}
};
-ReductionPromiseArray.prototype._promiseFulfilled =
-function ReductionPromiseArray$_promiseFulfilled(value, index) {
+ReductionPromiseArray.prototype._promiseFulfilled = function (value, index) {
var values = this._values;
- if (values === null) return;
+ values[index] = value;
var length = this.length();
var preservedValues = this._preservedValues;
var isEach = preservedValues !== null;
@@ -4139,7 +3687,7 @@ function ReductionPromiseArray$_promiseFulfilled(value, index) {
var valuesPhase = this._valuesPhase;
var valuesPhaseIndex;
if (!valuesPhase) {
- valuesPhase = this._valuesPhase = Array(length);
+ 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.
- *
- */
+},{"./util.js":38}],31:[function(_dereq_,module,exports){
"use strict";
var schedule;
-var _MutationObserver;
if (typeof process === "object" && typeof process.version === "string") {
- schedule = function Promise$_Scheduler(fn) {
- process.nextTick(fn);
- };
+ var version = process.version.split(".").map(Number);
+ schedule = (version[0] === 0 && version[1] > 10) || (version[0] > 0)
+ ? global.setImmediate : process.nextTick;
}
-else if ((typeof MutationObserver !== "undefined" &&
- (_MutationObserver = MutationObserver)) ||
- (typeof WebKitMutationObserver !== "undefined" &&
- (_MutationObserver = WebKitMutationObserver))) {
- schedule = (function() {
+else if (typeof MutationObserver !== "undefined") {
+ schedule = function(fn) {
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.classList.toggle("foo");
- };
-
- })();
+ var observer = new MutationObserver(fn);
+ observer.observe(div, {attributes: true});
+ return function() { div.classList.toggle("foo"); };
+ };
+ schedule.isStatic = true;
}
else if (typeof setTimeout !== "undefined") {
- schedule = function Promise$_Scheduler(fn) {
+ schedule = function (fn) {
setTimeout(fn, 0);
};
}
-else throw new Error("no async scheduler available");
+else {
+ schedule = function() {
+ throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/m3OTXk\u000a");
+ };
+}
module.exports = schedule;
-},{}],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.
- *
- */
+},{}],32:[function(_dereq_,module,exports){
"use strict";
module.exports =
function(Promise, PromiseArray) {
var PromiseInspection = Promise.PromiseInspection;
-var util = require("./util.js");
+var util = _dereq_("./util.js");
function SettledPromiseArray(values) {
this.constructor$(values);
+ this._promise._setIsSpreadable();
}
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) {
@@ -4347,61 +3822,35 @@ 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);
};
-Promise.settle = function Promise$Settle(promises) {
+Promise.settle = function (promises) {
return new SettledPromiseArray(promises).promise();
};
-Promise.prototype.settle = function Promise$settle() {
+Promise.prototype.settle = function () {
return new SettledPromiseArray(this).promise();
};
};
-},{"./util.js":35}],30:[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(Promise, PromiseArray, apiRejection) {
-var util = require("./util.js");
-var RangeError = require("./errors.js").RangeError;
-var AggregateError = require("./errors.js").AggregateError;
+var util = _dereq_("./util.js");
+var RangeError = _dereq_("./errors.js").RangeError;
+var AggregateError = _dereq_("./errors.js").AggregateError;
var isArray = util.isArray;
@@ -4413,15 +3862,16 @@ function SomePromiseArray(values) {
}
util.inherits(SomePromiseArray, PromiseArray);
-SomePromiseArray.prototype._init = function SomePromiseArray$_init() {
+SomePromiseArray.prototype._init = function () {
if (!this._initialized) {
return;
}
+ this._promise._setIsSpreadable();
if (this._howMany === 0) {
this._resolve([]);
return;
}
- this._init$(void 0, -5);
+ this._init$(undefined, -5);
var isArrayResolved = isArray(this._values);
if (!this._isResolved() &&
isArrayResolved &&
@@ -4430,28 +3880,24 @@ SomePromiseArray.prototype._init = function SomePromiseArray$_init() {
}
};
-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();
@@ -4463,9 +3909,7 @@ function SomePromiseArray$_promiseFulfilled(value) {
}
};
-SomePromiseArray.prototype._promiseRejected =
-function SomePromiseArray$_promiseRejected(reason) {
- if (this._isResolved()) return;
+SomePromiseArray.prototype._promiseRejected = function (reason) {
this._addRejected(reason);
if (this.howMany() > this._canPossiblyFulfill()) {
var e = new AggregateError();
@@ -4476,192 +3920,168 @@ function SomePromiseArray$_promiseRejected(reason) {
}
};
-SomePromiseArray.prototype._fulfilled = function SomePromiseArray$_fulfilled() {
+SomePromiseArray.prototype._fulfilled = function () {
return this._totalResolved;
};
-SomePromiseArray.prototype._rejected = function SomePromiseArray$_rejected() {
+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();
};
-SomePromiseArray.prototype._getRangeError =
-function SomePromiseArray$_getRangeError(count) {
+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);
};
-SomePromiseArray.prototype._resolveEmptyArray =
-function SomePromiseArray$_resolveEmptyArray() {
+SomePromiseArray.prototype._resolveEmptyArray = function () {
this._reject(this._getRangeError(0));
};
-function Promise$_Some(promises, howMany) {
+function some(promises, howMany) {
if ((howMany | 0) !== howMany || howMany < 0) {
- return apiRejection("expecting a positive integer");
+ return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/1wAmHx\u000a");
}
var ret = new SomePromiseArray(promises);
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);
+Promise.some = function (promises, howMany) {
+ return some(promises, howMany);
};
-Promise.prototype.some = function Promise$some(howMany) {
- return Promise$_Some(this, howMany);
+Promise.prototype.some = function (howMany) {
+ return some(this, howMany);
};
Promise._SomePromiseArray = SomePromiseArray;
};
-},{"./errors.js":10,"./util.js":35}],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.
- *
- */
+},{"./errors.js":13,"./util.js":38}],34:[function(_dereq_,module,exports){
"use strict";
module.exports = function(Promise) {
function PromiseInspection(promise) {
- if (promise !== void 0) {
+ if (promise !== undefined) {
+ promise = promise._target();
this._bitField = promise._bitField;
- this._settledValue = promise.isResolved()
- ? promise._settledValue
- : void 0;
+ this._settledValue = promise._settledValue;
}
else {
this._bitField = 0;
- this._settledValue = void 0;
+ this._settledValue = undefined;
}
}
-PromiseInspection.prototype.isFulfilled =
-Promise.prototype.isFulfilled = function Promise$isFulfilled() {
- return (this._bitField & 268435456) > 0;
-};
-
-PromiseInspection.prototype.isRejected =
-Promise.prototype.isRejected = function Promise$isRejected() {
- return (this._bitField & 134217728) > 0;
-};
-
-PromiseInspection.prototype.isPending =
-Promise.prototype.isPending = function Promise$isPending() {
- return (this._bitField & 402653184) === 0;
-};
-
-PromiseInspection.prototype.value =
-Promise.prototype.value = function Promise$value() {
+PromiseInspection.prototype.value = function () {
if (!this.isFulfilled()) {
- throw new TypeError("cannot get fulfillment value of a non-fulfilled promise");
+ 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 =
-Promise.prototype.reason = function Promise$reason() {
+PromiseInspection.prototype.reason = function () {
if (!this.isRejected()) {
- throw new TypeError("cannot get rejection reason of a non-rejected promise");
+ 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 Promise$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;
};
-},{}],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.
- *
- */
+},{}],35:[function(_dereq_,module,exports){
"use strict";
module.exports = function(Promise, INTERNAL) {
-var util = require("./util.js");
-var canAttach = require("./errors.js").canAttach;
+var util = _dereq_("./util.js");
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, originalPromise) {
+function tryConvertToPromise(obj, context) {
if (isObject(obj)) {
if (obj instanceof Promise) {
return obj;
}
else if (isAnyBluebirdPromise(obj)) {
var ret = new Promise(INTERNAL);
- ret._setTrace(void 0);
obj._then(
ret._fulfillUnchecked,
ret._rejectUncheckedCheckError,
@@ -4669,206 +4089,138 @@ function Promise$_Cast(obj, originalPromise) {
ret,
null
);
- ret._setFollowing();
return ret;
}
- var then = getThen(obj);
+ var then = util.tryCatch(getThen)(obj);
if (then === errorObj) {
- if (originalPromise !== void 0 && canAttach(then.e)) {
- originalPromise._attachExtraTrace(then.e);
- }
- return Promise.reject(then.e);
+ if (context) context._pushContext();
+ var ret = Promise.reject(then.e);
+ if (context) context._popContext();
+ return ret;
} else if (typeof then === "function") {
- return Promise$_doThenable(obj, then, originalPromise);
+ 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 Promise$_doThenable(x, then, originalPromise) {
- var resolver = Promise.defer();
- 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 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 Promise$_rejectFromThenable(r) {
- if (called) return;
- called = true;
- var trace = canAttach(r) ? r : new Error(r + "");
- if (originalPromise !== void 0) {
- originalPromise._attachExtraTrace(trace);
+ function resolveFromThenable(value) {
+ if (!promise) return;
+ if (x === value) {
+ promise._rejectCallback(
+ Promise._makeSelfResolutionError(), false, true);
+ } else {
+ promise._resolveCallback(value);
}
- resolver.promise._reject(r, trace);
+ promise = null;
}
- function Promise$_progressFromThenable(v) {
- if (called) return;
- var promise = resolver.promise;
+ 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(v);
+ promise._progress(value);
}
}
+ return ret;
}
-return Promise$_Cast;
+return tryConvertToPromise;
};
-},{"./errors.js":10,"./util.js":35}],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.
- *
- */
+},{"./util.js":38}],36:[function(_dereq_,module,exports){
"use strict";
-var _setTimeout = function(fn, ms) {
- var len = arguments.length;
- var arg0 = arguments[2];
- var arg1 = arguments[3];
- var arg2 = len >= 5 ? arguments[4] : void 0;
- setTimeout(function() {
- fn(arg0, arg1, arg2);
- }, ms|0);
-};
-
-module.exports = function(Promise, INTERNAL, cast) {
-var util = require("./util.js");
-var errors = require("./errors.js");
-var apiRejection = require("./errors_api_rejection")(Promise);
+module.exports = function(Promise, INTERNAL) {
+var util = _dereq_("./util.js");
var TimeoutError = Promise.TimeoutError;
-var afterTimeout = function Promise$_afterTimeout(promise, message, ms) {
+var afterTimeout = function (promise, message) {
if (!promise.isPending()) return;
if (typeof message !== "string") {
- message = "operation timed out after" + " " + ms + " ms"
+ message = "operation timed out";
}
var err = new TimeoutError(message);
- errors.markAsOriginatingFromRejection(err);
+ util.markAsOriginatingFromRejection(err);
promise._attachExtraTrace(err);
promise._cancel(err);
};
-var afterDelay = function Promise$_afterDelay(value, promise) {
- promise._fulfill(value);
-};
-
-var delay = Promise.delay = function Promise$Delay(value, ms) {
- if (ms === void 0) {
+var afterValue = function(value) { return delay(+this).thenReturn(value); };
+var delay = Promise.delay = function (value, ms) {
+ if (ms === undefined) {
ms = value;
- value = void 0;
+ value = undefined;
+ var ret = new Promise(INTERNAL);
+ setTimeout(function() { ret._fulfill(); }, ms);
+ return ret;
}
ms = +ms;
- var maybePromise = cast(value, void 0);
- var promise = new Promise(INTERNAL);
-
- if (maybePromise instanceof Promise) {
- promise._propagateFrom(maybePromise, 7);
- promise._follow(maybePromise);
- return promise.then(function(value) {
- return Promise.delay(value, ms);
- });
- } else {
- promise._setTrace(void 0);
- _setTimeout(afterDelay, ms, value, promise);
- }
- return promise;
+ return Promise.resolve(value)._then(afterValue, null, null, ms, undefined);
};
-Promise.prototype.delay = function Promise$delay(ms) {
+Promise.prototype.delay = function (ms) {
return delay(this, ms);
};
-Promise.prototype.timeout = function Promise$timeout(ms, message) {
+function successClear(value) {
+ clearTimeout(+this);
+ return value;
+}
+
+function failureClear(reason) {
+ clearTimeout(+this);
+ throw reason;
+}
+
+Promise.prototype.timeout = function (ms, message) {
ms = +ms;
-
- var ret = new Promise(INTERNAL);
- ret._propagateFrom(this, 7);
- ret._follow(this);
- _setTimeout(afterTimeout, ms, ret, message, ms);
- return ret.cancellable();
+ 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);
};
};
-},{"./errors.js":10,"./errors_api_rejection":11,"./util.js":35}],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}],37:[function(_dereq_,module,exports){
"use strict";
-module.exports = function (Promise, apiRejection, cast) {
- var TypeError = require("./errors.js").TypeError;
- var inherits = require("./util.js").inherits;
+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) {
@@ -4878,7 +4230,7 @@ module.exports = function (Promise, apiRejection, cast) {
if (inspection.isRejected()) {
return Promise.reject(inspection.error());
}
- inspections[i] = inspection.value();
+ inspections[i] = inspection._settledValue;
}
return inspections;
}
@@ -4888,7 +4240,7 @@ module.exports = function (Promise, apiRejection, cast) {
}
function castPreservingDisposable(thenable) {
- var maybePromise = cast(thenable, void 0);
+ var maybePromise = tryConvertToPromise(thenable);
if (maybePromise !== thenable &&
typeof thenable._isDisposable === "function" &&
typeof thenable._getDisposer === "function" &&
@@ -4907,8 +4259,9 @@ module.exports = function (Promise, apiRejection, cast) {
if (maybePromise instanceof Promise &&
maybePromise._isDisposable()) {
try {
- maybePromise = cast(maybePromise._getDisposer()
- .tryDispose(inspection), void 0);
+ maybePromise = tryConvertToPromise(
+ maybePromise._getDisposer().tryDispose(inspection),
+ resources.promise);
} catch (e) {
return thrower(e);
}
@@ -4937,20 +4290,21 @@ module.exports = function (Promise, apiRejection, cast) {
return dispose(this, inspection).thenThrow(reason);
}
- function Disposer(data, promise) {
+ function Disposer(data, promise, context) {
this._data = data;
this._promise = promise;
+ this._context = context;
}
- Disposer.prototype.data = function Disposer$data() {
+ Disposer.prototype.data = function () {
return this._data;
};
- Disposer.prototype.promise = function Disposer$promise() {
+ Disposer.prototype.promise = function () {
return this._promise;
};
- Disposer.prototype.resource = function Disposer$resource() {
+ Disposer.prototype.resource = function () {
if (this.promise().isFulfilled()) {
return this.promise().value();
}
@@ -4959,21 +4313,24 @@ module.exports = function (Promise, apiRejection, cast) {
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 = this._promise = null;
+ this._data = null;
return ret;
};
- Disposer.isDisposer = function Disposer$isDisposer(d) {
+ Disposer.isDisposer = function (d) {
return (d != null &&
typeof d.resource === "function" &&
typeof d.tryDispose === "function");
};
- function FunctionDisposer(fn, promise) {
- this.constructor$(fn, promise);
+ function FunctionDisposer(fn, promise, context) {
+ this.constructor$(fn, promise, context);
}
inherits(FunctionDisposer, Disposer);
@@ -4982,12 +4339,20 @@ module.exports = function (Promise, apiRejection, cast) {
return fn.call(resource, resource, inspection);
};
- Promise.using = function Promise$using() {
+ function maybeUnwrapDisposer(value) {
+ if (Disposer.isDisposer(value)) {
+ this.resources[this.index]._setDisposable(value);
+ return value.promise();
+ }
+ return value;
+ }
+
+ 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");
+ 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) {
@@ -4996,69 +4361,68 @@ module.exports = function (Promise, apiRejection, cast) {
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);
+ }
}
resources[i] = resource;
}
- return Promise.settle(resources)
+ var promise = Promise.settle(resources)
.then(inspectionMapper)
- .spread(fn)
- ._then(disposerSuccess, disposerFail, void 0, resources, void 0);
+ .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._setDisposable =
- function Promise$_setDisposable(disposer) {
+ Promise.prototype._setDisposable = function (disposer) {
this._bitField = this._bitField | 262144;
this._disposer = disposer;
};
- Promise.prototype._isDisposable = function Promise$_isDisposable() {
+ Promise.prototype._isDisposable = function () {
return (this._bitField & 262144) > 0;
};
- Promise.prototype._getDisposer = function Promise$_getDisposer() {
+ Promise.prototype._getDisposer = function () {
return this._disposer;
};
- Promise.prototype._unsetDisposable = function Promise$_unsetDisposable() {
+ Promise.prototype._unsetDisposable = function () {
this._bitField = this._bitField & (~262144);
- this._disposer = void 0;
+ this._disposer = undefined;
};
- Promise.prototype.disposer = function Promise$disposer(fn) {
+ Promise.prototype.disposer = function (fn) {
if (typeof fn === "function") {
- return new FunctionDisposer(fn, this);
+ return new FunctionDisposer(fn, this, createContext());
}
throw new TypeError();
};
};
-},{"./errors.js":10,"./util.js":35}],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.
- *
- */
+},{"./errors.js":13,"./util.js":38}],38:[function(_dereq_,module,exports){
"use strict";
-var es5 = require("./es5.js");
+var es5 = _dereq_("./es5.js");
+var canEvaluate = typeof navigator == "undefined";
var haveGetters = (function(){
try {
var o = {};
@@ -5074,46 +4438,20 @@ var haveGetters = (function(){
}
})();
-var canEvaluate = typeof navigator == "undefined";
+
var errorObj = {e: {}};
-function tryCatch1(fn, receiver, arg) {
- try { return fn.call(receiver, arg); }
- catch (e) {
+var tryCatchTarget;
+function tryCatcher() {
+ try {
+ return tryCatchTarget.apply(this, arguments);
+ } 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 tryCatch3(fn, receiver, arg, arg2, arg3) {
- try { return fn.call(receiver, arg, arg2, arg3); }
- catch (e) {
- errorObj.e = e;
- return errorObj;
- }
-}
-
-function tryCatch4(fn, receiver, arg, arg2, arg3, arg4) {
- try { return fn.call(receiver, arg, arg2, arg3, arg4); }
- 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) {
@@ -5175,7 +4513,7 @@ function getDataPropertyOrDefault(obj, key, defaultValue) {
: defaultValue;
}
} else {
- return {}.hasOwnProperty.call(obj, key) ? obj[key] : void 0;
+ return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
}
}
@@ -5275,6 +4613,46 @@ function filledRange(count, prefix, 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));
+ };
+ }
+})();
+
var ret = {
isClass: isClass,
isIdentifier: isIdentifier,
@@ -5288,23 +4666,22 @@ var ret = {
isObject: isObject,
canEvaluate: canEvaluate,
errorObj: errorObj,
- tryCatch1: tryCatch1,
- tryCatch2: tryCatch2,
- tryCatch3: tryCatch3,
- tryCatch4: tryCatch4,
- tryCatchApply: tryCatchApply,
+ tryCatch: tryCatch,
inherits: inherits,
withAppended: withAppended,
asString: asString,
maybeWrapAsError: maybeWrapAsError,
wrapsPrimitiveReceiver: wrapsPrimitiveReceiver,
toFastProperties: toFastProperties,
- filledRange: filledRange
+ filledRange: filledRange,
+ toString: safeToString,
+ canAttachTrace: canAttachTrace,
+ ensureErrorObject: ensureErrorObject,
+ originatesFromRejection: originatesFromRejection,
+ markAsOriginatingFromRejection: markAsOriginatingFromRejection
};
-
+try {throw new Error(); } catch (e) {ret.lastLineError = e;}
module.exports = ret;
-},{"./es5.js":12}]},{},[3])
-(3)
-});
-; ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }
\ No newline at end of file
+},{"./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; }
\ No newline at end of file