Skip to content
Snippets Groups Projects
index.js 7.56 MiB
Newer Older
  • Learn to ignore specific revisions
  • Romain CREY's avatar
    Romain CREY committed
        }
    
        shouldIgnore = function(line) {
            if (bluebirdFramePattern.test(line)) return true;
            var info = parseLineInfo(line);
            if (info) {
                if (info.fileName === firstFileName &&
                    (firstIndex <= info.line && info.line <= lastIndex)) {
                    return true;
                }
            }
            return false;
        };
    }
    
    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() {
        var v8stackFramePattern = /^\s*at\s*/;
        var v8stackFormatter = function(stack, error) {
            if (typeof stack === "string") return stack;
    
            if (error.name !== undefined &&
                error.message !== undefined) {
                return error.toString();
            }
            return formatNonError(error);
        };
    
        if (typeof Error.stackTraceLimit === "number" &&
            typeof Error.captureStackTrace === "function") {
            Error.stackTraceLimit += 6;
            stackFramePattern = v8stackFramePattern;
            formatStack = v8stackFormatter;
            var captureStackTrace = Error.captureStackTrace;
    
            shouldIgnore = function(line) {
                return bluebirdFramePattern.test(line);
            };
            return function(receiver, ignoreUntil) {
                Error.stackTraceLimit += 6;
                captureStackTrace(receiver, ignoreUntil);
                Error.stackTraceLimit -= 6;
            };
        }
        var err = new Error();
    
        if (typeof err.stack === "string" &&
            err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) {
            stackFramePattern = /@/;
            formatStack = v8stackFormatter;
            indentStackFrames = true;
            return function captureStackTrace(o) {
                o.stack = new Error().stack;
            };
        }
    
        var hasStackAfterThrow;
        try { throw new Error(); }
        catch(e) {
            hasStackAfterThrow = ("stack" in e);
        }
        if (!("stack" in err) && hasStackAfterThrow &&
            typeof Error.stackTraceLimit === "number") {
            stackFramePattern = v8stackFramePattern;
            formatStack = v8stackFormatter;
            return function captureStackTrace(o) {
                Error.stackTraceLimit += 6;
                try { throw new Error(); }
                catch(e) { o.stack = e.stack; }
                Error.stackTraceLimit -= 6;
            };
        }
    
        formatStack = function(stack, error) {
            if (typeof stack === "string") return stack;
    
            if ((typeof error === "object" ||
                typeof error === "function") &&
                error.name !== undefined &&
                error.message !== undefined) {
                return error.toString();
            }
            return formatNonError(error);
        };
    
        return null;
    
    })([]);
    
    if (typeof console !== "undefined" && typeof console.warn !== "undefined") {
        printWarning = function (message) {
            console.warn(message);
        };
        if (util.isNode && process.stderr.isTTY) {
            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") {
            printWarning = function(message, isSoft) {
                console.warn("%c" + message,
                            isSoft ? "color: darkorange" : "color: red");
            };
        }
    }
    
    var config = {
        warnings: warnings,
        longStackTraces: false,
        cancellation: false,
    
        monitoring: false,
        asyncHooks: false
    
    Romain CREY's avatar
    Romain CREY committed
    };
    
    if (longStackTraces) Promise.longStackTraces();
    
    return {
    
        asyncHooks: function() {
            return config.asyncHooks;
        },
    
    Romain CREY's avatar
    Romain CREY committed
        longStackTraces: function() {
            return config.longStackTraces;
        },
        warnings: function() {
            return config.warnings;
        },
        cancellation: function() {
            return config.cancellation;
        },
        monitoring: function() {
            return config.monitoring;
        },
        propagateFromFunction: function() {
            return propagateFromFunction;
        },
        boundValueFunction: function() {
            return boundValueFunction;
        },
        checkForgottenReturns: checkForgottenReturns,
        setBounds: setBounds,
        warn: warn,
        deprecated: deprecated,
        CapturedTrace: CapturedTrace,
        fireDomEvent: fireDomEvent,
        fireGlobalEvent: fireGlobalEvent
    };
    };
    
    
    /***/ }),
    
    /* 38 */
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    "use strict";
    
    module.exports = function(Promise, tryConvertToPromise, NEXT_FILTER) {
    
    var util = __webpack_require__(27);
    
    Romain CREY's avatar
    Romain CREY committed
    var CancellationError = Promise.CancellationError;
    var errorObj = util.errorObj;
    
    var catchFilter = __webpack_require__(39)(NEXT_FILTER);
    
    Romain CREY's avatar
    Romain CREY committed
    
    function PassThroughHandlerContext(promise, type, handler) {
        this.promise = promise;
        this.type = type;
        this.handler = handler;
        this.called = false;
        this.cancelPromise = null;
    }
    
    PassThroughHandlerContext.prototype.isFinallyHandler = function() {
        return this.type === 0;
    };
    
    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.isFinallyHandler()
                ? handler.call(promise._boundValue())
                : handler.call(promise._boundValue(), reasonOrValue);
            if (ret === NEXT_FILTER) {
                return ret;
            } else if (ret !== undefined) {
                promise._setReturnedNonUndefined();
                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,
                          new PassThroughHandlerContext(this, type, handler),
                          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);
    };
    
    Promise.prototype.tapCatch = function (handlerOrPredicate) {
        var len = arguments.length;
        if(len === 1) {
            return this._passThrough(handlerOrPredicate,
                                     1,
                                     undefined,
                                     finallyHandler);
        } else {
             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 Promise.reject(new TypeError(
                        "tapCatch statement predicate: "
                        + "expecting an object but got " + util.classString(item)
                    ));
                }
            }
            catchInstances.length = j;
            var handler = arguments[i];
            return this._passThrough(catchFilter(catchInstances, handler, this),
                                     1,
                                     undefined,
                                     finallyHandler);
        }
    
    };
    
    return PassThroughHandlerContext;
    };
    
    
    /***/ }),
    
    /* 39 */
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    "use strict";
    
    module.exports = function(NEXT_FILTER) {
    
    var util = __webpack_require__(27);
    var getKeys = __webpack_require__(28).keys;
    
    Romain CREY's avatar
    Romain CREY committed
    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;
    };
    
    
    /***/ }),
    
    /* 40 */
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    "use strict";
    
    
    var util = __webpack_require__(27);
    
    Romain CREY's avatar
    Romain CREY committed
    var maybeWrapAsError = util.maybeWrapAsError;
    
    var errors = __webpack_require__(33);
    
    Romain CREY's avatar
    Romain CREY committed
    var OperationalError = errors.OperationalError;
    
    var es5 = __webpack_require__(28);
    
    Romain CREY's avatar
    Romain CREY committed
    
    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(Math.max($_len - 1, 0)); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];};
                promise._fulfill(args);
            }
            promise = null;
        };
    }
    
    module.exports = nodebackForPromise;
    
    
    /***/ }),
    
    /* 41 */
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    "use strict";
    
    module.exports =
    function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) {
    
    var util = __webpack_require__(27);
    
    Romain CREY's avatar
    Romain CREY committed
    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);
        }
    };
    };
    
    
    /***/ }),
    
    /* 42 */
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    "use strict";
    
    module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) {
    var calledBind = false;
    var rejectThis = function(_, e) {
        this._reject(e);
    };
    
    var targetRejected = function(e, context) {
        context.promiseRejectionQueued = true;
        context.bindingPromise._then(rejectThis, rejectThis, null, this, e);
    };
    
    var bindingResolved = function(thisArg, context) {
        if (((this._bitField & 50397184) === 0)) {
            this._resolveCallback(context.target);
        }
    };
    
    var bindingRejected = function(e, context) {
        if (!context.promiseRejectionQueued) this._reject(e);
    };
    
    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,
                promise: ret,
                target: target,
                bindingPromise: maybePromise
            };
            target._then(INTERNAL, targetRejected, undefined, ret, context);
            maybePromise._then(
                bindingResolved, bindingRejected, undefined, ret, context);
            ret._setOnCancel(maybePromise);
        } else {
            ret._resolveCallback(target);
        }
        return ret;
    };
    
    Promise.prototype._setBoundTo = function (obj) {
        if (obj !== undefined) {
            this._bitField = this._bitField | 2097152;
            this._boundTo = obj;
        } else {
            this._bitField = this._bitField & (~2097152);
        }
    };
    
    Promise.prototype._isBound = function () {
        return (this._bitField & 2097152) === 2097152;
    };
    
    Promise.bind = function (thisArg, value) {
        return Promise.resolve(value).bind(thisArg);
    };
    };
    
    
    /***/ }),
    
    /* 43 */
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    "use strict";
    
    module.exports = function(Promise, PromiseArray, apiRejection, debug) {
    
    var util = __webpack_require__(27);
    
    Romain CREY's avatar
    Romain CREY committed
    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();
                promise._setWillBeCancelled();
                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.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();
    };
    
    };
    
    
    /***/ }),
    
    /* 44 */
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    "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);
        }
    };
    };
    
    
    /***/ }),
    
    /* 45 */
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    "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 = function() {
        return (this._bitField & 8454144) !== 0;
    };
    
    Promise.prototype.__isCancelled = function() {
        return (this._bitField & 65536) === 65536;
    };
    
    Promise.prototype._isCancelled = function() {
        return this._target().__isCancelled();
    };
    
    Promise.prototype.isCancelled = function() {
        return (this._target()._bitField & 8454144) !== 0;
    };
    
    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;
    };
    
    
    /***/ }),
    
    /* 46 */
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    "use strict";
    
    module.exports =
    
    function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async) {
    var util = __webpack_require__(27);
    
    Romain CREY's avatar
    Romain CREY committed
    var canEvaluate = util.canEvaluate;
    var tryCatch = util.tryCatch;
    var errorObj = util.errorObj;
    var reject;
    
    if (true) {
    if (canEvaluate) {
        var thenCallback = function(i) {
            return new Function("value", "holder", "                             \n\
                'use strict';                                                    \n\
                holder.pIndex = value;                                           \n\
                holder.checkFulfillment(this);                                   \n\
                ".replace(/Index/g, i));
        };
    
        var 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, async) {    \n\
                'use strict';                                                    \n\
                function [TheName](fn) {                                         \n\
                    [TheProperties]                                              \n\
                    this.fn = fn;                                                \n\
                    this.asyncNeeded = true;                                     \n\
                    this.now = 0;                                                \n\
                }                                                                \n\
                                                                                 \n\
                [TheName].prototype._callFunction = function(promise) {          \n\
                    promise._pushContext();                                      \n\
                    var ret = tryCatch(this.fn)([ThePassedArguments]);           \n\
                    promise._popContext();                                       \n\
                    if (ret === errorObj) {                                      \n\
                        promise._rejectCallback(ret.e, false);                   \n\
                    } else {                                                     \n\
                        promise._resolveCallback(ret);                           \n\
                    }                                                            \n\
                };                                                               \n\
                                                                                 \n\
                [TheName].prototype.checkFulfillment = function(promise) {       \n\
                    var now = ++this.now;                                        \n\
                    if (now === [TheTotal]) {                                    \n\
                        if (this.asyncNeeded) {                                  \n\
                            async.invoke(this._callFunction, this, promise);     \n\
                        } else {                                                 \n\
                            this._callFunction(promise);                         \n\
                        }                                                        \n\
                                                                                 \n\
                    }                                                            \n\
                };                                                               \n\
                                                                                 \n\