mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Changes
This commit is contained in:
5277
node_modules/bluebird/js/browser/bluebird.js
generated
vendored
5277
node_modules/bluebird/js/browser/bluebird.js
generated
vendored
File diff suppressed because it is too large
Load Diff
14
node_modules/bluebird/js/browser/bluebird.min.js
generated
vendored
14
node_modules/bluebird/js/browser/bluebird.min.js
generated
vendored
File diff suppressed because one or more lines are too long
48
node_modules/bluebird/js/main/cancel.js
generated
vendored
48
node_modules/bluebird/js/main/cancel.js
generated
vendored
@ -1,48 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise) {
|
||||
var errors = require("./errors.js");
|
||||
var async = require("./async.js");
|
||||
var CancellationError = errors.CancellationError;
|
||||
|
||||
Promise.prototype._cancel = function (reason) {
|
||||
if (!this.isCancellable()) return this;
|
||||
var parent;
|
||||
var promiseToReject = this;
|
||||
while ((parent = promiseToReject._cancellationParent) !== undefined &&
|
||||
parent.isCancellable()) {
|
||||
promiseToReject = parent;
|
||||
}
|
||||
this._unsetCancellable();
|
||||
promiseToReject._target()._rejectCallback(reason, false, true);
|
||||
};
|
||||
|
||||
Promise.prototype.cancel = function (reason) {
|
||||
if (!this.isCancellable()) return this;
|
||||
if (reason === undefined) reason = new CancellationError();
|
||||
async.invokeLater(this._cancel, this, reason);
|
||||
return this;
|
||||
};
|
||||
|
||||
Promise.prototype.cancellable = function () {
|
||||
if (this._cancellable()) return this;
|
||||
async.enableTrampoline();
|
||||
this._setCancellable();
|
||||
this._cancellationParent = undefined;
|
||||
return this;
|
||||
};
|
||||
|
||||
Promise.prototype.uncancellable = function () {
|
||||
var ret = this.then();
|
||||
ret._unsetCancellable();
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.prototype.fork = function (didFulfill, didReject, didProgress) {
|
||||
var ret = this._then(didFulfill, didReject, didProgress,
|
||||
undefined, undefined);
|
||||
|
||||
ret._setCancellable();
|
||||
ret._cancellationParent = undefined;
|
||||
return ret;
|
||||
};
|
||||
};
|
66
node_modules/bluebird/js/main/catch_filter.js
generated
vendored
66
node_modules/bluebird/js/main/catch_filter.js
generated
vendored
@ -1,66 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = function(NEXT_FILTER) {
|
||||
var util = require("./util.js");
|
||||
var errors = require("./errors.js");
|
||||
var tryCatch = util.tryCatch;
|
||||
var errorObj = util.errorObj;
|
||||
var keys = require("./es5.js").keys;
|
||||
var TypeError = errors.TypeError;
|
||||
|
||||
function CatchFilter(instances, callback, promise) {
|
||||
this._instances = instances;
|
||||
this._callback = callback;
|
||||
this._promise = promise;
|
||||
}
|
||||
|
||||
function safePredicate(predicate, e) {
|
||||
var safeObject = {};
|
||||
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\u000a\u000a See http://goo.gl/o84o68\u000a");
|
||||
return errorObj;
|
||||
}
|
||||
return retfilter;
|
||||
}
|
||||
|
||||
CatchFilter.prototype.doFilter = function (e) {
|
||||
var cb = this._callback;
|
||||
var promise = this._promise;
|
||||
var boundTo = promise._boundTo;
|
||||
for (var i = 0, len = this._instances.length; i < len; ++i) {
|
||||
var item = this._instances[i];
|
||||
var itemIsErrorType = item === Error ||
|
||||
(item != null && item.prototype instanceof Error);
|
||||
|
||||
if (itemIsErrorType && e instanceof item) {
|
||||
var ret = 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 = safePredicate(item, e);
|
||||
if (shouldHandle === errorObj) {
|
||||
e = errorObj.e;
|
||||
break;
|
||||
} else if (shouldHandle) {
|
||||
var ret = tryCatch(cb).call(boundTo, e);
|
||||
if (ret === errorObj) {
|
||||
NEXT_FILTER.e = ret.e;
|
||||
return NEXT_FILTER;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
NEXT_FILTER.e = e;
|
||||
return NEXT_FILTER;
|
||||
};
|
||||
|
||||
return CatchFilter;
|
||||
};
|
38
node_modules/bluebird/js/main/context.js
generated
vendored
38
node_modules/bluebird/js/main/context.js
generated
vendored
@ -1,38 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, CapturedTrace, isDebugging) {
|
||||
var contextStack = [];
|
||||
function Context() {
|
||||
this._trace = new CapturedTrace(peekContext());
|
||||
}
|
||||
Context.prototype._pushContext = function () {
|
||||
if (!isDebugging()) return;
|
||||
if (this._trace !== undefined) {
|
||||
contextStack.push(this._trace);
|
||||
}
|
||||
};
|
||||
|
||||
Context.prototype._popContext = function () {
|
||||
if (!isDebugging()) return;
|
||||
if (this._trace !== undefined) {
|
||||
contextStack.pop();
|
||||
}
|
||||
};
|
||||
|
||||
function createContext() {
|
||||
if (isDebugging()) return new Context();
|
||||
}
|
||||
|
||||
function peekContext() {
|
||||
var lastIndex = contextStack.length - 1;
|
||||
if (lastIndex >= 0) {
|
||||
return contextStack[lastIndex];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Promise.prototype._peekContext = peekContext;
|
||||
Promise.prototype._pushContext = Context.prototype._pushContext;
|
||||
Promise.prototype._popContext = Context.prototype._popContext;
|
||||
|
||||
return createContext;
|
||||
};
|
147
node_modules/bluebird/js/main/debuggability.js
generated
vendored
147
node_modules/bluebird/js/main/debuggability.js
generated
vendored
@ -1,147 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, CapturedTrace) {
|
||||
var async = require("./async.js");
|
||||
var Warning = require("./errors.js").Warning;
|
||||
var util = require("./util.js");
|
||||
var canAttachTrace = util.canAttachTrace;
|
||||
var unhandledRejectionHandled;
|
||||
var possiblyUnhandledRejection;
|
||||
var debugging = false || (util.isNode &&
|
||||
(!!process.env["BLUEBIRD_DEBUG"] ||
|
||||
process.env["NODE_ENV"] === "development"));
|
||||
|
||||
if (debugging) {
|
||||
async.disableTrampolineIfNecessary();
|
||||
}
|
||||
|
||||
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);
|
||||
util.notEnumerableProp(error, "stack",
|
||||
parsed.message + "\n" + parsed.stack.join("\n"));
|
||||
util.notEnumerableProp(error, "__stackCleaned__", true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._warn = function(message) {
|
||||
var warning = new Warning(message);
|
||||
var ctx = this._peekContext();
|
||||
if (ctx) {
|
||||
ctx.attachExtraTrace(warning);
|
||||
} else {
|
||||
var parsed = CapturedTrace.parseStackAndMessage(warning);
|
||||
warning.stack = parsed.message + "\n" + parsed.stack.join("\n");
|
||||
}
|
||||
CapturedTrace.formatAndLogError(warning, "");
|
||||
};
|
||||
|
||||
Promise.onPossiblyUnhandledRejection = function (fn) {
|
||||
possiblyUnhandledRejection = typeof fn === "function" ? fn : undefined;
|
||||
};
|
||||
|
||||
Promise.onUnhandledRejectionHandled = function (fn) {
|
||||
unhandledRejectionHandled = typeof fn === "function" ? fn : undefined;
|
||||
};
|
||||
|
||||
Promise.longStackTraces = function () {
|
||||
if (async.haveItemsQueued() &&
|
||||
debugging === false
|
||||
) {
|
||||
throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/DT1qyG\u000a");
|
||||
}
|
||||
debugging = CapturedTrace.isSupported();
|
||||
if (debugging) {
|
||||
async.disableTrampolineIfNecessary();
|
||||
}
|
||||
};
|
||||
|
||||
Promise.hasLongStackTraces = function () {
|
||||
return debugging && CapturedTrace.isSupported();
|
||||
};
|
||||
|
||||
if (!CapturedTrace.isSupported()) {
|
||||
Promise.longStackTraces = function(){};
|
||||
debugging = false;
|
||||
}
|
||||
|
||||
return function() {
|
||||
return debugging;
|
||||
};
|
||||
};
|
54
node_modules/bluebird/js/main/direct_resolve.js
generated
vendored
54
node_modules/bluebird/js/main/direct_resolve.js
generated
vendored
@ -1,54 +0,0 @@
|
||||
"use strict";
|
||||
var util = require("./util.js");
|
||||
var isPrimitive = util.isPrimitive;
|
||||
var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
|
||||
|
||||
module.exports = function(Promise) {
|
||||
var returner = function () {
|
||||
return this;
|
||||
};
|
||||
var thrower = function () {
|
||||
throw this;
|
||||
};
|
||||
|
||||
var wrapper = function (value, action) {
|
||||
if (action === 1) {
|
||||
return function () {
|
||||
throw value;
|
||||
};
|
||||
} else if (action === 2) {
|
||||
return function () {
|
||||
return value;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Promise.prototype["return"] =
|
||||
Promise.prototype.thenReturn = function (value) {
|
||||
if (wrapsPrimitiveReceiver && isPrimitive(value)) {
|
||||
return this._then(
|
||||
wrapper(value, 2),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined
|
||||
);
|
||||
}
|
||||
return this._then(returner, undefined, undefined, value, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype["throw"] =
|
||||
Promise.prototype.thenThrow = function (reason) {
|
||||
if (wrapsPrimitiveReceiver && isPrimitive(reason)) {
|
||||
return this._then(
|
||||
wrapper(reason, 1),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined
|
||||
);
|
||||
}
|
||||
return this._then(thrower, undefined, undefined, reason, undefined);
|
||||
};
|
||||
};
|
12
node_modules/bluebird/js/main/each.js
generated
vendored
12
node_modules/bluebird/js/main/each.js
generated
vendored
@ -1,12 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, INTERNAL) {
|
||||
var PromiseReduce = Promise.reduce;
|
||||
|
||||
Promise.prototype.each = function (fn) {
|
||||
return PromiseReduce(this, fn, null, INTERNAL);
|
||||
};
|
||||
|
||||
Promise.each = function (promises, fn) {
|
||||
return PromiseReduce(promises, fn, null, INTERNAL);
|
||||
};
|
||||
};
|
99
node_modules/bluebird/js/main/finally.js
generated
vendored
99
node_modules/bluebird/js/main/finally.js
generated
vendored
@ -1,99 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, NEXT_FILTER, tryConvertToPromise) {
|
||||
var util = require("./util.js");
|
||||
var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
|
||||
var isPrimitive = util.isPrimitive;
|
||||
var thrower = util.thrower;
|
||||
|
||||
function returnThis() {
|
||||
return this;
|
||||
}
|
||||
function throwThis() {
|
||||
throw this;
|
||||
}
|
||||
function return$(r) {
|
||||
return function() {
|
||||
return r;
|
||||
};
|
||||
}
|
||||
function throw$(r) {
|
||||
return function() {
|
||||
throw r;
|
||||
};
|
||||
}
|
||||
function promisedFinally(ret, reasonOrValue, isFulfilled) {
|
||||
var then;
|
||||
if (wrapsPrimitiveReceiver && isPrimitive(reasonOrValue)) {
|
||||
then = isFulfilled ? return$(reasonOrValue) : throw$(reasonOrValue);
|
||||
} else {
|
||||
then = isFulfilled ? returnThis : throwThis;
|
||||
}
|
||||
return ret._then(then, thrower, undefined, reasonOrValue, undefined);
|
||||
}
|
||||
|
||||
function finallyHandler(reasonOrValue) {
|
||||
var promise = this.promise;
|
||||
var handler = this.handler;
|
||||
|
||||
var ret = promise._isBound()
|
||||
? handler.call(promise._boundTo)
|
||||
: handler();
|
||||
|
||||
if (ret !== undefined) {
|
||||
var maybePromise = tryConvertToPromise(ret, promise);
|
||||
if (maybePromise instanceof Promise) {
|
||||
maybePromise = maybePromise._target();
|
||||
return promisedFinally(maybePromise, reasonOrValue,
|
||||
promise.isFulfilled());
|
||||
}
|
||||
}
|
||||
|
||||
if (promise.isRejected()) {
|
||||
NEXT_FILTER.e = reasonOrValue;
|
||||
return NEXT_FILTER;
|
||||
} else {
|
||||
return reasonOrValue;
|
||||
}
|
||||
}
|
||||
|
||||
function tapHandler(value) {
|
||||
var promise = this.promise;
|
||||
var handler = this.handler;
|
||||
|
||||
var ret = promise._isBound()
|
||||
? handler.call(promise._boundTo, value)
|
||||
: handler(value);
|
||||
|
||||
if (ret !== undefined) {
|
||||
var maybePromise = tryConvertToPromise(ret, promise);
|
||||
if (maybePromise instanceof Promise) {
|
||||
maybePromise = maybePromise._target();
|
||||
return promisedFinally(maybePromise, value, true);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
Promise.prototype._passThroughHandler = function (handler, isFinally) {
|
||||
if (typeof handler !== "function") return this.then();
|
||||
|
||||
var promiseAndHandler = {
|
||||
promise: this,
|
||||
handler: handler
|
||||
};
|
||||
|
||||
return this._then(
|
||||
isFinally ? finallyHandler : tapHandler,
|
||||
isFinally ? finallyHandler : undefined, undefined,
|
||||
promiseAndHandler, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype.lastly =
|
||||
Promise.prototype["finally"] = function (handler) {
|
||||
return this._passThroughHandler(handler, true);
|
||||
};
|
||||
|
||||
Promise.prototype.tap = function (handler) {
|
||||
return this._passThroughHandler(handler, false);
|
||||
};
|
||||
};
|
107
node_modules/bluebird/js/main/join.js
generated
vendored
107
node_modules/bluebird/js/main/join.js
generated
vendored
@ -1,107 +0,0 @@
|
||||
"use strict";
|
||||
module.exports =
|
||||
function(Promise, PromiseArray, tryConvertToPromise, INTERNAL) {
|
||||
var util = require("./util.js");
|
||||
var canEvaluate = util.canEvaluate;
|
||||
var tryCatch = util.tryCatch;
|
||||
var errorObj = util.errorObj;
|
||||
var reject;
|
||||
|
||||
if (!false) {
|
||||
if (canEvaluate) {
|
||||
var thenCallback = function(i) {
|
||||
return new Function("value", "holder", " \n\
|
||||
'use strict'; \n\
|
||||
holder.pIndex = value; \n\
|
||||
holder.checkFulfillment(this); \n\
|
||||
".replace(/Index/g, i));
|
||||
};
|
||||
|
||||
var caller = function(count) {
|
||||
var values = [];
|
||||
for (var i = 1; i <= count; ++i) values.push("holder.p" + i);
|
||||
return new Function("holder", " \n\
|
||||
'use strict'; \n\
|
||||
var callback = holder.fn; \n\
|
||||
return callback(values); \n\
|
||||
".replace(/values/g, values.join(", ")));
|
||||
};
|
||||
var thenCallbacks = [];
|
||||
var callers = [undefined];
|
||||
for (var i = 1; i <= 5; ++i) {
|
||||
thenCallbacks.push(thenCallback(i));
|
||||
callers.push(caller(i));
|
||||
}
|
||||
|
||||
var Holder = function(total, fn) {
|
||||
this.p1 = this.p2 = this.p3 = this.p4 = this.p5 = null;
|
||||
this.fn = fn;
|
||||
this.total = total;
|
||||
this.now = 0;
|
||||
};
|
||||
|
||||
Holder.prototype.callers = callers;
|
||||
Holder.prototype.checkFulfillment = function(promise) {
|
||||
var now = this.now;
|
||||
now++;
|
||||
var total = this.total;
|
||||
if (now >= total) {
|
||||
var handler = this.callers[total];
|
||||
promise._pushContext();
|
||||
var ret = tryCatch(handler)(this);
|
||||
promise._popContext();
|
||||
if (ret === errorObj) {
|
||||
promise._rejectCallback(ret.e, false, true);
|
||||
} else {
|
||||
promise._resolveCallback(ret);
|
||||
}
|
||||
} else {
|
||||
this.now = now;
|
||||
}
|
||||
};
|
||||
|
||||
var reject = function (reason) {
|
||||
this._reject(reason);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Promise.join = function () {
|
||||
var last = arguments.length - 1;
|
||||
var fn;
|
||||
if (last > 0 && typeof arguments[last] === "function") {
|
||||
fn = arguments[last];
|
||||
if (!false) {
|
||||
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 {
|
||||
callbacks[i].call(ret, maybePromise, holder);
|
||||
}
|
||||
}
|
||||
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 !== undefined ? ret.spread(fn) : ret;
|
||||
};
|
||||
|
||||
};
|
44
node_modules/bluebird/js/main/method.js
generated
vendored
44
node_modules/bluebird/js/main/method.js
generated
vendored
@ -1,44 +0,0 @@
|
||||
"use strict";
|
||||
module.exports =
|
||||
function(Promise, INTERNAL, tryConvertToPromise, apiRejection) {
|
||||
var util = require("./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);
|
||||
}
|
||||
};
|
||||
};
|
76
node_modules/bluebird/js/main/progress.js
generated
vendored
76
node_modules/bluebird/js/main/progress.js
generated
vendored
@ -1,76 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, PromiseArray) {
|
||||
var util = require("./util.js");
|
||||
var async = require("./async.js");
|
||||
var tryCatch = util.tryCatch;
|
||||
var errorObj = util.errorObj;
|
||||
|
||||
Promise.prototype.progressed = function (handler) {
|
||||
return this._then(undefined, undefined, handler, undefined, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype._progress = function (progressValue) {
|
||||
if (this._isFollowingOrFulfilledOrRejected()) return;
|
||||
this._target()._progressUnchecked(progressValue);
|
||||
|
||||
};
|
||||
|
||||
Promise.prototype._progressHandlerAt = function (index) {
|
||||
return index === 0
|
||||
? this._progressHandler0
|
||||
: this[(index << 2) + index - 5 + 2];
|
||||
};
|
||||
|
||||
Promise.prototype._doProgressWith = function (progression) {
|
||||
var progressValue = progression.value;
|
||||
var handler = progression.handler;
|
||||
var promise = progression.promise;
|
||||
var receiver = progression.receiver;
|
||||
|
||||
var ret = tryCatch(handler).call(receiver, progressValue);
|
||||
if (ret === errorObj) {
|
||||
if (ret.e != null &&
|
||||
ret.e.name !== "StopProgressPropagation") {
|
||||
var trace = util.canAttachTrace(ret.e)
|
||||
? ret.e : new Error(util.toString(ret.e));
|
||||
promise._attachExtraTrace(trace);
|
||||
promise._progress(ret.e);
|
||||
}
|
||||
} else if (ret instanceof Promise) {
|
||||
ret._then(promise._progress, null, null, promise, undefined);
|
||||
} else {
|
||||
promise._progress(ret);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Promise.prototype._progressUnchecked = function (progressValue) {
|
||||
var len = this._length();
|
||||
var progress = this._progress;
|
||||
for (var i = 0; i < len; i++) {
|
||||
var handler = this._progressHandlerAt(i);
|
||||
var promise = this._promiseAt(i);
|
||||
if (!(promise instanceof Promise)) {
|
||||
var receiver = this._receiverAt(i);
|
||||
if (typeof handler === "function") {
|
||||
handler.call(receiver, progressValue, promise);
|
||||
} else if (receiver instanceof PromiseArray &&
|
||||
!receiver._isResolved()) {
|
||||
receiver._promiseProgressed(progressValue, promise);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof handler === "function") {
|
||||
async.invoke(this._doProgressWith, this, {
|
||||
handler: handler,
|
||||
promise: promise,
|
||||
receiver: this._receiverAt(i),
|
||||
value: progressValue
|
||||
});
|
||||
} else {
|
||||
async.invoke(progress, promise, progressValue);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
700
node_modules/bluebird/js/main/promise.js
generated
vendored
700
node_modules/bluebird/js/main/promise.js
generated
vendored
@ -1,700 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = function() {
|
||||
var makeSelfResolutionError = function () {
|
||||
return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/LhFpo0\u000a");
|
||||
};
|
||||
var reflect = function() {
|
||||
return new Promise.PromiseInspection(this._target());
|
||||
};
|
||||
var apiRejection = function(msg) {
|
||||
return Promise.reject(new TypeError(msg));
|
||||
};
|
||||
var util = require("./util.js");
|
||||
var async = require("./async.js");
|
||||
var errors = require("./errors.js");
|
||||
var TypeError = Promise.TypeError = errors.TypeError;
|
||||
Promise.RangeError = errors.RangeError;
|
||||
Promise.CancellationError = errors.CancellationError;
|
||||
Promise.TimeoutError = errors.TimeoutError;
|
||||
Promise.OperationalError = errors.OperationalError;
|
||||
Promise.RejectionError = errors.OperationalError;
|
||||
Promise.AggregateError = errors.AggregateError;
|
||||
var INTERNAL = function(){};
|
||||
var APPLY = {};
|
||||
var NEXT_FILTER = {e: null};
|
||||
var tryConvertToPromise = require("./thenables.js")(Promise, INTERNAL);
|
||||
var PromiseArray =
|
||||
require("./promise_array.js")(Promise, INTERNAL,
|
||||
tryConvertToPromise, apiRejection);
|
||||
var CapturedTrace = require("./captured_trace.js")();
|
||||
var isDebugging = require("./debuggability.js")(Promise, CapturedTrace);
|
||||
/*jshint unused:false*/
|
||||
var createContext =
|
||||
require("./context.js")(Promise, CapturedTrace, isDebugging);
|
||||
var CatchFilter = require("./catch_filter.js")(NEXT_FILTER);
|
||||
var PromiseResolver = require("./promise_resolver.js");
|
||||
var nodebackForPromise = PromiseResolver._nodebackForPromise;
|
||||
var errorObj = util.errorObj;
|
||||
var tryCatch = util.tryCatch;
|
||||
function Promise(resolver) {
|
||||
if (typeof resolver !== "function") {
|
||||
throw new TypeError("the promise constructor requires a resolver function\u000a\u000a See http://goo.gl/EC22Yn\u000a");
|
||||
}
|
||||
if (this.constructor !== Promise) {
|
||||
throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/KsIlge\u000a");
|
||||
}
|
||||
this._bitField = 0;
|
||||
this._fulfillmentHandler0 = undefined;
|
||||
this._rejectionHandler0 = undefined;
|
||||
this._progressHandler0 = undefined;
|
||||
this._promise0 = undefined;
|
||||
this._receiver0 = undefined;
|
||||
this._settledValue = undefined;
|
||||
if (resolver !== INTERNAL) this._resolveFromResolver(resolver);
|
||||
}
|
||||
|
||||
Promise.prototype.toString = function () {
|
||||
return "[object Promise]";
|
||||
};
|
||||
|
||||
Promise.prototype.caught = Promise.prototype["catch"] = function (fn) {
|
||||
var len = arguments.length;
|
||||
if (len > 1) {
|
||||
var catchInstances = new Array(len - 1),
|
||||
j = 0, i;
|
||||
for (i = 0; i < len - 1; ++i) {
|
||||
var item = arguments[i];
|
||||
if (typeof item === "function") {
|
||||
catchInstances[j++] = item;
|
||||
} else {
|
||||
return Promise.reject(
|
||||
new TypeError("Catch filter must inherit from Error or be a simple predicate function\u000a\u000a See http://goo.gl/o84o68\u000a"));
|
||||
}
|
||||
}
|
||||
catchInstances.length = j;
|
||||
fn = arguments[i];
|
||||
var catchFilter = new CatchFilter(catchInstances, fn, this);
|
||||
return this._then(undefined, catchFilter.doFilter, undefined,
|
||||
catchFilter, undefined);
|
||||
}
|
||||
return this._then(undefined, fn, undefined, undefined, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype.reflect = function () {
|
||||
return this._then(reflect, reflect, undefined, this, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype.then = function (didFulfill, didReject, didProgress) {
|
||||
if (isDebugging() && arguments.length > 0 &&
|
||||
typeof didFulfill !== "function" &&
|
||||
typeof didReject !== "function") {
|
||||
var msg = ".then() only accepts functions but was passed: " +
|
||||
util.classString(didFulfill);
|
||||
if (arguments.length > 1) {
|
||||
msg += ", " + util.classString(didReject);
|
||||
}
|
||||
this._warn(msg);
|
||||
}
|
||||
return this._then(didFulfill, didReject, didProgress,
|
||||
undefined, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype.done = function (didFulfill, didReject, didProgress) {
|
||||
var promise = this._then(didFulfill, didReject, didProgress,
|
||||
undefined, undefined);
|
||||
promise._setIsFinal();
|
||||
};
|
||||
|
||||
Promise.prototype.spread = function (didFulfill, didReject) {
|
||||
return this.all()._then(didFulfill, didReject, undefined, APPLY, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype.isCancellable = function () {
|
||||
return !this.isResolved() &&
|
||||
this._cancellable();
|
||||
};
|
||||
|
||||
Promise.prototype.toJSON = function () {
|
||||
var ret = {
|
||||
isFulfilled: false,
|
||||
isRejected: false,
|
||||
fulfillmentValue: undefined,
|
||||
rejectionReason: undefined
|
||||
};
|
||||
if (this.isFulfilled()) {
|
||||
ret.fulfillmentValue = this.value();
|
||||
ret.isFulfilled = true;
|
||||
} else if (this.isRejected()) {
|
||||
ret.rejectionReason = this.reason();
|
||||
ret.isRejected = true;
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.prototype.all = function () {
|
||||
return new PromiseArray(this).promise();
|
||||
};
|
||||
|
||||
Promise.prototype.error = function (fn) {
|
||||
return this.caught(util.originatesFromRejection, fn);
|
||||
};
|
||||
|
||||
Promise.is = function (val) {
|
||||
return val instanceof Promise;
|
||||
};
|
||||
|
||||
Promise.fromNode = function(fn) {
|
||||
var ret = new Promise(INTERNAL);
|
||||
var result = tryCatch(fn)(nodebackForPromise(ret));
|
||||
if (result === errorObj) {
|
||||
ret._rejectCallback(result.e, true, true);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.all = function (promises) {
|
||||
return new PromiseArray(promises).promise();
|
||||
};
|
||||
|
||||
Promise.defer = Promise.pending = function () {
|
||||
var promise = new Promise(INTERNAL);
|
||||
return new PromiseResolver(promise);
|
||||
};
|
||||
|
||||
Promise.cast = function (obj) {
|
||||
var ret = tryConvertToPromise(obj);
|
||||
if (!(ret instanceof Promise)) {
|
||||
var val = ret;
|
||||
ret = new Promise(INTERNAL);
|
||||
ret._fulfillUnchecked(val);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.resolve = Promise.fulfilled = Promise.cast;
|
||||
|
||||
Promise.reject = Promise.rejected = function (reason) {
|
||||
var ret = new Promise(INTERNAL);
|
||||
ret._captureStackTrace();
|
||||
ret._rejectCallback(reason, true);
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.setScheduler = function(fn) {
|
||||
if (typeof fn !== "function") throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
|
||||
var prev = async._schedule;
|
||||
async._schedule = fn;
|
||||
return prev;
|
||||
};
|
||||
|
||||
Promise.prototype._then = function (
|
||||
didFulfill,
|
||||
didReject,
|
||||
didProgress,
|
||||
receiver,
|
||||
internalData
|
||||
) {
|
||||
var haveInternalData = internalData !== undefined;
|
||||
var ret = haveInternalData ? internalData : new Promise(INTERNAL);
|
||||
|
||||
if (!haveInternalData) {
|
||||
ret._propagateFrom(this, 4 | 1);
|
||||
ret._captureStackTrace();
|
||||
}
|
||||
|
||||
var target = this._target();
|
||||
if (target !== this) {
|
||||
if (receiver === undefined) receiver = this._boundTo;
|
||||
if (!haveInternalData) ret._setIsMigrated();
|
||||
}
|
||||
|
||||
var callbackIndex =
|
||||
target._addCallbacks(didFulfill, didReject, didProgress, ret, receiver);
|
||||
|
||||
if (target._isResolved() && !target._isSettlePromisesQueued()) {
|
||||
async.invoke(
|
||||
target._settlePromiseAtPostResolution, target, callbackIndex);
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.prototype._settlePromiseAtPostResolution = function (index) {
|
||||
if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled();
|
||||
this._settlePromiseAt(index);
|
||||
};
|
||||
|
||||
Promise.prototype._length = function () {
|
||||
return this._bitField & 131071;
|
||||
};
|
||||
|
||||
Promise.prototype._isFollowingOrFulfilledOrRejected = function () {
|
||||
return (this._bitField & 939524096) > 0;
|
||||
};
|
||||
|
||||
Promise.prototype._isFollowing = function () {
|
||||
return (this._bitField & 536870912) === 536870912;
|
||||
};
|
||||
|
||||
Promise.prototype._setLength = function (len) {
|
||||
this._bitField = (this._bitField & -131072) |
|
||||
(len & 131071);
|
||||
};
|
||||
|
||||
Promise.prototype._setFulfilled = function () {
|
||||
this._bitField = this._bitField | 268435456;
|
||||
};
|
||||
|
||||
Promise.prototype._setRejected = function () {
|
||||
this._bitField = this._bitField | 134217728;
|
||||
};
|
||||
|
||||
Promise.prototype._setFollowing = function () {
|
||||
this._bitField = this._bitField | 536870912;
|
||||
};
|
||||
|
||||
Promise.prototype._setIsFinal = function () {
|
||||
this._bitField = this._bitField | 33554432;
|
||||
};
|
||||
|
||||
Promise.prototype._isFinal = function () {
|
||||
return (this._bitField & 33554432) > 0;
|
||||
};
|
||||
|
||||
Promise.prototype._cancellable = function () {
|
||||
return (this._bitField & 67108864) > 0;
|
||||
};
|
||||
|
||||
Promise.prototype._setCancellable = function () {
|
||||
this._bitField = this._bitField | 67108864;
|
||||
};
|
||||
|
||||
Promise.prototype._unsetCancellable = function () {
|
||||
this._bitField = this._bitField & (~67108864);
|
||||
};
|
||||
|
||||
Promise.prototype._setIsMigrated = function () {
|
||||
this._bitField = this._bitField | 4194304;
|
||||
};
|
||||
|
||||
Promise.prototype._unsetIsMigrated = function () {
|
||||
this._bitField = this._bitField & (~4194304);
|
||||
};
|
||||
|
||||
Promise.prototype._isMigrated = function () {
|
||||
return (this._bitField & 4194304) > 0;
|
||||
};
|
||||
|
||||
Promise.prototype._receiverAt = function (index) {
|
||||
var ret = index === 0
|
||||
? this._receiver0
|
||||
: this[
|
||||
index * 5 - 5 + 4];
|
||||
if (ret === undefined && this._isBound()) {
|
||||
return this._boundTo;
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.prototype._promiseAt = function (index) {
|
||||
return index === 0
|
||||
? this._promise0
|
||||
: this[index * 5 - 5 + 3];
|
||||
};
|
||||
|
||||
Promise.prototype._fulfillmentHandlerAt = function (index) {
|
||||
return index === 0
|
||||
? this._fulfillmentHandler0
|
||||
: this[index * 5 - 5 + 0];
|
||||
};
|
||||
|
||||
Promise.prototype._rejectionHandlerAt = function (index) {
|
||||
return index === 0
|
||||
? this._rejectionHandler0
|
||||
: this[index * 5 - 5 + 1];
|
||||
};
|
||||
|
||||
Promise.prototype._migrateCallbacks = function (follower, index) {
|
||||
var fulfill = follower._fulfillmentHandlerAt(index);
|
||||
var reject = follower._rejectionHandlerAt(index);
|
||||
var progress = follower._progressHandlerAt(index);
|
||||
var promise = follower._promiseAt(index);
|
||||
var receiver = follower._receiverAt(index);
|
||||
if (promise instanceof Promise) promise._setIsMigrated();
|
||||
this._addCallbacks(fulfill, reject, progress, promise, receiver);
|
||||
};
|
||||
|
||||
Promise.prototype._addCallbacks = function (
|
||||
fulfill,
|
||||
reject,
|
||||
progress,
|
||||
promise,
|
||||
receiver
|
||||
) {
|
||||
var index = this._length();
|
||||
|
||||
if (index >= 131071 - 5) {
|
||||
index = 0;
|
||||
this._setLength(0);
|
||||
}
|
||||
|
||||
if (index === 0) {
|
||||
this._promise0 = promise;
|
||||
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 * 5 - 5;
|
||||
this[base + 3] = promise;
|
||||
this[base + 4] = receiver;
|
||||
if (typeof fulfill === "function")
|
||||
this[base + 0] = fulfill;
|
||||
if (typeof reject === "function")
|
||||
this[base + 1] = reject;
|
||||
if (typeof progress === "function")
|
||||
this[base + 2] = progress;
|
||||
}
|
||||
this._setLength(index + 1);
|
||||
return index;
|
||||
};
|
||||
|
||||
Promise.prototype._setProxyHandlers = function (receiver, promiseSlotValue) {
|
||||
var index = this._length();
|
||||
|
||||
if (index >= 131071 - 5) {
|
||||
index = 0;
|
||||
this._setLength(0);
|
||||
}
|
||||
if (index === 0) {
|
||||
this._promise0 = promiseSlotValue;
|
||||
this._receiver0 = receiver;
|
||||
} else {
|
||||
var base = index * 5 - 5;
|
||||
this[base + 3] = promiseSlotValue;
|
||||
this[base + 4] = receiver;
|
||||
}
|
||||
this._setLength(index + 1);
|
||||
};
|
||||
|
||||
Promise.prototype._proxyPromiseArray = function (promiseArray, index) {
|
||||
this._setProxyHandlers(promiseArray, index);
|
||||
};
|
||||
|
||||
Promise.prototype._resolveCallback = function(value, shouldBind) {
|
||||
if (this._isFollowingOrFulfilledOrRejected()) return;
|
||||
if (value === this)
|
||||
return this._rejectCallback(makeSelfResolutionError(), false, true);
|
||||
var maybePromise = tryConvertToPromise(value, this);
|
||||
if (!(maybePromise instanceof Promise)) return this._fulfill(value);
|
||||
|
||||
var propagationFlags = 1 | (shouldBind ? 4 : 0);
|
||||
this._propagateFrom(maybePromise, propagationFlags);
|
||||
var promise = maybePromise._target();
|
||||
if (promise._isPending()) {
|
||||
var len = this._length();
|
||||
for (var i = 0; i < len; ++i) {
|
||||
promise._migrateCallbacks(this, i);
|
||||
}
|
||||
this._setFollowing();
|
||||
this._setLength(0);
|
||||
this._setFollowee(promise);
|
||||
} else if (promise._isFulfilled()) {
|
||||
this._fulfillUnchecked(promise._value());
|
||||
} else {
|
||||
this._rejectUnchecked(promise._reason(),
|
||||
promise._getCarriedStackTrace());
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._rejectCallback =
|
||||
function(reason, synchronous, shouldNotMarkOriginatingFromRejection) {
|
||||
if (!shouldNotMarkOriginatingFromRejection) {
|
||||
util.markAsOriginatingFromRejection(reason);
|
||||
}
|
||||
var trace = util.ensureErrorObject(reason);
|
||||
var hasStack = trace === reason;
|
||||
this._attachExtraTrace(trace, synchronous ? hasStack : false);
|
||||
this._reject(reason, hasStack ? undefined : trace);
|
||||
};
|
||||
|
||||
Promise.prototype._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._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);
|
||||
}
|
||||
promise._popContext();
|
||||
|
||||
if (x === errorObj || x === promise || x === NEXT_FILTER) {
|
||||
var err = x === promise ? makeSelfResolutionError() : x.e;
|
||||
promise._rejectCallback(err, false, true);
|
||||
} else {
|
||||
promise._resolveCallback(x);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._target = function() {
|
||||
var ret = this;
|
||||
while (ret._isFollowing()) ret = ret._followee();
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.prototype._followee = function() {
|
||||
return this._rejectionHandler0;
|
||||
};
|
||||
|
||||
Promise.prototype._setFollowee = function(promise) {
|
||||
this._rejectionHandler0 = promise;
|
||||
};
|
||||
|
||||
Promise.prototype._cleanValues = function () {
|
||||
if (this._cancellable()) {
|
||||
this._cancellationParent = undefined;
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._propagateFrom = function (parent, flags) {
|
||||
if ((flags & 1) > 0 && parent._cancellable()) {
|
||||
this._setCancellable();
|
||||
this._cancellationParent = parent;
|
||||
}
|
||||
if ((flags & 4) > 0 && parent._isBound()) {
|
||||
this._setBoundTo(parent._boundTo);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._fulfill = function (value) {
|
||||
if (this._isFollowingOrFulfilledOrRejected()) return;
|
||||
this._fulfillUnchecked(value);
|
||||
};
|
||||
|
||||
Promise.prototype._reject = function (reason, carriedStackTrace) {
|
||||
if (this._isFollowingOrFulfilledOrRejected()) return;
|
||||
this._rejectUnchecked(reason, carriedStackTrace);
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
|
||||
this._clearCallbackDataAtIndex(index);
|
||||
|
||||
if (typeof handler === "function") {
|
||||
if (!isPromise) {
|
||||
handler.call(receiver, value, promise);
|
||||
} else {
|
||||
this._settlePromiseFromHandler(handler, receiver, value, promise);
|
||||
}
|
||||
} else if (receiver instanceof PromiseArray) {
|
||||
if (!receiver._isResolved()) {
|
||||
if (this._isFulfilled()) {
|
||||
receiver._promiseFulfilled(value, promise);
|
||||
}
|
||||
else {
|
||||
receiver._promiseRejected(value, promise);
|
||||
}
|
||||
}
|
||||
} else if (isPromise) {
|
||||
if (this._isFulfilled()) {
|
||||
promise._fulfill(value);
|
||||
} else {
|
||||
promise._reject(value, carriedStackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
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._isSettlePromisesQueued = function () {
|
||||
return (this._bitField &
|
||||
-1073741824) === -1073741824;
|
||||
};
|
||||
|
||||
Promise.prototype._setSettlePromisesQueued = function () {
|
||||
this._bitField = this._bitField | -1073741824;
|
||||
};
|
||||
|
||||
Promise.prototype._unsetSettlePromisesQueued = function () {
|
||||
this._bitField = this._bitField & (~-1073741824);
|
||||
};
|
||||
|
||||
Promise.prototype._queueSettlePromises = function() {
|
||||
async.settlePromises(this);
|
||||
this._setSettlePromisesQueued();
|
||||
};
|
||||
|
||||
Promise.prototype._fulfillUnchecked = function (value) {
|
||||
if (value === this) {
|
||||
var err = makeSelfResolutionError();
|
||||
this._attachExtraTrace(err);
|
||||
return this._rejectUnchecked(err, undefined);
|
||||
}
|
||||
this._setFulfilled();
|
||||
this._settledValue = value;
|
||||
this._cleanValues();
|
||||
|
||||
if (this._length() > 0) {
|
||||
this._queueSettlePromises();
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._rejectUncheckedCheckError = function (reason) {
|
||||
var trace = util.ensureErrorObject(reason);
|
||||
this._rejectUnchecked(reason, trace === reason ? undefined : trace);
|
||||
};
|
||||
|
||||
Promise.prototype._rejectUnchecked = function (reason, trace) {
|
||||
if (reason === this) {
|
||||
var err = makeSelfResolutionError();
|
||||
this._attachExtraTrace(err);
|
||||
return this._rejectUnchecked(err);
|
||||
}
|
||||
this._setRejected();
|
||||
this._settledValue = reason;
|
||||
this._cleanValues();
|
||||
|
||||
if (this._isFinal()) {
|
||||
async.throwLater(function(e) {
|
||||
if ("stack" in e) {
|
||||
async.invokeFirst(
|
||||
CapturedTrace.unhandledRejection, undefined, e);
|
||||
}
|
||||
throw e;
|
||||
}, trace === undefined ? reason : trace);
|
||||
return;
|
||||
}
|
||||
|
||||
if (trace !== undefined && trace !== reason) {
|
||||
this._setCarriedStackTrace(trace);
|
||||
}
|
||||
|
||||
if (this._length() > 0) {
|
||||
this._queueSettlePromises();
|
||||
} else {
|
||||
this._ensurePossibleRejectionHandled();
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._settlePromises = function () {
|
||||
this._unsetSettlePromisesQueued();
|
||||
var len = this._length();
|
||||
for (var i = 0; i < len; i++) {
|
||||
this._settlePromiseAt(i);
|
||||
}
|
||||
};
|
||||
|
||||
Promise._makeSelfResolutionError = makeSelfResolutionError;
|
||||
require("./progress.js")(Promise, PromiseArray);
|
||||
require("./method.js")(Promise, INTERNAL, tryConvertToPromise, apiRejection);
|
||||
require("./bind.js")(Promise, INTERNAL, tryConvertToPromise);
|
||||
require("./finally.js")(Promise, NEXT_FILTER, tryConvertToPromise);
|
||||
require("./direct_resolve.js")(Promise);
|
||||
require("./synchronous_inspection.js")(Promise);
|
||||
require("./join.js")(Promise, PromiseArray, tryConvertToPromise, INTERNAL);
|
||||
Promise.Promise = Promise;
|
||||
require('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL);
|
||||
require('./cancel.js')(Promise);
|
||||
require('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext);
|
||||
require('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise);
|
||||
require('./nodeify.js')(Promise);
|
||||
require('./call_get.js')(Promise);
|
||||
require('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection);
|
||||
require('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection);
|
||||
require('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL);
|
||||
require('./settle.js')(Promise, PromiseArray);
|
||||
require('./some.js')(Promise, PromiseArray, apiRejection);
|
||||
require('./promisify.js')(Promise, INTERNAL);
|
||||
require('./any.js')(Promise);
|
||||
require('./each.js')(Promise, INTERNAL);
|
||||
require('./timers.js')(Promise, INTERNAL);
|
||||
require('./filter.js')(Promise, INTERNAL);
|
||||
|
||||
util.toFastProperties(Promise);
|
||||
util.toFastProperties(Promise.prototype);
|
||||
function fillTypes(value) {
|
||||
var p = new Promise(INTERNAL);
|
||||
p._fulfillmentHandler0 = value;
|
||||
p._rejectionHandler0 = value;
|
||||
p._progressHandler0 = value;
|
||||
p._promise0 = value;
|
||||
p._receiver0 = value;
|
||||
p._settledValue = value;
|
||||
}
|
||||
// Complete slack tracking, opt out of field-type tracking and
|
||||
// stabilize map
|
||||
fillTypes({a: 1});
|
||||
fillTypes({b: 2});
|
||||
fillTypes({c: 3});
|
||||
fillTypes(1);
|
||||
fillTypes(function(){});
|
||||
fillTypes(undefined);
|
||||
fillTypes(false);
|
||||
fillTypes(new Promise(INTERNAL));
|
||||
CapturedTrace.setBounds(async.firstLineError, util.lastLineError);
|
||||
return Promise;
|
||||
|
||||
};
|
142
node_modules/bluebird/js/main/promise_array.js
generated
vendored
142
node_modules/bluebird/js/main/promise_array.js
generated
vendored
@ -1,142 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, INTERNAL, tryConvertToPromise,
|
||||
apiRejection) {
|
||||
var util = require("./util.js");
|
||||
var isArray = util.isArray;
|
||||
|
||||
function toResolutionValue(val) {
|
||||
switch(val) {
|
||||
case -2: return [];
|
||||
case -3: return {};
|
||||
}
|
||||
}
|
||||
|
||||
function PromiseArray(values) {
|
||||
var promise = this._promise = new Promise(INTERNAL);
|
||||
var parent;
|
||||
if (values instanceof Promise) {
|
||||
parent = values;
|
||||
promise._propagateFrom(parent, 1 | 4);
|
||||
}
|
||||
this._values = values;
|
||||
this._length = 0;
|
||||
this._totalResolved = 0;
|
||||
this._init(undefined, -2);
|
||||
}
|
||||
PromiseArray.prototype.length = function () {
|
||||
return this._length;
|
||||
};
|
||||
|
||||
PromiseArray.prototype.promise = function () {
|
||||
return this._promise;
|
||||
};
|
||||
|
||||
PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
|
||||
var values = tryConvertToPromise(this._values, this._promise);
|
||||
if (values instanceof Promise) {
|
||||
values = values._target();
|
||||
this._values = values;
|
||||
if (values._isFulfilled()) {
|
||||
values = values._value();
|
||||
if (!isArray(values)) {
|
||||
var err = new Promise.TypeError("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a");
|
||||
this.__hardReject__(err);
|
||||
return;
|
||||
}
|
||||
} else if (values._isPending()) {
|
||||
values._then(
|
||||
init,
|
||||
this._reject,
|
||||
undefined,
|
||||
this,
|
||||
resolveValueIfEmpty
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
this._reject(values._reason());
|
||||
return;
|
||||
}
|
||||
} else if (!isArray(values)) {
|
||||
this._promise._reject(apiRejection("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a")._reason());
|
||||
return;
|
||||
}
|
||||
|
||||
if (values.length === 0) {
|
||||
if (resolveValueIfEmpty === -5) {
|
||||
this._resolveEmptyArray();
|
||||
}
|
||||
else {
|
||||
this._resolve(toResolutionValue(resolveValueIfEmpty));
|
||||
}
|
||||
return;
|
||||
}
|
||||
var len = this.getActualLength(values.length);
|
||||
this._length = len;
|
||||
this._values = this.shouldCopyValues() ? new Array(len) : this._values;
|
||||
var promise = this._promise;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var isResolved = this._isResolved();
|
||||
var maybePromise = tryConvertToPromise(values[i], promise);
|
||||
if (maybePromise instanceof Promise) {
|
||||
maybePromise = maybePromise._target();
|
||||
if (isResolved) {
|
||||
maybePromise._unsetRejectionIsUnhandled();
|
||||
} else if (maybePromise._isPending()) {
|
||||
maybePromise._proxyPromiseArray(this, i);
|
||||
} else if (maybePromise._isFulfilled()) {
|
||||
this._promiseFulfilled(maybePromise._value(), i);
|
||||
} else {
|
||||
this._promiseRejected(maybePromise._reason(), i);
|
||||
}
|
||||
} else if (!isResolved) {
|
||||
this._promiseFulfilled(maybePromise, i);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PromiseArray.prototype._isResolved = function () {
|
||||
return this._values === null;
|
||||
};
|
||||
|
||||
PromiseArray.prototype._resolve = function (value) {
|
||||
this._values = null;
|
||||
this._promise._fulfill(value);
|
||||
};
|
||||
|
||||
PromiseArray.prototype.__hardReject__ =
|
||||
PromiseArray.prototype._reject = function (reason) {
|
||||
this._values = null;
|
||||
this._promise._rejectCallback(reason, false, true);
|
||||
};
|
||||
|
||||
PromiseArray.prototype._promiseProgressed = function (progressValue, index) {
|
||||
this._promise._progress({
|
||||
index: index,
|
||||
value: progressValue
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
PromiseArray.prototype._promiseFulfilled = function (value, index) {
|
||||
this._values[index] = value;
|
||||
var totalResolved = ++this._totalResolved;
|
||||
if (totalResolved >= this._length) {
|
||||
this._resolve(this._values);
|
||||
}
|
||||
};
|
||||
|
||||
PromiseArray.prototype._promiseRejected = function (reason, index) {
|
||||
this._totalResolved++;
|
||||
this._reject(reason);
|
||||
};
|
||||
|
||||
PromiseArray.prototype.shouldCopyValues = function () {
|
||||
return true;
|
||||
};
|
||||
|
||||
PromiseArray.prototype.getActualLength = function (len) {
|
||||
return len;
|
||||
};
|
||||
|
||||
return PromiseArray;
|
||||
};
|
123
node_modules/bluebird/js/main/promise_resolver.js
generated
vendored
123
node_modules/bluebird/js/main/promise_resolver.js
generated
vendored
@ -1,123 +0,0 @@
|
||||
"use strict";
|
||||
var util = require("./util.js");
|
||||
var maybeWrapAsError = util.maybeWrapAsError;
|
||||
var errors = require("./errors.js");
|
||||
var TimeoutError = errors.TimeoutError;
|
||||
var OperationalError = errors.OperationalError;
|
||||
var haveGetters = util.haveGetters;
|
||||
var es5 = require("./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);
|
||||
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;
|
||||
}
|
||||
util.markAsOriginatingFromRejection(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
function nodebackForPromise(promise) {
|
||||
return function(err, value) {
|
||||
if (promise === null) return;
|
||||
|
||||
if (err) {
|
||||
var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
|
||||
promise._attachExtraTrace(wrapped);
|
||||
promise._reject(wrapped);
|
||||
} else if (arguments.length > 2) {
|
||||
var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
|
||||
promise._fulfill(args);
|
||||
} else {
|
||||
promise._fulfill(value);
|
||||
}
|
||||
|
||||
promise = null;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
var PromiseResolver;
|
||||
if (!haveGetters) {
|
||||
PromiseResolver = function (promise) {
|
||||
this.promise = promise;
|
||||
this.asCallback = nodebackForPromise(promise);
|
||||
this.callback = this.asCallback;
|
||||
};
|
||||
}
|
||||
else {
|
||||
PromiseResolver = function (promise) {
|
||||
this.promise = promise;
|
||||
};
|
||||
}
|
||||
if (haveGetters) {
|
||||
var prop = {
|
||||
get: function() {
|
||||
return nodebackForPromise(this.promise);
|
||||
}
|
||||
};
|
||||
es5.defineProperty(PromiseResolver.prototype, "asCallback", prop);
|
||||
es5.defineProperty(PromiseResolver.prototype, "callback", prop);
|
||||
}
|
||||
|
||||
PromiseResolver._nodebackForPromise = nodebackForPromise;
|
||||
|
||||
PromiseResolver.prototype.toString = function () {
|
||||
return "[object PromiseResolver]";
|
||||
};
|
||||
|
||||
PromiseResolver.prototype.resolve =
|
||||
PromiseResolver.prototype.fulfill = function (value) {
|
||||
if (!(this instanceof PromiseResolver)) {
|
||||
throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\u000a\u000a See http://goo.gl/sdkXL9\u000a");
|
||||
}
|
||||
this.promise._resolveCallback(value);
|
||||
};
|
||||
|
||||
PromiseResolver.prototype.reject = function (reason) {
|
||||
if (!(this instanceof PromiseResolver)) {
|
||||
throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\u000a\u000a See http://goo.gl/sdkXL9\u000a");
|
||||
}
|
||||
this.promise._rejectCallback(reason);
|
||||
};
|
||||
|
||||
PromiseResolver.prototype.progress = function (value) {
|
||||
if (!(this instanceof PromiseResolver)) {
|
||||
throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\u000a\u000a See http://goo.gl/sdkXL9\u000a");
|
||||
}
|
||||
this.promise._progress(value);
|
||||
};
|
||||
|
||||
PromiseResolver.prototype.cancel = function (err) {
|
||||
this.promise.cancel(err);
|
||||
};
|
||||
|
||||
PromiseResolver.prototype.timeout = function () {
|
||||
this.reject(new TimeoutError("timeout"));
|
||||
};
|
||||
|
||||
PromiseResolver.prototype.isResolved = function () {
|
||||
return this.promise.isResolved();
|
||||
};
|
||||
|
||||
PromiseResolver.prototype.toJSON = function () {
|
||||
return this.promise.toJSON();
|
||||
};
|
||||
|
||||
module.exports = PromiseResolver;
|
79
node_modules/bluebird/js/main/props.js
generated
vendored
79
node_modules/bluebird/js/main/props.js
generated
vendored
@ -1,79 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = function(
|
||||
Promise, PromiseArray, tryConvertToPromise, apiRejection) {
|
||||
var util = require("./util.js");
|
||||
var isObject = util.isObject;
|
||||
var es5 = require("./es5.js");
|
||||
|
||||
function PropertiesPromiseArray(obj) {
|
||||
var keys = es5.keys(obj);
|
||||
var len = keys.length;
|
||||
var values = new Array(len * 2);
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var key = keys[i];
|
||||
values[i] = obj[key];
|
||||
values[i + len] = key;
|
||||
}
|
||||
this.constructor$(values);
|
||||
}
|
||||
util.inherits(PropertiesPromiseArray, PromiseArray);
|
||||
|
||||
PropertiesPromiseArray.prototype._init = function () {
|
||||
this._init$(undefined, -3) ;
|
||||
};
|
||||
|
||||
PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {
|
||||
this._values[index] = value;
|
||||
var totalResolved = ++this._totalResolved;
|
||||
if (totalResolved >= this._length) {
|
||||
var val = {};
|
||||
var keyOffset = this.length();
|
||||
for (var i = 0, len = this.length(); i < len; ++i) {
|
||||
val[this._values[i + keyOffset]] = this._values[i];
|
||||
}
|
||||
this._resolve(val);
|
||||
}
|
||||
};
|
||||
|
||||
PropertiesPromiseArray.prototype._promiseProgressed = function (value, index) {
|
||||
this._promise._progress({
|
||||
key: this._values[index + this.length()],
|
||||
value: value
|
||||
});
|
||||
};
|
||||
|
||||
PropertiesPromiseArray.prototype.shouldCopyValues = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
PropertiesPromiseArray.prototype.getActualLength = function (len) {
|
||||
return len >> 1;
|
||||
};
|
||||
|
||||
function props(promises) {
|
||||
var ret;
|
||||
var castValue = tryConvertToPromise(promises);
|
||||
|
||||
if (!isObject(castValue)) {
|
||||
return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/OsFKC8\u000a");
|
||||
} else if (castValue instanceof Promise) {
|
||||
ret = castValue._then(
|
||||
Promise.props, undefined, undefined, undefined, undefined);
|
||||
} else {
|
||||
ret = new PropertiesPromiseArray(castValue).promise();
|
||||
}
|
||||
|
||||
if (castValue instanceof Promise) {
|
||||
ret._propagateFrom(castValue, 4);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Promise.prototype.props = function () {
|
||||
return props(this);
|
||||
};
|
||||
|
||||
Promise.props = function (promises) {
|
||||
return props(promises);
|
||||
};
|
||||
};
|
146
node_modules/bluebird/js/main/reduce.js
generated
vendored
146
node_modules/bluebird/js/main/reduce.js
generated
vendored
@ -1,146 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise,
|
||||
PromiseArray,
|
||||
apiRejection,
|
||||
tryConvertToPromise,
|
||||
INTERNAL) {
|
||||
var async = require("./async.js");
|
||||
var util = require("./util.js");
|
||||
var tryCatch = util.tryCatch;
|
||||
var errorObj = util.errorObj;
|
||||
function ReductionPromiseArray(promises, fn, accum, _each) {
|
||||
this.constructor$(promises);
|
||||
this._promise._captureStackTrace();
|
||||
this._preservedValues = _each === INTERNAL ? [] : null;
|
||||
this._zerothIsAccum = (accum === undefined);
|
||||
this._gotAccum = false;
|
||||
this._reducingIndex = (this._zerothIsAccum ? 1 : 0);
|
||||
this._valuesPhase = undefined;
|
||||
var maybePromise = tryConvertToPromise(accum, this._promise);
|
||||
var rejected = false;
|
||||
var isPromise = maybePromise instanceof Promise;
|
||||
if (isPromise) {
|
||||
maybePromise = maybePromise._target();
|
||||
if (maybePromise._isPending()) {
|
||||
maybePromise._proxyPromiseArray(this, -1);
|
||||
} else if (maybePromise._isFulfilled()) {
|
||||
accum = maybePromise._value();
|
||||
this._gotAccum = true;
|
||||
} else {
|
||||
this._reject(maybePromise._reason());
|
||||
rejected = true;
|
||||
}
|
||||
}
|
||||
if (!(isPromise || this._zerothIsAccum)) this._gotAccum = true;
|
||||
this._callback = fn;
|
||||
this._accum = accum;
|
||||
if (!rejected) async.invoke(init, this, undefined);
|
||||
}
|
||||
function init() {
|
||||
this._init$(undefined, -5);
|
||||
}
|
||||
util.inherits(ReductionPromiseArray, PromiseArray);
|
||||
|
||||
ReductionPromiseArray.prototype._init = function () {};
|
||||
|
||||
ReductionPromiseArray.prototype._resolveEmptyArray = function () {
|
||||
if (this._gotAccum || this._zerothIsAccum) {
|
||||
this._resolve(this._preservedValues !== null
|
||||
? [] : this._accum);
|
||||
}
|
||||
};
|
||||
|
||||
ReductionPromiseArray.prototype._promiseFulfilled = function (value, index) {
|
||||
var values = this._values;
|
||||
values[index] = value;
|
||||
var length = this.length();
|
||||
var preservedValues = this._preservedValues;
|
||||
var isEach = preservedValues !== null;
|
||||
var gotAccum = this._gotAccum;
|
||||
var valuesPhase = this._valuesPhase;
|
||||
var valuesPhaseIndex;
|
||||
if (!valuesPhase) {
|
||||
valuesPhase = this._valuesPhase = new Array(length);
|
||||
for (valuesPhaseIndex=0; valuesPhaseIndex<length; ++valuesPhaseIndex) {
|
||||
valuesPhase[valuesPhaseIndex] = 0;
|
||||
}
|
||||
}
|
||||
valuesPhaseIndex = valuesPhase[index];
|
||||
|
||||
if (index === 0 && this._zerothIsAccum) {
|
||||
this._accum = value;
|
||||
this._gotAccum = gotAccum = true;
|
||||
valuesPhase[index] = ((valuesPhaseIndex === 0)
|
||||
? 1 : 2);
|
||||
} else if (index === -1) {
|
||||
this._accum = value;
|
||||
this._gotAccum = gotAccum = true;
|
||||
} else {
|
||||
if (valuesPhaseIndex === 0) {
|
||||
valuesPhase[index] = 1;
|
||||
} else {
|
||||
valuesPhase[index] = 2;
|
||||
this._accum = value;
|
||||
}
|
||||
}
|
||||
if (!gotAccum) return;
|
||||
|
||||
var callback = this._callback;
|
||||
var receiver = this._promise._boundTo;
|
||||
var ret;
|
||||
|
||||
for (var i = this._reducingIndex; i < length; ++i) {
|
||||
valuesPhaseIndex = valuesPhase[i];
|
||||
if (valuesPhaseIndex === 2) {
|
||||
this._reducingIndex = i + 1;
|
||||
continue;
|
||||
}
|
||||
if (valuesPhaseIndex !== 1) return;
|
||||
value = values[i];
|
||||
this._promise._pushContext();
|
||||
if (isEach) {
|
||||
preservedValues.push(value);
|
||||
ret = tryCatch(callback).call(receiver, value, i, length);
|
||||
}
|
||||
else {
|
||||
ret = tryCatch(callback)
|
||||
.call(receiver, this._accum, value, i, length);
|
||||
}
|
||||
this._promise._popContext();
|
||||
|
||||
if (ret === errorObj) return this._reject(ret.e);
|
||||
|
||||
var maybePromise = tryConvertToPromise(ret, this._promise);
|
||||
if (maybePromise instanceof Promise) {
|
||||
maybePromise = maybePromise._target();
|
||||
if (maybePromise._isPending()) {
|
||||
valuesPhase[i] = 4;
|
||||
return maybePromise._proxyPromiseArray(this, i);
|
||||
} else if (maybePromise._isFulfilled()) {
|
||||
ret = maybePromise._value();
|
||||
} else {
|
||||
return this._reject(maybePromise._reason());
|
||||
}
|
||||
}
|
||||
|
||||
this._reducingIndex = i + 1;
|
||||
this._accum = ret;
|
||||
}
|
||||
|
||||
this._resolve(isEach ? preservedValues : this._accum);
|
||||
};
|
||||
|
||||
function reduce(promises, fn, initialValue, _each) {
|
||||
if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
|
||||
var array = new ReductionPromiseArray(promises, fn, initialValue, _each);
|
||||
return array.promise();
|
||||
}
|
||||
|
||||
Promise.prototype.reduce = function (fn, initialValue) {
|
||||
return reduce(this, fn, initialValue, null);
|
||||
};
|
||||
|
||||
Promise.reduce = function (promises, fn, initialValue, _each) {
|
||||
return reduce(promises, fn, initialValue, _each);
|
||||
};
|
||||
};
|
94
node_modules/bluebird/js/main/synchronous_inspection.js
generated
vendored
94
node_modules/bluebird/js/main/synchronous_inspection.js
generated
vendored
@ -1,94 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise) {
|
||||
function PromiseInspection(promise) {
|
||||
if (promise !== undefined) {
|
||||
promise = promise._target();
|
||||
this._bitField = promise._bitField;
|
||||
this._settledValue = promise._settledValue;
|
||||
}
|
||||
else {
|
||||
this._bitField = 0;
|
||||
this._settledValue = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
PromiseInspection.prototype.value = function () {
|
||||
if (!this.isFulfilled()) {
|
||||
throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/hc1DLj\u000a");
|
||||
}
|
||||
return this._settledValue;
|
||||
};
|
||||
|
||||
PromiseInspection.prototype.error =
|
||||
PromiseInspection.prototype.reason = function () {
|
||||
if (!this.isRejected()) {
|
||||
throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/hPuiwB\u000a");
|
||||
}
|
||||
return this._settledValue;
|
||||
};
|
||||
|
||||
PromiseInspection.prototype.isFulfilled =
|
||||
Promise.prototype._isFulfilled = function () {
|
||||
return (this._bitField & 268435456) > 0;
|
||||
};
|
||||
|
||||
PromiseInspection.prototype.isRejected =
|
||||
Promise.prototype._isRejected = function () {
|
||||
return (this._bitField & 134217728) > 0;
|
||||
};
|
||||
|
||||
PromiseInspection.prototype.isPending =
|
||||
Promise.prototype._isPending = function () {
|
||||
return (this._bitField & 402653184) === 0;
|
||||
};
|
||||
|
||||
PromiseInspection.prototype.isResolved =
|
||||
Promise.prototype._isResolved = function () {
|
||||
return (this._bitField & 402653184) > 0;
|
||||
};
|
||||
|
||||
Promise.prototype.isPending = function() {
|
||||
return this._target()._isPending();
|
||||
};
|
||||
|
||||
Promise.prototype.isRejected = function() {
|
||||
return this._target()._isRejected();
|
||||
};
|
||||
|
||||
Promise.prototype.isFulfilled = function() {
|
||||
return this._target()._isFulfilled();
|
||||
};
|
||||
|
||||
Promise.prototype.isResolved = function() {
|
||||
return this._target()._isResolved();
|
||||
};
|
||||
|
||||
Promise.prototype._value = function() {
|
||||
return this._settledValue;
|
||||
};
|
||||
|
||||
Promise.prototype._reason = function() {
|
||||
this._unsetRejectionIsUnhandled();
|
||||
return this._settledValue;
|
||||
};
|
||||
|
||||
Promise.prototype.value = function() {
|
||||
var target = this._target();
|
||||
if (!target.isFulfilled()) {
|
||||
throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/hc1DLj\u000a");
|
||||
}
|
||||
return target._settledValue;
|
||||
};
|
||||
|
||||
Promise.prototype.reason = function() {
|
||||
var target = this._target();
|
||||
if (!target.isRejected()) {
|
||||
throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/hPuiwB\u000a");
|
||||
}
|
||||
target._unsetRejectionIsUnhandled();
|
||||
return target._settledValue;
|
||||
};
|
||||
|
||||
|
||||
Promise.PromiseInspection = PromiseInspection;
|
||||
};
|
0
node_modules/bluebird/js/main/any.js → node_modules/bluebird/js/release/any.js
generated
vendored
0
node_modules/bluebird/js/main/any.js → node_modules/bluebird/js/release/any.js
generated
vendored
2
node_modules/bluebird/js/main/assert.js → node_modules/bluebird/js/release/assert.js
generated
vendored
2
node_modules/bluebird/js/main/assert.js → node_modules/bluebird/js/release/assert.js
generated
vendored
@ -41,7 +41,7 @@ return function assert(boolExpr, message) {
|
||||
if (typeof boolExpr === "string" &&
|
||||
boolExpr.charAt(0) === "%") {
|
||||
var nativeCallName = boolExpr;
|
||||
var $_len = arguments.length;var args = new Array($_len - 2); for(var $_i = 2; $_i < $_len; ++$_i) {args[$_i - 2] = arguments[$_i];}
|
||||
var $_len = arguments.length;var args = new Array($_len - 2); for(var $_i = 2; $_i < $_len; ++$_i) {args[$_i - 2] = arguments[$_i];};
|
||||
if (nativeAssert(nativeCallName, args, message) === message) return;
|
||||
message = (nativeCallName + " !== " + message);
|
||||
}
|
113
node_modules/bluebird/js/main/async.js → node_modules/bluebird/js/release/async.js
generated
vendored
113
node_modules/bluebird/js/main/async.js → node_modules/bluebird/js/release/async.js
generated
vendored
@ -1,14 +1,15 @@
|
||||
"use strict";
|
||||
var firstLineError;
|
||||
try {throw new Error(); } catch (e) {firstLineError = e;}
|
||||
var schedule = require("./schedule.js");
|
||||
var Queue = require("./queue.js");
|
||||
var util = require("./util.js");
|
||||
var schedule = require("./schedule");
|
||||
var Queue = require("./queue");
|
||||
var util = require("./util");
|
||||
|
||||
function Async() {
|
||||
this._isTickUsed = false;
|
||||
this._lateQueue = new Queue(16);
|
||||
this._normalQueue = new Queue(16);
|
||||
this._haveDrainedQueues = false;
|
||||
this._trampolineEnabled = true;
|
||||
var self = this;
|
||||
this.drainQueues = function () {
|
||||
@ -18,23 +19,28 @@ function Async() {
|
||||
schedule.isStatic ? schedule(this.drainQueues) : schedule;
|
||||
}
|
||||
|
||||
Async.prototype.enableTrampoline = function() {
|
||||
this._trampolineEnabled = true;
|
||||
};
|
||||
|
||||
Async.prototype.disableTrampolineIfNecessary = function() {
|
||||
if (util.hasDevTools) {
|
||||
this._trampolineEnabled = false;
|
||||
}
|
||||
};
|
||||
|
||||
Async.prototype.enableTrampoline = function() {
|
||||
if (!this._trampolineEnabled) {
|
||||
this._trampolineEnabled = true;
|
||||
this._schedule = function(fn) {
|
||||
setTimeout(fn, 0);
|
||||
};
|
||||
}
|
||||
Async.prototype.haveItemsQueued = function () {
|
||||
return this._isTickUsed || this._haveDrainedQueues;
|
||||
};
|
||||
|
||||
Async.prototype.haveItemsQueued = function () {
|
||||
return this._normalQueue.length() > 0;
|
||||
|
||||
Async.prototype.fatalError = function(e, isNode) {
|
||||
if (isNode) {
|
||||
process.stderr.write("Fatal " + (e instanceof Error ? e.stack : e));
|
||||
process.exit(2);
|
||||
} else {
|
||||
this.throwLater(e);
|
||||
}
|
||||
};
|
||||
|
||||
Async.prototype.throwLater = function(fn, arg) {
|
||||
@ -42,8 +48,6 @@ Async.prototype.throwLater = function(fn, arg) {
|
||||
arg = fn;
|
||||
fn = function () { throw arg; };
|
||||
}
|
||||
var domain = this._getDomain();
|
||||
if (domain !== undefined) fn = domain.bind(fn);
|
||||
if (typeof setTimeout !== "undefined") {
|
||||
setTimeout(function() {
|
||||
fn(arg);
|
||||
@ -53,75 +57,22 @@ Async.prototype.throwLater = function(fn, arg) {
|
||||
fn(arg);
|
||||
});
|
||||
} catch (e) {
|
||||
throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/m3OTXk\u000a");
|
||||
throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
}
|
||||
};
|
||||
|
||||
Async.prototype._getDomain = function() {};
|
||||
|
||||
if (util.isNode) {
|
||||
var EventsModule = require("events");
|
||||
|
||||
var domainGetter = function() {
|
||||
var domain = process.domain;
|
||||
if (domain === null) return undefined;
|
||||
return domain;
|
||||
};
|
||||
|
||||
if (EventsModule.usingDomains) {
|
||||
Async.prototype._getDomain = domainGetter;
|
||||
} else {
|
||||
var descriptor =
|
||||
Object.getOwnPropertyDescriptor(EventsModule, "usingDomains");
|
||||
|
||||
if (!descriptor.configurable) {
|
||||
process.on("domainsActivated", function() {
|
||||
Async.prototype._getDomain = domainGetter;
|
||||
});
|
||||
} else {
|
||||
var usingDomains = false;
|
||||
Object.defineProperty(EventsModule, "usingDomains", {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return usingDomains;
|
||||
},
|
||||
set: function(value) {
|
||||
if (usingDomains || !value) return;
|
||||
usingDomains = true;
|
||||
Async.prototype._getDomain = domainGetter;
|
||||
util.toFastProperties(process);
|
||||
process.emit("domainsActivated");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function AsyncInvokeLater(fn, receiver, arg) {
|
||||
var domain = this._getDomain();
|
||||
if (domain !== undefined) fn = domain.bind(fn);
|
||||
this._lateQueue.push(fn, receiver, arg);
|
||||
this._queueTick();
|
||||
}
|
||||
|
||||
function AsyncInvoke(fn, receiver, arg) {
|
||||
var domain = this._getDomain();
|
||||
if (domain !== undefined) fn = domain.bind(fn);
|
||||
this._normalQueue.push(fn, receiver, arg);
|
||||
this._queueTick();
|
||||
}
|
||||
|
||||
function AsyncSettlePromises(promise) {
|
||||
var domain = this._getDomain();
|
||||
if (domain !== undefined) {
|
||||
var fn = domain.bind(promise._settlePromises);
|
||||
this._normalQueue.push(fn, promise, undefined);
|
||||
} else {
|
||||
this._normalQueue._pushOne(promise);
|
||||
}
|
||||
this._normalQueue._pushOne(promise);
|
||||
this._queueTick();
|
||||
}
|
||||
|
||||
@ -130,13 +81,18 @@ if (!util.hasDevTools) {
|
||||
Async.prototype.invoke = AsyncInvoke;
|
||||
Async.prototype.settlePromises = AsyncSettlePromises;
|
||||
} else {
|
||||
if (schedule.isStatic) {
|
||||
schedule = function(fn) { setTimeout(fn, 0); };
|
||||
}
|
||||
Async.prototype.invokeLater = function (fn, receiver, arg) {
|
||||
if (this._trampolineEnabled) {
|
||||
AsyncInvokeLater.call(this, fn, receiver, arg);
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
fn.call(receiver, arg);
|
||||
}, 100);
|
||||
this._schedule(function() {
|
||||
setTimeout(function() {
|
||||
fn.call(receiver, arg);
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -144,9 +100,9 @@ if (!util.hasDevTools) {
|
||||
if (this._trampolineEnabled) {
|
||||
AsyncInvoke.call(this, fn, receiver, arg);
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
this._schedule(function() {
|
||||
fn.call(receiver, arg);
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -154,16 +110,14 @@ if (!util.hasDevTools) {
|
||||
if (this._trampolineEnabled) {
|
||||
AsyncSettlePromises.call(this, promise);
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
this._schedule(function() {
|
||||
promise._settlePromises();
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Async.prototype.invokeFirst = function (fn, receiver, arg) {
|
||||
var domain = this._getDomain();
|
||||
if (domain !== undefined) fn = domain.bind(fn);
|
||||
this._normalQueue.unshift(fn, receiver, arg);
|
||||
this._queueTick();
|
||||
};
|
||||
@ -184,6 +138,7 @@ Async.prototype._drainQueue = function(queue) {
|
||||
Async.prototype._drainQueues = function () {
|
||||
this._drainQueue(this._normalQueue);
|
||||
this._reset();
|
||||
this._haveDrainedQueues = true;
|
||||
this._drainQueue(this._lateQueue);
|
||||
};
|
||||
|
||||
@ -198,5 +153,5 @@ Async.prototype._reset = function () {
|
||||
this._isTickUsed = false;
|
||||
};
|
||||
|
||||
module.exports = new Async();
|
||||
module.exports = Async;
|
||||
module.exports.firstLineError = firstLineError;
|
38
node_modules/bluebird/js/main/bind.js → node_modules/bluebird/js/release/bind.js
generated
vendored
38
node_modules/bluebird/js/main/bind.js → node_modules/bluebird/js/release/bind.js
generated
vendored
@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, INTERNAL, tryConvertToPromise) {
|
||||
module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) {
|
||||
var calledBind = false;
|
||||
var rejectThis = function(_, e) {
|
||||
this._reject(e);
|
||||
};
|
||||
@ -10,8 +11,7 @@ var targetRejected = function(e, context) {
|
||||
};
|
||||
|
||||
var bindingResolved = function(thisArg, context) {
|
||||
this._setBoundTo(thisArg);
|
||||
if (this._isPending()) {
|
||||
if (((this._bitField & 50397184) === 0)) {
|
||||
this._resolveCallback(context.target);
|
||||
}
|
||||
};
|
||||
@ -21,10 +21,16 @@ var bindingRejected = function(e, context) {
|
||||
};
|
||||
|
||||
Promise.prototype.bind = function (thisArg) {
|
||||
if (!calledBind) {
|
||||
calledBind = true;
|
||||
Promise.prototype._propagateFrom = debug.propagateFromFunction();
|
||||
Promise.prototype._boundValue = debug.boundValueFunction();
|
||||
}
|
||||
var maybePromise = tryConvertToPromise(thisArg);
|
||||
var ret = new Promise(INTERNAL);
|
||||
ret._propagateFrom(this, 1);
|
||||
var target = this._target();
|
||||
ret._setBoundTo(maybePromise);
|
||||
if (maybePromise instanceof Promise) {
|
||||
var context = {
|
||||
promiseRejectionQueued: false,
|
||||
@ -32,11 +38,11 @@ Promise.prototype.bind = function (thisArg) {
|
||||
target: target,
|
||||
bindingPromise: maybePromise
|
||||
};
|
||||
target._then(INTERNAL, targetRejected, ret._progress, ret, context);
|
||||
target._then(INTERNAL, targetRejected, undefined, ret, context);
|
||||
maybePromise._then(
|
||||
bindingResolved, bindingRejected, ret._progress, ret, context);
|
||||
bindingResolved, bindingRejected, undefined, ret, context);
|
||||
ret._setOnCancel(maybePromise);
|
||||
} else {
|
||||
ret._setBoundTo(thisArg);
|
||||
ret._resolveCallback(target);
|
||||
}
|
||||
return ret;
|
||||
@ -44,30 +50,18 @@ Promise.prototype.bind = function (thisArg) {
|
||||
|
||||
Promise.prototype._setBoundTo = function (obj) {
|
||||
if (obj !== undefined) {
|
||||
this._bitField = this._bitField | 131072;
|
||||
this._bitField = this._bitField | 2097152;
|
||||
this._boundTo = obj;
|
||||
} else {
|
||||
this._bitField = this._bitField & (~131072);
|
||||
this._bitField = this._bitField & (~2097152);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._isBound = function () {
|
||||
return (this._bitField & 131072) === 131072;
|
||||
return (this._bitField & 2097152) === 2097152;
|
||||
};
|
||||
|
||||
Promise.bind = function (thisArg, value) {
|
||||
var maybePromise = tryConvertToPromise(thisArg);
|
||||
var ret = new Promise(INTERNAL);
|
||||
|
||||
if (maybePromise instanceof Promise) {
|
||||
maybePromise._then(function(thisArg) {
|
||||
ret._setBoundTo(thisArg);
|
||||
ret._resolveCallback(value);
|
||||
}, ret._reject, ret._progress, ret, null);
|
||||
} else {
|
||||
ret._setBoundTo(thisArg);
|
||||
ret._resolveCallback(value);
|
||||
}
|
||||
return ret;
|
||||
return Promise.resolve(value).bind(thisArg);
|
||||
};
|
||||
};
|
@ -6,6 +6,6 @@ function noConflict() {
|
||||
catch (e) {}
|
||||
return bluebird;
|
||||
}
|
||||
var bluebird = require("./promise.js")();
|
||||
var bluebird = require("./promise")();
|
||||
bluebird.noConflict = noConflict;
|
||||
module.exports = bluebird;
|
@ -7,7 +7,7 @@ if (cr) {
|
||||
}
|
||||
|
||||
module.exports = function(Promise) {
|
||||
var util = require("./util.js");
|
||||
var util = require("./util");
|
||||
var canEvaluate = util.canEvaluate;
|
||||
var isIdentifier = util.isIdentifier;
|
||||
|
||||
@ -83,7 +83,7 @@ function caller(obj) {
|
||||
return fn.apply(obj, this);
|
||||
}
|
||||
Promise.prototype.call = function (methodName) {
|
||||
var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
|
||||
var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];};
|
||||
if (!false) {
|
||||
if (canEvaluate) {
|
||||
var maybeCaller = getMethodCaller(methodName);
|
125
node_modules/bluebird/js/release/cancel.js
generated
vendored
Normal file
125
node_modules/bluebird/js/release/cancel.js
generated
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, PromiseArray, apiRejection, debug) {
|
||||
var util = require("./util");
|
||||
var tryCatch = util.tryCatch;
|
||||
var errorObj = util.errorObj;
|
||||
var async = Promise._async;
|
||||
|
||||
Promise.prototype["break"] = Promise.prototype.cancel = function() {
|
||||
if (!debug.cancellation()) return this._warn("cancellation is disabled");
|
||||
|
||||
var promise = this;
|
||||
var child = promise;
|
||||
while (promise.isCancellable()) {
|
||||
if (!promise._cancelBy(child)) {
|
||||
if (child._isFollowing()) {
|
||||
child._followee().cancel();
|
||||
} else {
|
||||
child._cancelBranched();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
var parent = promise._cancellationParent;
|
||||
if (parent == null || !parent.isCancellable()) {
|
||||
if (promise._isFollowing()) {
|
||||
promise._followee().cancel();
|
||||
} else {
|
||||
promise._cancelBranched();
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if (promise._isFollowing()) promise._followee().cancel();
|
||||
child = promise;
|
||||
promise = parent;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._branchHasCancelled = function() {
|
||||
this._branchesRemainingToCancel--;
|
||||
};
|
||||
|
||||
Promise.prototype._enoughBranchesHaveCancelled = function() {
|
||||
return this._branchesRemainingToCancel === undefined ||
|
||||
this._branchesRemainingToCancel <= 0;
|
||||
};
|
||||
|
||||
Promise.prototype._cancelBy = function(canceller) {
|
||||
if (canceller === this) {
|
||||
this._branchesRemainingToCancel = 0;
|
||||
this._invokeOnCancel();
|
||||
return true;
|
||||
} else {
|
||||
this._branchHasCancelled();
|
||||
if (this._enoughBranchesHaveCancelled()) {
|
||||
this._invokeOnCancel();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Promise.prototype._cancelBranched = function() {
|
||||
if (this._enoughBranchesHaveCancelled()) {
|
||||
this._cancel();
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._cancel = function() {
|
||||
if (!this.isCancellable()) return;
|
||||
|
||||
this._setCancelled();
|
||||
async.invoke(this._cancelPromises, this, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype._cancelPromises = function() {
|
||||
if (this._length() > 0) this._settlePromises();
|
||||
};
|
||||
|
||||
Promise.prototype._unsetOnCancel = function() {
|
||||
this._onCancelField = undefined;
|
||||
};
|
||||
|
||||
Promise.prototype.isCancellable = function() {
|
||||
return this.isPending() && !this.isCancelled();
|
||||
};
|
||||
|
||||
Promise.prototype._doInvokeOnCancel = function(onCancelCallback, internalOnly) {
|
||||
if (util.isArray(onCancelCallback)) {
|
||||
for (var i = 0; i < onCancelCallback.length; ++i) {
|
||||
this._doInvokeOnCancel(onCancelCallback[i], internalOnly);
|
||||
}
|
||||
} else if (onCancelCallback !== undefined) {
|
||||
if (typeof onCancelCallback === "function") {
|
||||
if (!internalOnly) {
|
||||
var e = tryCatch(onCancelCallback).call(this._boundValue());
|
||||
if (e === errorObj) {
|
||||
this._attachExtraTrace(e.e);
|
||||
async.throwLater(e.e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
onCancelCallback._resultCancelled(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._invokeOnCancel = function() {
|
||||
var onCancelCallback = this._onCancel();
|
||||
this._unsetOnCancel();
|
||||
async.invoke(this._doInvokeOnCancel, this, onCancelCallback);
|
||||
};
|
||||
|
||||
Promise.prototype._invokeInternalOnCancel = function() {
|
||||
if (this.isCancellable()) {
|
||||
this._doInvokeOnCancel(this._onCancel(), true);
|
||||
this._unsetOnCancel();
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._resultCancelled = function() {
|
||||
this.cancel();
|
||||
};
|
||||
|
||||
};
|
42
node_modules/bluebird/js/release/catch_filter.js
generated
vendored
Normal file
42
node_modules/bluebird/js/release/catch_filter.js
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
module.exports = function(NEXT_FILTER) {
|
||||
var util = require("./util");
|
||||
var getKeys = require("./es5").keys;
|
||||
var tryCatch = util.tryCatch;
|
||||
var errorObj = util.errorObj;
|
||||
|
||||
function catchFilter(instances, cb, promise) {
|
||||
return function(e) {
|
||||
var boundTo = promise._boundValue();
|
||||
predicateLoop: for (var i = 0; i < instances.length; ++i) {
|
||||
var item = instances[i];
|
||||
|
||||
if (item === Error ||
|
||||
(item != null && item.prototype instanceof Error)) {
|
||||
if (e instanceof item) {
|
||||
return tryCatch(cb).call(boundTo, e);
|
||||
}
|
||||
} else if (typeof item === "function") {
|
||||
var matchesPredicate = tryCatch(item).call(boundTo, e);
|
||||
if (matchesPredicate === errorObj) {
|
||||
return matchesPredicate;
|
||||
} else if (matchesPredicate) {
|
||||
return tryCatch(cb).call(boundTo, e);
|
||||
}
|
||||
} else if (util.isObject(e)) {
|
||||
var keys = getKeys(item);
|
||||
for (var j = 0; j < keys.length; ++j) {
|
||||
var key = keys[j];
|
||||
if (item[key] != e[key]) {
|
||||
continue predicateLoop;
|
||||
}
|
||||
}
|
||||
return tryCatch(cb).call(boundTo, e);
|
||||
}
|
||||
}
|
||||
return NEXT_FILTER;
|
||||
};
|
||||
}
|
||||
|
||||
return catchFilter;
|
||||
};
|
69
node_modules/bluebird/js/release/context.js
generated
vendored
Normal file
69
node_modules/bluebird/js/release/context.js
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise) {
|
||||
var longStackTraces = false;
|
||||
var contextStack = [];
|
||||
|
||||
Promise.prototype._promiseCreated = function() {};
|
||||
Promise.prototype._pushContext = function() {};
|
||||
Promise.prototype._popContext = function() {return null;};
|
||||
Promise._peekContext = Promise.prototype._peekContext = function() {};
|
||||
|
||||
function Context() {
|
||||
this._trace = new Context.CapturedTrace(peekContext());
|
||||
}
|
||||
Context.prototype._pushContext = function () {
|
||||
if (this._trace !== undefined) {
|
||||
this._trace._promiseCreated = null;
|
||||
contextStack.push(this._trace);
|
||||
}
|
||||
};
|
||||
|
||||
Context.prototype._popContext = function () {
|
||||
if (this._trace !== undefined) {
|
||||
var trace = contextStack.pop();
|
||||
var ret = trace._promiseCreated;
|
||||
trace._promiseCreated = null;
|
||||
return ret;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
function createContext() {
|
||||
if (longStackTraces) return new Context();
|
||||
}
|
||||
|
||||
function peekContext() {
|
||||
var lastIndex = contextStack.length - 1;
|
||||
if (lastIndex >= 0) {
|
||||
return contextStack[lastIndex];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
Context.CapturedTrace = null;
|
||||
Context.create = createContext;
|
||||
Context.deactivateLongStackTraces = function() {};
|
||||
Context.activateLongStackTraces = function() {
|
||||
var Promise_pushContext = Promise.prototype._pushContext;
|
||||
var Promise_popContext = Promise.prototype._popContext;
|
||||
var Promise_PeekContext = Promise._peekContext;
|
||||
var Promise_peekContext = Promise.prototype._peekContext;
|
||||
var Promise_promiseCreated = Promise.prototype._promiseCreated;
|
||||
Context.deactivateLongStackTraces = function() {
|
||||
Promise.prototype._pushContext = Promise_pushContext;
|
||||
Promise.prototype._popContext = Promise_popContext;
|
||||
Promise._peekContext = Promise_PeekContext;
|
||||
Promise.prototype._peekContext = Promise_peekContext;
|
||||
Promise.prototype._promiseCreated = Promise_promiseCreated;
|
||||
longStackTraces = false;
|
||||
};
|
||||
longStackTraces = true;
|
||||
Promise.prototype._pushContext = Context.prototype._pushContext;
|
||||
Promise.prototype._popContext = Context.prototype._popContext;
|
||||
Promise._peekContext = Promise.prototype._peekContext = peekContext;
|
||||
Promise.prototype._promiseCreated = function() {
|
||||
var ctx = this._peekContext();
|
||||
if (ctx && ctx._promiseCreated == null) ctx._promiseCreated = this;
|
||||
};
|
||||
};
|
||||
return Context;
|
||||
};
|
@ -1,95 +1,310 @@
|
||||
"use strict";
|
||||
module.exports = function() {
|
||||
var async = require("./async.js");
|
||||
var util = require("./util.js");
|
||||
module.exports = function(Promise, Context) {
|
||||
var getDomain = Promise._getDomain;
|
||||
var async = Promise._async;
|
||||
var Warning = require("./errors").Warning;
|
||||
var util = require("./util");
|
||||
var canAttachTrace = util.canAttachTrace;
|
||||
var unhandledRejectionHandled;
|
||||
var possiblyUnhandledRejection;
|
||||
var bluebirdFramePattern =
|
||||
/[\\\/]bluebird[\\\/]js[\\\/](main|debug|zalgo|instrumented)/;
|
||||
/[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/;
|
||||
var stackFramePattern = null;
|
||||
var formatStack = null;
|
||||
var indentStackFrames = false;
|
||||
var warn;
|
||||
var printWarning;
|
||||
var debugging = !!(util.env("BLUEBIRD_DEBUG") != 0 &&
|
||||
(false ||
|
||||
util.env("BLUEBIRD_DEBUG") ||
|
||||
util.env("NODE_ENV") === "development"));
|
||||
var warnings = !!(util.env("BLUEBIRD_WARNINGS") != 0 &&
|
||||
(debugging || util.env("BLUEBIRD_WARNINGS")));
|
||||
var longStackTraces = !!(util.env("BLUEBIRD_LONG_STACK_TRACES") != 0 &&
|
||||
(debugging || util.env("BLUEBIRD_LONG_STACK_TRACES")));
|
||||
|
||||
function CapturedTrace(parent) {
|
||||
this._parent = parent;
|
||||
var length = this._length = 1 + (parent === undefined ? 0 : parent._length);
|
||||
captureStackTrace(this, CapturedTrace);
|
||||
if (length > 32) this.uncycle();
|
||||
Promise.prototype.suppressUnhandledRejections = function() {
|
||||
var target = this._target();
|
||||
target._bitField = ((target._bitField & (~1048576)) |
|
||||
2097152);
|
||||
};
|
||||
|
||||
Promise.prototype._ensurePossibleRejectionHandled = function () {
|
||||
if ((this._bitField & 2097152) !== 0) return;
|
||||
this._setRejectionIsUnhandled();
|
||||
async.invokeLater(this._notifyUnhandledRejection, this, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
|
||||
fireRejectionEvent("rejectionHandled",
|
||||
unhandledRejectionHandled, undefined, this);
|
||||
};
|
||||
|
||||
Promise.prototype._notifyUnhandledRejection = function () {
|
||||
if (this._isRejectionUnhandled()) {
|
||||
var reason = this._settledValue();
|
||||
this._setUnhandledRejectionIsNotified();
|
||||
fireRejectionEvent("unhandledRejection",
|
||||
possiblyUnhandledRejection, reason, this);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._setUnhandledRejectionIsNotified = function () {
|
||||
this._bitField = this._bitField | 262144;
|
||||
};
|
||||
|
||||
Promise.prototype._unsetUnhandledRejectionIsNotified = function () {
|
||||
this._bitField = this._bitField & (~262144);
|
||||
};
|
||||
|
||||
Promise.prototype._isUnhandledRejectionNotified = function () {
|
||||
return (this._bitField & 262144) > 0;
|
||||
};
|
||||
|
||||
Promise.prototype._setRejectionIsUnhandled = function () {
|
||||
this._bitField = this._bitField | 1048576;
|
||||
};
|
||||
|
||||
Promise.prototype._unsetRejectionIsUnhandled = function () {
|
||||
this._bitField = this._bitField & (~1048576);
|
||||
if (this._isUnhandledRejectionNotified()) {
|
||||
this._unsetUnhandledRejectionIsNotified();
|
||||
this._notifyUnhandledRejectionIsHandled();
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._isRejectionUnhandled = function () {
|
||||
return (this._bitField & 1048576) > 0;
|
||||
};
|
||||
|
||||
Promise.prototype._warn = function(message, shouldUseOwnTrace, promise) {
|
||||
return warn(message, shouldUseOwnTrace, promise || this);
|
||||
};
|
||||
|
||||
Promise.onPossiblyUnhandledRejection = function (fn) {
|
||||
var domain = getDomain();
|
||||
possiblyUnhandledRejection =
|
||||
typeof fn === "function" ? (domain === null ? fn : domain.bind(fn))
|
||||
: undefined;
|
||||
};
|
||||
|
||||
Promise.onUnhandledRejectionHandled = function (fn) {
|
||||
var domain = getDomain();
|
||||
unhandledRejectionHandled =
|
||||
typeof fn === "function" ? (domain === null ? fn : domain.bind(fn))
|
||||
: undefined;
|
||||
};
|
||||
|
||||
var disableLongStackTraces = function() {};
|
||||
Promise.longStackTraces = function () {
|
||||
if (async.haveItemsQueued() && !config.longStackTraces) {
|
||||
throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
}
|
||||
if (!config.longStackTraces && longStackTracesIsSupported()) {
|
||||
var Promise_captureStackTrace = Promise.prototype._captureStackTrace;
|
||||
var Promise_attachExtraTrace = Promise.prototype._attachExtraTrace;
|
||||
config.longStackTraces = true;
|
||||
disableLongStackTraces = function() {
|
||||
if (async.haveItemsQueued() && !config.longStackTraces) {
|
||||
throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
}
|
||||
Promise.prototype._captureStackTrace = Promise_captureStackTrace;
|
||||
Promise.prototype._attachExtraTrace = Promise_attachExtraTrace;
|
||||
Context.deactivateLongStackTraces();
|
||||
async.enableTrampoline();
|
||||
config.longStackTraces = false;
|
||||
};
|
||||
Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace;
|
||||
Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace;
|
||||
Context.activateLongStackTraces();
|
||||
async.disableTrampolineIfNecessary();
|
||||
}
|
||||
};
|
||||
|
||||
Promise.hasLongStackTraces = function () {
|
||||
return config.longStackTraces && longStackTracesIsSupported();
|
||||
};
|
||||
|
||||
Promise.config = function(opts) {
|
||||
opts = Object(opts);
|
||||
if ("longStackTraces" in opts) {
|
||||
if (opts.longStackTraces) {
|
||||
Promise.longStackTraces();
|
||||
} else if (!opts.longStackTraces && Promise.hasLongStackTraces()) {
|
||||
disableLongStackTraces();
|
||||
}
|
||||
}
|
||||
if ("warnings" in opts) {
|
||||
config.warnings = !!opts.warnings;
|
||||
}
|
||||
if ("cancellation" in opts && opts.cancellation && !config.cancellation) {
|
||||
if (async.haveItemsQueued()) {
|
||||
throw new Error(
|
||||
"cannot enable cancellation after promises are in use");
|
||||
}
|
||||
Promise.prototype._clearCancellationData =
|
||||
cancellationClearCancellationData;
|
||||
Promise.prototype._propagateFrom = cancellationPropagateFrom;
|
||||
Promise.prototype._onCancel = cancellationOnCancel;
|
||||
Promise.prototype._setOnCancel = cancellationSetOnCancel;
|
||||
Promise.prototype._attachCancellationCallback =
|
||||
cancellationAttachCancellationCallback;
|
||||
Promise.prototype._execute = cancellationExecute;
|
||||
propagateFromFunction = cancellationPropagateFrom;
|
||||
config.cancellation = true;
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._execute = function(executor, resolve, reject) {
|
||||
try {
|
||||
executor(resolve, reject);
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
};
|
||||
Promise.prototype._onCancel = function () {};
|
||||
Promise.prototype._setOnCancel = function (handler) { ; };
|
||||
Promise.prototype._attachCancellationCallback = function(onCancel) {
|
||||
;
|
||||
};
|
||||
Promise.prototype._captureStackTrace = function () {};
|
||||
Promise.prototype._attachExtraTrace = function () {};
|
||||
Promise.prototype._clearCancellationData = function() {};
|
||||
Promise.prototype._propagateFrom = function (parent, flags) {
|
||||
;
|
||||
;
|
||||
};
|
||||
|
||||
function cancellationExecute(executor, resolve, reject) {
|
||||
var promise = this;
|
||||
try {
|
||||
executor(resolve, reject, function(onCancel) {
|
||||
if (typeof onCancel !== "function") {
|
||||
throw new TypeError("onCancel must be a function, got: " +
|
||||
util.toString(onCancel));
|
||||
}
|
||||
promise._attachCancellationCallback(onCancel);
|
||||
});
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
util.inherits(CapturedTrace, Error);
|
||||
|
||||
CapturedTrace.prototype.uncycle = function() {
|
||||
var length = this._length;
|
||||
if (length < 2) return;
|
||||
var nodes = [];
|
||||
var stackToIndex = {};
|
||||
function cancellationAttachCancellationCallback(onCancel) {
|
||||
if (!this.isCancellable()) return this;
|
||||
|
||||
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;
|
||||
var previousOnCancel = this._onCancel();
|
||||
if (previousOnCancel !== undefined) {
|
||||
if (util.isArray(previousOnCancel)) {
|
||||
previousOnCancel.push(onCancel);
|
||||
} else {
|
||||
this._setOnCancel([previousOnCancel, onCancel]);
|
||||
}
|
||||
} else {
|
||||
this._setOnCancel(onCancel);
|
||||
}
|
||||
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;
|
||||
function cancellationOnCancel() {
|
||||
return this._onCancelField;
|
||||
}
|
||||
|
||||
function cancellationSetOnCancel(onCancel) {
|
||||
this._onCancelField = onCancel;
|
||||
}
|
||||
|
||||
function cancellationClearCancellationData() {
|
||||
this._cancellationParent = undefined;
|
||||
this._onCancelField = undefined;
|
||||
}
|
||||
|
||||
function cancellationPropagateFrom(parent, flags) {
|
||||
if ((flags & 1) !== 0) {
|
||||
this._cancellationParent = parent;
|
||||
var branchesRemainingToCancel = parent._branchesRemainingToCancel;
|
||||
if (branchesRemainingToCancel === undefined) {
|
||||
branchesRemainingToCancel = 0;
|
||||
}
|
||||
parent._branchesRemainingToCancel = branchesRemainingToCancel + 1;
|
||||
}
|
||||
if ((flags & 2) !== 0 && parent._isBound()) {
|
||||
this._setBoundTo(parent._boundTo);
|
||||
}
|
||||
}
|
||||
|
||||
function bindingPropagateFrom(parent, flags) {
|
||||
if ((flags & 2) !== 0 && parent._isBound()) {
|
||||
this._setBoundTo(parent._boundTo);
|
||||
}
|
||||
}
|
||||
var propagateFromFunction = bindingPropagateFrom;
|
||||
|
||||
function boundValueFunction() {
|
||||
var ret = this._boundTo;
|
||||
if (ret !== undefined) {
|
||||
if (ret instanceof Promise) {
|
||||
if (ret.isFulfilled()) {
|
||||
return ret.value();
|
||||
} else {
|
||||
cycleEdgeNode._parent = undefined;
|
||||
cycleEdgeNode._length = 1;
|
||||
return undefined;
|
||||
}
|
||||
var currentChildLength = cycleEdgeNode._length + 1;
|
||||
for (var j = i - 2; j >= 0; --j) {
|
||||
nodes[j]._length = currentChildLength;
|
||||
currentChildLength++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
CapturedTrace.prototype.parent = function() {
|
||||
return this._parent;
|
||||
};
|
||||
function longStackTracesCaptureStackTrace() {
|
||||
this._trace = new CapturedTrace(this._peekContext());
|
||||
}
|
||||
|
||||
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;
|
||||
function longStackTracesAttachExtraTrace(error, ignoreSelf) {
|
||||
if (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 = parseStackAndMessage(error);
|
||||
util.notEnumerableProp(error, "stack",
|
||||
parsed.message + "\n" + parsed.stack.join("\n"));
|
||||
util.notEnumerableProp(error, "__stackCleaned__", true);
|
||||
}
|
||||
}
|
||||
removeCommonRoots(stacks);
|
||||
removeDuplicateOrEmptyJumps(stacks);
|
||||
util.notEnumerableProp(error, "stack", reconstructStack(message, stacks));
|
||||
util.notEnumerableProp(error, "__stackCleaned__", true);
|
||||
};
|
||||
}
|
||||
|
||||
function checkForgottenReturns(returnValue, promiseCreated, name, promise) {
|
||||
if (returnValue === undefined &&
|
||||
promiseCreated !== null &&
|
||||
config.longStackTraces &&
|
||||
config.warnings) {
|
||||
var msg = "a promise was created in a " + name +
|
||||
" handler but was not returned from it";
|
||||
promise._warn(msg, true, promiseCreated);
|
||||
}
|
||||
}
|
||||
|
||||
function deprecated(name, replacement) {
|
||||
var message = name +
|
||||
" is deprecated and will be removed in a future version.";
|
||||
if (replacement) message += " Use " + replacement + " instead.";
|
||||
return warn(message);
|
||||
}
|
||||
|
||||
function warn(message, shouldUseOwnTrace, promise) {
|
||||
if (!config.warnings) return;
|
||||
var warning = new Warning(message);
|
||||
var ctx;
|
||||
if (shouldUseOwnTrace) {
|
||||
promise._attachExtraTrace(warning);
|
||||
} else if (config.longStackTraces && (ctx = Promise._peekContext())) {
|
||||
ctx.attachExtraTrace(warning);
|
||||
} else {
|
||||
var parsed = parseStackAndMessage(warning);
|
||||
warning.stack = parsed.message + "\n" + parsed.stack.join("\n");
|
||||
}
|
||||
formatAndLogError(warning, "", true);
|
||||
}
|
||||
|
||||
function reconstructStack(message, stacks) {
|
||||
for (var i = 0; i < stacks.length - 1; ++i) {
|
||||
@ -144,8 +359,8 @@ 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 isTraceLine = " (No stack trace)" === line ||
|
||||
stackFramePattern.test(line);
|
||||
var isInternalFrame = isTraceLine && shouldIgnore(line);
|
||||
if (isTraceLine && !isInternalFrame) {
|
||||
if (indentStackFrames && line.charAt(0) !== " ") {
|
||||
@ -171,7 +386,7 @@ function stackFramesAsArray(error) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
CapturedTrace.parseStackAndMessage = function(error) {
|
||||
function parseStackAndMessage(error) {
|
||||
var stack = error.stack;
|
||||
var message = error.toString();
|
||||
stack = typeof stack === "string" && stack.length > 0
|
||||
@ -180,36 +395,27 @@ CapturedTrace.parseStackAndMessage = function(error) {
|
||||
message: message,
|
||||
stack: cleanStack(stack)
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
CapturedTrace.formatAndLogError = function(error, title) {
|
||||
function formatAndLogError(error, title, isSoft) {
|
||||
if (typeof console !== "undefined") {
|
||||
var message;
|
||||
if (typeof error === "object" || typeof error === "function") {
|
||||
if (util.isObject(error)) {
|
||||
var stack = error.stack;
|
||||
message = title + formatStack(stack, error);
|
||||
} else {
|
||||
message = title + String(error);
|
||||
}
|
||||
if (typeof warn === "function") {
|
||||
warn(message);
|
||||
if (typeof printWarning === "function") {
|
||||
printWarning(message, isSoft);
|
||||
} 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) {
|
||||
function fireRejectionEvent(name, localHandler, reason, promise) {
|
||||
var localEventFired = false;
|
||||
try {
|
||||
if (typeof localHandler === "function") {
|
||||
@ -247,9 +453,9 @@ function(name, localHandler, reason, promise) {
|
||||
|
||||
if (!globalEventFired && !localEventFired && !domEventFired &&
|
||||
name === "unhandledRejection") {
|
||||
CapturedTrace.formatAndLogError(reason, "Unhandled rejection ");
|
||||
formatAndLogError(reason, "Unhandled rejection ");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function formatNonError(obj) {
|
||||
var str;
|
||||
@ -258,7 +464,8 @@ function formatNonError(obj) {
|
||||
(obj.name || "anonymous") +
|
||||
"]";
|
||||
} else {
|
||||
str = obj.toString();
|
||||
str = obj && typeof obj.toString === "function"
|
||||
? obj.toString() : util.toString(obj);
|
||||
var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
|
||||
if (ruselessToString.test(str)) {
|
||||
try {
|
||||
@ -284,6 +491,10 @@ function snip(str) {
|
||||
return str.substr(0, maxChars - 3) + "...";
|
||||
}
|
||||
|
||||
function longStackTracesIsSupported() {
|
||||
return typeof captureStackTrace === "function";
|
||||
}
|
||||
|
||||
var shouldIgnore = function() { return false; };
|
||||
var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;
|
||||
function parseLineInfo(line) {
|
||||
@ -295,8 +506,9 @@ function parseLineInfo(line) {
|
||||
};
|
||||
}
|
||||
}
|
||||
CapturedTrace.setBounds = function(firstLineError, lastLineError) {
|
||||
if (!CapturedTrace.isSupported()) return;
|
||||
|
||||
function setBounds(firstLineError, lastLineError) {
|
||||
if (!longStackTracesIsSupported()) return;
|
||||
var firstStackLines = firstLineError.stack.split("\n");
|
||||
var lastStackLines = lastLineError.stack.split("\n");
|
||||
var firstIndex = -1;
|
||||
@ -335,6 +547,82 @@ CapturedTrace.setBounds = function(firstLineError, lastLineError) {
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
function CapturedTrace(parent) {
|
||||
this._parent = parent;
|
||||
this._promisesCreated = 0;
|
||||
var length = this._length = 1 + (parent === undefined ? 0 : parent._length);
|
||||
captureStackTrace(this, CapturedTrace);
|
||||
if (length > 32) this.uncycle();
|
||||
}
|
||||
util.inherits(CapturedTrace, Error);
|
||||
Context.CapturedTrace = CapturedTrace;
|
||||
|
||||
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.attachExtraTrace = function(error) {
|
||||
if (error.__stackCleaned__) return;
|
||||
this.uncycle();
|
||||
var parsed = 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);
|
||||
util.notEnumerableProp(error, "stack", reconstructStack(message, stacks));
|
||||
util.notEnumerableProp(error, "__stackCleaned__", true);
|
||||
};
|
||||
|
||||
var captureStackTrace = (function stackDetection() {
|
||||
@ -351,7 +639,7 @@ var captureStackTrace = (function stackDetection() {
|
||||
|
||||
if (typeof Error.stackTraceLimit === "number" &&
|
||||
typeof Error.captureStackTrace === "function") {
|
||||
Error.stackTraceLimit = Error.stackTraceLimit + 6;
|
||||
Error.stackTraceLimit += 6;
|
||||
stackFramePattern = v8stackFramePattern;
|
||||
formatStack = v8stackFormatter;
|
||||
var captureStackTrace = Error.captureStackTrace;
|
||||
@ -360,9 +648,9 @@ var captureStackTrace = (function stackDetection() {
|
||||
return bluebirdFramePattern.test(line);
|
||||
};
|
||||
return function(receiver, ignoreUntil) {
|
||||
Error.stackTraceLimit = Error.stackTraceLimit + 6;
|
||||
Error.stackTraceLimit += 6;
|
||||
captureStackTrace(receiver, ignoreUntil);
|
||||
Error.stackTraceLimit = Error.stackTraceLimit - 6;
|
||||
Error.stackTraceLimit -= 6;
|
||||
};
|
||||
}
|
||||
var err = new Error();
|
||||
@ -382,14 +670,15 @@ var captureStackTrace = (function stackDetection() {
|
||||
catch(e) {
|
||||
hasStackAfterThrow = ("stack" in e);
|
||||
}
|
||||
if (!("stack" in err) && hasStackAfterThrow) {
|
||||
if (!("stack" in err) && hasStackAfterThrow &&
|
||||
typeof Error.stackTraceLimit === "number") {
|
||||
stackFramePattern = v8stackFramePattern;
|
||||
formatStack = v8stackFormatter;
|
||||
return function captureStackTrace(o) {
|
||||
Error.stackTraceLimit = Error.stackTraceLimit + 6;
|
||||
Error.stackTraceLimit += 6;
|
||||
try { throw new Error(); }
|
||||
catch(e) { o.stack = e.stack; }
|
||||
Error.stackTraceLimit = Error.stackTraceLimit - 6;
|
||||
Error.stackTraceLimit -= 6;
|
||||
};
|
||||
}
|
||||
|
||||
@ -474,19 +763,50 @@ var fireGlobalEvent = (function() {
|
||||
})();
|
||||
|
||||
if (typeof console !== "undefined" && typeof console.warn !== "undefined") {
|
||||
warn = function (message) {
|
||||
printWarning = function (message) {
|
||||
console.warn(message);
|
||||
};
|
||||
if (util.isNode && process.stderr.isTTY) {
|
||||
warn = function(message) {
|
||||
process.stderr.write("\u001b[31m" + message + "\u001b[39m\n");
|
||||
printWarning = function(message, isSoft) {
|
||||
var color = isSoft ? "\u001b[33m" : "\u001b[31m";
|
||||
console.warn(color + message + "\u001b[0m\n");
|
||||
};
|
||||
} else if (!util.isNode && typeof (new Error().stack) === "string") {
|
||||
warn = function(message) {
|
||||
console.warn("%c" + message, "color: red");
|
||||
printWarning = function(message, isSoft) {
|
||||
console.warn("%c" + message,
|
||||
isSoft ? "color: darkorange" : "color: red");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return CapturedTrace;
|
||||
var config = {
|
||||
warnings: warnings,
|
||||
longStackTraces: false,
|
||||
cancellation: false
|
||||
};
|
||||
|
||||
if (longStackTraces) Promise.longStackTraces();
|
||||
|
||||
return {
|
||||
longStackTraces: function() {
|
||||
return config.longStackTraces;
|
||||
},
|
||||
warnings: function() {
|
||||
return config.warnings;
|
||||
},
|
||||
cancellation: function() {
|
||||
return config.cancellation;
|
||||
},
|
||||
propagateFromFunction: function() {
|
||||
return propagateFromFunction;
|
||||
},
|
||||
boundValueFunction: function() {
|
||||
return boundValueFunction;
|
||||
},
|
||||
checkForgottenReturns: checkForgottenReturns,
|
||||
setBounds: setBounds,
|
||||
warn: warn,
|
||||
deprecated: deprecated,
|
||||
CapturedTrace: CapturedTrace
|
||||
};
|
||||
};
|
46
node_modules/bluebird/js/release/direct_resolve.js
generated
vendored
Normal file
46
node_modules/bluebird/js/release/direct_resolve.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise) {
|
||||
function returner() {
|
||||
return this.value;
|
||||
}
|
||||
function thrower() {
|
||||
throw this.reason;
|
||||
}
|
||||
|
||||
Promise.prototype["return"] =
|
||||
Promise.prototype.thenReturn = function (value) {
|
||||
if (value instanceof Promise) value.suppressUnhandledRejections();
|
||||
return this._then(
|
||||
returner, undefined, undefined, {value: value}, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype["throw"] =
|
||||
Promise.prototype.thenThrow = function (reason) {
|
||||
return this._then(
|
||||
thrower, undefined, undefined, {reason: reason}, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype.catchThrow = function (reason) {
|
||||
if (arguments.length <= 1) {
|
||||
return this._then(
|
||||
undefined, thrower, undefined, {reason: reason}, undefined);
|
||||
} else {
|
||||
var _reason = arguments[1];
|
||||
var handler = function() {throw _reason;};
|
||||
return this.caught(reason, handler);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype.catchReturn = function (value) {
|
||||
if (arguments.length <= 1) {
|
||||
if (value instanceof Promise) value.suppressUnhandledRejections();
|
||||
return this._then(
|
||||
undefined, returner, undefined, {value: value}, undefined);
|
||||
} else {
|
||||
var _value = arguments[1];
|
||||
if (_value instanceof Promise) _value.suppressUnhandledRejections();
|
||||
var handler = function() {return _value;};
|
||||
return this.caught(value, handler);
|
||||
}
|
||||
};
|
||||
};
|
29
node_modules/bluebird/js/release/each.js
generated
vendored
Normal file
29
node_modules/bluebird/js/release/each.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, INTERNAL) {
|
||||
var PromiseReduce = Promise.reduce;
|
||||
var PromiseAll = Promise.all;
|
||||
|
||||
function promiseAllThis() {
|
||||
return PromiseAll(this);
|
||||
}
|
||||
|
||||
function PromiseMapSeries(promises, fn) {
|
||||
return PromiseReduce(promises, fn, INTERNAL, INTERNAL);
|
||||
}
|
||||
|
||||
Promise.prototype.each = function (fn) {
|
||||
return this.mapSeries(fn)
|
||||
._then(promiseAllThis, undefined, undefined, this, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype.mapSeries = function (fn) {
|
||||
return PromiseReduce(this, fn, INTERNAL, INTERNAL);
|
||||
};
|
||||
|
||||
Promise.each = function (promises, fn) {
|
||||
return PromiseMapSeries(promises, fn)
|
||||
._then(promiseAllThis, undefined, undefined, promises, undefined);
|
||||
};
|
||||
|
||||
Promise.mapSeries = PromiseMapSeries;
|
||||
};
|
4
node_modules/bluebird/js/main/errors.js → node_modules/bluebird/js/release/errors.js
generated
vendored
4
node_modules/bluebird/js/main/errors.js → node_modules/bluebird/js/release/errors.js
generated
vendored
@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
var es5 = require("./es5.js");
|
||||
var es5 = require("./es5");
|
||||
var Objectfreeze = es5.freeze;
|
||||
var util = require("./util.js");
|
||||
var util = require("./util");
|
||||
var inherits = util.inherits;
|
||||
var notEnumerableProp = util.notEnumerableProp;
|
||||
|
0
node_modules/bluebird/js/main/es5.js → node_modules/bluebird/js/release/es5.js
generated
vendored
0
node_modules/bluebird/js/main/es5.js → node_modules/bluebird/js/release/es5.js
generated
vendored
0
node_modules/bluebird/js/main/filter.js → node_modules/bluebird/js/release/filter.js
generated
vendored
0
node_modules/bluebird/js/main/filter.js → node_modules/bluebird/js/release/filter.js
generated
vendored
100
node_modules/bluebird/js/release/finally.js
generated
vendored
Normal file
100
node_modules/bluebird/js/release/finally.js
generated
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, tryConvertToPromise) {
|
||||
var util = require("./util");
|
||||
var CancellationError = Promise.CancellationError;
|
||||
var errorObj = util.errorObj;
|
||||
|
||||
function FinallyHandlerCancelReaction(finallyHandler) {
|
||||
this.finallyHandler = finallyHandler;
|
||||
}
|
||||
|
||||
FinallyHandlerCancelReaction.prototype._resultCancelled = function() {
|
||||
checkCancel(this.finallyHandler);
|
||||
};
|
||||
|
||||
function checkCancel(ctx, reason) {
|
||||
if (ctx.cancelPromise != null) {
|
||||
if (arguments.length > 1) {
|
||||
ctx.cancelPromise._reject(reason);
|
||||
} else {
|
||||
ctx.cancelPromise._cancel();
|
||||
}
|
||||
ctx.cancelPromise = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function succeed() {
|
||||
return finallyHandler.call(this, this.promise._target()._settledValue());
|
||||
}
|
||||
function fail(reason) {
|
||||
if (checkCancel(this, reason)) return;
|
||||
errorObj.e = reason;
|
||||
return errorObj;
|
||||
}
|
||||
function finallyHandler(reasonOrValue) {
|
||||
var promise = this.promise;
|
||||
var handler = this.handler;
|
||||
|
||||
if (!this.called) {
|
||||
this.called = true;
|
||||
var ret = this.type === 0
|
||||
? handler.call(promise._boundValue())
|
||||
: handler.call(promise._boundValue(), reasonOrValue);
|
||||
if (ret !== undefined) {
|
||||
var maybePromise = tryConvertToPromise(ret, promise);
|
||||
if (maybePromise instanceof Promise) {
|
||||
if (this.cancelPromise != null) {
|
||||
if (maybePromise.isCancelled()) {
|
||||
var reason =
|
||||
new CancellationError("late cancellation observer");
|
||||
promise._attachExtraTrace(reason);
|
||||
errorObj.e = reason;
|
||||
return errorObj;
|
||||
} else if (maybePromise.isPending()) {
|
||||
maybePromise._attachCancellationCallback(
|
||||
new FinallyHandlerCancelReaction(this));
|
||||
}
|
||||
}
|
||||
return maybePromise._then(
|
||||
succeed, fail, undefined, this, undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (promise.isRejected()) {
|
||||
checkCancel(this);
|
||||
errorObj.e = reasonOrValue;
|
||||
return errorObj;
|
||||
} else {
|
||||
checkCancel(this);
|
||||
return reasonOrValue;
|
||||
}
|
||||
}
|
||||
|
||||
Promise.prototype._passThrough = function(handler, type, success, fail) {
|
||||
if (typeof handler !== "function") return this.then();
|
||||
return this._then(success, fail, undefined, {
|
||||
promise: this,
|
||||
handler: handler,
|
||||
called: false,
|
||||
cancelPromise: null,
|
||||
type: type
|
||||
}, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype.lastly =
|
||||
Promise.prototype["finally"] = function (handler) {
|
||||
return this._passThrough(handler,
|
||||
0,
|
||||
finallyHandler,
|
||||
finallyHandler);
|
||||
};
|
||||
|
||||
Promise.prototype.tap = function (handler) {
|
||||
return this._passThrough(handler, 1, finallyHandler);
|
||||
};
|
||||
|
||||
return finallyHandler;
|
||||
};
|
140
node_modules/bluebird/js/main/generators.js → node_modules/bluebird/js/release/generators.js
generated
vendored
140
node_modules/bluebird/js/main/generators.js → node_modules/bluebird/js/release/generators.js
generated
vendored
@ -2,10 +2,12 @@
|
||||
module.exports = function(Promise,
|
||||
apiRejection,
|
||||
INTERNAL,
|
||||
tryConvertToPromise) {
|
||||
var errors = require("./errors.js");
|
||||
tryConvertToPromise,
|
||||
Proxyable,
|
||||
debug) {
|
||||
var errors = require("./errors");
|
||||
var TypeError = errors.TypeError;
|
||||
var util = require("./util.js");
|
||||
var util = require("./util");
|
||||
var errorObj = util.errorObj;
|
||||
var tryCatch = util.tryCatch;
|
||||
var yieldHandlers = [];
|
||||
@ -30,6 +32,7 @@ function promiseFromYieldHandler(value, yieldHandlers, traceParent) {
|
||||
function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) {
|
||||
var promise = this._promise = new Promise(INTERNAL);
|
||||
promise._captureStackTrace();
|
||||
promise._setOnCancel(this);
|
||||
this._stack = stack;
|
||||
this._generatorFunction = generatorFunction;
|
||||
this._receiver = receiver;
|
||||
@ -37,7 +40,75 @@ function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) {
|
||||
this._yieldHandlers = typeof yieldHandler === "function"
|
||||
? [yieldHandler].concat(yieldHandlers)
|
||||
: yieldHandlers;
|
||||
this._yieldedPromise = null;
|
||||
}
|
||||
util.inherits(PromiseSpawn, Proxyable);
|
||||
|
||||
PromiseSpawn.prototype._isResolved = function() {
|
||||
return this.promise === null;
|
||||
};
|
||||
|
||||
PromiseSpawn.prototype._cleanup = function() {
|
||||
this._promise = this._generator = null;
|
||||
};
|
||||
|
||||
PromiseSpawn.prototype._promiseCancelled = function() {
|
||||
if (this._isResolved()) return;
|
||||
var implementsReturn = typeof this._generator["return"] !== "undefined";
|
||||
|
||||
var result;
|
||||
if (!implementsReturn) {
|
||||
var reason = new Promise.CancellationError(
|
||||
"generator .return() sentinel");
|
||||
Promise.coroutine.returnSentinel = reason;
|
||||
this._promise._attachExtraTrace(reason);
|
||||
this._promise._pushContext();
|
||||
result = tryCatch(this._generator["throw"]).call(this._generator,
|
||||
reason);
|
||||
this._promise._popContext();
|
||||
if (result === errorObj && result.e === reason) {
|
||||
result = null;
|
||||
}
|
||||
} else {
|
||||
this._promise._pushContext();
|
||||
result = tryCatch(this._generator["return"]).call(this._generator,
|
||||
undefined);
|
||||
this._promise._popContext();
|
||||
}
|
||||
var promise = this._promise;
|
||||
this._cleanup();
|
||||
if (result === errorObj) {
|
||||
promise._rejectCallback(result.e, false);
|
||||
} else {
|
||||
promise.cancel();
|
||||
}
|
||||
};
|
||||
|
||||
PromiseSpawn.prototype._promiseFulfilled = function(value) {
|
||||
this._yieldedPromise = null;
|
||||
this._promise._pushContext();
|
||||
var result = tryCatch(this._generator.next).call(this._generator, value);
|
||||
this._promise._popContext();
|
||||
this._continue(result);
|
||||
};
|
||||
|
||||
PromiseSpawn.prototype._promiseRejected = function(reason) {
|
||||
this._yieldedPromise = null;
|
||||
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._resultCancelled = function() {
|
||||
if (this._yieldedPromise instanceof Promise) {
|
||||
var promise = this._yieldedPromise;
|
||||
this._yieldedPromise = null;
|
||||
promise.cancel();
|
||||
}
|
||||
};
|
||||
|
||||
PromiseSpawn.prototype.promise = function () {
|
||||
return this._promise;
|
||||
@ -47,17 +118,20 @@ PromiseSpawn.prototype._run = function () {
|
||||
this._generator = this._generatorFunction.call(this._receiver);
|
||||
this._receiver =
|
||||
this._generatorFunction = undefined;
|
||||
this._next(undefined);
|
||||
this._promiseFulfilled(undefined);
|
||||
};
|
||||
|
||||
PromiseSpawn.prototype._continue = function (result) {
|
||||
var promise = this._promise;
|
||||
if (result === errorObj) {
|
||||
return this._promise._rejectCallback(result.e, false, true);
|
||||
this._cleanup();
|
||||
return promise._rejectCallback(result.e, false);
|
||||
}
|
||||
|
||||
var value = result.value;
|
||||
if (result.done === true) {
|
||||
this._promise._resolveCallback(value);
|
||||
this._cleanup();
|
||||
return promise._resolveCallback(value);
|
||||
} else {
|
||||
var maybePromise = tryConvertToPromise(value, this._promise);
|
||||
if (!(maybePromise instanceof Promise)) {
|
||||
@ -66,9 +140,9 @@ PromiseSpawn.prototype._continue = function (result) {
|
||||
this._yieldHandlers,
|
||||
this._promise);
|
||||
if (maybePromise === null) {
|
||||
this._throw(
|
||||
this._promiseRejected(
|
||||
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) +
|
||||
"A value %s was yielded that could not be treated as a promise\u000a\u000a See http://goo.gl/MqrFmX\u000a\u000a".replace("%s", value) +
|
||||
"From coroutine:\u000a" +
|
||||
this._stack.split("\n").slice(1, -7).join("\n")
|
||||
)
|
||||
@ -76,35 +150,25 @@ PromiseSpawn.prototype._continue = function (result) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
maybePromise._then(
|
||||
this._next,
|
||||
this._throw,
|
||||
undefined,
|
||||
this,
|
||||
null
|
||||
);
|
||||
maybePromise = maybePromise._target();
|
||||
var bitField = maybePromise._bitField;
|
||||
;
|
||||
if (((bitField & 50397184) === 0)) {
|
||||
this._yieldedPromise = maybePromise;
|
||||
maybePromise._proxy(this, null);
|
||||
} else if (((bitField & 33554432) !== 0)) {
|
||||
this._promiseFulfilled(maybePromise._value());
|
||||
} else if (((bitField & 16777216) !== 0)) {
|
||||
this._promiseRejected(maybePromise._reason());
|
||||
} else {
|
||||
this._promiseCancelled();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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 (value) {
|
||||
this._promise._pushContext();
|
||||
var result = tryCatch(this._generator.next).call(this._generator, value);
|
||||
this._promise._popContext();
|
||||
this._continue(result);
|
||||
};
|
||||
|
||||
Promise.coroutine = function (generatorFunction, options) {
|
||||
if (typeof generatorFunction !== "function") {
|
||||
throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/6Vqhm0\u000a");
|
||||
throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
}
|
||||
var yieldHandler = Object(options).yieldHandler;
|
||||
var PromiseSpawn$ = PromiseSpawn;
|
||||
@ -113,20 +177,24 @@ Promise.coroutine = function (generatorFunction, options) {
|
||||
var generator = generatorFunction.apply(this, arguments);
|
||||
var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler,
|
||||
stack);
|
||||
var ret = spawn.promise();
|
||||
spawn._generator = generator;
|
||||
spawn._next(undefined);
|
||||
return spawn.promise();
|
||||
spawn._promiseFulfilled(undefined);
|
||||
return ret;
|
||||
};
|
||||
};
|
||||
|
||||
Promise.coroutine.addYieldHandler = function(fn) {
|
||||
if (typeof fn !== "function") throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
|
||||
if (typeof fn !== "function") {
|
||||
throw new TypeError("expecting a function but got " + util.classString(fn));
|
||||
}
|
||||
yieldHandlers.push(fn);
|
||||
};
|
||||
|
||||
Promise.spawn = function (generatorFunction) {
|
||||
debug.deprecated("Promise.spawn()", "Promise.coroutine()");
|
||||
if (typeof generatorFunction !== "function") {
|
||||
return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/6Vqhm0\u000a");
|
||||
return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
}
|
||||
var spawn = new PromiseSpawn(generatorFunction, this);
|
||||
var ret = spawn.promise();
|
149
node_modules/bluebird/js/release/join.js
generated
vendored
Normal file
149
node_modules/bluebird/js/release/join.js
generated
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
"use strict";
|
||||
module.exports =
|
||||
function(Promise, PromiseArray, tryConvertToPromise, INTERNAL) {
|
||||
var util = require("./util");
|
||||
var canEvaluate = util.canEvaluate;
|
||||
var tryCatch = util.tryCatch;
|
||||
var errorObj = util.errorObj;
|
||||
var reject;
|
||||
|
||||
if (!false) {
|
||||
if (canEvaluate) {
|
||||
var thenCallback = function(i) {
|
||||
return new Function("value", "holder", " \n\
|
||||
'use strict'; \n\
|
||||
holder.pIndex = value; \n\
|
||||
holder.checkFulfillment(this); \n\
|
||||
".replace(/Index/g, i));
|
||||
};
|
||||
|
||||
var promiseSetter = function(i) {
|
||||
return new Function("promise", "holder", " \n\
|
||||
'use strict'; \n\
|
||||
holder.pIndex = promise; \n\
|
||||
".replace(/Index/g, i));
|
||||
};
|
||||
|
||||
var generateHolderClass = function(total) {
|
||||
var props = new Array(total);
|
||||
for (var i = 0; i < props.length; ++i) {
|
||||
props[i] = "this.p" + (i+1);
|
||||
}
|
||||
var assignment = props.join(" = ") + " = null;";
|
||||
var cancellationCode= "var promise;\n" + props.map(function(prop) {
|
||||
return " \n\
|
||||
promise = " + prop + "; \n\
|
||||
if (promise instanceof Promise) { \n\
|
||||
promise.cancel(); \n\
|
||||
} \n\
|
||||
";
|
||||
}).join("\n");
|
||||
var passedArguments = props.join(", ");
|
||||
var name = "Holder$" + total;
|
||||
|
||||
|
||||
var code = "return function(tryCatch, errorObj, Promise) { \n\
|
||||
'use strict'; \n\
|
||||
function [TheName](fn) { \n\
|
||||
[TheProperties] \n\
|
||||
this.fn = fn; \n\
|
||||
this.now = 0; \n\
|
||||
} \n\
|
||||
[TheName].prototype.checkFulfillment = function(promise) { \n\
|
||||
var now = ++this.now; \n\
|
||||
if (now === [TheTotal]) { \n\
|
||||
promise._pushContext(); \n\
|
||||
var callback = this.fn; \n\
|
||||
var ret = tryCatch(callback)([ThePassedArguments]); \n\
|
||||
promise._popContext(); \n\
|
||||
if (ret === errorObj) { \n\
|
||||
promise._rejectCallback(ret.e, false); \n\
|
||||
} else { \n\
|
||||
promise._resolveCallback(ret); \n\
|
||||
} \n\
|
||||
} \n\
|
||||
}; \n\
|
||||
\n\
|
||||
[TheName].prototype._resultCancelled = function() { \n\
|
||||
[CancellationCode] \n\
|
||||
}; \n\
|
||||
\n\
|
||||
return [TheName]; \n\
|
||||
}(tryCatch, errorObj, Promise); \n\
|
||||
";
|
||||
|
||||
code = code.replace(/\[TheName\]/g, name)
|
||||
.replace(/\[TheTotal\]/g, total)
|
||||
.replace(/\[ThePassedArguments\]/g, passedArguments)
|
||||
.replace(/\[TheProperties\]/g, assignment)
|
||||
.replace(/\[CancellationCode\]/g, cancellationCode);
|
||||
|
||||
return new Function("tryCatch", "errorObj", "Promise", code)
|
||||
(tryCatch, errorObj, Promise);
|
||||
};
|
||||
|
||||
var holderClasses = [];
|
||||
var thenCallbacks = [];
|
||||
var promiseSetters = [];
|
||||
|
||||
for (var i = 0; i < 8; ++i) {
|
||||
holderClasses.push(generateHolderClass(i + 1));
|
||||
thenCallbacks.push(thenCallback(i + 1));
|
||||
promiseSetters.push(promiseSetter(i + 1));
|
||||
}
|
||||
|
||||
reject = function (reason) {
|
||||
this._reject(reason);
|
||||
};
|
||||
}}
|
||||
|
||||
Promise.join = function () {
|
||||
var last = arguments.length - 1;
|
||||
var fn;
|
||||
if (last > 0 && typeof arguments[last] === "function") {
|
||||
fn = arguments[last];
|
||||
if (!false) {
|
||||
if (last <= 8 && canEvaluate) {
|
||||
var ret = new Promise(INTERNAL);
|
||||
ret._captureStackTrace();
|
||||
var HolderClass = holderClasses[last - 1];
|
||||
var holder = new HolderClass(fn);
|
||||
var callbacks = thenCallbacks;
|
||||
|
||||
for (var i = 0; i < last; ++i) {
|
||||
var maybePromise = tryConvertToPromise(arguments[i], ret);
|
||||
if (maybePromise instanceof Promise) {
|
||||
maybePromise = maybePromise._target();
|
||||
var bitField = maybePromise._bitField;
|
||||
;
|
||||
if (((bitField & 50397184) === 0)) {
|
||||
maybePromise._then(callbacks[i], reject,
|
||||
undefined, ret, holder);
|
||||
promiseSetters[i](maybePromise, holder);
|
||||
} else if (((bitField & 33554432) !== 0)) {
|
||||
callbacks[i].call(ret,
|
||||
maybePromise._value(), holder);
|
||||
} else if (((bitField & 16777216) !== 0)) {
|
||||
ret._reject(maybePromise._reason());
|
||||
} else {
|
||||
ret._cancel();
|
||||
}
|
||||
} else {
|
||||
callbacks[i].call(ret, maybePromise, holder);
|
||||
}
|
||||
}
|
||||
if (!ret._isFateSealed()) {
|
||||
ret._setAsyncGuaranteed();
|
||||
ret._setOnCancel(holder);
|
||||
}
|
||||
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 !== undefined ? ret.spread(fn) : ret;
|
||||
};
|
||||
|
||||
};
|
72
node_modules/bluebird/js/main/map.js → node_modules/bluebird/js/release/map.js
generated
vendored
72
node_modules/bluebird/js/main/map.js → node_modules/bluebird/js/release/map.js
generated
vendored
@ -3,28 +3,28 @@ module.exports = function(Promise,
|
||||
PromiseArray,
|
||||
apiRejection,
|
||||
tryConvertToPromise,
|
||||
INTERNAL) {
|
||||
var async = require("./async.js");
|
||||
var util = require("./util.js");
|
||||
INTERNAL,
|
||||
debug) {
|
||||
var getDomain = Promise._getDomain;
|
||||
var util = require("./util");
|
||||
var tryCatch = util.tryCatch;
|
||||
var errorObj = util.errorObj;
|
||||
var PENDING = {};
|
||||
var EMPTY_ARRAY = [];
|
||||
|
||||
function MappingPromiseArray(promises, fn, limit, _filter) {
|
||||
this.constructor$(promises);
|
||||
this._promise._captureStackTrace();
|
||||
this._callback = fn;
|
||||
var domain = getDomain();
|
||||
this._callback = domain === null ? fn : domain.bind(fn);
|
||||
this._preservedValues = _filter === INTERNAL
|
||||
? new Array(this.length())
|
||||
: null;
|
||||
this._limit = limit;
|
||||
this._inFlight = 0;
|
||||
this._queue = limit >= 1 ? [] : EMPTY_ARRAY;
|
||||
async.invoke(init, this, undefined);
|
||||
this._init$(undefined, -2);
|
||||
}
|
||||
util.inherits(MappingPromiseArray, PromiseArray);
|
||||
function init() {this._init$(undefined, -2);}
|
||||
|
||||
MappingPromiseArray.prototype._init = function () {};
|
||||
|
||||
@ -33,39 +33,58 @@ MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
|
||||
var length = this.length();
|
||||
var preservedValues = this._preservedValues;
|
||||
var limit = this._limit;
|
||||
if (values[index] === PENDING) {
|
||||
|
||||
if (index < 0) {
|
||||
index = (index * -1) - 1;
|
||||
values[index] = value;
|
||||
if (limit >= 1) {
|
||||
this._inFlight--;
|
||||
this._drainQueue();
|
||||
if (this._isResolved()) return;
|
||||
if (this._isResolved()) return true;
|
||||
}
|
||||
} else {
|
||||
if (limit >= 1 && this._inFlight >= limit) {
|
||||
values[index] = value;
|
||||
this._queue.push(index);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (preservedValues !== null) preservedValues[index] = value;
|
||||
|
||||
var promise = this._promise;
|
||||
var callback = this._callback;
|
||||
var receiver = this._promise._boundTo;
|
||||
this._promise._pushContext();
|
||||
var receiver = promise._boundValue();
|
||||
promise._pushContext();
|
||||
var ret = tryCatch(callback).call(receiver, value, index, length);
|
||||
this._promise._popContext();
|
||||
if (ret === errorObj) return this._reject(ret.e);
|
||||
var promiseCreated = promise._popContext();
|
||||
debug.checkForgottenReturns(
|
||||
ret,
|
||||
promiseCreated,
|
||||
preservedValues !== null ? "Promise.filter" : "Promise.map",
|
||||
promise
|
||||
);
|
||||
if (ret === errorObj) {
|
||||
this._reject(ret.e);
|
||||
return true;
|
||||
}
|
||||
|
||||
var maybePromise = tryConvertToPromise(ret, this._promise);
|
||||
if (maybePromise instanceof Promise) {
|
||||
maybePromise = maybePromise._target();
|
||||
if (maybePromise._isPending()) {
|
||||
var bitField = maybePromise._bitField;
|
||||
;
|
||||
if (((bitField & 50397184) === 0)) {
|
||||
if (limit >= 1) this._inFlight++;
|
||||
values[index] = PENDING;
|
||||
return maybePromise._proxyPromiseArray(this, index);
|
||||
} else if (maybePromise._isFulfilled()) {
|
||||
values[index] = maybePromise;
|
||||
maybePromise._proxy(this, (index + 1) * -1);
|
||||
return false;
|
||||
} else if (((bitField & 33554432) !== 0)) {
|
||||
ret = maybePromise._value();
|
||||
} else if (((bitField & 16777216) !== 0)) {
|
||||
this._reject(maybePromise._reason());
|
||||
return true;
|
||||
} else {
|
||||
return this._reject(maybePromise._reason());
|
||||
this._cancel();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
values[index] = ret;
|
||||
@ -77,8 +96,9 @@ MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
|
||||
} else {
|
||||
this._resolve(values);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
MappingPromiseArray.prototype._drainQueue = function () {
|
||||
@ -108,23 +128,23 @@ MappingPromiseArray.prototype.preservedValues = function () {
|
||||
};
|
||||
|
||||
function map(promises, fn, options, _filter) {
|
||||
if (typeof fn !== "function") {
|
||||
return apiRejection("expecting a function but got " + util.classString(fn));
|
||||
}
|
||||
var limit = typeof options === "object" && options !== null
|
||||
? options.concurrency
|
||||
: 0;
|
||||
limit = typeof limit === "number" &&
|
||||
isFinite(limit) && limit >= 1 ? limit : 0;
|
||||
return new MappingPromiseArray(promises, fn, limit, _filter);
|
||||
return new MappingPromiseArray(promises, fn, limit, _filter).promise();
|
||||
}
|
||||
|
||||
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();
|
||||
return map(this, fn, options, null);
|
||||
};
|
||||
|
||||
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();
|
||||
return map(promises, fn, options, _filter);
|
||||
};
|
||||
|
||||
|
55
node_modules/bluebird/js/release/method.js
generated
vendored
Normal file
55
node_modules/bluebird/js/release/method.js
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
module.exports =
|
||||
function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) {
|
||||
var util = require("./util");
|
||||
var tryCatch = util.tryCatch;
|
||||
|
||||
Promise.method = function (fn) {
|
||||
if (typeof fn !== "function") {
|
||||
throw new Promise.TypeError("expecting a function but got " + util.classString(fn));
|
||||
}
|
||||
return function () {
|
||||
var ret = new Promise(INTERNAL);
|
||||
ret._captureStackTrace();
|
||||
ret._pushContext();
|
||||
var value = tryCatch(fn).apply(this, arguments);
|
||||
var promiseCreated = ret._popContext();
|
||||
debug.checkForgottenReturns(
|
||||
value, promiseCreated, "Promise.method", ret);
|
||||
ret._resolveFromSyncValue(value);
|
||||
return ret;
|
||||
};
|
||||
};
|
||||
|
||||
Promise.attempt = Promise["try"] = function (fn) {
|
||||
if (typeof fn !== "function") {
|
||||
return apiRejection("expecting a function but got " + util.classString(fn));
|
||||
}
|
||||
var ret = new Promise(INTERNAL);
|
||||
ret._captureStackTrace();
|
||||
ret._pushContext();
|
||||
var value;
|
||||
if (arguments.length > 1) {
|
||||
debug.deprecated("calling Promise.try with more than 1 argument");
|
||||
var arg = arguments[1];
|
||||
var ctx = arguments[2];
|
||||
value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg)
|
||||
: tryCatch(fn).call(ctx, arg);
|
||||
} else {
|
||||
value = tryCatch(fn)();
|
||||
}
|
||||
var promiseCreated = ret._popContext();
|
||||
debug.checkForgottenReturns(
|
||||
value, promiseCreated, "Promise.try", ret);
|
||||
ret._resolveFromSyncValue(value);
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.prototype._resolveFromSyncValue = function (value) {
|
||||
if (value === util.errorObj) {
|
||||
this._rejectCallback(value.e, false);
|
||||
} else {
|
||||
this._resolveCallback(value, true);
|
||||
}
|
||||
};
|
||||
};
|
51
node_modules/bluebird/js/release/nodeback.js
generated
vendored
Normal file
51
node_modules/bluebird/js/release/nodeback.js
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
var util = require("./util");
|
||||
var maybeWrapAsError = util.maybeWrapAsError;
|
||||
var errors = require("./errors");
|
||||
var OperationalError = errors.OperationalError;
|
||||
var es5 = require("./es5");
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
util.markAsOriginatingFromRejection(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
function nodebackForPromise(promise, multiArgs) {
|
||||
return function(err, value) {
|
||||
if (promise === null) return;
|
||||
if (err) {
|
||||
var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
|
||||
promise._attachExtraTrace(wrapped);
|
||||
promise._reject(wrapped);
|
||||
} else if (!multiArgs) {
|
||||
promise._fulfill(value);
|
||||
} else {
|
||||
var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];};
|
||||
promise._fulfill(args);
|
||||
}
|
||||
promise = null;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = nodebackForPromise;
|
18
node_modules/bluebird/js/main/nodeify.js → node_modules/bluebird/js/release/nodeify.js
generated
vendored
18
node_modules/bluebird/js/main/nodeify.js → node_modules/bluebird/js/release/nodeify.js
generated
vendored
@ -1,14 +1,15 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise) {
|
||||
var util = require("./util.js");
|
||||
var async = require("./async.js");
|
||||
var util = require("./util");
|
||||
var async = Promise._async;
|
||||
var tryCatch = util.tryCatch;
|
||||
var errorObj = util.errorObj;
|
||||
|
||||
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));
|
||||
var ret =
|
||||
tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val));
|
||||
if (ret === errorObj) {
|
||||
async.throwLater(ret.e);
|
||||
}
|
||||
@ -16,7 +17,7 @@ function spreadAdapter(val, nodeback) {
|
||||
|
||||
function successAdapter(val, nodeback) {
|
||||
var promise = this;
|
||||
var receiver = promise._boundTo;
|
||||
var receiver = promise._boundValue();
|
||||
var ret = val === undefined
|
||||
? tryCatch(nodeback).call(receiver, null)
|
||||
: tryCatch(nodeback).call(receiver, null, val);
|
||||
@ -27,19 +28,18 @@ function successAdapter(val, nodeback) {
|
||||
function errorAdapter(reason, nodeback) {
|
||||
var promise = this;
|
||||
if (!reason) {
|
||||
var target = promise._target();
|
||||
var newReason = target._getCarriedStackTrace();
|
||||
var newReason = new Error(reason + "");
|
||||
newReason.cause = reason;
|
||||
reason = newReason;
|
||||
}
|
||||
var ret = tryCatch(nodeback).call(promise._boundTo, reason);
|
||||
var ret = tryCatch(nodeback).call(promise._boundValue(), reason);
|
||||
if (ret === errorObj) {
|
||||
async.throwLater(ret.e);
|
||||
}
|
||||
}
|
||||
|
||||
Promise.prototype.asCallback =
|
||||
Promise.prototype.nodeify = function (nodeback, options) {
|
||||
Promise.prototype.asCallback = Promise.prototype.nodeify = function (nodeback,
|
||||
options) {
|
||||
if (typeof nodeback == "function") {
|
||||
var adapter = successAdapter;
|
||||
if (options !== undefined && Object(options).spread) {
|
755
node_modules/bluebird/js/release/promise.js
generated
vendored
Normal file
755
node_modules/bluebird/js/release/promise.js
generated
vendored
Normal file
@ -0,0 +1,755 @@
|
||||
"use strict";
|
||||
module.exports = function() {
|
||||
var makeSelfResolutionError = function () {
|
||||
return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
};
|
||||
var reflectHandler = function() {
|
||||
return new Promise.PromiseInspection(this._target());
|
||||
};
|
||||
var apiRejection = function(msg) {
|
||||
return Promise.reject(new TypeError(msg));
|
||||
};
|
||||
function Proxyable() {}
|
||||
var UNDEFINED_BINDING = {};
|
||||
var util = require("./util");
|
||||
|
||||
var getDomain;
|
||||
if (util.isNode) {
|
||||
getDomain = function() {
|
||||
var ret = process.domain;
|
||||
if (ret === undefined) ret = null;
|
||||
return ret;
|
||||
};
|
||||
} else {
|
||||
getDomain = function() {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
util.notEnumerableProp(Promise, "_getDomain", getDomain);
|
||||
|
||||
var es5 = require("./es5");
|
||||
var Async = require("./async");
|
||||
var async = new Async();
|
||||
es5.defineProperty(Promise, "_async", {value: async});
|
||||
var errors = require("./errors");
|
||||
var TypeError = Promise.TypeError = errors.TypeError;
|
||||
Promise.RangeError = errors.RangeError;
|
||||
var CancellationError = 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 = {};
|
||||
var tryConvertToPromise = require("./thenables")(Promise, INTERNAL);
|
||||
var PromiseArray =
|
||||
require("./promise_array")(Promise, INTERNAL,
|
||||
tryConvertToPromise, apiRejection, Proxyable);
|
||||
var Context = require("./context")(Promise);
|
||||
/*jshint unused:false*/
|
||||
var createContext = Context.create;
|
||||
var debug = require("./debuggability")(Promise, Context);
|
||||
var CapturedTrace = debug.CapturedTrace;
|
||||
var finallyHandler = require("./finally")(Promise, tryConvertToPromise);
|
||||
var catchFilter = require("./catch_filter")(NEXT_FILTER);
|
||||
var nodebackForPromise = require("./nodeback");
|
||||
var errorObj = util.errorObj;
|
||||
var tryCatch = util.tryCatch;
|
||||
function check(self, executor) {
|
||||
if (typeof executor !== "function") {
|
||||
throw new TypeError("expecting a function but got " + util.classString(executor));
|
||||
}
|
||||
if (self.constructor !== Promise) {
|
||||
throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
}
|
||||
}
|
||||
|
||||
function Promise(executor) {
|
||||
this._bitField = 0;
|
||||
this._fulfillmentHandler0 = undefined;
|
||||
this._rejectionHandler0 = undefined;
|
||||
this._promise0 = undefined;
|
||||
this._receiver0 = undefined;
|
||||
if (executor !== INTERNAL) {
|
||||
check(this, executor);
|
||||
this._resolveFromExecutor(executor);
|
||||
}
|
||||
this._promiseCreated();
|
||||
}
|
||||
|
||||
Promise.prototype.toString = function () {
|
||||
return "[object Promise]";
|
||||
};
|
||||
|
||||
Promise.prototype.caught = Promise.prototype["catch"] = function (fn) {
|
||||
var len = arguments.length;
|
||||
if (len > 1) {
|
||||
var catchInstances = new Array(len - 1),
|
||||
j = 0, i;
|
||||
for (i = 0; i < len - 1; ++i) {
|
||||
var item = arguments[i];
|
||||
if (util.isObject(item)) {
|
||||
catchInstances[j++] = item;
|
||||
} else {
|
||||
return apiRejection("expecting an object but got " + util.classString(item));
|
||||
}
|
||||
}
|
||||
catchInstances.length = j;
|
||||
fn = arguments[i];
|
||||
return this.then(undefined, catchFilter(catchInstances, fn, this));
|
||||
}
|
||||
return this.then(undefined, fn);
|
||||
};
|
||||
|
||||
Promise.prototype.reflect = function () {
|
||||
return this._then(reflectHandler,
|
||||
reflectHandler, undefined, this, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype.then = function (didFulfill, didReject) {
|
||||
if (debug.warnings() && arguments.length > 0 &&
|
||||
typeof didFulfill !== "function" &&
|
||||
typeof didReject !== "function") {
|
||||
var msg = ".then() only accepts functions but was passed: " +
|
||||
util.classString(didFulfill);
|
||||
if (arguments.length > 1) {
|
||||
msg += ", " + util.classString(didReject);
|
||||
}
|
||||
this._warn(msg);
|
||||
}
|
||||
return this._then(didFulfill, didReject, undefined, undefined, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype.done = function (didFulfill, didReject) {
|
||||
var promise =
|
||||
this._then(didFulfill, didReject, undefined, undefined, undefined);
|
||||
promise._setIsFinal();
|
||||
};
|
||||
|
||||
Promise.prototype.spread = function (fn) {
|
||||
if (typeof fn !== "function") {
|
||||
return apiRejection("expecting a function but got " + util.classString(fn));
|
||||
}
|
||||
return this.all()._then(fn, undefined, undefined, APPLY, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype.toJSON = function () {
|
||||
var ret = {
|
||||
isFulfilled: false,
|
||||
isRejected: false,
|
||||
fulfillmentValue: undefined,
|
||||
rejectionReason: undefined
|
||||
};
|
||||
if (this.isFulfilled()) {
|
||||
ret.fulfillmentValue = this.value();
|
||||
ret.isFulfilled = true;
|
||||
} else if (this.isRejected()) {
|
||||
ret.rejectionReason = this.reason();
|
||||
ret.isRejected = true;
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.prototype.all = function () {
|
||||
if (arguments.length > 0) {
|
||||
this._warn(".all() was passed arguments but it does not take any");
|
||||
}
|
||||
return new PromiseArray(this).promise();
|
||||
};
|
||||
|
||||
Promise.prototype.error = function (fn) {
|
||||
return this.caught(util.originatesFromRejection, fn);
|
||||
};
|
||||
|
||||
Promise.is = function (val) {
|
||||
return val instanceof Promise;
|
||||
};
|
||||
|
||||
Promise.fromNode = Promise.fromCallback = function(fn) {
|
||||
var ret = new Promise(INTERNAL);
|
||||
var multiArgs = arguments.length > 1 ? !!Object(arguments[1]).multiArgs
|
||||
: false;
|
||||
var result = tryCatch(fn)(nodebackForPromise(ret, multiArgs));
|
||||
if (result === errorObj) {
|
||||
ret._rejectCallback(result.e, true);
|
||||
}
|
||||
if (!ret._isFateSealed()) ret._setAsyncGuaranteed();
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.all = function (promises) {
|
||||
return new PromiseArray(promises).promise();
|
||||
};
|
||||
|
||||
Promise.cast = function (obj) {
|
||||
var ret = tryConvertToPromise(obj);
|
||||
if (!(ret instanceof Promise)) {
|
||||
ret = new Promise(INTERNAL);
|
||||
ret._captureStackTrace();
|
||||
ret._setFulfilled();
|
||||
ret._rejectionHandler0 = obj;
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.resolve = Promise.fulfilled = Promise.cast;
|
||||
|
||||
Promise.reject = Promise.rejected = function (reason) {
|
||||
var ret = new Promise(INTERNAL);
|
||||
ret._captureStackTrace();
|
||||
ret._rejectCallback(reason, true);
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.setScheduler = function(fn) {
|
||||
if (typeof fn !== "function") {
|
||||
throw new TypeError("expecting a function but got " + util.classString(fn));
|
||||
}
|
||||
var prev = async._schedule;
|
||||
async._schedule = fn;
|
||||
return prev;
|
||||
};
|
||||
|
||||
Promise.prototype._then = function (
|
||||
didFulfill,
|
||||
didReject,
|
||||
_, receiver,
|
||||
internalData
|
||||
) {
|
||||
var haveInternalData = internalData !== undefined;
|
||||
var promise = haveInternalData ? internalData : new Promise(INTERNAL);
|
||||
var target = this._target();
|
||||
var bitField = target._bitField;
|
||||
|
||||
if (!haveInternalData) {
|
||||
promise._propagateFrom(this, 3);
|
||||
promise._captureStackTrace();
|
||||
if (receiver === undefined &&
|
||||
((this._bitField & 2097152) !== 0)) {
|
||||
if (!((bitField & 50397184) === 0)) {
|
||||
receiver = this._boundValue();
|
||||
} else {
|
||||
receiver = target === this ? undefined : this._boundTo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var domain = getDomain();
|
||||
if (!((bitField & 50397184) === 0)) {
|
||||
var handler, value, settler = target._settlePromiseCtx;
|
||||
if (((bitField & 33554432) !== 0)) {
|
||||
value = target._rejectionHandler0;
|
||||
handler = didFulfill;
|
||||
} else if (((bitField & 16777216) !== 0)) {
|
||||
value = target._fulfillmentHandler0;
|
||||
handler = didReject;
|
||||
target._unsetRejectionIsUnhandled();
|
||||
} else {
|
||||
settler = target._settlePromiseLateCancellationObserver;
|
||||
value = new CancellationError("late cancellation observer");
|
||||
target._attachExtraTrace(value);
|
||||
handler = didReject;
|
||||
}
|
||||
|
||||
async.invoke(settler, target, {
|
||||
handler: domain === null ? handler
|
||||
: (typeof handler === "function" && domain.bind(handler)),
|
||||
promise: promise,
|
||||
receiver: receiver,
|
||||
value: value
|
||||
});
|
||||
} else {
|
||||
target._addCallbacks(didFulfill, didReject, promise, receiver, domain);
|
||||
}
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
Promise.prototype._length = function () {
|
||||
return this._bitField & 65535;
|
||||
};
|
||||
|
||||
Promise.prototype._isFateSealed = function () {
|
||||
return (this._bitField & 117506048) !== 0;
|
||||
};
|
||||
|
||||
Promise.prototype._isFollowing = function () {
|
||||
return (this._bitField & 67108864) === 67108864;
|
||||
};
|
||||
|
||||
Promise.prototype._setLength = function (len) {
|
||||
this._bitField = (this._bitField & -65536) |
|
||||
(len & 65535);
|
||||
};
|
||||
|
||||
Promise.prototype._setFulfilled = function () {
|
||||
this._bitField = this._bitField | 33554432;
|
||||
};
|
||||
|
||||
Promise.prototype._setRejected = function () {
|
||||
this._bitField = this._bitField | 16777216;
|
||||
};
|
||||
|
||||
Promise.prototype._setFollowing = function () {
|
||||
this._bitField = this._bitField | 67108864;
|
||||
};
|
||||
|
||||
Promise.prototype._setIsFinal = function () {
|
||||
this._bitField = this._bitField | 4194304;
|
||||
};
|
||||
|
||||
Promise.prototype._isFinal = function () {
|
||||
return (this._bitField & 4194304) > 0;
|
||||
};
|
||||
|
||||
Promise.prototype._unsetCancelled = function() {
|
||||
this._bitField = this._bitField & (~65536);
|
||||
};
|
||||
|
||||
Promise.prototype._setCancelled = function() {
|
||||
this._bitField = this._bitField | 65536;
|
||||
};
|
||||
|
||||
Promise.prototype._setAsyncGuaranteed = function() {
|
||||
this._bitField = this._bitField | 134217728;
|
||||
};
|
||||
|
||||
Promise.prototype._receiverAt = function (index) {
|
||||
var ret = index === 0 ? this._receiver0 : this[
|
||||
index * 4 - 4 + 3];
|
||||
if (ret === UNDEFINED_BINDING) {
|
||||
return undefined;
|
||||
} else if (ret === undefined && this._isBound()) {
|
||||
return this._boundValue();
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.prototype._promiseAt = function (index) {
|
||||
return this[
|
||||
index * 4 - 4 + 2];
|
||||
};
|
||||
|
||||
Promise.prototype._fulfillmentHandlerAt = function (index) {
|
||||
return this[
|
||||
index * 4 - 4 + 0];
|
||||
};
|
||||
|
||||
Promise.prototype._rejectionHandlerAt = function (index) {
|
||||
return this[
|
||||
index * 4 - 4 + 1];
|
||||
};
|
||||
|
||||
Promise.prototype._boundValue = function() {};
|
||||
|
||||
Promise.prototype._migrateCallback0 = function (follower) {
|
||||
var bitField = follower._bitField;
|
||||
var fulfill = follower._fulfillmentHandler0;
|
||||
var reject = follower._rejectionHandler0;
|
||||
var promise = follower._promise0;
|
||||
var receiver = follower._receiverAt(0);
|
||||
if (receiver === undefined) receiver = UNDEFINED_BINDING;
|
||||
this._addCallbacks(fulfill, reject, promise, receiver, null);
|
||||
};
|
||||
|
||||
Promise.prototype._migrateCallbackAt = function (follower, index) {
|
||||
var fulfill = follower._fulfillmentHandlerAt(index);
|
||||
var reject = follower._rejectionHandlerAt(index);
|
||||
var promise = follower._promiseAt(index);
|
||||
var receiver = follower._receiverAt(index);
|
||||
if (receiver === undefined) receiver = UNDEFINED_BINDING;
|
||||
this._addCallbacks(fulfill, reject, promise, receiver, null);
|
||||
};
|
||||
|
||||
Promise.prototype._addCallbacks = function (
|
||||
fulfill,
|
||||
reject,
|
||||
promise,
|
||||
receiver,
|
||||
domain
|
||||
) {
|
||||
var index = this._length();
|
||||
|
||||
if (index >= 65535 - 4) {
|
||||
index = 0;
|
||||
this._setLength(0);
|
||||
}
|
||||
|
||||
if (index === 0) {
|
||||
this._promise0 = promise;
|
||||
this._receiver0 = receiver;
|
||||
if (typeof fulfill === "function") {
|
||||
this._fulfillmentHandler0 =
|
||||
domain === null ? fulfill : domain.bind(fulfill);
|
||||
}
|
||||
if (typeof reject === "function") {
|
||||
this._rejectionHandler0 =
|
||||
domain === null ? reject : domain.bind(reject);
|
||||
}
|
||||
} else {
|
||||
var base = index * 4 - 4;
|
||||
this[base + 2] = promise;
|
||||
this[base + 3] = receiver;
|
||||
if (typeof fulfill === "function") {
|
||||
this[base + 0] =
|
||||
domain === null ? fulfill : domain.bind(fulfill);
|
||||
}
|
||||
if (typeof reject === "function") {
|
||||
this[base + 1] =
|
||||
domain === null ? reject : domain.bind(reject);
|
||||
}
|
||||
}
|
||||
this._setLength(index + 1);
|
||||
return index;
|
||||
};
|
||||
|
||||
Promise.prototype._proxy = function (proxyable, arg) {
|
||||
this._addCallbacks(undefined, undefined, arg, proxyable, null);
|
||||
};
|
||||
|
||||
Promise.prototype._resolveCallback = function(value, shouldBind) {
|
||||
if (((this._bitField & 117506048) !== 0)) return;
|
||||
if (value === this)
|
||||
return this._rejectCallback(makeSelfResolutionError(), false);
|
||||
var maybePromise = tryConvertToPromise(value, this);
|
||||
if (!(maybePromise instanceof Promise)) return this._fulfill(value);
|
||||
|
||||
if (shouldBind) this._propagateFrom(maybePromise, 2);
|
||||
|
||||
var promise = maybePromise._target();
|
||||
var bitField = promise._bitField;
|
||||
if (((bitField & 50397184) === 0)) {
|
||||
var len = this._length();
|
||||
if (len > 0) promise._migrateCallback0(this);
|
||||
for (var i = 1; i < len; ++i) {
|
||||
promise._migrateCallbackAt(this, i);
|
||||
}
|
||||
this._setFollowing();
|
||||
this._setLength(0);
|
||||
this._setFollowee(promise);
|
||||
} else if (((bitField & 33554432) !== 0)) {
|
||||
this._fulfill(promise._value());
|
||||
} else if (((bitField & 16777216) !== 0)) {
|
||||
this._reject(promise._reason());
|
||||
} else {
|
||||
var reason = new CancellationError("late cancellation observer");
|
||||
promise._attachExtraTrace(reason);
|
||||
this._reject(reason);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._rejectCallback =
|
||||
function(reason, synchronous, ignoreNonErrorWarnings) {
|
||||
var trace = util.ensureErrorObject(reason);
|
||||
var hasStack = trace === reason;
|
||||
if (!hasStack && !ignoreNonErrorWarnings && debug.warnings()) {
|
||||
var message = "a promise was rejected with a non-error: " +
|
||||
util.classString(reason);
|
||||
this._warn(message, true);
|
||||
}
|
||||
this._attachExtraTrace(trace, synchronous ? hasStack : false);
|
||||
this._reject(reason);
|
||||
};
|
||||
|
||||
Promise.prototype._resolveFromExecutor = function (executor) {
|
||||
var promise = this;
|
||||
this._captureStackTrace();
|
||||
this._pushContext();
|
||||
var synchronous = true;
|
||||
var r = this._execute(executor, function(value) {
|
||||
promise._resolveCallback(value);
|
||||
}, function (reason) {
|
||||
promise._rejectCallback(reason, synchronous);
|
||||
});
|
||||
synchronous = false;
|
||||
this._popContext();
|
||||
|
||||
if (r !== undefined) {
|
||||
promise._rejectCallback(r, true);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._settlePromiseFromHandler = function (
|
||||
handler, receiver, value, promise
|
||||
) {
|
||||
var bitField = promise._bitField;
|
||||
if (((bitField & 65536) !== 0)) return;
|
||||
promise._pushContext();
|
||||
var x;
|
||||
if (receiver === APPLY) {
|
||||
if (!value || typeof value.length !== "number") {
|
||||
x = errorObj;
|
||||
x.e = new TypeError("cannot .spread() a non-array: " +
|
||||
util.classString(value));
|
||||
} else {
|
||||
x = tryCatch(handler).apply(this._boundValue(), value);
|
||||
}
|
||||
} else {
|
||||
x = tryCatch(handler).call(receiver, value);
|
||||
}
|
||||
var promiseCreated = promise._popContext();
|
||||
bitField = promise._bitField;
|
||||
if (((bitField & 65536) !== 0)) return;
|
||||
|
||||
if (x === NEXT_FILTER) {
|
||||
promise._reject(value);
|
||||
} else if (x === errorObj || x === promise) {
|
||||
var err = x === promise ? makeSelfResolutionError() : x.e;
|
||||
promise._rejectCallback(err, false);
|
||||
} else {
|
||||
debug.checkForgottenReturns(x, promiseCreated, "", promise);
|
||||
promise._resolveCallback(x);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._target = function() {
|
||||
var ret = this;
|
||||
while (ret._isFollowing()) ret = ret._followee();
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.prototype._followee = function() {
|
||||
return this._rejectionHandler0;
|
||||
};
|
||||
|
||||
Promise.prototype._setFollowee = function(promise) {
|
||||
this._rejectionHandler0 = promise;
|
||||
};
|
||||
|
||||
Promise.prototype._settlePromise = function(promise, handler, receiver, value) {
|
||||
var isPromise = promise instanceof Promise;
|
||||
var bitField = this._bitField;
|
||||
var asyncGuaranteed = ((bitField & 134217728) !== 0);
|
||||
if (((bitField & 65536) !== 0)) {
|
||||
if (isPromise) promise._invokeInternalOnCancel();
|
||||
|
||||
if (handler === finallyHandler) {
|
||||
receiver.cancelPromise = promise;
|
||||
if (tryCatch(handler).call(receiver, value) === errorObj) {
|
||||
promise._reject(errorObj.e);
|
||||
}
|
||||
} else if (handler === reflectHandler) {
|
||||
promise._fulfill(reflectHandler.call(receiver));
|
||||
} else if (receiver instanceof Proxyable) {
|
||||
receiver._promiseCancelled(promise);
|
||||
} else if (isPromise || promise instanceof PromiseArray) {
|
||||
promise._cancel();
|
||||
} else {
|
||||
receiver.cancel();
|
||||
}
|
||||
} else if (typeof handler === "function") {
|
||||
if (!isPromise) {
|
||||
handler.call(receiver, value, promise);
|
||||
} else {
|
||||
if (asyncGuaranteed) promise._setAsyncGuaranteed();
|
||||
this._settlePromiseFromHandler(handler, receiver, value, promise);
|
||||
}
|
||||
} else if (receiver instanceof Proxyable) {
|
||||
if (!receiver._isResolved()) {
|
||||
if (((bitField & 33554432) !== 0)) {
|
||||
receiver._promiseFulfilled(value, promise);
|
||||
} else {
|
||||
receiver._promiseRejected(value, promise);
|
||||
}
|
||||
}
|
||||
} else if (isPromise) {
|
||||
if (asyncGuaranteed) promise._setAsyncGuaranteed();
|
||||
if (((bitField & 33554432) !== 0)) {
|
||||
promise._fulfill(value);
|
||||
} else {
|
||||
promise._reject(value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._settlePromiseLateCancellationObserver = function(ctx) {
|
||||
var handler = ctx.handler;
|
||||
var promise = ctx.promise;
|
||||
var receiver = ctx.receiver;
|
||||
var value = ctx.value;
|
||||
if (typeof handler === "function") {
|
||||
if (!(promise instanceof Promise)) {
|
||||
handler.call(receiver, value, promise);
|
||||
} else {
|
||||
this._settlePromiseFromHandler(handler, receiver, value, promise);
|
||||
}
|
||||
} else if (promise instanceof Promise) {
|
||||
promise._reject(value);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._settlePromiseCtx = function(ctx) {
|
||||
this._settlePromise(ctx.promise, ctx.handler, ctx.receiver, ctx.value);
|
||||
};
|
||||
|
||||
Promise.prototype._settlePromise0 = function(handler, value, bitField) {
|
||||
var promise = this._promise0;
|
||||
var receiver = this._receiverAt(0);
|
||||
this._promise0 = undefined;
|
||||
this._receiver0 = undefined;
|
||||
this._settlePromise(promise, handler, receiver, value);
|
||||
};
|
||||
|
||||
Promise.prototype._clearCallbackDataAtIndex = function(index) {
|
||||
var base = index * 4 - 4;
|
||||
this[base + 2] =
|
||||
this[base + 3] =
|
||||
this[base + 0] =
|
||||
this[base + 1] = undefined;
|
||||
};
|
||||
|
||||
Promise.prototype._fulfill = function (value) {
|
||||
var bitField = this._bitField;
|
||||
if (((bitField & 117506048) >>> 16)) return;
|
||||
if (value === this) {
|
||||
var err = makeSelfResolutionError();
|
||||
this._attachExtraTrace(err);
|
||||
return this._reject(err);
|
||||
}
|
||||
this._setFulfilled();
|
||||
this._rejectionHandler0 = value;
|
||||
|
||||
if ((bitField & 65535) > 0) {
|
||||
if (((bitField & 134217728) !== 0)) {
|
||||
this._settlePromises();
|
||||
} else {
|
||||
async.settlePromises(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._reject = function (reason) {
|
||||
var bitField = this._bitField;
|
||||
if (((bitField & 117506048) >>> 16)) return;
|
||||
this._setRejected();
|
||||
this._fulfillmentHandler0 = reason;
|
||||
|
||||
if (this._isFinal()) {
|
||||
return async.fatalError(reason, util.isNode);
|
||||
}
|
||||
|
||||
if ((bitField & 65535) > 0) {
|
||||
if (((bitField & 134217728) !== 0)) {
|
||||
this._settlePromises();
|
||||
} else {
|
||||
async.settlePromises(this);
|
||||
}
|
||||
} else {
|
||||
this._ensurePossibleRejectionHandled();
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._fulfillPromises = function (len, value) {
|
||||
for (var i = 1; i < len; i++) {
|
||||
var handler = this._fulfillmentHandlerAt(i);
|
||||
var promise = this._promiseAt(i);
|
||||
var receiver = this._receiverAt(i);
|
||||
this._clearCallbackDataAtIndex(i);
|
||||
this._settlePromise(promise, handler, receiver, value);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._rejectPromises = function (len, reason) {
|
||||
for (var i = 1; i < len; i++) {
|
||||
var handler = this._rejectionHandlerAt(i);
|
||||
var promise = this._promiseAt(i);
|
||||
var receiver = this._receiverAt(i);
|
||||
this._clearCallbackDataAtIndex(i);
|
||||
this._settlePromise(promise, handler, receiver, reason);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype._settlePromises = function () {
|
||||
var bitField = this._bitField;
|
||||
var len = (bitField & 65535);
|
||||
|
||||
if (len > 0) {
|
||||
if (((bitField & 16842752) !== 0)) {
|
||||
var reason = this._fulfillmentHandler0;
|
||||
this._settlePromise0(this._rejectionHandler0, reason, bitField);
|
||||
this._rejectPromises(len, reason);
|
||||
} else {
|
||||
var value = this._rejectionHandler0;
|
||||
this._settlePromise0(this._fulfillmentHandler0, value, bitField);
|
||||
this._fulfillPromises(len, value);
|
||||
}
|
||||
this._setLength(0);
|
||||
}
|
||||
this._clearCancellationData();
|
||||
};
|
||||
|
||||
Promise.prototype._settledValue = function() {
|
||||
var bitField = this._bitField;
|
||||
if (((bitField & 33554432) !== 0)) {
|
||||
return this._rejectionHandler0;
|
||||
} else if (((bitField & 16777216) !== 0)) {
|
||||
return this._fulfillmentHandler0;
|
||||
}
|
||||
};
|
||||
|
||||
function deferResolve(v) {this.promise._resolveCallback(v);}
|
||||
function deferReject(v) {this.promise._rejectCallback(v, false);}
|
||||
|
||||
Promise.defer = Promise.pending = function() {
|
||||
debug.deprecated("Promise.defer", "new Promise");
|
||||
var promise = new Promise(INTERNAL);
|
||||
return {
|
||||
promise: promise,
|
||||
resolve: deferResolve,
|
||||
reject: deferReject
|
||||
};
|
||||
};
|
||||
|
||||
util.notEnumerableProp(Promise,
|
||||
"_makeSelfResolutionError",
|
||||
makeSelfResolutionError);
|
||||
|
||||
require("./method")(Promise, INTERNAL, tryConvertToPromise, apiRejection,
|
||||
debug);
|
||||
require("./bind")(Promise, INTERNAL, tryConvertToPromise, debug);
|
||||
require("./cancel")(Promise, PromiseArray, apiRejection, debug);
|
||||
require("./direct_resolve")(Promise);
|
||||
require("./synchronous_inspection")(Promise);
|
||||
require("./join")(
|
||||
Promise, PromiseArray, tryConvertToPromise, INTERNAL, debug);
|
||||
Promise.Promise = Promise;
|
||||
require('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
|
||||
require('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug);
|
||||
require('./timers.js')(Promise, INTERNAL);
|
||||
require('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise, Proxyable, debug);
|
||||
require('./nodeify.js')(Promise);
|
||||
require('./call_get.js')(Promise);
|
||||
require('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection);
|
||||
require('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection);
|
||||
require('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
|
||||
require('./settle.js')(Promise, PromiseArray, debug);
|
||||
require('./some.js')(Promise, PromiseArray, apiRejection);
|
||||
require('./promisify.js')(Promise, INTERNAL);
|
||||
require('./any.js')(Promise);
|
||||
require('./each.js')(Promise, INTERNAL);
|
||||
require('./filter.js')(Promise, INTERNAL);
|
||||
|
||||
util.toFastProperties(Promise);
|
||||
util.toFastProperties(Promise.prototype);
|
||||
function fillTypes(value) {
|
||||
var p = new Promise(INTERNAL);
|
||||
p._fulfillmentHandler0 = value;
|
||||
p._rejectionHandler0 = value;
|
||||
p._promise0 = value;
|
||||
p._receiver0 = value;
|
||||
}
|
||||
// Complete slack tracking, opt out of field-type tracking and
|
||||
// stabilize map
|
||||
fillTypes({a: 1});
|
||||
fillTypes({b: 2});
|
||||
fillTypes({c: 3});
|
||||
fillTypes(1);
|
||||
fillTypes(function(){});
|
||||
fillTypes(undefined);
|
||||
fillTypes(false);
|
||||
fillTypes(new Promise(INTERNAL));
|
||||
debug.setBounds(Async.firstLineError, util.lastLineError);
|
||||
return Promise;
|
||||
|
||||
};
|
184
node_modules/bluebird/js/release/promise_array.js
generated
vendored
Normal file
184
node_modules/bluebird/js/release/promise_array.js
generated
vendored
Normal file
@ -0,0 +1,184 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, INTERNAL, tryConvertToPromise,
|
||||
apiRejection, Proxyable) {
|
||||
var util = require("./util");
|
||||
var isArray = util.isArray;
|
||||
|
||||
function toResolutionValue(val) {
|
||||
switch(val) {
|
||||
case -2: return [];
|
||||
case -3: return {};
|
||||
}
|
||||
}
|
||||
|
||||
function PromiseArray(values) {
|
||||
var promise = this._promise = new Promise(INTERNAL);
|
||||
if (values instanceof Promise) {
|
||||
promise._propagateFrom(values, 3);
|
||||
}
|
||||
promise._setOnCancel(this);
|
||||
this._values = values;
|
||||
this._length = 0;
|
||||
this._totalResolved = 0;
|
||||
this._init(undefined, -2);
|
||||
}
|
||||
util.inherits(PromiseArray, Proxyable);
|
||||
|
||||
PromiseArray.prototype.length = function () {
|
||||
return this._length;
|
||||
};
|
||||
|
||||
PromiseArray.prototype.promise = function () {
|
||||
return this._promise;
|
||||
};
|
||||
|
||||
PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
|
||||
var values = tryConvertToPromise(this._values, this._promise);
|
||||
if (values instanceof Promise) {
|
||||
values = values._target();
|
||||
var bitField = values._bitField;
|
||||
;
|
||||
this._values = values;
|
||||
|
||||
if (((bitField & 50397184) === 0)) {
|
||||
this._promise._setAsyncGuaranteed();
|
||||
return values._then(
|
||||
init,
|
||||
this._reject,
|
||||
undefined,
|
||||
this,
|
||||
resolveValueIfEmpty
|
||||
);
|
||||
} else if (((bitField & 33554432) !== 0)) {
|
||||
values = values._value();
|
||||
} else if (((bitField & 16777216) !== 0)) {
|
||||
return this._reject(values._reason());
|
||||
} else {
|
||||
return this._cancel();
|
||||
}
|
||||
}
|
||||
values = util.asArray(values);
|
||||
if (values === null) {
|
||||
var err = apiRejection(
|
||||
"expecting an array or an iterable object but got " + util.classString(values)).reason();
|
||||
this._promise._rejectCallback(err, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (values.length === 0) {
|
||||
if (resolveValueIfEmpty === -5) {
|
||||
this._resolveEmptyArray();
|
||||
}
|
||||
else {
|
||||
this._resolve(toResolutionValue(resolveValueIfEmpty));
|
||||
}
|
||||
return;
|
||||
}
|
||||
this._iterate(values);
|
||||
};
|
||||
|
||||
PromiseArray.prototype._iterate = function(values) {
|
||||
var len = this.getActualLength(values.length);
|
||||
this._length = len;
|
||||
this._values = this.shouldCopyValues() ? new Array(len) : this._values;
|
||||
var result = this._promise;
|
||||
var isResolved = false;
|
||||
var bitField = null;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var maybePromise = tryConvertToPromise(values[i], result);
|
||||
|
||||
if (maybePromise instanceof Promise) {
|
||||
maybePromise = maybePromise._target();
|
||||
bitField = maybePromise._bitField;
|
||||
} else {
|
||||
bitField = null;
|
||||
}
|
||||
|
||||
if (isResolved) {
|
||||
if (bitField !== null) {
|
||||
maybePromise.suppressUnhandledRejections();
|
||||
}
|
||||
} else if (bitField !== null) {
|
||||
if (((bitField & 50397184) === 0)) {
|
||||
maybePromise._proxy(this, i);
|
||||
this._values[i] = maybePromise;
|
||||
} else if (((bitField & 33554432) !== 0)) {
|
||||
isResolved = this._promiseFulfilled(maybePromise._value(), i);
|
||||
} else if (((bitField & 16777216) !== 0)) {
|
||||
isResolved = this._promiseRejected(maybePromise._reason(), i);
|
||||
} else {
|
||||
isResolved = this._promiseCancelled(i);
|
||||
}
|
||||
} else {
|
||||
isResolved = this._promiseFulfilled(maybePromise, i);
|
||||
}
|
||||
}
|
||||
if (!isResolved) result._setAsyncGuaranteed();
|
||||
};
|
||||
|
||||
PromiseArray.prototype._isResolved = function () {
|
||||
return this._values === null;
|
||||
};
|
||||
|
||||
PromiseArray.prototype._resolve = function (value) {
|
||||
this._values = null;
|
||||
this._promise._fulfill(value);
|
||||
};
|
||||
|
||||
PromiseArray.prototype._cancel = function() {
|
||||
if (this._isResolved() || !this._promise.isCancellable()) return;
|
||||
this._values = null;
|
||||
this._promise._cancel();
|
||||
};
|
||||
|
||||
PromiseArray.prototype._reject = function (reason) {
|
||||
this._values = null;
|
||||
this._promise._rejectCallback(reason, false);
|
||||
};
|
||||
|
||||
PromiseArray.prototype._promiseFulfilled = function (value, index) {
|
||||
this._values[index] = value;
|
||||
var totalResolved = ++this._totalResolved;
|
||||
if (totalResolved >= this._length) {
|
||||
this._resolve(this._values);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
PromiseArray.prototype._promiseCancelled = function() {
|
||||
this._cancel();
|
||||
return true;
|
||||
};
|
||||
|
||||
PromiseArray.prototype._promiseRejected = function (reason) {
|
||||
this._totalResolved++;
|
||||
this._reject(reason);
|
||||
return true;
|
||||
};
|
||||
|
||||
PromiseArray.prototype._resultCancelled = function() {
|
||||
if (this._isResolved()) return;
|
||||
var values = this._values;
|
||||
this._cancel();
|
||||
if (values instanceof Promise) {
|
||||
values.cancel();
|
||||
} else {
|
||||
for (var i = 0; i < values.length; ++i) {
|
||||
if (values[i] instanceof Promise) {
|
||||
values[i].cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PromiseArray.prototype.shouldCopyValues = function () {
|
||||
return true;
|
||||
};
|
||||
|
||||
PromiseArray.prototype.getActualLength = function (len) {
|
||||
return len;
|
||||
};
|
||||
|
||||
return PromiseArray;
|
||||
};
|
131
node_modules/bluebird/js/main/promisify.js → node_modules/bluebird/js/release/promisify.js
generated
vendored
131
node_modules/bluebird/js/main/promisify.js → node_modules/bluebird/js/release/promisify.js
generated
vendored
@ -1,21 +1,29 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, INTERNAL) {
|
||||
var THIS = {};
|
||||
var util = require("./util.js");
|
||||
var nodebackForPromise = require("./promise_resolver.js")
|
||||
._nodebackForPromise;
|
||||
var util = require("./util");
|
||||
var nodebackForPromise = require("./nodeback");
|
||||
var withAppended = util.withAppended;
|
||||
var maybeWrapAsError = util.maybeWrapAsError;
|
||||
var canEvaluate = util.canEvaluate;
|
||||
var TypeError = require("./errors").TypeError;
|
||||
var defaultSuffix = "Async";
|
||||
var defaultPromisified = {__isPromisified__: true};
|
||||
var noCopyPropsPattern =
|
||||
/^(?:length|name|arguments|caller|callee|prototype|__isPromisified__)$/;
|
||||
var defaultFilter = function(name, func) {
|
||||
var noCopyProps = [
|
||||
"arity", "length",
|
||||
"name",
|
||||
"arguments",
|
||||
"caller",
|
||||
"callee",
|
||||
"prototype",
|
||||
"__isPromisified__"
|
||||
];
|
||||
var noCopyPropsPattern = new RegExp("^(?:" + noCopyProps.join("|") + ")$");
|
||||
|
||||
var defaultFilter = function(name) {
|
||||
return util.isIdentifier(name) &&
|
||||
name.charAt(0) !== "_" &&
|
||||
!util.isClass(func);
|
||||
name !== "constructor";
|
||||
};
|
||||
|
||||
function propsFilter(key) {
|
||||
@ -43,7 +51,7 @@ 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 '%s'-suffix\u000a\u000a See http://goo.gl/iWrZbw\u000a"
|
||||
throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\u000a\u000a See http://goo.gl/MqrFmX\u000a"
|
||||
.replace("%s", suffix));
|
||||
}
|
||||
}
|
||||
@ -105,7 +113,7 @@ var parameterCount = function(fn) {
|
||||
};
|
||||
|
||||
makeNodePromisifiedEval =
|
||||
function(callback, receiver, originalName, fn) {
|
||||
function(callback, receiver, originalName, fn, _, multiArgs) {
|
||||
var newParameterCount = Math.max(0, parameterCount(fn) - 1);
|
||||
var argumentOrder = switchCaseArgumentOrder(newParameterCount);
|
||||
var shouldProxyThis = typeof callback === "string" || receiver === THIS;
|
||||
@ -150,22 +158,13 @@ function(callback, receiver, originalName, fn) {
|
||||
var getFunctionCode = typeof callback === "string"
|
||||
? ("this != null ? this['"+callback+"'] : fn")
|
||||
: "fn";
|
||||
|
||||
return new Function("Promise",
|
||||
"fn",
|
||||
"receiver",
|
||||
"withAppended",
|
||||
"maybeWrapAsError",
|
||||
"nodebackForPromise",
|
||||
"tryCatch",
|
||||
"errorObj",
|
||||
"INTERNAL","'use strict'; \n\
|
||||
var body = "'use strict'; \n\
|
||||
var ret = function (Parameters) { \n\
|
||||
'use strict'; \n\
|
||||
var len = arguments.length; \n\
|
||||
var promise = new Promise(INTERNAL); \n\
|
||||
promise._captureStackTrace(); \n\
|
||||
var nodeback = nodebackForPromise(promise); \n\
|
||||
var nodeback = nodebackForPromise(promise, " + multiArgs + "); \n\
|
||||
var ret; \n\
|
||||
var callback = tryCatch([GetFunctionCode]); \n\
|
||||
switch(len) { \n\
|
||||
@ -174,28 +173,39 @@ function(callback, receiver, originalName, fn) {
|
||||
if (ret === errorObj) { \n\
|
||||
promise._rejectCallback(maybeWrapAsError(ret.e), true, true);\n\
|
||||
} \n\
|
||||
if (!promise._isFateSealed()) promise._setAsyncGuaranteed(); \n\
|
||||
return promise; \n\
|
||||
}; \n\
|
||||
ret.__isPromisified__ = true; \n\
|
||||
notEnumerableProp(ret, '__isPromisified__', true); \n\
|
||||
return ret; \n\
|
||||
"
|
||||
.replace("Parameters", parameterDeclaration(newParameterCount))
|
||||
.replace("[CodeForSwitchCase]", generateArgumentSwitchCase())
|
||||
.replace("[GetFunctionCode]", getFunctionCode))(
|
||||
Promise,
|
||||
fn,
|
||||
receiver,
|
||||
withAppended,
|
||||
maybeWrapAsError,
|
||||
nodebackForPromise,
|
||||
util.tryCatch,
|
||||
util.errorObj,
|
||||
INTERNAL
|
||||
);
|
||||
".replace("[CodeForSwitchCase]", generateArgumentSwitchCase())
|
||||
.replace("[GetFunctionCode]", getFunctionCode);
|
||||
body = body.replace("Parameters", parameterDeclaration(newParameterCount));
|
||||
return new Function("Promise",
|
||||
"fn",
|
||||
"receiver",
|
||||
"withAppended",
|
||||
"maybeWrapAsError",
|
||||
"nodebackForPromise",
|
||||
"tryCatch",
|
||||
"errorObj",
|
||||
"notEnumerableProp",
|
||||
"INTERNAL",
|
||||
body)(
|
||||
Promise,
|
||||
fn,
|
||||
receiver,
|
||||
withAppended,
|
||||
maybeWrapAsError,
|
||||
nodebackForPromise,
|
||||
util.tryCatch,
|
||||
util.errorObj,
|
||||
util.notEnumerableProp,
|
||||
INTERNAL);
|
||||
};
|
||||
}
|
||||
|
||||
function makeNodePromisifiedClosure(callback, receiver, _, fn) {
|
||||
function makeNodePromisifiedClosure(callback, receiver, _, fn, __, multiArgs) {
|
||||
var defaultThis = (function() {return this;})();
|
||||
var method = callback;
|
||||
if (typeof method === "string") {
|
||||
@ -208,15 +218,16 @@ function makeNodePromisifiedClosure(callback, receiver, _, fn) {
|
||||
promise._captureStackTrace();
|
||||
var cb = typeof method === "string" && this !== defaultThis
|
||||
? this[method] : callback;
|
||||
var fn = nodebackForPromise(promise);
|
||||
var fn = nodebackForPromise(promise, multiArgs);
|
||||
try {
|
||||
cb.apply(_receiver, withAppended(arguments, fn));
|
||||
} catch(e) {
|
||||
promise._rejectCallback(maybeWrapAsError(e), true, true);
|
||||
}
|
||||
if (!promise._isFateSealed()) promise._setAsyncGuaranteed();
|
||||
return promise;
|
||||
}
|
||||
promisified.__isPromisified__ = true;
|
||||
util.notEnumerableProp(promisified, "__isPromisified__", true);
|
||||
return promisified;
|
||||
}
|
||||
|
||||
@ -224,7 +235,7 @@ var makeNodePromisified = canEvaluate
|
||||
? makeNodePromisifiedEval
|
||||
: makeNodePromisifiedClosure;
|
||||
|
||||
function promisifyAll(obj, suffix, filter, promisifier) {
|
||||
function promisifyAll(obj, suffix, filter, promisifier, multiArgs) {
|
||||
var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$");
|
||||
var methods =
|
||||
promisifiableMethods(obj, suffix, suffixRegexp, filter);
|
||||
@ -233,37 +244,48 @@ function promisifyAll(obj, suffix, filter, promisifier) {
|
||||
var key = methods[i];
|
||||
var fn = methods[i+1];
|
||||
var promisifiedKey = key + suffix;
|
||||
obj[promisifiedKey] = promisifier === makeNodePromisified
|
||||
? makeNodePromisified(key, THIS, key, fn, suffix)
|
||||
: promisifier(fn, function() {
|
||||
return makeNodePromisified(key, THIS, key, fn, suffix);
|
||||
});
|
||||
if (promisifier === makeNodePromisified) {
|
||||
obj[promisifiedKey] =
|
||||
makeNodePromisified(key, THIS, key, fn, suffix, multiArgs);
|
||||
} else {
|
||||
var promisified = promisifier(fn, function() {
|
||||
return makeNodePromisified(key, THIS, key,
|
||||
fn, suffix, multiArgs);
|
||||
});
|
||||
util.notEnumerableProp(promisified, "__isPromisified__", true);
|
||||
obj[promisifiedKey] = promisified;
|
||||
}
|
||||
}
|
||||
util.toFastProperties(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
function promisify(callback, receiver) {
|
||||
return makeNodePromisified(callback, receiver, undefined, callback);
|
||||
function promisify(callback, receiver, multiArgs) {
|
||||
return makeNodePromisified(callback, receiver, undefined,
|
||||
callback, null, multiArgs);
|
||||
}
|
||||
|
||||
Promise.promisify = function (fn, receiver) {
|
||||
Promise.promisify = function (fn, options) {
|
||||
if (typeof fn !== "function") {
|
||||
throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
|
||||
throw new TypeError("expecting a function but got " + util.classString(fn));
|
||||
}
|
||||
if (isPromisified(fn)) {
|
||||
return fn;
|
||||
}
|
||||
var ret = promisify(fn, arguments.length < 2 ? THIS : receiver);
|
||||
options = Object(options);
|
||||
var receiver = options.context === undefined ? THIS : options.context;
|
||||
var multiArgs = !!options.multiArgs;
|
||||
var ret = promisify(fn, receiver, multiArgs);
|
||||
util.copyDescriptors(fn, ret, propsFilter);
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.promisifyAll = function (target, options) {
|
||||
if (typeof target !== "function" && typeof target !== "object") {
|
||||
throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/9ITlV0\u000a");
|
||||
throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
}
|
||||
options = Object(options);
|
||||
var multiArgs = !!options.multiArgs;
|
||||
var suffix = options.suffix;
|
||||
if (typeof suffix !== "string") suffix = defaultSuffix;
|
||||
var filter = options.filter;
|
||||
@ -272,7 +294,7 @@ Promise.promisifyAll = function (target, options) {
|
||||
if (typeof promisifier !== "function") promisifier = makeNodePromisified;
|
||||
|
||||
if (!util.isIdentifier(suffix)) {
|
||||
throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/8FZo5V\u000a");
|
||||
throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
}
|
||||
|
||||
var keys = util.inheritedDataKeys(target);
|
||||
@ -280,12 +302,13 @@ Promise.promisifyAll = function (target, options) {
|
||||
var value = target[keys[i]];
|
||||
if (keys[i] !== "constructor" &&
|
||||
util.isClass(value)) {
|
||||
promisifyAll(value.prototype, suffix, filter, promisifier);
|
||||
promisifyAll(value, suffix, filter, promisifier);
|
||||
promisifyAll(value.prototype, suffix, filter, promisifier,
|
||||
multiArgs);
|
||||
promisifyAll(value, suffix, filter, promisifier, multiArgs);
|
||||
}
|
||||
}
|
||||
|
||||
return promisifyAll(target, suffix, filter, promisifier);
|
||||
return promisifyAll(target, suffix, filter, promisifier, multiArgs);
|
||||
};
|
||||
};
|
||||
|
118
node_modules/bluebird/js/release/props.js
generated
vendored
Normal file
118
node_modules/bluebird/js/release/props.js
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
"use strict";
|
||||
module.exports = function(
|
||||
Promise, PromiseArray, tryConvertToPromise, apiRejection) {
|
||||
var util = require("./util");
|
||||
var isObject = util.isObject;
|
||||
var es5 = require("./es5");
|
||||
var Es6Map;
|
||||
if (typeof Map === "function") Es6Map = Map;
|
||||
|
||||
var mapToEntries = (function() {
|
||||
var index = 0;
|
||||
var size = 0;
|
||||
|
||||
function extractEntry(value, key) {
|
||||
this[index] = value;
|
||||
this[index + size] = key;
|
||||
index++;
|
||||
}
|
||||
|
||||
return function mapToEntries(map) {
|
||||
size = map.size;
|
||||
index = 0;
|
||||
var ret = new Array(map.size * 2);
|
||||
map.forEach(extractEntry, ret);
|
||||
return ret;
|
||||
};
|
||||
})();
|
||||
|
||||
var entriesToMap = function(entries) {
|
||||
var ret = new Es6Map();
|
||||
var length = entries.length / 2 | 0;
|
||||
for (var i = 0; i < length; ++i) {
|
||||
var key = entries[length + i];
|
||||
var value = entries[i];
|
||||
ret.set(key, value);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
function PropertiesPromiseArray(obj) {
|
||||
var isMap = false;
|
||||
var entries;
|
||||
if (Es6Map !== undefined && obj instanceof Es6Map) {
|
||||
entries = mapToEntries(obj);
|
||||
isMap = true;
|
||||
} else {
|
||||
var keys = es5.keys(obj);
|
||||
var len = keys.length;
|
||||
entries = new Array(len * 2);
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var key = keys[i];
|
||||
entries[i] = obj[key];
|
||||
entries[i + len] = key;
|
||||
}
|
||||
}
|
||||
this.constructor$(entries);
|
||||
this._isMap = isMap;
|
||||
this._init$(undefined, -3);
|
||||
}
|
||||
util.inherits(PropertiesPromiseArray, PromiseArray);
|
||||
|
||||
PropertiesPromiseArray.prototype._init = function () {};
|
||||
|
||||
PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {
|
||||
this._values[index] = value;
|
||||
var totalResolved = ++this._totalResolved;
|
||||
if (totalResolved >= this._length) {
|
||||
var val;
|
||||
if (this._isMap) {
|
||||
val = entriesToMap(this._values);
|
||||
} else {
|
||||
val = {};
|
||||
var keyOffset = this.length();
|
||||
for (var i = 0, len = this.length(); i < len; ++i) {
|
||||
val[this._values[i + keyOffset]] = this._values[i];
|
||||
}
|
||||
}
|
||||
this._resolve(val);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
PropertiesPromiseArray.prototype.shouldCopyValues = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
PropertiesPromiseArray.prototype.getActualLength = function (len) {
|
||||
return len >> 1;
|
||||
};
|
||||
|
||||
function props(promises) {
|
||||
var ret;
|
||||
var castValue = tryConvertToPromise(promises);
|
||||
|
||||
if (!isObject(castValue)) {
|
||||
return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
} else if (castValue instanceof Promise) {
|
||||
ret = castValue._then(
|
||||
Promise.props, undefined, undefined, undefined, undefined);
|
||||
} else {
|
||||
ret = new PropertiesPromiseArray(castValue).promise();
|
||||
}
|
||||
|
||||
if (castValue instanceof Promise) {
|
||||
ret._propagateFrom(castValue, 2);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Promise.prototype.props = function () {
|
||||
return props(this);
|
||||
};
|
||||
|
||||
Promise.props = function (promises) {
|
||||
return props(promises);
|
||||
};
|
||||
};
|
0
node_modules/bluebird/js/main/queue.js → node_modules/bluebird/js/release/queue.js
generated
vendored
0
node_modules/bluebird/js/main/queue.js → node_modules/bluebird/js/release/queue.js
generated
vendored
10
node_modules/bluebird/js/main/race.js → node_modules/bluebird/js/release/race.js
generated
vendored
10
node_modules/bluebird/js/main/race.js → node_modules/bluebird/js/release/race.js
generated
vendored
@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
module.exports = function(
|
||||
Promise, INTERNAL, tryConvertToPromise, apiRejection) {
|
||||
var isArray = require("./util.js").isArray;
|
||||
var util = require("./util");
|
||||
|
||||
var raceLater = function (promise) {
|
||||
return promise.then(function(array) {
|
||||
@ -14,13 +14,15 @@ function race(promises, parent) {
|
||||
|
||||
if (maybePromise instanceof Promise) {
|
||||
return raceLater(maybePromise);
|
||||
} else if (!isArray(promises)) {
|
||||
return apiRejection("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a");
|
||||
} else {
|
||||
promises = util.asArray(promises);
|
||||
if (promises === null)
|
||||
return apiRejection("expecting an array or an iterable object but got " + util.classString(promises));
|
||||
}
|
||||
|
||||
var ret = new Promise(INTERNAL);
|
||||
if (parent !== undefined) {
|
||||
ret._propagateFrom(parent, 4 | 1);
|
||||
ret._propagateFrom(parent, 3);
|
||||
}
|
||||
var fulfill = ret._fulfill;
|
||||
var reject = ret._reject;
|
162
node_modules/bluebird/js/release/reduce.js
generated
vendored
Normal file
162
node_modules/bluebird/js/release/reduce.js
generated
vendored
Normal file
@ -0,0 +1,162 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise,
|
||||
PromiseArray,
|
||||
apiRejection,
|
||||
tryConvertToPromise,
|
||||
INTERNAL,
|
||||
debug) {
|
||||
var getDomain = Promise._getDomain;
|
||||
var util = require("./util");
|
||||
var tryCatch = util.tryCatch;
|
||||
|
||||
function ReductionPromiseArray(promises, fn, initialValue, _each) {
|
||||
this.constructor$(promises);
|
||||
var domain = getDomain();
|
||||
this._fn = domain === null ? fn : domain.bind(fn);
|
||||
if (initialValue !== undefined) {
|
||||
initialValue = Promise.resolve(initialValue);
|
||||
initialValue._attachCancellationCallback(this);
|
||||
}
|
||||
this._initialValue = initialValue;
|
||||
this._currentCancellable = null;
|
||||
this._eachValues = _each === INTERNAL ? [] : undefined;
|
||||
this._promise._captureStackTrace();
|
||||
this._init$(undefined, -5);
|
||||
}
|
||||
util.inherits(ReductionPromiseArray, PromiseArray);
|
||||
|
||||
ReductionPromiseArray.prototype._gotAccum = function(accum) {
|
||||
if (this._eachValues !== undefined && accum !== INTERNAL) {
|
||||
this._eachValues.push(accum);
|
||||
}
|
||||
};
|
||||
|
||||
ReductionPromiseArray.prototype._eachComplete = function(value) {
|
||||
this._eachValues.push(value);
|
||||
return this._eachValues;
|
||||
};
|
||||
|
||||
ReductionPromiseArray.prototype._init = function() {};
|
||||
|
||||
ReductionPromiseArray.prototype._resolveEmptyArray = function() {
|
||||
this._resolve(this._eachValues !== undefined ? this._eachValues
|
||||
: this._initialValue);
|
||||
};
|
||||
|
||||
ReductionPromiseArray.prototype.shouldCopyValues = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
ReductionPromiseArray.prototype._resolve = function(value) {
|
||||
this._promise._resolveCallback(value);
|
||||
this._values = null;
|
||||
};
|
||||
|
||||
ReductionPromiseArray.prototype._resultCancelled = function(sender) {
|
||||
if (sender === this._initialValue) return this._cancel();
|
||||
if (this._isResolved()) return;
|
||||
this._resultCancelled$();
|
||||
if (this._currentCancellable instanceof Promise) {
|
||||
this._currentCancellable.cancel();
|
||||
}
|
||||
if (this._initialValue instanceof Promise) {
|
||||
this._initialValue.cancel();
|
||||
}
|
||||
};
|
||||
|
||||
ReductionPromiseArray.prototype._iterate = function (values) {
|
||||
this._values = values;
|
||||
var value;
|
||||
var i;
|
||||
var length = values.length;
|
||||
if (this._initialValue !== undefined) {
|
||||
value = this._initialValue;
|
||||
i = 0;
|
||||
} else {
|
||||
value = Promise.resolve(values[0]);
|
||||
i = 1;
|
||||
}
|
||||
|
||||
this._currentCancellable = value;
|
||||
|
||||
if (!value.isRejected()) {
|
||||
for (; i < length; ++i) {
|
||||
var ctx = {
|
||||
accum: null,
|
||||
value: values[i],
|
||||
index: i,
|
||||
length: length,
|
||||
array: this
|
||||
};
|
||||
value = value._then(gotAccum, undefined, undefined, ctx, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
if (this._eachValues !== undefined) {
|
||||
value = value
|
||||
._then(this._eachComplete, undefined, undefined, this, undefined);
|
||||
}
|
||||
value._then(completed, completed, undefined, value, this);
|
||||
};
|
||||
|
||||
Promise.prototype.reduce = function (fn, initialValue) {
|
||||
return reduce(this, fn, initialValue, null);
|
||||
};
|
||||
|
||||
Promise.reduce = function (promises, fn, initialValue, _each) {
|
||||
return reduce(promises, fn, initialValue, _each);
|
||||
};
|
||||
|
||||
function completed(valueOrReason, array) {
|
||||
if (this.isFulfilled()) {
|
||||
array._resolve(valueOrReason);
|
||||
} else {
|
||||
array._reject(valueOrReason);
|
||||
}
|
||||
}
|
||||
|
||||
function reduce(promises, fn, initialValue, _each) {
|
||||
if (typeof fn !== "function") {
|
||||
return apiRejection("expecting a function but got " + util.classString(fn));
|
||||
}
|
||||
var array = new ReductionPromiseArray(promises, fn, initialValue, _each);
|
||||
return array.promise();
|
||||
}
|
||||
|
||||
function gotAccum(accum) {
|
||||
this.accum = accum;
|
||||
this.array._gotAccum(accum);
|
||||
var value = tryConvertToPromise(this.value, this.array._promise);
|
||||
if (value instanceof Promise) {
|
||||
this.array._currentCancellable = value;
|
||||
return value._then(gotValue, undefined, undefined, this, undefined);
|
||||
} else {
|
||||
return gotValue.call(this, value);
|
||||
}
|
||||
}
|
||||
|
||||
function gotValue(value) {
|
||||
var array = this.array;
|
||||
var promise = array._promise;
|
||||
var fn = tryCatch(array._fn);
|
||||
promise._pushContext();
|
||||
var ret;
|
||||
if (array._eachValues !== undefined) {
|
||||
ret = fn.call(promise._boundValue(), value, this.index, this.length);
|
||||
} else {
|
||||
ret = fn.call(promise._boundValue(),
|
||||
this.accum, value, this.index, this.length);
|
||||
}
|
||||
if (ret instanceof Promise) {
|
||||
array._currentCancellable = ret;
|
||||
}
|
||||
var promiseCreated = promise._popContext();
|
||||
debug.checkForgottenReturns(
|
||||
ret,
|
||||
promiseCreated,
|
||||
array._eachValues !== undefined ? "Promise.each" : "Promise.reduce",
|
||||
promise
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
};
|
28
node_modules/bluebird/js/main/schedule.js → node_modules/bluebird/js/release/schedule.js
generated
vendored
28
node_modules/bluebird/js/main/schedule.js → node_modules/bluebird/js/release/schedule.js
generated
vendored
@ -1,23 +1,19 @@
|
||||
"use strict";
|
||||
var util = require("./util");
|
||||
var schedule;
|
||||
var noAsyncScheduler = function() {
|
||||
throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/m3OTXk\u000a");
|
||||
throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
};
|
||||
if (require("./util.js").isNode) {
|
||||
var version = process.versions.node.split(".").map(Number);
|
||||
schedule = (version[0] === 0 && version[1] > 10) || (version[0] > 0)
|
||||
? global.setImmediate : process.nextTick;
|
||||
|
||||
if (!schedule) {
|
||||
if (typeof setImmediate !== "undefined") {
|
||||
schedule = setImmediate;
|
||||
} else if (typeof setTimeout !== "undefined") {
|
||||
schedule = setTimeout;
|
||||
} else {
|
||||
schedule = noAsyncScheduler;
|
||||
}
|
||||
}
|
||||
} else if (typeof MutationObserver !== "undefined") {
|
||||
if (util.isNode && typeof MutationObserver === "undefined") {
|
||||
var GlobalSetImmediate = global.setImmediate;
|
||||
var ProcessNextTick = process.nextTick;
|
||||
schedule = util.isRecentNode
|
||||
? function(fn) { GlobalSetImmediate.call(global, fn); }
|
||||
: function(fn) { ProcessNextTick.call(process, fn); };
|
||||
} else if ((typeof MutationObserver !== "undefined") &&
|
||||
!(typeof window !== "undefined" &&
|
||||
window.navigator &&
|
||||
window.navigator.standalone)) {
|
||||
schedule = function(fn) {
|
||||
var div = document.createElement("div");
|
||||
var observer = new MutationObserver(fn);
|
21
node_modules/bluebird/js/main/settle.js → node_modules/bluebird/js/release/settle.js
generated
vendored
21
node_modules/bluebird/js/main/settle.js → node_modules/bluebird/js/release/settle.js
generated
vendored
@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
module.exports =
|
||||
function(Promise, PromiseArray) {
|
||||
function(Promise, PromiseArray, debug) {
|
||||
var PromiseInspection = Promise.PromiseInspection;
|
||||
var util = require("./util.js");
|
||||
var util = require("./util");
|
||||
|
||||
function SettledPromiseArray(values) {
|
||||
this.constructor$(values);
|
||||
@ -14,27 +14,30 @@ SettledPromiseArray.prototype._promiseResolved = function (index, inspection) {
|
||||
var totalResolved = ++this._totalResolved;
|
||||
if (totalResolved >= this._length) {
|
||||
this._resolve(this._values);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
SettledPromiseArray.prototype._promiseFulfilled = function (value, index) {
|
||||
var ret = new PromiseInspection();
|
||||
ret._bitField = 268435456;
|
||||
ret._settledValue = value;
|
||||
this._promiseResolved(index, ret);
|
||||
ret._bitField = 33554432;
|
||||
ret._settledValueField = value;
|
||||
return this._promiseResolved(index, ret);
|
||||
};
|
||||
SettledPromiseArray.prototype._promiseRejected = function (reason, index) {
|
||||
var ret = new PromiseInspection();
|
||||
ret._bitField = 134217728;
|
||||
ret._settledValue = reason;
|
||||
this._promiseResolved(index, ret);
|
||||
ret._bitField = 16777216;
|
||||
ret._settledValueField = reason;
|
||||
return this._promiseResolved(index, ret);
|
||||
};
|
||||
|
||||
Promise.settle = function (promises) {
|
||||
debug.deprecated(".settle()", ".reflect()");
|
||||
return new SettledPromiseArray(promises).promise();
|
||||
};
|
||||
|
||||
Promise.prototype.settle = function () {
|
||||
return new SettledPromiseArray(this).promise();
|
||||
return Promise.settle(this);
|
||||
};
|
||||
};
|
35
node_modules/bluebird/js/main/some.js → node_modules/bluebird/js/release/some.js
generated
vendored
35
node_modules/bluebird/js/main/some.js → node_modules/bluebird/js/release/some.js
generated
vendored
@ -1,10 +1,11 @@
|
||||
"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 = require("./util");
|
||||
var RangeError = require("./errors").RangeError;
|
||||
var AggregateError = require("./errors").AggregateError;
|
||||
var isArray = util.isArray;
|
||||
var CANCELLATION = {};
|
||||
|
||||
|
||||
function SomePromiseArray(values) {
|
||||
@ -58,18 +59,40 @@ SomePromiseArray.prototype._promiseFulfilled = function (value) {
|
||||
} else {
|
||||
this._resolve(this._values);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
};
|
||||
SomePromiseArray.prototype._promiseRejected = function (reason) {
|
||||
this._addRejected(reason);
|
||||
return this._checkOutcome();
|
||||
};
|
||||
|
||||
SomePromiseArray.prototype._promiseCancelled = function () {
|
||||
if (this._values instanceof Promise || this._values == null) {
|
||||
return this._cancel();
|
||||
}
|
||||
this._addRejected(CANCELLATION);
|
||||
return this._checkOutcome();
|
||||
};
|
||||
|
||||
SomePromiseArray.prototype._checkOutcome = function() {
|
||||
if (this.howMany() > this._canPossiblyFulfill()) {
|
||||
var e = new AggregateError();
|
||||
for (var i = this.length(); i < this._values.length; ++i) {
|
||||
e.push(this._values[i]);
|
||||
if (this._values[i] !== CANCELLATION) {
|
||||
e.push(this._values[i]);
|
||||
}
|
||||
}
|
||||
this._reject(e);
|
||||
if (e.length > 0) {
|
||||
this._reject(e);
|
||||
} else {
|
||||
this._cancel();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
SomePromiseArray.prototype._fulfilled = function () {
|
||||
@ -104,7 +127,7 @@ SomePromiseArray.prototype._resolveEmptyArray = function () {
|
||||
|
||||
function some(promises, howMany) {
|
||||
if ((howMany | 0) !== howMany || howMany < 0) {
|
||||
return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/1wAmHx\u000a");
|
||||
return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
}
|
||||
var ret = new SomePromiseArray(promises);
|
||||
var promise = ret.promise();
|
96
node_modules/bluebird/js/release/synchronous_inspection.js
generated
vendored
Normal file
96
node_modules/bluebird/js/release/synchronous_inspection.js
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise) {
|
||||
function PromiseInspection(promise) {
|
||||
if (promise !== undefined) {
|
||||
promise = promise._target();
|
||||
this._bitField = promise._bitField;
|
||||
this._settledValueField = promise._isFateSealed()
|
||||
? promise._settledValue() : undefined;
|
||||
}
|
||||
else {
|
||||
this._bitField = 0;
|
||||
this._settledValueField = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
PromiseInspection.prototype._settledValue = function() {
|
||||
return this._settledValueField;
|
||||
};
|
||||
|
||||
var value = PromiseInspection.prototype.value = function () {
|
||||
if (!this.isFulfilled()) {
|
||||
throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
}
|
||||
return this._settledValue();
|
||||
};
|
||||
|
||||
var reason = PromiseInspection.prototype.error =
|
||||
PromiseInspection.prototype.reason = function () {
|
||||
if (!this.isRejected()) {
|
||||
throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||||
}
|
||||
return this._settledValue();
|
||||
};
|
||||
|
||||
var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
|
||||
return (this._bitField & 33554432) !== 0;
|
||||
};
|
||||
|
||||
var isRejected = PromiseInspection.prototype.isRejected = function () {
|
||||
return (this._bitField & 16777216) !== 0;
|
||||
};
|
||||
|
||||
var isPending = PromiseInspection.prototype.isPending = function () {
|
||||
return (this._bitField & 50397184) === 0;
|
||||
};
|
||||
|
||||
var isResolved = PromiseInspection.prototype.isResolved = function () {
|
||||
return (this._bitField & 50331648) !== 0;
|
||||
};
|
||||
|
||||
PromiseInspection.prototype.isCancelled =
|
||||
Promise.prototype._isCancelled = function() {
|
||||
return (this._bitField & 65536) === 65536;
|
||||
};
|
||||
|
||||
Promise.prototype.isCancelled = function() {
|
||||
return this._target()._isCancelled();
|
||||
};
|
||||
|
||||
Promise.prototype.isPending = function() {
|
||||
return isPending.call(this._target());
|
||||
};
|
||||
|
||||
Promise.prototype.isRejected = function() {
|
||||
return isRejected.call(this._target());
|
||||
};
|
||||
|
||||
Promise.prototype.isFulfilled = function() {
|
||||
return isFulfilled.call(this._target());
|
||||
};
|
||||
|
||||
Promise.prototype.isResolved = function() {
|
||||
return isResolved.call(this._target());
|
||||
};
|
||||
|
||||
Promise.prototype.value = function() {
|
||||
return value.call(this._target());
|
||||
};
|
||||
|
||||
Promise.prototype.reason = function() {
|
||||
var target = this._target();
|
||||
target._unsetRejectionIsUnhandled();
|
||||
return reason.call(target);
|
||||
};
|
||||
|
||||
Promise.prototype._value = function() {
|
||||
return this._settledValue();
|
||||
};
|
||||
|
||||
Promise.prototype._reason = function() {
|
||||
this._unsetRejectionIsUnhandled();
|
||||
return this._settledValue();
|
||||
};
|
||||
|
||||
Promise.PromiseInspection = PromiseInspection;
|
||||
};
|
@ -1,42 +1,49 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, INTERNAL) {
|
||||
var util = require("./util.js");
|
||||
var util = require("./util");
|
||||
var errorObj = util.errorObj;
|
||||
var isObject = util.isObject;
|
||||
|
||||
function tryConvertToPromise(obj, context) {
|
||||
if (isObject(obj)) {
|
||||
if (obj instanceof Promise) {
|
||||
return obj;
|
||||
}
|
||||
else if (isAnyBluebirdPromise(obj)) {
|
||||
var ret = new Promise(INTERNAL);
|
||||
obj._then(
|
||||
ret._fulfillUnchecked,
|
||||
ret._rejectUncheckedCheckError,
|
||||
ret._progressUnchecked,
|
||||
ret,
|
||||
null
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
var then = util.tryCatch(getThen)(obj);
|
||||
if (obj instanceof Promise) return obj;
|
||||
var then = getThen(obj);
|
||||
if (then === errorObj) {
|
||||
if (context) context._pushContext();
|
||||
var ret = Promise.reject(then.e);
|
||||
if (context) context._popContext();
|
||||
return ret;
|
||||
} else if (typeof then === "function") {
|
||||
if (isAnyBluebirdPromise(obj)) {
|
||||
var ret = new Promise(INTERNAL);
|
||||
obj._then(
|
||||
ret._fulfill,
|
||||
ret._reject,
|
||||
undefined,
|
||||
ret,
|
||||
null
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
return doThenable(obj, then, context);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
function getThen(obj) {
|
||||
function doGetThen(obj) {
|
||||
return obj.then;
|
||||
}
|
||||
|
||||
function getThen(obj) {
|
||||
try {
|
||||
return doGetThen(obj);
|
||||
} catch (e) {
|
||||
errorObj.e = e;
|
||||
return errorObj;
|
||||
}
|
||||
}
|
||||
|
||||
var hasProp = {}.hasOwnProperty;
|
||||
function isAnyBluebirdPromise(obj) {
|
||||
return hasProp.call(obj, "_promise0");
|
||||
@ -49,39 +56,25 @@ function doThenable(x, then, context) {
|
||||
promise._captureStackTrace();
|
||||
if (context) context._popContext();
|
||||
var synchronous = true;
|
||||
var result = util.tryCatch(then).call(x,
|
||||
resolveFromThenable,
|
||||
rejectFromThenable,
|
||||
progressFromThenable);
|
||||
var result = util.tryCatch(then).call(x, resolve, reject);
|
||||
synchronous = false;
|
||||
|
||||
if (promise && result === errorObj) {
|
||||
promise._rejectCallback(result.e, true, true);
|
||||
promise = null;
|
||||
}
|
||||
|
||||
function resolveFromThenable(value) {
|
||||
function resolve(value) {
|
||||
if (!promise) return;
|
||||
if (x === value) {
|
||||
promise._rejectCallback(
|
||||
Promise._makeSelfResolutionError(), false, true);
|
||||
} else {
|
||||
promise._resolveCallback(value);
|
||||
}
|
||||
promise._resolveCallback(value);
|
||||
promise = null;
|
||||
}
|
||||
|
||||
function rejectFromThenable(reason) {
|
||||
function reject(reason) {
|
||||
if (!promise) return;
|
||||
promise._rejectCallback(reason, synchronous, true);
|
||||
promise = null;
|
||||
}
|
||||
|
||||
function progressFromThenable(value) {
|
||||
if (!promise) return;
|
||||
if (typeof promise._progress === "function") {
|
||||
promise._progress(value);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
44
node_modules/bluebird/js/main/timers.js → node_modules/bluebird/js/release/timers.js
generated
vendored
44
node_modules/bluebird/js/main/timers.js → node_modules/bluebird/js/release/timers.js
generated
vendored
@ -1,34 +1,42 @@
|
||||
"use strict";
|
||||
module.exports = function(Promise, INTERNAL) {
|
||||
var util = require("./util.js");
|
||||
var util = require("./util");
|
||||
var TimeoutError = Promise.TimeoutError;
|
||||
|
||||
var afterTimeout = function (promise, message) {
|
||||
var afterTimeout = function (promise, message, parent) {
|
||||
if (!promise.isPending()) return;
|
||||
var err;
|
||||
if (typeof message !== "string") {
|
||||
message = "operation timed out";
|
||||
if (message instanceof Error) {
|
||||
err = message;
|
||||
} else {
|
||||
err = new TimeoutError("operation timed out");
|
||||
}
|
||||
} else {
|
||||
err = new TimeoutError(message);
|
||||
}
|
||||
var err = new TimeoutError(message);
|
||||
util.markAsOriginatingFromRejection(err);
|
||||
promise._attachExtraTrace(err);
|
||||
promise._cancel(err);
|
||||
promise._reject(err);
|
||||
parent.cancel();
|
||||
};
|
||||
|
||||
var afterValue = function(value) { return delay(+this).thenReturn(value); };
|
||||
var delay = Promise.delay = function (value, ms) {
|
||||
if (ms === undefined) {
|
||||
ms = value;
|
||||
value = undefined;
|
||||
var ret = new Promise(INTERNAL);
|
||||
setTimeout(function() { ret._fulfill(); }, ms);
|
||||
return ret;
|
||||
var delay = Promise.delay = function (ms, value) {
|
||||
var ret;
|
||||
if (value !== undefined) {
|
||||
ret = Promise.resolve(value)
|
||||
._then(afterValue, null, null, ms, undefined);
|
||||
} else {
|
||||
ret = new Promise(INTERNAL);
|
||||
setTimeout(function() { ret._fulfill(); }, +ms);
|
||||
}
|
||||
ms = +ms;
|
||||
return Promise.resolve(value)._then(afterValue, null, null, ms, undefined);
|
||||
ret._setAsyncGuaranteed();
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.prototype.delay = function (ms) {
|
||||
return delay(this, ms);
|
||||
return delay(ms, this);
|
||||
};
|
||||
|
||||
function successClear(value) {
|
||||
@ -47,10 +55,10 @@ function failureClear(reason) {
|
||||
|
||||
Promise.prototype.timeout = function (ms, message) {
|
||||
ms = +ms;
|
||||
var ret = this.then().cancellable();
|
||||
ret._cancellationParent = this;
|
||||
var parent = this.then();
|
||||
var ret = parent.then();
|
||||
var handle = setTimeout(function timeoutTimeout() {
|
||||
afterTimeout(ret, message);
|
||||
afterTimeout(ret, message, parent);
|
||||
}, ms);
|
||||
return ret._then(successClear, failureClear, undefined, handle, undefined);
|
||||
};
|
127
node_modules/bluebird/js/main/using.js → node_modules/bluebird/js/release/using.js
generated
vendored
127
node_modules/bluebird/js/main/using.js → node_modules/bluebird/js/release/using.js
generated
vendored
@ -1,21 +1,11 @@
|
||||
"use strict";
|
||||
module.exports = function (Promise, apiRejection, tryConvertToPromise,
|
||||
createContext) {
|
||||
var TypeError = require("./errors.js").TypeError;
|
||||
var inherits = require("./util.js").inherits;
|
||||
var PromiseInspection = Promise.PromiseInspection;
|
||||
|
||||
function inspectionMapper(inspections) {
|
||||
var len = inspections.length;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var inspection = inspections[i];
|
||||
if (inspection.isRejected()) {
|
||||
return Promise.reject(inspection.error());
|
||||
}
|
||||
inspections[i] = inspection._settledValue;
|
||||
}
|
||||
return inspections;
|
||||
}
|
||||
createContext, INTERNAL, debug) {
|
||||
var util = require("./util");
|
||||
var TypeError = require("./errors").TypeError;
|
||||
var inherits = require("./util").inherits;
|
||||
var errorObj = util.errorObj;
|
||||
var tryCatch = util.tryCatch;
|
||||
|
||||
function thrower(e) {
|
||||
setTimeout(function(){throw e;}, 0);
|
||||
@ -34,9 +24,9 @@ module.exports = function (Promise, apiRejection, tryConvertToPromise,
|
||||
function dispose(resources, inspection) {
|
||||
var i = 0;
|
||||
var len = resources.length;
|
||||
var ret = Promise.defer();
|
||||
var ret = new Promise(INTERNAL);
|
||||
function iterator() {
|
||||
if (i >= len) return ret.resolve();
|
||||
if (i >= len) return ret._fulfill();
|
||||
var maybePromise = castPreservingDisposable(resources[i++]);
|
||||
if (maybePromise instanceof Promise &&
|
||||
maybePromise._isDisposable()) {
|
||||
@ -55,21 +45,7 @@ module.exports = function (Promise, apiRejection, tryConvertToPromise,
|
||||
iterator();
|
||||
}
|
||||
iterator();
|
||||
return ret.promise;
|
||||
}
|
||||
|
||||
function disposerSuccess(value) {
|
||||
var inspection = new PromiseInspection();
|
||||
inspection._settledValue = value;
|
||||
inspection._bitField = 268435456;
|
||||
return dispose(this, inspection).thenReturn(value);
|
||||
}
|
||||
|
||||
function disposerFail(reason) {
|
||||
var inspection = new PromiseInspection();
|
||||
inspection._settledValue = reason;
|
||||
inspection._bitField = 134217728;
|
||||
return dispose(this, inspection).thenThrow(reason);
|
||||
return ret;
|
||||
}
|
||||
|
||||
function Disposer(data, promise, context) {
|
||||
@ -129,16 +105,43 @@ module.exports = function (Promise, apiRejection, tryConvertToPromise,
|
||||
return value;
|
||||
}
|
||||
|
||||
function ResourceList(length) {
|
||||
this.length = length;
|
||||
this.promise = null;
|
||||
this[length-1] = null;
|
||||
}
|
||||
|
||||
ResourceList.prototype._resultCancelled = function() {
|
||||
var len = this.length;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var item = this[i];
|
||||
if (item instanceof Promise) {
|
||||
item.cancel();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Promise.using = function () {
|
||||
var len = arguments.length;
|
||||
if (len < 2) return apiRejection(
|
||||
"you must pass at least 2 arguments to Promise.using");
|
||||
var fn = arguments[len - 1];
|
||||
if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
|
||||
len--;
|
||||
var resources = new Array(len);
|
||||
if (typeof fn !== "function") {
|
||||
return apiRejection("expecting a function but got " + util.classString(fn));
|
||||
}
|
||||
var input;
|
||||
var spreadArgs = true;
|
||||
if (len === 2 && Array.isArray(arguments[0])) {
|
||||
input = arguments[0];
|
||||
len = input.length;
|
||||
spreadArgs = false;
|
||||
} else {
|
||||
input = arguments;
|
||||
len--;
|
||||
}
|
||||
var resources = new ResourceList(len);
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var resource = arguments[i];
|
||||
var resource = input[i];
|
||||
if (Disposer.isDisposer(resource)) {
|
||||
var disposer = resource;
|
||||
resource = resource.promise();
|
||||
@ -156,31 +159,51 @@ module.exports = function (Promise, apiRejection, tryConvertToPromise,
|
||||
resources[i] = resource;
|
||||
}
|
||||
|
||||
var promise = Promise.settle(resources)
|
||||
.then(inspectionMapper)
|
||||
.then(function(vals) {
|
||||
promise._pushContext();
|
||||
var ret;
|
||||
try {
|
||||
ret = fn.apply(undefined, vals);
|
||||
} finally {
|
||||
promise._popContext();
|
||||
var reflectedResources = new Array(resources.length);
|
||||
for (var i = 0; i < reflectedResources.length; ++i) {
|
||||
reflectedResources[i] = Promise.resolve(resources[i]).reflect();
|
||||
}
|
||||
|
||||
var resultPromise = Promise.all(reflectedResources)
|
||||
.then(function(inspections) {
|
||||
for (var i = 0; i < inspections.length; ++i) {
|
||||
var inspection = inspections[i];
|
||||
if (inspection.isRejected()) {
|
||||
errorObj.e = inspection.error();
|
||||
return errorObj;
|
||||
} else if (!inspection.isFulfilled()) {
|
||||
resultPromise.cancel();
|
||||
return;
|
||||
}
|
||||
inspections[i] = inspection.value();
|
||||
}
|
||||
promise._pushContext();
|
||||
|
||||
fn = tryCatch(fn);
|
||||
var ret = spreadArgs
|
||||
? fn.apply(undefined, inspections) : fn(inspections);
|
||||
var promiseCreated = promise._popContext();
|
||||
debug.checkForgottenReturns(
|
||||
ret, promiseCreated, "Promise.using", promise);
|
||||
return ret;
|
||||
})
|
||||
._then(
|
||||
disposerSuccess, disposerFail, undefined, resources, undefined);
|
||||
});
|
||||
|
||||
var promise = resultPromise.lastly(function() {
|
||||
var inspection = new Promise.PromiseInspection(resultPromise);
|
||||
return dispose(resources, inspection);
|
||||
});
|
||||
resources.promise = promise;
|
||||
promise._setOnCancel(resources);
|
||||
return promise;
|
||||
};
|
||||
|
||||
Promise.prototype._setDisposable = function (disposer) {
|
||||
this._bitField = this._bitField | 262144;
|
||||
this._bitField = this._bitField | 131072;
|
||||
this._disposer = disposer;
|
||||
};
|
||||
|
||||
Promise.prototype._isDisposable = function () {
|
||||
return (this._bitField & 262144) > 0;
|
||||
return (this._bitField & 131072) > 0;
|
||||
};
|
||||
|
||||
Promise.prototype._getDisposer = function () {
|
||||
@ -188,7 +211,7 @@ module.exports = function (Promise, apiRejection, tryConvertToPromise,
|
||||
};
|
||||
|
||||
Promise.prototype._unsetDisposable = function () {
|
||||
this._bitField = this._bitField & (~262144);
|
||||
this._bitField = this._bitField & (~131072);
|
||||
this._disposer = undefined;
|
||||
};
|
||||
|
140
node_modules/bluebird/js/main/util.js → node_modules/bluebird/js/release/util.js
generated
vendored
140
node_modules/bluebird/js/main/util.js → node_modules/bluebird/js/release/util.js
generated
vendored
@ -1,27 +1,14 @@
|
||||
"use strict";
|
||||
var es5 = require("./es5.js");
|
||||
var es5 = require("./es5");
|
||||
var canEvaluate = typeof navigator == "undefined";
|
||||
var haveGetters = (function(){
|
||||
try {
|
||||
var o = {};
|
||||
es5.defineProperty(o, "f", {
|
||||
get: function () {
|
||||
return 3;
|
||||
}
|
||||
});
|
||||
return o.f === 3;
|
||||
}
|
||||
catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
var errorObj = {e: {}};
|
||||
var tryCatchTarget;
|
||||
function tryCatcher() {
|
||||
try {
|
||||
return tryCatchTarget.apply(this, arguments);
|
||||
var target = tryCatchTarget;
|
||||
tryCatchTarget = null;
|
||||
return target.apply(this, arguments);
|
||||
} catch (e) {
|
||||
errorObj.e = e;
|
||||
return errorObj;
|
||||
@ -59,7 +46,8 @@ function isPrimitive(val) {
|
||||
}
|
||||
|
||||
function isObject(value) {
|
||||
return !isPrimitive(value);
|
||||
return typeof value === "function" ||
|
||||
typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
function maybeWrapAsError(maybeError) {
|
||||
@ -82,6 +70,7 @@ function withAppended(target, appendee) {
|
||||
function getDataPropertyOrDefault(obj, key, defaultValue) {
|
||||
if (es5.isES5) {
|
||||
var desc = Object.getOwnPropertyDescriptor(obj, key);
|
||||
|
||||
if (desc != null) {
|
||||
return desc.get == null && desc.set == null
|
||||
? desc.value
|
||||
@ -104,23 +93,32 @@ function notEnumerableProp(obj, name, value) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
var wrapsPrimitiveReceiver = (function() {
|
||||
return this !== "string";
|
||||
}).call("string");
|
||||
|
||||
function thrower(r) {
|
||||
throw r;
|
||||
}
|
||||
|
||||
var inheritedDataKeys = (function() {
|
||||
var excludedPrototypes = [
|
||||
Array.prototype,
|
||||
Object.prototype,
|
||||
Function.prototype
|
||||
];
|
||||
|
||||
var isExcludedProto = function(val) {
|
||||
for (var i = 0; i < excludedPrototypes.length; ++i) {
|
||||
if (excludedPrototypes[i] === val) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if (es5.isES5) {
|
||||
var oProto = Object.prototype;
|
||||
var getKeys = Object.getOwnPropertyNames;
|
||||
return function(obj) {
|
||||
var ret = [];
|
||||
var visitedKeys = Object.create(null);
|
||||
while (obj != null && obj !== oProto) {
|
||||
while (obj != null && !isExcludedProto(obj)) {
|
||||
var keys;
|
||||
try {
|
||||
keys = getKeys(obj);
|
||||
@ -141,11 +139,23 @@ var inheritedDataKeys = (function() {
|
||||
return ret;
|
||||
};
|
||||
} else {
|
||||
var hasProp = {}.hasOwnProperty;
|
||||
return function(obj) {
|
||||
if (isExcludedProto(obj)) return [];
|
||||
var ret = [];
|
||||
|
||||
/*jshint forin:false */
|
||||
for (var key in obj) {
|
||||
ret.push(key);
|
||||
enumeration: for (var key in obj) {
|
||||
if (hasProp.call(obj, key)) {
|
||||
ret.push(key);
|
||||
} else {
|
||||
for (var i = 0; i < excludedPrototypes.length; ++i) {
|
||||
if (hasProp.call(excludedPrototypes[i], key)) {
|
||||
continue enumeration;
|
||||
}
|
||||
}
|
||||
ret.push(key);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
@ -153,13 +163,22 @@ var inheritedDataKeys = (function() {
|
||||
|
||||
})();
|
||||
|
||||
var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/;
|
||||
function isClass(fn) {
|
||||
try {
|
||||
if (typeof fn === "function") {
|
||||
var keys = es5.names(fn.prototype);
|
||||
if (es5.isES5) return keys.length > 1;
|
||||
return keys.length > 0 &&
|
||||
!(keys.length === 1 && keys[0] === "constructor");
|
||||
|
||||
var hasMethods = es5.isES5 && keys.length > 1;
|
||||
var hasMethodsOtherThanConstructor = keys.length > 0 &&
|
||||
!(keys.length === 1 && keys[0] === "constructor");
|
||||
var hasThisAssignmentAndStaticMethods =
|
||||
thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0;
|
||||
|
||||
if (hasMethods || hasMethodsOtherThanConstructor ||
|
||||
hasThisAssignmentAndStaticMethods) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (e) {
|
||||
@ -169,10 +188,10 @@ function isClass(fn) {
|
||||
|
||||
function toFastProperties(obj) {
|
||||
/*jshint -W027,-W055,-W031*/
|
||||
function f() {}
|
||||
f.prototype = obj;
|
||||
function FakeConstructor() {}
|
||||
FakeConstructor.prototype = obj;
|
||||
var l = 8;
|
||||
while (l--) new f();
|
||||
while (l--) new FakeConstructor();
|
||||
return obj;
|
||||
eval(obj);
|
||||
}
|
||||
@ -239,11 +258,50 @@ function copyDescriptors(from, to, filter) {
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
var key = keys[i];
|
||||
if (filter(key)) {
|
||||
es5.defineProperty(to, key, es5.getDescriptor(from, key));
|
||||
try {
|
||||
es5.defineProperty(to, key, es5.getDescriptor(from, key));
|
||||
} catch (ignore) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var asArray = function(v) {
|
||||
if (es5.isArray(v)) {
|
||||
return v;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
if (typeof Symbol !== "undefined" && Symbol.iterator) {
|
||||
var ArrayFrom = typeof Array.from === "function" ? function(v) {
|
||||
return Array.from(v);
|
||||
} : function(v) {
|
||||
var ret = [];
|
||||
var it = v[Symbol.iterator]();
|
||||
var itResult;
|
||||
while (!((itResult = it.next()).done)) {
|
||||
ret.push(itResult.value);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
asArray = function(v) {
|
||||
if (es5.isArray(v)) {
|
||||
return v;
|
||||
} else if (v != null && typeof v[Symbol.iterator] === "function") {
|
||||
return ArrayFrom(v);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
var isNode = typeof process !== "undefined" &&
|
||||
classString(process).toLowerCase() === "[object process]";
|
||||
|
||||
function env(key, def) {
|
||||
return isNode ? process.env[key] : def;
|
||||
}
|
||||
|
||||
var ret = {
|
||||
isClass: isClass,
|
||||
isIdentifier: isIdentifier,
|
||||
@ -251,7 +309,7 @@ var ret = {
|
||||
getDataPropertyOrDefault: getDataPropertyOrDefault,
|
||||
thrower: thrower,
|
||||
isArray: es5.isArray,
|
||||
haveGetters: haveGetters,
|
||||
asArray: asArray,
|
||||
notEnumerableProp: notEnumerableProp,
|
||||
isPrimitive: isPrimitive,
|
||||
isObject: isObject,
|
||||
@ -261,7 +319,6 @@ var ret = {
|
||||
inherits: inherits,
|
||||
withAppended: withAppended,
|
||||
maybeWrapAsError: maybeWrapAsError,
|
||||
wrapsPrimitiveReceiver: wrapsPrimitiveReceiver,
|
||||
toFastProperties: toFastProperties,
|
||||
filledRange: filledRange,
|
||||
toString: safeToString,
|
||||
@ -273,8 +330,15 @@ var ret = {
|
||||
copyDescriptors: copyDescriptors,
|
||||
hasDevTools: typeof chrome !== "undefined" && chrome &&
|
||||
typeof chrome.loadTimes === "function",
|
||||
isNode: typeof process !== "undefined" &&
|
||||
classString(process).toLowerCase() === "[object process]"
|
||||
isNode: isNode,
|
||||
env: env
|
||||
};
|
||||
ret.isRecentNode = ret.isNode && (function() {
|
||||
var version = process.versions.node.split(".").map(Number);
|
||||
return (version[0] === 0 && version[1] > 10) || (version[0] > 0);
|
||||
})();
|
||||
|
||||
if (ret.isNode) ret.toFastProperties(process);
|
||||
|
||||
try {throw new Error(); } catch (e) {ret.lastLineError = e;}
|
||||
module.exports = ret;
|
Reference in New Issue
Block a user